File indexing completed on 2024-12-22 05:33:15

0001 <?php
0002 /*
0003  * on this file gfx inclusion is useless as gfx is already running
0004  */
0005 
0006 class StepsController extends EController
0007 {
0008   public function index()
0009   {
0010     //empty for now
0011   }
0012   
0013   public function _error($s)
0014   {
0015     return '<span style="color:red">'.$s.'</span>';
0016   }
0017   
0018   public function _notify($s)
0019   {
0020     return '<span style="color:green">'.$s.'</span>';
0021   }
0022   
0023   public function step1($args)
0024   {
0025         $working = false;
0026         
0027         $name = EHeaderDataParser::post('name');
0028         $host = EHeaderDataParser::post('host');
0029         $user = EHeaderDataParser::post('user');
0030         $pass = EHeaderDataParser::post('password');
0031         $pass2 = EHeaderDataParser::post('password2');
0032         $notification = '';
0033         
0034         $database_path = ELoader::$prev_path.'/config/database.conf.php';
0035     
0036     $cf = new EConfigFile();
0037     $cf->set_abs_file($database_path);
0038         
0039         if((empty($name)) and !empty($cf->get('name'))){
0040       $name = $cf->get('name');
0041     }
0042     
0043     if((empty($host)) and !empty($cf->get('host'))){
0044       $host = $cf->get('host');
0045     }
0046     
0047     if((empty($user)) and !empty($cf->get('user'))){
0048       $user = $cf->get('user');
0049     }
0050     
0051     if((empty($pass)) and !empty($cf->get('password'))){
0052       $pass = $pass2 = $cf->get('password');
0053     }
0054         
0055         if(!empty($name) and !empty($user) and !empty($host) and !empty($pass) and !empty($pass2)){
0056       if($pass!=$pass2){
0057         $this->_error('Warning! Your passwords didn\'t match! Please reinsert them!');
0058       } else {
0059         $cf->set('name', $name);
0060         $cf->set('user', $user);
0061         $cf->set('host', $host);
0062         $cf->set('password', $pass);
0063         
0064         EDatabase::set_db_info($name,$host,$user,$pass);
0065         EUtility::hide_output(); // hiding output as mysqli functions are surely outputting something
0066         if(!EDatabase::open_session()){
0067           EUtility::show_output();
0068           $notification = $this->_error('Couldn\'t open connection to database! Please check config!');
0069         } else {
0070           OCSTest::install_ocs_database(); //execute soft install
0071           $out = EUtility::show_output();
0072           
0073           if(!empty($out)){
0074             $notification = $this->_error('Something went wrong with install phase! Please check config!');
0075           } else {            
0076             $notification = $this->_notify('We can connect to database! Database is installed and configuration saved!');
0077             $working = true;
0078             $cf->save();
0079           }
0080         }
0081       }
0082     }
0083     
0084     $data = array();
0085     $data['name'] = $name;
0086     $data['user'] = $user;
0087     $data['host'] = $host;
0088     $data['pass'] = $pass;
0089     $data['pass2'] = $pass2;
0090     $data['working'] = $working;
0091     $data['notification'] = $notification;
0092     EStructure::view('wizard/step1', $data);
0093     
0094   }
0095   
0096   public function step2()
0097   {
0098     EStructure::view("header");
0099     if($this->arg_key('save')){
0100       $ocsserver_path = ELoader::$prev_path.'/config/ocsserver.conf.php';
0101         
0102       $cf = new EConfigFile();
0103       $cf->set_abs_file($ocsserver_path);
0104       
0105       $name = $cf->get('name');
0106       $host = $cf->get('host');
0107       $website = $cf->get('website');
0108       $contact = $cf->get('contact');
0109       $location = $cf->get('location');
0110       $ssl = $cf->get('ssl');
0111       $format = $cf->get('format');
0112       $termsofuse = $cf->get('termsofuse');
0113       $register = $cf->get('register');
0114       $version = $cf->get('version');
0115       $serverid = $cf->get('serverid');
0116       
0117       $provider = OCSXML::generate_providers($serverid,$name,$location,$termsofuse,$register, $ssl=false);
0118       
0119       $provider_path = ELoader::$prev_path.'/providers.xml';
0120       
0121       $stream = fopen($provider_path, 'w');
0122       fwrite($stream, $provider);
0123       fclose($stream);
0124       
0125       EStructure::view('wizard/step2save');
0126     }
0127       
0128     $serverid = EHeaderDataParser::post('serverid');
0129     $name = EHeaderDataParser::post('name');
0130     $host = EHeaderDataParser::post('host');
0131     $website = EHeaderDataParser::post('website');
0132     $location = EHeaderDataParser::post('location');
0133     $termsofuse = EHeaderDataParser::post('termsofuse');
0134     $register = EHeaderDataParser::post('register');
0135     $contact = EHeaderDataParser::post('contact');
0136     $ssl = EHeaderDataParser::post('ssl');
0137     $format = EHeaderDataParser::post('format');
0138     $version = OCSUser::version();
0139     
0140     //try to guess correct values
0141     if(empty($host)){
0142       $host = $_SERVER["SERVER_NAME"];
0143     }
0144     
0145     if(empty($website)){
0146       $website = EUtility::get_domain($host);
0147     }
0148     
0149     if(empty($name)){
0150       $name = ucfirst(EUtility::get_clear_domain($host)).' OCS Server';
0151     }
0152     
0153     if(empty($serverid)){
0154       $serverid = 'ocs_'.EUtility::get_clear_domain($host);
0155     }
0156     
0157     if(empty($location)){
0158       $location = 'http://'.ELoader::$root_path.'/v1/';
0159     }
0160     
0161     if($ssl=='yes'){
0162       $location = str_replace('http://','https://',$location);
0163     } else {
0164       $location = str_replace('https://','http://',$location);
0165     }
0166     
0167     //initialize everything to empty string
0168     $ssly = ''; $ssln = ''; $jsony = ''; $jsonn = '';
0169     //set the correct value for each menu
0170     if($ssl=='yes'){ $ssly = 'selected'; } else { $ssln = 'selected'; }
0171     if($format=='json'){ $jsony = 'selected'; } else { $jsonn = 'selected'; }
0172     
0173     $ocsserver_path = ELoader::$prev_path.'/config/ocsserver.conf.php';
0174         
0175     $cf = new EConfigFile();
0176     $cf->set_abs_file($ocsserver_path);
0177     
0178     $cf->set('name', $name);
0179     $cf->set('host', $host);
0180     $cf->set('website', $host);
0181     $cf->set('contact', $contact);
0182     $cf->set('location', $location);
0183     $cf->set('ssl', $ssl);
0184     $cf->set('format', $format);
0185     $cf->set('termsofuse', $termsofuse);
0186     $cf->set('register', $register);
0187     $cf->set('version', $version);
0188     $cf->set('serverid', $serverid);
0189     $cf->save();
0190     
0191     $data = array();
0192     $data['serverid'] = $serverid;
0193     $data['name'] = $name;
0194     $data['website'] = $website;
0195     $data['host'] = $host;
0196     $data['location'] = $location;
0197     $data['termsofuse'] = $termsofuse;
0198     $data['register'] = $register;
0199     $data['contact'] = $contact;
0200     $data['ssln'] = $ssln;
0201     $data['ssly'] = $ssly;
0202     $data['jsonn'] = $jsonn;
0203     $data['jsony'] = $jsony;
0204     $data['exampleprovider'] = htmlspecialchars(OCSXML::generate_providers($serverid,$name,$location,$termsofuse,$register, $ssl=false), ENT_QUOTES);
0205     
0206     //performing /v1/config get request
0207     $s = new ENetworkSocket($location);
0208     EUtility::hide_output();
0209     $c = $s->get('config');
0210     if(empty(EUtility::show_output())){
0211       $data['configcall'] = htmlspecialchars($c);
0212     } else {
0213       $data['configcall'] = 'We couldn\'t connect to OCS server. Check SSL settings and server location entries.';
0214     }
0215     EStructure::view('wizard/step2', $data);
0216     EStructure::view("footer");
0217   }
0218   
0219   public function step3()
0220   {
0221     if($this->arg_key('save')){
0222       $pass1 = EHeaderDataParser::post('pass');
0223       $pass2 = EHeaderDataParser::post('pass2');
0224       
0225       if($pass1==$pass2){
0226         $cf = new EConfigFile('generic');
0227     
0228         $cf->set('password', $pass1);
0229         $cf->set('enabled', 'protected');
0230         $cf->save();
0231       }
0232       EStructure::view('wizard/step3save');
0233     } else {
0234       $data = array();
0235       
0236       if(isset(EConfig::$data['generic']['password'])){
0237         $data['pass'] = EConfig::$data['generic']['password'];
0238       } else {
0239         $data['pass'] = '';
0240       }
0241       
0242       EStructure::view('wizard/step3', $data);
0243     }
0244   }
0245 }
0246 
0247 ?>