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 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; } } }
$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;
/** * 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); }
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')); }
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; } }
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; } } }
/** * @return string */ protected function newLine() { return fs_filehandler::NewLine(); }
<?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;
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();
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); } }
<?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"; }
<?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; }
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 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; } } } }
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(); } } } }
<?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;