[eluser]Nevio[/eluser]
I'm doing script for CI autoinstaller. It will be done like this bellow:
- enter domain name
- check domainname/filename.extension
- if it exists, retrieve basepath
- if not say that file must exist!
This installer is just for localhost purposes. FTP is out of a range for now lol
ADDED:
I did this... Anyone got better idea? Thanks.
Code:
$data = $this->_toObject( $data );
if(! $data->domainname || strlen( $data->domainname ) < 4 )
{
return json_encode( array (
'status' => 'false',
'title' => 'Domain name error!',
'message' => 'Domain name must be specified! Current value isn\'t set nor that it exist!'
));
}
if(! preg_match ("/^[a-z0-9][a-z0-9\-]+[a-z0-9](\.[a-z]{2,4})+$/i", $data->domainname ) )
{
return json_encode( array (
'status' => 'false',
'title' => 'Domain name not valid!',
'message' => 'Domain name is incorrect! Please use fully qualified domain name without http:// or https://'
));
}
// Okay it passes! lets check now if required file is accessable!
$url = $data->domainname . self::URL_SEPARATOR . $this->_ci->config->item( 'system_installer_file' );
// okay, lets go curl it!
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url ); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1 );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1 );// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 3 ); // times out after 4s
$result = curl_exec($ch); // run the whole process
curl_close($ch);
$response = json_decode( $result );
if(! is_object( $response ) )
{
return json_encode( array (
'status' => 'false',
'title' => 'Domain name coudn\'t be reached',
'message' => 'Please check for domain name and file existance! They don\'t exist or are invalid!'
));
}
$path = base64_decode( $response->pathinfo ) . DIRECTORY_SEPARATOR;
// now it's the time to extract codeigniter!
$archive = $this->_retrieveCiArchivePath();
if(! file_exists( $archive ) )
{
return json_encode( array (
'status' => 'false',
'title' => 'CodeIgniter archive error',
'message' => 'We cannot allocate codeigniter archive package. Please reinstall application!'
));
}
$zip = new ZipArchive();
if(! $zip->open( $archive ) )
{
return json_encode( array (
'status' => 'false',
'title' => 'CodeIgniter archive error',
'message' => 'We cannot open archive. Archive got some errors! It must be zip type!'
));
}
$zip->extractTo( $path );
$zip->close();
// okay! lets's go update and say that frontend is installed!
$obj = new stdClass();
$obj->f_installed = YES;
$obj->f_url = $data->domainname;
$obj->f_basepath = $path;
//$this->_ci->db->where( "id", $this->_ci->config->item('system_table_id') );
//$this->_ci->db->update( 'system', $obj );
return json_encode( array (
'status' => 'true',
'title' => 'Frontend successfully installed!',
'message' => 'We did just base extractions. Still you need to setup database and change configuration file url! Please wait...',
'url' => site_url('settings/frontend')
));