Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function isIPv4(token){
  2.     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
  3. }
  4.  
  5. function isTeXR(token){
  6.     return !isNokIn(token) && (/^.*\/.*\/.*\/.*$/.exec(token) !== null || (/^.*$/.exec(token) && !isIPv4(token)))
  7. }
  8.  
  9. function isNokIn(token){
  10.     return /^INT.*/.exec(token) !== null
  11. }
  12.  
  13. function getInt(tokens){
  14.     console.log(tokens)
  15.     //NOK
  16.     if (isNokIn(tokens[0])) return {int:tokens[0],v:'NOK'}
  17.     //IOS
  18.     if (tokens.length === 6 && isTeXR(tokens[0])) return {int:tokens[0],v:'IOS'}
  19.     if (tokens.length === 9 && isTeXR(tokens[0])) return {int:tokens[0],v:'IOS'}
  20.     if (tokens.length === 8 && isTeXR(tokens[0]) && tokens[5] === 'interface') return {int:tokens[0],v:'IOS'}
  21.     if (tokens.length === 7 && isIPv4(tokens[0]) && isTeXR(tokens[6])) return {int:tokens[6],v:'IOS'}
  22.     if (tokens.length === 5 && isTeXR(tokens[0])) return {int:tokens[0],v:'IOS'}
  23.     return undefined
  24. }
  25.  
  26. function getILockOutput(i,prev){
  27.     console.log(i)
  28.     if (i.v === 'IOS'){
  29.         if (prev !== null && prev.v === 'IOS'){
  30.             return `interface `+i.int+`
  31. shutdown
  32. !
  33. `}
  34.         else {
  35.             return `configure t
  36. interface `+i.int+`
  37. shutdown
  38. !
  39. `}
  40.     }
  41.     else if(i.v === 'NOK'){
  42.         if (prev !== null && prev.v === 'IOS'){
  43.         return `end
  44. configure service ies 3000 interface "` + i.int+ `" shutdown
  45. `}else{
  46.         return `configure service ies 3000 interface "` + i.int+ `" shutdown
  47.         `}
  48.     }
  49. }
  50. function getIUnlockOutput(i,prev){
  51.     if (i.v === 'IOS'){
  52.         if (prev !== null && prev.v === 'IOS'){
  53.             return `interface `+i.int+`
  54. no shutdown
  55. !
  56. `
  57. }
  58.         else {
  59.             return `configure t
  60. interface `+i.int+`
  61. no shutdown
  62. !
  63. `}
  64.     }else if(i.v === 'NOK'){
  65.         if (prev !== null && prev.v === 'IOS'){
  66.         return `end
  67. configure service ies 3000 interface "` + i.int+ `" no shutdown
  68. `}else{
  69.         return `configure service ies 3000 interface "` + i.int+ `" no shutdown
  70.         `}
  71.     }
  72. }
  73.  
  74.  
  75. function parseInput(input,l){
  76.     let output = ""
  77.     let lines = input.trim().split('\n')
  78.     let prev = null
  79.     lines.forEach(element => {
  80.         let tokens = element.trim().split(/[\t ]+/)
  81.         i = getInt(tokens)        
  82.         if (l === 'l') output+=getILockOutput(i,prev)
  83.         else output+=getIUnlockOutput(i,prev)
  84.         prev = i
  85.     })
  86.     if (prev.v === 'IOS') output+='end\n'
  87.     return output
  88. }
  89.  
  90. function convert(l){
  91.     document.getElementById('out').value = parseInput(document.getElementById('in').value,l)
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement