Example #1
0
 # Create a default FTP account if set in the system options...
 if (GetSystemOption('auto_ftpuser') == "true") {
     # Get the current account ID for the new user...
     $acc_fk = $clientid['ac_id_pk'];
     $password = $_POST['inPassword'];
     $access_type = "RW";
     $homedirectoy_to_use = "/";
     # Just need to check that an account doesnt already exist with the same username....
     $sql = "SELECT * FROM z_ftpaccounts WHERE ft_user_vc='" . Cleaner('i', $username) . "' AND ft_deleted_ts IS NULL";
     $existsftp = DataExchange("t", $z_db_name, $sql);
     $permissionset = "\t\t<Option Name=\"FileRead\">1</Option>\r\n\t\t<Option Name=\"FileWrite\">1</Option>\r\n\t\t<Option Name=\"FileDelete\">1</Option>\r\n\t\t<Option Name=\"FileAppend\">1</Option>\r\n\t\t<Option Name=\"DirCreate\">1</Option>\r\n\t\t<Option Name=\"DirDelete\">1</Option>\r\n\t\t<Option Name=\"DirList\">1</Option>\r\n\t\t<Option Name=\"DirSubdirs\">1</Option>";
     if ($existsftp < 1) {
         if (ShowServerPlatform() == 'Windows') {
             zapi_ftpaccount_add(GetSystemOption('filezilla_root'), $username, $password, GetSystemOption('zpanel_version'), ChangeSafeSlashesToWin(GetSystemOption('hosted_dir') . $username), $permissionset);
         } else {
             zapi_ftpaccount_add(GetSystemOption('filezilla_root'), $username, $password, GetSystemOption('zpanel_version'), ChangeWinSlashesToNIX(GetSystemOption('hosted_dir') . $username), $permissionset);
         }
         # If all has gone well we need to now create the domain in the database...
         $sql = "INSERT INTO z_ftpaccounts (ft_acc_fk,\r\n\t\t\t\t\t\t\t\t\t\t\tft_user_vc,\r\n\t\t\t\t\t\t\t\t\t\t\tft_directory_vc,\r\n\t\t\t\t\t\t\t\t\t\t\tft_access_vc,\r\n\t\t\t\t\t\t\t\t\t\t\tft_created_ts) VALUES (\r\n\t\t\t\t\t\t\t\t\t\t" . $acc_fk . ",\r\n\t\t\t\t\t\t\t\t\t\t'" . Cleaner('i', $username) . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . Cleaner('i', "/") . "',\r\n\t\t\t\t\t\t\t\t\t\t'" . Cleaner('i', "RW") . "',\r\n\t\t\t\t\t\t\t\t\t\t" . time() . ")";
         DataExchange("w", $z_db_name, $sql);
         # Now we add some infomation to the system log.
         TriggerLog($useraccount['ac_id_pk'], $b = "> New FTP account has been created for the new user (" . Cleaner('i', $username) . ").");
     } else {
         TriggerLog($useraccount['ac_id_pk'], $b = "> Could not auto create new FTP user (" . Cleaner('i', $username) . ") as a duplicate account exists on the server.");
     }
 }
 # Send the user account details via. email (if requested)...
 if ($_POST['inSWE'] == 1) {
     if ($_POST['inEmailAddress'] != '') {
         include "lang/" . GetSystemOption('zpanel_lang') . ".php";
         $messagesubject = $lang['225'];
Example #2
0
function zapi_ftpaccount_add($filezilla_root, $username, $password, $zp_version, $directorytouse, $permissionset)
{
    if (ShowServerPlatform() == "Windows") {
        # Add a FileZilla FTP Account
        $filezilla_reload = "\"" . $filezilla_root . "FileZilla server.exe\" /reload-config";
        $filezilla_config = $filezilla_root . "FileZilla Server.xml";
        $content = implode('', file($filezilla_config));
        $content1 = explode("</Users>", $content);
        $content2 = explode("</FileZillaServer>", $content1[1], 2);
        $content = $content1[0] . $content2[1];
        $editfile = fopen($filezilla_config, "w");
        fwrite($editfile, $content);
        fclose($editfile);
        $new_file = implode('', file($filezilla_config));
        $new_file .= "<User Name=\"{$username}\">\r\n\t<Option Name=\"Pass\">" . md5($password) . "</Option>\r\n\t<Option Name=\"Group\"/>\r\n\t<Option Name=\"Bypass server userlimit\">0</Option>\r\n\t<Option Name=\"User Limit\">0</Option>\r\n\t<Option Name=\"IP Limit\">0</Option>\r\n\t<Option Name=\"Enabled\">1</Option>\r\n\t<Option Name=\"Comments\">Auto account generated by ZPanel (v." . $zp_version . ").</Option>\r\n\t<Option Name=\"ForceSsl\">0</Option>\r\n\t<IpFilter>\r\n\t<Disallowed/>\r\n\t<Allowed/>\r\n\t</IpFilter>\r\n\t<Permissions>\r\n\t<Permission Dir=\"" . $directorytouse . "\">\r\n\t{$permissionset}\r\n\t<Option Name=\"IsHome\">1</Option>\r\n\t<Option Name=\"AutoCreate\">0</Option>\r\n\t</Permission>\r\n\t</Permissions>\r\n\t<SpeedLimits DlType=\"0\" DlLimit=\"10\" ServerDlLimitBypass=\"0\" UlType=\"0\" UlLimit=\"10\" ServerUlLimitBypass=\"0\">\r\n\t<Download/>\r\n\t<Upload/>\r\n\t</SpeedLimits>\r\n\t</User>\r\n\t</Users>\r\n\t</FileZillaServer>";
        $editfile = fopen($filezilla_config, "w");
        if (!fwrite($editfile, $new_file)) {
            return false;
        } else {
            return true;
        }
        fclose($editfile);
    } else {
        # Server is POSIX based - Lets use ProFTPd
        $proftpd_config = "/etc/zpanel/conf/ftp/zftpd.passwd";
        $auto_salt = GenerateRandomPassword(8);
        $ftp_password = crypt($password, '$1$' . $auto_salt . '$');
        $directorytouse = ChangeWinSlashesToNIX($directorytouse);
        $new_file = implode('', file($proftpd_config));
        $new_file .= "# USER:"******"\n" . $username . ":" . $ftp_password . ":1010:1010::" . $directorytouse . ":/bin/false\n# END USER:"******"\n";
        $editfile = fopen($proftpd_config, "w");
        if (!fwrite($editfile, preg_replace('/^[ \\t]*[\\r\\n]+/m', '', $new_file))) {
            # Log to system, unable to write the file...
            TriggerLog(1, "Was unable to write to the ProFTPd configuration file (" . $proftpd_config . "), check that the file is not read-only and that the file path in the ZPanel settings is correct.");
            return false;
        } else {
            return true;
            # Reload the FTP daemon here!!
        }
        fclose($editfile);
    }
}