Exemplo n.º 1
0
 public function runcon()
 {
     $iscmd = function ($line, $cmd) {
         if ($line == $cmd || substr($line, 0, strlen($cmd) + 1) == $cmd . ' ') {
             return true;
         }
         return false;
     };
     while (true) {
         $chint = $this->getFullHint();
         // $cline = readline($chint);
         $cline = $this->readio_readline($chint);
         $rline = trim($cline);
         // var_dump($cline);
         // exit;
         if ($cline == "") {
         } else {
             if ($rline == 'exit' || $rline == 'bye') {
                 $this->quit();
             } else {
                 if ($rline == 'help' || $rline == '?' || $rline == 'usage') {
                     $this->help();
                 } else {
                     if ($rline == 'version') {
                         echo "htsh - 1.0\n";
                     } else {
                         if ($rline == 'history') {
                             print_r(readline_list_history());
                         } else {
                             if ($iscmd($rline, 'switch2ip')) {
                                 $this->switchhostip($rline);
                             } else {
                                 if ($iscmd($rline, 'switch2host')) {
                                     $this->switchhostip($rline);
                                 } else {
                                     if ($iscmd($rline, 'push')) {
                                         $this->notimplcmd($rline);
                                     } else {
                                         // echo $cline . "\n";
                                         $this->runCmd($cline);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
<?php

var_dump(readline_list_history());
var_dump(readline_list_history(1));
Exemplo n.º 3
0
     }
     if (!$mcc->set($key, $value, 0)) {
         # print 'Error: ' . $mcc->error_string() . "\n";
         print "MemCached error\n";
     }
     break;
 case 'delete':
     $key = implode(' ', $args);
     if (!$mcc->delete($key)) {
         # print 'Error: ' . $mcc->error_string() . "\n";
         print "MemCached error\n";
     }
     break;
 case 'history':
     if (function_exists('readline_list_history')) {
         foreach (readline_list_history() as $num => $line) {
             print "{$num}: {$line}\n";
         }
     } else {
         print "readline_list_history() not available\n";
     }
     break;
 case 'dumpmcc':
     var_dump($mcc);
     break;
 case 'quit':
 case 'exit':
     $quit = true;
     break;
 default:
     $bad = true;
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function listHistory()
 {
     return readline_list_history();
 }
Exemplo n.º 5
0
}
// check if argv[1] provided, if not check readline support and wait for user pass
if (isset($argv[1])) {
    $password = $argv[1];
} else {
    // get available extensions
    $available_extensions = get_loaded_extensions();
    // not in array
    if (!in_array("readline", $available_extensions)) {
        $Result->show_cli("readline php extension is required.\nOr provide password as first argument", true);
    } else {
        // read password
        $line = readline("Enter password: "******"Password must be at least 8 characters long", true);
}
// hash passowrd
$password_crypted = $User->crypt_user_pass($password);
// save type
$crypt_type = $User->return_crypt_type();
// set update array
$values = array("id" => 1, "password" => $password_crypted);
// update password
if (!$Admin->object_modify("users", "edit", "id", $values)) {
    $Result->show_cli("Failed to update Admin password", false);
Exemplo n.º 6
0
 public function execute($args)
 {
     echo "Insert database information: \n\n";
     for ($i = 0; $i < 6; $i++) {
         switch ($i) {
             case 0:
                 $command = $this->makeGreen("HOSTNAME (localhost): ", false);
                 break;
             case 1:
                 $command = $this->makeGreen("USERNAME (root): ", false);
                 break;
             case 2:
                 $command = $this->makeGreen("PASSWORD (root): ", false);
                 break;
             case 3:
                 $command = $this->makeGreen("DATABASE: ", false);
                 break;
             case 4:
                 $command = $this->makeGreen("PORT (3306): ", false);
                 break;
             case 5:
                 $command = $this->makeGreen("CIPHER_KEY (AAAAAAAA): ", false);
                 break;
         }
         $line = readline($command);
         readline_add_history($line);
     }
     // dump history
     $params = readline_list_history();
     $params[0] = empty($params[0]) ? 'localhost' : $params[0];
     $params[1] = empty($params[1]) ? 'root' : $params[1];
     $params[2] = empty($params[2]) ? 'root' : $params[2];
     $params[4] = empty($params[4]) ? '3306' : $params[4];
     $params[5] = empty($params[5]) ? 'AAAAAAAA' : $params[5];
     if (empty($params[3])) {
         $this->makeRed("\nDATABASE cannot be null\n");
         exit;
     }
     // Name of the file
     $filename = 'quaver-skeleton.sql';
     // MySQL host
     $mysql_host = $params[0];
     // MySQL username
     $mysql_username = $params[1];
     // MySQL password
     $mysql_password = $params[2];
     // Database name
     $mysql_database = $params[3];
     // Connect to MySQL server
     $mysqli = new \mysqli($mysql_host, $mysql_username, $mysql_password, $mysql_database);
     if (mysqli_connect_errno()) {
         die($this->makeRed("Error connecting to MySQL server: (" . mysqli_connect_errno() . ") \n", false));
     }
     // Read in entire file
     $sql = file_get_contents(GLOBAL_PATH . '/vendor/millolab/quaver-cli/Quaver/' . $filename) or die($this->makeRed("Unable to open file! \n", false));
     // Execute statement
     if ($mysqli->multi_query($sql)) {
         $this->makeGreen("Tables imported successfully \n");
     } else {
         die($this->makeRed("An error has been occurred: " . $mysqli->error . " \n", false));
     }
     // Disconnect MySQL
     $mysqli->close();
     // Change Config.yml and export it
     $config = Config::getInstance();
     $configYML = $config->importYML();
     if (!isset($configYML)) {
         $configYML = $config->importYML(GLOBAL_PATH . '/App/Config_example.yml');
     }
     if (isset($configYML['db'])) {
         $configYML['db']['HOSTNAME'] = $mysql_host;
         $configYML['db']['USERNAME'] = $mysql_username;
         $configYML['db']['PASSWORD'] = $mysql_password;
         $configYML['db']['DATABASE'] = $mysql_database;
         $configYML['db']['PORT'] = (int) $params[4];
         $configYML['db']['CIPHER_KEY'] = $params[5];
         $config->exportYML('Config.yml', $configYML);
     } else {
         die($this->makeRed("An error has been occurred with Config.yml \n", false));
     }
     // Folders
     $class = new Folders();
     $class->execute(null);
     // Resources
     $class = new Resources();
     $class->execute(null);
 }
Exemplo n.º 7
0
 public function listHistory()
 {
     if (!function_exists('readline_list_history')) {
         throw new BadMethodCallException('Method "readline_list_history" not available, update PHP and/or enable ext-readline compiled against libreadline instead of libedit');
     }
     return readline_list_history();
 }
Exemplo n.º 8
0
<?php

//get 3 commands from user
for ($i = 0; $i < 3; $i++) {
    $line = readline("Command: ");
    readline_add_history($line);
}
//dump history
print_r(readline_list_history());
//dump variables
print_r(readline_info());