function process() { if (!($c = ArgsHolder::get()->shiftCommand())) { return io::out('Incorrect parameter', IO::MESSAGE_FAIL) | 1; } $root = Config::get('ROOT_DIR'); $file = $root . '/includes/env/' . strtolower($c) . '_env.php'; if (!file_exists($file)) { return io::out('Mode ' . $c . ' not exists', IO::MESSAGE_FAIL) | 1; } IO::out('Updating Loader', false); $loader = fopen($root . '/includes/env/Loader.php', 'w'); flock($loader, LOCK_EX); $put = '<?php require_once("' . $c . '_env.php");'; fwrite($loader, $put); flock($loader, LOCK_UN); fclose($loader); io::done(); io::out('Backup config.ini', false); if (copy($root . '/config/config.ini', $root . '/config/config.ini.bak')) { io::done(); } else { return IO::out('Can\'t backup file config.ini', IO::MESSAGE_FAIL) | 1; } IO::out('Updating config.ini', false); $file_array = file($root . '/config/config.ini'); $str = null; foreach ($file_array as $fa) { if (preg_match('/\\[\\s*config\\s*:\\s*\\S+\\]/', $fa, $match)) { $str .= '[config : ' . $c . ']' . PHP_EOL; } else { $str .= $fa; } } $config = fopen($root . '/config/config.ini', 'w'); flock($config, LOCK_EX); fwrite($config, $str); flock($config, LOCK_UN); fclose($config); io::done(); IO::done('Enviroments set to ~WHITE~' . $c . '~~~'); }
public function createController($name) { IO::out('~WHITE~Checking:~~~'); if (file_exists($this->root_dir . '/controllers/' . $name . '.php')) { return io::out('Controller with name ~WHITE~' . $name . '~~~ exist!', IO::MESSAGE_FAIL); } io::done(' controllers '); if (file_exists($this->root_dir . $this->models_dir . '/' . $name)) { return io::out('Model with name ~WHITE~' . $name . '~~~ exist!', IO::MESSAGE_FAIL); } io::done(' models'); $pages = Config::get('xmlpages_dir'); if (file_exists($this->root_dir . '/' . $pages . '/' . $name)) { return io::out('Pages for model with name ~WHITE~' . $name . ' ~~~ exist!', IO::MESSAGE_FAIL); } io::done(' pages'); IO::out('~WHITE~Creating:~~~'); // TODO models_dir if (mkdir($this->root_dir . $this->models_dir . '/' . $name, 0775)) { IO::done(" {$this->models_dir} / " . $name); } else { return IO::out("Error while creating directory {$this->models_dir} / " . $name, IO::MESSAGE_FAIL); } if (copy(dirname(__FILE__) . '/templates/autoload.tpl', $this->root_dir . $this->models_dir . '/' . $name . '/autoload.php')) { io::done(" {$this->models_dir} /" . $name . '/autoload.php'); } else { return IO::out('Error while creating ' . $this->models_dir . '/' . $name . '/autoload.php', IO::MESSAGE_FAIL); } // TODO xmlpages_dir if (mkdir($this->root_dir . '/pages/' . $name, 0775)) { IO::done(' /pages/' . $name); } else { return IO::out('Error while creating directory /pages/' . $name, IO::MESSAGE_FAIL); } if (copy(dirname(__FILE__) . '/templates/controller.tpl', $this->root_dir . '/controllers/' . $name . '.php')) { io::done(' /controllers/' . $name . '.php'); } else { return IO::out('Error while creating /controllers/' . $name . '.php', IO::MESSAGE_FAIL); } }
public function process() { Console::initCore(); $this->separate = ArgsHolder::get()->getOption('separate'); $this->all = ArgsHolder::get()->getOption('all'); if ($r = ArgsHolder::get()->getOption('send-email')) { $this->send_email = true; $this->email_address = explode(",", $r); foreach ($this->email_address as $emails) { if (!preg_match(POSTChecker::$email_regexp, $emails)) { io::out("Incorrect email address format", IO::MESSAGE_FAIL); return; } } } try { $root = Config::get('ROOT_DIR'); $name = basename($root); //Create MySQL dump $sqlname = $this->createMySQL($root, $name, $this->separate); //Create backup file $filename = $this->createTar($root, $name, $this->separate); if (!$this->separate) { unlink($root . '/' . $sqlname); } if ($this->send_email) { if (is_array($this->email_address)) { $toout = implode(',', $this->email_address); } else { $toout = $this->email_address; } io::out("Sending email to ~WHITE~" . $toout . '~~~', false); $a = Mail::CreateMail(); foreach ($this->email_address as $emails) { $a->toAdd($emails); } $a->setSubject("Backup " . $filename); $a->setFromname(Config::getInstance()->mail->default_from_name); $a->setFrom(Config::getInstance()->mail->default_from); $a->Message("Backup with filename " . $filename); $a->attachAdd($root . "/" . $filename); if ($this->separate) { $a->attachAdd($root . "/" . $sqlname); } $r = $a->send(); if ($r === false) { io::out('', IO::MESSAGE_FAIL); } else { io::done(); if (ArgsHolder::get()->getOption('clean')) { IO::out('Cleaning ', false); if ($this->separate) { IO::out($sqlname . ' ', false); unlink($root . '/' . $sqlname); } IO::out($filename . ' ', false); unlink($root . '/' . $filename); IO::done(); } } } } catch (Exception $e) { io::out($e->getMessage(), IO::MESSAGE_FAIL); return; } }
function process() { $root = Config::get('ROOT_DIR'); $file_array = file_get_contents($root . '/config/config.ini'); try { //Look for php-cgi in the system $php_path = exec("which php-cgi"); if (empty($php_path) || !is_executable($php_path)) { IO::out('Look for PHP-CGI in the system.', IO::MESSAGE_FAIL); IO::out("You can't to check hosting because PHP-CGI not found."); return; } $out = exec("echo \"<?php echo 'php-cgi test' ?>\" | {$php_path} -q "); if ($out != "php-cgi test") { IO::out('Look for PHP-CGI in the system.', IO::MESSAGE_FAIL); IO::out("You can't to check hosting because PHP-CGI not found."); return; } IO::out('Look for PHP-CGI in the system.', IO::MESSAGE_OK); $toini = array(); foreach ($this->for_check as $k => $v) { $output = array(); $subcmd = '<?php $r=ini_get("' . $k . '");if($r) echo $r; else echo ((int)$r);'; exec("echo '" . $subcmd . "' | {$php_path} -q", $output); if ($k == 'error_log') { IO::out($k . ' = ' . $output[0], IO::MESSAGE_OK); continue; } if ($k == 'error_log' || $k == 'max_execution_time' || $k == 'max_input_time' || $k == 'upload_max_filesize' || $k == 'memory_limit' || $k == 'post_max_size') { $ch = str_replace('m', '', strtolower($output[0])); if ((int) $ch >= (int) $v) { IO::out($k . ' = ' . $output[0], IO::MESSAGE_OK); continue; } else { io::out($k . ' = ' . $output[0] . ' this must be >=' . $v, IO::MESSAGE_FAIL); continue; } } if ($v == $output[0]) { IO::out($k . ' = ' . $output[0], IO::MESSAGE_OK); } else { $out = array(); $subcmd = '<?php ini_set("' . $k . '","' . $v . '");$r=ini_get("' . $k . '");if($r=="' . $v . '") echo 111; else echo print_r($r);'; exec("echo '" . $subcmd . "' | {$php_path} -q", $out); if ($out[0] == 111) { $toini[$k] = $v; IO::out($k . ' = ' . $output[0] . ', but you can set "' . $v . '"', IO::MESSAGE_WARN); } else { io::out($k . ' = ' . $output[0], IO::MESSAGE_FAIL); } } } $output = array(); $subcmd = '<?php $r=ini_get("upload_max_filesize");if($r) echo $r; else echo ((int)$r);'; exec("echo '" . $subcmd . "' | {$php_path} -q", $output); $umf = str_replace('m', '', strtolower($output[0])); $output = array(); $subcmd = '<?php $r=ini_get("post_max_size");if($r) echo $r; else echo ((int)$r);'; exec("echo '" . $subcmd . "' | {$php_path} -q", $output); $pms = str_replace('m', '', strtolower($output[0])); $output = array(); $subcmd = '<?php $r=ini_get("memory_limit");if($r) echo $r; else echo ((int)$r);'; exec("echo '" . $subcmd . "' | {$php_path} -q", $output); $ml = str_replace('m', '', strtolower($output[0])); if ((int) $pms < (int) $umf) { IO::out('post_max_size < upload_max_filesize', IO::MESSAGE_FAIL); } if ((int) $pms > (int) $ml) { IO::out('post_max_size > memory_limit', IO::MESSAGE_FAIL); } if ((int) $pms >= (int) $umf && (int) $pms < (int) $ml) { IO::out('upload_max_filesize(' . $umf . ')=< ini.post_max_size(' . $pms . ') < ini.memory_limit(' . $ml . ')', IO::MESSAGE_OK); } if (is_writable('/tmp')) { IO::out('Temp dir is writable.', IO::MESSAGE_OK); } else { IO::out('Temp dir is not writable!', IO::MESSAGE_FAIL); } IO::out(); IO::out('Check for extensions:'); exec("{$php_path} -m", $output); foreach ($this->ext as $e) { if ($e == 'gd') { if (!in_array($e, $output)) { if (!in_array('imagick', $output)) { io::out('Extension ' . $e . ' or imagick are not loaded.', IO::MESSAGE_FAIL); } else { io::out('Extension imagick is loaded.', IO::MESSAGE_OK); } } else { io::out('Extension ' . $e . ' is loaded.', IO::MESSAGE_OK); } continue; } if (!in_array($e, $output)) { io::out('Extension ' . $e . ' is not loaded.', IO::MESSAGE_FAIL); } else { if ($e == 'apc') { io::out('Extension ' . $e . ' is loaded.You can set "apc.enabled=On" in php.ini.', IO::MESSAGE_OK); continue; } else { io::out('Extension ' . $e . ' is loaded.', IO::MESSAGE_OK); } } } IO::out(); IO::out('Check for modes:'); IO::out('Check for Production:'); foreach ($this->mod_production as $k => $v) { $output = array(); $subcmd = '<?php ini_set("' . $k . '",' . (int) $v . ');$r=ini_get("' . $k . '");if($r==' . $v . ') echo 1; else echo (int)$r;'; exec("echo '" . $subcmd . "' | {$php_path} -q", $output); if ($output[0]) { IO::out($k . ' = ' . $v, IO::MESSAGE_OK); } else { IO::out($k . ' = ' . $output[0], IO::MESSAGE_FAIL); } } IO::out(); IO::out('Check for Development:'); foreach ($this->mod_dev as $k => $v) { $output = array(); $subcmd = '<?php ini_set("' . $k . '",' . (int) $v . ');$r=ini_get("' . $k . '");if($r==' . $v . ') echo 1; else echo (int)$r;'; exec("echo '" . $subcmd . "' | {$php_path} -q", $output); if ($output[0]) { IO::out($k . ' = ' . $v, IO::MESSAGE_OK); } else { IO::out($k . ' = ' . $output[0], IO::MESSAGE_FAIL); } } IO::out(); if (ArgsHolder::get()->getOption('generate-ini')) { if (!empty($toini)) { io::out('Generating php.ini', false); $res = array(); if (file_exists(Config::get('ROOT_DIR') . '/php.ini')) { $file = file(Config::get('ROOT_DIR') . '/php.ini'); for ($i = 0; $i < count($file); $i++) { if ($file[$i] != "\n") { $res[strtok($file[$i], '=')] = strtok('='); } } } foreach ($toini as $k => $v) { if (!isset($res[$k])) { $res[$k] = $v; } if ($res[$k] != $toini[$k]) { $res[$k] = $toini[$k]; } } foreach ($res as $key => $val) { $write[] = $key . '=' . $val; } $f = fopen(Config::get('ROOT_DIR') . '/php.ini', 'w'); if (flock($f, LOCK_EX)) { fwrite($f, implode("\n", $write)); flock($f, LOCK_UN); } else { echo "Couldn't get the lock!"; } fclose($f); IO::done(); } } } catch (exception $e) { io::out($e->getmessage(), IO::MESSAGE_FAIL); return; } }