/** * */ static function readLine($hidden = false) { if ($hidden) { return console::readPass(); } return console::readLn(); }
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."); }
function test($username = null) { using('lepton.user.*'); using('lepton.mvc.request'); if ($username) { console::write("Password: "******"Success!"); } } else { console::writeLn("Use: user test username"); } }
function main($argc, $argv) { if ($this->getParameterCount() == 0) { $this->usage(); return 1; } switch ($this->getParameter(0)) { case 'call': if ($this->hasArgument('u')) { $user = $this->getArgument('u'); $pass = null; if ($this->hasArgument('p')) { printf('Password: '******':', $paramlistitem . ':'); $data[$k] = $v; } $site = $this->conf->vs_siteurl; $xc = new XmlrpcClient($site . '/api/xmlrpc', $user, $pass); $ret = $xc->call($this->getParameter(1), $data); if ($ret) { if (arr::hasKey($ret, 'faultCode')) { printf("Error %d: %s\n", $ret['faultCode'], $ret['faultString']); } else { debug::inspect($ret, false, false); } } else { printf("Server error.\n"); } break; case 'config': $editor = new ConfigEditor(); $editor->loop(); break; case 'set': $key = $this->getParameter(1); $defs = $this->conf->getDefs($key); $val = $this->getParameter(2); $this->printValue($key, $val); switch ($defs['vartype']) { case 'boolean': if ($val == "1") { $this->conf->{$key} = true; } else { $this->conf->{$key} = false; } break; case 'integer': $this->conf->{$key} = intval($val); break; case 'float': $this->conf->{$key} = floatval($val); break; default: $this->conf->{$key} = $val; } break; case 'get': if ($this->getParameterCount() > 1) { $key = $this->getParameter(1); $val = $this->conf->{$key}; $this->printValue($key, $val); } else { $keys = $this->conf->getAll(); ksort($keys); foreach ($keys as $key => $val) { if ($key) { $this->printValue($key, $val); } } } break; case 'backup': $filename = $this->getParameter(1); printf("Backing up to %s...\n", $filename); $keys = $this->conf->getAll(); file_put_contents($filename, serialize($keys)); break; case 'restore': $filename = $this->getParameter(1); printf("Restoring from %s...\n", $filename); $keys = unserialize(file_get_contents($filename)); foreach ($keys as $key => $value) { printf(" %s: ", $key); $this->conf->{$key} = $value; printf("Ok\n"); } break; case 'unset': $keys = $this->getParameters(); $keys = array_slice($keys, 1); foreach ($keys as $key) { printf("Unset key: %s\n", $key); $this->conf->{$key} = null; } break; default: $params = $this->getParameters(); $cmd = $params[0]; $params = array_slice($params, 1); $cmdm = 'cmd_' . $cmd; if (is_callable(array($this, $cmdm))) { call_user_func_array(array($this, $cmdm), $params); } else { printf("Unknown command: %s, try -h\n", $cmd); } break; } }