public function read(DOMElement $e) { $tn = end(explode(':',$e->tagName)); switch($tn) { case 'function': foreach($e->childNodes as $cnn) { if (typeOf($cnn) == 'DOMElement') { $cnt = end(explode(':',$cnn->tagName)); if ($cnt == 'from') { $this->from[] = $cnn->nodeValue; } elseif ($cnt == 'to') { $this->to = $cnn->nodeValue; } else { printf("Warning: Didn't expect %s here\n", $cnn->nodeName); } } } printf(__astr("[\b{phprefactor}] Refactoring{%s} --> %s\n"), join(', ',$this->from), $this->to); break; default: printf("I don't know what to do with %s!\n", $tn); } }
public static function listActions() { console::writeLn("Valid actions:"); foreach (self::$_actions as $action => $data) { console::writeLn(" %s: %s", __astr('\\b{' . $action . '}'), $data['info']); } }
/** * * * * */ function sets() { if (isset($this->data['sets'])) { console::writeLn(__astr("\\b{%-50s %-8s %-8s %-8s}"), 'Sets', 'CurSize', 'LastSize', 'Installed'); foreach ($this->data['sets'] as $set => $void) { console::writeLn("%-50s %-8s %-8s %-8s", $set, $this->data['filesize'][$set]['current'], $this->data['filesize'][$set]['last'], 'No'); } } else { console::writeLn(__astr("No data in the cache, try doing an \\b{update} first.")); } }
public function addFiles($pattern) { $last = count($this->files); $dir = dirname($pattern); $match = basename($pattern); if ($dir[0] != '/' && $dir[0] != '.') { $dir = './' . $dir; } $files = file_find_all($dir, $match); foreach ($files as $file) { $this->files[] = $file; } printf(__astr("[\\b{fileset}] Added %s, %d files total (%d new)\n"), $pattern, count($files), count($files) - $last); }
function match($pattern = '*') { $hf = fopen('/etc/hosts', 'r'); console::writeLn(__astr('\\b{%-20s %-15s %-6s %s}'), 'Groupname', 'Target', 'Act', 'Hosts'); $groupname = null; $hosts = array(); while (!feof($hf)) { $h = fgets($hf); $h = str_replace("\r", "", $h); $h = str_replace("\n", "", $h); $h = trim($h); if (strlen($h) > 0) { if ($h[0] == '#') { $c = explode(' ', trim(substr($h, 1))); if ($c[0] == 'GROUP') { $groupname = $c[1]; $active = $c[2] == 'ENABLED'; } elseif ($c[0] == 'ENDGROUP') { $hostlist = array(); foreach ($hosts as $host) { if (strlen(trim($host)) > 0) { $hostlist[] = trim($host); } } if (count(array_unique($targets)) == 1) { $target = $targets[0]; } else { $target = 'Multiple'; } console::writeLn('%-20s %-15s %-6s %s', $groupname, $target, $active ? 'Yes' : 'No', join(', ', $hostlist)); $groupname = null; $hosts = array(); $targets = array(); } elseif ($groupname != null) { $hosts = array_merge($hosts, array_slice($c, 1)); $targets[] = $c[0]; } } elseif ($groupname != null) { $c = explode(' ', trim($h)); $hosts = array_merge($hosts, array_slice($c, 1)); $targets[] = $c[0]; } } } }
/** * @brief Show usage information on the command. * * If -h is specified as a valid argument, it will invoke the usage() * method. Data displayed from this method is hosted in the application. * */ function usage() { $args = array(); $cmds = array(); $cmdlist = array(); $optsingle = array(); $optsargs = array(); foreach ($this->arguments as $arg => $val) { $opts = ''; if (strlen($val[0]) > 1) { $optsargs[] = $val[0][0]; } else { $optsingle[] = $val[0]; } if ($val[0] != null) { $opts .= '-' . $val[0][0]; } if (strlen($val[0]) > 2) { $opts .= 'arg'; } if ($val[1] != NULL) { if ($opts != '') { $opts .= ','; } $opts .= '--' . $val[1]; } if (strlen($val[0]) > 1) { $opts .= ' arg'; } $desc = $val[2]; $args[] = sprintf(" %-20s %s", __astr($opts), $desc); } if (isset($this->commands)) { foreach ($this->commands as $cmd) { $cmds[] = sprintf(" %-20s %s", __astr($cmd[0]), $cmd[1]); $tmp = explode(' ', $cmd[0]); $cmdlist[] = $tmp[0]; } } $argstr = sprintf('[-%s]', join('', $optsingle)); foreach ($optsargs as $optarg) { $argstr .= sprintf(' [-%s arg]', $optarg); } Console::writeLn("%s - %s", $this->getName(), $this->description); if (isset($this->copyright)) { console::writeLn("%s", $this->copyright); } if (isset($this->license)) { console::writeLn("%s", $this->license); } Console::writeLn(""); Console::writeLn("Usage:"); if (count($cmdlist) > 0) { $cmdstr = '[' . join('|', $cmdlist) . ']'; } else { $cmdstr = ''; } Console::writeLn(" %s %s %s %s", $this->getName(), $argstr, $cmdstr, __astr('\\g{params...}')); Console::writeLn(""); Console::writeLn("Arguments:"); console::writeLn(join("\n", $args)); Console::writeLn(); if (count($cmds) > 0) { Console::writeLn("Commands:"); console::writeLn(join("\n", $cmds)); Console::writeLn(); } Console::writeLn("Environment Variables:"); Console::writeLn(" APP_PATH The application dir path"); Console::writeLn(" SYS_PATH The system path"); Console::writeLn(" DEBUG Show extended debug info (1-5)"); Console::writeLn(" LOGFILE Log file to output debug info to"); Console::writeLn(""); console::writeLn("%s (%s)", LEPTON_PLATFORM_ID, PHP_RUNTIME_OS); console::writeLn("Allocated %0.3f KB (%0.3f KB total used)", memory_get_usage() / 1024 / 1024, memory_get_usage(true) / 1024 / 1024); }
function package($op = null, $pkgname = null) { ModuleManager::load('lepton.utils.l2package'); switch ($op) { case 'install': $pm = new L2PackageManager(); $pkg = new L2Package($pkgname); $pm->installPackage($pkg); break; case 'remove': $pm = new L2PackageManager(); $pkg = new L2Package($pkgname); $pm->removePackage($pkg); break; case 'list': $pm = new L2PackageManager(); $pm->listPackages(); break; default: Console::writeLn(__astr("\\b{Package}: Manage packages (l2p)")); Console::writeLn(__astr(" package \\b{install} \\u{package.l2p} Installs a package")); Console::writeLn(__astr(" package \\b{remove} \\u{package} Removes a package")); Console::writeLn(__astr(" package \\b{list} [\\u{package}] List packages")); Console::writeLn(__astr(" package \\b{info} [\\u{package}] Show information on packages")); Console::writeLn(__astr(" package \\b{find} [\\u{filename}] Find package that owns file")); Console::writeLn(__astr(" package \\b{update} [\\u{package}|\\b{all}] List packages")); Console::writeLn(); } }
function compile() { $this->openDatabase(); foreach ($this->db as $key => $val) { if (string::like('lang:*', $key)) { $out = ''; $keyparts = explode(':', $key); $lang = $keyparts[1]; $out = sprintf("<?php\n// Do not edit! Automatically generated by 'lepton strings'\n\n"); $out .= sprintf("intl::registerLanguage('%s',array(\n", $lang); foreach ($val as $src => $str) { $out .= sprintf(" '%s' => '%s'", str_replace('\'', '\\\'', $src), str_replace('\'', '\\\'', $str)); if ($str != end($val)) { $out .= ','; } $out .= "\n"; } $out .= sprintf("));"); console::writeLn(__astr("\\g{Generated:} %s"), $lang); file_put_contents(base::appPath() . 'languages/' . $lang . '.php', $out); } } }
function extensions() { $cb = 0; Console::writeLn(__astr("\\b{Loaded extensions:}")); $ext = get_loaded_extensions(); sort($ext); foreach ($ext as $val) { Console::write(' %-18s', $val); $cb++; if ($cb > 3 && $val != end($ext)) { Console::writeLn(); $cb = 0; } } Console::writeLn(); Console::writeLn(); }
function ppp($command = null) { $args = func_get_args(); $args = array_slice($args, 1); using('lepton.user.providers.ppp'); switch ($command) { case 'genkey': if (count($args) > 0) { $key = PppAuthentication::generateSequenceKeyFromString($args[0]); console::writeLn(__astr("Plaintext String: \\b{%s}"), $args[0]); } else { $key = PppAuthentication::generateRandomSequenceKey(); } console::writeLn(__astr("Generated key: \\b{%s}"), $key); break; case 'printcard': if (count($args) > 1) { $key = PppAuthentication::generateSequenceKeyFromString($args[1]); console::writeLn(__astr("Plaintext String: \\b{%s}"), $args[1]); } else { $key = PppAuthentication::generateRandomSequenceKey(); } console::writeLn(__astr("Generated key: \\b{%s}"), $key); if (count($args) > 0) { $card = intval($args[0]) - 1; } else { $card = 0; } PppAuthentication::printPasswordCard($key, 4, $card); break; case 'printcode': if (count($args) > 2) { $key = PppAuthentication::generateSequenceKeyFromString($args[2]); console::writeLn(__astr("Plaintext String: \\b{%s}"), $args[2]); console::writeLn(__astr("Generated key: \\b{%s}"), $key); } else { $key = PppAuthentication::generateRandomSequenceKey(); console::writeLn(__astr("Generated key: \\b{%s}"), $key); } if (count($args) > 1) { $card = $args[0]; $code = $args[1]; } else { $card = 0; $code = 1; } console::writeLn(PppAuthentication::getCode($key, $code, 4)); break; case 'getlotto': $key = PppAuthentication::generateRandomSequenceKey(); $code = rand(0, 65535); console::writeLn(PppAuthentication::getLotto($key, $code)); break; case 'tostring': if (count($args) > 0) { console::writeLn(PppAuthentication::cardIndexToString($args[0])); } else { console::writeLn("Not enough parameters."); } break; case '': console::writeLn(__astr("ppp \\b{printcard} [\\u{card} [\\u{key}]] -- Print a specific card (with specific key)")); console::writeLn(__astr("ppp \\b{printcode} [\\u{card} \\u{code} [\\u{key}]] -- Print code from card")); console::writeLn(__astr("ppp \\b{genkey} [\\u{string}] -- Generate key (from string)")); console::writeLn(__astr("ppp \\b{getlotto} -- return lotto numbers")); console::writeLn(__astr("ppp \\b{tostring} \\u{code} -- return string representation of code index")); break; default: console::writeLn("Bad command."); } }
public function initialize($rootuser = null) { console::writeLn(__astr('\\b{Initializing database}')); $db = config::get('lepton.db.default'); $dbc = config::get('lepton.db.default'); console::writeLn(" Database: %s", $dbc['database']); console::writeLn(" User: %s", $dbc['username']); console::writeLn(" Host: %s", $dbc['hostname']); switch ($db['driver']) { case 'pdo/mysql': case 'mysql': console::writeLn(" Driver: MySQL"); break; default: console::fatal('This version of the script does not support anything else than MySQL'); exit(1); } console::writeLn(__astr("\n\\b{Creating database and user}")); console::writeLn(" The script can create the database and the user. Hit enter to skip this step."); console::write(" Password for root user: "******"SHOW DATABASES LIKE %s", $dbc['database']); if (count($dblist) == 0) { console::writeLn("Creating database..."); try { $conn->exec(sprintf("CREATE DATABASE %s;", $dbc['database'])); } catch (Exception $e) { console::writeLn("Not successful, does the database already exist?"); } } console::writeLn("Creating user..."); $conn->exec(sprintf("GRANT ALL ON %s.* TO %s@localhost IDENTIFIED BY '%s';", $dbc['database'], $dbc['username'], $dbc['password'])); $conn->exec("USE " . $dbc['database']); } else { console::writeLn("No password specified, ignoring database and user creation."); $conn = new DatabaseConnection(); } console::writeLn(__astr("\n\\b{Importing tables}")); $f = glob(base::basePath() . '/dist/sql/*.sql'); foreach ($f as $fn) { $fc = file_get_contents($fn); console::writeLn(" [sys] %s", basename($fn)); $conn->exec($fc); } $f = glob(base::appPath() . '/sql/*.sql'); foreach ($f as $fn) { $fc = file_get_contents($fn); console::writeLn(" [app] %s", basename($fn)); $conn->exec($fc); } console::writeLn("All done."); }
protected function printValue($key, $val, $inst = 0) { $defs = $this->conf->getDefs($key); if (arr::hasKey($defs, 'vartype')) { $typeset = $defs['vartype']; } else { $typeset = typeof($val); } if ($inst == 0) { printf(__astr("'\\b{%s}' = \\g{%s(}"), $key, $typeset); } if (typeof($val) == 'array') { foreach ($val as $k => $v) { $this->printValue($k, $v, $inst + 1); } } else { switch ($typeset) { case 'boolean': if ($val) { printf(__astr("\\c{ltcyan true}")); } else { printf(__astr("(\\c{cyan false})")); } break; case 'NULL': printf(__astr("\\c{red NULL}")); break; case 'integer': printf(__astr("\\c{cyan %d}"), $val); break; case 'float': printf(__astr("\\c{cyan %.2f}"), $val); break; default: printf(__astr("\\c{yellow '%s'}"), $val); } if ($inst == 0) { printf(__astr("\\g{)} ")); } printf(__astr(" \\c{ltgreen //} \\c{green %s}"), $defs['description']); printf("\n"); } }
public function listPackages() { Console::writeLn(__astr("\\b{Installed packages:}")); foreach ($this->cache['special:installed'] as $pkg => $x) { Console::writeLn(__astr(" \\b{%s}: Installed"), $pkg); } Console::writeLn(__astr("\\b{Available packages:}")); $g = glob(APP_PATH . '/pkg/*.l2?'); foreach ($g as $package) { Console::write(__astr(" \\b{%s}: "), basename($package)); $p = new L2Package($package); Console::writeLn("%s (%s)", $p->getTitle(), $p->getVersion()); } }
/** * * @return Option key */ function runMenu() { while (true) { $col = 0; console::writeLn($this->title); $keys = array(); foreach ($this->options as $key => $option) { if ($this->width) { console::write(' [%s] %-' . $this->width . 's', $option['state'] ? __astr('\\b{x}') : ' ', $key); } else { console::writeLn(' %s. [%s] %s', $key, $option['state'] ? __astr('\\b{x}') : ' ', $option['value']); } if ($this->columns) { $col++; if ($col > $this->columns) { $col = 0; console::writeLn(); } } $keys[] = $key; } if ($this->columns && $col > 0) { console::writeLn(); } if (count($keys) > 10) { $keys = array_merge(array_slice($keys, 0, 9), array('...')); } $keystr = join('/', $keys); $prompt = '[Y/n/help/all/none/invert/reset/' . $keystr . ']: '; $rl = readline::read($prompt); foreach (explode(' ', $rl) as $r) { foreach ($this->options as $key => $option) { if ($key == $r) { $this->options[$key]['state'] = !$this->options[$key]['state']; } } if (strtolower($r) == 'help') { console::writeLn("Type any of the alternatives listed above. They will be evaluated in the order they are provided."); console::writeLn("When you are done, hit enter on an empty line or enter 'y'. To cancel, enter 'n'."); } if (strtolower($r) == 'y' || $r == '') { return true; } if (strtolower($r) == 'n') { return false; } if (strtolower($r) == 'all') { foreach ($this->options as $key => $option) { $this->options[$key]['state'] = true; } } if (strtolower($r) == 'none') { foreach ($this->options as $key => $option) { $this->options[$key]['state'] = false; } } if (strtolower($r) == 'reset') { foreach ($this->options as $key => $option) { $this->options[$key]['state'] = $this->options[$key]['default']; } } if (strtolower($r) == 'invert') { foreach ($this->options as $key => $option) { $this->options[$key]['state'] = !$this->options[$key]['state']; } } } } }