예제 #1
0
 function index()
 {
     if ($this->method !== 'post') {
         $this->error('403', 'Forbidden');
         return;
     }
     copy(FCPATH . 'app/koken/recover.php', FCPATH . 'recover.php');
     function rollback($back)
     {
         foreach ($back as $b) {
             $f = FCPATH . $b;
             $dest = str_replace('.off', '', $f);
             if (is_dir($dest)) {
                 delete_files($dest, true, 1);
             } else {
                 if (file_exists($dest)) {
                     unlink($dest);
                 }
             }
             @rename($f, $dest);
         }
     }
     function fail($msg = 'Koken does not have the necessary permissions to perform the update automatically. Try setting the permissions on the entire Koken folder to 777, then try again.')
     {
         @unlink(FCPATH . 'recover.php');
         delete_files(FCPATH . 'storage/tmp', true);
         die(json_encode(array('error' => $msg)));
     }
     $get_core = $this->input->post('url');
     if ($get_core) {
         if (ENVIRONMENT === 'development') {
             $manifest = FCPATH . 'manifest.php';
             require $manifest;
             if (count($compatCheckFailures)) {
                 die(json_encode(array('requirements' => $compatCheckFailures)));
             }
             //hack
             sleep(2);
             // fail();
             unlink(FCPATH . 'recover.php');
             die(json_encode(array('migrations' => array('0001.php', '0001.php', '0001.php'))));
         }
         $old_mask = umask(0);
         $core = FCPATH . 'storage/tmp/core.zip';
         make_child_dir(dirname($core));
         if ($this->_download($get_core, $core)) {
             $this->load->library('unzip');
             $this->unzip->extract($core);
             @unlink($core);
             $manifest = FCPATH . 'storage/tmp/manifest.php';
             require $manifest;
             if (count($compatCheckFailures)) {
                 delete_files(FCPATH . 'storage/tmp', true);
                 unlink(FCPATH . 'recover.php');
                 die(json_encode(array('requirements' => $compatCheckFailures)));
             }
             $migrations_before = scandir($this->migrate_path);
             $moved = array();
             // updateFileList comes from manifest.php
             foreach ($updateFileList as $path) {
                 $fullPath = FCPATH . 'storage/tmp/' . $path;
                 $dest = FCPATH . $path;
                 $off = $dest . '.off';
                 if (!file_exists($fullPath)) {
                     rollback($moved);
                     umask($old_mask);
                     fail();
                 }
                 if (file_exists($dest)) {
                     if (file_exists($off)) {
                         delete_files($off, true, 1);
                     }
                     if (rename($dest, $off)) {
                         $moved[] = $path;
                     } else {
                         rollback($moved);
                         umask($old_mask);
                         fail();
                     }
                 }
                 if (!rename($fullPath, $dest)) {
                     rollback($moved);
                     umask($old_mask);
                     fail();
                 }
             }
             foreach ($moved as $m) {
                 $path = FCPATH . $m . '.off';
                 if (is_dir($path)) {
                     delete_files($path, true, 1);
                 } else {
                     if (file_exists($path)) {
                         unlink($path);
                     }
                 }
             }
             unlink(FCPATH . 'recover.php');
             @unlink(FCPATH . 'manifest.php');
             // Remove temporary update files
             delete_files(FCPATH . 'storage/tmp', true);
             if (is_really_callable('opcache_reset')) {
                 opcache_reset();
             }
             die(json_encode(array('migrations' => array_values(array_diff(scandir($this->migrate_path), $migrations_before)))));
         } else {
             umask($old_mask);
             @unlink($core);
             fail();
         }
     }
 }
예제 #2
0
 function index()
 {
     // TODO: require auth for this controller
     // director-core will need some reworking
     // if (!$this->auth)
     // {
     // 	$this->error('401', 'The action requires an authentication token.');
     // return;
     // }
     list($params, ) = $this->parse_params(func_get_args());
     include FCPATH . 'app' . DIRECTORY_SEPARATOR . 'koken' . DIRECTORY_SEPARATOR . 'ffmpeg.php';
     $ffmpeg = new FFmpeg();
     function max_upload_to_bytes($val)
     {
         $val = strtolower($val);
         if (preg_match('/(k|m|g)/', $val, $match)) {
             $val = (int) str_replace($match[1], '', $val);
             switch ($match[1]) {
                 case 'k':
                     $val *= 1024;
                     break;
                 case 'm':
                     $val *= 1048576;
                     break;
                 case 'g':
                     $val *= 1073741824;
                     break;
             }
             return $val;
         } else {
             return (int) $val;
         }
     }
     $max_upload = max_upload_to_bytes(ini_get('upload_max_filesize'));
     $post_max = max_upload_to_bytes(ini_get('post_max_size'));
     $max = min($max_upload, $post_max);
     if ($max >= 1024) {
         $max_clean = $max / 1024 . 'KB';
     }
     if ($max >= 1048576) {
         $max_clean = $max / 1048576 . 'MB';
     }
     if ($max >= 1073741824) {
         $max_clean = $max / 1073741824 . 'GB';
     }
     $c = new Content();
     $c->select_max('modified_on')->get();
     $a = new Album();
     $a->select_max('modified_on')->get();
     $t = new Text();
     $t->select_max('modified_on')->get();
     $this->load->library('webhostwhois');
     $webhost = new WebhostWhois(array('useDns' => false));
     if (!defined('MAX_PARALLEL_REQUESTS')) {
         // Hosts we know do not limit parallel requests
         $power_hosts = array('dreamhost', 'media-temple-grid', 'go-daddy', 'in-motion', 'rackspace-cloud');
         $parallel = in_array($webhost->key, $power_hosts) ? 8 : 3;
     } else {
         $parallel = MAX_PARALLEL_REQUESTS;
     }
     // TODO: Some of this info should be limited to authenticated sessions
     $data = array('version' => KOKEN_VERSION, 'operating_system' => PHP_OS, 'memory_limit' => ini_get('memory_limit'), 'auto_updates' => AUTO_UPDATE, 'php_version' => PHP_VERSION, 'exif_support' => is_really_callable('exif_read_data'), 'iptc_support' => is_really_callable('iptcparse'), 'ffmpeg_support' => is_really_callable('exec') ? $ffmpeg->version() : false, 'upload_limit' => $max, 'upload_limit_clean' => $max_clean, 'timestamp' => (int) max($c->modified_on, $a->modified_on, $t->modified_on), 'rewrite_enabled' => $this->check_for_rewrite(), 'mysql_version' => $this->db->call_function('get_server_info', $this->db->conn_id), 'max_parallel_requests' => $parallel, 'webhost' => $webhost->key, 'store' => KOKEN_STORE_URL, 'server_software' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : 'Unknown');
     $this->set_response_data($data);
 }
예제 #3
0
 function is_enabled()
 {
     return is_really_callable('curl_multi_exec');
 }