Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
768fdcc0
Commit
768fdcc0
authored
May 03, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(dashboar, widgets) cleanup openvpn.widget.php, use status_openvpn.php for ajax action
parent
c40b1824
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
128 additions
and
259 deletions
+128
-259
openvpn.widget.php
src/www/widgets/widgets/openvpn.widget.php
+128
-259
No files found.
src/www/widgets/widgets/openvpn.widget.php
View file @
768fdcc0
<?php
/*
Copyright (C) 2014
Deciso B.V.
Copyright (C) 2014-2016
Deciso B.V.
All rights reserved.
Redistribution and use in source and binary forms, with or without
...
...
@@ -26,259 +26,128 @@
POSSIBILITY OF SUCH DAMAGE.
*/
$nocsrf
=
true
;
require_once
(
"guiconfig.inc"
);
require_once
(
"openvpn.inc"
);
/* Handle AJAX */
if
(
$_GET
[
'action'
])
{
if
(
$_GET
[
'action'
]
==
"kill"
)
{
$port
=
$_GET
[
'port'
];
$remipp
=
$_GET
[
'remipp'
];
if
(
!
empty
(
$port
)
and
!
empty
(
$remipp
))
{
$retval
=
kill_client
(
$port
,
$remipp
);
echo
htmlentities
(
"|
{
$port
}
|
{
$remipp
}
|
{
$retval
}
|"
);
}
else
{
echo
gettext
(
"invalid input"
);
}
exit
;
}
}
function
kill_client
(
$port
,
$remipp
)
{
//$tcpsrv = "tcp://127.0.0.1:{$port}";
$tcpsrv
=
"unix:///var/etc/openvpn/
{
$port
}
.sock"
;
$errval
;
$errstr
;
/* open a tcp connection to the management port of each server */
$fp
=
@
stream_socket_client
(
$tcpsrv
,
$errval
,
$errstr
,
1
);
$killed
=
-
1
;
if
(
$fp
)
{
stream_set_timeout
(
$fp
,
1
);
fputs
(
$fp
,
"kill
{
$remipp
}
\n
"
);
while
(
!
feof
(
$fp
))
{
$line
=
fgets
(
$fp
,
1024
);
$info
=
stream_get_meta_data
(
$fp
);
if
(
$info
[
'timed_out'
])
{
break
;
}
/* parse header list line */
if
(
strpos
(
$line
,
"INFO:"
)
!==
false
)
{
continue
;
}
if
(
strpos
(
$line
,
"SUCCESS"
)
!==
false
)
{
$killed
=
0
;
}
break
;
}
fclose
(
$fp
);
}
return
$killed
;
}
$servers
=
openvpn_get_active_servers
();
$sk_servers
=
openvpn_get_active_servers
(
"p2p"
);
$clients
=
openvpn_get_active_clients
();
?>
<br
/>
<script
type=
"text/javascript"
>
function
killClient
(
mport
,
remipp
)
{
var
busy
=
function
(
index
,
icon
)
{
jQuery
(
icon
).
bind
(
"
onclick
"
,
""
);
jQuery
(
icon
).
attr
(
'
src
'
,
jQuery
(
icon
).
attr
(
'
src
'
).
replace
(
"
\
.gif
"
,
"
_d.gif
"
));
jQuery
(
icon
).
css
(
"
cursor
"
,
"
wait
"
);
}
jQuery
(
'
span[name="i:
'
+
mport
+
"
:
"
+
remipp
+
'
"]
'
).
each
(
busy
);
jQuery
.
ajax
(
"
<?=
$_SERVER
[
'SCRIPT_NAME'
];
?>
"
+
"
?action=kill&port=
"
+
mport
+
"
&remipp=
"
+
remipp
,
{
type
:
"
get
"
,
complete
:
killComplete
}
);
}
function
killComplete
(
req
)
{
var
values
=
req
.
responseText
.
split
(
"
|
"
);
if
(
values
[
3
]
!=
"
0
"
)
{
alert
(
'
<?=
gettext
(
"An error occurred."
);
?>
'
+
'
(
'
+
values
[
3
]
+
'
)
'
);
return
;
}
jQuery
(
'
tr[name="r:
'
+
values
[
1
]
+
"
:
"
+
values
[
2
]
+
'
"]
'
).
each
(
function
(
index
,
row
)
{
jQuery
(
row
).
fadeOut
(
1000
);
}
);
}
$
(
document
).
ready
(
function
()
{
// link kill buttons
$
(
"
.act_kill_client
"
).
click
(
function
(
event
){
event
.
preventDefault
();
var
port
=
$
(
this
).
data
(
"
client-port
"
);
var
ip
=
$
(
this
).
data
(
"
client-ip
"
);
$
.
post
(
'
/status_openvpn.php
'
,
{
action
:
'
kill
'
,
port
:
port
,
remipp
:
ip
},
function
(
data
)
{
location
.
reload
();
});
});
});
</script>
<?php
foreach
(
$servers
as
$server
)
:
?>
<table
class=
"table table-striped"
style=
"padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px"
width=
"100%"
border=
"0"
cellpadding=
"0"
cellspacing=
"0"
>
<?php
foreach
(
$servers
as
$server
)
:
?>
<
table
class
="
table
table
-
striped
table
-
condensed
">
<thead
>
<tr>
<td
colspan=
"6"
class=
"listtopic
"
>
<?=
$server
[
'name'
];
?>
Client connections
</td
>
<th colspan="
3
">
<?=
$server['name']
;?> <?=gettext("
Client
connections
");?>
</th
>
</tr>
<tr>
<td>
<table
style=
"padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px"
class=
"tabcont sortable"
width=
"100%"
border=
"0"
cellpadding=
"0"
cellspacing=
"0"
sortableMultirow=
"2"
>
<tr>
<td
class=
"listhdrr"
>
Name/Time
</td>
<td
class=
"listhdrr"
>
Real/Virtual IP
</td>
</tr>
<?php
$rowIndex
=
0
;
foreach
(
$server
[
'conns'
]
as
$conn
)
:
$evenRowClass
=
$rowIndex
%
2
?
" listMReven"
:
" listMRodd"
;
$rowIndex
++
;
?>
<tr
name=
'
<?php
echo
"r:
{
$server
[
'mgmt'
]
}
:
{
$conn
[
'remote_host'
]
}
"
;
?>
'
class=
"
<?=
$evenRowClass
?>
"
>
<td
class=
"listMRlr"
>
<?=
$conn
[
'common_name'
];
?>
</td>
<td
class=
"listMRr"
>
<?=
$conn
[
'remote_host'
];
?>
</td>
<td
class=
'listMR'
rowspan=
"2"
>
<span
class=
"glyphicon glyphicon-remove"
onclick=
"killClient('
<?php
echo
$server
[
'mgmt'
];
?>
', '
<?php
echo
$conn
[
'remote_host'
];
?>
');"
style=
'cursor:pointer;'
name=
'
<?php
echo
"i:
{
$server
[
'mgmt'
]
}
:
{
$conn
[
'remote_host'
]
}
"
;
?>
'
title=
'Kill client connection from
<?php
echo
$conn
[
'remote_host'
];
?>
'
alt=
''
></span>
</td>
</tr>
<tr
name=
'
<?php
echo
"r:
{
$server
[
'mgmt'
]
}
:
{
$conn
[
'remote_host'
]
}
"
;
?>
'
class=
"
<?=
$evenRowClass
?>
"
>
<td
class=
"listMRlr"
>
<?=
$conn
[
'connect_time'
];
?>
</td>
<td
class=
"listMRr"
>
<?=
$conn
[
'virtual_addr'
];
?>
</td>
<th><?=gettext("
Name
/
Time
");?></th>
<th><?=gettext("
Real
/
Virtual
IP
");?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$server['conns']
= array();
$server['conns'][]
= array('remote_host' => 'xxx1', 'common_name' => 'cn1');
$server['conns'][]
= array('remote_host' => 'xxx2', 'common_name' => 'cn2');
$server['conns'][]
= array('remote_host' => 'xxx3', 'common_name' => 'cn3');
<?php
endforeach
;
?>
<tfoot>
foreach (
$server['conns']
as
$conn
) :?>
<tr>
<td
colspan=
"6"
class=
"list"
height=
"12"
></td>
</tr>
</tfoot>
</table>
<td><?=
$conn['common_name'];?><br/><?=$conn['connect_time']
;?></td>
<td><?=
$conn['remote_host'];?><br/><?=$conn['virtual_addr']
;?></td>
<td>
<span class="
glyphicon
glyphicon
-
remove
act_kill_client
" data-client-port="
<?=
$server
[
'mgmt'
];
?>
"
data-client-ip="
<?=
$conn
[
'remote_host'
];
?>
"
style='cursor:pointer;'
title='Kill client connection from
<?=
$conn
[
'remote_host'
];
?>
'>
</span>
</td>
</tr>
</table>
<?php
endforeach
;
?>
<?php
if
(
!
empty
(
$sk_servers
))
{
?>
<table
class=
"table table-striped"
style=
"padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px"
width=
"100%"
border=
"0"
cellpadding=
"0"
cellspacing=
"0"
>
endforeach
;
?>
</tbody>
</table>
<br/>
<?php
endforeach
;
?>
<?php
if
(
!
empty
(
$sk_servers
))
:?>
<
table
class
="
table
table
-
striped
table
-
condensed
">
<thead>
<tr>
<td
colspan=
"6"
class=
"listtopic"
>
<?=
gettext
(
'Peer to Peer Server Instance Statistics'
)
?>
</td>
<th colspan="
3
"><?= gettext('Peer to Peer Server Instance Statistics') ?></th>
</tr>
<tr>
<table
style=
"padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px"
class=
"tabcont sortable"
width=
"100%"
border=
"0"
cellpadding=
"0"
cellspacing=
"0"
>
<tr>
<td
class=
"listhdrr"
>
<?=
gettext
(
'Name/Time'
)
?>
</td>
<td
class=
"listhdrr"
>
<?=
gettext
(
'Remote/Virtual IP'
)
?>
</td>
<th><?= gettext('Name/Time') ?></th>
<th><?= gettext('Remote/Virtual IP') ?></th>
<th></th>
</tr>
<?php
foreach
(
$sk_servers
as
$sk_server
)
:
?>
<tr
name=
'
<?php
echo
"r:
{
$sk_server
[
'port'
]
}
:
{
$sk_server
[
'remote_host'
]
}
"
;
?>
'
>
<td
class=
"listlr"
>
<?=
$sk_server
[
'name'
];
?>
</td>
<td
class=
"listr"
>
<?=
$sk_server
[
'remote_host'
];
?>
</td>
<td
rowspan=
"2"
align=
"center"
>
<?php
if
(
$sk_server
[
'status'
]
==
"up"
)
{
/* tunnel is up */
$iconfn
=
"text-success"
;
}
else
{
/* tunnel is down */
$iconfn
=
"text-danger"
;
}
echo
"<span class='glyphicon glyphicon-transfer "
.
$iconfn
.
"'></span>"
;
?>
</td>
</tr>
<tr
name=
'
<?php
echo
"r:
{
$sk_server
[
'port'
]
}
:
{
$sk_server
[
'remote_host'
]
}
"
;
?>
'
>
<td
class=
"listlr"
>
<?=
$sk_server
[
'connect_time'
];
?>
</td>
<td
class=
"listr"
>
<?=
$sk_server
[
'virtual_addr'
];
?>
</thead>
<tbody>
<?php
foreach (
$sk_servers
as
$sk_server
) :?>
<tr>
<td><?=
$sk_server['name'];?><br/><?=$sk_server['connect_time']
;?></td>
<td><?=
$sk_server['remote_host'];?><br/><?=$sk_server['virtual_addr']
;?></td>
<td>
<span class='glyphicon glyphicon-transfer <?=
$sk_server['status']
== "
up
" ? "
text
-
success
" : "
text
-
danger
";?>'></span>
</td>
</tr>
<?php
endforeach
;
?>
endforeach; ?>
</tbody>
</table>
</tr>
</table>
<br/>
<?php
}
?>
<?php
if
(
!
empty
(
$clients
))
{
?>
<table
class=
"table table-striped"
style=
"padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px"
width=
"100%"
border=
"0"
cellpadding=
"0"
cellspacing=
"0"
>
endif; ?>
<?php
if (!empty(
$clients
)) {?>
<table class="
table
table
-
striped
table
-
condensed
">
<thead>
<tr>
<td
colspan=
"6"
class=
"listtopic"
>
<?=
gettext
(
'Client Instance Statistics'
)
?>
</td>
<th colspan="
3
"><?= gettext('Client Instance Statistics') ?></th>
</tr>
<tr>
<table
class=
"table table-striped"
style=
"padding-top:0px; padding-bottom:0px; padding-left:0px; padding-right:0px"
class=
"tabcont sortable"
width=
"100%"
border=
"0"
cellpadding=
"0"
cellspacing=
"0"
>
<tr>
<td
class=
"listhdrr"
>
<?=
gettext
(
'Name/Time'
)
?>
</td>
<td
class=
"listhdrr"
>
<?=
gettext
(
'Remote/Virtual IP'
)
?>
</td>
<th><?= gettext('Name/Time') ?></th>
<th><?= gettext('Remote/Virtual IP') ?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach
(
$clients
as
$client
)
:
?>
<tr
name=
'
<?php
echo
"r:
{
$client
[
'port'
]
}
:
{
$client
[
'remote_host'
]
}
"
;
?>
'
>
<td
class=
"listlr"
>
<?=
$client
[
'name'
];
?>
</td>
<td
class=
"listr"
>
<?=
$client
[
'remote_host'
];
?>
</td>
<td
rowspan=
"2"
align=
"center"
>
<?php
if
(
$client
[
'status'
]
==
"up"
)
{
/* tunnel is up */
$iconfn
=
"text-success"
;
}
else
{
/* tunnel is down */
$iconfn
=
"text-danger"
;
}
echo
"<span class='glyphicon glyphicon-transfer "
.
$iconfn
.
"'></span>"
;
?>
</td>
</tr>
<tr
name=
'
<?php
echo
"r:
{
$client
[
'port'
]
}
:
{
$client
[
'remote_host'
]
}
"
;
?>
'
>
<td
class=
"listlr"
>
<?=
$client
[
'connect_time'
];
?>
</td>
<td
class=
"listr"
>
<?=
$client
[
'virtual_addr'
];
?>
<?php
foreach (
$clients
as
$client
) :?>
<tr>
<td><?=
$client['name'];?><br/><?=$client['connect_time']
;?></td>
<td><?=
$client['remote_host'];?><br/><?=$client['virtual_addr']
;?></td>
<td>
<span class='glyphicon glyphicon-transfer <?=
$client['status']
== "
up
" ? "
text
-
success
" : "
text
-
danger
" ;?>'></span>
</td>
</tr>
<?php
endforeach
;
?>
endforeach; ?>
</tbody>
</table>
</tr>
</table>
<?php
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment