-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopenvpn_parser.html
More file actions
116 lines (115 loc) · 4.5 KB
/
openvpn_parser.html
File metadata and controls
116 lines (115 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!-- This is used by the oconf BB tag to parse openvpn configurations -->
<style type="text/css">
.ovpn_cont {
border: 1px solid darkgrey;
position: relative;
}
.ovpn_title {
border-bottom: 2px solid darkgrey;
padding: 3px;
background: linear-gradient(rgb(163,182,200),rgb(123,150,176));
position: relative;
}
.ovpn_config {
font-family: monospace;
background: #FFF;
position: relative;
}
.ovpn_line, .linnum, .lincont {
display: inline-block;
}
.ovpn_line:hover {
background: lightgrey;
}
.linnum {
min-width: 3em;
text-align: right;
padding-right: 7px;
border-right: 1px solid darkgrey;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
-o-user-select: none;
user-select: none;
}
.lincont {
padding-left: 7px;
}
.ovpn_line {
width: 100%;
}
.conf_swap {
float: right;
}
</style>
<script type="text/javascript">
var configs = document.getElementsByClassName("ovpn_config");
var arr = [].slice.call(configs);
arr.forEach(function(config) {
console.log(config);
var pretty = config.getElementsByClassName("ovpn_pretty").item(0);
var post = config.getElementsByClassName("ovpn_post").item(0);
var out = post.innerHTML;
console.log(out);
// strip out inline certificates and keys
out=out.replace(/<br\/?>/gm, "\n");
out=out.replace(/(<|\<)cert(>|\>)[\s\S]*(<|\<)\/cert(>|\>)/gm, "<cert>\n--STRIPPED INLINE CERT--\n</cert>");
out=out.replace(/(<|<)ca(>|>)[\s\S]*(<|<)\/ca(>|>)/gm, "<ca>\n--STRIPPED INLINE CA CERT--\n</ca>");
out=out.replace(/(<|<)key(>|>)[\s\S]*(<|<)\/key(>|>)/gm, "<key>\n--STRIPPED INLINE KEY--\n</key>");
lin_num(post);
out=out.replace(/<(?:.|\n)*?>/gm, "");
// strip out comment lines
out=out.replace(/(#.*)|(\s+;.*)/gm, "");
// remove empty lines
out=out.replace(/^[\s]*[\r\n]|^#.*|^;.*/gm, "");
pretty.innerHTML=out;
console.log(lin_num(pretty));
pretty.innerHTML=lin_num(pretty);
post.style.display="none";
pretty.style.display="block";
post.innerHTML=post.innerHTML.replace(/<br>/gm, "\n");
post.innerHTML=post.innerHTML.replace(/(<|\<)cert(>|\>)[\s\S]*(<|\<)\/cert(>|\>)/gm, "<cert>\n--STRIPPED INLINE CERT--\n</cert>");
post.innerHTML=post.innerHTML.replace(/(<|<)ca(>|>)[\s\S]*(<|<)\/ca(>|>)/gm, "<ca>\n--STRIPPED INLINE CA CERT--\n</ca>");
post.innerHTML=post.innerHTML.replace(/(<|<)key(>|>)[\s\S]*(<|<)\/key(>|>)/gm, "<key>\n--STRIPPED INLINE KEY--\n</key>");
post.innerHTML=lin_num(post);
});
function makeid(){
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for( var i=0; i < 5; i++ ){
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
function lin_num(text){
var id = makeid();
console.log(text);
var text_ar = text.innerHTML.split("\n");
console.log("Total Lines: " + text_ar.length);
console.log(text_ar);
var out = "";
var linnum = 1;
text_ar.forEach(function(line){
if (linnum < text_ar.length){
out+="<div id=\""+id+linnum+"\" class=\"ovpn_line\"><div class=\"linnum\">"+linnum+"</div><div class=\"lincont\">"+line+"</div></div>\n";
linnum++;
}
});
return out;
}
function swap_conf(button){
var p = button.parentNode.parentNode;
var pretty = p.getElementsByClassName("ovpn_pretty").item(0);
var post = p.getElementsByClassName("ovpn_post").item(0);
console.log(p);
if (button.innerHTML == "View Original"){
pretty.style.display="none";
post.style.display="block";
button.innerHTML = "View Formatted";
} else {
pretty.style.display="block";
post.style.display="none";
button.innerHTML = "View Original";
}
}
</script>