openvpn-mgt/web/index.html

229 lines
6.2 KiB
HTML
Raw Normal View History

2019-08-16 15:23:19 +00:00
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>OpenVPN Manager</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="bootstrap.min.js"></script>
<link rel="stylesheet" href="bootstrap.min.css" />
<style>
body
{
padding: 0px 10px 10px 10px;
}
.hidden {
display:none;
}
#background
{
position: fixed;
width: 100%;
height: 100%;
background-position: bottom right;
background-repeat: no-repeat;
}
.container
{
margin-top: 10px;
}
.section
{
position: relative;
width: 930px;
padding: 30px 0px 10px 10px;
border: 1px solid #cccccc;
border-radius: 4px;
}
.section_title
{
position: absolute;
top: 0px;
left: 0px;
padding: 3px 7px 3px 7px;
border-bottom: 1px solid #cccccc;
border-right: 1px solid #cccccc;
border-bottom-right-radius: 4px;
border-top-left-radius: 4px;
color: #989898;
font-size: 12px;
font-weight: bold;
background-color: #f5f5f5;
}
.alert
{
float: left;
padding-bottom: 14px;
margin: 4px 0px 0px 0px;
width: 867px;
}
.btn
{
font-weight: bold;
}
.btn.active, .btn:active
{
background-color: rgb(47, 150, 180);
color: white;
text-shadow: 0px 0px 0px;
}
table {
border-style: solid none solid solid;
border-width: 1px;
border-spacing:0;
margin: 1em;
border-collapse:collapse;
}
th {
padding: 5px 2em 5px 2em;
border-style: solid solid none none;
border-width: 1px;
text-align: left;
font-weight:bold;
vertical-align: middle;
}
td {
padding: 5px 2em 5px 2em;
border-style: solid solid none none;
border-width: 1px;
vertical-align: middle;
height: 16px;
}
select.interface {
width: 5em;
}
</style>
<script type="text/javascript">
last_change="";
$(function() {
2019-08-17 11:39:39 +00:00
ajax({"action":"get-remotes"} );
2019-08-16 15:23:19 +00:00
});
2019-08-17 11:39:39 +00:00
function ajax(action){
2019-08-16 15:23:19 +00:00
$.ajax({
type: 'post',
2019-08-17 20:16:12 +00:00
url: 'ajax',
2019-08-16 15:23:19 +00:00
data: JSON.stringify(action),
error:function(msg){
console.log( 'Error !: (' + msg.responseText + ')' );
},
success:function(data){
if (action["action"] == "get-remotes") {
2019-08-17 11:39:39 +00:00
refresh(data);
2019-08-16 15:23:19 +00:00
}
}
});
}
function vpn_restart(pid) {
if(confirm("are you sure you want to restart this session ?")) {
2019-08-17 11:39:39 +00:00
ajax({action: 'restart', params: {session: pid}});
2019-08-16 15:23:19 +00:00
}
}
function vpn_kill(pid) {
if(confirm("are you sure you want to kill this openvpn client ?")) {
2019-08-17 11:39:39 +00:00
ajax({action: 'kill', params: {session: pid}});
2019-08-16 15:23:19 +00:00
}
}
function server_change(pid) {
2019-08-17 11:39:39 +00:00
ajax({action: 'set-remote', params: {server: $('#server_'+pid).val() , session: pid}});
2019-08-16 15:23:19 +00:00
}
2019-08-16 22:16:57 +00:00
function auth(pid) {
2019-08-17 11:39:39 +00:00
ajax({action: "auth-user-pass", params:{session: pid,
2019-08-16 22:16:57 +00:00
user:$('#auth_'+pid+'>input.user').val(),
password:$('#auth_'+pid+'>input.pass').val()}});
}
2019-08-17 11:39:39 +00:00
function refresh(data) {
setTimeout(function(){ ajax({"action":"get-remotes"} )}, 3000);
2019-08-16 15:23:19 +00:00
if (data["last_change"] == last_change) {
return;
}
last_change = data["last_change"];
$('#result>tbody').remove();
$('#result').append('<tbody></ybody>');
$.each(data, function(index, infos) {
if (!infos) {
return;
} else if (index == "remotes") {
remotes = {};
$.each(infos, function(provider, list) {
remotes[provider]={};
var keys = [];
for (var key in list) {
keys.push(key);
}
keys.sort ();
for (i in keys) {
remotes[provider][keys[i]]=list[keys[i]];
}
});
2019-08-16 15:23:19 +00:00
} else if (index == "sessions") {
$.each(infos, function(pid, infos) {
line = '<tr>';
line +='<td>'+infos['identifier']+'</td>';
line +='<td>'+infos['provider']+'</td>';
if (possible=remotes[infos['provider']]) {
line += '<td><select id="server_'+pid+'" onchange="server_change('+pid+')">'
if (infos['active-vpn']=="") {
line += '<option value="">----------------</option>'
}
$.each(possible, function(name, remote) {
2019-08-16 15:23:19 +00:00
line += '<option value="'+remote+'"';
if(remote == infos['active-vpn']) {
line += ' selected ';
}
line += '>'+name+'</option>';
2019-08-16 15:23:19 +00:00
});
line+='</select></td>'
} else {
line +='<td>'+infos['active-vpn']+'</td>';
}
2019-08-16 22:16:57 +00:00
if(infos['status']=="Need Password") {
line +='<td><form id="auth_'+pid+'" action="#" onsubmit="auth('+pid+') ; return false" >';
line +='<input class="user" placeholder="Enter login" size="8">';
line +='<input type="password" placeholder="Password" size="8" class="pass">';
line +='<input type="submit" value="G0">';
line +='</form></td>';
} else {
2019-08-16 15:23:19 +00:00
line +='<td>'+infos['status']+'</td>';
2019-08-16 22:16:57 +00:00
}
2019-08-16 15:23:19 +00:00
line +='<td><a href="javascript:vpn_restart('+pid+')">Reload</a></td>';
line +='<td><a href="javascript:vpn_kill('+pid+')">Kill</a></td>';
line += '</tr>\n';
$('#result>tbody').append(line);
});
}
});
}
</script>
</head>
<body>
<h1>VPN Sessions</h1>
<table id="result">
<thead>
<tr>
<th>VPN Identifier</th>
<th>Provider</th>
<th>VPN Server</th>
<th>Status</th>
<th colspan="2">&nbsp;</th>
</tr>
</thead>
</table>
</body>
</html>