Revision 53663f57
Added by Jim Pingle about 15 years ago
etc/inc/openvpn.inc | ||
---|---|---|
704 | 704 |
|
705 | 705 |
} |
706 | 706 |
|
707 |
function openvpn_get_active_servers() { |
|
708 |
$servers = array(); |
|
709 |
global $config; |
|
710 |
if (is_array($config['openvpn']['openvpn-server'])) { |
|
711 |
foreach ($config['openvpn']['openvpn-server'] as & $settings) { |
|
712 |
|
|
713 |
$prot = $settings['protocol']; |
|
714 |
$port = $settings['local_port']; |
|
715 |
|
|
716 |
$server = array(); |
|
717 |
$server['port'] = $settings['local_port']; |
|
718 |
if ($settings['description']) |
|
719 |
$server['name'] = "{$settings['description']} {$prot}:{$port}"; |
|
720 |
else |
|
721 |
$server['name'] = "Server {$prot}:{$port}"; |
|
722 |
$server['conns'] = array(); |
|
723 |
|
|
724 |
$tcpsrv = "tcp://127.0.0.1:{$port}"; |
|
725 |
$errval; |
|
726 |
$errstr; |
|
727 |
|
|
728 |
/* open a tcp connection to the management port of each server */ |
|
729 |
$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1); |
|
730 |
if ($fp) { |
|
731 |
|
|
732 |
/* send our status request */ |
|
733 |
fputs($fp, "status 2\n"); |
|
734 |
|
|
735 |
/* recv all response lines */ |
|
736 |
while (!feof($fp)) { |
|
737 |
|
|
738 |
/* read the next line */ |
|
739 |
$line = fgets($fp, 1024); |
|
740 |
|
|
741 |
/* parse header list line */ |
|
742 |
if (strstr($line, "HEADER")) |
|
743 |
continue; |
|
744 |
|
|
745 |
/* parse end of output line */ |
|
746 |
if (strstr($line, "END")) |
|
747 |
break; |
|
748 |
|
|
749 |
/* parse client list line */ |
|
750 |
if (strstr($line, "CLIENT_LIST")) { |
|
751 |
$list = explode(",", $line); |
|
752 |
$conn = array(); |
|
753 |
$conn['common_name'] = $list[1]; |
|
754 |
$conn['remote_host'] = $list[2]; |
|
755 |
$conn['virtual_addr'] = $list[3]; |
|
756 |
$conn['bytes_recv'] = $list[4]; |
|
757 |
$conn['bytes_sent'] = $list[5]; |
|
758 |
$conn['connect_time'] = $list[6]; |
|
759 |
$server['conns'][] = $conn; |
|
760 |
} |
|
761 |
} |
|
762 |
|
|
763 |
/* cleanup */ |
|
764 |
fclose($fp); |
|
765 |
} else { |
|
766 |
$conn = array(); |
|
767 |
$conn['common_name'] = "[error]"; |
|
768 |
$conn['remote_host'] = "Management Daemon Unreachable"; |
|
769 |
$conn['virtual_addr'] = ""; |
|
770 |
$conn['bytes_recv'] = 0; |
|
771 |
$conn['bytes_sent'] = 0; |
|
772 |
$conn['connect_time'] = 0; |
|
773 |
$server['conns'][] = $conn; |
|
774 |
} |
|
775 |
|
|
776 |
$servers[] = $server; |
|
777 |
} |
|
778 |
} |
|
779 |
return $servers; |
|
780 |
} |
|
781 |
|
|
782 |
function openvpn_get_active_clients() { |
|
783 |
$clients = array(); |
|
784 |
global $config; |
|
785 |
if (is_array($config['openvpn']['openvpn-client'])) { |
|
786 |
foreach ($config['openvpn']['openvpn-client'] as & $settings) { |
|
787 |
|
|
788 |
$prot = $settings['protocol']; |
|
789 |
$port = $settings['local_port']; |
|
790 |
|
|
791 |
$client = array(); |
|
792 |
$client['port'] = $settings['local_port']; |
|
793 |
if ($settings['description']) |
|
794 |
$client['name'] = "{$settings['description']} {$prot}:{$port}"; |
|
795 |
else |
|
796 |
$client['name'] = "Client {$prot}:{$port}"; |
|
797 |
|
|
798 |
$tcpcli = "tcp://127.0.0.1:{$port}"; |
|
799 |
$errval; |
|
800 |
$errstr; |
|
801 |
|
|
802 |
$client['status']="down"; |
|
803 |
|
|
804 |
/* open a tcp connection to the management port of each cli */ |
|
805 |
$fp = @stream_socket_client($tcpcli, $errval, $errstr, 1); |
|
806 |
if ($fp) { |
|
807 |
|
|
808 |
/* send our status request */ |
|
809 |
fputs($fp, "state 1\n"); |
|
810 |
|
|
811 |
/* recv all response lines */ |
|
812 |
while (!feof($fp)) { |
|
813 |
/* read the next line */ |
|
814 |
$line = fgets($fp, 1024); |
|
815 |
|
|
816 |
/* Get the client state */ |
|
817 |
if (strstr($line,"CONNECTED")) { |
|
818 |
$client['status']="up"; |
|
819 |
$list = explode(",", $line); |
|
820 |
|
|
821 |
$client['connect_time'] = date("D M j G:i:s Y", $list[0]); |
|
822 |
$client['virtual_addr'] = $list[3]; |
|
823 |
$client['remote_host'] = $list[4]; |
|
824 |
} |
|
825 |
/* parse end of output line */ |
|
826 |
if (strstr($line, "END")) |
|
827 |
break; |
|
828 |
} |
|
829 |
|
|
830 |
/* If up, get read/write stats */ |
|
831 |
if (strcmp($client['status'], "up") == 0) { |
|
832 |
fputs($fp, "status 2\n"); |
|
833 |
/* recv all response lines */ |
|
834 |
while (!feof($fp)) { |
|
835 |
/* read the next line */ |
|
836 |
$line = fgets($fp, 1024); |
|
837 |
|
|
838 |
if (strstr($line,"TCP/UDP read bytes")) { |
|
839 |
$list = explode(",", $line); |
|
840 |
$client['bytes_recv'] = $list[1]; |
|
841 |
} |
|
842 |
|
|
843 |
if (strstr($line,"TCP/UDP write bytes")) { |
|
844 |
$list = explode(",", $line); |
|
845 |
$client['bytes_sent'] = $list[1]; |
|
846 |
} |
|
847 |
|
|
848 |
/* parse end of output line */ |
|
849 |
if (strstr($line, "END")) |
|
850 |
break; |
|
851 |
} |
|
852 |
} |
|
853 |
|
|
854 |
fclose($fp); |
|
855 |
|
|
856 |
} else { |
|
857 |
$DisplayNote=true; |
|
858 |
$client['remote_host'] = "No Management Daemon"; |
|
859 |
$client['virtual_addr'] = "See Note Below"; |
|
860 |
$client['bytes_recv'] = 0; |
|
861 |
$client['bytes_sent'] = 0; |
|
862 |
$client['connect_time'] = 0; |
|
863 |
} |
|
864 |
|
|
865 |
$clients[] = $client; |
|
866 |
} |
|
867 |
} |
|
868 |
return $clients; |
|
869 |
} |
|
707 | 870 |
?> |
usr/local/www/status_openvpn.php | ||
---|---|---|
45 | 45 |
|
46 | 46 |
$pgtitle = array("Status", "OpenVPN"); |
47 | 47 |
require("guiconfig.inc"); |
48 |
require_once("vpn.inc"); |
|
48 |
require_once("openvpn.inc");
|
|
49 | 49 |
|
50 | 50 |
/* Handle AJAX */ |
51 | 51 |
if($_GET['action']) { |
... | ... | |
88 | 88 |
return $killed; |
89 | 89 |
} |
90 | 90 |
|
91 |
$servers = array(); |
|
92 |
$clients = array(); |
|
93 |
|
|
94 |
if (is_array($config['openvpn']['openvpn-server'])) { |
|
95 |
foreach ($config['openvpn']['openvpn-server'] as & $settings) { |
|
96 |
|
|
97 |
$prot = $settings['protocol']; |
|
98 |
$port = $settings['local_port']; |
|
99 |
|
|
100 |
$server = array(); |
|
101 |
$server['port'] = $settings['local_port']; |
|
102 |
if ($settings['description']) |
|
103 |
$server['name'] = "{$settings['description']} {$prot}:{$port}"; |
|
104 |
else |
|
105 |
$server['name'] = "Server {$prot}:{$port}"; |
|
106 |
$server['conns'] = array(); |
|
107 |
|
|
108 |
$tcpsrv = "tcp://127.0.0.1:{$port}"; |
|
109 |
$errval; |
|
110 |
$errstr; |
|
111 |
|
|
112 |
/* open a tcp connection to the management port of each server */ |
|
113 |
$fp = @stream_socket_client($tcpsrv, $errval, $errstr, 1); |
|
114 |
if ($fp) { |
|
115 |
|
|
116 |
/* send our status request */ |
|
117 |
fputs($fp, "status 2\n"); |
|
118 |
|
|
119 |
/* recv all response lines */ |
|
120 |
while (!feof($fp)) { |
|
121 |
|
|
122 |
/* read the next line */ |
|
123 |
$line = fgets($fp, 1024); |
|
124 |
|
|
125 |
/* parse header list line */ |
|
126 |
if (strstr($line, "HEADER")) |
|
127 |
continue; |
|
128 |
|
|
129 |
/* parse end of output line */ |
|
130 |
if (strstr($line, "END")) |
|
131 |
break; |
|
132 |
|
|
133 |
/* parse client list line */ |
|
134 |
if (strstr($line, "CLIENT_LIST")) { |
|
135 |
$list = explode(",", $line); |
|
136 |
$conn = array(); |
|
137 |
$conn['common_name'] = $list[1]; |
|
138 |
$conn['remote_host'] = $list[2]; |
|
139 |
$conn['virtual_addr'] = $list[3]; |
|
140 |
$conn['bytes_recv'] = $list[4]; |
|
141 |
$conn['bytes_sent'] = $list[5]; |
|
142 |
$conn['connect_time'] = $list[6]; |
|
143 |
$server['conns'][] = $conn; |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
/* cleanup */ |
|
148 |
fclose($fp); |
|
149 |
} else { |
|
150 |
$conn = array(); |
|
151 |
$conn['common_name'] = "[error]"; |
|
152 |
$conn['remote_host'] = "Management Daemon Unreachable"; |
|
153 |
$conn['virtual_addr'] = ""; |
|
154 |
$conn['bytes_recv'] = 0; |
|
155 |
$conn['bytes_sent'] = 0; |
|
156 |
$conn['connect_time'] = 0; |
|
157 |
$server['conns'][] = $conn; |
|
158 |
} |
|
159 |
|
|
160 |
$servers[] = $server; |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
|
|
165 |
if (is_array($config['openvpn']['openvpn-client'])) { |
|
166 |
foreach ($config['openvpn']['openvpn-client'] as & $settings) { |
|
167 |
|
|
168 |
$prot = $settings['protocol']; |
|
169 |
$port = $settings['local_port']; |
|
170 |
|
|
171 |
$client = array(); |
|
172 |
$client['port'] = $settings['local_port']; |
|
173 |
if ($settings['description']) |
|
174 |
$client['name'] = "{$settings['description']} {$prot}:{$port}"; |
|
175 |
else |
|
176 |
$client['name'] = "Client {$prot}:{$port}"; |
|
177 |
|
|
178 |
$tcpcli = "tcp://127.0.0.1:{$port}"; |
|
179 |
$errval; |
|
180 |
$errstr; |
|
181 |
|
|
182 |
$client['status']="down"; |
|
183 |
|
|
184 |
/* open a tcp connection to the management port of each cli */ |
|
185 |
$fp = @stream_socket_client($tcpcli, $errval, $errstr, 1); |
|
186 |
if ($fp) { |
|
91 |
$servers = openvpn_get_active_servers(); |
|
92 |
$clients = openvpn_get_active_clients(); |
|
187 | 93 |
|
188 |
/* send our status request */ |
|
189 |
fputs($fp, "state 1\n"); |
|
190 |
|
|
191 |
/* recv all response lines */ |
|
192 |
while (!feof($fp)) { |
|
193 |
/* read the next line */ |
|
194 |
$line = fgets($fp, 1024); |
|
195 |
|
|
196 |
/* Get the client state */ |
|
197 |
if (strstr($line,"CONNECTED")) { |
|
198 |
$client['status']="up"; |
|
199 |
$list = explode(",", $line); |
|
200 |
|
|
201 |
$client['connect_time'] = date("D M j G:i:s Y", $list[0]); |
|
202 |
$client['virtual_addr'] = $list[3]; |
|
203 |
$client['remote_host'] = $list[4]; |
|
204 |
} |
|
205 |
/* parse end of output line */ |
|
206 |
if (strstr($line, "END")) |
|
207 |
break; |
|
208 |
} |
|
209 |
|
|
210 |
/* If up, get read/write stats */ |
|
211 |
if (strcmp($client['status'], "up") == 0) { |
|
212 |
fputs($fp, "status 2\n"); |
|
213 |
/* recv all response lines */ |
|
214 |
while (!feof($fp)) { |
|
215 |
/* read the next line */ |
|
216 |
$line = fgets($fp, 1024); |
|
217 |
|
|
218 |
if (strstr($line,"TCP/UDP read bytes")) { |
|
219 |
$list = explode(",", $line); |
|
220 |
$client['bytes_recv'] = $list[1]; |
|
221 |
} |
|
222 |
|
|
223 |
if (strstr($line,"TCP/UDP write bytes")) { |
|
224 |
$list = explode(",", $line); |
|
225 |
$client['bytes_sent'] = $list[1]; |
|
226 |
} |
|
227 |
|
|
228 |
/* parse end of output line */ |
|
229 |
if (strstr($line, "END")) |
|
230 |
break; |
|
231 |
} |
|
232 |
} |
|
233 |
|
|
234 |
fclose($fp); |
|
235 |
|
|
236 |
} else { |
|
237 |
$DisplayNote=true; |
|
238 |
$client['remote_host'] = "No Management Daemon"; |
|
239 |
$client['virtual_addr'] = "See Note Below"; |
|
240 |
$client['bytes_recv'] = 0; |
|
241 |
$client['bytes_sent'] = 0; |
|
242 |
$client['connect_time'] = 0; |
|
243 |
} |
|
244 |
|
|
245 |
$clients[] = $client; |
|
246 |
} |
|
247 |
} |
|
248 | 94 |
include("head.inc"); ?> |
249 | 95 |
|
250 | 96 |
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>"> |
Also available in: Unified diff
Move these functions to a more central location. Part of ticket #496