Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isIPv4(token){
- return /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/.exec(token) !== null
- }
- function isTeXR(token){
- return !isNokIn(token) && (/^.*\/.*\/.*\/.*$/.exec(token) !== null || (/^.*$/.exec(token) && !isIPv4(token)))
- }
- function isNokIn(token){
- return /^INT.*/.exec(token) !== null
- }
- function getInt(tokens){
- console.log(tokens)
- //NOK
- if (isNokIn(tokens[0])) return {int:tokens[0],v:'NOK'}
- //IOS
- if (tokens.length === 6 && isTeXR(tokens[0])) return {int:tokens[0],v:'IOS'}
- if (tokens.length === 9 && isTeXR(tokens[0])) return {int:tokens[0],v:'IOS'}
- if (tokens.length === 8 && isTeXR(tokens[0]) && tokens[5] === 'interface') return {int:tokens[0],v:'IOS'}
- if (tokens.length === 7 && isIPv4(tokens[0]) && isTeXR(tokens[6])) return {int:tokens[6],v:'IOS'}
- if (tokens.length === 5 && isTeXR(tokens[0])) return {int:tokens[0],v:'IOS'}
- return undefined
- }
- function getILockOutput(i,prev){
- console.log(i)
- if (i.v === 'IOS'){
- if (prev !== null && prev.v === 'IOS'){
- return `interface `+i.int+`
- shutdown
- !
- `}
- else {
- return `configure t
- interface `+i.int+`
- shutdown
- !
- `}
- }
- else if(i.v === 'NOK'){
- if (prev !== null && prev.v === 'IOS'){
- return `end
- configure service ies 3000 interface "` + i.int+ `" shutdown
- `}else{
- return `configure service ies 3000 interface "` + i.int+ `" shutdown
- `}
- }
- }
- function getIUnlockOutput(i,prev){
- if (i.v === 'IOS'){
- if (prev !== null && prev.v === 'IOS'){
- return `interface `+i.int+`
- no shutdown
- !
- `
- }
- else {
- return `configure t
- interface `+i.int+`
- no shutdown
- !
- `}
- }else if(i.v === 'NOK'){
- if (prev !== null && prev.v === 'IOS'){
- return `end
- configure service ies 3000 interface "` + i.int+ `" no shutdown
- `}else{
- return `configure service ies 3000 interface "` + i.int+ `" no shutdown
- `}
- }
- }
- function parseInput(input,l){
- let output = ""
- let lines = input.trim().split('\n')
- let prev = null
- lines.forEach(element => {
- let tokens = element.trim().split(/[\t ]+/)
- i = getInt(tokens)
- if (l === 'l') output+=getILockOutput(i,prev)
- else output+=getIUnlockOutput(i,prev)
- prev = i
- })
- if (prev.v === 'IOS') output+='end\n'
- return output
- }
- function convert(l){
- document.getElementById('out').value = parseInput(document.getElementById('in').value,l)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement