Пример #1
0
 public function _api_request_cmd($cmd)
 {
     try {
         if (null === self::$_db) {
             self::$_db = \frdl\DB::_(array('driver' => $this->data['config']['db-driver'], 'host' => $this->data['config']['db-host'], 'dbname' => $this->data['config']['db-dbname'], 'user' => $this->data['config']['db-user'], 'password' => $this->data['config']['db-pwd'], 'pfx' => $this->data['config']['db-pfx']), false);
         }
     } catch (\Exception $e) {
         /* no explicit need of DB connection here */
     }
     foreach ($this->data['settings']->cli as $cmdpfx => $console) {
         $t = $console['cli.cmd.cli'];
         $l = strlen($t);
         if (substr($cmd, 0, $l) === $t) {
             $cmd = substr($cmd, $l, strlen($cmd));
             if (is_subclass_of($console['cli.class'], $console['cli.class.required.parent']) && is_subclass_of($console['cli.class'], '\\frdl\\aSQL\\Engines\\Terminal\\CLI')) {
                 $this->Console = new $console['cli.class']();
                 $this->Console->applyApp($this);
                 $this->Console->exe($cmd);
                 return $this->_api_response($this->Console->dump());
             } else {
                 \webdof\wResponse::status(501);
                 trigger_error('No valid Console SubClass.', E_USER_NOTICE);
                 continue;
             }
         }
     }
     \webdof\wResponse::status(404);
     die('API cli not found');
 }
Пример #2
0
Файл: pm.php Проект: frdl/webfan
 public function find($o)
 {
     if (!isset($this->argtoks['arguments'][1]) || intval($this->argtoks['arguments'][1]['pos']) !== 2) {
         return $this->wrongArgumentCount();
     }
     $this->packagefullname = str_replace(array('"', "'"), array('', ''), $this->argtoks['arguments'][1]['cmd']);
     try {
         $this->F = new \frdl\ApplicationComposer\Repos\Fetch($o);
         $this->result->searchresults = $this->F->search($this->packagefullname);
         $this->result->searchresults = array_unique($this->result->searchresults);
     } catch (\Exception $e) {
         \webdof\wResponse::status(409);
         $this->result->out = $e->getMessage();
         return;
     }
     if (isset($this->argtoks['flags']['s']) && true === $this->aSess['isAdmin']) {
         $p = new \frdl\ApplicationComposer\Package(array(), \frdl\xGlobal\webfan::db()->settings(), $this->db);
         $p->db()->begin();
         foreach ($this->result->searchresults as $num => $s) {
             if (is_array($s)) {
                 foreach ($s as $num2 => $s2) {
                     $v = explode('/', $s2->name);
                     if (2 === count($v) && !$p->find($v[0], $v[1])) {
                         $p->vendor = $v[0];
                         $p->package = $v[1];
                         $p->url = $s2->url;
                         $p->description = $s2->description;
                         $p->time_last_fetch_info = time();
                         $p->create();
                     }
                 }
             } else {
                 $v = explode('/', $s->name);
                 if (2 === count($v) && !$p->find($v[0], $v[1])) {
                     $p->vendor = $v[0];
                     $p->package = $v[1];
                     $p->url = $s->url;
                     $p->description = $s->description;
                     $p->time_last_fetch_info = time();
                     $p->create();
                 }
             }
         }
         $p->db()->commit();
     }
     $this->result->out = 'OK';
 }
Пример #3
0
    protected function create_tables()
    {
        if (isset($this->argtoks['flags']['d'])) {
            ini_set('display_errors', 1);
            error_reporting(E_ALL);
        }
        if (!is_string($this->data['config']['db-pfx']) || '' === trim($this->data['config']['db-pfx'])) {
            $str = 'Please provide a table prefix!';
            $this->result->out = $str;
            $this->result->js .= 'alert("' . $str . '");';
            return;
        }
        $settings = array('driver' => $this->data['config']['db-driver'], 'host' => $this->data['config']['db-host'], 'dbname' => $this->data['config']['db-dbname'], 'user' => $this->data['config']['db-user'], 'password' => $this->data['config']['db-pwd'], 'pfx' => $this->data['config']['db-pfx']);
        $this->_db->Connect($settings, false);
        if (true !== $this->_db->connected) {
            $str = 'No database connection!';
            $this->result->out = $str;
            $this->result->js .= 'alert("' . $str . '");';
            return;
        }
        try {
            $S = new \frdl\_db();
            $cfile = $this->data['config']['FILES']['database-schema'];
            if (file_exists($cfile)) {
                $oldSchema = $S->load_schema(file_get_contents($cfile));
                //$oldSchema = $S->load_schema($this->read($cfile, 'rb',  null));
            } else {
                $oldSchema = $S->schema();
            }
            if (!is_object($oldSchema)) {
                $oldSchema = $S->schema();
            }
            $S->check($schema, $tables, null, true, true, true, $this->_db, $settings, $oldSchema);
            $this->result->js .= '
            	$(document).wdPostbox(\'deleteMessage\', \'system-error-database-missing-or-obsolete-tables-' . $oldSchema->version . '\',  \'update\', false);	 	 
            	$(document).wdPostbox(\'deleteMessage\', \'system-error-database-missing-or-obsolete-tables-' . $schema->version . '\',  \'update\', false);	 	   	
					 	   
          ';
        } catch (\Exception $e) {
            $tablesOK = false;
            $this->result->out = 'Error checking tables! ' . $e->getMessage();
            return $this->result;
        }
        $S->tables($tables, false);
        $report = $S->check_tables($schema, $tables, $schema);
        file_put_contents($cfile, $S->save_schema($schema, 128));
        $this->data['config']['db-schema-version'] = $schema->version;
        if (true !== $this->writeToConfigFile()) {
            \webdof\wResponse::status(409);
            $this->result->out = 'set config: ERROR writing config file';
        } else {
            $this->result->out = $report;
        }
        return $this->result;
    }
Пример #4
0
 protected function _exec($args)
 {
     if (false !== $this->HALT || 'HALT' === $this->state) {
         return;
     }
     $command = $args['command']['cmd'];
     $cmd_file = $this->get_cmd_file($command);
     $this->statusText = 'Invoke frdl command...';
     if (isset($this->shell['commands'][$command]) && is_callable($this->shell['commands'][$command])) {
         return $this->App->OutData(call_user_func($this->shell['commands'][$command], $args));
     } elseif (false !== $cmd_file) {
         require $cmd_file;
         $classname = '\\frdl\\ApplicationComposer\\Command\\' . $command;
         try {
             if (!is_subclass_of($classname, '\\frdl\\ApplicationComposer\\Command\\CMD')) {
                 \webdof\wResponse::status('409');
                 die('Invalid CMD class in ' . __METHOD__ . ' ' . __LINE__);
             }
             $CMD = new $classname();
             return $this->App->OutData($CMD($this, $args));
         } catch (\Exception $e) {
             return $this->App->OutData('out', 'Error: ' . $e->getMessage());
         }
     }
     $this->statusText = 'Command not found: ' . strip_tags($command);
 }