VPN-Management-GUI 2.0.3 porting start

This commit is contained in:
2012-07-16 19:30:19 +00:00
commit d3b0130655
545 changed files with 19128 additions and 0 deletions

View File

@@ -0,0 +1,296 @@
<?php
if (!defined ("LOCAL_SECURITY_KEY"))
die ();
// ----------------------------------------------
function check_authorize ()
{
if (!isset ($_SERVER['PHP_AUTH_USER']))
{ authenticate (); }
else
{
$_SESSION['logged'] = true;
$_SESSION['username'] = $_SERVER['PHP_AUTH_USER'];
$_SESSION['password'] = $_SERVER['PHP_AUTH_PW'];
}
}
// ----------------------------------------------
function authenticate ()
{
global $config;
header('WWW-Authenticate: Basic realm="'. $config['AUTH_REALM'] .'"');
header('HTTP/1.0 401 Unauthorized');
echo '<h2>You need the valid User Name to access the '. $config['AUTH_REALM'] .' !</h2>';
exit;
}
// ----------------------------------------------
function session_defaults ()
{
$_SESSION['logged'] = FALSE;
$_SESSION['username'] = '';
$_SESSION['password'] = '';
$_SESSION['cookie'] = 0;
$_SESSION['remember'] = FALSE;
}
// ----------------------------------------------
function load_plugins ()
{
global $config;
if (isset ($config['Plugins']))
{
foreach ($config['Plugins'] as $PluginName => $PluginData)
{
// Check if the config.inc for a plugin exists
if (file_exists ('plugins/'. $PluginData['Folder'] .'/config.inc'))
{
include ('plugins/'. $PluginData['Folder'] .'/config.inc');
// Check if claimed inc files do exist
if (isset ($config['Plugins'][$PluginName]['Action']['Include']) &&
!file_exists ('plugins/'. $PluginData['Folder'] .'/'.
$config['Plugins'][$PluginName]['Action']['Include']))
$config['Plugins'][$PluginName]['Action']['Include'] = NULL;
if (isset ($config['Plugins'][$PluginName]['Left']['Menu']) &&
!file_exists ('plugins/'. $PluginData['Folder'] .'/'.
$config['Plugins'][$PluginName]['Left']['Menu']))
$config['Plugins'][$PluginName]['Left']['Menu'] = NULL;
if (isset ($config['Plugins'][$PluginName]['Left']['Status']) &&
!file_exists ('plugins/'. $PluginData['Folder'] .'/'.
$config['Plugins'][$PluginName]['Left']['Status']))
$config['Plugins'][$PluginName]['Left']['Status'] = NULL;
}
}
}
}
// ----------------------------------------------
function seconds_string ($seconds, $periods = null)
{
$Wanted = '';
// Define time periods
if (!is_array ($periods))
{
$periods = array (
'years' => 31556926,
'months' => 2629743,
'weeks' => 604800,
'days' => 86400,
'hours' => 3600,
'minutes' => 60,
'seconds' => 1
);
}
// Wanted
if (empty ($seconds))
{ $Wanted = ''; }
else
{
// Loop
$seconds = (int) $seconds;
foreach ($periods as $period => $value)
{
$count = floor ($seconds / $value);
if ($count == 0)
continue;
elseif ($count == 1)
$Wanted .= ($count . ' ' . substr ($period, 0, strlen ($period) - 1) . ' ');
else
$Wanted .= ($count . ' ' . $period . ' ');
$seconds = $seconds % $value;
}
}
return rtrim ($Wanted);
}
// ----------------------------------------------
function chomp (&$string)
{
if (is_array ($string))
{
foreach ($string as $i => $val)
{ $endchar = chomp ($string[$i]); }
}
else
{
$endchar = substr ("$string", strlen("$string") - 1, 1);
if ($endchar == "\n")
{ $string = substr ("$string", 0, -1); }
}
return $endchar;
}
// ----------------------------------------------
function str_strip_spaces ($aline)
{
while (strpos ($aline, "\t") != FALSE) $aline = str_replace ("\t", ' ', $aline);
while (strpos ($aline, ' ') != FALSE) $aline = str_replace (' ', ' ', $aline);
return $aline;
}
// ----------------------------------------------
// Returns $afile only if it is the full name, or prefixed by $apath
function str_file_fullname ($apath, $afile)
{
if (substr ($afile, 0, 1) != '/')
$afile = ($apath . $afile);
return $afile;
}
// ----------------------------------------------
// Returns $afile only if it is the full name, or prefixed by $apath
function str_openssldata_to_string ($adata)
{
$Return = '';
$amonth = array ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
if (substr ($adata, -1, 1) == 'Z')
{
$Return = sprintf ("%s %d %s%02d, %02d:%02d:%02d",
$amonth [substr ($adata, 2, 2) - 1],
substr ($adata, 4, 2),
(substr ($adata, 0, 2) > 50 ? '19' : '20'),
substr ($adata, 0, 2),
substr ($adata, 6, 2),
substr ($adata, 8, 2),
substr ($adata, 10, 2));
}
return $Return;
}
// ----------------------------------------------
function str_get_sometag ($aline, $sometag)
{
if (eregi ($sometag, $aline, $anarray))
return $anarray[1];
else
return '';
}
// ----------------------------------------------
// Writes content into file
// Optionally sames old file into backup file.
// The Backup File has to reside on the same partition!
function writefile ($afile, $adata, $abackup = NULL)
{
// Move the old file into Backup one
if ($abackup != NULL)
{
if (file_exists ($afile))
{
if (file_exists ($abackup))
if (!unlink ($abackup))
exit;
if (!rename ($afile, $abackup))
exit;
}
}
$fp = fopen ($afile, "w", 0);
if (!$fp)
exit;
fputs ($fp, $adata);
fclose ($fp);
}
// ----------------------------------------------
// Guess the full file name
function if_file_exists (&$sFileName, $bFix = FALSE)
{
global $config;
if (strpos ($sFileName, '/') == FALSE)
{
$sLongFileName = $config['openvpn']['folder'] . $sFileName;
if (file_exists ($sLongFileName) && $bFix)
$sFileName = $sLongFileName;
}
return file_exists ($sFileName);
}
// ----------------------------------------------
function zlib_check_functions ()
{
$Result = '';
$ZLibs = array
(
'gzcompress'
);
foreach ($ZLibs as $Function)
{
$Result .= $Function . '<font color="black">:</font> ' . (function_exists ($Function) ?
'<font color="black">OK</font>' :
'<font color="red">DOES NOT EXIST</font>') . '<br>';
}
return $Result;
}
// ----------------------------------------------
function html_dump ($aname, $athing)
{
echo '<pre><b><font color="darkgreen">'. $aname .'</font></b>: ';
print_r ($athing);
echo "</pre><br>\n";
}
// ----------------------------------------------
function html_error ($amessage, $ifexit = true)
{
global $config;
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->assign ('Company_Name', $config['Company_Name']);
$smarty->assign ('title', 'OpenVPN Web GUI : error');
$smarty->assign ('action', 'ERROR');
$smarty->assign ('message', $amessage);
$smarty->display ('action-error.tpl');
if ($ifexit)
exit;
}
// ----------------------------------------------
function html_postredir ($url)
{
header ('HTTP/1.1 303 REDIRECT');
header ('Location: '. $url);
#header ('Status: 303'); // if 1st header generates 500, then commend it out and use this one as 2nd
}
// ----------------------------------------------
// ----------------------------------------------
function html_download ($sFile, $sName)
{
header ('Content-type: application/octet-stream');
header ('Content-Disposition: attachment; filename="'. $sName . '"');
readfile ($sFile);
}
// ----------------------------------------------
function html_download_data ($sData, $sName)
{
header ('Content-type: application/octet-stream');
header ('Content-Disposition: attachment; filename="'. $sName . '"');
echo $sData;
}
?>

View File

@@ -0,0 +1,380 @@
<?php
//if (!defined ("LOCAL_SECURITY_KEY"))
// die ();
// ----------------------------------------------
function openssl_check_functions ()
{
$Result = '';
$OpenSSLs = array
(
'openssl_csr_new',
'openssl_csr_sign',
'openssl_csr_export_to_file',
'openssl_pkey_new',
'openssl_pkey_get_private',
'openssl_pkey_export_to_file',
'openssl_x509_export_to_file'
);
foreach ($OpenSSLs as $Function)
{
$Result .= $Function . '<font color="black">:</font> ' . (function_exists ($Function) ?
'<font color="black">OK</font>' :
'<font color="red">DOES NOT EXIST</font>') . '<br>';
}
return $Result;
}
// ----------------------------------------------
function openssl_load_database ($afile = '')
{
global $config;
global $openssl;
$afile = ($afile == '' ? $config['openssl']['database'] : $afile);
$lines = file ($afile);
if (!is_array ($lines))
exit;
foreach ($lines as $line_num => $line)
{
chomp ($line);
$linetokens = explode ("\t", $line);
// Ensure that all the fields are set
if (count ($linetokens) == 6)
{
// Decode the openssl's database. See apps/apps.h
$openssl['Database'][] = array ('Status' => $linetokens[0],
'ExpDate' => $linetokens[1],
'RevDate' => $linetokens[2],
'Serial' => $linetokens[3],
'File' => $linetokens[4],
'Name' => $linetokens[5],
'Country' => openssl_get_country ($linetokens[5]),
'State' => openssl_get_state ($linetokens[5]),
'City' => openssl_get_city ($linetokens[5]),
'Company' => openssl_get_company ($linetokens[5]),
'Department' => openssl_get_department ($linetokens[5]),
'CN' => openssl_get_CN ($linetokens[5]),
'Email' => openssl_get_email ($linetokens[5])
);
}
}
}
// ----------------------------------------------
function openssl_write_database ($afile = '')
{
global $config;
global $openssl;
$afile = ($afile == '' ? $config['openssl']['database'] : $afile);
$atext = '';
for ($i = 0; $i < count ($openssl['Database']); $i++)
{
$atext .= ($atext == '' ? '' : "\n");
$atext .= $openssl['Database'][$i]['Status'] ."\t".
$openssl['Database'][$i]['ExpDate'] ."\t".
$openssl['Database'][$i]['RevDate'] ."\t".
$openssl['Database'][$i]['Serial'] ."\t".
$openssl['Database'][$i]['File'] ."\t".
$openssl['Database'][$i]['Name'];
}
writefile ($afile, $atext, $afile .'.old');
}
// ----------------------------------------------
function openssl_write_database_attr ($atext = '', $afile = '')
{
global $config;
global $openssl;
$afile = ($afile == '' ? $config['openssl']['database'] : $afile) .'.attr';
$atext = ($atext == '' ? "unique_subject = yes\n" : $atext);
if (file_exists ($afile))
{
ob_start ();
readfile ($afile);
$atext = ob_get_contents ();
ob_end_clean ();
}
writefile ($afile, $atext, $afile .'.old');
}
// ----------------------------------------------
// Returns the PEM file with spaces reduced and replaced to &nbsp;
function openssl_load_cert ($anid)
{
global $config;
do
{
$lines = file ($config['openssl']['pubfolder'] . $anid . '.pem');
if (!is_array ($lines))
{
$Return = '';
break;
}
foreach ($lines as $line_num => $line)
{
chomp ($line);
$Return[] = str_replace (' ', '&nbsp;', htmlspecialchars (str_replace (' ', ' ', $line)));
}
} while (FALSE);
return $Return;
}
// ----------------------------------------------
function openssl_load_serial ($afile = '')
{
global $config;
$afile = ($afile == '' ? $config['openssl']['serial'] : $afile);
$lines = file ($afile);
if (!is_array ($lines))
exit;
$Return = sscanf ($lines[0], "%X");
return $Return[0];
}
// ----------------------------------------------
function openssl_write_serial ($iNumber, $afile = '')
{
global $config;
$afile = ($afile == '' ? $config['openssl']['serial'] : $afile);
writefile ($afile, openssl_hex_serial ($iNumber) . "\n", $afile .'.old');
}
// ----------------------------------------------
// Supports up to 999,999 serials
function openssl_hex_serial ($iNumber)
{
if ($iNumber < 100)
$sString = sprintf ("%02X", $iNumber);
elseif ($iNumber < 10000)
$sString = sprintf ("%04X", $iNumber);
else
$sString = sprintf ("%06X", $iNumber);
return $sString;
}
// ----------------------------------------------
// Builds User Private Key, CSR and Public Certificate
function openssl_build_key (&$anoutput, $adn, $validdays = NULL)
{
global $config;
global $openssl;
$anoutput = '';
$Return = FALSE;
// Allow to override default value
$validdays = ($validdays == NULL ? $config['openssl']['default']['expiration'] : $validdays);
do
{
if (!isset ($adn) ||
!isset ($adn['countryName']) ||
!isset ($adn['stateOrProvinceName']) ||
!isset ($adn['localityName']) ||
!isset ($adn['organizationName']) ||
!isset ($adn['organizationalUnitName']) ||
!isset ($adn['commonName']) ||
!isset ($adn['emailAddress'])
)
{ $anoutput .= "- ERROR on ". __LINE__ ." line: incomplete DN information\n"; break; }
$anoutput .= "+ OK got the valid input\n";
// Get the new User Private Key
$UserPrivKey = openssl_pkey_new (array($config['openssl']['config'],0));
if ($UserPrivKey == FALSE)
{ $anoutput .= "- ERROR on ". (__LINE__ - 2) ." line (openssl_pkey_new):\n ". openssl_error_strings () ." (that might usually mean that the openssl.cnf file is unavailable)"; break; }
$anoutput .= "+ OK got the User Private Key\n";
// Generate the User Certificate Request
$UserReq = openssl_csr_new ($adn,
$UserPrivKey,
$config['openssl']['config']);
if ($UserReq == FALSE)
{ $anoutput .= "- ERROR on ". (__LINE__ - 4) ." line (openssl_csr_new):\n ". openssl_error_strings (); break; }
$anoutput .= "+ OK generated the User Certificate Request\n";
// Read the openssl serial
$CAserial = openssl_load_serial ($config['openssl']['serial']);
$anoutput .= "+ OK read current openssl serial (". openssl_hex_serial ($CAserial) .")\n";
$UserPubCertFile = $config['openssl']['pubfolder'] . openssl_hex_serial ($CAserial) .'.pem';
$UserCertReqFile = $config['openssl']['reqfolder'] . openssl_hex_serial ($CAserial) .'.csr';
$UserPrivKeyFile = $config['openssl']['prvfolder'] . openssl_hex_serial ($CAserial) .'.key';
// Read the openssl database
openssl_load_database ($config['openssl']['database']);
$anoutput .= "+ OK read the openssl database (". count ($openssl['Database']) ." items)\n";
// Get CA's Private Key
$CAPrivKey = openssl_pkey_get_private ($config['openssl']['CA']['priv']);
if ($CAPrivKey == FALSE)
{ $anoutput .= "- ERROR on ". (__LINE__ - 2) ." line (openssl_pkey_get_private)\n ". openssl_error_strings (); break; }
$anoutput .= "+ OK read the CA Private Key\n";
// Get a CA-signed cert that lasts for 1 year
$UserPubCert = openssl_csr_sign ($UserReq,
$config['openssl']['CA']['pub'],
$CAPrivKey,
$validdays,
$config['openssl']['config'],
$CAserial);
if ($UserPubCert == FALSE)
{ $anoutput .= "- ERROR on ". (__LINE__ - 7) ." line (openssl_csr_sign)\n ". openssl_error_strings (); break; }
$anoutput .= "+ OK signed the User Certificate Request with CA Private Key\n";
// Add the new row into openssl database
$openssl['Database'][] = array ('Status' => 'V',
'ExpDate' => date ('ymdHis',
time() +
date ('Z') +
($validdays * 24 * 60 * 60)) .'Z',
'RevDate' => '',
'Serial' => openssl_hex_serial ($CAserial),
'File' => openssl_hex_serial ($CAserial) .'.crt',
'Name' => openssl_make_name ($adn)
);
// Create files
$OldUMask = umask (0007);
// Write User Private Key
if (!openssl_pkey_export_to_file ($UserPrivKey, $UserPrivKeyFile, NULL, $config['openssl']['config']))
{ $anoutput .= "- ERROR on ". (__LINE__ - 1) ." line (openssl_pkey_export_to_file)\n ". openssl_error_strings () ." (That might mean that the key folder is not write enabled for www user)"; break; }
$anoutput .= "+ OK wrote User Private Key into file $UserPrivKeyFile\n";
// Write User Public Certificate
if (!openssl_x509_export_to_file ($UserPubCert, $UserPubCertFile, FALSE))
{ $anoutput .= "- ERROR on ". (__LINE__ - 1) ." line (openssl_x509_export_to_file)\n ". openssl_error_strings (); break; }
$anoutput .= "+ OK wrote User Public Certificate into file $UserPubCertFile\n";
// Write User Certificate Request
if (!openssl_csr_export_to_file ($UserReq, $UserCertReqFile))
{ $anoutput .= "- ERROR on ". (__LINE__ - 1) ." line (openssl_csr_export_to_file)\n ". openssl_error_strings (); break; }
$anoutput .= "+ OK wrote User Certificate Request into file $UserCertReqFile\n";
// Write new openssl database
openssl_write_database ($config['openssl']['database']);
openssl_write_database_attr ('', $config['openssl']['database']);
$anoutput .= "+ OK wrote new openssl database\n";
// Write new openssl serial
openssl_write_serial ($CAserial + 1, $config['openssl']['serial']);
$anoutput .= "+ OK wrote new openssl serial\n";
umask ($OldUMask);
$Return = openssl_hex_serial ($CAserial);
} while (FALSE);
return $Return;
}
// ----------------------------------------------
function openssl_error_strings ()
{
$sString = '';
while ($msg = openssl_error_string ())
$sString .= $msg ."\n";
return $sString;
}
// ----------------------------------------------
function openssl_make_name ($adn)
{
$sString = '';
if (strlen ($adn['countryName']) > 0) $sString .= '/C=' . $adn['countryName'];
if (strlen ($adn['stateOrProvinceName']) > 0) $sString .= '/ST=' . $adn['stateOrProvinceName'];
if (strlen ($adn['localityName']) > 0) $sString .= '/L=' . $adn['localityName'];
if (strlen ($adn['organizationName']) > 0) $sString .= '/O=' . $adn['organizationName'];
if (strlen ($adn['organizationalUnitName']) > 0) $sString .= '/OU=' . $adn['organizationalUnitName'];
if (strlen ($adn['commonName']) > 0) $sString .= '/CN=' . $adn['commonName'];
if (strlen ($adn['emailAddress']) > 0) $sString .= '/emailAddress='. $adn['emailAddress'];
return $sString;
}
// ----------------------------------------------
function openssl_get_country ($aline)
{ return str_get_sometag ($aline . '/', '\/C=([^/]*)\/'); }
// ----------------------------------------------
function openssl_get_state ($aline)
{ return str_get_sometag ($aline . '/', '\/ST=([^/]*)\/'); }
// ----------------------------------------------
function openssl_get_city ($aline)
{ return str_get_sometag ($aline . '/', '\/L=([^/]*)\/'); }
// ----------------------------------------------
function openssl_get_company ($aline)
{ return str_get_sometag ($aline . '/', '\/O=([^/]*)\/'); }
// ----------------------------------------------
function openssl_get_department ($aline)
{ return str_get_sometag ($aline . '/', '\/OU=([^/]*)\/'); }
// ----------------------------------------------
function openssl_get_CN ($aline)
{ return str_get_sometag ($aline . '/', '\/CN=([^/]*)\/'); }
// ----------------------------------------------
function openssl_get_email ($aline)
{ return str_get_sometag ($aline . '/', '\/emailAddress=([^/]*)\/'); }
// ----------------------------------------------
// Guess the full file name
function openssl_get_filename ($iSerial, $sExt)
{
global $config;
$sReturn = $config['openssl']['folder'] . openssl_hex_serial ($iSerial) . $sExt;
if (!file_exists ($sReturn))
{
$sReturn = $config['openssl']['pubfolder'] . openssl_hex_serial ($iSerial) . $sExt;
if (!file_exists ($sReturn))
{
$sReturn = $config['openssl']['reqfolder'] . openssl_hex_serial ($iSerial) . $sExt;
if (!file_exists ($sReturn))
{
$sReturn = $config['openssl']['prvfolder'] . openssl_hex_serial ($iSerial) . $sExt;
if (!file_exists ($sReturn))
{
$sReturn = '';
}
}
}
}
return $sReturn;
}
?>

View File

@@ -0,0 +1,146 @@
<?php
//if (!defined ("LOCAL_SECURITY_KEY"))
// die ();
// ----------------------------------------------
function openvpn_load_server_conf ()
{
global $config;
global $openvpn;
global $openssl;
$lines = file ($config['openvpn']['config']);
if (!is_array ($lines))
exit;
foreach ($lines as $line_num => $line)
{
chomp ($line);
$linetokens = explode (' ', str_strip_spaces ($line));
switch (strtolower ($linetokens[0]))
{
case 'local': $openvpn['Server']['Local'] = $linetokens[1]; break;
case 'proto': $openvpn['Server']['Proto'] = $linetokens[1]; break;
case 'port': $openvpn['Server']['Port'] = $linetokens[1]; break;
case 'dev': $openvpn['Server']['Dev'] = $linetokens[1]; break;
case 'mode': $openvpn['Server']['Mode'] = $linetokens[1]; break;
case 'max-clients': $openvpn['Server']['MaxClients'] = $linetokens[1]; break;
case 'status':
$openvpn['Server']['Status']['Exists'] = if_file_exists ($linetokens[1], true);
$openvpn['Server']['Status']['File'] = $linetokens[1];
break;
case 'status-version': $openvpn['Server']['Status']['Version'] = $linetokens[1]; break;
case 'ca':
$openssl['Server']['CA']['Exists'] = if_file_exists ($linetokens[1], true);
$openssl['Server']['CA']['File'] = $linetokens[1];
break;
case 'dh':
$openvpn['Server']['DH']['Exists'] = if_file_exists ($linetokens[1], true);
$openvpn['Server']['DH']['File'] = $linetokens[1];
break;
case 'cert':
$openvpn['Server']['Certificate']['Exists'] = if_file_exists ($linetokens[1], true);
$openvpn['Server']['Certificate']['File'] = $linetokens[1];
break;
case 'key':
$openvpn['Server']['Private_Key']['Exists'] = if_file_exists ($linetokens[1], true);
$openvpn['Server']['Private_Key']['File'] = $linetokens[1];
break;
case 'tls-auth':
$openvpn['Server']['TLS_Auth']['Exists'] = if_file_exists ($linetokens[1], true);
$openvpn['Server']['TLS_Auth']['File'] = $linetokens[1];
$openvpn['Server']['TLS_Auth']['Key'] = $linetokens[2];
break;
case 'crl-verify':
$openvpn['Server']['CRL_Verify']['Exists'] = if_file_exists ($linetokens[1], true);
$openvpn['Server']['CRL_Verify']['File'] = $linetokens[1];
break;
}
}
}
// ----------------------------------------------
function openvpn_load_status ()
{
global $config;
global $openvpn;
$stop_reading = FALSE;
if (!isset ($openvpn['Server']['Status']['File']))
exit;
$lines = file (str_file_fullname ($config['openvpn']['folder'], $openvpn['Server']['Status']['File']));
if (!is_array ($lines))
exit;
foreach ($lines as $line_num => $line)
{
chomp ($line);
$linetokens = explode (',', $line);
if ($linetokens[0] == 'TITLE')
$openvpn['Server']['Title'] = $linetokens[1];
else if ($linetokens[0] == 'TIME')
{
$openvpn['Server']['DateTime'] = $linetokens[1];
$openvpn['Server']['Time'] = $linetokens[2];
}
else if ($linetokens[0] == 'HEADER' && $linetokens[1] == 'CLIENT_LIST')
{
// We will need to know what field is what ?
}
else if ($linetokens[0] == 'HEADER' && $linetokens[1] == 'ROUTING_TABLE')
{
// We will need to know what field is what ?
}
else if ($linetokens[0] == 'CLIENT_LIST')
{
$openvpn['Client'][] = array ('CN' => str_replace ('_', ' ', $linetokens[1]),
'REALADDR' => $linetokens[2],
'VIRTADDR' => $linetokens[3],
'BYTESRCV' => $linetokens[4],
'BYTESSND' => $linetokens[5],
'SINCE' => $linetokens[6],
'SINCEUT' => $linetokens[7],
'Seconds_Ago' => seconds_string (time () - $linetokens[7])
);
}
else if ($linetokens[0] == 'ROUTING_TABLE')
{
$openvpn['Routing'][] = array ('VIRTADDR' => $linetokens[1],
'CN' => str_replace ('_', ' ', $linetokens[2]),
'REALADDR' => $linetokens[3],
'LAST' => $linetokens[4],
'Seconds_Ago' => seconds_string (time () - $linetokens[4])
);
}
}
}
// ----------------------------------------------
function openvpn_find_connected ()
{
global $openvpn;
global $openssl;
// find who is connected
if (isset ($openvpn['Client']))
$cnconnected = count ($openvpn['Client']);
else
$cnconnected = 0;
$cntotal = count ($openssl['Database']);
if ($cnconnected > 0)
for ($i = 0; $i < $cnconnected; $i++)
for ($j = 0; $j < $cntotal; $j++)
if ($openvpn['Client'][$i]['CN'] == $openssl['Database'][$j]['CN'])
{
$openssl['Database'][$j]['Connected'] = true;
break;
}
}
?>

View File

@@ -0,0 +1,113 @@
<?php
/*
* Copyrights are following:
*
* Eric Mueller <eric@themepark.com>
* http://www.zend.com/codex.php?id=535&single=1
*
* Denis125 <webmaster@atlant.ru>
* http://www.zend.com/codex.php?id=470&single=1
*
* Peter Listiak <mlady@users.sourceforge.net>
*
* PK ZIP
* http://www.pkware.com/appnote.txt
*/
class zipfile
{
var $datasec = array ();
var $ctrl_dir = array ();
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
var $old_offset = 0;
function unix2DosTime ($unixtime = 0)
{
$timearray = ($unixtime == 0) ?
getdate () :
getdate ($unixtime);
if ($timearray['year'] < 1980)
{
$timearray['year'] = 1980;
$timearray['mon'] = 1;
$timearray['mday'] = 1;
$timearray['hours'] = 0;
$timearray['minutes'] = 0;
$timearray['seconds'] = 0;
}
return (($timearray['year'] - 1980) << 25) |
($timearray['mon'] << 21) |
($timearray['mday'] << 16) |
($timearray['hours'] << 11) |
($timearray['minutes'] << 5) |
($timearray['seconds'] >> 1);
}
function addFile ($data, $name, $time = 0)
{
$name = str_replace ('\\', '/', $name);
$dtime = dechex ($this->unix2DosTime ($time));
$hexdtime = '\x' . $dtime[6] . $dtime[7] .
'\x' . $dtime[4] . $dtime[5] .
'\x' . $dtime[2] . $dtime[3] .
'\x' . $dtime[0] . $dtime[1];
eval ('$hexdtime = "' . $hexdtime . '";');
$unc_len = strlen ($data);
$crc = crc32 ($data);
$zdata = gzcompress ($data);
$zdata = substr (substr ($zdata, 0, strlen ($zdata) - 4), 2);
$c_len = strlen ($zdata);
$fr = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00" .
$hexdtime .
pack ('V', $crc) .
pack ('V', $c_len) .
pack ('V', $unc_len) .
pack ('v', strlen ($name)) .
pack ('v', 0) .
$name .
$zdata .
pack ('V', $crc) .
pack ('V', $c_len) .
pack ('V', $unc_len);
$this -> datasec[] = $fr;
$cdrec = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00" .
$hexdtime .
pack ('V', $crc) .
pack ('V', $c_len) .
pack ('V', $unc_len) .
pack ('v', strlen ($name)) .
pack ('v', 0 ) .
pack ('v', 0 ) .
pack ('v', 0 ) .
pack ('v', 0 ) .
pack ('V', 32 ) .
pack ('V', $this -> old_offset ) .
$name;
$this -> old_offset += strlen ($fr);
$this -> ctrl_dir[] = $cdrec;
}
function file ()
{
$data = implode ('', $this -> datasec);
$ctrldir = implode ('', $this -> ctrl_dir);
return $data .
$ctrldir .
$this -> eof_ctrl_dir .
pack ('v', sizeof ($this -> ctrl_dir)) .
pack ('v', sizeof ($this -> ctrl_dir)) .
pack ('V', strlen ($ctrldir)) .
pack ('V', strlen ($data)) .
"\x00\x00";
}
}
?>