function _clear_system_caches() { Shutter::clear_cache(array('api', 'core', 'site', 'locks')); delete_files(FCPATH . 'app' . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'datamapper' . DIRECTORY_SEPARATOR . 'cache', true, 1); $this->_compile_plugins(); $a = new Album(); $a->repair_tree(); $s = new Setting(); $s->where('name', 'site_url')->get(); if ($this->check_for_rewrite()) { if ($s->value === 'default') { $htaccess = create_htaccess(); $root_htaccess = FCPATH . '.htaccess'; $current = file_get_contents($root_htaccess); preg_match('/#MARK#.*/s', $htaccess, $match); $htaccess = preg_replace('/#MARK#.*/s', str_replace('$', '\\$', $match[0]), $current); file_put_contents($root_htaccess, $htaccess); } else { if (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_FILENAME'])) { $doc_root = str_replace($_SERVER['PHP_SELF'], '', $_SERVER['SCRIPT_FILENAME']); } else { $doc_root = $_SERVER['DOCUMENT_ROOT']; } $doc_root = realpath($doc_root); $target = $doc_root . str_replace('/', DIRECTORY_SEPARATOR, $s->value); $htaccess = create_htaccess($s->value); $file = $target . DIRECTORY_SEPARATOR . '.htaccess'; if (file_exists($file)) { $existing = file_get_contents($file); if (strpos($existing, '#MARK#') !== false) { preg_match('/#MARK#.*/s', $htaccess, $match); $htaccess = preg_replace('/#MARK#.*/s', str_replace('$', '\\$', $match[0]), $existing); } else { $htaccess = $existing . "\n\n" . $htaccess; } } file_put_contents($file, $htaccess); if ("{$doc_root}" . DIRECTORY_SEPARATOR !== FCPATH) { $root_htaccess = FCPATH . '.htaccess'; if (file_exists($root_htaccess)) { $current = file_get_contents($root_htaccess); $redirect = create_htaccess($s->value, true); if (strpos($current, '#MARK#') !== false) { preg_match('/#MARK#.*/s', $redirect, $match); $redirect = preg_replace('/#MARK#.*/s', str_replace('$', '\\$', $match[0]), $current); } else { $redirect = $current . "\n\n" . $redirect; } file_put_contents($root_htaccess, $redirect); } } } } }
function __construct() { if (!file_exists('database/database.sqlite3')) { mkdir('database', 0700) or die('Cannot create folder "database"'); create_htaccess(); $this->open('database/database.sqlite3', SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE); $this->exec('CREATE TABLE data (access_key char(32), content varchar(1048576))'); //the database shouldn't be accessed by everyone chmod("database/database.sqlite3", 0600) or die('Cannot set access rights for database.sqlite3 (chmod 0600)'); } else { //if it is the case, that you move the database file manually to the folder chmod('database', 0700) or die('Cannot set access rights for "database"-folder (chmod 0700)'); chmod("database/database.sqlite3", 0600) or die('Cannot set access rights for "database.sqlite3"-file (chmod 0600)'); $this->open('database/database.sqlite3', SQLITE3_OPEN_READWRITE); } }
function index() { if (!$this->auth) { $this->error('403', 'Forbidden'); return; } $image_processing = new Setting(); $image_processing->where('name', 'image_processing_library')->get(); include FCPATH . 'app' . DIRECTORY_SEPARATOR . 'koken' . DIRECTORY_SEPARATOR . 'DarkroomUtils.php'; $libs = DarkroomUtils::libraries(); if ($image_processing->exists()) { if (!isset($libs[$image_processing->value])) { $top = array_shift(array_keys($libs)); $lib = $libs[$top]; $image_processing->value = $lib['key']; $image_processing->save(); } } else { if (!defined('MAGICK_PATH_FINAL') || (MAGICK_PATH_FINAL === 'convert' || !isset($libs[MAGICK_PATH_FINAL]))) { $top = array_shift(array_keys($libs)); $lib = $libs[$top]; } else { $lib = $libs[MAGICK_PATH_FINAL]; } $image_processing->name = 'image_processing_library'; $image_processing->value = $lib['key']; $image_processing->save(); } $last_check = new Setting(); $last_check->where('name', 'last_migration'); $last_check_count = $last_check->count(); if ($last_check_count > 1) { $last_check->where('name', 'last_migration')->order_by('value ASC')->limit($last_check_count - 1)->get(); $last_check->delete_all(); } $s = new Setting(); $settings = $s->get_iterated(); $data = array('image_processing_libraries' => array_values($libs)); $bools = array('has_toured', 'site_hidpi', 'retain_image_metadata', 'image_use_defaults', 'use_default_labels_links', 'uploading_publish_on_captured_date'); foreach ($settings as $setting) { // Don't allow dupes to screw things up if (isset($data[$setting->name])) { continue; } $value = $setting->value; if (in_array($setting->name, $bools)) { $value = $value == 'true'; } if ($setting->name === 'last_upload') { $value = $value === 'false' ? false : (int) $value; } $data[$setting->name] = $value; } if (!isset($data['uploading_publish_on_captured_date'])) { $data['uploading_publish_on_captured_date'] = false; } if (!isset($data['uploading_default_album_visibility'])) { $data['uploading_default_album_visibility'] = 'public'; } if (!isset($data['email_handler'])) { $data['email_handler'] = 'DDI_Email'; } $data['email_handlers'] = Shutter::get_email_handlers(); $disable_cache_file = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'no-site-cache'; $data['enable_site_cache'] = !file_exists($disable_cache_file); if ($this->method != 'get') { if ($this->auth_role !== 'god') { $this->error('403', 'Forbidden'); return; } if (isset($_POST['signin_bg'])) { $c = new Content(); $c->get_by_id($_POST['signin_bg']); if ($c->exists()) { $_c = $c->to_array(); $large = array_pop($_c['presets']); // TODO: Error checking for permissions reject $f = $large['url']; $to = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'wallpaper' . DIRECTORY_SEPARATOR . 'signin.jpg'; if (extension_loaded('curl')) { $cp = curl_init($f); $fp = fopen($to, "w+"); if (!$fp) { curl_close($cp); } else { curl_setopt($cp, CURLOPT_FILE, $fp); curl_exec($cp); curl_close($cp); fclose($fp); } } elseif (ini_get('allow_url_fopen')) { copy($f, $to); } } } else { if (isset($_POST['enable_site_cache'])) { if ($_POST['enable_site_cache'] === 'true') { @unlink($disable_cache_file); } else { touch($disable_cache_file); delete_files(dirname($disable_cache_file) . DIRECTORY_SEPARATOR . 'site', true, 1); } unset($_POST['enable_site_cache']); } // TODO: Make sure new path is not inside real_base // TODO: Ensure that real_base is not deleted under any circumstances if (isset($_POST['site_url']) && $_POST['site_url'] !== $data['site_url']) { $_POST['site_url'] = strtolower(rtrim($_POST['site_url'], '/')); if (empty($_POST['site_url'])) { $_POST['site_url'] = '/'; } if (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_FILENAME'])) { $php_self = str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF']); $doc_root = preg_replace('~' . $php_self . '$~i', '', $_SERVER['SCRIPT_FILENAME']); } else { $doc_root = $_SERVER['DOCUMENT_ROOT']; } $doc_root = realpath($doc_root); $target = $doc_root . str_replace('/', DIRECTORY_SEPARATOR, $_POST['site_url']); $php_include_base = rtrim(preg_replace('~^' . $doc_root . '~', '', FCPATH), DIRECTORY_SEPARATOR); $real_base = $doc_root; if (empty($php_include_base)) { $real_base .= DIRECTORY_SEPARATOR; } else { $real_base .= $php_include_base; } @($target_dir = dir($target)); $real_base_dir = dir($real_base); function compare_paths($one, $two) { return rtrim($one, DIRECTORY_SEPARATOR) === rtrim($two, DIRECTORY_SEPARATOR); } if ($target_dir && compare_paths($target_dir->path, $real_base_dir->path)) { $_POST['site_url'] = 'default'; $htaccess = create_htaccess(); $root_htaccess = FCPATH . '.htaccess'; $current = file_get_contents($root_htaccess); preg_match('/#MARK#.*/s', $htaccess, $match); $htaccess = preg_replace('/#MARK#.*/s', str_replace('$', '\\$', $match[0]), $current); file_put_contents($root_htaccess, $htaccess); } else { if ($target_dir) { $reserved = array('admin', 'app', 'storage'); foreach ($reserved as $dir) { $_dir = dir(rtrim($real_base_dir->path, '/') . "/{$dir}"); if (compare_paths($target_dir->path, $_dir->path)) { $this->error('400', "This directory is reserved for Koken core files. Please choose another location."); return; } } } if (!make_child_dir($target)) { $this->error('500', "Koken was not able to create the Site URL directory. Make sure the path provided is writable by the web server and try again."); return; } $php_include_rel = str_replace(DIRECTORY_SEPARATOR, '/', $php_include_base); $php_include_base = str_replace('\\', '\\\\', $php_include_base); $doc_root_php = str_replace('\\', '\\\\', $doc_root); $php = <<<OUT <?php \t\$rewrite = false; \t\$real_base_folder = '{$php_include_rel}'; \trequire '{$doc_root_php}{$php_include_base}' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'site' . DIRECTORY_SEPARATOR . 'site.php'; OUT; $htaccess = create_htaccess($_POST['site_url']); if ($this->check_for_rewrite()) { $file = $target . DIRECTORY_SEPARATOR . '.htaccess'; $file_data = $htaccess; $put_mode = FILE_APPEND; if ($_POST['site_url'] !== 'default' && "{$doc_root}" . DIRECTORY_SEPARATOR !== FCPATH) { $root_htaccess = FCPATH . '.htaccess'; if (file_exists($root_htaccess)) { $current = file_get_contents($root_htaccess); $redirect = create_htaccess($_POST['site_url'], true); preg_match('/#MARK#.*/s', $redirect, $match); $redirect = preg_replace('/#MARK#.*/s', str_replace('$', '\\$', $match[0]), $current); file_put_contents($root_htaccess, $redirect); } } } else { $file = $target . DIRECTORY_SEPARATOR . 'index.php'; $file_data = $php; $put_mode = 0; } if (file_exists($file)) { rename($file, "{$file}.bkup"); } if (!file_put_contents($file, $file_data, $put_mode)) { $this->error('500', "Koken was not able to create the necessary files in the Site URL directory. Make sure that path has sufficient permissions so that Koken may write the files."); return; } } if ($data['site_url'] !== 'default') { $old = $doc_root . str_replace('/', DIRECTORY_SEPARATOR, $data['site_url']); $old_dir = dir($old); if (!compare_paths($old_dir->path, $real_base_dir->path)) { if ($this->check_for_rewrite()) { $old_file = $old . DIRECTORY_SEPARATOR . '.htaccess'; } else { $old_file = $old . DIRECTORY_SEPARATOR . 'index.php'; } unlink($old_file); $backup = $old_file . '.bkup'; if (file_exists($backup)) { rename($backup, $old_file); } // This will only remove the dir if it is empty @rmdir($old); } } } global $raw_input_data; if (isset($raw_input_data['url_data'])) { $url_data = json_decode($raw_input_data['url_data'], true); $u = new Url(); $u->order_by('id DESC')->get(); $existing_data = unserialize($u->data); $transformed = array(); foreach ($url_data as $key => $udata) { $transformed[] = array('type' => $key, 'data' => $udata); } if ($existing_data !== $transformed) { $n = new Url(); $n->data = serialize($transformed); $n->save(); } unset($_POST['url_data']); } $save = array(); foreach ($_POST as $key => $val) { if (isset($data[$key]) && $data[$key] !== $val) { if ($key === 'retain_image_metadata' || $key !== 'image_processing_library' && strpos($key, 'image_') === 0) { delete_files(FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'images', true, 1); } $save[$key] = $val; } } foreach ($save as $k => $v) { $s = new Setting(); $s->where('name', $k)->get(); if ($s->exists()) { $s->value = $v; $s->save(); } else { if (in_array($k, array('uploading_default_album_visibility', 'uploading_publish_on_captured_date', 'email_handler'))) { $n = new Setting(); $n->name = $k; $n->value = $v; $n->save(); } } } if (isset($save['email_handler']) || isset($save['email_delivery_address'])) { $this->_compile_plugins(); } } $this->redirect('/settings'); } if (!isset($data['site_timezone']) || empty($data['site_timezone']) || $data['site_timezone'] === 'Etc/UTC') { $data['site_timezone'] = 'UTC'; } else { if ($data['site_timezone'] === 'Etc/GMT+12') { $data['site_timezone'] = 'Pacific/Auckland'; } } $data['image_processing_library_label'] = $libs[$data['image_processing_library']]['label']; $migrate_path = FCPATH . 'app' . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR; $migrations = scandir($migrate_path); $data['migrations'] = array(); if (!isset($data['last_migration'])) { $migration_setting = new Setting(); $migration_setting->name = 'last_migration'; $migration_setting->value = '26'; $migration_setting->save(); $data['last_migration'] = '26'; } if (!isset($data['has_toured']) || ENVIRONMENT === 'development') { $data['has_toured'] = true; } foreach ($migrations as $migration) { $migration = str_replace('.php', '', $migration); $migration_int = (int) $migration; if ($migration_int > $data['last_migration']) { $data['migrations'][] = $migration; } } unset($data['last_migration']); $data = Shutter::filter('api.settings', array($data)); $this->set_response_data($data); }
function step_3() { global $_path, $_rewrite; if (request_confirm('Create_Configuration')) { if (create_config()) { if ($_rewrite) { // si l'URL_REWRITING est activé. create_htaccess(); } if (file_exists($_path . "Config.php")) { ?> <form method="POST" action="<?php echo get_link("Install") . "&step=2"; ?> "> <p>Félicitation Le fichier de configuration à votre base de donnée à bien été crée Ce fichier va permettre à Caranille de communiquer à votre base de donnée.</p><br /> <br /><br /> <input type="submit" name="Choose_Curve" value="Continuer"/> </form> <?php } else { echo 'Le fichier de configuration n\'a pu être crée. Veuillez vérifier que PHP à bien les droits d\'écriture'; } } } }
function check_use_short_urls($value, $oldvalue) { if ($value && $value == 'true') { create_htaccess(); return true; } if ((!$value || $value == 'false') && file_exists(CAT_PATH . '/.htaccess')) { unlink(CAT_PATH . '/.htaccess'); } return false; }
<?php $path = FCPATH . '.htaccess'; if (file_exists($path)) { $htaccess = create_htaccess(); file_put_contents($path, $htaccess); } $done = true;
function step_3() { global $_path, $_rewrite, $install_step, $bdd; $aff = false; if (request_confirm('Create_Configuration')) { if (create_config()) { if ($_rewrite) { // si l'URL_REWRITING est activé. create_htaccess(); } } $aff = true; } elseif ($install_step == 2) { if (empty($_POST)) { $aff = true; } else { if (!request_confirm('Choose_Curve')) { $aff = false; } else { echo "cas de figure inattendue...<br/>"; } } } else { $aff = false; } if ($aff) { if (file_exists($_path . "Config.php")) { connect_db(); if ($bdd !== false) { ?> <form method="POST" action="<?php echo get_link("Index", "Install"); ?> "> <p>Félicitation Le fichier de configuration à votre base de donnée à bien été crée Ce fichier va permettre à Caranille de communiquer à votre base de donnée.</p><br /> <br /><br /> <input type="submit" name="Choose_Curve" value="Continuer"/> </form> <?php } else { echo "Le fichier de configuration contient une erreur..."; } } else { echo "Le fichier de configuration n'a pu être crée. Veuillez vérifier que PHP à bien les droits d'écriture"; } } else { echo "erreur inattendue...<br/>"; } }
# # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. include_once str_replace('//', '/', dirname(__FILE__) . '/') . 'config.php'; require_once ROOT_DIR . '/' . INC_DIR . '/functions.php'; $htaccess = ROOT_DIR . '/.htaccess'; if (!file_exists($htaccess)) { create_htaccess($htaccess); } $path = ROOT_DIR . '/' . CACHE_DIR . '/'; if (!file_exists($path)) { header("Location: " . URL . "/update.php"); exit(1); } if (isset($_GET['year']) && $_GET['year'] !== "") { $path .= $_GET['year'] . "/"; } if (isset($_GET['month']) && $_GET['month'] !== "") { $path .= $_GET['month'] . "/"; } if (isset($_GET['day']) && $_GET['day'] !== "") { $path .= $_GET['day'] . "/"; }