/** * Standard modular run function. * * @return tempcode Results */ function run() { require_lang('stats'); require_lang('dates'); $delete_older_than = post_param_integer('delete_older_than', NULL); if (is_null($delete_older_than)) { @ob_end_clean(); $delete_older_than = intval(get_option('stats_store_time')); require_code('form_templates'); $fields = form_input_integer(do_lang_tempcode('DPLU_DAYS'), do_lang_tempcode('DESCRIPTION_DELETE_DAYS'), 'delete_older_than', $delete_older_than, true); $post_url = get_self_url(false, false, NULL, false, true); $submit_name = do_lang_tempcode('DELETE'); $hidden = build_keep_post_fields(); $title = get_page_title('PAGE_STATS_DELETE'); $tpl = do_template('FORM_SCREEN', array('SKIP_VALIDATION' => true, 'HIDDEN' => $hidden, 'TITLE' => $title, 'TEXT' => do_lang_tempcode('DELETE_DATA_AVAILABLE'), 'URL' => $post_url, 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name)); $echo = globalise($tpl, NULL, '', true); $echo->evaluate_echo(); exit; } if (function_exists('set_time_limit')) { @set_time_limit(0); } // Write install.php file $template = get_custom_file_base() . '/data_custom/modules/admin_cleanup/page_stats.php.pre'; if (!file_exists($template)) { $template = get_file_base() . '/data/modules/admin_cleanup/page_stats.php.pre'; } $_install_php_file = file_get_contents($template); $install_php_file = ocp_tempnam('ps'); $tmpfile = fopen($install_php_file, 'wb'); fwrite($tmpfile, substr($_install_php_file, 0, strpos($_install_php_file, '{!!DB!!}'))); // Get old data do { $or_list = ''; $data = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'stats WHERE date_and_time<' . strval(time() - 60 * 60 * 24 * $delete_older_than), 500); foreach ($data as $d) { $list = ''; foreach ($d as $name => $value) { if (is_null($value)) { continue; } if ($list != '') { $list .= ','; } $list .= "'" . (is_string($name) ? $name : strval($name)) . "'=>"; if (!is_integer($value)) { $list .= "'" . str_replace('\'', '\\\'', $value) . "'"; } else { $list .= strval($value); } } fwrite($tmpfile, "\t\$GLOBALS['SITE_DB']->query_insert('stats',array({$list}));\n"); if ($or_list != '') { $or_list .= ' OR '; } $or_list .= 'id=' . strval($d['id']); } if ($or_list != '') { $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'stats WHERE ' . $or_list); } } while ($data != array()); fwrite($tmpfile, substr($_install_php_file, strpos($_install_php_file, '{!!DB!!}') + 8)); // Make tar require_code('tar'); $file = 'stats-leading-to-' . date('Y-m-d', utctime_to_usertime(time() - 60 * 60 * 24 * $delete_older_than)); $stats_backup_url = get_custom_base_url() . '/exports/backups/' . $file . '.tar'; $myfile = tar_open(get_custom_file_base() . '/exports/backups/' . $file . '.tar', 'wb'); tar_add_file($myfile, $file . '.php', $install_php_file, 0664, time(), true); tar_close($myfile); fclose($tmpfile); @unlink($install_php_file); $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'stats WHERE date_and_time<' . strval(time() - 60 * 60 * 24 * $delete_older_than)); return do_template('CLEANUP_PAGE_STATS', array('_GUID' => '1df213eee7c5c6b97168e5a34e92d3b0', 'STATS_BACKUP_URL' => $stats_backup_url)); }
/** * The actualiser to create a .po TAR. * * @return tempcode The UI */ function export_po() { $lang = filter_naughty(get_param('id')); // Send header header('Content-Type: application/octet-stream' . '; authoritative=true;'); if (strstr(ocp_srv('HTTP_USER_AGENT'), 'MSIE') !== false) { header('Content-Disposition: filename="ocportal-' . $lang . '.tar"'); } else { header('Content-Disposition: attachment; filename="ocportal-' . $lang . '.tar"'); } require_code('tar'); require_code('lang_compile'); require_code('character_sets'); $tempfile = ocp_tempnam('po'); $tar = tar_open($tempfile, 'wb'); $dh = @opendir(get_custom_file_base() . '/lang_custom/' . $lang); if ($dh !== false) { $charset = do_lang('charset', NULL, NULL, NULL, $lang); $english_charset = do_lang('charset', NULL, NULL, NULL, fallback_lang()); while (($f = readdir($dh)) !== false) { if (substr($f, -4) == '.ini') { $path = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $f; $entries = array(); _get_lang_file_map($path, $entries, false, false); $mtime = filemtime($path); $data = ' msgid "" msgstr "" "Project-Id-Version: ocportal\\n" "PO-Revision-Date: ' . gmdate('Y-m-d H:i', $mtime) . '+0000\\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n" "Language-Team: FULL NAME <EMAIL@ADDRESS>\\n" "MIME-Version: 1.0\\n" "Content-Type: text/plain; charset=UTF-8\\n" "Content-Transfer-Encoding: 8bit\\n" "X-ocPortal-Export-Date: ' . gmdate('Y-m-d H:i', $mtime) . '+0000\\n" "X-Generator: ocPortal (' . ocp_version_full() . ')\\n" '; $entries2 = array(); $en_seen_before = array(); foreach ($entries as $key => $val) { $english = do_lang($key, NULL, NULL, NULL, fallback_lang(), false); if (is_null($english)) { continue; } if ($english == '') { continue; } $val = convert_to_internal_encoding($val, $charset, 'utf-8'); $val = str_replace(chr(10), '\\n', $val); $english = convert_to_internal_encoding($english, $english_charset, 'utf-8'); $english = str_replace(chr(10), '\\n', $english); $seen_before = false; if (isset($en_seen_before[$val])) { $seen_before = true; foreach ($entries2 as $_key => $_val) { if ($entries2[$_key][2] == $val) { $entries2[$_key][1] = true; } } } $entries2[$key] = array($val, $seen_before, $english); $en_seen_before[$val] = 1; } require_code('support2'); foreach ($entries2 as $key => $_val) { list($val, $seen_before, $english) = $_val; $data .= '#: [strings]' . $key . chr(10); if ($seen_before) { $data .= 'msgctxt "[strings]' . $key . '"' . chr(10); } $wrapped = preg_replace('#"\\n"$#', '', ocp_mb_chunk_split(str_replace('"', '\\"', $english), 76, '"' . chr(10) . '"')); if (strpos($wrapped, chr(10)) !== false) { $data .= 'msgid ""' . chr(10) . '"' . $wrapped . '"' . chr(10); } else { $data .= 'msgid "' . $wrapped . '"' . chr(10); } $wrapped = preg_replace('#"\\n"$#', '', ocp_mb_chunk_split(str_replace('"', '\\"', $val), 76, '"' . chr(10) . '"')); if (strpos($wrapped, chr(10)) !== false) { $data .= 'msgstr ""' . chr(10) . '"' . $wrapped . '"' . chr(10); } else { $data .= 'msgstr "' . $wrapped . '"' . chr(10); } $data .= chr(10); } tar_add_file($tar, basename($f, '.ini') . '/' . basename($f, '.ini') . '-' . strtolower($lang) . '.po', $data, 0666, $mtime); } } } tar_close($tar); readfile($tempfile); @unlink($tempfile); $GLOBALS['SCREEN_TEMPLATE_CALLED'] = ''; exit; return new ocp_tempcode(); // For code quality checker }
/** * The upgrader.php script handler. */ function upgrade_script() { @ini_set('ocproducts.xss_detect', '0'); require_lang('upgrade'); require_code('database_action'); require_code('config2'); if (function_exists('set_time_limit')) { @set_time_limit(180); } if (array_key_exists('given_password', $_POST)) { $given_password = post_param('given_password'); if (check_master_password($given_password)) { $type = get_param('type', 'misc'); require_code('abstract_file_manager'); up_do_header(); if (post_param('ftp_username', '') != '') { $_POST['uses_ftp'] = '1'; _ftp_info(true); // To give early error if there's a problem } // Handle shared site upgrading with no per-site UI global $SITE_INFO; if (isset($SITE_INFO['custom_file_base_stub'])) { require_code('shared_installs'); $u = current_share_user(); if (!is_null($u)) { upgrade_sharedinstall_sites(); echo '<p>Now regenerate <kbd>template.sql</kbd>, using something like <kbd>mysqldump -uroot -p myocp_site_shareddemo > ~/public_html/template.sql</kbd></p>'; up_do_footer(); return; } } $show_more_link = true; switch ($type) { case 'misc': clear_caches_1(); $l_choices = do_lang('FU_CHOICES'); $oc = get_option('site_closed') == '0' ? do_lang('SITE_OPEN') : do_lang('SITE_CLOSED'); $a = float_to_raw_string(ocp_version_number()); $b = get_value('version'); if (is_null($b)) { $b = '2.5'; } $l_up_info = do_lang('FU_UP_INFO' . ($a == $b ? '_1' : '_2'), $a, $b); $l_fu_closedness = do_lang('FU_CLOSENESS', $oc); $l_maintenance = do_lang('FU_MAINTENANCE'); $l_upgrading = do_lang('FU_UPGRADING'); $l_take_backup = do_lang('FU_TAKE_BACKUP'); $l_clear_caches = fu_link('upgrader.php?type=decache', do_lang('FU_CLEAR_CACHES')); $l_check_permissions = fu_link('upgrader.php?type=check_perms', do_lang('FU_CHECK_PERMISSIONS')); $l_fix_permissions = fu_link('upgrader.php?type=fix_perms', do_lang('FU_FIX_PERMISSIONS')); $l_close_site = fu_link('upgrader.php?type=close_site', do_lang('FU_CLOSE_SITE'), get_option('site_closed') == '1'); $l_integrity_scan = fu_link('upgrader.php?type=integrity_scan&allow_merging=1', do_lang('FU_INTEGRITY_SCAN'), false, do_lang('FU_WILL_MERGE')); $l_integrity_scan_no_merging = fu_link('upgrader.php?type=integrity_scan', do_lang('FU_INTEGRITY_SCAN_NO_CSS_MERGE')); $l_database_upgrade = fu_link('upgrader.php?type=db_upgrade', do_lang('FU_DATABASE_UPGRADE')); $l_theme_upgrade = fu_link('upgrader.php?type=theme_upgrade', do_lang('FU_THEME_UPGRADE')); $l_open_site = fu_link('upgrader.php?type=open_site', do_lang('FU_OPEN_SITE'), get_option('site_closed') == '0'); $l_error_correction = do_lang('FU_ERROR_CORRECTION'); $l_not_for_patch = do_lang('FU_NOT_FOR_PATCH'); $l_tutorial = fu_link('http://ocportal.com/docs/tut_upgrade.htm', do_lang('FU_TUTORIAL')); $l_release_notes = do_lang('FU_RELEASE_NOTES'); $l_refer_release_notes = do_lang('FU_REFER_RELEASE_NOTES'); $news_id = post_param_integer('news_id', NULL); $tar_url = ''; if (!is_null($news_id)) { require_code('files'); $fetch_url = 'http://ocportal.com/uploads/website_specific/ocportal.com/scripts/fetch_release_details.php?news_id=' . strval($news_id) . '&from_version=' . urlencode(strval(ocp_version()) . '.' . ocp_version_minor()); $news = http_download_file($fetch_url, NULL, true, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 30.0); $details = unserialize($news); if ($details[0] != '') { $l_refer_release_notes = $details[0] . '<div style="overflow: auto; height: 150px">' . $details[2] . '</div>'; } $tar_url = $details[1]; } $l_download = fu_link('upgrader.php?type=file_upgrade&tar_url=' . urlencode(base64_encode($tar_url)), do_lang('FU_DOWNLOAD')); $l_important = do_lang('IMPORTANT'); $l_bugs = do_lang('FU_BUGS'); $l_upgrade_steps = do_lang('FU_UPGRADE_STEPS'); $l_action = do_lang('ACTION'); $l_step = do_lang('FU_STEP'); $l_estimated_time = do_lang('FU_ESTIMATED_TIME'); $l_safe_mode = fu_link('index.php?keep_safe_mode=1', do_lang('FU_SAFE_MODE')); $num_addons = $GLOBALS['SITE_DB']->query_value('addons', 'COUNT(*)'); $l_addon_management = fu_link('adminzone/index.php?page=admin_addons&keep_safe_mode=1', do_lang('FU_ADDON_MANAGEMENT', integer_format($num_addons)), $num_addons == 0); $l_customisations = do_lang('FU_CUSTOMISATIONS'); $closed = comcode_to_tempcode(get_option('closed'), NULL, true); $closed_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => 'SITE'), get_module_zone('admin_config'), NULL, false, false, false, 'group_CLOSED_SITE'); echo "\n<p>{$l_choices}</p>\n\n<div style=\"margin: 0 50px\">\n\t<h2>{$l_maintenance}…</h2><ul>\n\t\t<li>{$l_clear_caches}</li>\n\t\t<li>{$l_check_permissions}</li>\n\t\t<li>{$l_fix_permissions}</li>\n\t</ul>\n\n\t<h2 style=\"margin-top: 40px\">{$l_upgrading}…</h2>\n\n\t<h3>{$l_important}</h3>\n\n\t<p>{$l_bugs}</p>\n\n\t<h3>{$l_release_notes}</h3>\n\n\t<p>{$l_refer_release_notes}</p>\n\n\t<h3>{$l_upgrade_steps}</h3>\n\n\t<div class=\"wide_table_wrap\"><table style=\"margin-top: 5px\" class=\"solidborder wide_table spaced_table\">\n\t\t<tr>\n\t\t\t<th>{$l_step}</th>\n\t\t\t<th>{$l_action}</th>\n\t\t\t<th>{$l_estimated_time}</th>\n\t\t</tr>\n\t\t<tr><th>X</th><td>{$l_not_for_patch} {$l_tutorial}</td><td>" . escape_html(display_time_period(60 * 120)) . "</td></tr>\n\t\t<tr><th>1</th><td>{$l_take_backup}</td><td>" . escape_html(display_time_period(60 * 120)) . "</td></tr>\n\t\t<tr><th>2</th><td>{$l_close_site} {$l_fu_closedness}<br /><q style=\"font-style: italic\">" . $closed->evaluate() . "</q> <span class=\"associated_link_to_small\">[<a href=\"" . escape_html($closed_url->evaluate()) . "\" title=\"(this link will open in a new window)\" target=\"_blank\">" . do_lang('CHANGE') . "</a>]</span></td><td>" . escape_html(display_time_period(60)) . "</td></tr>\n\t\t<tr><th>3</th><td>{$l_download}</td><td>" . escape_html(display_time_period(60 * 5)) . "</td></tr>\n\t\t<tr><th>4</th><td>{$l_not_for_patch} {$l_integrity_scan_no_merging}<!-- " . do_lang('OR') . " {$l_integrity_scan}--></td><td>" . str_replace(' ', ' ', escape_html(display_time_period(60 * 10))) . " †</td></tr>\n\t\t<tr><th>5</th><td>{$l_not_for_patch} {$l_database_upgrade}<br />{$l_up_info}</td><td>" . escape_html(display_time_period(60 * 5)) . "</td></tr>\n\t\t<tr><th>6</th><td>{$l_not_for_patch} {$l_theme_upgrade}</td><td>" . escape_html(display_time_period(60 * 5)) . "</td></tr>\n\t\t<tr><th>7</th><td>{$l_clear_caches}</td><td>1 minute</td></tr>\n\t\t<tr><th>8</th><td>{$l_open_site} {$l_fu_closedness}</td><td>1 minute</td></tr>\n\t</table></div>\n\n\t<p>† {$l_customisations}</p>\n\n\t<h2 style=\"margin-top: 40px\">{$l_error_correction}…</h2><ul style=\"margin-top: 5px\">\n\t\t<li>{$l_safe_mode}</li>\n\t\t<li>{$l_addon_management}</li>\n\t</ul>\n</div>\n"; $show_more_link = false; break; case 'decache': clear_caches_2(); echo '<p>' . do_lang('SUCCESS') . '</p>'; break; case 'check_perms': echo check_perms(); break; case 'fix_perms': echo fix_perms(); break; case 'open_site': set_option('site_closed', '0'); echo '<p>' . do_lang('SUCCESS') . '</p>'; break; case 'close_site': set_option('closed', do_lang('FU_CLOSED_FOR_UPGRADES', get_site_name())); set_option('site_closed', '1'); echo '<p>' . do_lang('SUCCESS') . '</p>'; break; case 'file_upgrade': if (get_param('tar_url', '') == '') { echo do_lang('FU_FILE_UPGRADE_INFO'); } echo do_lang('FU_FILE_UPGRADE_INFO_MANUAL'); echo '<form title="' . do_lang('PROCEED') . '" enctype="multipart/form-data" action="upgrader.php?type=_file_upgrade" method="post">' . post_fields_relay(); echo '<label for="url">' . do_lang('URL') . '</label> <input type="text" id="url" name="url" value="' . escape_html(base64_decode(get_param('tar_url', ''))) . '" /> '; if (ocp_srv('HTTP_HOST') == 'ocportal.com' || $GLOBALS['DEBUG_MODE']) { echo '<br /><label for="upload">' . do_lang('UPLOAD') . '</label> <input type="file" id="upload" name="upload" />'; } echo '<input type="submit" value="' . do_lang('PROCEED') . '" />'; echo '</form>'; $show_more_link = false; break; case '_file_upgrade': require_code('tar'); if (function_exists('set_time_limit')) { @set_time_limit(0); } if (post_param('url', '') == '' && (ocp_srv('HTTP_HOST') == 'ocportal.com' || $GLOBALS['DEBUG_MODE'])) { $temp_path = $_FILES['upload']['tmp_name']; } else { if (post_param('url', '') == '') { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } $temp_path = ocp_tempnam('ocpfu'); $myfile = fopen($temp_path, 'wb'); http_download_file(post_param('url'), NULL, true, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $myfile); fclose($myfile); } $upgrade_resource = tar_open($temp_path, 'rb'); //tar_extract_to_folder($upgrade_resource,'',true); disable_php_memory_limit(); $directory = tar_get_directory($upgrade_resource); // Uses up to around 5MB $data = array('todo' => array()); $popup_simple_extract = _ftp_info() === false; if (!$popup_simple_extract) { echo '<p>' . do_lang('EXTRACTING_MESSAGE') . '</p>'; } $addon_contents = array(); // Find addons foreach ($directory as $upgrade_file2) { // See if we can find an addon registry file in our upgrade TAR if (strpos($upgrade_file2['path'], '/addon_registry/') !== false && substr($upgrade_file2['path'], -4) == '.php') { $file_data = tar_get_file($upgrade_resource, $upgrade_file2['path']); $addon_contents[basename($upgrade_file2['path'], '.php')] = $file_data['data']; } } // Process files foreach ($directory as $offset => $upgrade_file) { // skip over these, from manually installer package (which may be used for an upgrade) if ($upgrade_file['path'] == 'info.php') { continue; } if ($upgrade_file['path'] == 'install.php') { continue; } if ($upgrade_file['path'] == 'install.sql') { continue; } if ($upgrade_file['path'] == 'info.php.template') { continue; } if (!$popup_simple_extract) { // See if we can skip the file, if the on-disk version is identical? if (file_exists(get_file_base() . '/' . $upgrade_file['path']) && filesize(get_file_base() . '/' . $upgrade_file['path']) == $upgrade_file['size']) { $tar_data = tar_get_file($upgrade_resource, $upgrade_file['path']); if (file_get_contents(get_file_base() . '/' . $upgrade_file['path']) == $tar_data['data']) { echo do_lang('U_SKIPPING_MESSAGE', escape_html($upgrade_file['path'])) . '<br />'; continue; } } } // Addon registry file, for installed addon if (strpos($upgrade_file['path'], '/addon_registry/') !== false && file_exists(get_file_base() . '/' . $upgrade_file['path'])) { if (substr($upgrade_file['path'], -1) != '/') { if ($popup_simple_extract) { $data['todo'][] = array($upgrade_file['path'], $upgrade_file['mtime'], $offset + 512, $upgrade_file['size'], ($upgrade_file['mode'] & 02) != 0); } else { $file_data = tar_get_file($upgrade_resource, $upgrade_file['path']); afm_make_file($upgrade_file['path'], $file_data['data'], ($file_data['mode'] & 02) != 0); echo do_lang('U_EXTRACTING_MESSAGE', escape_html($upgrade_file['path'])) . '<br />'; } } } else { // Some other file $found = NULL; if (substr($upgrade_file['path'], -1) != '/') { foreach ($addon_contents as $addon_name => $addon_data) { // See if this is the addon for the file $shortened_path = $upgrade_file['path']; $shortened_path = preg_replace('#^themes/default/(templates|css)/#', '', $shortened_path); if (strpos($addon_data, '\'' . addslashes($shortened_path) . '\'') !== false) { $found = $addon_name; break; } } } // Install if either of the following is true: // - it's some file not in an addon (shouldn't actually happen) // - it's a new addon (addon that is not installed or uninstalled i.e. does not have an exported mod file) // - it's a file in an addon we have installed // - we're upgrading from an ocPortal version that doesn't support addons yet if (is_null($found) || !file_exists(get_file_base() . '/imports/mods/' . $found . '.tar') || file_exists(get_file_base() . '/sources/hooks/systems/addon_registry/' . $found . '.php') || !file_exists(get_file_base() . '/sources/hooks/systems/addon_registry')) { if (substr($upgrade_file['path'], -1) == '/') { afm_make_directory($upgrade_file['path'], false, true); } else { if ($popup_simple_extract) { $data['todo'][] = array($upgrade_file['path'], $upgrade_file['mtime'], $offset + 512, $upgrade_file['size'], ($upgrade_file['mode'] & 02) != 0); } else { $file_data = tar_get_file($upgrade_resource, $upgrade_file['path']); if (!file_exists(get_file_base() . '/' . dirname($upgrade_file['path']))) { afm_make_directory(dirname($upgrade_file['path']), false, true); } afm_make_file($upgrade_file['path'], $file_data['data'], ($file_data['mode'] & 02) != 0); echo do_lang('U_EXTRACTING_MESSAGE', escape_html($upgrade_file['path'])) . '<br />'; } } } if (substr($upgrade_file['path'], -1) != '/') { // If true: We need to copy it into our archived addon so that addon is kept up-to-date if (!is_null($found) && file_exists(get_file_base() . '/imports/mods/' . $found . '.tar')) { $old_mod_file = tar_open(get_file_base() . '/imports/mods/' . $found . '.tar', 'rb'); $new_mod_file = tar_open(get_file_base() . '/imports/mods/' . $found . '.new.tar', 'wb'); $directory2 = tar_get_directory($old_mod_file, true); if (!is_null($directory2)) { foreach ($directory2 as $d) { if ($d['path'] == $upgrade_file['path']) { continue; } $file_data = tar_get_file($old_mod_file, $d['path']); if ($d['path'] == 'mod.inf') { $file_data['data'] = preg_replace('#^version=.*#m', 'version=(version-synched)', $file_data['data']); } tar_add_file($new_mod_file, $d['path'], $file_data['data'], $d['mode'], $d['mtime']); } $file_data = tar_get_file($upgrade_resource, $upgrade_file['path']); tar_add_file($new_mod_file, $upgrade_file['path'], $file_data['data'], $upgrade_file['mode'], $upgrade_file['mtime']); tar_close($new_mod_file); tar_close($old_mod_file); unlink(get_file_base() . '/imports/mods/' . $found . '.tar'); rename(get_file_base() . '/imports/mods/' . $found . '.new.tar', get_file_base() . '/imports/mods/' . $found . '.tar'); echo do_lang('U_PACKING_MESSAGE', escape_html($upgrade_file['path'])) . '<br />'; } } } } } tar_close($upgrade_resource); if ($popup_simple_extract) { copy($temp_path, get_custom_file_base() . '/data_custom/upgrader.tar.tmp'); @unlink($temp_path); $temp_path = get_custom_file_base() . '/data_custom/upgrader.tar.tmp'; $tmp_data_path = get_custom_file_base() . '/data_custom/upgrader.tmp'; $tmp_data_file = fopen($tmp_data_path, 'wb'); fwrite($tmp_data_file, serialize($data)); fclose($tmp_data_file); global $SITE_INFO; $extract_url = get_base_url() . '/data/upgrader2.php?hashed_password='******'admin_password']) . '&tmp_path=' . urlencode($temp_path) . '&file_offset=0&tmp_data_path=' . urlencode($tmp_data_path) . '&done=' . urlencode(do_lang('DONE')); echo '<p>' . do_lang('FU_EXTRACTING_WINDOW', integer_format(count($data['todo']))) . '</p>'; echo '<iframe frameBorder="0" title="" style="width: 100%; height: 400px" src="' . escape_html($extract_url) . '"></iframe>'; } else { echo '<p>' . do_lang('SUCCESS') . '</p>'; @unlink($temp_path); } unset($_POST['news_id']); break; case 'integrity_scan': $allow_merging = either_param_integer('allow_merging', 0); echo run_integrity_check(false, $allow_merging == 1); break; case '_integrity_scan': _integrity_scan(); echo '<p>' . do_lang('SUCCESS') . '</p>'; break; case 'db_upgrade': $something_done = false; clear_caches_2(); if (version_specific()) { echo do_lang('FU_UPGRADED_CORE_TABLES'); $something_done = true; } $done = upgrade_modules(); if ($done != '') { echo do_lang('FU_UPGRADE_MODULES', $done); $something_done = true; } if (!$something_done) { echo do_lang('NO_UPGRADE_DONE'); } $version_files = ocp_version_number(); $_version_database = get_value('ocf_version'); $version_database = floatval($_version_database); if (is_null($_version_database)) { $version_database = 2.1; } // Either 2.0 or 2.1, and they are equivalent in terms of what we need to do if ($version_database < $version_files) { echo do_lang('FU_MUST_UPGRADE_OCF', fu_link('upgrader.php?type=ocf', do_lang('FU_UPGRADE_OCF'))); } break; case 'theme_upgrade': echo upgrade_themes(); break; case 'ocf': // Only to be launched as a consequent of db_upgrade if (ocf_upgrade()) { echo '<p>' . do_lang('SUCCESS') . '</p>'; } else { echo do_lang('FU_NO_OCF_UPGRADE'); } break; } if ($show_more_link) { echo '<hr /><div>' . fu_link('upgrader.php?type=misc', do_lang('MORE_OPTIONS')) . '</div>'; } } else { up_do_header(); up_do_login(do_lang('USER_BAD_PASSWORD')); } } else { up_do_header(); up_do_login(); } up_do_footer(); }
/** * Add a folder to the TAR archive * * @param array The TAR file handle * @param ?resource The logfile to write to (NULL: no logging) * @param PATH The full path to the folder to add * @param ?integer The maximum file size to add (NULL: no limit) * @param PATH The subpath relative to the path (should be left as the default '', as this is used for the recursion to distinguish the adding base path from where it's currently looking) * @param ?array A map (filename=>1) of files to not back up (NULL: none) * @param ?array A list of directories ONLY to back up from the root (NULL: no restriction) * @param boolean Whether to output spaces as we go to keep the connection alive * @param boolean Whether to not skip "special files" (ones not normally archive) */ function tar_add_folder(&$resource, $logfile, $path, $max_size = NULL, $subpath = '', $avoid_backing_up = NULL, $root_only_dirs = NULL, $tick = false, $all_files = false) { require_code('files'); $_full = $path == '' ? $subpath : $path . '/' . $subpath; if ($_full == '') { $_full = '.'; } if (!is_null($logfile)) { $dh = @opendir($_full); if ($dh === false) { if (fwrite($logfile, 'Could not access ' . $_full . ' [case 2]' . "\n") == 0) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } } } else { $dh = opendir($_full); } if ($dh !== false) { while (($entry = readdir($dh)) !== false) { if ($entry == '.' || $entry == '..') { continue; } if ($tick) { @(print ' '); } $_subpath = $subpath == '' ? $entry : $subpath . '/' . $entry; if (($all_files || !should_ignore_file($_subpath)) && $entry != 'backups') { $full = $path == '' ? $_subpath : $path . '/' . $_subpath; if (!is_readable($full)) { if (fwrite($logfile, 'Could not access ' . $full . "\n") == 0) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } continue; } if (is_dir($full)) { if (is_null($root_only_dirs) || in_array($entry, $root_only_dirs)) { tar_add_folder($resource, $logfile, $path, $max_size, $_subpath, $avoid_backing_up, NULL, $tick, $all_files); } } else { if ($full != $resource['full'] && (is_null($max_size) || filesize($full) < $max_size * 1024 * 1024) && (is_null($avoid_backing_up) || !array_key_exists($_subpath, $avoid_backing_up))) { //echo $_subpath.'<br />'; tar_add_file($resource, $_subpath, $full, fileperms($full), filemtime($full), true); if (!is_null($logfile) && fwrite($logfile, 'Backed up file ' . $full . ' (' . clean_file_size(filesize($full)) . ')' . "\n") == 0) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } } } } } closedir($dh); } }
/** * Create an addon to spec. * * @param string Filename to create in exports/mods directory (should end in .tar) * @param array List of files to include * @param string Addon name * @param string Addon incompatibilities (comma-separated) * @param string Addon dependencies (comma-separated) * @param string Addon author * @param string Addon organisation * @param string Addon version * @param string Addon description * @param PATH Directory to save to */ function create_addon($file, $files, $name, $incompatibilities, $dependencies, $author, $organisation, $version, $description, $dir = 'exports/mods') { require_code('tar'); $_full = get_custom_file_base() . '/' . $dir . '/' . $file; $tar = tar_open($_full, 'wb'); $max_mtime = 0; foreach ($files as $val) { if ($val == 'mod.inf') { continue; } $full = get_file_base() . '/' . filter_naughty($val); $themed_suffix = get_param('theme', $GLOBALS['FORUM_DRIVER']->get_theme()) . '__'; $themed_version = dirname($full) . '/' . $themed_suffix . basename($full); if (!file_exists($full) && !file_exists($themed_version)) { continue; } if (get_param_integer('keep_theme_test', 0) == 1 && file_exists($themed_version)) { $mode = fileperms($themed_version); $mtime = 0; //if ((file_exists(get_file_base().'/.git')) && (function_exists('json_decode')) && (filemtime($themed_version)>60*60*24-31*4/*If newer than 4 months it is likely git has garbled the modification date during a checkout*/)) //{ // $_themed_version=dirname($val).'/'.$themed_suffix.basename($val); // require_code('files'); // $json_data=@json_decode(http_download_file('http://github.com/api/v2/json/commits/list/chrisgraham/ocPortal/master/'.$_themed_version)); // if (isset($json_data->commits[0]->committed_date)) $mtime=strtotime($json_data->commits[0]->committed_date); //} if ($mtime == 0) { $mtime = filemtime($themed_version); } if ($mtime > $max_mtime) { $max_mtime = $mtime; } tar_add_file($tar, $val, $themed_version, $mode, $mtime, true); } else { $mode = fileperms($full); $mtime = 0; //if ((file_exists(get_file_base().'/.git')) && (function_exists('json_decode')) && (filemtime($full)>60*60*24-31*4/*If newer than 4 months it is likely git has garbled the modification date during a checkout*/)) //{ // require_code('files'); // $json_data=@json_decode(http_download_file('http://github.com/api/v2/json/commits/list/chrisgraham/ocPortal/master/'.$val)); // if (isset($json_data->commits[0]->committed_date)) $mtime=strtotime($json_data->commits[0]->committed_date); //} if ($mtime == 0) { $mtime = filemtime($full); } if ($mtime > $max_mtime) { $max_mtime = $mtime; } tar_add_file($tar, $val, $full, $mode, $mtime, true); $full = get_file_base() . '/' . filter_naughty($val) . '.editfrom'; if (file_exists($full)) { $mode = fileperms($full); $mtime = filemtime($full); tar_add_file($tar, $val . '.editfrom', $full, $mode, $mtime, true); } } // If it's a theme, make a mod.php for the theme to restore images_custom mappings if (substr($val, 0, 7) == 'themes/' && substr($val, -10) == '/theme.ini') { $theme = substr($val, 7, strpos($val, '/theme.ini') - 7); $images = $GLOBALS['SITE_DB']->query_select('theme_images', array('*'), array('theme' => $theme)); $data = '<' . '?php' . "\n"; foreach ($images as $image) { $data .= '$GLOBALS[\'SITE_DB\']->query_insert(\'theme_images\',array(\'id\'=>\'' . db_escape_string($image['id']) . '\',\'theme\'=>\'' . db_escape_string($image['theme']) . '\',\'path\'=>\'' . db_escape_string($image['path']) . '\',\'lang\'=>\'' . db_escape_string($image['lang']) . '\'),false,true);' . "\n"; } $data .= "?" . ">\n"; tar_add_file($tar, 'mod.php', $data, 0444, time()); } } // Our special file $name = str_replace('"', '\'', $name); $author = str_replace('"', '\'', $author); $organisation = str_replace('"', '\'', $organisation); $version = str_replace('"', '\'', $version); $incompatibilities = str_replace('"', '\'', $incompatibilities); $dependencies = str_replace('"', '\'', $dependencies); $description = str_replace(chr(13), '', str_replace(chr(10), '\\n', str_replace('"', '\'', $description))); $mod_inf = "name=" . $name . "\nauthor=" . $author . "\norganisation=" . $organisation . "\nversion=" . $version . "\nincompatibilities=" . $incompatibilities . "\ndependencies=" . $dependencies . "\ndescription=" . $description . "\n"; tar_add_file($tar, 'mod.inf', $mod_inf, 0644, time()); tar_close($tar); @touch($_full, $max_mtime); fix_permissions($_full); sync_file($_full); }
/** * Backend function to do a backup (meant to be run as a shutdown function - essentially a background task). * * @param ?string The filename to backup to (NULL: get global) * @param ?string The type of backup to do (NULL: get global) * @set full incremental * @param ?integer The maximum size of a file to include in the backup (NULL: get global) */ function make_backup_2($file = NULL, $b_type = NULL, $max_size = NULL) { global $STARTED_BACKUP; if ($STARTED_BACKUP) { return; } $STARTED_BACKUP = true; if (is_null($file)) { global $MB2_FILE, $MB2_B_TYPE, $MB2_MAX_SIZE; $file = $MB2_FILE; $b_type = $MB2_B_TYPE; $max_size = $MB2_MAX_SIZE; } if (function_exists('set_time_limit')) { @set_time_limit(0); } $logfile_path = get_custom_file_base() . '/exports/backups/' . $file . '.txt'; $logfile = @fopen($logfile_path, 'wt') or intelligent_write_error($logfile_path); // .txt file because IIS doesn't allow .log download @ini_set('log_errors', '1'); @ini_set('error_log', $logfile_path); fwrite($logfile, 'This is a log file for an ocPortal backup. The backup is not complete unless this log terminates with a completion message.' . "\n\n"); require_code('tar'); $myfile = tar_open(get_custom_file_base() . '/exports/backups/' . filter_naughty($file), 'wb'); // Write readme.txt file tar_add_file($myfile, 'readme.txt', do_lang('BACKUP_README', get_timezoned_date(time())), 0664, time()); // Write restore.php file $template = get_custom_file_base() . '/data_custom/modules/admin_backup/restore.php.pre'; if (!file_exists($template)) { $template = get_file_base() . '/data/modules/admin_backup/restore.php.pre'; } $_install_php_file = file_get_contents($template); $place = strpos($_install_php_file, '{!!DB!!}'); $__install_php_file = ocp_tempnam('ocpbak'); $install_php_file = fopen($__install_php_file, 'wb'); fwrite($install_php_file, substr($_install_php_file, 0, $place)); get_table_backup($logfile, 'db_meta', 'db_meta_indices', $install_php_file); if (fwrite($install_php_file, substr($_install_php_file, $place + 8)) == 0) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } fclose($install_php_file); tar_add_file($myfile, 'restore.php', $__install_php_file, 0664, time(), true); @unlink($__install_php_file); if ($b_type == 'full') { set_value('last_backup', strval(time())); $original_files = get_param_integer('keep_backup_alien', 0) == 1 ? unserialize(file_get_contents(get_file_base() . '/data/files.dat')) : NULL; $root_only_dirs = array_merge(find_all_zones(false, false, true), array('data', 'data_custom', 'exports', 'imports', 'lang', 'lang_custom', 'lang_cached', 'pages', 'persistant_cache', 'safe_mode_temp', 'sources', 'sources_custom', 'text', 'text_custom', 'themes', 'uploads', 'site')); tar_add_folder($myfile, $logfile, get_file_base(), $max_size, '', $original_files, $root_only_dirs, !running_script('cron_bridge'), true); } elseif ($b_type == 'incremental') { $threshold = intval(get_value('last_backup')); set_value('last_backup', strval(time())); $directory = tar_add_folder_incremental($myfile, $logfile, get_file_base(), $threshold, $max_size); $_directory = ''; foreach ($directory as $d) { $a = ''; foreach ($d as $k => $v) { if ($a != '') { $a .= ", "; } $a .= $k . '=' . $v; } $_directory .= $a . "\n"; } tar_add_file($myfile, 'DIRECTORY', $_directory, 0664, time()); } else { set_value('last_backup', strval(time())); } tar_close($myfile); if (!file_exists(get_custom_file_base() . '/exports/backups/' . filter_naughty($file))) { warn_exit(do_lang_tempcode('INTERNAL_ERROR')); } rename(get_custom_file_base() . '/exports/backups/' . filter_naughty($file), get_custom_file_base() . '/exports/backups/' . filter_naughty($file) . '.tar'); sync_file('exports/backups/' . filter_naughty($file) . '.tar'); fix_permissions('exports/backups/' . filter_naughty($file) . '.tar'); $url = get_base_url() . '/exports/backups/' . $file . '.tar'; if (function_exists('gzopen')) { if (fwrite($logfile, "\n" . do_lang('COMPRESSING') . "\n") == 0) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } $myfile = gzopen(get_custom_file_base() . '/exports/backups/' . $file . '.tar.gz.tmp', 'wb') or intelligent_write_error(get_custom_file_base() . '/exports/backups/' . $file . '.tar.gz.tmp'); $tar_path = get_custom_file_base() . '/exports/backups/' . filter_naughty($file) . '.tar'; $fp_in = fopen($tar_path, 'rb'); while (!feof($fp_in)) { $read = fread($fp_in, 8192); gzwrite($myfile, $read, strlen($read)); } fclose($fp_in); gzclose($myfile); rename(get_custom_file_base() . '/exports/backups/' . $file . '.tar.gz.tmp', get_custom_file_base() . '/exports/backups/' . $file . '.tar.gz'); fix_permissions(get_custom_file_base() . '/exports/backups/' . $file . '.tar.gz'); sync_file('exports/backups/' . filter_naughty($file) . '.tar.gz'); $url = get_base_url() . '/exports/backups/' . $file . '.tar.gz'; } if (fwrite($logfile, "\n" . do_lang('SUCCESS') . "\n") == 0) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } fclose($logfile); sync_file($logfile_path); fix_permissions($logfile_path); sync_file($logfile_path); // Remote backup $copy_server = get_option('backup_server_hostname'); if ($copy_server != '') { $path_stub = get_custom_file_base() . '/exports/backups/'; if (file_exists($path_stub . $file . '.tar.gz')) { $_file = $file . '.tar.gz'; } elseif (file_exists($path_stub . $file . '.tar')) { $_file = $file . '.tar'; } else { $file = NULL; } if (!is_null($file)) { $copy_port = get_option('backup_server_port'); if ($copy_port == '') { $copy_port = '21'; } $copy_user = get_option('backup_server_user'); if ($copy_user == '') { $copy_user = '******'; } $copy_password = get_option('backup_server_password'); if (is_null($copy_password)) { $copy_password = get_option('staff_address'); } $copy_path = get_option('backup_server_path'); if ($copy_path == '') { $copy_path = $_file; } elseif (substr($copy_path, -1) == '/' || $copy_path == '') { $copy_path .= $_file; } $ftp_connection = @ftp_connect($copy_server, intval($copy_port)); if ($ftp_connection !== false) { if (@ftp_login($ftp_connection, $copy_user, $copy_password)) { @ftp_delete($ftp_connection, $path_stub . $_file); @ftp_put($ftp_connection, $copy_path, $path_stub, FTP_BINARY); } @ftp_close($ftp_connection); } } } require_code('notifications'); dispatch_notification('backup_finished', NULL, do_lang('BACKUP', NULL, NULL, NULL, get_site_default_lang()), do_lang('BACKUP_FINISHED', comcode_escape($url), get_site_default_lang()), NULL, A_FROM_SYSTEM_PRIVILEGED); }
$gpath = get_custom_file_base() . '/exports/mods/' . $generate_filename; $tar = tar_open($gpath, 'wb'); $probe_dir = post_param('probe_dir', ''); $done = array(); foreach ($addons['non_bundled'] + $addons['bundled'] as $addon => $files) { if (post_param_integer('addon_' . $addon, 0) == 1) { foreach ($files as $file) { if (preg_match('#^(data\\_custom/|ocp_sitemap.xml$|info.php$)#', $file) == 0) { if (filemtime(get_file_base() . '/' . $file) > $cutoff_point) { if ($probe_dir == '' || @file_get_contents($probe_dir . '/' . $file) !== file_get_contents(get_file_base() . '/' . $file)) { $new_filename = $file; if (preg_match('#^(lang)\\_custom/#', $file) != 0 && ($probe_dir == '' || file_exists($probe_dir . '/' . $file))) { $new_filename .= '.quarantine'; } if (!isset($done[$new_filename])) { tar_add_file($tar, $new_filename, get_file_base() . '/' . $file, fileperms(get_file_base() . '/' . $file), filemtime(get_file_base() . '/' . $file), true); $done[$new_filename] = true; } } } } } } } tar_close($tar); require_code('mime_types'); header('Content-Type: ' . get_mime_type('tar') . '; authoritative=true;'); header('Content-Disposition: filename="' . str_replace(chr(13), '', str_replace(chr(10), '', addslashes($generate_filename))) . '"'); $myfile = fopen($gpath, 'rb'); fpassthru($myfile); fclose($myfile);