/**
  * Read db data from memory cache daemon
  * @param string $command The command to invoke
  * @param array $args The command arguments
  * @param string &$output The output from the read socket
  * @return int  The command exit code
  */
 private function dbRead($command, $args, &$output)
 {
     if (!isset(self::$socket)) {
         $socketPath = '/var/run/smwingsd.sock';
         $errno = 0;
         $errstr = '';
         self::$socket = $this->phpWrapper->fsockopen('unix://' . $socketPath, -1, $errno, $errstr);
         if (!is_resource(self::$socket)) {
             $this->getLog()->warning(sprintf("Invalid socket (%d): %s. Fall back to exec().", $errno, $errstr));
         }
     }
     if (!is_resource(self::$socket)) {
         return $this->dbExec($command, call_user_func_array(array($this, 'prepareArguments'), $args), $output);
     }
     // prepend the database name and command
     array_unshift($args, $this->db, $command);
     try {
         $this->sendMessage(self::$socket, 0x10, $args);
         if ($command === 'getjson') {
             $output = $this->recvMessage(self::$socket);
         } else {
             $output = json_decode($this->recvMessage(self::$socket), TRUE);
         }
     } catch (\Exception $ex) {
         $this->log->exception($ex);
         return 1;
     }
     return 0;
 }
Example #2
0
 public function authenticate()
 {
     $args = func_get_args();
     $args[] =& $this->state['credentials'];
     $this->state['authenticated'] = $this->authenticationValidator->evaluate($args);
     $this->modified = TRUE;
     if ($this->state['authenticated'] === TRUE) {
         $this->log->notice(sprintf("%s: user `%s` authenticated", __CLASS__, $args[0]));
     }
     return $this->state['authenticated'];
 }
Example #3
0
 private function fetchTaskStatus($taskId)
 {
     $socketPath = sprintf(self::PTRACK_PATH_TEMPLATE, $taskId);
     $dumpPath = sprintf(self::PTRACK_DUMP_PATH, md5($socketPath));
     $taskStatus = FALSE;
     $errno = 0;
     $errstr = "";
     $socket = $this->phpWrapper->fsockopen('unix://' . $socketPath, -1, $errno, $errstr);
     if ($socket === FALSE) {
         $socketPathExists = $errno != 2;
         if ($socketPathExists) {
             $this->log->error(sprintf('%s: Socket %s exists, but open failed: errno %d, errstr %s', __CLASS__, $socketPath, $errno, $errstr));
         }
         $taskStatus = $this->fetchDumpFile($dumpPath);
     } else {
         $this->sendMessage($socket, self::TY_QUERY);
         $taskStatus = $this->recvMessage($socket);
         $this->phpWrapper->fclose($socket);
     }
     return $taskStatus;
 }