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);
    }
}
Example #2
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();
    }
}
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;
        }
    }
}
Example #4
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;
 }
Example #5
0
 static function getCheckUpdate()
 {
     global $zdbh, $controller, $zlo;
     $module_path = "./modules/" . $controller->GetControllerRequest('URL', 'module');
     // Get Update URL and Version From module.xml
     $mod_xml = "./modules/" . $controller->GetControllerRequest('URL', 'module') . "/module.xml";
     $mod_config = new xml_reader(fs_filehandler::ReadFileContents($mod_xml));
     $mod_config->Parse();
     $module_updateurl = $mod_config->document->updateurl[0]->tagData;
     $module_version = $mod_config->document->version[0]->tagData;
     // Download XML in Update URL and get Download URL and Version
     $myfile = check_remote_xml($module_updateurl, $module_path . "/" . $controller->GetControllerRequest('URL', 'module') . ".xml");
     $update_config = new xml_reader(fs_filehandler::ReadFileContents($module_path . "/" . $controller->GetControllerRequest('URL', 'module') . ".xml"));
     $update_config->Parse();
     $update_url = $update_config->document->downloadurl[0]->tagData;
     $update_version = $update_config->document->latestversion[0]->tagData;
     if ($update_version > $module_version) {
         return true;
     }
     return false;
 }
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']);
            }
        }
    }
}
 /**
  * @return string
  */
 protected function newLine()
 {
     return fs_filehandler::NewLine();
 }
Example #8
0
 /**
  * Returns an array of the XML tags from the module.xml file.
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @global obj $zlo The Generic ZPX logging object.
  * @param string $modulefolder The module folder name of which to import the XML data from.
  * @return mixed Will an array of the module XML data if the parsing of the document is successful otherwise will return 'false'.
  */
 static function GetModuleXMLTags($modulefolder)
 {
     global $zlo;
     $mod_xml = "modules/{$modulefolder}/module.xml";
     $info = array();
     try {
         $mod_config = new xml_reader(fs_filehandler::ReadFileContents($mod_xml));
         $mod_config->Parse();
         $info['name'] = $mod_config->document->name[0]->tagData;
         $info['version'] = $mod_config->document->version[0]->tagData;
         $info['desc'] = $mod_config->document->desc[0]->tagData;
         $info['authorname'] = $mod_config->document->authorname[0]->tagData;
         $info['authoremail'] = $mod_config->document->authoremail[0]->tagData;
         $info['authorurl'] = $mod_config->document->authorurl[0]->tagData;
         $info['updateurl'] = $mod_config->document->updateurl[0]->tagData;
         return $info;
     } catch (Exception $e) {
         return false;
     }
 }
 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;
             }
         }
     }
 }
        if (!fs_director::CheckForEmptyValue($bandwidth)) {
            //$zdbh->query("UPDATE x_bandwidth SET bd_transamount_bi=(bd_transamount_bi+" . $bandwidth . ") WHERE bd_acc_fk = " . $domain['vh_acc_fk'] . " AND bd_month_in = " . date("Ym") . "");
            $numrows = $zdbh->prepare("UPDATE x_bandwidth SET bd_transamount_bi=(bd_transamount_bi+:bandwidth) WHERE bd_acc_fk = :vh_acc_fk AND bd_month_in = :date");
            $numrows->bindParam(':bandwidth', $bandwidth);
            $date = date("Ym");
            $numrows->bindParam(':date', $date);
            $numrows->bindParam(':vh_acc_fk', $domain['vh_acc_fk']);
            $numrows->execute();
        } else {
            echo "No bandwidth used, skipping!" . fs_filehandler::NewLine();
        }
        //$checksize = $zdbh->query("SELECT * FROM x_bandwidth WHERE bd_month_in = " . date("Ym") . " AND bd_acc_fk = " . $domain['vh_acc_fk'] . "")->fetch();
        $numrows = $zdbh->prepare("SELECT * FROM x_bandwidth WHERE bd_month_in = :date AND bd_acc_fk = :vh_acc_fk");
        $date = date("Ym");
        $numrows->bindParam(':date', $date);
        $numrows->bindParam(':vh_acc_fk', $domain['vh_acc_fk']);
        $numrows->execute();
        $checksize = $numrows->fetch();
        if ($checksize['bd_transamount_bi'] > $domainowner['bandwidthquota']) {
            $updatesql = $zdbh->prepare("UPDATE x_bandwidth SET bd_transover_in = 1 WHERE bd_acc_fk = :vh_acc_fk");
            $updatesql->bindParam(':vh_acc_fk', $domain['vh_acc_fk']);
            $updatesql->execute();
        } else {
            $updatesql = $zdbh->prepare("UPDATE x_bandwidth SET bd_transover_in = 0 WHERE bd_acc_fk =:vh_acc_fk");
            $updatesql->bindParam(':vh_acc_fk', $domain['vh_acc_fk']);
            $updatesql->execute();
        }
    }
}
echo "END Calculating bandwidth usage" . fs_filehandler::NewLine();
 static function CheckCronForErrors()
 {
     global $zdbh;
     global $controller;
     $retval = FALSE;
     //Try to create the cron file if it doesnt exist...
     if (!file_exists(ctrl_options::GetSystemOption('cron_file'))) {
         fs_filehandler::UpdateFile(ctrl_options::GetSystemOption('cron_file'), 0644, "");
     }
     $currentuser = ctrl_users::GetUserDetail();
     // Check to make sure the cron is not blank before we go any further...
     if ($controller->GetControllerRequest('FORM', 'inScript') == '') {
         self::$blank = TRUE;
         $retval = TRUE;
     }
     // Check to make sure the cron script exists before we go any further...
     if (!is_file(fs_director::RemoveDoubleSlash(fs_director::ConvertSlashes(ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . '/public_html/' . $controller->GetControllerRequest('FORM', 'inScript'))))) {
         self::$noexists = TRUE;
         $retval = TRUE;
     }
     // Check to see if creating system cron file was successful...
     if (!is_file(ctrl_options::GetSystemOption('cron_file'))) {
         self::$cronnoexists = TRUE;
         $retval = TRUE;
     }
     // Check to makesystem cron file is writable...
     if (!is_writable(ctrl_options::GetSystemOption('cron_file'))) {
         self::$cronnowrite = TRUE;
         $retval = TRUE;
     }
     // Check to make sure the cron is not a duplicate...
     $sql = "SELECT COUNT(*) FROM x_cronjobs WHERE ct_acc_fk=:userid AND ct_script_vc=:inScript AND ct_deleted_ts IS NULL";
     $numrows = $zdbh->prepare($sql);
     $numrows->bindParam(':userid', $currentuser['userid']);
     $numrows->bindParam(':inScript', $controller->GetControllerRequest('FORM', 'inScript'));
     if ($numrows->execute()) {
         if ($numrows->fetchColumn() != 0) {
             self::$alreadyexists = TRUE;
             $retval = TRUE;
         }
     }
     return $retval;
 }
 /**
  * This adds text data into a specified file. This can be before the start or at the end of the file.
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @param string $file The system path to the file.
  * @param string $content The content to add to the file.
  * @param int $pos Where to add the text. (0 = At the start, 1 = At the end of the file)
  */
 static function AddTextToFile($file, $content, $pos)
 {
     $current_version = @fs_filehandler::ReadFileContents($file);
     if ($pos == 0) {
         $new_version = $content . fs_filehandler::NewLine() . $current_version;
     } else {
         $new_version = $current_version . fs_filehandler::NewLine() . $content;
     }
     fs_filehandler::UpdateFile($file, 0777, $new_version);
 }
Example #13
0
<?php

/**
 * Hook created by Bobby Allen to obtain latest zpanel version number and add it to the DB for querying (caching bascially!)
 * This script is handy for caching the latest version of ZPanel to reduce bandwidth from the server.
 * 
 */
echo fs_filehandler::NewLine() . "START ZPanel Updates hook" . fs_filehandler::NewLine();
echo "Checking for latest version of ZPanel..." . fs_filehandler::NewLine();
CheckZPanelLatestVersion();
echo "END ZPanel Updates hook" . fs_filehandler::NewLine();
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;
}
Example #14
0
 static function getPackageSelection()
 {
     global $controller;
     $toReturn = "";
     $packages = new xml_reader(fs_filehandler::ReadFileContents("./modules/" . $controller->GetControllerRequest('URL', 'module') . "/packages/packages.xml"));
     $packages->Parse();
     $toReturn .= "\n\t\t(Sortable columns - click on column header)\n\t\t<table class=\"table table-striped sortable\" border=\"0\" width=\"100%\">\n\t\t  <tr>\n\t\t\t<th>" . ui_language::translate("Package") . "<br />\n\t\t\t" . ui_language::translate("Name") . "</th>\n\t\t\t<th>" . ui_language::translate("Version") . "<br />\n\t\t\t" . ui_language::translate("Number") . "</th>\n\t\t\t<th>" . ui_language::translate("Package") . "<br />\n\t\t\t" . ui_language::translate("Type") . "</th>\n\t\t\t<th>" . ui_language::translate("Package") . "<br />\n\t\t\t" . ui_language::translate("Description") . "</th>\n\t\t\t<th>" . ui_language::translate("Database") . "<br />\n\t\t\t" . ui_language::translate("Required") . "?</th>\n\t\t\t<th>&nbsp;</th>\n\t\t  </tr>";
     foreach ($packages->document->package as $package) {
         // START - Info and DB tags by tgates
         if ($package->db[0]->tagData == 'yes') {
             $package->pkgdb[0]->tagData = "yes";
         } else {
             $package->pkgdb[0]->tagData = "no";
         }
         if ($package->db[0]->tagData == 'yes') {
             $package->db[0]->tagData = "<font color='green'><strong>" . ui_language::translate("YES") . "</strong></font>";
         } else {
             $package->db[0]->tagData = "<font color='red'><strong>" . ui_language::translate("NO") . "</strong></font>";
         }
         // END - Info and DB tags by tgates
         $toReturn .= "<tr>\n\t\t\t<td>" . $package->name[0]->tagData . "</td>\n\t\t\t<td>" . $package->version[0]->tagData . "</td>\n\t\t\t<td>" . $package->type[0]->tagData . "</td>\n\t\t\t<td>" . $package->info[0]->tagData . "</td>\n\t\t\t<td><center>" . $package->db[0]->tagData . "</center></td>\n\t\t\t<td>\n\t\t\t\t<form id=\"install\" name=\"Install\" action=\"/?module=sentastico\" method=\"post\">\n\t\t\t\t<input type=\"hidden\" name=\"startinstall\" value=\"true\"> \n\t\t\t\t<input type=\"hidden\" name=\"pkgzip\" value=" . $package->zipname[0]->tagData . "> \n\t\t\t\t<input type=\"hidden\" name=\"pkg\" value='" . $package->name[0]->tagData . "'> \n\t\t\t\t<input type=\"hidden\" name=\"pkgdb\" value=" . $package->pkgdb[0]->tagData . "> \n\t\t\t\t<input class=\"btn btn-primary btn-small\" type=\"submit\" name=\"doInstall\" value=" . ui_language::translate("Install") . " />\n\t\t\t\t</form>\n\t\t\t</td>\n\t\t</tr>";
     }
     return $toReturn;
 }
Example #15
0
<?php

/**
 * @copyright 2014-2015 MADmin Project (http://www.MADmin.org/) 
 * MADmin is a GPL fork of the ZPanel Project whose original header follows:
 *
 * Hook created by Bobby Allen to obtain latest zpanel version number and add it to the DB for querying (caching bascially!)
 * This script is handy for caching the latest version of ZPanel to reduce bandwidth from the server.
 * 
 */
echo fs_filehandler::NewLine() . "START MADmin Updates hook" . fs_filehandler::NewLine();
echo "Checking for latest version of MADmin..." . fs_filehandler::NewLine();
CheckMADminLatestVersion();
echo "END MADmin Updates hook" . fs_filehandler::NewLine();
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;
 /**
  * Builds database schema from the module XML file (dbs.xml)
  * @author Russell Skinner (rustus@sentora.org)
  * @global db_driver $zdbh The ZPX database handle.
  */
 static function moduledb_commit()
 {
     global $zdbh;
     $mod_db_dir = ctrl_options::GetSystemOption('sentora_root') . "modules/*/{dbs.xml}";
     try {
         foreach (glob($mod_db_dir, GLOB_BRACE) as $mod_db_file) {
             $db_config = new xml_reader(fs_filehandler::ReadFileContents($mod_db_file));
             $db_config->Parse();
             $database = $db_config->document->database[0]->tagData;
             $sql = $zdbh->prepare("CREATE DATABASE IF NOT EXISTS {$database}");
             $sql->execute();
             foreach ($db_config->document->table_structure as $table) {
                 $table_name = $table->table_name[0]->tagData;
                 // Check if table exists, if not then create it.
                 $sql = $zdbh->prepare("SHOW TABLES FROM {$database} LIKE '{$table_name}'");
                 $sql->execute();
                 $table_exists = $sql->fetch();
                 if (!$table_exists) {
                     $sql = $zdbh->prepare("CREATE TABLE {$database}.{$table_name} (create_temp INT)");
                     $sql->execute();
                 }
                 // Loop through columnns for selected table
                 foreach ($table->column as $data) {
                     $column_name = $data->column_name[0]->tagData;
                     $column_structure = $data->column_structure[0]->tagData;
                     $sql = $zdbh->prepare("SHOW COLUMNS FROM {$database}.{$table_name} LIKE '{$column_name}'");
                     $sql->execute();
                     $column_exists = $sql->fetch();
                     if (!$column_exists) {
                         $sql = $zdbh->prepare("ALTER TABLE {$database}.{$table_name} ADD {$column_name} {$column_structure}");
                         $sql->execute();
                     }
                 }
                 // Populate tables with data from xml
                 $sql = $zdbh->prepare("SELECT COUNT(*) FROM {$database}.{$table_name}");
                 $sql->execute();
                 $empty = $sql->fetch();
                 if ($empty[0] == 0) {
                     // Loop through inserts/updates for selected table
                     foreach ($table->data as $data) {
                         if (!empty($data->insert[0])) {
                             $insert = $data->insert[0]->tagData;
                             $sql = $zdbh->prepare("INSERT INTO {$database}.{$table_name} {$insert}");
                             $sql->execute();
                         }
                         if (!empty($data->update[0])) {
                             $update = $data->update[0]->tagData;
                             $sql = $zdbh->prepare("UPDATE {$database}.{$table_name} SET {$update}");
                             $sql->execute();
                         }
                     }
                 }
                 // Remove temp table if created.
                 $sql = $zdbh->prepare("SHOW COLUMNS FROM {$database}.{$table_name} LIKE 'create_temp'");
                 $sql->execute();
                 $table_exists = $sql->fetch();
                 if ($table_exists) {
                     $sql = $zdbh->prepare("ALTER TABLE {$database}.{$table_name} DROP create_temp");
                     $sql->execute();
                 }
             }
         }
     } catch (Exception $e) {
         echo ui_sysmessage::shout($e, 'zdebug', 'zdebug');
     }
     return;
 }
<?php

echo fs_filehandler::NewLine() . "START MySQL Databases hook" . fs_filehandler::NewLine();
echo "Calculating the total size of all MySQL databases...." . fs_filehandler::NewLine();
CalculateAllDatabaseSize();
echo "END MySQL Databases hook" . fs_filehandler::NewLine();
/*
 * Calculate the total size of all MySQL database.
 */
function CalculateAllDatabaseSize()
{
    global $zdbh;
    include 'cnf/db.php';
    $z_db_user = $user;
    $z_db_pass = $pass;
    $mysqlsql = $zdbh->query("SELECT my_id_pk, my_name_vc FROM x_mysql_databases WHERE my_deleted_ts IS NULL");
    while ($database = $mysqlsql->fetch()) {
        $currentdb = new db_driver("mysql:host={$host};dbname=" . $database['my_name_vc'] . "", $z_db_user, $z_db_pass);
        $currentdb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $dbsize = $currentdb->query("SHOW TABLE STATUS");
        $dbgetsize = 0;
        while ($row = $dbsize->fetch()) {
            $dbgetsize = $dbgetsize + ($row['Data_length'] + $row['Index_length']);
        }
        //$zdbh->query("UPDATE x_mysql_databases SET my_usedspace_bi = '" . $dbgetsize . "' WHERE my_id_pk =" . $database['my_id_pk'] . "");
        $numrows = $zdbh->prepare("UPDATE x_mysql_databases SET my_usedspace_bi = :dbgetsize WHERE my_id_pk =:my_id_pk");
        $numrows->bindParam(':dbgetsize', $dbgetsize);
        $numrows->bindParam(':my_id_pk', $database['my_id_pk']);
        $numrows->execute();
        //echo "Database found: " . $database['my_name_vc'] . " - " . $dbgetsize . " \n";
    }
 static function WriteCronFile()
 {
     global $zdbh;
     $currentuser = ctrl_users::GetUserDetail();
     $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();
             // removed openbase_dir and suhosin directives from daemon run - daemon now runs just fine on windows
             //$line .= "" . ctrl_options::GetSystemOption('daemon_timing') . " " . ctrl_options::GetSystemOption('php_exer') . " -d suhosin.executor.func.blacklist=\"passthru, show_source, shell_exec, system, pcntl_exec, popen, pclose, proc_open, proc_nice, proc_terminate, proc_get_status, proc_close, leak, apache_child_terminate, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid, posix_setuid, escapeshellcmd, escapeshellarg, exec\" -d open_basedir=\"" . ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/" . ctrl_options::GetSystemOption('openbase_seperator') . ctrl_options::GetSystemOption('openbase_temp') . "\" " . ctrl_options::GetSystemOption('daemon_exer') . "" . 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()) {
             $fetchRows = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_id_pk=:userid AND ac_deleted_ts IS NULL");
             $fetchRows->bindParam(':userid', $rowcron['ct_acc_fk']);
             $fetchRows->execute();
             $rowclient = $fetchRows->fetch();
             if ($rowclient && $rowclient['ac_enabled_in'] != 0) {
                 $line .= "# CRON ID: " . $rowcron['ct_id_pk'] . "" . fs_filehandler::NewLine();
                 // removed openbase_dir and suhosin directives - allows proper running of jobs on Windows
                 //$line .= "" . $rowcron['ct_timing_vc'] . " " . ctrl_options::GetSystemOption('php_exer') . " -d suhosin.executor.func.blacklist=\"passthru, show_source, shell_exec, system, pcntl_exec, popen, pclose, proc_open, proc_nice, proc_terminate, proc_get_status, proc_close, leak, apache_child_terminate, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid, posix_setuid, escapeshellcmd, escapeshellarg, exec\" -d open_basedir=\"" . ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/" . ctrl_options::GetSystemOption('openbase_seperator') . ctrl_options::GetSystemOption('openbase_temp') . "\" " . $rowcron['ct_fullpath_vc'] . "" . 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'), 0644, $line)) {
             if (sys_versions::ShowOSPlatformVersion() != "Windows") {
                 $returnValue = ctrl_system::systemCommand(ctrl_options::GetSystemOption('zsudo'), array(ctrl_options::GetSystemOption('cron_reload_command'), ctrl_options::GetSystemOption('cron_reload_flag'), ctrl_options::GetSystemOption('cron_reload_user'), ctrl_options::GetSystemOption('cron_reload_path')));
                 //var_dump( $returnValue );
             }
             return true;
         } else {
             return false;
         }
     } else {
         $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();
         if (fs_filehandler::UpdateFile(ctrl_options::GetSystemOption('cron_file'), 0644, $line)) {
             if (sys_versions::ShowOSPlatformVersion() != "Windows") {
                 $returnValue = ctrl_system::systemCommand(ctrl_options::GetSystemOption('zsudo'), array(ctrl_options::GetSystemOption('cron_reload_command'), ctrl_options::GetSystemOption('cron_reload_flag'), ctrl_options::GetSystemOption('cron_reload_user'), ctrl_options::GetSystemOption('cron_reload_path')));
                 //var_dump( $returnValue );
             }
             return true;
         } else {
             return false;
         }
     }
 }
Example #19
0
            if ($rowftpaccounts['ft_access_vc'] == 'RW') {
                $permissionset = "<Option Name=\"FileRead\">1</Option>" . fs_filehandler::NewLine();
                $permissionset .= "<Option Name=\"FileWrite\">1</Option>" . fs_filehandler::NewLine();
                $permissionset .= "<Option Name=\"FileDelete\">1</Option>" . fs_filehandler::NewLine();
                $permissionset .= "<Option Name=\"FileAppend\">1</Option>" . fs_filehandler::NewLine();
                $permissionset .= "<Option Name=\"DirCreate\">1</Option>" . fs_filehandler::NewLine();
                $permissionset .= "<Option Name=\"DirDelete\">1</Option>" . fs_filehandler::NewLine();
                $permissionset .= "<Option Name=\"DirList\">1</Option>" . fs_filehandler::NewLine();
                $permissionset .= "<Option Name=\"DirSubdirs\">1</Option>" . fs_filehandler::NewLine();
                $accessmode = "Full access";
            }
            $line .= $permissionset;
            $line .= "<Option Name=\"IsHome\">1</Option>" . fs_filehandler::NewLine();
            $line .= "<Option Name=\"AutoCreate\">0</Option>" . fs_filehandler::NewLine();
            $line .= "</Permission>" . fs_filehandler::NewLine();
            $line .= "</Permissions>" . fs_filehandler::NewLine();
            $line .= "<SpeedLimits DlType=\"0\" DlLimit=\"10\" ServerDlLimitBypass=\"0\" UlType=\"0\" UlLimit=\"10\" ServerUlLimitBypass=\"0\">" . fs_filehandler::NewLine();
            $line .= "<Download/>" . fs_filehandler::NewLine();
            $line .= "<Upload/>" . fs_filehandler::NewLine();
            $line .= "</SpeedLimits>" . fs_filehandler::NewLine();
            $line .= "</User>" . fs_filehandler::NewLine();
            // end user loop
        }
    }
    $line .= "</Users>" . fs_filehandler::NewLine();
    $line .= "</FileZillaServer>";
    // Write the Filezilla config file
    if (fs_filehandler::UpdateFile($ftpconfigfile, 0777, $line)) {
        exec($ftp_reload);
    }
}
Example #20
0
 static function ExecuteAddDomain($uid, $domain, $destination, $autohome)
 {
     global $zdbh;
     $retval = FALSE;
     runtime_hook::Execute('OnBeforeAddDomain');
     $currentuser = ctrl_users::GetUserDetail($uid);
     $domain = strtolower(str_replace(' ', '', $domain));
     if (!fs_director::CheckForEmptyValue(self::CheckCreateForErrors($domain))) {
         //** New Home Directory **//
         if ($autohome == 1) {
             $destination = "/" . str_replace(".", "_", $domain);
             $vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/public_html/" . $destination . "/";
             fs_director::CreateDirectory($vhost_path);
             fs_director::SetFileSystemPermissions($vhost_path, 0777);
             //** Existing Home Directory **//
         } else {
             $destination = "/" . $destination;
             $vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/public_html/" . $destination . "/";
         }
         // Error documents:- Error pages are added automatically if they are found in the _errorpages directory
         // and if they are a valid error code, and saved in the proper format, i.e. <error_number>.html
         fs_director::CreateDirectory($vhost_path . "/_errorpages/");
         $errorpages = ctrl_options::GetSystemOption('static_dir') . "/errorpages/";
         if (is_dir($errorpages)) {
             if ($handle = @opendir($errorpages)) {
                 while (($file = @readdir($handle)) !== false) {
                     if ($file != "." && $file != "..") {
                         $page = explode(".", $file);
                         if (!fs_director::CheckForEmptyValue(self::CheckErrorDocument($page[0]))) {
                             fs_filehandler::CopyFile($errorpages . $file, $vhost_path . '/_errorpages/' . $file);
                         }
                     }
                 }
                 closedir($handle);
             }
         }
         // Lets copy the default welcome page across...
         if (!file_exists($vhost_path . "/index.html") && !file_exists($vhost_path . "/index.php") && !file_exists($vhost_path . "/index.htm")) {
             fs_filehandler::CopyFileSafe(ctrl_options::GetSystemOption('static_dir') . "pages/welcome.html", $vhost_path . "/index.html");
         }
         // If all has gone well we need to now create the domain in the database...
         $sql = $zdbh->prepare("INSERT INTO x_vhosts (vh_acc_fk,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t vh_name_vc,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t vh_directory_vc,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t vh_type_in,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t vh_created_ts) VALUES (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t :userid,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t :domain,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t :destination,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t 1,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t :time)");
         //CLEANER FUNCTION ON $domain and $homedirectory_to_use (Think I got it?)
         $time = time();
         $sql->bindParam(':time', $time);
         $sql->bindParam(':userid', $currentuser['userid']);
         $sql->bindParam(':domain', $domain);
         $sql->bindParam(':destination', $destination);
         $sql->execute();
         // Only run if the Server platform is Windows.
         if (sys_versions::ShowOSPlatformVersion() == 'Windows') {
             if (ctrl_options::GetSystemOption('disable_hostsen') == 'false') {
                 // Lets add the hostname to the HOSTS file so that the server can view the domain immediately...
                 @exec("C:/Sentora/bin/zpss/setroute.exe " . $domain . "");
                 @exec("C:/Sentora/bin/zpss/setroute.exe www." . $domain . "");
             }
         }
         self::SetWriteApacheConfigTrue();
         $retval = TRUE;
         runtime_hook::Execute('OnAfterAddDomain');
         return $retval;
     }
 }
Example #21
0
 static function getCustomPackageSelection()
 {
     global $controller;
     $toReturn = "";
     if (file_exists("./modules/" . $controller->GetControllerRequest('URL', 'module') . "/packages/custom_packages.xml")) {
         $packages = new xml_reader(fs_filehandler::ReadFileContents("./modules/" . $controller->GetControllerRequest('URL', 'module') . "/packages/custom_packages.xml"));
         $packages->Parse();
         foreach ($packages->document->package as $package) {
             // START - Info and DB tags by tgates
             if ($package->db[0]->tagData == 'yes') {
                 $package->pkgdb[0]->tagData = "yes";
             } else {
                 $package->pkgdb[0]->tagData = "no";
             }
             if ($package->db[0]->tagData == 'yes') {
                 $package->db[0]->tagData = "<font color='green'><strong>" . ui_language::translate("YES") . "</strong></font>";
             } else {
                 $package->db[0]->tagData = "<font color='red'><strong>" . ui_language::translate("NO") . "</strong></font>";
             }
             // END - Info and DB tags by tgates
             $toReturn .= "<tr>\n\t\t\t<td>" . $package->name[0]->tagData . "</td>\n\t\t\t<td>" . $package->version[0]->tagData . "</td>\n\t\t\t<td>" . $package->type[0]->tagData . "</td>\n\t\t\t<td>" . $package->info[0]->tagData . "</td>\n\t\t\t<td><center>" . $package->db[0]->tagData . "</center></td>\n\t\t\t<td>\n\t\t\t\t<form id=\"install\" name=\"Install\" action=\"/?module=sentastico\" method=\"post\">\n\t\t\t\t<input type=\"hidden\" name=\"startinstall\" value=\"true\"> \n\t\t\t\t<input type=\"hidden\" name=\"pkgzip\" value=" . $package->zipname[0]->tagData . "> \n\t\t\t\t<input type=\"hidden\" name=\"pkg\" value='" . $package->name[0]->tagData . "'> \n\t\t\t\t<input type=\"hidden\" name=\"pkgdb\" value=" . $package->pkgdb[0]->tagData . "> \n\t\t\t\t<input class=\"btn btn-primary btn-small\" type=\"submit\" name=\"doInstall\" value=" . ui_language::translate("Install") . " />\n\t\t\t\t</form>\n\t\t\t</td>\n\t\t</tr>";
         }
         $toReturn .= "</table><br />";
     } else {
         $toReturn .= "</table><br />";
     }
     //$toReturn .= "</form>";
     return $toReturn;
 }
Example #22
0
 static function WriteCronFile()
 {
     global $zdbh;
     $currentuser = ctrl_users::GetUserDetail();
     $line = "";
     $sql = "SELECT * FROM x_cronjobs WHERE ct_deleted_ts IS NULL";
     $numrows = $zdbh->query($sql);
     //common header whatever there are some cron task or not
     if (sys_versions::ShowOSPlatformVersion() != "Windows") {
         $line .= 'SHELL=/bin/bash' . fs_filehandler::NewLine();
         $line .= 'PATH=/sbin:/bin:/usr/sbin:/usr/bin' . fs_filehandler::NewLine();
         $line .= 'HOME=/' . fs_filehandler::NewLine();
         $line .= fs_filehandler::NewLine();
     }
     $restrictinfos = ctrl_options::GetSystemOption('php_exer') . " -d suhosin.executor.func.blacklist=\"passthru, show_source, shell_exec, system, pcntl_exec, popen, pclose, proc_open, proc_nice, proc_terminate, proc_get_status, proc_close, leak, apache_child_terminate, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid, posix_setuid, escapeshellcmd, escapeshellarg, exec\" -d open_basedir=\"" . ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/" . ctrl_options::GetSystemOption('openbase_seperator') . ctrl_options::GetSystemOption('openbase_temp') . "\" ";
     $line .= "#################################################################################" . fs_filehandler::NewLine();
     $line .= "# CRONTAB FOR MADmin CRON MANAGER MODULE                                        " . fs_filehandler::NewLine();
     $line .= "# Module Developed by Bobby Allen, 17/12/2009                                    " . fs_filehandler::NewLine();
     $line .= "# File automatically generated by MADmin " . sys_versions::ShowMADminVersion() . fs_filehandler::NewLine();
     if (sys_versions::ShowOSPlatformVersion() == "Windows") {
         $line .= "# Cron Debug infomation can be found in file C:\\WINDOWS\\System32\\crontab.txt " . fs_filehandler::NewLine();
         $line .= "#################################################################################" . fs_filehandler::NewLine();
         $line .= "" . ctrl_options::GetSystemOption('daemon_timing') . " " . $restrictinfos . ctrl_options::GetSystemOption('daemon_exer') . fs_filehandler::NewLine();
     }
     $line .= "#################################################################################" . fs_filehandler::NewLine();
     $line .= "# NEVER MANUALLY REMOVE OR EDIT ANY OF THE CRON ENTRIES FROM THIS FILE,          " . fs_filehandler::NewLine();
     $line .= "#  -> USE MADmin INSTEAD! (Menu -> Advanced -> Cron Manager)                    " . fs_filehandler::NewLine();
     $line .= "#################################################################################" . fs_filehandler::NewLine();
     //Write command lines in crontab, if any
     if ($numrows->fetchColumn() != 0) {
         $sql = $zdbh->prepare($sql);
         $sql->execute();
         while ($rowcron = $sql->fetch()) {
             $fetchRows = $zdbh->prepare("SELECT * FROM x_accounts WHERE ac_id_pk=:userid AND ac_deleted_ts IS NULL");
             $fetchRows->bindParam(':userid', $rowcron['ct_acc_fk']);
             $fetchRows->execute();
             $rowclient = $fetchRows->fetch();
             if ($rowclient && $rowclient['ac_enabled_in'] != 0) {
                 $line .= "# CRON ID: " . $rowcron['ct_id_pk'] . fs_filehandler::NewLine();
                 $line .= $rowcron['ct_timing_vc'] . " " . $restrictinfos . $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'), 0644, $line)) {
         if (sys_versions::ShowOSPlatformVersion() != "Windows") {
             $returnValue = ctrl_system::systemCommand(ctrl_options::GetSystemOption('zsudo'), array(ctrl_options::GetSystemOption('cron_reload_command'), ctrl_options::GetSystemOption('cron_reload_flag'), ctrl_options::GetSystemOption('cron_reload_user'), ctrl_options::GetSystemOption('cron_reload_path')));
         }
         return true;
     } else {
         return false;
     }
 }
        runtime_hook::Execute('OnAfterPurgeBackup');
    }
    // Clean temp backups....
    echo fs_filehandler::NewLine() . "Purging backups from temp folder..." . fs_filehandler::NewLine();
    clearstatcache();
    echo "[FILE][PURGE_DATE][FILE_DATE][ACTION]" . fs_filehandler::NewLine();
    $temp_dir = ctrl_options::GetSystemOption('sentora_root') . "/modules/backupmgr/temp/";
    if ($handle = @opendir($temp_dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                $filetime = @filemtime($temp_dir . $file);
                if ($filetime == NULL) {
                    $filetime = @filemtime(utf8_decode($temp_dir . $file));
                }
                $filetime = floor((time() - $filetime) / 86400);
                echo "" . $file . " - " . $purge_date . " - " . $filetime . "";
                if (1 <= $filetime) {
                    //delete the file
                    echo " - Deleting file..." . fs_filehandler::NewLine();
                    unlink($temp_dir . $file);
                } else {
                    echo " - Skipping file..." . fs_filehandler::NewLine();
                }
            }
        }
    }
} else {
    echo "Backup Config module DISABLED...nothing to do." . fs_filehandler::NewLine();
}
echo "END Backup Config." . fs_filehandler::NewLine();
Example #24
0
function ReloadBindHook()
{
    if (sys_versions::ShowOSPlatformVersion() == "Windows") {
        $reload_bind = ctrl_options::GetSystemOption('bind_dir') . "rndc.exe reload";
    } else {
        $reload_bind = ctrl_options::GetSystemOption('zsudo') . " service " . ctrl_options::GetSystemOption('bind_service') . " reload";
    }
    echo "Reloading BIND now..." . fs_filehandler::NewLine();
    pclose(popen($reload_bind, 'r'));
}
Example #25
0
<?php

/**
 * @copyright 2014-2015 Sentora Project (http://www.sentora.org/) 
 * Sentora is a GPL fork of the ZPanel Project whose original header follows:
 *
 * Hook created by Bobby Allen to obtain latest zpanel version number and add it to the DB for querying (caching bascially!)
 * This script is handy for caching the latest version of ZPanel to reduce bandwidth from the server.
 * 
 */
echo fs_filehandler::NewLine() . "START Sentora Updates hook" . fs_filehandler::NewLine();
echo "Checking for latest version of Sentora..." . fs_filehandler::NewLine();
CheckSentoraLatestVersion();
echo "END Sentora Updates hook" . fs_filehandler::NewLine();
function CheckSentoraLatestVersion()
{
    // Grab the latest version of Sentora from the Sentora 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);
    # Sentora 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;
Example #26
0
                    $versionsql->bindParam(':mo_id_pk', $modules['mo_id_pk']);
                    $versionsql->bindParam(':latest_version', $latest_version);
                    $versionsql->bindParam(':downloadurl', $downloadurl);
                    $versionsql->execute();
                } else {
                    $versionsql = $zdbh->prepare("UPDATE x_modules SET mo_updatever_vc = '', mo_updateurl_tx = '' WHERE mo_id_pk = :mo_id_pk");
                    $versionsql->bindParam(':mo_id_pk', $modules['mo_id_pk']);
                    $versionsql->execute();
                }
            } else {
                echo "The remote file was not parsed correctly or does not exist." . fs_filehandler::NewLine();
            }
        } else {
            echo "The remote file does not exist." . fs_filehandler::NewLine();
        }
    } else {
        echo "Couldn't open the module XML file for (" . $modules['mo_name_vc'] . ")" . fs_filehandler::NewLine();
    }
}
echo "END getting module version update information!" . fs_filehandler::NewLine();
/*
 * Please DO NOT remove the below code, this helps us at the MADmin project
 * find out non-personal infomation about how people are running MADmin. The only infomation
 * that we are passing back here is your MADmin version and what OS you are running it on in addition
 * to collecting the email address of the default 'zadmin' account to enable automatic email
 * notficiations of new releases and urgent patches.
 */
$zdbh->bindQuery('SELECT ac_email_vc AS email FROM x_accounts WHERE ac_user_vc = :user', array(':user' => 'zadmin'));
$zadmin = $zdbh->returnRow();
ws_generic::DoPostRequest('http://api.MADmin.org/hello.json', "version=" . sys_versions::ShowMADminVersion() . "&platform=" . sys_versions::ShowOSPlatformVersion() . "&url=" . ctrl_options::GetSystemOption('MADmin_domain') . "mail=" . $zadmin['email']);
return true;
 /**
  * Captures the RAW POST data passed to this script.
  * @author Bobby Allen (ballen@bobbyallen.me)
  * @return string The raw request data.
  */
 static function ProcessRawRequest()
 {
     $xml_raw_data = fs_filehandler::ReadFileContents('php://input');
     return $xml_raw_data;
 }
Example #28
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();
            }
        }
    }
}
 static function ExcuteVhostPost($data)
 {
     global $controller;
     $file = "C:\\sentora\\configs\\apache\\httpd-vhosts.conf";
     if (fs_filehandler::UpdateFile($file, 0777, $data)) {
         self::$statusDataWrite = "File updated";
         self::$functionRan = 1;
         self::$messageType = 'zannounceok';
         return true;
     } else {
         self::$statusDataWrite = "Faile d to update file";
         self::$functionRan = 1;
         self::$messageType = 'zannounceerror';
         return false;
     }
 }