function GenerateVisitorStats()
{
    include 'cnf/db.php';
    $z_db_user = $user;
    $z_db_pass = $pass;
    try {
        $zdbh = new db_driver("mysql:host=localhost;dbname=" . $dbname . "", $z_db_user, $z_db_pass);
    } catch (PDOException $e) {
    }
    $sql = $zdbh->prepare("SELECT * FROM x_vhosts LEFT JOIN x_accounts ON x_vhosts.vh_acc_fk=x_accounts.ac_id_pk WHERE vh_deleted_ts IS NULL");
    $sql->execute();
    echo "Generating visitor stats html..." . fs_filehandler::NewLine();
    while ($rowvhost = $sql->fetch()) {
        if (!file_exists(ctrl_options::GetOption('sentora_root') . "modules/visitor_stats/stats/" . $rowvhost['ac_user_vc'] . "")) {
            @mkdir(ctrl_options::GetOption('sentora_root') . "modules/visitor_stats/stats/" . $rowvhost['ac_user_vc'] . "", 777, TRUE);
        }
        if (sys_versions::ShowOSPlatformVersion() == "Windows") {
            $runcommand = ctrl_options::GetOption('sentora_root') . "modules/visitor_stats/bin/visitors.exe -A -m 30 " . ctrl_options::GetOption('log_dir') . "domains/" . $rowvhost['ac_user_vc'] . "/" . $rowvhost['vh_name_vc'] . "-access.log -o html > " . ctrl_options::GetOption('sentora_root') . "modules/visitor_stats/stats/" . $rowvhost['ac_user_vc'] . "/" . $rowvhost['vh_name_vc'] . ".html";
        } else {
            chmod(ctrl_options::GetOption('sentora_root') . "modules/visitor_stats/bin/visitors", 4777);
            $runcommand = ctrl_options::GetOption('sentora_root') . "modules/visitor_stats/bin/visitors -A -m 30 " . ctrl_options::GetOption('log_dir') . "domains/" . $rowvhost['ac_user_vc'] . "/" . $rowvhost['vh_name_vc'] . "-access.log -o html > " . ctrl_options::GetOption('sentora_root') . "modules/visitor_stats/stats/" . $rowvhost['ac_user_vc'] . "/" . $rowvhost['vh_name_vc'] . ".html";
        }
        echo "Generating stats for: " . $rowvhost['ac_user_vc'] . "/" . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
        system($runcommand);
    }
}
function DeleteAliasForDeletedClient()
{
    global $zdbh;
    $deletedclients = array();
    $sql = "SELECT COUNT(*) FROM x_accounts WHERE ac_deleted_ts IS NOT NULL";
    if ($numrows = $zdbh->query($sql)) {
        if ($numrows->fetchColumn() != 0) {
            $sql = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_deleted_ts IS NOT NULL");
            $sql->execute();
            while ($rowclient = $sql->fetch()) {
                $deletedclients[] = $rowclient['ac_id_pk'];
            }
        }
    }
    // Include mail server specific file here.
    if (file_exists("modules/aliases/hooks/" . ctrl_options::GetSystemOption('mailserver_php') . "")) {
        include "modules/aliases/hooks/" . ctrl_options::GetSystemOption('mailserver_php') . "";
    }
    foreach ($deletedclients as $deletedclient) {
        $bindArray = array(':deletedclient' => $deletedclient);
        $sqlStatment = $zdbh->bindQuery("SELECT * FROM x_aliases WHERE al_acc_fk=:deletedclient AND al_deleted_ts IS NULL", $bindArray);
        $result = $zdbh->returnRow();
        if ($result) {
            $sql = $zdbh->prepare("UPDATE x_aliases SET al_deleted_ts=:time WHERE al_acc_fk=:deletedclient");
            $sql->bindParam(':time', time());
            $sql->bindParam(':deletedclient', $deletedclient);
            $sql->execute();
        }
    }
}
示例#3
0
 static function getConfig()
 {
     global $zdbh;
     $currentuser = ctrl_users::GetUserDetail();
     $sql = "SELECT * FROM x_settings WHERE so_module_vc=:name AND so_usereditable_en = 'true' ORDER BY so_cleanname_vc";
     //$numrows = $zdbh->query($sql);
     $name = ui_module::GetModuleName();
     $numrows = $zdbh->prepare($sql);
     $numrows->bindParam(':name', $name);
     $numrows->execute();
     if ($numrows->fetchColumn() != 0) {
         $sql = $zdbh->prepare($sql);
         $sql->bindParam(':name', $name);
         $res = array();
         $sql->execute();
         while ($rowmailsettings = $sql->fetch()) {
             if (ctrl_options::CheckForPredefinedOptions($rowmailsettings['so_defvalues_tx'])) {
                 $fieldhtml = ctrl_options::OuputSettingMenuField($rowmailsettings['so_name_vc'], $rowmailsettings['so_defvalues_tx'], $rowmailsettings['so_value_tx']);
             } else {
                 $fieldhtml = ctrl_options::OutputSettingTextArea($rowmailsettings['so_name_vc'], $rowmailsettings['so_value_tx']);
             }
             array_push($res, array('cleanname' => ui_language::translate($rowmailsettings['so_cleanname_vc']), 'name' => $rowmailsettings['so_name_vc'], 'description' => ui_language::translate($rowmailsettings['so_desc_tx']), 'value' => $rowmailsettings['so_value_tx'], 'fieldhtml' => $fieldhtml));
         }
         return $res;
     } else {
         return false;
     }
 }
示例#4
0
function GenerateWebalizerStats()
{
    global $zdbh;
    $sql = $zdbh->prepare("SELECT * FROM x_vhosts LEFT JOIN x_accounts ON x_vhosts.vh_acc_fk=x_accounts.ac_id_pk WHERE vh_deleted_ts IS NULL");
    $sql->execute();
    echo "Generating webalizer stats html..." . fs_filehandler::NewLine();
    while ($rowvhost = $sql->fetch()) {
        $basedir = ctrl_options::GetSystemOption('MADmin_root') . "modules/webalizer_stats/stats/" . $rowvhost['ac_user_vc'] . "/" . $rowvhost['vh_name_vc'];
        if (!file_exists($basedir)) {
            @mkdir($basedir, 0755, TRUE);
        }
        /** set webalizer command dependant on OS */
        if (sys_versions::ShowOSPlatformVersion() == "Windows") {
            $command = ctrl_options::GetSystemOption('MADmin_root') . 'modules/webalizer_stats/bin/webalizer.exe';
        } else {
            chmod(ctrl_options::GetSystemOption('MADmin_root') . "modules/webalizer_stats/bin/webalizer", 4777);
            $command = "webalizer";
        }
        /** all other args and flags are the same so keep them outsite to avoid duplication */
        $flag = '-o';
        $secondFlags = '-d -F clf -n';
        $domain = $rowvhost['vh_name_vc'];
        $logFile = realpath(ctrl_options::GetSystemOption('log_dir') . 'domains/' . $rowvhost['ac_user_vc'] . '/' . $rowvhost['vh_name_vc'] . '-access.log');
        $statsPath = ctrl_options::GetSystemOption('MADmin_root') . "modules/webalizer_stats/stats/" . $rowvhost['ac_user_vc'] . '/' . $rowvhost['vh_name_vc'];
        /** build arg array, this is in the required order! do not just change the order of this array */
        $args = array($logFile, $flag, $statsPath, $secondFlags, $domain);
        echo "Generating stats for: " . $rowvhost['ac_user_vc'] . "/" . $rowvhost['vh_name_vc'] . fs_filehandler::NewLine();
        $returnValue = ctrl_system::systemCommand($command, $args);
        echo (0 === $returnValue ? 'Succeeded' : 'Failed') . fs_filehandler::NewLine();
    }
}
 static function DisplayApacheConfig()
 {
     global $zdbh;
     $line = "<h2>" . ui_language::translate("Configure your Apache Settings") . "</h2>";
     $line .= "<form action=\"./?module=apache_admin&action=UpdateApacheConfig\" method=\"post\">";
     $line .= "<table class=\"table table-striped\">";
     $count = 0;
     $sql = "SELECT COUNT(*) FROM x_settings WHERE so_module_vc=:module AND so_usereditable_en = 'true'";
     $moduleName = ui_module::GetModuleName();
     $numrows = $zdbh->prepare($sql);
     $numrows->bindParam(':module', $moduleName);
     $numrows->execute();
     if ($numrows) {
         if ($numrows->fetchColumn() != 0) {
             $sql = $zdbh->prepare("SELECT * FROM x_settings WHERE so_module_vc=:module AND so_usereditable_en = 'true' ORDER BY so_cleanname_vc");
             $sql->bindParam(':module', $moduleName);
             $sql->execute();
             while ($row = $sql->fetch()) {
                 $count++;
                 if (ctrl_options::CheckForPredefinedOptions($row['so_defvalues_tx'])) {
                     $fieldhtml = ctrl_options::OuputSettingMenuField($row['so_name_vc'], $row['so_defvalues_tx'], $row['so_value_tx']);
                 } else {
                     $fieldhtml = ctrl_options::OutputSettingTextArea($row['so_name_vc'], $row['so_value_tx']);
                 }
                 $line .= "<tr valign=\"top\"><th nowrap=\"nowrap\">" . ui_language::translate($row['so_cleanname_vc']) . "</th><td>" . $fieldhtml . "</td><td>" . ui_language::translate($row['so_desc_tx']) . "</td></tr>";
             }
             $line .= "<tr><th>" . ui_language::translate("Force Update") . "</th><td><input type=\"checkbox\"></td><td>" . ui_language::translate("Force vhost.conf to be updated on next daemon run. Any change in settings also triggers vhost.conf to be updated.") . "</td></tr>";
             $line .= "<tr><th colspan=\"3\"><button class=\"button-loader btn btn-primary\" type=\"submit\" id=\"button\" name=\"inSaveSystem\">" . ui_language::translate("Save Changes") . "</button><button class=\"button-loader btn btn-default\" type=\"button\" onclick=\"window.location.href='./?module=moduleadmin';return false;\">" . ui_language::translate("Cancel") . "</button></th></tr>";
         }
     }
     $line .= "</table>";
     $line .= runtime_csfr::Token();
     $line .= "</form>";
     return $line;
 }
function DeleteMailboxesForDeletedClient()
{
    global $zdbh;
    $deletedclients = array();
    $sql = "SELECT COUNT(*) FROM x_accounts WHERE ac_deleted_ts IS NOT NULL";
    if ($numrows = $zdbh->query($sql)) {
        if ($numrows->fetchColumn() != 0) {
            $sql = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_deleted_ts IS NOT NULL");
            $sql->execute();
            while ($rowclient = $sql->fetch()) {
                $deletedclients[] = $rowclient['ac_id_pk'];
            }
        }
    }
    // Include mail server specific file here.
    if (file_exists("modules/mailboxes/hooks/" . ctrl_options::GetSystemOption('mailserver_php') . "")) {
        include "modules/mailboxes/hooks/" . ctrl_options::GetSystemOption('mailserver_php') . "";
    }
    foreach ($deletedclients as $deletedclient) {
        //      $result = $zdbh->query("SELECT * FROM x_mailboxes WHERE mb_acc_fk=" . $deletedclient . " AND mb_deleted_ts IS NULL")->Fetch();
        $numrows = $zdbh->prepare("SELECT * FROM x_mailboxes WHERE mb_acc_fk=:deletedclient AND mb_deleted_ts IS NULL");
        $numrows->bindParam(':deletedclient', $deletedclient);
        $numrows->execute();
        $result = $numrows->fetch();
        if ($result) {
            $time = time();
            $sql = $zdbh->prepare("UPDATE x_mailboxes SET mb_deleted_ts=:time WHERE mb_acc_fk=:deletedclient");
            $sql->bindParam(':time', $time);
            $sql->bindParam(':deletedclient', $deletedclient);
            $sql->execute();
        }
    }
}
示例#7
0
 /**
  * The 'worker' methods.
  */
 static function ListPackages($uid)
 {
     global $zdbh;
     $sql = "SELECT * FROM x_packages WHERE pk_reseller_fk=:uid AND pk_deleted_ts IS NULL";
     //$numrows = $zdbh->query($sql);
     $numrows = $zdbh->prepare($sql);
     $numrows->bindParam(':uid', $uid);
     $numrows->execute();
     if ($numrows->fetchColumn() != 0) {
         $sql = $zdbh->prepare($sql);
         $sql->bindParam(':uid', $uid);
         $res = array();
         $sql->execute();
         while ($rowpackages = $sql->fetch()) {
             //$numrows = $zdbh->query("SELECT COUNT(*) FROM x_accounts WHERE ac_package_fk=" . $rowpackages['pk_id_pk'] . " AND ac_deleted_ts IS NULL")->fetchColumn();
             $numrows = $zdbh->prepare("SELECT COUNT(*) FROM x_accounts WHERE ac_package_fk=:pk_id_pk AND ac_deleted_ts IS NULL");
             $numrows->bindParam(':pk_id_pk', $rowpackages['pk_id_pk']);
             $numrows->execute();
             $Column = $numrows->fetchColumn();
             array_push($res, array('packageid' => $rowpackages['pk_id_pk'], 'created' => date(ctrl_options::GetSystemOption('MADmin_df'), $rowpackages['pk_created_ts']), 'clients' => $Column[0], 'packagename' => ui_language::translate($rowpackages['pk_name_vc'])));
         }
         return $res;
     } else {
         return false;
     }
 }
示例#8
0
 /**
  * Sends the email with the contents of the object (Body etc. set using the parant calls in phpMailer!)
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @return boolean 
  */
 public function SendEmail()
 {
     $this->Mailer = ctrl_options::GetSystemOption('mailer_type');
     $this->From = ctrl_options::GetSystemOption('email_from_address');
     $this->FromName = ctrl_options::GetSystemOption('email_from_name');
     if (ctrl_options::GetSystemOption('email_smtp') != 'false') {
         $this->IsSMTP();
         if (ctrl_options::GetSystemOption('smtp_auth') != 'false') {
             $this->SMTPAuth = true;
             $this->Username = ctrl_options::GetSystemOption('smtp_username');
             $this->Password = ctrl_options::GetSystemOption('smtp_password');
         }
         if (ctrl_options::GetSystemOption('smtp_secure') != 'false') {
             $this->SMTPSecure = ctrl_options::GetSystemOption('smtp_secure');
         }
         $this->Host = ctrl_options::GetSystemOption('smtp_server');
         $this->Port = ctrl_options::GetSystemOption('smtp_port');
     }
     ob_start();
     $send_resault = $this->Send();
     $error = ob_get_contents();
     ob_clean();
     if ($send_resault) {
         runtime_hook::Execute('OnSuccessfulSendEmail');
         return true;
     } else {
         $logger = new debug_logger();
         $logger->method = ctrl_options::GetSystemOption('logmode');
         $logger->logcode = "061";
         $logger->detail = 'Error sending email (using sys_email): ' . $error . '';
         $logger->writeLog();
         runtime_hook::Execute('OnFailedSendEmail');
         return false;
     }
 }
function DeleteApacheClientFiles()
{
    global $zdbh;
    $sql = "SELECT * FROM x_accounts WHERE ac_deleted_ts IS NOT NULL";
    $numrows = $zdbh->query($sql);
    if ($numrows->fetchColumn() != 0) {
        $sql = $zdbh->prepare($sql);
        $res = array();
        $sql->execute();
        while ($rowdeletedaccounts = $sql->fetch()) {
            // Check for an active user with same username
            $sql2 = "SELECT COUNT(*) FROM x_accounts WHERE ac_user_vc=:user AND ac_deleted_ts IS NULL";
            $numrows2 = $zdbh->prepare($sql2);
            $user = $rowdeletedaccounts['ac_user_vc'];
            $numrows2->bindParam(':user', $user);
            if ($numrows2->execute()) {
                if ($numrows2->fetchColumn() == 0) {
                    if (file_exists(ctrl_options::GetSystemOption('hosted_dir') . $rowdeletedaccounts['ac_user_vc'])) {
                        fs_director::RemoveDirectory(ctrl_options::GetSystemOption('hosted_dir') . $rowdeletedaccounts['ac_user_vc']);
                    }
                }
            }
        }
    }
}
示例#10
0
 public static function Template()
 {
     if (!fs_director::CheckForEmptyValue(ctrl_options::GetSystemOption('server_ip'))) {
         return ctrl_options::GetSystemOption('server_ip');
     } else {
         return sys_monitoring::ServerIPAddress();
     }
 }
 public static function Template()
 {
     $currentuser = ctrl_users::GetUserDetail(ctrl_auth::CurrentUserID());
     if ($currentuser['lastlogon']) {
         return date(ctrl_options::GetSystemOption('sentora_df'), $currentuser['lastlogon']);
     } else {
         return "<: Never :>";
     }
 }
 static function getZpanelNews()
 {
     $handle = @file_get_contents(ctrl_options::GetSystemOption('news_url'));
     $content = $handle;
     if (!$content) {
         return false;
     }
     return ws_generic::JSONToArray($content, true);
 }
示例#13
0
 /**
  * Checks that the Server API given in the webservice request XML is valid and matches the one stored in the x_settings table.
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @return boolean
  */
 public function CheckServerAPIKey()
 {
     if ($this->wsdataarray['apikey'] != ctrl_options::GetSystemOption('apikey')) {
         runtime_hook::Execute('OnBadAPIKeyAuth');
         return false;
     } else {
         runtime_hook::Execute('OnGoodAPIKeyAuth');
         return true;
     }
 }
示例#14
0
function CheckZPanelLatestVersion()
{
    // Grab the latest version of ZPanel from the ZPanel API servers and cache it into the database.
    $live_version = ws_generic::ReadURLRequestResult(ctrl_options::GetSystemOption('update_url'));
    if (!$live_version) {
        return false;
    }
    $versionnumber = ws_generic::JSONToArray($live_version);
    ctrl_options::SetSystemOption('latestzpversion', $versionnumber[0]['version']);
    return true;
}
示例#15
0
 /**
  * Reports on whether a TCP port is listening for connections.
  * @author Pascal peyremorte
  * @param int $port The port number of which to check (eg. 25 for SMTP).
  * @return boolean
  */
 static function LocalPortStatus($port)
 {
     $timeout = ctrl_options::GetSystemOption('servicechk_to');
     $fp = @fsockopen('127.0.0.1', $port, $errno, $errstr, $timeout);
     if ($fp !== false) {
         fclose($fp);
         #do not leave the port open.
         return true;
     }
     return false;
 }
示例#16
0
 public static function getZpanelUpdates()
 {
     if (ctrl_options::GetSystemOption('dbversion') < ctrl_options::GetSystemOption('latestzpversion')) {
         $msg = ui_language::translate("There are currently new updates for your ZPanel installation, please download the latest release") . " (<strong>" . ctrl_options::GetSystemOption('latestzpversion') . "</strong>) from <a href=\"http://www.zpanelcp.com/\">http://www.zpanelcp.com/</a>.";
     } elseif (ctrl_options::GetSystemOption('dbversion') == ctrl_options::GetSystemOption('latestzpversion')) {
         $msg = "Congratulations, You are running the most recent version of ZPanel (<strong>" . ctrl_options::GetSystemOption('latestzpversion') . "</strong>)!";
     } else {
         $msg = "You appear to be running a BETA release, unless you are testing or developing we recommend you download and use the latest stable release (<strong>" . ctrl_options::GetSystemOption('latestzpversion') . "</strong>).";
     }
     return $msg;
 }
 public static function Template()
 {
     global $controller;
     if (!$controller->GetControllerRequest('URL', 'module')) {
         $line = "";
         $modcats = ui_moduleloader::GetModuleCats();
         foreach ($modcats as $modcat) {
             $mods = ui_moduleloader::GetModuleList($modcat['mc_id_pk'], "modadmin");
             if ($mods) {
                 $line .= "<table class=\"zcat\">";
                 $line .= "<tr>";
                 $line .= "<th align=\"left\">";
                 $line .= "<a name=\"" . str_replace(" ", "_", strtolower($modcat['mc_name_vc'])) . "\"></a>";
                 $line .= "" . ui_language::translate($modcat['mc_name_vc']) . "";
                 $line .= "<a href=\"#\" class=\"zcat\" id=\"zcat_" . str_replace(" ", "_", strtolower($modcat['mc_name_vc'])) . "_a\"></a>";
                 $line .= "</th>";
                 $line .= "</tr>";
                 $line .= "<tr>";
                 $line .= "<td align=\"left\">";
                 $line .= "<div class=\"zcat_" . str_replace(" ", "_", strtolower($modcat['mc_name_vc'])) . "\" id=\"zcat_" . str_replace(" ", "_", strtolower($modcat['mc_name_vc'])) . "\">";
                 $line .= "<table class=\"zcatcontent\" align=\"left\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
                 $line .= "<tr>";
                 $line .= "<td>";
                 $line .= "<table align=\"left\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
                 $line .= "<tr>";
                 $icons_per_row = ctrl_options::GetSystemOption('module_icons_pr');
                 $num_icons = 0;
                 foreach ($mods as $mod) {
                     //$translatename = '<: '.$mod['mo_name_vc'].' :>';
                     //$translatename = $mod['mo_name_vc'];
                     $translatename = ui_language::translate($mod['mo_name_vc']);
                     $cleanname = str_replace(" ", "ZP(br)", $translatename);
                     if ($num_icons == $icons_per_row) {
                         $line .= "</tr><tr>";
                         $num_icons = 0;
                     }
                     $line .= "<td style=\"text-align:center;\" align=\"left\">";
                     $line .= "<a href=\"?module=" . $mod['mo_folder_vc'] . "\" title=\"<: " . $mod['mo_desc_tx'] . " :>\">";
                     $line .= "<img src=\"modules/" . $mod['mo_folder_vc'] . "/assets/icon.png\" border=\"0\" />";
                     $line .= "</a>";
                     $line .= "<br />";
                     $line .= "<a href=\"?module=" . $mod['mo_folder_vc'] . "\">" . $cleanname . "</a>";
                     $line .= "</td>";
                     $num_icons++;
                 }
                 $line .= "</tr></table></td></tr></table></div></td></tr></table><br>";
             }
         }
         return $line;
     }
 }
 /**
  * Returns a list of all avaliable CSS styles for a given theme. If only a single CSS style then it will return false.
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @param string $template The template name (folder name) of which to check for extra CSS stlyes.
  * @return array List of avaliable CSS styles for this theme.
  */
 static function ListAvaliableCSS($template)
 {
     $allstyles = array();
     $handle = @opendir(ctrl_options::GetSystemOption('sentora_root') . "etc/styles/" . $template . "/css");
     $chkdir = ctrl_options::GetSystemOption('sentora_root') . "etc/styles/" . $template . "/css/";
     if ($handle) {
         while ($file = readdir($handle)) {
             if ($file != "." && $file != ".." && strtolower(substr($file, -4)) == ".css") {
                 if (is_file($chkdir . $file)) {
                     array_push($allstyles, array('name' => str_replace(".css", "", $file)));
                 }
             }
         }
         closedir($handle);
     }
     return $allstyles;
 }
 public static function getSentoraUpdates()
 {
     $installed = ctrl_options::GetSystemOption('dbversion');
     $lastest = ctrl_options::GetSystemOption('latestzpversion');
     $lastest_tagged = ' (<strong>' . $lastest . '</strong>)';
     if ($installed < $lastest) {
         $msg = ui_language::translate('There are currently new updates for your Sentora installation, please download the latest release') . $lastest_tagged . ' from <a href="http://www.sentora.org/">http://www.sentora.org/</a>.';
     } elseif ($installed == $lastest) {
         $msg = 'Congratulations, You are running the most recent version of Sentora' . $lastest_tagged . '!';
     } else {
         $msg = 'You are running a BETA release (<strong>' . $installed . '</strong>), thank you to report what you observed.<br>' . '<b>Do not use it for production.</b>';
         if ($latest >= '1.0.3') {
             $msg .= '<br><br>Unless you are testing or developing we recommend you to download and use the latest stable release' . $lastest_tagged . '.';
         }
     }
     return $msg;
 }
function WriteCronFile()
{
    global $zdbh;
    $line = "";
    $sql = "SELECT * FROM x_cronjobs WHERE ct_deleted_ts IS NULL";
    $numrows = $zdbh->query($sql);
    if ($numrows->fetchColumn() != 0) {
        $sql = $zdbh->prepare($sql);
        $sql->execute();
        $line .= "#################################################################################" . fs_filehandler::NewLine();
        $line .= "# CRONTAB FOR ZPANEL CRON MANAGER MODULE                                         " . fs_filehandler::NewLine();
        $line .= "# Module Developed by Bobby Allen, 17/12/2009                                    " . fs_filehandler::NewLine();
        $line .= "# Automatically generated by Sentora " . sys_versions::ShowSentoraVersion() . "      " . fs_filehandler::NewLine();
        $line .= "#################################################################################" . fs_filehandler::NewLine();
        $line .= "# WE DO NOT RECOMMEND YOU MODIFY THIS FILE DIRECTLY, PLEASE USE ZPANEL INSTEAD!  " . fs_filehandler::NewLine();
        $line .= "#################################################################################" . fs_filehandler::NewLine();
        if (sys_versions::ShowOSPlatformVersion() == "Windows") {
            $line .= "# Cron Debug infomation can be found in this file here:-                        " . fs_filehandler::NewLine();
            $line .= "# C:\\WINDOWS\\System32\\crontab.txt                                                " . fs_filehandler::NewLine();
            $line .= "#################################################################################" . fs_filehandler::NewLine();
            $line .= "" . ctrl_options::GetSystemOption('daemon_timing') . " " . ctrl_options::GetSystemOption('php_exer') . " " . ctrl_options::GetSystemOption('daemon_exer') . "" . fs_filehandler::NewLine();
            $line .= "#################################################################################" . fs_filehandler::NewLine();
        }
        $line .= "# DO NOT MANUALLY REMOVE ANY OF THE CRON ENTRIES FROM THIS FILE, USE ZPANEL      " . fs_filehandler::NewLine();
        $line .= "# INSTEAD! THE ABOVE ENTRIES ARE USED FOR ZPANEL TASKS, DO NOT REMOVE THEM!      " . fs_filehandler::NewLine();
        $line .= "#################################################################################" . fs_filehandler::NewLine();
        while ($rowcron = $sql->fetch()) {
            //$rowclient = $zdbh->query("SELECT * FROM x_accounts WHERE ac_id_pk=" . $rowcron['ct_acc_fk'] . " AND ac_deleted_ts IS NULL")->fetch();
            $numrows = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_id_pk=:userid AND ac_deleted_ts IS NULL");
            $numrows->bindParam(':userid', $rowcron['ct_acc_fk']);
            $numrows->execute();
            $rowclient = $numrows->fetch();
            if ($rowclient && $rowclient['ac_enabled_in'] != 0) {
                $line .= "# CRON ID: " . $rowcron['ct_id_pk'] . "" . fs_filehandler::NewLine();
                $line .= "" . $rowcron['ct_timing_vc'] . " " . ctrl_options::GetSystemOption('php_exer') . " " . $rowcron['ct_fullpath_vc'] . "" . fs_filehandler::NewLine();
                $line .= "# END CRON ID: " . $rowcron['ct_id_pk'] . "" . fs_filehandler::NewLine();
            }
        }
        if (fs_filehandler::UpdateFile(ctrl_options::GetSystemOption('cron_file'), 0777, $line)) {
            return true;
        } else {
            return false;
        }
    }
}
 /**
  * Executes a hook file at the called position.
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @param string $name The name of the hook of which to execute.
  */
 static function Execute($name)
 {
     $hook_log = new debug_logger();
     $mod_folder = "modules/*/hooks/{" . $name . ".hook.php}";
     $hook_log->method = ctrl_options::GetSystemOption('logmode');
     $hook_log->logcode = "861";
     foreach (glob($mod_folder, GLOB_BRACE) as $hook_file) {
         if (file_exists($hook_file)) {
             $hook_log->detail = "Execute hook file (" . $hook_file . ")";
             try {
                 include $hook_file;
             } catch (Exception $e) {
                 $hook_log->detail .= ' -> Exception(' . $e->getMessage() . ') :(';
             }
             $hook_log->writeLog();
         }
     }
 }
 /**
  * Reports on whether a TCP or UDP port is listening for connections.
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @param int $port The port number of which to check (eg. 25 for SMTP).
  * @param boolean $udp Port is a UDP port as opposed to a TCP port.
  * @return boolean 
  */
 static function PortStatus($port, $udp = false)
 {
     $timeout = ctrl_options::GetSystemOption('servicechk_to');
     if ($udp) {
         $ip = 'udp://' . $_SERVER['SERVER_ADDR'];
     } else {
         $ip = $_SERVER['SERVER_ADDR'];
     }
     $fp = @fsockopen($ip, $port, $errno, $errstr, $timeout);
     if (!$fp) {
         runtime_hook::Execute('OnPortStatusDown');
         $retval = false;
     } else {
         runtime_hook::Execute('OnPortStatusUp');
         $retval = true;
     }
     return $retval;
 }
示例#23
0
function CheckMADminLatestVersion()
{
    // Grab the latest version of MADmin from the MADmin API servers and cache it into the database.
    $live_version = ws_generic::ReadURLRequestResult(ctrl_options::GetSystemOption('update_url'));
    if (!$live_version) {
        return false;
    }
    $versionnumber = ws_generic::JSONToArray($live_version);
    # MADmin API returns simple object not in an array like it was for zpanel.
    #    if(count($versionnumber) > 1) {
    #        $currentVersionSetting = current($versionnumber);
    #        $currentVersion = $currentVersionSetting['version'];
    #    } else {
    $currentVersion = $versionnumber['version'];
    #    }
    ctrl_options::SetSystemOption('latestzpversion', $currentVersion);
    return true;
}
function TriggerDNSUpdate($id)
{
    global $zdbh;
    $GetRecords = ctrl_options::GetSystemOption('dns_hasupdates');
    $records = explode(",", $GetRecords);
    foreach ($records as $record) {
        $RecordArray[] = $record;
    }
    if (!in_array($id, $RecordArray)) {
        $newlist = $GetRecords . "," . $id;
        $newlist = str_replace(",,", ",", $newlist);
        $sql = "UPDATE x_settings SET so_value_tx=:newlist WHERE so_name_vc='dns_hasupdates'";
        $sql = $zdbh->prepare($sql);
        $sql->bindParam(':newlist', $newlist);
        $sql->execute();
        return true;
    }
}
function DeleteFTPForDeletedClient()
{
    global $zdbh;
    global $controller;
    $deletedclients = array();
    $sql = "SELECT COUNT(*) FROM x_accounts WHERE ac_deleted_ts IS NOT NULL";
    if ($numrows = $zdbh->query($sql)) {
        if ($numrows->fetchColumn() != 0) {
            $sql = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_deleted_ts IS NOT NULL");
            $sql->execute();
            while ($rowclient = $sql->fetch()) {
                $deletedclients[] = $rowclient['ac_id_pk'];
            }
        }
    }
    // Include FTP server specific file here.
    if (file_exists("modules/ftp_management/hooks/" . ctrl_options::GetSystemOption('ftp_php') . "")) {
        include "modules/ftp_management/hooks/" . ctrl_options::GetSystemOption('ftp_php') . "";
    }
}
示例#26
0
 /**
  * Writes the log infomation out to a predefined logging medium (from $this->method)
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @global db_driver $zdbh The ZPX database handle.
  * @return boolean 
  */
 function writeLog()
 {
     global $zdbh;
     runtime_hook::Execute('OnWriteErrorLog');
     if ($this->method == "screen") {
         die($this->logcode . ' - ' . $this->detail);
     } elseif ($this->method == "file") {
         fs_filehandler::AddTextToFile(ctrl_options::GetSystemOption('logfile'), date('c') . ' - ' . $this->logcode . ' - ' . $this->detail, 1);
     } elseif ($this->method == "email") {
         $email_log = new sys_email();
         $email_log->Subject = "Sentora Error Log";
         $email_log->Body = "" . date('c') . ' - ' . $this->logcode . ' - ' . $this->detail . "";
         $email_log->AddAddress(ctrl_options::GetSystemOption('email_from_address'));
         $email_log->SendEmail();
     } elseif ($this->method == "db") {
         $statement = "INSERT INTO x_logs (lg_user_fk, lg_code_vc, lg_module_vc, lg_detail_tx, lg_stack_tx) VALUES (0, '" . $this->logcode . "', 'NA', '" . $this->detail . "', '" . $this->mextra . "')";
         if ($zdbh->exec($statement)) {
             $retval = true;
         } else {
             $retval = false;
         }
         try {
             $statement = "INSERT INTO x_logs (lg_user_fk, lg_code_vc, lg_module_vc, lg_detail_tx, lg_stack_tx, lg_when_ts) VALUES (0, '" . $this->logcode . "', 'NA', '" . $this->detail . "', '" . $this->mextra . "','" . time() . "')";
             if ($zdbh->exec($statement) > 0) {
                 $retval = true;
             } else {
                 $retval = false;
             }
         } catch (Exception $e) {
             $temp_log_obj->method = "text";
             $temp_log_obj->logcode = "012";
             $temp_log_obj->detail = "Unable to log infomation to the required place (in the database)";
             $temp_log_obj->mextra = $e;
             $temp_log_obj->writeLog();
         }
         return true;
     } else {
         echo $this->logcode . " - " . $this->detail . " - " . $this->mextra;
     }
     return;
 }
function DeleteParkedDomainsForDeletedClient()
{
    global $zdbh;
    $deletedclients = array();
    $sql = "SELECT COUNT(*) FROM x_accounts WHERE ac_deleted_ts IS NOT NULL";
    if ($numrows = $zdbh->query($sql)) {
        if ($numrows->fetchColumn() != 0) {
            $sql = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_deleted_ts IS NOT NULL");
            $sql->execute();
            while ($rowclient = $sql->fetch()) {
                $deletedclients[] = $rowclient['ac_id_pk'];
            }
        }
    }
    foreach ($deletedclients as $deletedclient) {
        $deletedir = false;
        //$result = $zdbh->query("SELECT * FROM x_vhosts WHERE vh_acc_fk=" . $deletedclient . " AND vh_type_in=3 AND vh_deleted_ts IS NULL")->Fetch();
        $numrows = $zdbh->prepare("SELECT * FROM x_vhosts WHERE vh_acc_fk=:deletedclient AND vh_type_in=3 AND vh_deleted_ts IS NULL");
        $numrows->bindParam(':deletedclient', $deletedclient);
        $numrows->execute();
        $result = $numrows->fetch();
        if ($result) {
            $sql = $zdbh->prepare("UPDATE x_vhosts SET vh_deleted_ts=:time WHERE vh_acc_fk=:deletedclient AND vh_type_in=3");
            $time = time();
            $sql->bindParam(':time', $time);
            $sql->bindParam(':deletedclient', $deletedclient);
            $sql->execute();
            $deletedir = true;
        }
        if ($deletedir == true) {
            $currentuser = ctrl_users::GetUserDetail($deletedclient);
            if (is_dir(ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'])) {
                fs_filehandler::RemoveDirectory(ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username']);
            }
        }
    }
}
 static function CheckZoneRecord($domainID)
 {
     global $zdbh;
     $hasrecords = false;
     $sql = 'SELECT COUNT(*) FROM x_dns WHERE dn_vhost_fk=:domainID AND dn_deleted_ts IS NULL';
     $numrows = $zdbh->prepare($sql);
     $numrows->bindParam(':domainID', $domainID);
     if ($numrows->execute()) {
         if ($numrows->fetchColumn() != 0) {
             $hasrecords = true;
             $sql = $zdbh->prepare("SELECT * FROM x_dns WHERE dn_vhost_fk=:domainID AND dn_deleted_ts IS NULL ORDER BY dn_type_vc");
             $sql->bindParam(':domainID', $domainID);
             $sql->execute();
             $numrows = $zdbh->prepare("SELECT dn_name_vc FROM x_dns WHERE dn_vhost_fk=:domainID AND dn_deleted_ts IS NULL");
             $numrows->bindParam(':domainID', $domainID);
             $numrows->execute();
             $domain = $numrows->fetch();
             $zonecheck_file = ctrl_options::GetSystemOption('temp_dir') . $domain['dn_name_vc'] . ".txt";
             $checkline = "\$" . "TTL 10800" . fs_filehandler::NewLine();
             $checkline .= "@ IN SOA " . $domain['dn_name_vc'] . ". ";
             $checkline .= "postmaster." . $domain['dn_name_vc'] . ". (" . fs_filehandler::NewLine();
             $checkline .= " " . date("Ymdt") . " ;serial" . fs_filehandler::NewLine();
             $checkline .= " " . ctrl_options::GetSystemOption('refresh_ttl') . " ;refresh after 6 hours" . fs_filehandler::NewLine();
             $checkline .= " " . ctrl_options::GetSystemOption('retry_ttl') . " ;retry after 1 hour" . fs_filehandler::NewLine();
             $checkline .= " " . ctrl_options::GetSystemOption('expire_ttl') . " ;expire after 1 week" . fs_filehandler::NewLine();
             $checkline .= " " . ctrl_options::GetSystemOption('minimum_ttl') . " ) ;minimum TTL of 1 day" . fs_filehandler::NewLine();
             while ($rowdns = $sql->fetch()) {
                 if ($rowdns['dn_type_vc'] == "A") {
                     $checkline .= $rowdns['dn_host_vc'] . " " . $rowdns['dn_ttl_in'] . " IN A " . $rowdns['dn_target_vc'] . fs_filehandler::NewLine();
                 }
                 if ($rowdns['dn_type_vc'] == "AAAA") {
                     $checkline .= $rowdns['dn_host_vc'] . " " . $rowdns['dn_ttl_in'] . " IN AAAA " . $rowdns['dn_target_vc'] . fs_filehandler::NewLine();
                 }
                 if ($rowdns['dn_type_vc'] == "CNAME") {
                     $checkline .= $rowdns['dn_host_vc'] . " " . $rowdns['dn_ttl_in'] . " IN CNAME " . $rowdns['dn_target_vc'] . fs_filehandler::NewLine();
                 }
                 if ($rowdns['dn_type_vc'] == "MX") {
                     $checkline .= $rowdns['dn_host_vc'] . " " . $rowdns['dn_ttl_in'] . " IN MX " . $rowdns['dn_priority_in'] . " " . $rowdns['dn_target_vc'] . "." . fs_filehandler::NewLine();
                 }
                 if ($rowdns['dn_type_vc'] == "TXT") {
                     $checkline .= $rowdns['dn_host_vc'] . " " . $rowdns['dn_ttl_in'] . " IN TXT \"" . stripslashes($rowdns['dn_target_vc']) . "\"" . fs_filehandler::NewLine();
                 }
                 if ($rowdns['dn_type_vc'] == "SRV") {
                     $checkline .= $rowdns['dn_host_vc'] . " " . $rowdns['dn_ttl_in'] . " IN SRV " . $rowdns['dn_priority_in'] . " " . $rowdns['dn_weight_in'] . " " . $rowdns['dn_port_in'] . " " . $rowdns['dn_target_vc'] . "." . fs_filehandler::NewLine();
                 }
                 if ($rowdns['dn_type_vc'] == "SPF") {
                     $checkline .= $rowdns['dn_host_vc'] . " " . $rowdns['dn_ttl_in'] . " IN SPF \"" . stripslashes($rowdns['dn_target_vc']) . "\"" . fs_filehandler::NewLine();
                 }
                 if ($rowdns['dn_type_vc'] == "NS") {
                     $checkline .= $rowdns['dn_host_vc'] . " " . $rowdns['dn_ttl_in'] . " IN NS " . $rowdns['dn_target_vc'] . "." . fs_filehandler::NewLine();
                 }
             }
             fs_filehandler::UpdateFile($zonecheck_file, 0777, $checkline);
         }
     }
     if ($hasrecords == true) {
         //Check the temp zone record for errors
         if (file_exists($zonecheck_file)) {
             ob_start();
             $command = ctrl_options::GetSystemOption('named_checkzone');
             $args = array($domain['dn_name_vc'], $zonecheck_file);
             $retval = ctrl_system::systemCommand($command, $args);
             $content_grabbed = ob_get_contents();
             ob_end_clean();
             unlink($zonecheck_file);
             if ($retval == 0) {
                 //Syntax check passed.
                 return $content_grabbed;
             } else {
                 //Syntax ERROR.
                 return $content_grabbed;
             }
         }
     }
 }
示例#29
0
function TriggerApacheQuotaUsage()
{
    global $zdbh;
    global $controller;
    $sql = $zdbh->prepare("SELECT * FROM x_vhosts WHERE vh_deleted_ts IS NULL");
    $sql->execute();
    while ($rowvhost = $sql->fetch()) {
        if ($rowvhost['vh_enabled_in'] == 1 && ctrl_users::CheckUserEnabled($rowvhost['vh_acc_fk']) || $rowvhost['vh_enabled_in'] == 1 && ctrl_options::GetSystemOption('apache_allow_disabled') == strtolower("true")) {
            //$checksize = $zdbh->query("SELECT * FROM x_bandwidth WHERE bd_month_in = " . date("Ym") . " AND bd_acc_fk = " . $rowvhost['vh_acc_fk'] . "")->fetch();
            $date = date("Ym");
            $findsize = $zdbh->prepare("SELECT * FROM x_bandwidth WHERE bd_month_in = :date AND bd_acc_fk = :acc");
            $findsize->bindParam(':date', $date);
            $findsize->bindParam(':acc', $rowvhost['vh_acc_fk']);
            $findsize->execute();
            $checksize = $findsize->fetch();
            $currentuser = ctrl_users::GetUserDetail($rowvhost['vh_acc_fk']);
            if ($checksize['bd_diskover_in'] != $checksize['bd_diskcheck_in'] && $checksize['bd_diskover_in'] == 1) {
                echo "Disk usage over quota, triggering Apache..." . fs_filehandler::NewLine();
                $updateapache = $zdbh->prepare("UPDATE x_settings SET so_value_tx = 'true' WHERE so_name_vc ='apache_changed'");
                $updateapache->execute();
                //$updateapache = $zdbh->query("UPDATE x_bandwidth SET bd_diskcheck_in = 1 WHERE bd_acc_fk =" . $rowvhost['vh_acc_fk'] . "");
                $updateapache2 = $zdbh->prepare("UPDATE x_bandwidth SET bd_diskcheck_in = 1 WHERE bd_acc_fk = :acc");
                $updateapache2->bindParam(':acc', $rowvhost['vh_acc_fk']);
                $updateapache2->execute();
            }
            if ($checksize['bd_diskover_in'] != $checksize['bd_diskcheck_in'] && $checksize['bd_diskover_in'] == 0) {
                echo "Disk usage under quota, triggering Apache..." . fs_filehandler::NewLine();
                $updateapache = $zdbh->prepare("UPDATE x_settings SET so_value_tx = 'true' WHERE so_name_vc ='apache_changed'");
                $updateapache->execute();
                //$updateapache = $zdbh->query("UPDATE x_bandwidth SET bd_diskcheck_in = 0 WHERE bd_acc_fk =" . $rowvhost['vh_acc_fk'] . "");
                $updateapache2 = $zdbh->prepare("UPDATE x_bandwidth SET bd_diskcheck_in = 0 WHERE bd_acc_fk = :acc");
                $updateapache2->bindParam(':acc', $rowvhost['vh_acc_fk']);
                $updateapache2->execute();
            }
            if ($checksize['bd_transover_in'] != $checksize['bd_transcheck_in'] && $checksize['bd_transover_in'] == 1) {
                echo "Bandwidth usage over quota, triggering Apache..." . fs_filehandler::NewLine();
                $updateapache = $zdbh->prepare("UPDATE x_settings SET so_value_tx = 'true' WHERE so_name_vc ='apache_changed'");
                $updateapache->execute();
                //$updateapache = $zdbh->query("UPDATE x_bandwidth SET bd_transcheck_in = 1 WHERE bd_acc_fk =" . $rowvhost['vh_acc_fk'] . "");
                $updateapache2 = $zdbh->prepare("UPDATE x_bandwidth SET bd_transcheck_in = 1 WHERE bd_acc_fk = :acc");
                $updateapache2->bindParam(':acc', $rowvhost['vh_acc_fk']);
                $updateapache2->execute();
            }
            if ($checksize['bd_transover_in'] != $checksize['bd_transcheck_in'] && $checksize['bd_transover_in'] == 0) {
                echo "Bandwidth usage under quota, triggering Apache..." . fs_filehandler::NewLine();
                $updateapache = $zdbh->prepare("UPDATE x_settings SET so_value_tx = 'true' WHERE so_name_vc ='apache_changed'");
                $updateapache->execute();
                //$updateapache = $zdbh->query("UPDATE x_bandwidth SET bd_transcheck_in = 0 WHERE bd_acc_fk =" . $rowvhost['vh_acc_fk'] . "");
                $updateapache2 = $zdbh->prepare("UPDATE x_bandwidth SET bd_transcheck_in = 0 WHERE bd_acc_fk = :acc");
                $updateapache2->bindParam(':acc', $rowvhost['vh_acc_fk']);
                $updateapache2->execute();
            }
        }
    }
}
示例#30
0
 *
 * This program (ZPanel) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
$mailserver_db = ctrl_options::GetSystemOption('mailserver_db');
include 'cnf/db.php';
$z_db_user = $user;
$z_db_pass = $pass;
try {
    $mail_db = new db_driver("mysql:host=" . $host . ";dbname=" . $mailserver_db . "", $z_db_user, $z_db_pass);
} catch (PDOException $e) {
}
// Deleting Postfix Distubution List
if (!fs_director::CheckForEmptyValue(self::$delete)) {
    //$result = $mail_db->query("SELECT address FROM alias WHERE address='" . $rowdl['dl_address_vc'] . "'")->Fetch();
    $numrows = $mail_db->prepare("SELECT address FROM alias WHERE address=:dl_address_vc");
    $numrows->bindParam(':dl_address_vc', $rowdl['dl_address_vc']);
    $numrows->execute();
    $result = $numrows->fetch();
    if ($result) {