public function cmdDel() { if (($login = ArgsHolder::get()->shiftCommand()) === false) { return io::out('Incorrect param count', IO::MESSAGE_FAIL) | 1; } if (IO::YES != io::dialog('Do You really want to delete user ~RED~' . $login . '~~~?', IO::NO | IO::YES, IO::NO)) { return io::out('Cancelled ', IO::MESSAGE_FAIL) | 2; } try { if (ArgsHolder::get()->getOption('confirm')) { if (OneTimeTokenAuth::exists($user_id = User::findIdBy('login', $login))) { io::out('Deleting User... ', false); OneTimeTokenAuth::deleteByUserId($user_id); return io::done(); } else { return io::out('There is no user ~WHITE~' . $login . '~~~', IO::MESSAGE_FAIL) | 2; } } if ($user = User::findBy("login", $login)) { io::out('Deleting user ', false); $user->delete(); io::done(); } else { return io::out('There is no user ~WHITE~' . $login . '~~~', IO::MESSAGE_FAIL) | 2; } } catch (UserException $e) { return io::out($e->getMessage(), IO::MESSAGE_FAIL) | 127; } }
public function RestartById($c) { if (!count(DB::query('SELECT * from ' . self::TABLE . ' WHERE id="' . $c . '"'))) { io::out("Work with id={$c} is not exists", IO::MESSAGE_FAIL); return; } $list = DB::query('SELECT * FROM ' . self::TABLE . ' where isnull(finished_at) and not isnull(locked_at) and isnull(failed_at) and id=' . $c . ' ORDER BY run_at DESC'); if (count($list)) { IO::out("This is working now...You cant restart!", IO::MESSAGE_FAIL); return; } if (IO::YES == io::dialog('Do you really want to restart work with id ' . $c . '?', IO::NO | IO::YES, IO::NO)) { DB::query("UPDATE " . self::TABLE . " set attempts='1',finished_at=null, locked_at=null, \n failed_at=null, run_at=now() WHERE id='" . $c . "'"); $php_path = exec("which php"); if (empty($php_path)) { return $this->log("###" . date("c") . " Call from console PHP executable not found"); } if (!is_executable($php_path)) { return $this->log("###" . date("c") . " Call from console {$php_path} could not be executed"); } exec($php_path . ' ' . trim(escapeshellarg(Config::get('ROOT_DIR') . "/vendors/delayedjob/JobHandler.php"), "'") . ' >> ' . Config::get('ROOT_DIR') . '/logs/delayedjob.log 2>&1 &'); io::done('Restarting...'); } else { io::done('Cancel restart'); } IO::out(""); }
function cmdUnlock() { IO::out('Unlocking Package Manager', false); $pm = new PM(); if ($pm->unlock(true)) { io::done(); } }
public function deleteQueue($c) { if (!DB::query('SELECT id from ' . self::TABLE . ' WHERE queue="' . $c . '"')) { io::out("Queue {$c} is not exists", IO::MESSAGE_FAIL); return; } if (IO::YES == io::dialog('Realy you really want to delete all jobs with queue ' . $c . '?', IO::NO | IO::YES, IO::NO)) { DB::query("DELETE FROM " . self::TABLE . " WHERE queue='" . $c . "'"); io::done('Deleting...'); } else { io::done('Cancel delete'); } }
public function cmdDeluser() { $login = ArgsHolder::get()->shiftCommand(); $group = ArgsHolder::get()->shiftCommand(); if ($login === false || $group === false) { return io::out('Incorrect param count', IO::MESSAGE_FAIL) | 1; } if (!in_array($group, array_values(ACL::getGroups()))) { return io::out("No such group {$group}", IO::MESSAGE_FAIL) | 3; } if (!($id = UserManager::get()->getIdByLogin($login))) { return io::out("No such user {$login}", IO::MESSAGE_FAIL) | 3; } if (IO::YES == io::dialog('Remove user ~WHITE~ ' . $login . '~~~ from group ~WHITE~' . $group . '~~~', IO::NO | IO::YES, IO::YES)) { io::out('deleting...', false); ACL::deleteUserFromGroup($id, $group); io::done(); } }
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 . '~~~'); }
function process() { $root = Config::get('ROOT_DIR'); if (($src = ArgsHolder::get()->shiftCommand()) === false || ($new = ArgsHolder::get()->shiftCommand()) === false) { return io::out('Incorrect param count', IO::MESSAGE_FAIL) | 1; } $src_file = $root . '/includes/env/' . strtolower($src) . '_env.php'; $new_file = $root . '/includes/env/' . strtolower($new) . '_env.php'; if (file_exists($new_file)) { return io::out('Enviroments ~WHITE~' . $new . '~~~ already exists!', IO::MESSAGE_FAIL) | 2; } if (!file_exists($src_file)) { return io::out('Source enviroments ~WHITE~' . $src . '~~~ is not exists!', IO::MESSAGE_FAIL) | 2; } io::out('Writing files', false); if (!copy($src_file, $new_file)) { return io::out('Unable copy env files (' . $src_file . ' to ' . $new_file . ')', IO::MESSAGE_FAIL) | 3; } $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 .= '[' . $new . ': base ]' . PHP_EOL . $match[0] . PHP_EOL; } else { $str .= $fa; } } $config = fopen($root . '/config/config.ini', 'w'); flock($config, LOCK_EX); $r = fwrite($config, $str); flock($config, LOCK_UN); fclose($config); if (!$r) { return io::out('Cant write ~WHITE~config.ini~~~', IO::MESSAGE_FAIL) | 4; } io::done(); }
public function cmdRemove() { if (($name = ArgsHolder::get()->shiftCommand()) === false) { return io::out('Incorrect param count', IO::MESSAGE_FAIL); } if (file_exists($this->root_dir . '/controllers/' . $name . '.php')) { if (IO::YES == io::dialog('Realy Delete controller,models,pages with name ~WHITE~' . $name . '~~~?', IO::NO | IO::YES, IO::NO)) { IO::out('~WHITE~Removing:~~~'); self::rRem($this->root_dir . '/controllers/' . $name . '.php'); io::done(' controllers/' . $name . '.php'); self::rRem($this->root_dir . $this->models_dir . '/' . $name); io::done(' ' . $this->models_dir . '/' . $name); self::rRem($this->root_dir . '/pages/' . $name); io::done(' pages/' . $name); } } else { io::out('Controller with name ~WHITE~' . $name . '~~~ not exist ', IO::MESSAGE_FAIL); } }
public function createTar($root, $name, $separate = null) { if (file_exists($root . '/' . $name . "_" . date('Ymd') . ".tar.bz2")) { $filename = $name . "_" . date('Ymd_H_i_s') . '.tar'; } else { $filename = $name . "_" . date('Ymd') . '.tar'; } //$cmd="tar -cvf ".$root."/".$filename." ".$root." --exclude='*web*' --exclude='*~'"; chdir($root); IO::out('Packing main... ' . "\t", false); if ($this->all) { $cmd = "tar --exclude='.svn' --exclude='*~' -cvf " . $root . "/" . $filename . " * 2>&1"; } else { $cmd = "tar --exclude='web' --exclude='.svn' --exclude='*~' -cvf " . $root . "/" . $filename . " * 2>&1"; } exec($cmd, $out, $return); if ($return == 0) { io::done(); } if (IO::getVerboseLevel() == IO::MESSAGE_INFO || $return) { foreach ($out as $o) { io::out($o); } } if ($return) { io::out('Return code ' . $return, IO::MESSAGE_FAIL); io::out('Executed command: ' . $cmd); return; } if (!$this->all) { $cmd = "tar --exclude='*~' --exclude='.svn' -uvf " . $root . "/" . $filename . " ./web/css/ ./web/js/ 2>&1"; io::out('Adding web/css, web/js...', false); exec($cmd, $out, $return); if ($return == 0 && !$this->all) { io::done(); } if (IO::getVerboseLevel() == IO::MESSAGE_INFO || $return) { foreach ($out as $o) { io::out($o); } } if ($return) { io::out('Return code ' . $return, IO::MESSAGE_FAIL); io::out('Executed command: ' . $cmd); return; } } io::out('Bzip ' . $filename . '...', false); $cmd = "bzip2 -9 " . $root . "/" . $filename; exec($cmd, $out, $return); if ($return == 0) { io::done(); } if (IO::getVerboseLevel() == IO::MESSAGE_INFO || $return) { foreach ($out as $o) { io::out($o); } } if ($return) { io::out('Return code ' . $return, IO::MESSAGE_FAIL); io::out('Executed command: ' . $cmd); return; } return $filename . ".bz2"; }
static function undeploy($dir) { $f = $dir->getFile('queries.sql'); // файла нет или он пустой if (!$f->canRead() || ($queries = file_get_contents($f)) === false) { return; } io::out("\t" . '[~PURPLE~Q~~~] ' . basename($f->getParent()) . '/' . basename($f) . '~~~', false); SqlTask::execQuery($queries); io::done(); }
/** * Снимает блокировку системы. * */ function cmdUnlock() { IO::out('Unlocking Package Manager', false); if (PackageManager::get()->unlock(true)) { io::done(); } }
function delete($what) { io::out('Deleting: '); foreach ($what as $t) { echo $t; if (file_exists($t)) { if (is_dir($t)) { $t = new Dir($t, true); } else { $t = new File($t, true); } $r = $t->delete(); io::done(); } else { echo " Not found."; } echo PHP_EOL; } }
function cmdFlush() { io::out('Flushing repository information...', false); $this->rl->flushRepositories(); io::done(); }
public function process() { Console::initCore(); $version = array(); exec('tidy -v 2>&1', $version, $ret); $version = implode("\n", $version); if ($ret != 0) { return io::out("You should install tidy to use converter. Exiting.") | 1; } $ah = ArgsHolder::get(); $this->show_body_only = $ah->getOption('show-body-only'); $this->tidy_only = $ah->getOption('tidy-only'); if ($f = ArgsHolder::get()->getOption('output')) { $this->output_file = trim($f, "/"); } if (($filename = ArgsHolder::get()->shiftCommand()) === false) { $this->cmdHelp(); return io::out("Choose file to convert. Exiting.", IO::MESSAGE_FAIL) | 2; } if (!file_exists($filename)) { $filename = getcwd() . "/" . trim($filename, "/"); } touch($filename); if (!file_exists($filename)) { return io::out("File " . $filename . " not found", IO::MESSAGE_FAIL) | 2; } if (!empty($this->output_file)) { if (dirname($this->output_file) == "") { $this->output_file = getcwd() . "/" . $this->output_file; } if (!is_dir(dirname($this->output_file))) { return io::out("Output direcotory doesn't exists", IO::MESSAGE_FAIL) | 4; } touch($this->output_file); } $output = $ret = null; exec("tidy -config " . escapeshellarg(dirname(__FILE__) . "/tidy.config") . " -q " . ($this->show_body_only ? " --show-body-only yes " : " ") . (" --error-file " . escapeshellarg(dirname(__FILE__)) . "/error.log ") . escapeshellarg($filename), $output, $ret); if ($ret == 0) { io::done('Tidy-ize done. '); } elseif ($ret == 1) { io::out('Tidy-ize done, but with warnings. (' . dirname(__FILE__) . "/error.log) ", IO::MESSAGE_WARN); } else { return io::out("Tidy-ize failed. ", IO::MESSAGE_FAIL) | 3; } if ($this->tidy_only) { if (!empty($this->output_file)) { io::out('Writing html to file '); $_r = file_put_contents($this->output_file, implode("\n", $output)); if ($_r === false) { return io::out("Can't write to file. May be permission denied? ", IO::MESSAGE_FAIL) | 5; } io::done(); } else { echo implode("\n", $output) . "\n"; } return 0; } $doc = new DOMDocument('1.0', 'utf-8'); $doc->loadHTML(implode("\n", $output)); $doc->encoding = "utf-8"; $subst = array("a" => "WHyperLink", "td" => "WTableColumn", "tr" => "WTableRow", "th" => "WTableHeader", "table" => "WTable", "br" => "WText:br:1", "img" => "WImage", "abbr" => "WText:abbr:1", "acronym" => "WText:acronym:1", "address" => "WText:address:1", "b" => "WText:b:1", "big" => "WText:big:1", "blockquote" => "WText:blockquote:1", "button" => "WButton:type:button", "cite" => "WText:cite:1", "code" => "WText:code:1", "div" => "WBlock", "dfn" => "WText:dfn:1", "em" => "WText:em:1", "fieldset" => "WFieldSet", "form" => "WForm", "h1" => "WText:h:1", "h2" => "WText:h:2", "h3" => "WText:h:3", "h4" => "WText:h:4", "h5" => "WText:h:5", "h6" => "WText:h:6", "hr" => "WText:hr:1", "i" => "WText:i:1", "input" => "WEdit", "ins" => "WText:ins:1", "kbd" => "WText:kbd:1", "li" => "WListItem", "ol" => "WList:ol:1", "option" => "WSelectOption", "p" => "WText:p:1", "pre" => "WText:pre:1", "q" => "WText:q:1", "samp" => "WText:samp:1", "script" => "WInlineScript", "select" => "WSelect", "small" => "WText:small:1", "span" => "WText", "strike" => "WText:strike:1", "strong" => "WText:strong:1", "style" => "WCSS", "sub" => "WText:sub:1", "sup" => "WText:sup:1", "textarea" => "WTextarea", "ul" => "WList", "var" => "WText:var:1", "body" => "root"); foreach ($subst as $replace_from => $replace_to) { @(list($replace_to, $new_attr_name, $new_attr_value) = explode(":", $replace_to)); $nl = $doc->getElementsByTagName($replace_from); for ($i = 0, $c = $nl->length; $i < $c; $i++) { $n_dn = $doc->createElement($replace_to); $cn = $nl->item(0); $cnl = $cn->childNodes; if ($cn->hasAttributes()) { foreach ($cn->attributes as $attrName => $attrNode) { if (substr((string) $attrNode->value, 0, 2) != "__" && !empty($attrNode->value)) { $n_dn->setAttribute((string) $attrName, $attrNode->value); } } } if (isset($new_attr_value, $new_attr_name)) { $n_dn->setAttribute($new_attr_name, $new_attr_value); } for ($j = 0; $j < $cnl->length; $j++) { if ($cnl->item($j) instanceof DOMText) { $n_dn->appendChild($doc->createTextNode($cnl->item($j)->nodeValue)); } else { $n_dn->appendChild($cnl->item($j)->cloneNode(true)); } } $cn->parentNode->replaceChild($n_dn, $cn); } } io::out('Dumping XML...', false); if ($this->show_body_only) { if (!empty($this->output_file)) { file_put_contents($this->output_file, utf8_decode($doc->saveXML($doc->getElementsByTagName("root")->item(0)))); } else { echo utf8_decode($doc->saveXML($doc->getElementsByTagName("root")->item(0))); } } else { if (!empty($this->output_file)) { $doc->save($this->output_file); } else { echo $doc->saveXML(); } } io::done(); }
/** * Инсталяция пакета * * Пакет $package может быть представлен ввиде локального фала(~/mypackage.tbz), * имени пакета (admin) или ввиде имени пакет, версии и отношения (news>=2.0-alpha) * * @throw PackageManagerException, RepositoryListException * @param string $package */ static function install($package) { // локальный файл if (($fp = realpath($package)) !== false) { if (($p = Package::isPackage(new File($fp, true))) !== false) { $package = $p; } else { throw new PackageManagerException('Given file (' . $package . ') isn\'t a well formed package.'); } } // зависимости io::out('~WHITE~Checking dependencies~~~'); $installList = Deps::calculate($package); if ($installList === false) { throw new PackageManagerException('Невозможно удовлетворить зависимости, или не найдены требуемые пакеты.'); } elseif ($installList instanceof Package) { return IO::out('Установленная версия пакета ' . $installList->name . ': ' . $installList->version) | 0; } $newPackages = array(); $updatePackages = array(); $installedPackages = array(); $list = array(); for ($i = 0, $c = count($installList); $i < $c; $i++) { $package = $installList[$i]; if ($package->status != Package::INSTALLED) { $list[] = $package; } // for information oupput if ($package->status == Package::INSTALLED) { $installedPackages[] = $package; } else { if (false === ($p = PackageManager::getInstalledPackage($package->name))) { $newPackages[] = $package; } else { $updatePackages[] = $p; } } } foreach ($newPackages as $p) { $n[] = $p->name . '(' . $p->version . ')'; } if (isset($n)) { io::out('New Packages: ' . implode(', ', $n)); } foreach ($updatePackages as $p) { $u[] = $p->name . '(' . $p->version . ')'; } if (isset($u)) { io::out('Packages to be updated: ' . implode(', ', $u)); } foreach ($installedPackages as $p) { $inst[] = $p->name . '(' . $p->version . ')'; } if (isset($inst)) { io::out('Installed Packages: ' . implode(', ', $inst)); } // доставка $deployList = array(); io::out('~WHITE~Fetching packages~~~'); $dDir = self::getDownloadDir(); foreach ($list as $package) { io::out($package->name . '_' . $package->version . ': ', false); $tFile = $dDir->getFile($package->name . '_' . $package->version . '.tbz'); //look in downloaded dir $p = Package::isPackage($tFile); if ($p instanceof Package && $p->name == $package->name && $p->version == $package->version) { io::out('Already downloaded', false); $deployList[] = $p; } else { // откат для скачанногофайла PackageManager::getRollback()->push('delete', $tFile); $deployList[] = $package->delivery($tFile); } io::done(); } try { foreach ($deployList as $p) { io::out('~WHITE~Deploying ' . $p->name . '(' . $p->version . '):~~~'); $p->deploy(); $p->file->move(PackageManager::getInstalledDir()->getFile($p->name . '_' . $p->version . '.tbz')); PackageManager::get()->packagesSequence->addPackage($p->name, $p->version); } } catch (Exception $e) { echo $e->getMessage(); PackageManager::getRollback()->stepBack(); } return; }