function add($username = null) { using('lepton.user.*'); if ($username) { console::write("New password: "******"Confirm: "); $pc = console::readPass(); if ($p != $pc) { console::fatal('Passwords mismatch.'); exit(1); } $password = $p; console::write("DisplayName: "); $displayname = console::readLn(); console::write("E-Mail: "); $email = console::readLn(); console::write("Flags: "); $flags = console::readLn(); console::write("Is this correct? [Y/n] "); $ok = console::readLn(); if (strtolower($ok) == 'n') { exit(1); } $u = new UserRecord(); $u->username = $username; $u->password = $password; $u->email = $email; $u->flags = $flags; $u->displayname = $displayname; if (User::create($u)) { console::writeLn("User created."); } else { console::writeLn("Couldn't create user."); } } else { console::writeLn("Use: user add username"); } }
function addgroup($group = null) { if (!$group) { console::fatal("You need to specify the group to add!"); exit(1); } }
public function spell($lang = null) { $this->openDatabase(); if (!$lang) { $lang = $this->db['db:defaultlang']; } if (!function_exists('pspell_new')) { console::fatal("strings spell requires the pspell extension"); exit(1); } $sp = pspell_new($lang); if (!$sp) { console::fatal("Couldn't load dictionary for %s", $lang); exit(1); } foreach ($this->db['lang:' . $lang] as $key => $str) { $strn = explode(' ', $str); foreach ($strn as $word) { if (!pspell_check($sp, $word)) { console::write("%s: ", $word); $suggestions = pspell_suggest($sp, $word); foreach ($suggestions as $suggestion) { console::write('%s ,', $suggestion); } console::writeLn(); } } } }
private function geoLocationInsert($fn) { $this->progress = null; $this->activity = "Importing"; $this->doTaskUpdate(); $dest = base::appPath() . '/geocache/' . $fn; $fz = fopen('zip://' . $dest . '#' . basename($dest, '.zip') . '.txt', 'rb'); if (!$fz) { console::fatal("Could not open file %s (%s)", $dest, $fn); } $this->doTaskUpdate(); $batch = array(); $rowstot = 0; while (!feof($fz)) { $row = fgetcsv($fz, 16000, "\t", '*'); $batch[] = $row; $rowstot++; if (count($batch) >= 50) { $this->progress['read'] += count($batch); $this->doTaskUpdate(); $this->geoLocationInsertBatch($batch); $batch = array(); } } $this->clearTask(); console::writeLn("%s imported, %d rows.", $fn, $rowstot); }
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."); }