예제 #1
0
 /**
  * The actualiser for super debranding.
  *
  * @return tempcode		The UI
  */
 function actual()
 {
     require_code('config2');
     if (get_file_base() == get_custom_file_base()) {
         require_code('abstract_file_manager');
         force_have_afm_details();
     }
     set_value('rebrand_name', post_param('rebrand_name'));
     set_value('rebrand_base_url', post_param('rebrand_base_url'));
     set_value('company_name', post_param('company_name'));
     set_option('show_docs', post_param('show_docs', '0'));
     require_code('database_action');
     //set_option('allow_member_integration','off');
     foreach (array(get_file_base() . '/pages/comcode_custom/' . get_site_default_lang(), get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang()) as $dir) {
         if (!file_exists($dir)) {
             require_code('files');
             if (@mkdir($dir, 0777) === false) {
                 warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY_REPAIR', escape_html($dir)));
             }
             fix_permissions($dir, 0777);
             sync_file($dir);
         }
     }
     $keyboard_map_path = get_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/keymap.txt';
     $myfile = @fopen($keyboard_map_path, 'wb');
     if ($myfile === false) {
         intelligent_write_error($keyboard_map_path);
     }
     $km = post_param('keyboard_map');
     if (fwrite($myfile, $km) < strlen($km)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($keyboard_map_path);
     sync_file($keyboard_map_path);
     $adminguide_path = get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang() . '/website.txt';
     $adminguide = post_param('adminguide');
     $adminguide = str_replace('__company__', post_param('company_name'), $adminguide);
     $myfile = @fopen($adminguide_path, 'wb');
     if ($myfile === false) {
         intelligent_write_error($adminguide_path);
     }
     if (fwrite($myfile, $adminguide) < strlen($adminguide)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($adminguide_path);
     sync_file($adminguide_path);
     $start_path = get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang() . '/start.txt';
     if (!file_exists($start_path)) {
         $start = post_param('start_page');
         $myfile = @fopen($start_path, 'wb');
         if ($myfile === false) {
             intelligent_write_error($start_path);
         }
         if (fwrite($myfile, $start) < strlen($start)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         fix_permissions($start_path);
         sync_file($start_path);
     }
     if (get_file_base() == get_custom_file_base()) {
         $critical_errors = file_get_contents(get_file_base() . '/sources/critical_errors.php');
         $critical_errors = str_replace('ocPortal', post_param('rebrand_name'), $critical_errors);
         $critical_errors = str_replace('http://ocportal.com', post_param('rebrand_base_url'), $critical_errors);
         $critical_errors = str_replace('ocProducts', 'ocProducts/' . post_param('company_name'), $critical_errors);
         $critical_errors_path = 'sources_custom/critical_errors.php';
         afm_make_file($critical_errors_path, $critical_errors, false);
     }
     $save_header_path = get_file_base() . '/themes/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '/templates_custom/HEADER.tpl';
     $header_path = $save_header_path;
     if (!file_exists($header_path)) {
         $header_path = get_file_base() . '/themes/default/templates/HEADER.tpl';
     }
     $header_tpl = file_get_contents($header_path);
     $header_tpl = str_replace('Copyright ocProducts Limited', '', $header_tpl);
     $myfile = @fopen($save_header_path, 'wb');
     if ($myfile === false) {
         intelligent_write_error($save_header_path);
     }
     if (fwrite($myfile, $header_tpl) < strlen($header_tpl)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($save_header_path);
     sync_file($save_header_path);
     if (post_param_integer('churchy', 0) == 1) {
         if (is_object($GLOBALS['FORUM_DB'])) {
             $GLOBALS['FORUM_DB']->query_delete('f_emoticons', array('e_code' => ':devil:'), '', 1);
         } else {
             $GLOBALS['SITE_DB']->query_delete('f_emoticons', array('e_code' => ':devil:'), '', 1);
         }
     }
     // Make sure some stuff is disabled for non-admin staff
     $staff_groups = $GLOBALS['FORUM_DRIVER']->get_moderator_groups();
     $disallowed_pages = array('admin_setupwizard', 'admin_addons', 'admin_backup', 'admin_errorlog', 'admin_import', 'admin_occle', 'admin_phpinfo', 'admin_debrand');
     foreach (array_keys($staff_groups) as $id) {
         foreach ($disallowed_pages as $page) {
             $GLOBALS['SITE_DB']->query_delete('group_page_access', array('page_name' => $page, 'zone_name' => 'adminzone', 'group_id' => $id), '', 1);
             // in case already exists
             $GLOBALS['SITE_DB']->query_insert('group_page_access', array('page_name' => $page, 'zone_name' => 'adminzone', 'group_id' => $id));
         }
     }
     // Clean up the theme images
     //  background-image
     $theme = $GLOBALS['FORUM_DRIVER']->get_theme();
     find_theme_image('background_image');
     //$GLOBALS['SITE_DB']->query_update('theme_images',array('path'=>'themes/default/images/blank.gif'),array('id'=>'background-image','theme'=>$theme),'',1); No longer ocp-specific
     //  logo/*
     if (addon_installed('zone_logos')) {
         find_theme_image('logo/adminzone-logo');
         find_theme_image('logo/cms-logo');
         find_theme_image('logo/collaboration-logo');
         $main_logo_url = find_theme_image('logo/-logo', false, true);
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $main_logo_url), array('id' => 'logo/adminzone-logo', 'theme' => $theme), '', 1);
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $main_logo_url), array('id' => 'logo/cms-logo', 'theme' => $theme), '', 1);
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $main_logo_url), array('id' => 'logo/collaboration-logo', 'theme' => $theme), '', 1);
     }
     // Various other icons
     require_code('uploads');
     $path = get_url('', 'favicon', 'themes/default/images_custom');
     if ($path[0] != '') {
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $path[0]), array('id' => 'favicon'));
     }
     $path = get_url('', 'appleicon', 'themes/default/images_custom');
     if ($path[0] != '') {
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $path[0]), array('id' => 'appleicon'));
     }
     if (addon_installed('ocf_avatars')) {
         $path = get_url('', 'system_avatar', 'themes/default/images_custom');
         if ($path[0] != '') {
             $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $path[0]), array('id' => 'ocf_default_avatars/default_set/ocp_fanatic'));
         }
     }
     $title = get_page_title('SUPER_DEBRAND');
     // Redirect them back to editing screen
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
예제 #2
0
/**
 * Copies a file (NOT a directory) on the open AFM connection.
 *
 * @param  PATH		The path to the file we are copying.
 * @param  PATH		The target path.
 * @param  boolean	Whether world access is required for the copy.
 */
function afm_copy($old_path, $new_path, $world_access)
{
    $a = get_custom_file_base() . '/' . $old_path;
    if (!file_exists($a)) {
        $a = get_file_base() . '/' . $old_path;
    }
    $contents = file_get_contents($a);
    afm_make_file($new_path, $contents, $world_access);
}
예제 #3
0
파일: tar.php 프로젝트: erico-deh/ocPortal
/**
 * Extract all the files in the specified TAR file to the specified path.
 *
 * @param  array			The TAR file handle
 * @param  PATH			The full path to the folder to extract to
 * @param  boolean		Whether to extract via the AFM (assumes AFM has been set up prior to this function call)
 * @param  ?array			The files to extract (NULL: all)
 * @param  boolean		Whether to take backups of Comcode pages
 */
function tar_extract_to_folder(&$resource, $path, $use_afm = false, $files = NULL, $comcode_backups = false)
{
    if (!array_key_exists('directory', $resource)) {
        tar_get_directory($resource);
    }
    if (substr($path, -1) != '/') {
        $path .= '/';
    }
    $directory = $resource['directory'];
    foreach ($directory as $file) {
        if ($file['path'] != 'mod.inf' && $file['path'] != 'mod.php' && (is_null($files) || in_array($file['path'], $files))) {
            // Special case for directories. ocPortal doesn't add directory records, but at least 7-zip does
            if (substr($file['path'], -1) == '/') {
                if (!$use_afm) {
                    @mkdir($path . $file['path'], 0777);
                    fix_permissions($path . $file['path'], 0777);
                    sync_file($path . $file['path']);
                } else {
                    afm_make_directory($path . $file['path'], true);
                }
                continue;
            }
            $data = tar_get_file($resource, $file['path']);
            $path_components = explode('/', $file['path']);
            $buildup = '';
            foreach ($path_components as $i => $component) {
                if ($component != '') {
                    if (array_key_exists($i + 1, $path_components)) {
                        $buildup .= $component . '/';
                        if (!$use_afm) {
                            if (!file_exists($path . $buildup)) {
                                @mkdir($path . $buildup, 0777);
                                fix_permissions($path . $buildup, 0777);
                                sync_file($path . $buildup);
                            }
                        } else {
                            afm_make_directory($path . $buildup, true);
                        }
                    }
                }
            }
            // Take backup of Comcode page, if requested
            if ($comcode_backups) {
                if (substr($file['path'], -4) == '.txt') {
                    if (!$use_afm) {
                        if (file_exists(get_custom_file_base() . '/' . $path . $file['path'])) {
                            copy(get_custom_file_base() . '/' . $path . $file['path'], $path . $file['path'] . '.' . strval(time()));
                        }
                    } else {
                        if (file_exists(get_custom_file_base() . '/' . $path . $file['path'])) {
                            afm_copy($path . $file['path'], $path . $file['path'] . '.' . strval(time()), true);
                        }
                    }
                }
            }
            // Actually make file
            if ($path == '/' && $comcode_backups && get_param_integer('keep_theme_test', 0) == 1 && preg_match('#^[\\w\\_]+\\.txt$#', basename($file['path'])) != 0) {
                $theme = NULL;
                foreach ($directory as $file2) {
                    $matches = array();
                    if (preg_match('#^themes/([\\w\\_\\-]+)/#', $file2['path'], $matches) != 0) {
                        $theme = $matches[1];
                        break;
                    }
                }
                if (!is_null($theme)) {
                    $file['path'] = dirname($file['path']) . '/' . $theme . '__' . basename($file['path']);
                }
            }
            if (!$use_afm) {
                $myfile = @fopen(get_custom_file_base() . '/' . $path . $file['path'], 'wb');
                if ($myfile === false) {
                    intelligent_write_error($path . $file['path']);
                }
                if (fwrite($myfile, $data['data']) < strlen($data['data'])) {
                    warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                }
                $fullpath = get_custom_file_base() . '/' . $path . $file['path'];
                @chmod($fullpath, $data['mode']);
                fclose($myfile);
                fix_permissions($fullpath);
                sync_file($fullpath);
            } else {
                afm_make_file($path . $file['path'], $data['data'], ($data['mode'] & 02) != 0);
            }
        }
    }
}
예제 #4
0
/**
 * 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}&hellip;</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}&hellip;</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(' ', '&nbsp;', escape_html(display_time_period(60 * 10))) . "&nbsp;&dagger;</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>&dagger; {$l_customisations}</p>\n\n\t<h2 style=\"margin-top: 40px\">{$l_error_correction}&hellip;</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();
}
예제 #5
0
/**
 * Add a zone.
 *
 * @param  ID_TEXT		Name of the zone
 * @param  SHORT_TEXT	The zone title
 * @param  ID_TEXT		The zones default page
 * @param  SHORT_TEXT	The header text
 * @param  ID_TEXT		The theme
 * @param  BINARY			Whether the zone is wide
 * @param  BINARY			Whether the zone requires a session for pages to be used
 * @param  BINARY			Whether the zone in displayed in the menu coded into some themes
 */
function actual_add_zone($zone, $title, $default_page = 'start', $header_text = '', $theme = 'default', $wide = 0, $require_session = 0, $displayed_in_menu = 1)
{
    require_code('type_validation');
    if (!is_alphanumeric($zone, true)) {
        warn_exit(do_lang_tempcode('BAD_CODENAME'));
    }
    if (get_file_base() != get_custom_file_base()) {
        warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT'));
    }
    // Check doesn't already exist
    $test = $GLOBALS['SITE_DB']->query_value_null_ok('zones', 'zone_header_text', array('zone_name' => $zone));
    if (!is_null($test)) {
        if (file_exists(get_file_base() . '/' . $zone)) {
            warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($zone)));
        } else {
            persistant_cache_delete(array('ZONE', $zone));
            $GLOBALS['SITE_DB']->query_delete('zones', array('zone_name' => $zone), '', 1);
        }
    }
    if (!file_exists(get_file_base() . '/' . $zone)) {
        // Create structure
        afm_make_directory($zone . '/pages/minimodules_custom', true, true);
        afm_make_directory($zone . '/pages/minimodules', false, true);
        afm_make_directory($zone . '/pages/modules_custom', true, true);
        afm_make_directory($zone . '/pages/modules', false, true);
        $langs = array_keys(find_all_langs(true));
        foreach ($langs as $lang) {
            afm_make_directory($zone . '/pages/comcode_custom/' . $lang, true, true);
            afm_make_directory($zone . '/pages/comcode/' . $lang, false, true);
            afm_make_directory($zone . '/pages/html_custom/' . $lang, true, true);
            afm_make_directory($zone . '/pages/html/' . $lang, false, true);
        }
        afm_make_file($zone . '/index.php', file_get_contents(get_file_base() . '/site/index.php'), false);
        if (file_exists(get_file_base() . '/pages/.htaccess')) {
            afm_make_file($zone . '/pages/.htaccess', file_get_contents(get_file_base() . '/pages/.htaccess'), false);
        }
        $index_php = array('pages/comcode', 'pages/comcode/EN', 'pages/comcode_custom', 'pages/comcode_custom/EN', 'pages/html', 'pages/html/EN', 'pages/html_custom', 'pages/html_custom/EN', 'pages/modules', 'pages/modules_custom', 'pages');
        foreach ($index_php as $i) {
            afm_make_file($zone . '/' . $i . '/index.html', '', false);
        }
        $default_menu = <<<END
[block="zone_{$zone}_menu" type="tree" caption="Menu"]side_stored_menu[/block]
[block failsafe="1"]side_users_online[/block]
[block failsafe="1"]side_stats[/block]
[block]side_personal_stats[/block]
END;
        afm_make_file($zone . '/pages/comcode_custom/EN/panel_left.txt', $default_menu, true);
    }
    afm_make_file($zone . '/pages/comcode_custom/EN/' . filter_naughty($default_page) . '.txt', '[title]' . do_lang('YOUR_NEW_ZONE') . '[/title]' . chr(10) . chr(10) . do_lang('YOUR_NEW_ZONE_PAGE', $zone . ':' . $default_page) . chr(10) . chr(10) . '[block]main_comcode_page_children[/block]', true);
    $GLOBALS['SITE_DB']->query_insert('zones', array('zone_name' => $zone, 'zone_title' => insert_lang($title, 1), 'zone_default_page' => $default_page, 'zone_header_text' => insert_lang($header_text, 1), 'zone_theme' => $theme, 'zone_wide' => $wide, 'zone_require_session' => $require_session, 'zone_displayed_in_menu' => $displayed_in_menu));
    require_code('menus2');
    $menu_item_count = $GLOBALS['SITE_DB']->query_value('menu_items', 'COUNT(*)', array('i_menu' => 'zone_menu'));
    if ($menu_item_count < 40) {
        add_menu_item_simple('zone_menu', NULL, $title, $zone . ':', 0, 1);
    }
    log_it('ADD_ZONE', $zone);
    persistant_cache_delete('ALL_ZONES');
    decache('main_sitemap');
    decache('side_stored_menu');
    decache('side_zone_jump');
}