OpenVPN_Management_GUI/Admin/Modules/VPNconfig/include/viewcert.php

129 lines
7.1 KiB
PHP

<?php
include ($_SERVER["DOCUMENT_ROOT"]."/Site/checkadmin.php");
include ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/config.inc");
include ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/include/functions.inc");
include ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/include/openvpn-functions.inc");
include ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/include/openssl-functions.inc");
openvpn_load_server_conf ();
if (!isset ($openvpn['Server'])) html_error ("The OpenVPN server has no configuration file");
openvpn_load_status ();
if (!isset ($openvpn['Server']['Title'])) html_error ("The OpenVPN server has no status file");
openssl_load_database ();
openvpn_find_connected ();
$openvpn["Certificates"] = $openssl["Database"];
$openvpn["Seconds_Ago"] = time () - $openvpn['Server']['Time'];
$cntotal = count ($openssl['Database']);
$GETid = $cert;
$GETidDEC = sscanf ($GETid, '%X');
for ($j = 0; $j < $cntotal; $j++)
if ($openssl['Database'][$j]['Serial'] == $GETid)
{
$openssl['Database'][$j]['ExpDate'] = str_openssldata_to_string ($openssl['Database'][$j]['ExpDate']);
$openssl['Database'][$j]['RevDate'] = str_openssldata_to_string ($openssl['Database'][$j]['RevDate']);
$openvpn['Certificate'] = $openssl['Database'][$j];
$openvpn['CertificateFileCRT'] = openssl_get_filename ($GETidDEC[0], '.pem');
$openvpn['CertificateFileKEY'] = openssl_get_filename ($GETidDEC[0], '.key');
$openvpn['CertificateFileCSR'] = openssl_get_filename ($GETidDEC[0], '.csr');
break;
}
?>
<table border="0" width="100%" cellspacing="0" cellpadding="4">
<tr valign="top"><td colspan="2" style="border-top:1px groove black; border-bottom:1px groove black"><b>Certificate Information</b></td></tr>
<tr valign="top">
<td nowrap width="1%" align="right" bgcolor="#DDFFCC">Serial</td>
<td><font color="blue"><?php echo $openvpn['Certificate']['Serial']; ?>
</font></td>
</tr>
<tr valign="top">
<td nowrap width="1%" align="right" bgcolor="#DDFFCC">Status</td>
<?php echo '<td><font color="blue">'; ?><?php if ($openvpn['Certificate']['Status'] == 'V'): ?><?php echo 'Valid'; ?><?php elseif ($openvpn['Certificate']['Status'] == 'R'): ?><?php echo 'Revoked'; ?><?php elseif ($openvpn['Certificate']['Status'] == 'E'): ?><?php echo 'Expired'; ?><?php endif; ?><?php echo ''; ?><?php if ($openvpn['Certificate']['Connected']): ?><?php echo ', Now connected'; ?><?php endif; ?><?php echo '</font></td>'; ?>
</tr>
<tr valign="top">
<td nowrap width="1%" align="right" bgcolor="#DDFFCC" style="border-bottom:1px groove black"><?php echo ''; ?><?php if ($openvpn['Certificate']['Status'] == 'V'): ?><?php echo 'Expiration'; ?><?php elseif ($openvpn['Certificate']['Status'] == 'R'): ?><?php echo 'Revoked'; ?><?php else: ?><?php echo '&nbsp;'; ?><?php endif; ?><?php echo '</td>'; ?>
<td style="border-bottom:1px groove black"><font color="darkgreen"><?php echo ''; ?><?php if ($openvpn['Certificate']['Status'] == 'V'): ?><?php echo ''; ?><?php echo $openvpn['Certificate']['ExpDate']; ?><?php echo ''; ?><?php elseif ($openvpn['Certificate']['Status'] == 'R'): ?><?php echo ''; ?><?php echo $openvpn['Certificate']['RevDate']; ?><?php echo ''; ?><?php else: ?><?php echo '&nbsp;'; ?><?php endif; ?><?php echo '</font></td>'; ?>
</tr>
<tr valign="top">
<td nowrap width="1%" align="right" bgcolor="#DDFFCC">Common Name</td>
<td><font color="blue"><?php echo $openvpn['Certificate']['CN']; ?>
</font></td>
</tr>
<tr valign="top">
<td nowrap width="1%" align="right" bgcolor="#DDFFCC" style="border-bottom:1px groove black">e-mail</td>
<td style="border-bottom:1px groove black"><font color="darkgreen"><?php echo ''; ?><?php if ($openvpn['Certificate']['Email'] != ''): ?><?php echo '<a href="mailto:'; ?><?php echo $openvpn['Certificate']['Email']; ?><?php echo '">'; ?><?php echo $openvpn['Certificate']['Email']; ?><?php echo '</a>'; ?><?php else: ?><?php echo '&nbsp;'; ?><?php endif; ?><?php echo '</font></td>'; ?>
</tr>
<tr valign="top">
<td nowrap width="1%" align="right" bgcolor="#DDFFCC">Country</td>
<td><font color="darkgreen"><?php echo $openvpn['Certificate']['Country']; ?>
</font></td>
</tr>
<tr valign="top">
<td nowrap width="1%" align="right" bgcolor="#DDFFCC">State or Province</td>
<td><font color="darkgreen"><?php echo $openvpn['Certificate']['State']; ?>
</font></td>
</tr>
<tr valign="top">
<td nowrap width="1%" align="right" bgcolor="#DDFFCC">City</td>
<td><font color="darkgreen"><?php echo $openvpn['Certificate']['City']; ?>
</font></td>
</tr>
<tr valign="top">
<td nowrap width="1%" align="right" bgcolor="#DDFFCC">Company</td>
<td><font color="darkgreen"><?php echo $openvpn['Certificate']['Company']; ?>
</font></td>
</tr>
<tr valign="top">
<td nowrap width="1%" align="right" bgcolor="#DDFFCC">Department</td>
<td><font color="darkgreen"><?php echo $openvpn['Certificate']['Department']; ?>
</font></td>
</tr>
<tr valign="top"><td colspan="2" style="border-top:1px groove black; border-bottom:1px groove black"><b>Certificate Files</b></td></tr>
<tr valign="top">
<td nowrap width="1%" align="right" bgcolor="#DDFFCC">Public Certificate</td>
<td><?php echo ''; ?><?php if ($openvpn['CertificateFileCRT'] != ''): ?><?php echo '<a href="/Admin/Modules/VPNconfig/include/getfile.php?Action=DownloadCertificate&id='; ?><?php echo $openvpn['Certificate']['Serial']; ?><?php echo '&Type=CRT" title=\'Download Public Certificate\'>Download</a>'; ?><?php else: ?><?php echo '&lt;File not found&gt;'; ?><?php endif; ?><?php echo ''; ?>
</td>
</tr>
<tr valign="top">
<td nowrap width="1%" align="right" bgcolor="#DDFFCC">Private Key</td>
<td><?php echo ''; ?><?php if ($openvpn['CertificateFileKEY'] != ''): ?><?php echo '<a href="g/Admin/Modules/VPNconfig/include/getfile.php?Action=DownloadCertificate&id='; ?><?php echo $openvpn['Certificate']['Serial']; ?><?php echo '&Type=KEY" title=\'Download Private Key\'>Download</a>'; ?><?php else: ?><?php echo '&lt;File not found&gt;'; ?><?php endif; ?><?php echo ''; ?>
</td>
</tr>
<tr valign="top">
<td style="border-bottom:1px groove black" nowrap width="1%" align="right" bgcolor="#DDFFCC">Certificate Request</td>
<td style="border-bottom:1px groove black"><?php echo ''; ?><?php if ($openvpn['CertificateFileCSR'] != ''): ?><?php echo '<a href=/Admin/Modules/VPNconfig/include/getfile.php?Action=DownloadCertificate&id='; ?><?php echo $openvpn['Certificate']['Serial']; ?><?php echo '&Type=CSR" title=\'Download Certificate Request\'>Download</a>'; ?><?php else: ?><?php echo '&lt;File not found&gt;'; ?><?php endif; ?><?php echo ''; ?>
</td>
</tr>
<tr valign="top">
<td style="border-bottom:1px groove black" nowrap width="1%" align="right" bgcolor="#DDFFCC">Archive</td>
<td style="border-bottom:1px groove black"><?php echo ''; ?><?php if ($openvpn['CertificateFileCRT'] != '' || $openvpn['CertificateFileKEY'] != '' || $openvpn['CertificateFileCSR'] != ''): ?><?php echo '<a href="/Admin/Modules/VPNconfig/include/getfile.php?Action=DownloadCertificate&id='; ?><?php echo $openvpn['Certificate']['Serial']; ?><?php echo '&Type=ZIP" title=\'Download all files in one archive\'>Download</a>'; ?><?php else: ?><?php echo '&lt;File not found&gt;'; ?><?php endif; ?><?php echo ''; ?>
</td>
</tr>
</table>