Ejemplo n.º 1
0
 /**
  * Starts the terminal process
  * Uses the class Process.
  * @return true if runs
  */
 private function startProcess()
 {
     self::$process = new Process("su - {$this->login}");
     //        self::$process = new Process("vi");
     if (!self::$process->isResource()) {
         throw new Exception("RESOURCE NOT AVAIBLE");
         return false;
     }
     usleep(500000);
     self::$process->put($this->password);
     self::$process->put(chr(13));
     self::$process->get();
     usleep(500000);
     self::$status = self::$process->getStatus();
     self::$meta = self::$process->metaData();
 }
 /**
  * Open the terminal process.
  * @param string $login
  * @param string $password
  * @return bool - true if runs
  */
 private function open($login, $password)
 {
     $this->login = $login;
     $this->password = $password;
     if (!is_writable(self::$commandsFile)) {
         $this->output("\r\nNeed permission to write in " . self::$commandsFile . "\r\n");
         return false;
     }
     // Clean commands
     file_put_contents(self::$commandsFile, "");
     $this->startProcess();
     do {
         $out = self::$process->get();
         //can be there for work
         var_dump($out);
         // Detect "blocking" (wait for stdin)
         if (sizeof($out) == 1 && ord($out) == 0) {
             // echo "TSET";
             $this->listenCommand();
         } else {
             // echo "AAAA";
             // Provisorio, meldels. (usuario www-data não tem controle de servico, dude!)
             //must be commented
             // if(preg_match('/-su: no job control in this shell/', $out)) continue;
             $this->output($out);
         }
         flush();
         usleep(10000);
         self::$status = self::$process->getStatus();
         self::$meta = self::$process->metaData();
         //must be there to work
         var_dump(self::$meta);
     } while (self::$meta['eof'] === false);
     return true;
 }