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,66 @@
<?php
//include($_SERVER["DOCUMENT_ROOT"]."/Site/mysql.php");
// Change: your company name
$config['Company_Name'] = 'SchulVPN';
// Change: your company home page
$config['URL_Home_Page'] = 'http://10.10.63.60/index.php';
$config['AUTH_REALM'] = $config['Company_Name'] .' OpenVPN Web GUI v.0.3.2';
// What files to include into ZIP
$config['Download']['ZIP']['.pem'] = true;
$config['Download']['ZIP']['.key'] = true;
$config['Download']['ZIP']['.csr'] = false;
// All the following files should be placed into downloads folder
$config['Download']['ZIP']['Others'] = array ('readme.txt','ca.crt', 'schulvpn.ovpn', 'certinstall.sh');
//$config['Download']['ZIP']['Others'] = array ('readme.txt', 'install.cmd', 'tls-auth.key');
// Use the real absolute path here.
$config['PluginsAbsolutePath'] = $_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNConfig/plugins/";
// If there are no plugins
//$config['Plugins'] = NULL;
// Otherwise, follow this example:
//$config['Plugins']['PLUGINMANE']['Folder'] = 'FOLDERNAME';
// The post-install helper plugin. Shows if PHP5 has the neccessary functions available
$config['Plugins']['systemcheck']['Folder'] = 'systemcheck';
// OPENVPN ________________________________
// Change: the configuration directory
$config['openvpn']['folder'] = db_getconfval("ovpnconfdir")."/";
// Change: configuration and status file names
$config['openvpn']['config'] = $config['openvpn']['folder'].db_getconfval("ovpnconffile");
$config['openvpn']['status'] = $config['openvpn']['folder']."openvpn-status.log";
// OPENSSL ________________________________
// Change: openssl keys directory
$config['openssl']['folder'] = db_getconfval("ovpnkeydir")."/keys/";
// Change: different folders for Public Certificates, Certificate Requests and Private Keys.
// NOTE: openssl somehow respects only newpem folder (for Public Certificates).
$config['openssl']['pubfolder'] = $config['openssl']['folder'];
$config['openssl']['reqfolder'] = $config['openssl']['folder'];
$config['openssl']['prvfolder'] = $config['openssl']['folder'];
// Change: openssl CA private and public keys
$config['openssl']['CA']['priv'] = $config['openssl']['folder'] .'ca.key';
$config['openssl']['CA']['pub'] = $config['openssl']['folder'] .'ca.crt';
// Change: openssl serial file
$config['openssl']['serial'] = $config['openssl']['folder'] .'serial';
// Change: openssl database
$config['openssl']['database'] = $config['openssl']['folder'] .'index.txt';
// Change: openssl configuration
$config['openssl']['config'] = $config['openvpn']['folder'] .'openssl.cnf';
// NEW OPENSSL CERTIFICATE DEFAULTS _________
// Change all of them as it is done in your easy-rsa/vars
$config['openssl']['default']['expiration'] = 3560;
$config['openssl']['default']['countryName'] = 'AT';
$config['openssl']['default']['stateOrProvinceName'] = 'Tirol';
$config['openssl']['default']['localityName'] = 'Innsbruck';
$config['openssl']['default']['organizationName'] = 'HTL';
$config['openssl']['default']['organizationalUnitName'] = '';
$config['openssl']['default']['commonName'] = '';
$config['openssl']['default']['emailAddress'] = 'vpn@students.htlinn.ac.at';
?>

View File

@@ -0,0 +1,251 @@
<?php
// ----------------------------------------------
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 ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/plugins/". $PluginData['Folder'] ."/config.inc"))
{
include ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/plugins/". $PluginData['Folder'] ."/config.inc");
// Check if claimed inc files do exist
if (isset ($config['Plugins'][$PluginName]['Action']['Include']) &&
!file_exists ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/plugins/". $PluginData['Folder'] ."/".
$config['Plugins'][$PluginName]['Action']['Include']))
$config['Plugins'][$PluginName]['Action']['Include'] = NULL;
if (isset ($config['Plugins'][$PluginName]['Left']['Menu']) &&
!file_exists ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/plugins/". $PluginData['Folder'] ."/".
$config['Plugins'][$PluginName]['Left']['Menu']))
$config['Plugins'][$PluginName]['Left']['Menu'] = NULL;
if (isset ($config['Plugins'][$PluginName]['Left']['Status']) &&
!file_exists ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/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;
echo $amessage;
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,377 @@
<?php
// ----------------------------------------------
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,11 @@
<?php
session_start();
include ($_SERVER["DOCUMENT_ROOT"]."/Site/checkadmin.php");
include ($_SERVER["DOCUMENT_ROOT"]."/Config/_siteconfig_.php");
$path = $_REQUEST["path"];
// Write to file vpnid_man
exec("touch /var/vpn/squid_restart");
header ("Location: ".$path."&uebergabe=3");
?>

View File

@@ -0,0 +1,11 @@
<?php
session_start();
include ($_SERVER["DOCUMENT_ROOT"]."/Site/checkadmin.php");
include ($_SERVER["DOCUMENT_ROOT"]."/Config/_siteconfig_.php");
$path = $_REQUEST["path"];
// Write to file vpnid_man
exec("touch /var/vpn/squid_start");
header ("Location: ".$path."&uebergabe=4");
?>

View File

@@ -0,0 +1,11 @@
<?php
session_start();
include ($_SERVER["DOCUMENT_ROOT"]."/Site/checkadmin.php");
include ($_SERVER["DOCUMENT_ROOT"]."/Config/_siteconfig_.php");
$path = $_REQUEST["path"];
// Write to file vpnid_man
exec("touch /var/vpn/squid_stop");
header ("Location: ".$path."&uebergabe=5");
?>