Advertisement
Alberts00

vpnstatus

Nov 17th, 2013
2,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.33 KB | None | 0 0
  1. <?php
  2. // OpenVPN (php-based) web status script
  3. //
  4. // This script has been released to the public domain by Pablo Hoffman
  5. // on February 28, 2007.
  6. //
  7. // Original location:
  8. // http://pablohoffman.com/software/vpnstatus/vpnstatus.txt
  9.  
  10. // Configuration values --------
  11. $vpn_name = "VPN";
  12. $vpn_host = "type your vps address here or localhost";
  13. $vpn_port = 7550;
  14. // -----------------------------
  15.  
  16. $fp = fsockopen($vpn_host, $vpn_port, $errno, $errstr, 30);
  17. if (!$fp) {
  18.     echo "$errstr ($errno)<br />\n";
  19.     exit;
  20. }
  21.  
  22. fwrite($fp, "status\n\n\n");
  23. sleep(1);
  24. fwrite($fp, "quit\n\n\n");
  25. sleep(1);
  26. $clients = array();
  27. $inclients = $inrouting = false;
  28. while (!feof($fp)) {
  29.     $line = fgets($fp, 128);
  30.     if (substr($line, 0, 13) == "ROUTING TABLE") {
  31.         $inclients = false;
  32.     }
  33.     if ($inclients) {
  34.         $cdata = split(',', $line);
  35.         $clines[$cdata[1]] = array($cdata[2], $cdata[3], $cdata[4]);
  36.     }
  37.     if (substr($line, 0, 11) == "Common Name") {
  38.         $inclients = true;
  39.     }
  40.  
  41.     if (substr($line, 0, 12) == "GLOBAL STATS") {
  42.         $inrouting = false;
  43.     }
  44.     if ($inrouting) {
  45.         $routedata = split(',', $line);
  46.         array_push($clients, array_merge($routedata,
  47. $clines[$routedata[2]]));
  48.     }
  49.     if (substr($line, 0, 15) == "Virtual Address") {
  50.         $inrouting = true;
  51.     }
  52. }
  53.  
  54. $headers = array('VPN Address', 'Name', 'Real Address', 'Last Act',
  55. 'Recv', 'Sent', 'Connected Since');
  56. $tdalign = array('left', 'left', 'left', 'left', 'right', 'right',
  57. 'left');
  58. /* DEBUG
  59. print "<pre>";
  60. print_r($headers);
  61. print_r($clients);
  62. print_r($clines);
  63. print_r($routedata);
  64. print "</pre>";
  65. */
  66. fclose($fp);
  67.  
  68.  
  69.  
  70. ?>
  71. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  72.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  73. <html xmlns="http://www.w3.org/1999/xhtml">
  74. <head>
  75.  
  76. <title><?php echo $vpn_name ?> status</title>
  77.  
  78. <meta http-equiv='refresh' content='300' />
  79.  
  80. <style type="text/css">
  81. body {
  82.     font-family: Verdana, Arial, Helvetica, sans-serif;
  83.     font-size: 14px;
  84.     background-color: #E5EAF0;
  85. }
  86. h1 {
  87.     color: green;
  88.     font-size: 24px;
  89.     text-align: center;
  90.     padding-bottom: 0;
  91.     margin-bottom: 0;
  92. }
  93. p.info {
  94.     text-align: center;
  95.     font-size: 12px;
  96. }
  97. .status0 {
  98.     background: #ebb;
  99. }
  100. .status1 {
  101.     background: lime;
  102. }
  103. table {
  104.     #border: medium solid maroon;
  105.     margin: 0 auto;
  106.     border-collapse: collapse;
  107. }
  108. th {
  109.     background: maroon;
  110.     color: white;
  111. }
  112. tr {
  113.     border-bottom: 1px solid silver;
  114. }
  115. td {
  116.     padding: 0px 10px 0px 10px;
  117. }
  118. </style>
  119.  
  120. </head>
  121.  
  122. <body>
  123.  
  124.  
  125. <table>
  126. <tr>
  127. <?php foreach ($headers as $th) { ?>
  128. <th><?php echo $th?></th>
  129. <?php } ?>
  130. </tr>
  131.  
  132. <?php foreach ($clients as $client) {
  133.     $client[3] = date ('Y-m-d H:i', strtotime($client[3]));
  134.     $client[6] = date ('Y-m-d H:i', strtotime($client[6]));
  135.     $client[4] = number_format($client[4], 0, '', '.');
  136.     $client[5] = number_format($client[5], 0, '', '.');
  137.     $client[2] = preg_replace('/(.*):.*/', '$1', $client[2]);
  138.     $i = 0;
  139. ?>
  140. <tr>
  141. <?php foreach ($client as $td) { ?>
  142. <td align='<?php echo $tdalign[$i++] ?>'><?php echo $td?></td>
  143. <?php } ?>
  144. </tr>
  145. <?php } ?>
  146.  
  147. </table>
  148. <p class='info'>This page gets reloaded every 5 min.<br />Last update:
  149. <b><?php echo date ("Y-m-d H:i:s") ?></b></p>
  150. </body>
  151.  
  152. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement