示例#1
0
 public function genMyVpnKeys()
 {
     $result = $this->getMyAttributes(array("cn", "mail"));
     $this->loggerObj->log("Regenerating VPN Credentials for {$this->username}");
     $zip = new ZipArchive();
     $zipFilename = "{$this->username}.vpn.credentials.zip";
     $status = $zip->open($zipFilename, ZipArchive::OVERWRITE);
     if ($status !== TRUE) {
         throw new Exception("Cannot create Zip File");
     }
     list($cert, $pub, $priv) = generateSslKeypair($result["cn"][0], $result["mail"][0], 2048);
     $zip->addFromString("client.key", $priv);
     $zip->addFromString("client.crt", $cert);
     $status = $zip->close();
     $updateStatus = $this->updateMyProperty("VPN", $pub);
     if (!$updateStatus) {
         unlink($zipFilename);
         throw new Exception("Error occured during LDAP Update. Please try again Later!");
     }
     $this->loggerObj->log("VPN Credentials for {$this->username} have been reset successfully");
     return $zipFilename;
 }
示例#2
0
 private function genUserVpnKeys($vpnProperty, $vpnFolder)
 {
     $tmpPath = getConfig("tmpPath");
     $result = $this->getMyAttributes(array("cn", "sAMAccountName"));
     $this->loggerObj->log("Regenerating VPN Credentials for {$this->username}");
     $zip = new ZipArchive();
     $zipFilename = "{$tmpPath}/{$this->username}.{$vpnProperty}.credentials.zip";
     $status = $zip->open("{$zipFilename}", ZipArchive::OVERWRITE);
     if ($status !== TRUE) {
         throw new Exception("Cannot create Zip File");
     }
     $commonName = $result["sAMAccountName"][0];
     list($cert, $priv) = generateSslKeypair($commonName, intval(getConfig("vpnKeyLength")));
     // If vpn targets are configured, put the client key and cert in each target
     $vpnTargets = getConfig("vpnTargets");
     if ($vpnTargets == NULL) {
         $zip->addFromString("client.key", $priv);
         $zip->addFromString("client.crt", $cert);
     } else {
         foreach ($vpnTargets as $target) {
             $zip->addFromString("{$target}/client.key", $priv);
             $zip->addFromString("{$target}/client.crt", $cert);
         }
     }
     // Try to add the source vpn files
     if (file_exists($vpnFolder)) {
         zipFolder($zip, $vpnFolder);
     } else {
         throw new Exception("VPN Container is Not Found. Kindly contact the server administrator!");
     }
     // Compress and save the files
     $status = $zip->close();
     if ($status !== TRUE) {
         throw new Exception("Cannot create Zip File");
     }
     $updateStatus = $this->updateMyProperty($vpnProperty, $cert);
     if ($updateStatus !== TRUE) {
         unlink($zipFilename);
         throw new Exception("Error occured during LDAP Update: {$updateStatus}. Please try again Later!");
     }
     $this->loggerObj->log("VPN Credentials for {$this->username} have been reset successfully");
     return $zipFilename;
 }