Skip to content

Commit a22ed08

Browse files
committed
Add demo content
Add demo content add favicon fix some code styling
1 parent 45f9eae commit a22ed08

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
Не знайшовши on-line алтернативи, вирішив реалізувати свій варіант. Спочатку було зроблено також на мові програмування perl, але згодом я вирішив переробити його на javascript, що значно полегшить інтеграцію даного інструменту в різні онлайн сервіси.
1212

1313
Працездатність перевірено на резервних копіях обладнання Juniper серії MX. Результати конвертора звірено з рідним виводом команди ```show | display omit | display set | no-more``` того ж обладнання.
14+
## Демо
15+
Демо https://mr-method.github.io/jun2set/
1416

1517
## Відомі баги :beetle:
1618
Деякі блоки конфігурації конвертуються в один рядок, хоча вивід команди ```show | display set | no-more``` того ж блоку виводить в кілька рядків, наприклад:

favicon.ico

15 KB
Binary file not shown.

index.html

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Juniper config converter</title>
8+
<link rel="shortcut icon" type="image/jpg" href="favicon.ico"/>
89
<link rel="stylesheet" href="jun.css" />
910
</head>
1011

@@ -27,6 +28,7 @@ <h2>Juniper config to set converter</h2>
2728
<div id="controls">
2829
<button type="button" data-convert>Convert</button>
2930
<button type="button" data-clear>Clear</button>
31+
<button type="button" data-demo>Demo</button>
3032
</div>
3133
<div class="output" style="display: none;">
3234
<pre id="preout"><code id="textout" class="Codeblock"></code></pre>

jun.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,35 @@ date: 2023.08.13
99

1010
const btnConvert = document.querySelector('[data-convert]');
1111
const btnClean = document.querySelector('[data-clear]');
12+
const btnDemo = document.querySelector('[data-demo]');
1213
const outputBlock = document.querySelector('.output');
1314
const codeBlock = document.getElementById('textout');
1415
let setInstance = "";
1516

1617
btnConvert.addEventListener('click', doConvert);
1718
btnClean.addEventListener('click', destroyBoxes);
19+
btnDemo.addEventListener('click', setDemo);
1820
const dptree = {};
1921

20-
function SetDPTree(commands, mode, leaf) {
22+
function setDPTree(commands, mode, leaf) {
2123
let str = commands.join(' ');
2224
if ( dptree[mode] === undefined ) dptree[mode] = {};
2325
if ( dptree[mode][str] === undefined ) dptree[mode][str] = leaf;
2426
}
2527

26-
function GetDPTree(commands, mode) {
28+
function getDPTree(commands, mode) {
2729
let str = commands.join(' ');
2830
if ( dptree[mode] === undefined || dptree[mode][str] === undefined ) return;
2931
setInstance += dptree[mode][str];
3032
delete dptree[mode][str];
3133
}
3234

35+
function setDemo (e) {
36+
document.getElementById("textin").value =
37+
"system {\n processes {\n general-authentication-service {\n traceoptions {\n" +
38+
" file gas.log size 10k files 3;\n flag all;\n }\n }\n }\n}";
39+
}
40+
3341
function FiltrInactive(leaf) {
3442
let str = leaf.slice();
3543
console.log(str);
@@ -112,19 +120,19 @@ function doConvert() {
112120
a = a.replace('inactive: ', '');
113121
const linactive = [...tree];
114122
linactive[0] = 'deactivate';
115-
SetDPTree(tree, 'inactive_array', retSetCommand(linactive, a));
123+
setDPTree(tree, 'inactive_array', retSetCommand(linactive, a));
116124
} else if (a.includes('protect: ')) {
117125
a = a.replace('protect: ', '');
118126
const lprotect = [...tree];
119127
lprotect[0] = 'protect';
120-
SetDPTree(tree, 'protect_line', retSetCommand(lprotect, a));
128+
setDPTree(tree, 'protect_line', retSetCommand(lprotect, a));
121129
}
122130
b.split(' ').forEach(function (item) {
123131
if (!item.includes(']')) {
124132
setInstance += retSetCommand(tree, a+' '+item);
125133
} else {
126-
GetDPTree(tree, 'inactive_array');
127-
GetDPTree(tree, 'protect_array');
134+
getDPTree(tree, 'inactive_array');
135+
getDPTree(tree, 'protect_array');
128136
}
129137
});
130138
// alert(retSetCommand(tree, cleanElem.split(';')[0]));
@@ -133,20 +141,20 @@ function doConvert() {
133141
cleanElem = cleanElem.replace('inactive: ', '');
134142
const linactive = [...tree];
135143
linactive[0] = 'deactivate';
136-
SetDPTree(tree, 'inactive_line', retSetCommand(linactive, FiltrInactive(cleanElem.replace(/\;\s*.*/, '')))); //.split(' ')[0]
144+
setDPTree(tree, 'inactive_line', retSetCommand(linactive, FiltrInactive(cleanElem.replace(/\;\s*.*/, '')))); //.split(' ')[0]
137145
} else if (cleanElem.includes('protect: ')) {
138146
cleanElem = cleanElem.replace('protect: ', '');
139147
const lprotect = [...tree];
140148
lprotect[0] = 'protect';
141-
SetDPTree(tree, 'protect_line', retSetCommand(lprotect, cleanElem.replace(/\;\s*.*/, '')));
149+
setDPTree(tree, 'protect_line', retSetCommand(lprotect, cleanElem.replace(/\;\s*.*/, '')));
142150
}
143151
setInstance += retSetCommand(tree, cleanElem.replace(/\;\s*.*/, ''));
144152
}
145-
GetDPTree(tree, 'inactive_line');
146-
GetDPTree(tree, 'protect_line');
153+
getDPTree(tree, 'inactive_line');
154+
getDPTree(tree, 'protect_line');
147155
} else if (cleanElem === '}') {
148-
GetDPTree(tree, 'inactive_block');
149-
GetDPTree(tree, 'protect_block');
156+
getDPTree(tree, 'inactive_block');
157+
getDPTree(tree, 'protect_block');
150158
tree.pop();
151159
} else {
152160
cleanElem = cleanElem.replace(' {', '');
@@ -155,13 +163,13 @@ function doConvert() {
155163
const linactive = [...tree];
156164
linactive[0] = 'deactivate';
157165
tree.push(cleanElem);
158-
SetDPTree(tree, 'inactive_block', retSetCommand(linactive, cleanElem));
166+
setDPTree(tree, 'inactive_block', retSetCommand(linactive, cleanElem));
159167
} else if (cleanElem.includes('protect: ')) {
160168
cleanElem = cleanElem.replace('protect: ', '');
161169
const lprotect = [...tree];
162170
lprotect[0] = 'protect';
163171
tree.push(cleanElem);
164-
SetDPTree(tree, 'protect_block', retSetCommand(lprotect, cleanElem));
172+
setDPTree(tree, 'protect_block', retSetCommand(lprotect, cleanElem));
165173
} else {
166174
tree.push(cleanElem);
167175
}

0 commit comments

Comments
 (0)