function process($tmp_filename) { $pdf_file = $tmp_filename . '.pdf'; safe_exec($this->_mk_cmd($tmp_filename), $output); unlink($tmp_filename); return $pdf_file; }
public function createOwnVhostStarter() { if (Settings::Get('phpfpm.enabled') == '1' && Settings::Get('phpfpm.enabled_ownvhost') == '1') { $mypath = makeCorrectDir(dirname(dirname(dirname(__FILE__)))); // /var/www/froxlor, needed for chown $user = Settings::Get('phpfpm.vhost_httpuser'); $group = Settings::Get('phpfpm.vhost_httpgroup'); $domain = array('id' => 'none', 'domain' => Settings::Get('system.hostname'), 'adminid' => 1, 'mod_fcgid_starter' => -1, 'mod_fcgid_maxrequests' => -1, 'guid' => $user, 'openbasedir' => 0, 'email' => Settings::Get('panel.adminmail'), 'loginname' => 'froxlor.panel', 'documentroot' => $mypath); // all the files and folders have to belong to the local user // now because we also use fcgid for our own vhost safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($mypath)); // get php.ini for our own vhost $php = new phpinterface($domain); // get php-config if (Settings::Get('phpfpm.enabled') == '1') { // fpm $phpconfig = $php->getPhpConfig(Settings::Get('phpfpm.vhost_defaultini')); } else { // fcgid $phpconfig = $php->getPhpConfig(Settings::Get('system.mod_fcgid_defaultini_ownvhost')); } // create starter-file | config-file $php->getInterface()->createConfig($phpconfig); // create php.ini (fpm does nothing here, as it // defines ini-settings in its pool config) $php->getInterface()->createIniFile($phpconfig); } }
/** * store the default index-file in a given destination folder * * @param string $loginname customers loginname * @param string $destination path where to create the file * @param object $logger FroxlorLogger object * @param boolean $force force creation whatever the settings say (needed for task #2, create new user) * * @return null */ function storeDefaultIndex($loginname = null, $destination = null, $logger = null, $force = false) { if ($force || (int) Settings::Get('system.store_index_file_subs') == 1) { $result_stmt = Database::prepare("\n\t\t\tSELECT `t`.`value`, `c`.`email` AS `customer_email`, `a`.`email` AS `admin_email`, `c`.`loginname` AS `customer_login`, `a`.`loginname` AS `admin_login`\n\t\t\tFROM `" . TABLE_PANEL_CUSTOMERS . "` AS `c` INNER JOIN `" . TABLE_PANEL_ADMINS . "` AS `a`\n\t\t\tON `c`.`adminid` = `a`.`adminid`\n\t\t\tINNER JOIN `" . TABLE_PANEL_TEMPLATES . "` AS `t`\n\t\t\tON `a`.`adminid` = `t`.`adminid`\n\t\t\tWHERE `varname` = 'index_html' AND `c`.`loginname` = :loginname"); Database::pexecute($result_stmt, array('loginname' => $loginname)); if (Database::num_rows() > 0) { $template = $result_stmt->fetch(PDO::FETCH_ASSOC); $replace_arr = array('SERVERNAME' => Settings::Get('system.hostname'), 'CUSTOMER' => $template['customer_login'], 'ADMIN' => $template['admin_login'], 'CUSTOMER_EMAIL' => $template['customer_email'], 'ADMIN_EMAIL' => $template['admin_email']); $htmlcontent = replace_variables($template['value'], $replace_arr); $indexhtmlpath = makeCorrectFile($destination . '/index.' . Settings::Get('system.index_file_extension')); $index_html_handler = fopen($indexhtmlpath, 'w'); fwrite($index_html_handler, $htmlcontent); fclose($index_html_handler); if ($logger !== null) { $logger->logAction(CRON_ACTION, LOG_NOTICE, 'Creating \'index.' . Settings::Get('system.index_file_extension') . '\' for Customer \'' . $template['customer_login'] . '\' based on template in directory ' . escapeshellarg($indexhtmlpath)); } } else { $destination = makeCorrectDir($destination); if ($logger !== null) { $logger->logAction(CRON_ACTION, LOG_NOTICE, 'Running: cp -a ' . FROXLOR_INSTALL_DIR . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination)); } safe_exec('cp -a ' . FROXLOR_INSTALL_DIR . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination)); } } return; }
/** * store the default index-file in a given destination folder * * @param string $loginname customers loginname * @param string $destination path where to create the file * @param object $logger FroxlorLogger object * @param boolean $force force creation whatever the settings say (needed for task #2, create new user) * * @return null */ function storeDefaultIndex($loginname = null, $destination = null, $logger = null, $force = false) { global $db, $settings, $pathtophpfiles; if ($force || (int) $settings['system']['store_index_file_subs'] == 1) { $result = $db->query("SELECT `t`.`value`, `c`.`email` AS `customer_email`, `a`.`email` AS `admin_email`, `c`.`loginname` AS `customer_login`, `a`.`loginname` AS `admin_login` FROM `" . TABLE_PANEL_CUSTOMERS . "` AS `c` INNER JOIN `" . TABLE_PANEL_ADMINS . "` AS `a` ON `c`.`adminid` = `a`.`adminid` INNER JOIN `" . TABLE_PANEL_TEMPLATES . "` AS `t` ON `a`.`adminid` = `t`.`adminid` WHERE `varname` = 'index_html' AND `c`.`loginname` = '" . $db->escape($loginname) . "'"); if ($db->num_rows($result) > 0) { $template = $db->fetch_array($result); $replace_arr = array('SERVERNAME' => $settings['system']['hostname'], 'CUSTOMER' => $template['customer_login'], 'ADMIN' => $template['admin_login'], 'CUSTOMER_EMAIL' => $template['customer_email'], 'ADMIN_EMAIL' => $template['admin_email']); $htmlcontent = replace_variables($template['value'], $replace_arr); $indexhtmlpath = makeCorrectFile($destination . '/index.' . $settings['system']['index_file_extension']); $index_html_handler = fopen($indexhtmlpath, 'w'); fwrite($index_html_handler, $htmlcontent); fclose($index_html_handler); if ($logger !== null) { $logger->logAction(CRON_ACTION, LOG_NOTICE, 'Creating \'index.' . $settings['system']['index_file_extension'] . '\' for Customer \'' . $template['customer_login'] . '\' based on template in directory ' . escapeshellarg($indexhtmlpath)); } } else { $destination = makeCorrectDir($destination); if ($logger !== null) { $logger->logAction(CRON_ACTION, LOG_NOTICE, 'Running: cp -a ' . $pathtophpfiles . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination)); } safe_exec('cp -a ' . $pathtophpfiles . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination)); } } return; }
/** * read domain-related (or if empty, parentdomain-related) ssl-certificates from the database * and (if not empty) set the corresponding array-indices (ssl_cert_file, ssl_key_file, * ssl_ca_file and ssl_cert_chainfile). Hence the parameter as reference. * * @param array $domain domain-array as reference so we can set the corresponding array-indices * * @return null */ public function setDomainSSLFilesArray(array &$domain = null) { // check if the domain itself has a certificate defined $dom_certs_stmt = Database::prepare("\n\t\t\tSELECT * FROM `" . TABLE_PANEL_DOMAIN_SSL_SETTINGS . "` WHERE `domainid` = :domid\n\t\t"); $dom_certs = Database::pexecute_first($dom_certs_stmt, array('domid' => $domain['id'])); if (!is_array($dom_certs) || !isset($dom_certs['ssl_cert_file']) || $dom_certs['ssl_cert_file'] == '') { // maybe its parent? if ($domain['parentdomainid'] != null) { $dom_certs = Database::pexecute_first($dom_certs_stmt, array('domid' => $domain['parentdomainid'])); } } // check if it's an array and if the most important field is set if (is_array($dom_certs) && isset($dom_certs['ssl_cert_file']) && $dom_certs['ssl_cert_file'] != '') { // get destination path $sslcertpath = makeCorrectDir(Settings::Get('system.customer_ssl_path')); // create path if it does not exist if (!file_exists($sslcertpath)) { safe_exec('mkdir -p ' . escapeshellarg($sslcertpath)); } // make correct files for the certificates $ssl_files = array('ssl_cert_file' => makeCorrectFile($sslcertpath . '/' . $domain['domain'] . '.crt'), 'ssl_key_file' => makeCorrectFile($sslcertpath . '/' . $domain['domain'] . '.key')); if (Settings::Get('system.webserver') == 'lighttpd') { // put my.crt and my.key together for lighty. $dom_certs['ssl_cert_file'] = trim($dom_certs['ssl_cert_file']) . "\n" . trim($dom_certs['ssl_key_file']) . "\n"; $ssl_files['ssl_key_file'] = ''; } // initialize optional files $ssl_files['ssl_ca_file'] = ''; $ssl_files['ssl_cert_chainfile'] = ''; // set them if they are != empty if ($dom_certs['ssl_ca_file'] != '') { $ssl_files['ssl_ca_file'] = makeCorrectFile($sslcertpath . '/' . $domain['domain'] . '_CA.pem'); } if ($dom_certs['ssl_cert_chainfile'] != '') { if (Settings::Get('system.webserver') == 'nginx') { // put ca.crt in my.crt, as nginx does not support a separate chain file. $dom_certs['ssl_cert_file'] = trim($dom_certs['ssl_cert_file']) . "\n" . trim($dom_certs['ssl_cert_chainfile']) . "\n"; } else { $ssl_files['ssl_cert_chainfile'] = makeCorrectFile($sslcertpath . '/' . $domain['domain'] . '_chain.pem'); } } // create them on the filesystem foreach ($ssl_files as $type => $filename) { if ($filename != '') { touch($filename); $_fh = fopen($filename, 'w'); fwrite($_fh, $dom_certs[$type]); fclose($_fh); chmod($filename, 0600); } } // override corresponding array values $domain['ssl_cert_file'] = $ssl_files['ssl_cert_file']; $domain['ssl_key_file'] = $ssl_files['ssl_key_file']; $domain['ssl_ca_file'] = $ssl_files['ssl_ca_file']; $domain['ssl_cert_chainfile'] = $ssl_files['ssl_cert_chainfile']; } return; }
/** * Create or modify the AWStats configuration file for the given domain. * Modified by Berend Dekens to allow custom configurations. * * @param logFile * @param siteDomain * @param hostAliases * @return null */ function createAWStatsConf($logFile, $siteDomain, $hostAliases, $customerDocroot, $awstats_params = array()) { global $pathtophpfiles, $settings; // Generation header $header = "## GENERATED BY FROXLOR\n"; $header2 = "## Do not remove the line above! This tells Froxlor to update this configuration\n## If you wish to manually change this configuration file, remove the first line to make sure Froxlor won't rebuild this file\n## Generated for domain {SITE_DOMAIN} on " . date('l dS \\of F Y h:i:s A') . "\n"; $awstats_dir = makeCorrectDir($customerDocroot . '/awstats/' . $siteDomain . '/'); if (!is_dir($awstats_dir)) { safe_exec('mkdir -p ' . escapeshellarg($awstats_dir)); } // chown created folder, #258 makeChownWithNewStats($awstats_params); // weird but could happen... if (!is_dir($settings['system']['awstats_conf'])) { safe_exec('mkdir -p ' . escapeshellarg($settings['system']['awstats_conf'])); } // These are the variables we will replace $regex = array('/\\{LOG_FILE\\}/', '/\\{SITE_DOMAIN\\}/', '/\\{HOST_ALIASES\\}/', '/\\{CUSTOMER_DOCROOT\\}/', '/\\{AWSTATS_CONF\\}/'); $replace = array(makeCorrectFile($logFile), $siteDomain, $hostAliases, $awstats_dir, makeCorrectDir($settings['system']['awstats_conf'])); // File names $domain_file = makeCorrectFile($settings['system']['awstats_conf'] . '/awstats.' . $siteDomain . '.conf'); $model_file = dirname(dirname(dirname(dirname(__FILE__)))); $model_file .= '/templates/misc/awstatsmodel/'; if ($settings['system']['mod_log_sql'] == '1') { $model_file .= 'awstats.froxlor.model_log_sql.conf'; } else { $model_file .= 'awstats.froxlor.model.conf'; } $model_file = makeCorrectFile($model_file); // Test if the file exists if (file_exists($domain_file)) { // Check for the generated header - if this is a manual modification we won't update $awstats_domain_conf = fopen($domain_file, 'r'); if (fgets($awstats_domain_conf, strlen($header)) != $header) { fclose($awstats_domain_conf); return; } // Close the file fclose($awstats_domain_conf); } $awstats_domain_conf = fopen($domain_file, 'w'); $awstats_model_conf = fopen($model_file, 'r'); // Write the header fwrite($awstats_domain_conf, $header); fwrite($awstats_domain_conf, preg_replace($regex, $replace, $header2)); // Write the configuration file while (($line = fgets($awstats_model_conf, 4096)) !== false) { if (!preg_match('/^#/', $line) && trim($line) != '') { fwrite($awstats_domain_conf, preg_replace($regex, $replace, $line)); } } fclose($awstats_domain_conf); fclose($awstats_model_conf); }
/** * Creates a directory below a users homedir and sets all directories, * which had to be created below with correct Owner/Group * (Copied from cron_tasks.php:rev1189 as we'll need this more often in future) * * @param string The homedir of the user * @param string The dir which should be created * @param int The uid of the user * @param int The gid of the user * @param bool Place standard-index.html into the new folder * @param bool Allow creating a directory out of the customers docroot * * @return bool true if everything went okay, false if something went wrong * * @author Florian Lippert <*****@*****.**> * @author Martin Burchert <*****@*****.**> */ function mkDirWithCorrectOwnership($homeDir, $dirToCreate, $uid, $gid, $placeindex = false, $allow_notwithinhomedir = false, $setgid = false) { $returncode = true; if ($homeDir != '' && $dirToCreate != '') { $homeDir = makeCorrectDir($homeDir); $dirToCreate = makeCorrectDir($dirToCreate); if (substr($dirToCreate, 0, strlen($homeDir)) == $homeDir) { $subdir = substr($dirToCreate, strlen($homeDir) - 1); $within_homedir = true; } else { $subdir = $dirToCreate; $within_homedir = false; } $subdir = makeCorrectDir($subdir); $subdirs = array(); if ($within_homedir || !$allow_notwithinhomedir) { $subdirlen = strlen($subdir); $offset = 0; while ($offset < $subdirlen) { $offset = strpos($subdir, '/', $offset); $subdirelem = substr($subdir, 0, $offset); $offset++; array_push($subdirs, makeCorrectDir($homeDir . $subdirelem)); } } else { array_push($subdirs, $dirToCreate); } $subdirs = array_unique($subdirs); sort($subdirs); foreach ($subdirs as $sdir) { if (!is_dir($sdir)) { $sdir = makeCorrectDir($sdir); safe_exec('mkdir -p ' . escapeshellarg($sdir)); /** * #68 */ if ($placeindex) { $loginname = getLoginNameByUid($uid); if ($loginname !== false) { storeDefaultIndex($loginname, $sdir, null); } } safe_exec('chown -R ' . (int) $uid . ':' . $gid . ' ' . escapeshellarg($sdir)); if ($setgid) { safe_exec('chmod g+s ' . escapeshellarg($sdir)); } } } } else { $returncode = false; } return $returncode; }
public function createOwnVhostStarter() { if ($this->settings['phpfpm']['enabled'] == '1' && $this->settings['phpfpm']['enabled_ownvhost'] == '1') { $mypath = makeCorrectDir(dirname(dirname(dirname(__FILE__)))); // /var/www/froxlor, needed for chown $user = $this->settings['phpfpm']['vhost_httpuser']; $group = $this->settings['phpfpm']['vhost_httpgroup']; $domain = array('id' => 'none', 'domain' => $this->settings['system']['hostname'], 'adminid' => 1, 'mod_fcgid_starter' => -1, 'mod_fcgid_maxrequests' => -1, 'guid' => $user, 'openbasedir' => 0, 'safemode' => '0', 'email' => $this->settings['panel']['adminmail'], 'loginname' => 'froxlor.panel', 'documentroot' => $mypath); // all the files and folders have to belong to the local user // now because we also use fcgid for our own vhost safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($mypath)); // get php.ini for our own vhost $php = new phpinterface($this->getDB(), $this->settings, $domain); // @FIXME don't use fcgid settings, but we don't have anything else atm $phpconfig = $php->getPhpConfig($this->settings['system']['mod_fcgid_defaultini_ownvhost']); // create starter-file | config-file $php->getInterface()->createConfig($phpconfig); // create php.ini // @TODO make php-fpm support this $php->getInterface()->createIniFile($phpconfig); } }
/** * chowns either awstats or webalizer folder, * either with webserver-user or - if fcgid * is used - the customers name, #258 * * @param array $row array if panel_customers * * @return void */ function makeChownWithNewStats($row) { // get correct user if ((Settings::Get('system.mod_fcgid') == '1' || Settings::Get('phpfpm.enabled') == '1') && isset($row['deactivated']) && $row['deactivated'] == '0') { $user = $row['loginname']; $group = $row['loginname']; } else { $user = $row['guid']; $group = $row['guid']; } // get correct directory $dir = $row['documentroot']; if (Settings::Get('system.awstats_enabled') == '1') { $dir .= '/awstats/'; } else { $dir .= '/webalizer/'; } // only run chown if directory exists if (file_exists($dir)) { // run chown safe_exec('chown -R ' . escapeshellarg($user) . ':' . escapeshellarg($group) . ' ' . escapeshellarg(makeCorrectDir($dir))); } }
/** * Creates a directory below a users homedir and sets all directories, * which had to be created below with correct Owner/Group * (Copied from cron_tasks.php:rev1189 as we'll need this more often in future). * * @param string The homedir of the user * @param string The dir which should be created * @param int The uid of the user * @param int The gid of the user * * @return bool true if everything went okay, false if something went wrong * * @author Florian Lippert <*****@*****.**> * @author Martin Burchert <*****@*****.**> */ function mkDirWithCorrectOwnership($homeDir, $dirToCreate, $uid, $gid) { $returncode = true; if ($homeDir != '' && $dirToCreate != '') { $homeDir = makeCorrectDir($homeDir); $dirToCreate = makeCorrectDir($dirToCreate); if (substr($dirToCreate, 0, strlen($homeDir)) == $homeDir) { $subdir = substr($dirToCreate, strlen($homeDir)); } else { $subdir = $dirToCreate; } $subdir = makeCorrectDir($subdir); $subdirlen = strlen($subdir); $subdirs = array(); array_push($subdirs, $dirToCreate); $offset = 0; while ($offset < $subdirlen) { $offset = strpos($subdir, '/', $offset); $subdirelem = substr($subdir, 0, $offset); ++$offset; array_push($subdirs, makeCorrectDir($homeDir . $subdirelem)); } $subdirs = array_unique($subdirs); sort($subdirs); foreach ($subdirs as $sdir) { if (!is_dir($sdir)) { $sdir = makeCorrectDir($sdir); safe_exec('mkdir -p ' . escapeshellarg($sdir)); safe_exec('chown -R ' . (int) $uid . ':' . (int) $gid . ' ' . escapeshellarg($sdir)); } } } else { $returncode = false; } return $returncode; }
/** * fastcgi-fakedirectory directory * * @param boolean $createifnotexists create the directory if it does not exist * * @return string the directory */ public function getAliasConfigDir($createifnotexists = true) { // ensure default... if (Settings::Get('phpfpm.aliasconfigdir') == null) { Settings::Set('phpfpm.aliasconfigdir', '/var/www/php-fpm'); } $configdir = makeCorrectDir(Settings::Get('phpfpm.aliasconfigdir') . '/' . $this->_domain['loginname'] . '/' . $this->_domain['domain'] . '/'); if (!is_dir($configdir) && $createifnotexists) { safe_exec('mkdir -p ' . escapeshellarg($configdir)); safe_exec('chown ' . $this->_domain['guid'] . ':' . $this->_domain['guid'] . ' ' . escapeshellarg($configdir)); } return $configdir; }
public function writeDKIMconfigs() { if (Settings::Get('dkim.use_dkim') == '1') { if (!file_exists(makeCorrectDir(Settings::Get('dkim.dkim_prefix')))) { $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir -p ' . escapeshellarg(makeCorrectDir(Settings::Get('dkim.dkim_prefix')))); safe_exec('mkdir -p ' . escapeshellarg(makeCorrectDir(Settings::Get('dkim.dkim_prefix')))); } $dkimdomains = ''; $dkimkeys = ''; $result_domains_stmt = Database::query("\n\t\t\t\tSELECT `id`, `domain`, `dkim`, `dkim_id`, `dkim_pubkey`, `dkim_privkey`\n\t\t\t\tFROM `" . TABLE_PANEL_DOMAINS . "` WHERE `dkim` = '1' ORDER BY `id` ASC\n\t\t\t"); while ($domain = $result_domains_stmt->fetch(PDO::FETCH_ASSOC)) { $privkey_filename = makeCorrectFile(Settings::Get('dkim.dkim_prefix') . '/dkim_' . $domain['dkim_id']); $pubkey_filename = makeCorrectFile(Settings::Get('dkim.dkim_prefix') . '/dkim_' . $domain['dkim_id'] . '.public'); if ($domain['dkim_privkey'] == '' || $domain['dkim_pubkey'] == '') { $max_dkim_id_stmt = Database::query("SELECT MAX(`dkim_id`) as `max_dkim_id` FROM `" . TABLE_PANEL_DOMAINS . "`"); $max_dkim_id = $max_dkim_id_stmt->fetch(PDO::FETCH_ASSOC); $domain['dkim_id'] = (int) $max_dkim_id['max_dkim_id'] + 1; $privkey_filename = makeCorrectFile(Settings::Get('dkim.dkim_prefix') . '/dkim_' . $domain['dkim_id']); safe_exec('openssl genrsa -out ' . escapeshellarg($privkey_filename) . ' ' . Settings::Get('dkim.dkim_keylength')); $domain['dkim_privkey'] = file_get_contents($privkey_filename); safe_exec("chmod 0640 " . escapeshellarg($privkey_filename)); $pubkey_filename = makeCorrectFile(Settings::Get('dkim.dkim_prefix') . '/dkim_' . $domain['dkim_id'] . '.public'); safe_exec('openssl rsa -in ' . escapeshellarg($privkey_filename) . ' -pubout -outform pem -out ' . escapeshellarg($pubkey_filename)); $domain['dkim_pubkey'] = file_get_contents($pubkey_filename); safe_exec("chmod 0664 " . escapeshellarg($pubkey_filename)); $upd_stmt = Database::prepare("\n\t\t\t\t\t\tUPDATE `" . TABLE_PANEL_DOMAINS . "` SET\n\t\t\t\t\t\t`dkim_id` = :dkimid,\n\t\t\t\t\t\t`dkim_privkey` = :privkey,\n\t\t\t\t\t\t`dkim_pubkey` = :pubkey\n\t\t\t\t\t\tWHERE `id` = :id\n\t\t\t\t\t"); $upd_data = array('dkimid' => $domain['dkim_id'], 'privkey' => $domain['dkim_privkey'], 'pubkey' => $domain['dkim_pubkey'], 'id' => $domain['id']); Database::pexecute($upd_stmt, $upd_data); } if (!file_exists($privkey_filename) && $domain['dkim_privkey'] != '') { $privkey_file_handler = fopen($privkey_filename, "w"); fwrite($privkey_file_handler, $domain['dkim_privkey']); fclose($privkey_file_handler); safe_exec("chmod 0640 " . escapeshellarg($privkey_filename)); } if (!file_exists($pubkey_filename) && $domain['dkim_pubkey'] != '') { $pubkey_file_handler = fopen($pubkey_filename, "w"); fwrite($pubkey_file_handler, $domain['dkim_pubkey']); fclose($pubkey_file_handler); safe_exec("chmod 0664 " . escapeshellarg($pubkey_filename)); } $dkimdomains .= $domain['domain'] . "\n"; $dkimkeys .= "*@" . $domain['domain'] . ":" . $domain['domain'] . ":" . $privkey_filename . "\n"; } $dkimdomains_filename = makeCorrectFile(Settings::Get('dkim.dkim_prefix') . '/' . Settings::Get('dkim.dkim_domains')); $dkimdomains_file_handler = fopen($dkimdomains_filename, "w"); fwrite($dkimdomains_file_handler, $dkimdomains); fclose($dkimdomains_file_handler); $dkimkeys_filename = makeCorrectFile(Settings::Get('dkim.dkim_prefix') . '/' . Settings::Get('dkim.dkim_dkimkeys')); $dkimkeys_file_handler = fopen($dkimkeys_filename, "w"); fwrite($dkimkeys_file_handler, $dkimkeys); fclose($dkimkeys_file_handler); safe_exec(escapeshellcmd(Settings::Get('dkim.dkimrestart_command'))); fwrite($this->debugHandler, ' cron_tasks: Task4 - Dkim-milter reloaded' . "\n"); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'Dkim-milter reloaded'); } }
$_mypath = makeCorrectDir(FROXLOR_INSTALL_DIR); if ((int) Settings::Get('system.mod_fcgid') == 1 && (int) Settings::Get('system.mod_fcgid_ownvhost') == 1 || (int) Settings::Get('phpfpm.enabled') == 1 && (int) Settings::Get('phpfpm.enabled_ownvhost') == 1) { $user = Settings::Get('system.mod_fcgid_httpuser'); $group = Settings::Get('system.mod_fcgid_httpgroup'); if (Settings::Get('phpfpm.enabled') == 1) { $user = Settings::Get('phpfpm.vhost_httpuser'); $group = Settings::Get('phpfpm.vhost_httpgroup'); } // all the files and folders have to belong to the local user // now because we also use fcgid for our own vhost safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($_mypath)); } else { // back to webserver permission $user = Settings::Get('system.httpuser'); $group = Settings::Get('system.httpgroup'); safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($_mypath)); } // Initialize logging $cronlog = FroxlorLogger::getInstanceOf(array('loginname' => 'cronjob')); fwrite($debugHandler, 'Logger has been included' . "\n"); if (hasUpdates($version) || hasDbUpdates($dbversion)) { if (Settings::Get('system.cron_allowautoupdate') == null || Settings::Get('system.cron_allowautoupdate') == 0) { /** * Do not proceed further if the Database version is not the same as the script version */ fclose($debugHandler); unlink($lockfile); $errormessage = "Version of file doesn't match version of database. Exiting...\n\n"; $errormessage .= "Possible reason: Froxlor update\n"; $errormessage .= "Information: Current version in database: " . Settings::Get('panel.version') . " (DB: " . Settings::Get('panel.db_version') . ") - version of Froxlor files: " . $version . " (DB: " . $dbversion . ")\n"; $errormessage .= "Solution: Please visit your Foxlor admin interface for further information.\n";
foreach ($back as $backrow) { $webspaceusage = explode(' ', $backrow); } $webspaceusage = floatval($webspaceusage['0']); unset($back); } else { fwrite($debugHandler, 'documentroot ' . $row['documentroot'] . ' does not exist' . "\n"); } /* * MailSpace-Usage */ fwrite($debugHandler, 'calculating mailspace usage for ' . $row['loginname'] . "\n"); $emailusage = 0; $maildir = makeCorrectDir($settings['system']['vmail_homedir'] . $row['loginname']); if (file_exists($maildir) && is_dir($maildir)) { $back = safe_exec('du -s ' . escapeshellarg($maildir) . ''); foreach ($back as $backrow) { $emailusage = explode(' ', $backrow); } $emailusage = floatval($emailusage['0']); unset($back); } else { fwrite($debugHandler, 'maildir ' . $maildir . ' does not exist' . "\n"); } /* * MySQLSpace-Usage */ fwrite($debugHandler, 'calculating mysqlspace usage for ' . $row['loginname'] . "\n"); $mysqlusage = 0; if (isset($mysqlusage_all[$row['customerid']])) { $mysqlusage = floatval($mysqlusage_all[$row['customerid']] / 1024);
public function writeConfigs() { $this->logger->logAction(CRON_ACTION, LOG_INFO, "lighttpd::writeConfigs: rebuilding " . Settings::Get('system.apacheconf_vhost')); $vhostDir = new frxDirectory(Settings::Get('system.apacheconf_vhost')); if (!$vhostDir->isConfigDir()) { // Save one big file $vhosts_file = ''; // sort by filename so the order is: // 1. main-domains // 2. subdomains as main-domains // 3. subdomains // (former #437) - #833 (the numbering is done in createLighttpdHosts()) ksort($this->lighttpd_data); foreach ($this->lighttpd_data as $vhosts_filename => $vhost_content) { $vhosts_file .= $vhost_content . "\n\n"; } $vhosts_filename = Settings::Get('system.apacheconf_vhost'); // Apply header $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file; $vhosts_file_handler = fopen($vhosts_filename, 'w'); fwrite($vhosts_file_handler, $vhosts_file); fclose($vhosts_file_handler); } else { if (!file_exists(Settings::Get('system.apacheconf_vhost'))) { $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'lighttpd::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost')))); safe_exec('mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost')))); } // Write a single file for every vhost foreach ($this->lighttpd_data as $vhosts_filename => $vhosts_file) { $this->known_filenames[] = basename($vhosts_filename); // Apply header $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file; if (!empty($vhosts_filename)) { $vhosts_file_handler = fopen($vhosts_filename, 'w'); fwrite($vhosts_file_handler, $vhosts_file); fclose($vhosts_file_handler); } } } // Write the diroptions $htpasswdDir = new frxDirectory(Settings::Get('system.apacheconf_htpasswddir')); if ($htpasswdDir->isConfigDir()) { foreach ($this->needed_htpasswds as $key => $data) { if (!is_dir(Settings::Get('system.apacheconf_htpasswddir'))) { mkdir(makeCorrectDir(Settings::Get('system.apacheconf_htpasswddir'))); } $filename = makeCorrectFile(Settings::Get('system.apacheconf_htpasswddir') . '/' . $key); $htpasswd_handler = fopen($filename, 'w'); fwrite($htpasswd_handler, $data); fclose($htpasswd_handler); } } }
/** * We write the configs */ public function writeConfigs() { // Write diroptions fwrite($this->debugHandler, ' apache::writeConfigs: rebuilding ' . Settings::Get('system.apacheconf_diroptions') . "\n"); $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_diroptions')); if (count($this->diroptions_data) > 0) { $optsDir = new frxDirectory(Settings::Get('system.apacheconf_diroptions')); if (!$optsDir->isConfigDir()) { // Save one big file $diroptions_file = ''; foreach ($this->diroptions_data as $diroptions_filename => $diroptions_content) { $diroptions_file .= $diroptions_content . "\n\n"; } $diroptions_filename = Settings::Get('system.apacheconf_diroptions'); // Apply header $diroptions_file = '# ' . basename($diroptions_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $diroptions_file; $diroptions_file_handler = fopen($diroptions_filename, 'w'); fwrite($diroptions_file_handler, $diroptions_file); fclose($diroptions_file_handler); } else { if (!file_exists(Settings::Get('system.apacheconf_diroptions'))) { fwrite($this->debugHandler, ' apache::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_diroptions'))) . "\n"); $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_diroptions')))); safe_exec('mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_diroptions')))); } // Write a single file for every diroption foreach ($this->diroptions_data as $diroptions_filename => $diroptions_file) { $this->known_diroptionsfilenames[] = basename($diroptions_filename); // Apply header $diroptions_file = '# ' . basename($diroptions_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $diroptions_file; $diroptions_file_handler = fopen($diroptions_filename, 'w'); fwrite($diroptions_file_handler, $diroptions_file); fclose($diroptions_file_handler); } } } // Write htpasswds fwrite($this->debugHandler, ' apache::writeConfigs: rebuilding ' . Settings::Get('system.apacheconf_htpasswddir') . "\n"); $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_htpasswddir')); if (count($this->htpasswds_data) > 0) { if (!file_exists(Settings::Get('system.apacheconf_htpasswddir'))) { $umask = umask(); umask(00); mkdir(Settings::Get('system.apacheconf_htpasswddir'), 0751); umask($umask); } $htpasswdDir = new frxDirectory(Settings::Get('system.apacheconf_htpasswddir')); if ($htpasswdDir->isConfigDir(true)) { foreach ($this->htpasswds_data as $htpasswd_filename => $htpasswd_file) { $this->known_htpasswdsfilenames[] = basename($htpasswd_filename); $htpasswd_file_handler = fopen($htpasswd_filename, 'w'); fwrite($htpasswd_file_handler, $htpasswd_file); fclose($htpasswd_file_handler); } } else { fwrite($this->debugHandler, ' cron_tasks: WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!' . "\n"); echo 'WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!'; $this->logger->logAction(CRON_ACTION, LOG_WARNING, 'WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!'); } } // Write virtualhosts fwrite($this->debugHandler, ' apache::writeConfigs: rebuilding ' . Settings::Get('system.apacheconf_vhost') . "\n"); $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_vhost')); if (count($this->virtualhosts_data) > 0) { $vhostDir = new frxDirectory(Settings::Get('system.apacheconf_vhost')); if (!$vhostDir->isConfigDir()) { // Save one big file $vhosts_file = ''; // sort by filename so the order is: // 1. subdomains x-29 // 2. subdomains as main-domains 30 // 3. main-domains 35 // #437 ksort($this->virtualhosts_data); foreach ($this->virtualhosts_data as $vhosts_filename => $vhost_content) { $vhosts_file .= $vhost_content . "\n\n"; } // Include diroptions file in case it exists if (file_exists(Settings::Get('system.apacheconf_diroptions'))) { $vhosts_file .= "\n" . 'Include ' . Settings::Get('system.apacheconf_diroptions') . "\n\n"; } $vhosts_filename = Settings::Get('system.apacheconf_vhost'); // Apply header $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file; $vhosts_file_handler = fopen($vhosts_filename, 'w'); fwrite($vhosts_file_handler, $vhosts_file); fclose($vhosts_file_handler); } else { if (!file_exists(Settings::Get('system.apacheconf_vhost'))) { fwrite($this->debugHandler, ' apache::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))) . "\n"); $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost')))); safe_exec('mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost')))); } // Write a single file for every vhost foreach ($this->virtualhosts_data as $vhosts_filename => $vhosts_file) { $this->known_vhostfilenames[] = basename($vhosts_filename); // Apply header $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file; $vhosts_file_handler = fopen($vhosts_filename, 'w'); fwrite($vhosts_file_handler, $vhosts_file); fclose($vhosts_file_handler); } } } }
/** * Title * * Description * * @access public */ function playSound($filename, $exclusive = 0, $priority = 0) { global $ignoreSound; if (file_exists(ROOT . 'sounds/' . $filename . '.mp3')) { $filename = ROOT . 'sounds/' . $filename . '.mp3'; } elseif (file_exists(ROOT . 'sounds/' . $filename)) { $filename = ROOT . 'sounds/' . $filename; } if (defined('SETTINGS_HOOK_BEFORE_PLAYSOUND') && SETTINGS_HOOK_BEFORE_PLAYSOUND != '') { eval(SETTINGS_HOOK_BEFORE_PLAYSOUND); } if (!$ignoreSound) { if (file_exists($filename)) { if (IsWindowsOS()) { safe_exec(DOC_ROOT . '/rc/madplay.exe ' . $filename, $exclusive, $priority); } else { safe_exec('mplayer ' . $filename, $exclusive, $priority); } } } if (defined('SETTINGS_HOOK_AFTER_PLAYSOUND') && SETTINGS_HOOK_AFTER_PLAYSOUND != '') { eval(SETTINGS_HOOK_AFTER_PLAYSOUND); } }
$group = Settings::Get('system.mod_fcgid_httpgroup'); if (Settings::Get('phpfpm.enabled') == 1) { $user = Settings::Get('phpfpm.vhost_httpuser'); $group = Settings::Get('phpfpm.vhost_httpgroup'); } // all the files and folders have to belong to the local user // now because we also use fcgid for our own vhost safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($_mypath)); } else { // back to webserver permission $user = Settings::Get('system.httpuser'); $group = Settings::Get('system.httpgroup'); safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($_mypath)); } // be sure HTMLPurifier's cache folder is writable safe_exec('chmod -R 0755 ' . escapeshellarg(dirname(__FILE__) . '/classes/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer')); // Initialize logging $cronlog = FroxlorLogger::getInstanceOf(array('loginname' => 'cronjob')); fwrite($debugHandler, 'Logger has been included' . "\n"); if (Settings::Get('panel.version') == null || Settings::Get('panel.version') != $version) { if (Settings::Get('system.cron_allowautoupdate') == null || Settings::Get('system.cron_allowautoupdate') == 0) { /** * Do not proceed further if the Database version is not the same as the script version */ fclose($debugHandler); unlink($lockfile); $errormessage = "Version of file doesnt match version of database. Exiting...\n\n"; $errormessage .= "Possible reason: Froxlor update\n"; $errormessage .= "Information: Current version in database: " . Settings::Get('panel.version') . " - version of Froxlor files: " . $version . "\n"; $errormessage .= "Solution: Please visit your Foxlor admin interface for further information.\n"; die($errormessage);
$result = $result_stmt->fetch(PDO::FETCH_ASSOC); if (isset($result['customerid']) && $result['customerid'] != '' && $result['customerid'] == $userinfo['customerid']) { if (isset($_POST['send']) && $_POST['send'] == 'send') { // do we have to remove the symlink and folder in suexecpath? if ((int) Settings::Get('perl.suexecworkaround') == 1) { $loginname = getCustomerDetail($result['customerid'], 'loginname'); $suexecpath = makeCorrectDir(Settings::Get('perl.suexecpath') . '/' . $loginname . '/' . md5($result['path']) . '/'); $perlsymlink = makeCorrectFile($result['path'] . '/cgi-bin'); // remove symlink if (file_exists($perlsymlink)) { safe_exec('rm -f ' . escapeshellarg($perlsymlink)); $log->logAction(USR_ACTION, LOG_DEBUG, "deleted suexecworkaround symlink '" . $perlsymlink . "'"); } // remove folder in suexec-path if (file_exists($suexecpath)) { safe_exec('rm -rf ' . escapeshellarg($suexecpath)); $log->logAction(USR_ACTION, LOG_DEBUG, "deleted suexecworkaround path '" . $suexecpath . "'"); } } $stmt = Database::prepare("DELETE FROM `" . TABLE_PANEL_HTACCESS . "`\n\t\t\t\t\tWHERE `customerid`= :customerid\n\t\t\t\t\tAND `id`= :id"); Database::pexecute($stmt, array("customerid" => $userinfo['customerid'], "id" => $id)); $log->logAction(USR_ACTION, LOG_INFO, "deleted htaccess for '" . str_replace($userinfo['documentroot'], '/', $result['path']) . "'"); inserttask('1'); redirectTo($filename, array('page' => $page, 's' => $s)); } else { ask_yesno('extras_reallydelete_pathoptions', $filename, array('id' => $id, 'page' => $page, 'action' => $action), str_replace($userinfo['documentroot'], '/', $result['path'])); } } } elseif ($action == 'add') { if (isset($_POST['send']) && $_POST['send'] == 'send') { $path = makeCorrectDir(validate($_POST['path'], 'path'));
ob_start(); } $github = json_decode(stripslashes($_POST['payload']), true); $ref = explode('/', $github['ref']); $user = $github['repository']['owner']['name']; $repository = $github['repository']['name']; $branch = $ref[2]; $codebase_path = $GLOBALS['codebases_path']; $codebase = sprintf('%s/%s/%s', $user, $repository, $branch); $branch_path = $codebase_path . $codebase; $commands = array("cd {$branch_path}"); // create folder structure if needed. // if no folder, we do a clone, otherwise pull if (!is_dir($branch_path)) { mkdir($branch_path, 0777, true); $commands[] = sprintf('%s clone -b %s git@github.com:%s/%s.git .', $git_path, $branch, $user, $repository); } else { $commands[] = "{$git_path} pull"; } // update submodules $commands[] = "{$git_path} submodule init"; $commands[] = "{$git_path} submodule update"; // execute commands safe_exec($commands, $output); print_r($commands); print_r($output); echo "\n\nPOST[payload]\n\n"; echo json_beautify($_POST['payload']); if ($_GET['debug_email']) { mail($_GET['debug_email'], 'git hook ' . time(), ob_get_contents()); }
Database::pexecute($result_quota_stmt, array('customerid' => $row['customerid'])); // get correct user if (Settings::Get('system.mod_fcgid') == 1 && $row['deactivated'] == '0') { $user = $row['loginname']; $group = $row['loginname']; } else { $user = $row['guid']; $group = $row['guid']; } while ($row_quota = $result_quota_stmt->fetch(PDO::FETCH_ASSOC)) { $quotafile = "" . $row_quota['homedir'] . ".ftpquota"; $fh = fopen($quotafile, 'w'); $stringdata = "0 " . $current_diskspace['all'] * 1024 . ""; fwrite($fh, $stringdata); fclose($fh); safe_exec('chown ' . $user . ':' . $group . ' ' . escapeshellarg($quotafile) . ''); } } } /** * Admin Usage */ $result_stmt = Database::query("SELECT `adminid` FROM `" . TABLE_PANEL_ADMINS . "` ORDER BY `adminid` ASC"); while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) { if (isset($admin_traffic[$row['adminid']])) { $ins_data = array('adminid' => $row['adminid'], 'year' => date('Y', time()), 'month' => date('m', time()), 'day' => date('d', time()), 'stamp' => time(), 'http' => $admin_traffic[$row['adminid']]['http'], 'ftp_up' => $admin_traffic[$row['adminid']]['ftp_up'], 'ftp_down' => $admin_traffic[$row['adminid']]['ftp_down'], 'mail' => $admin_traffic[$row['adminid']]['mail']); $ins_stmt = Database::prepare("\n\t\t\tINSERT INTO `" . TABLE_PANEL_TRAFFIC_ADMINS . "` SET\n\t\t\t`adminid` = :adminid,\n\t\t\t`year` = :year,\n\t\t\t`month` = :month,\n\t\t\t`day` = :day,\n\t\t\t`stamp` = :stamp,\n\t\t\t`http` = :http,\n\t\t\t`ftp_up` = :ftp_up,\n\t\t\t`ftp_down` = :ftp_down,\n\t\t\t`mail` = :mail\n\t\t"); Database::pexecute($ins_stmt, $ins_data); $upd_data = array('traffic' => $admin_traffic[$row['adminid']]['sum_month'], 'adminid' => $row['adminid']); $upd_stmt = Database::prepare("\n\t\t\tUPDATE `" . TABLE_PANEL_ADMINS . "` SET\n\t\t\t`traffic_used` = :traffic\n\t\t\tWHERE `adminid` = :adminid\n\t\t"); Database::pexecute($upd_stmt, $upd_data);
public function writeConfigs() { fwrite($this->debugHandler, ' nginx::writeConfigs: rebuilding ' . Settings::Get('system.apacheconf_vhost') . "\n"); $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_vhost')); $vhostDir = new frxDirectory(Settings::Get('system.apacheconf_vhost')); if (!$vhostDir->isConfigDir()) { // Save one big file $vhosts_file = ''; // sort by filename so the order is: // 1. subdomains // 2. subdomains as main-domains // 3. main-domains ksort($this->nginx_data); foreach ($this->nginx_data as $vhosts_filename => $vhost_content) { $vhosts_file .= $vhost_content . "\n\n"; } $vhosts_filename = Settings::Get('system.apacheconf_vhost'); // Apply header $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file; $vhosts_file_handler = fopen($vhosts_filename, 'w'); fwrite($vhosts_file_handler, $vhosts_file); fclose($vhosts_file_handler); } else { if (!file_exists(Settings::Get('system.apacheconf_vhost'))) { fwrite($this->debugHandler, ' nginx::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))) . "\n"); $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost')))); safe_exec('mkdir -p ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost')))); } // Write a single file for every vhost foreach ($this->nginx_data as $vhosts_filename => $vhosts_file) { $this->known_filenames[] = basename($vhosts_filename); // Apply header $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file; if (!empty($vhosts_filename)) { $vhosts_file_handler = fopen($vhosts_filename, 'w'); fwrite($vhosts_file_handler, $vhosts_file); fclose($vhosts_file_handler); } } } // htaccess stuff if (count($this->htpasswds_data) > 0) { if (!file_exists(Settings::Get('system.apacheconf_htpasswddir'))) { $umask = umask(); umask(00); mkdir(Settings::Get('system.apacheconf_htpasswddir'), 0751); umask($umask); } elseif (!is_dir(Settings::Get('system.apacheconf_htpasswddir'))) { fwrite($this->debugHandler, ' cron_tasks: WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!' . "\n"); echo 'WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!'; $this->logger->logAction(CRON_ACTION, LOG_WARNING, 'WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!'); } if (is_dir(Settings::Get('system.apacheconf_htpasswddir'))) { foreach ($this->htpasswds_data as $htpasswd_filename => $htpasswd_file) { $this->known_htpasswdsfilenames[] = basename($htpasswd_filename); $htpasswd_file_handler = fopen($htpasswd_filename, 'w'); // Filter duplicate pairs of username and password $htpasswd_file = implode("\n", array_unique(explode("\n", $htpasswd_file))); fwrite($htpasswd_file_handler, $htpasswd_file); fclose($htpasswd_file_handler); } } } }
/** * removes the immutable flag for a file * * @param string $filename the file to set the flag for * * @return boolean */ function removeImmutable($filename = null) { safe_exec(_getImmutableFunction(true) . escapeshellarg($filename)); }
/** * extract complete directories from a zipfile * * @param filename path to zipfile to extract * @param directory which directory in zipfile to extract * @param destination destination directory for files to extract * @return success true/error false */ private function ExtractZip($Filename, $Directory, $Destination) { if (!file_exists($Filename)) { return false; } //fix slash notation for correct paths if (substr($Directory, -1, 1) == '/') { $Directory = substr($Directory, 0, strlen($Directory) - 1); } if (substr($Destination, -1, 1) != '/') { $Destination .= '/'; } //open zipfile to read its contents $ZipHandle = zip_open(realpath($Filename)); if (is_resource($ZipHandle)) { while ($ZipEntry = zip_read($ZipHandle)) { if (substr(zip_entry_name($ZipEntry), 0, strlen($Directory)) == $Directory) { //fix relative path from zipfile $NewPath = zip_entry_name($ZipEntry); $NewPath = substr($NewPath, strlen($Directory)); //directory if (substr($NewPath, -1, 1) == '/') { if (!file_exists($Destination . $NewPath)) { mkdir($Destination . $NewPath, 0777, true); } } else { //files if (zip_entry_open($ZipHandle, $ZipEntry)) { $File = fopen($Destination . $NewPath, "wb"); if ($File) { while ($Line = zip_entry_read($ZipEntry)) { fwrite($File, $Line); } fclose($File); } else { return false; } } } } } zip_close($ZipHandle); return true; } else { $ReturnLines = array(); $ReturnVal = -1; //on 64 bit systems the zip functions can fail -> use exec to extract the files $ReturnLines = safe_exec('unzip -o -qq ' . escapeshellarg(realpath($Filename)) . ' ' . escapeshellarg($Directory . '/*') . ' -d ' . escapeshellarg(sys_get_temp_dir()), $ReturnVal); if ($ReturnVal == 0) { //fix absolute structure of extracted data if (!file_exists($Destination)) { mkdir($Destination, 0777, true); } safe_exec('cp -Rf ' . sys_get_temp_dir() . '/' . $Directory . '/*' . ' ' . escapeshellarg($Destination)); self::UnlinkRecursive(sys_get_temp_dir() . '/' . $Directory . '/'); return true; } else { return false; } } return false; }
public function writeConfigs() { fwrite($this->debugHandler, ' lighttpd::writeConfigs: rebuilding ' . $this->settings['system']['apacheconf_vhost'] . "\n"); $this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . $this->settings['system']['apacheconf_vhost']); if (!isConfigDir($this->settings['system']['apacheconf_vhost'])) { // Save one big file foreach ($this->lighttpd_data as $vhosts_filename => $vhost_content) { $vhosts_file .= $vhost_content . "\n\n"; } $vhosts_filename = $this->settings['system']['apacheconf_vhost']; // Apply header $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file; $vhosts_file_handler = fopen($vhosts_filename, 'w'); fwrite($vhosts_file_handler, $vhosts_file); fclose($vhosts_file_handler); } else { if (!file_exists($this->settings['system']['apacheconf_vhost'])) { fwrite($this->debugHandler, ' lighttpd::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])) . "\n"); $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost']))); safe_exec('mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost']))); } // Write a single file for every vhost foreach ($this->lighttpd_data as $vhosts_filename => $vhosts_file) { $this->known_filenames[] = basename($vhosts_filename); // Apply header $vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file; if (!empty($vhosts_filename)) { $vhosts_file_handler = fopen($vhosts_filename, 'w'); fwrite($vhosts_file_handler, $vhosts_file); fclose($vhosts_file_handler); } } $this->wipeOutOldConfigs(); } // Write the diroptions if (isConfigDir($this->settings['system']['apacheconf_htpasswddir'])) { foreach ($this->needed_htpasswds as $key => $data) { if (!is_dir($this->settings['system']['apacheconf_htpasswddir'])) { mkdir($this->settings['system']['apacheconf_htpasswddir']); } $filename = $this->settings['system']['apacheconf_htpasswddir'] . '/' . $key; $htpasswd_handler = fopen($filename, 'w'); fwrite($htpasswd_handler, $data); fclose($htpasswd_handler); } } }
// We do not want to set a quota for root by accident if ($row['guid'] != 0) { // The user has no quota in Froxlor, but on the filesystem if (($row['diskspace'] == 0 || $row['diskspace'] == -1024) && $usedquota[$row['guid']]['block']['hard'] != 0) { $cronlog->logAction(CRON_ACTION, LOG_NOTICE, "Disabling quota for " . $row['loginname']); if (isFreeBSD()) { safe_exec(Settings::Get('system.diskquota_quotatool_path') . " -e " . escapeshellarg(Settings::Get('system.diskquota_customer_partition')) . ":0:0 " . $row['guid']); } else { safe_exec(Settings::Get('system.diskquota_quotatool_path') . " -u " . $row['guid'] . " -bl 0 -q 0 " . escapeshellarg(Settings::Get('system.diskquota_customer_partition'))); } } elseif ($row['diskspace'] != $usedquota[$row['guid']]['block']['hard'] && $row['diskspace'] != -1024) { $cronlog->logAction(CRON_ACTION, LOG_NOTICE, "Setting quota for " . $row['loginname'] . " from " . $usedquota[$row['guid']]['block']['hard'] . " to " . $row['diskspace']); if (isFreeBSD()) { safe_exec(Settings::Get('system.diskquota_quotatool_path') . " -e " . escapeshellarg(Settings::Get('system.diskquota_customer_partition')) . ":" . $row['diskspace'] . ":" . $row['diskspace'] . " " . $row['guid']); } else { safe_exec(Settings::Get('system.diskquota_quotatool_path') . " -u " . $row['guid'] . " -bl " . $row['diskspace'] . " -q " . $row['diskspace'] . " " . escapeshellarg(Settings::Get('system.diskquota_customer_partition'))); } } } } } } } if ($num_results != 0) { $where = array(); $where_data = array(); foreach ($resultIDs as $id) { $where[] = "`id` = :id_" . (int) $id; $where_data['id_' . $id] = $id; } $where = implode($where, ' OR ');
/** * 1st: check for task of generation * 2nd: if task found, generate cron.d-file * 3rd: maybe restart cron? */ function checkCrondConfigurationFile() { // check for task $result_tasks_stmt = Database::query("\n\t\t\tSELECT * FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '99'\n\t\t\t"); $num_results = Database::num_rows(); // is there a task for re-generating the cron.d-file? if ($num_results > 0) { // get all crons and their intervals if (isFreeBSD()) { // FreeBSD does not need a header as we are writing directly to the crontab $cronfile = "\n"; } else { $cronfile = "# automatically generated cron-configuration by froxlor\n"; $cronfile .= "# do not manually edit this file as it will be re-generated periodically.\n"; $cronfile .= "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n#\n"; } // get all the crons $result_stmt = Database::query("\n\t\t\t\tSELECT * FROM `" . TABLE_PANEL_CRONRUNS . "` WHERE `isactive` = '1'\n\t\t\t\t"); $hour_delay = 0; $day_delay = 5; $month_delay = 7; while ($row_cronentry = $result_stmt->fetch(PDO::FETCH_ASSOC)) { // create cron.d-entry if (preg_match("/(\\d+) (MINUTE|HOUR|DAY|WEEK|MONTH)/", $row_cronentry['interval'], $matches)) { if ($matches[1] == 1) { $minvalue = "*"; } else { $minvalue = "*/" . $matches[1]; } switch ($matches[2]) { case "MINUTE": $cronfile .= $minvalue . " * * * * "; break; case "HOUR": $cronfile .= $hour_delay . " " . $minvalue . " * * * "; $hour_delay += 3; break; case "DAY": if ($row_cronentry['cronfile'] == 'traffic') { // traffic at exactly 0:00 o'clock $cronfile .= "0 0 " . $minvalue . " * * "; } else { $cronfile .= $day_delay . " 0 " . $minvalue . " * * "; $day_delay += 5; } break; case "MONTH": $cronfile .= $month_delay . " 0 1 " . $minvalue . " * "; $month_delay += 7; break; case "WEEK": $cronfile .= $day_delay . " 0 " . $matches[1] * 7 . " * * "; $day_delay += 5; break; } // create entry-line $binpath = Settings::Get("system.croncmdline"); // fallback as it is important if ($binpath === null) { $binpath = "/usr/bin/nice -n 5 /usr/bin/php5 -q"; } $cronfile .= "root " . $binpath . " " . FROXLOR_INSTALL_DIR . "/scripts/froxlor_master_cronjob.php --" . $row_cronentry['cronfile'] . " 1> /dev/null\n"; } } if (isFreeBSD()) { // FreeBSD handles the cron-stuff in another way. We need to directly // write to the crontab file as there is not cron.d/froxlor file // (settings for system.cronconfig should be set correctly of course) $crontab = file_get_contents(Settings::Get("system.cronconfig")); if ($crontab === false) { die("Oh snap, we cannot read the crontab file. This should not happen.\nPlease check the path and permissions, the cron will keep trying if you don't stop the cron-service.\n\n"); } // now parse out / replace our entries $crontablines = explode("\n", $crontab); $newcrontab = ""; foreach ($crontablines as $ctl) { $ctl = trim($ctl); if (!empty($ctl) && !preg_match("/(.*)froxlor_master_cronjob\\.php(.*)/", $ctl)) { $newcrontab .= $ctl . "\n"; } } // re-assemble old-content + new froxlor-content $newcrontab .= $cronfile; // now continue with writing the file $cronfile = $newcrontab; } // write the file if (file_put_contents(Settings::Get("system.cronconfig"), $cronfile) === false) { // oh snap cannot create new crond-file die("Oh snap, we cannot create the cron-file. This should not happen.\nPlease check the path and permissions, the cron will keep trying if you don't stop the cron-service.\n\n"); } // correct permissions chmod(Settings::Get("system.cronconfig"), 0640); // remove all re-generation tasks Database::query("DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = '99'"); // run reload command safe_exec(escapeshellcmd(Settings::Get('system.crondreload'))); } return true; }
* @copyright (c) the authors * @author Michael Kaufmann <*****@*****.**> * @author Froxlor team <*****@*****.**> (2010-) * @license GPLv2 http://files.froxlor.org/misc/COPYING.txt * @package Cron * * @since 0.9.29.1 * */ $cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'calculating mailspace usage'); $maildirs_stmt = Database::query("\n\tSELECT `id`, CONCAT(`homedir`, `maildir`) AS `maildirpath` FROM `" . TABLE_MAIL_USERS . "` ORDER BY `id`\n"); $upd_stmt = Database::prepare("\n\tUPDATE `" . TABLE_MAIL_USERS . "` SET `mboxsize` = :size WHERE `id` = :id\n"); while ($maildir = $maildirs_stmt->fetch(PDO::FETCH_ASSOC)) { $_maildir = makeCorrectDir($maildir['maildirpath']); if (file_exists($_maildir) && is_dir($_maildir)) { // mail-address allows many special characters, see http://en.wikipedia.org/wiki/Email_address#Local_part $return = false; $back = safe_exec('du -sk ' . escapeshellarg($_maildir), $return, array('|', '&', '`', '$', '~', '?')); foreach ($back as $backrow) { $emailusage = explode(' ', $backrow); } $emailusage = floatval($emailusage['0']); // as freebsd does not have the -b flag for 'du' which gives // the size in bytes, we use "-sk" for all and calculate from KiB $emailusage *= 1024; unset($back); Database::pexecute($upd_stmt, array('size' => $emailusage, 'id' => $maildir['id'])); } else { $cronlog->logAction(CRON_ACTION, LOG_WARNING, 'maildir ' . $_maildir . ' does not exist'); } }
/** * Function which make webalizer statistics and returns used traffic since last run * * @param string Name of logfile * @param string Place where stats should be build * @param string Caption for webalizer output * @return int Used traffic * @author Florian Lippert <*****@*****.**> */ function callWebalizerGetTraffic($logfile, $outputdir, $caption, $usersdomainlist) { global $cronlog; $returnval = 0; $logfile = makeCorrectFile(Settings::Get('system.logfiles_directory') . $logfile . '-access.log'); if (file_exists($logfile)) { $domainargs = ''; foreach ($usersdomainlist as $domainid => $domain) { // hide referer $domainargs .= ' -r ' . escapeshellarg($domain); } $outputdir = makeCorrectDir($outputdir); if (!file_exists($outputdir)) { safe_exec('mkdir -p ' . escapeshellarg($outputdir)); } if (file_exists($outputdir . 'webalizer.hist.1')) { @unlink($outputdir . 'webalizer.hist.1'); } if (file_exists($outputdir . 'webalizer.hist') && !file_exists($outputdir . 'webalizer.hist.1')) { safe_exec('cp ' . escapeshellarg($outputdir . 'webalizer.hist') . ' ' . escapeshellarg($outputdir . 'webalizer.hist.1')); } $verbosity = ''; if (Settings::Get('system.webalizer_quiet') == '1') { $verbosity = '-q'; } elseif (Settings::Get('system.webalizer_quiet') == '2') { $verbosity = '-Q'; } $we = '/usr/bin/webalizer'; // FreeBSD uses other paths, #140 if (!file_exists($we)) { $we = '/usr/local/bin/webalizer'; } $cronlog->logAction(CRON_ACTION, LOG_INFO, "Running webalizer for domain '" . $caption . "'"); safe_exec($we . ' ' . $verbosity . ' -p -o ' . escapeshellarg($outputdir) . ' -n ' . escapeshellarg($caption) . $domainargs . ' ' . escapeshellarg($logfile)); /** * Format of webalizer.hist-files: * Month: $webalizer_hist_row['0'] * Year: $webalizer_hist_row['1'] * KB: $webalizer_hist_row['5'] */ $httptraffic = array(); $webalizer_hist = @file_get_contents($outputdir . 'webalizer.hist'); $cronlog->logAction(CRON_ACTION, LOG_INFO, "Gathering traffic information from '" . $webalizer_hist . "'"); $webalizer_hist_rows = explode("\n", $webalizer_hist); foreach ($webalizer_hist_rows as $webalizer_hist_row) { if ($webalizer_hist_row != '') { $webalizer_hist_row = explode(' ', $webalizer_hist_row); if (isset($webalizer_hist_row['0']) && isset($webalizer_hist_row['1']) && isset($webalizer_hist_row['5'])) { $month = intval($webalizer_hist_row['0']); $year = intval($webalizer_hist_row['1']); $traffic = floatval($webalizer_hist_row['5']); if (!isset($httptraffic[$year])) { $httptraffic[$year] = array(); } $httptraffic[$year][$month] = $traffic; } } } reset($httptraffic); $httptrafficlast = array(); $webalizer_lasthist = @file_get_contents($outputdir . 'webalizer.hist.1'); $cronlog->logAction(CRON_ACTION, LOG_INFO, "Gathering traffic information from '" . $webalizer_lasthist . "'"); $webalizer_lasthist_rows = explode("\n", $webalizer_lasthist); foreach ($webalizer_lasthist_rows as $webalizer_lasthist_row) { if ($webalizer_lasthist_row != '') { $webalizer_lasthist_row = explode(' ', $webalizer_lasthist_row); if (isset($webalizer_lasthist_row['0']) && isset($webalizer_lasthist_row['1']) && isset($webalizer_lasthist_row['5'])) { $month = intval($webalizer_lasthist_row['0']); $year = intval($webalizer_lasthist_row['1']); $traffic = floatval($webalizer_lasthist_row['5']); if (!isset($httptrafficlast[$year])) { $httptrafficlast[$year] = array(); } $httptrafficlast[$year][$month] = $traffic; } } } reset($httptrafficlast); foreach ($httptraffic as $year => $months) { foreach ($months as $month => $traffic) { if (!isset($httptrafficlast[$year][$month])) { $returnval += $traffic; } elseif ($httptrafficlast[$year][$month] < $httptraffic[$year][$month]) { $returnval += $httptraffic[$year][$month] - $httptrafficlast[$year][$month]; } } } } return floatval($returnval); }
if ($settings['system']['diskquota_enabled']) { fwrite($debugHandler, ' cron_tasks: Task10 started - setting filesystem quota' . "\n"); $cronlog->logAction(CRON_ACTION, LOG_INFO, 'Task10 started - setting filesystem quota'); $usedquota = getFilesystemQuota(); # Select all customers Froxlor knows about $result = $db->query("SELECT `guid`, `loginname`, `diskspace` FROM `" . TABLE_PANEL_CUSTOMERS . "`;"); while ($row = $db->fetch_array($result)) { # We do not want to set a quota for root by accident if ($row['guid'] != 0) { # The user has no quota in Froxlor, but on the filesystem if (($row['diskspace'] == 0 || $row['diskspace'] == -1024) && $usedquota[$row['guid']]['block']['hard'] != 0) { $cronlog->logAction(CRON_ACTION, LOG_NOTICE, "Disabling quota for " . $row['loginname']); safe_exec($settings['system']['diskquota_quotatool_path'] . " -u " . $row['guid'] . " -bl 0 -q 0 " . escapeshellarg($settings['system']['diskquota_customer_partition'])); } elseif ($row['diskspace'] != $usedquota[$row['guid']]['block']['hard'] && $row['diskspace'] != -1024) { $cronlog->logAction(CRON_ACTION, LOG_NOTICE, "Setting quota for " . $row['loginname'] . " from " . $usedquota[$row['guid']]['block']['hard'] . " to " . $row['diskspace']); safe_exec($settings['system']['diskquota_quotatool_path'] . " -u " . $row['guid'] . " -bl " . $row['diskspace'] . " -q " . $row['diskspace'] . " " . escapeshellarg($settings['system']['diskquota_customer_partition'])); } } } } else { fwrite($debugHandler, ' cron_tasks: Task10 skipped - filesystem quota not enabled' . "\n"); $cronlog->logAction(CRON_ACTION, LOG_INFO, 'Task10 skipped - filesystem quota not enabled'); } } } if ($db->num_rows($result_tasks) != 0) { $where = array(); foreach ($resultIDs as $id) { $where[] = '`id`=\'' . (int) $id . '\''; } $where = implode($where, ' OR ');