Example #1
0
 /**
  * Send a get request to the server.
  */
 public function get($url)
 {
     $server = $this->generate_server();
     $socket = new ENetworkSocket($server);
     $raw_data = $socket->get($url);
     //if result is in json format, parse json
     // else parse xml
     if ($this->is_json_encoded($raw_data)) {
         return json_decode($raw_data);
     } else {
         $data = EXmlParser::to_array($raw_data, $this->ocs_data_fields);
         return $data;
     }
 }
Example #2
0
 public function step2()
 {
     EStructure::view("header");
     if ($this->arg_key('save')) {
         $ocsserver_path = ELoader::$prev_path . '/config/ocsserver.conf.php';
         $cf = new EConfigFile();
         $cf->set_abs_file($ocsserver_path);
         $name = $cf->get('name');
         $host = $cf->get('host');
         $website = $cf->get('website');
         $contact = $cf->get('contact');
         $location = $cf->get('location');
         $ssl = $cf->get('ssl');
         $format = $cf->get('format');
         $termsofuse = $cf->get('termsofuse');
         $register = $cf->get('register');
         $version = $cf->get('version');
         $serverid = $cf->get('serverid');
         $provider = OCSXML::generate_providers($serverid, $name, $location, $termsofuse, $register, $ssl = false);
         $provider_path = ELoader::$prev_path . '/providers.xml';
         $stream = fopen($provider_path, 'w');
         fwrite($stream, $provider);
         fclose($stream);
         EStructure::view('wizard/step2save');
     }
     $serverid = EHeaderDataParser::post('serverid');
     $name = EHeaderDataParser::post('name');
     $host = EHeaderDataParser::post('host');
     $website = EHeaderDataParser::post('website');
     $location = EHeaderDataParser::post('location');
     $termsofuse = EHeaderDataParser::post('termsofuse');
     $register = EHeaderDataParser::post('register');
     $contact = EHeaderDataParser::post('contact');
     $ssl = EHeaderDataParser::post('ssl');
     $format = EHeaderDataParser::post('format');
     $version = OCSUser::version();
     //try to guess correct values
     if (empty($host)) {
         $host = $_SERVER["SERVER_NAME"];
     }
     if (empty($website)) {
         $website = EUtility::get_domain($host);
     }
     if (empty($name)) {
         $name = ucfirst(EUtility::get_clear_domain($host)) . ' OCS Server';
     }
     if (empty($serverid)) {
         $serverid = 'ocs_' . EUtility::get_clear_domain($host);
     }
     if (empty($location)) {
         $location = 'http://' . ELoader::$root_path . '/v1/';
     }
     if ($ssl == 'yes') {
         $location = str_replace('http://', 'https://', $location);
     } else {
         $location = str_replace('https://', 'http://', $location);
     }
     //initialize everything to empty string
     $ssly = '';
     $ssln = '';
     $jsony = '';
     $jsonn = '';
     //set the correct value for each menu
     if ($ssl == 'yes') {
         $ssly = 'selected';
     } else {
         $ssln = 'selected';
     }
     if ($format == 'json') {
         $jsony = 'selected';
     } else {
         $jsonn = 'selected';
     }
     $ocsserver_path = ELoader::$prev_path . '/config/ocsserver.conf.php';
     $cf = new EConfigFile();
     $cf->set_abs_file($ocsserver_path);
     $cf->set('name', $name);
     $cf->set('host', $host);
     $cf->set('website', $host);
     $cf->set('contact', $contact);
     $cf->set('location', $location);
     $cf->set('ssl', $ssl);
     $cf->set('format', $format);
     $cf->set('termsofuse', $termsofuse);
     $cf->set('register', $register);
     $cf->set('version', $version);
     $cf->set('serverid', $serverid);
     $cf->save();
     $data = array();
     $data['serverid'] = $serverid;
     $data['name'] = $name;
     $data['website'] = $website;
     $data['host'] = $host;
     $data['location'] = $location;
     $data['termsofuse'] = $termsofuse;
     $data['register'] = $register;
     $data['contact'] = $contact;
     $data['ssln'] = $ssln;
     $data['ssly'] = $ssly;
     $data['jsonn'] = $jsonn;
     $data['jsony'] = $jsony;
     $data['exampleprovider'] = htmlspecialchars(OCSXML::generate_providers($serverid, $name, $location, $termsofuse, $register, $ssl = false), ENT_QUOTES);
     //performing /v1/config get request
     $s = new ENetworkSocket($location);
     EUtility::hide_output();
     $c = $s->get('config');
     if (empty(EUtility::show_output())) {
         $data['configcall'] = htmlspecialchars($c);
     } else {
         $data['configcall'] = 'We couldn\'t connect to OCS server. Check SSL settings and server location entries.';
     }
     EStructure::view('wizard/step2', $data);
     EStructure::view("footer");
 }