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;
 }
function zipFolder($zipArchive, $folder, $basePath = null)
{
    if (!is_dir($folder)) {
        return -1;
    }
    $entries = array_diff(scandir($folder), array('..', '.'));
    foreach ($entries as $f) {
        $absFilePath = "{$folder}/{$f}";
        if ($basePath) {
            $newBasePath = $basePath . "/" . $f;
        } else {
            $newBasePath = $f;
        }
        if (is_dir($absFilePath)) {
            zipFolder($zipArchive, $absFilePath, $newBasePath);
        } else {
            $zipArchive->addFile($absFilePath, $newBasePath);
        }
    }
}