Пример #1
0
 function main($argc, $argv)
 {
     if ($this->getParameterCount() == 0) {
         $this->usage();
         return 1;
     }
     switch ($this->getParameter(0)) {
         case 'call':
             if ($this->hasArgument('u')) {
                 $user = $this->getArgument('u');
                 $pass = null;
                 if ($this->hasArgument('p')) {
                     printf('Password: '******':', $paramlistitem . ':');
                 $data[$k] = $v;
             }
             $site = $this->conf->vs_siteurl;
             $xc = new XmlrpcClient($site . '/api/xmlrpc', $user, $pass);
             $ret = $xc->call($this->getParameter(1), $data);
             if ($ret) {
                 if (arr::hasKey($ret, 'faultCode')) {
                     printf("Error %d: %s\n", $ret['faultCode'], $ret['faultString']);
                 } else {
                     debug::inspect($ret, false, false);
                 }
             } else {
                 printf("Server error.\n");
             }
             break;
         case 'config':
             $editor = new ConfigEditor();
             $editor->loop();
             break;
         case 'set':
             $key = $this->getParameter(1);
             $defs = $this->conf->getDefs($key);
             $val = $this->getParameter(2);
             $this->printValue($key, $val);
             switch ($defs['vartype']) {
                 case 'boolean':
                     if ($val == "1") {
                         $this->conf->{$key} = true;
                     } else {
                         $this->conf->{$key} = false;
                     }
                     break;
                 case 'integer':
                     $this->conf->{$key} = intval($val);
                     break;
                 case 'float':
                     $this->conf->{$key} = floatval($val);
                     break;
                 default:
                     $this->conf->{$key} = $val;
             }
             break;
         case 'get':
             if ($this->getParameterCount() > 1) {
                 $key = $this->getParameter(1);
                 $val = $this->conf->{$key};
                 $this->printValue($key, $val);
             } else {
                 $keys = $this->conf->getAll();
                 ksort($keys);
                 foreach ($keys as $key => $val) {
                     if ($key) {
                         $this->printValue($key, $val);
                     }
                 }
             }
             break;
         case 'backup':
             $filename = $this->getParameter(1);
             printf("Backing up to %s...\n", $filename);
             $keys = $this->conf->getAll();
             file_put_contents($filename, serialize($keys));
             break;
         case 'restore':
             $filename = $this->getParameter(1);
             printf("Restoring from %s...\n", $filename);
             $keys = unserialize(file_get_contents($filename));
             foreach ($keys as $key => $value) {
                 printf("  %s: ", $key);
                 $this->conf->{$key} = $value;
                 printf("Ok\n");
             }
             break;
         case 'unset':
             $keys = $this->getParameters();
             $keys = array_slice($keys, 1);
             foreach ($keys as $key) {
                 printf("Unset key: %s\n", $key);
                 $this->conf->{$key} = null;
             }
             break;
         default:
             $params = $this->getParameters();
             $cmd = $params[0];
             $params = array_slice($params, 1);
             $cmdm = 'cmd_' . $cmd;
             if (is_callable(array($this, $cmdm))) {
                 call_user_func_array(array($this, $cmdm), $params);
             } else {
                 printf("Unknown command: %s, try -h\n", $cmd);
             }
             break;
     }
 }
Пример #2
0
 function siteinfo()
 {
     $xc = new XmlrpcClient('http://ebooks.noccylabs.info/api/xmlrpc');
     debug::inspect($xc->call('vs.siteinfo'));
 }