Beispiel #1
0
 function main($id, $mode)
 {
     global $config, $db, $user, $auth, $template, $cache;
     global $phpbb_root_path, $phpEx;
     global $method, $test_ftp_connection, $test_connection;
     include "{$phpbb_root_path}includes/functions_transfer.{$phpEx}";
     include "{$phpbb_root_path}includes/editor.{$phpEx}";
     include "{$phpbb_root_path}includes/functions_mods.{$phpEx}";
     include "{$phpbb_root_path}includes/mod_parser.{$phpEx}";
     // start the page
     $user->add_lang(array('install', 'acp/mods'));
     $this->tpl_name = 'acp_mods';
     $this->page_title = 'ACP_CAT_MODS';
     $this->mods_dir = $phpbb_root_path . 'store/mods';
     // get any url vars
     $action = request_var('action', '');
     $mod_id = request_var('mod_id', 0);
     $mod_url = request_var('mod_url', '');
     $parent = request_var('parent', 0);
     $mod_path = request_var('mod_path', '');
     if ($mod_path) {
         $mod_path = urldecode($mod_path);
         $mod_dir = substr($mod_path, 1, strpos($mod_path, '/', 1));
         $this->mod_root = $this->mods_dir . '/' . $mod_dir;
         $this->backup_root = $this->mod_root . '_backups/';
     }
     switch ($mode) {
         case 'config':
             $ftp_method = request_var('ftp_method', '');
             if (!$ftp_method || !class_exists($ftp_method)) {
                 $ftp_method = 'ftp';
                 $ftp_methods = transfer::methods();
                 if (!in_array('ftp', $ftp_methods)) {
                     $ftp_method = $ftp_methods[0];
                 }
             }
             if (isset($_POST['submit']) && check_form_key('acp_mods')) {
                 $ftp_host = request_var('host', '');
                 $ftp_username = request_var('username', '');
                 $ftp_password = request_var('password', '');
                 // not stored, used to test connection
                 $ftp_root_path = request_var('root_path', '');
                 $ftp_port = request_var('port', 21);
                 $ftp_timeout = request_var('timeout', 10);
                 $write_method = request_var('write_method', 0);
                 $file_perms = request_var('file_perms', '0644');
                 $dir_perms = request_var('dir_perms', '0755');
                 $compress_method = request_var('compress_method', '');
                 $preview_changes = request_var('preview_changes', 0);
                 $error = '';
                 if ($write_method == WRITE_DIRECT) {
                     // the very best method would be to check every file for is_writable
                     if (!is_writable("{$phpbb_root_path}common.{$phpEx}") || !is_writable("{$phpbb_root_path}adm/style/acp_groups.html")) {
                         $error = 'FILESYSTEM_NOT_WRITABLE';
                     }
                 } else {
                     if ($write_method == WRITE_FTP) {
                         // check the correctness of FTP infos
                         $test_ftp_connection = true;
                         $test_connection = false;
                         test_ftp_connection($ftp_method, $test_ftp_connection, $test_connection);
                         if ($test_connection !== true) {
                             $error = $test_connection;
                         }
                     } else {
                         if ($write_method == WRITE_MANUAL) {
                             // the compress class requires write access to the /store/ dir
                             if (!is_writable("{$phpbb_root_path}store/")) {
                                 $error = 'STORE_NOT_WRITABLE';
                             }
                         }
                     }
                 }
                 if (empty($error)) {
                     set_config('ftp_method', $ftp_method);
                     set_config('ftp_host', $ftp_host);
                     set_config('ftp_username', $ftp_username);
                     set_config('ftp_root_path', $ftp_root_path);
                     set_config('ftp_port', $ftp_port);
                     set_config('ftp_timeout', $ftp_timeout);
                     set_config('write_method', $write_method);
                     set_config('compress_method', $compress_method);
                     set_config('preview_changes', $preview_changes);
                     set_config('am_file_perms', $file_perms);
                     set_config('am_dir_perms', $dir_perms);
                     trigger_error($user->lang['MOD_CONFIG_UPDATED'] . adm_back_link($this->u_action));
                 } else {
                     $template->assign_var('ERROR', $user->lang[$error]);
                 }
             } else {
                 if (isset($_POST['submit']) && !check_form_key('acp_mods')) {
                     trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
                 }
             }
             add_form_key('acp_mods');
             // implicit else
             include "{$phpbb_root_path}includes/functions_compress.{$phpEx}";
             foreach (compress::methods() as $method) {
                 $template->assign_block_vars('compress', array('METHOD' => $method));
             }
             $requested_data = call_user_func(array($ftp_method, 'data'));
             foreach ($requested_data as $data => $default) {
                 $default = !empty($config['ftp_' . $data]) ? $config['ftp_' . $data] : $default;
                 $template->assign_block_vars('data', array('DATA' => $data, 'NAME' => $user->lang[strtoupper($ftp_method . '_' . $data)], 'EXPLAIN' => $user->lang[strtoupper($ftp_method . '_' . $data) . '_EXPLAIN'], 'DEFAULT' => !empty($_REQUEST[$data]) ? request_var($data, '') : $default));
             }
             $template->assign_vars(array('S_CONFIG' => true, 'U_CONFIG' => $this->u_action . '&mode=config', 'UPLOAD_METHOD' => $ftp_method, 'WRITE_DIRECT' => $config['write_method'] == WRITE_DIRECT ? ' checked="checked"' : '', 'WRITE_FTP' => $config['write_method'] == WRITE_FTP ? ' checked="checked"' : '', 'WRITE_MANUAL' => $config['write_method'] == WRITE_MANUAL ? ' checked="checked"' : '', 'WRITE_METHOD_DIRECT' => WRITE_DIRECT, 'WRITE_METHOD_FTP' => WRITE_FTP, 'WRITE_METHOD_MANUAL' => WRITE_MANUAL, 'COMPRESS_METHOD' => $config['compress_method'], 'DIR_PERMS' => $config['am_dir_perms'], 'FILE_PERMS' => $config['am_file_perms'], 'PREVIEW_CHANGES_YES' => $config['preview_changes'] ? ' checked="checked"' : '', 'PREVIEW_CHANGES_NO' => !$config['preview_changes'] ? ' checked="checked"' : '', 'S_HIDE_FTP' => $config['write_method'] == WRITE_FTP ? false : true));
             break;
         case 'frontend':
             if ($config['write_method'] == WRITE_FTP) {
                 $method = basename(request_var('method', ''));
                 if (!$method || !class_exists($method)) {
                     $method = 'ftp';
                     $methods = transfer::methods();
                     if (!in_array('ftp', $methods)) {
                         $method = $methods[0];
                     }
                 }
                 $test_connection = false;
                 $test_ftp_connection = request_var('test_connection', '');
                 if (!empty($test_ftp_connection) || $action == 'install') {
                     test_ftp_connection($method, $test_ftp_connection, $test_connection);
                     // Make sure the login details are correct before continuing
                     if ($test_connection !== true || !empty($test_ftp_connection)) {
                         $action = 'pre_install';
                         $test_ftp_connection = true;
                     }
                 }
             }
             switch ($action) {
                 case 'pre_install':
                     $this->pre_install($mod_path);
                     break;
                 case 'install':
                     $this->install($mod_path, $parent);
                     break;
                 case 'pre_uninstall':
                 case 'uninstall':
                     $this->uninstall($action, $mod_id);
                     break;
                 case 'details':
                     $mod_ident = $mod_id ? $mod_id : $mod_path;
                     $this->list_details($mod_ident);
                     break;
                 default:
                     $template->assign_vars(array('S_FRONTEND' => true));
                     $this->list_installed();
                     $this->list_uninstalled();
                     break;
             }
             return;
             break;
     }
 }
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $cache;
        global $phpbb_root_path, $phpEx;
        global $ftp_method, $test_ftp_connection, $test_connection, $sort_key, $sort_dir;
        include "{$phpbb_root_path}includes/functions_transfer.{$phpEx}";
        include "{$phpbb_root_path}includes/editor.{$phpEx}";
        include "{$phpbb_root_path}includes/functions_mods.{$phpEx}";
        include "{$phpbb_root_path}includes/mod_parser.{$phpEx}";
        // start the page
        $user->add_lang(array('install', 'acp/mods'));
        $this->tpl_name = 'acp_mods';
        $this->page_title = 'ACP_CAT_MODS';
        $this->store_dir = $phpbb_root_path . 'store';
        $this->mods_dir = $phpbb_root_path . 'store/mods';
        // get any url vars
        $action = request_var('action', '');
        $mod_id = request_var('mod_id', 0);
        $mod_url = request_var('mod_url', '');
        $parent = request_var('parent', 0);
        //sort keys
        $sort_key = request_var('sk', 't');
        $sort_dir = request_var('sd', 'a');
        $mod_path = request_var('mod_path', '');
        if ($mod_path) {
            $mod_path = htmlspecialchars_decode($mod_path);
            // "/my_mod/install.xml" or "/./contrib/blah.xml"
            $mod_dir = substr($mod_path, 1, strpos($mod_path, '/', 1));
            // "my_mod/"
            $this->mod_root = $this->mods_dir . '/' . $mod_dir;
            // "./../store/mods/my_mod/"
            $this->backup_root = "{$this->mod_root}_backups/";
            // "./../store/mods/my_mod/_backups/"
            $this->edited_root = "{$this->mod_root}_edited/";
            // "./../store/mods/my_mod/_edited/"
        }
        switch ($mode) {
            case 'config':
                $ftp_method = request_var('ftp_method', $config['ftp_method']);
                if (!$ftp_method || !class_exists($ftp_method)) {
                    $ftp_method = 'ftp';
                    $ftp_methods = transfer::methods();
                    if (!in_array('ftp', $ftp_methods)) {
                        $ftp_method = $ftp_methods[0];
                    }
                }
                if (isset($_POST['submit']) && check_form_key('acp_mods')) {
                    $ftp_host = request_var('host', '');
                    $ftp_username = request_var('username', '');
                    $ftp_password = request_var('password', '');
                    // not stored, used to test connection
                    $ftp_root_path = request_var('root_path', '');
                    $ftp_port = request_var('port', 21);
                    $ftp_timeout = request_var('timeout', 10);
                    $write_method = request_var('write_method', 0);
                    $file_perms = request_var('file_perms', '0644');
                    $dir_perms = request_var('dir_perms', '0755');
                    $compress_method = request_var('compress_method', '');
                    $preview_changes = request_var('preview_changes', 0);
                    $error = '';
                    if ($write_method == WRITE_DIRECT) {
                        // the very best method would be to check every file for is_writable
                        if (!is_writable("{$phpbb_root_path}common.{$phpEx}") || !is_writable("{$phpbb_root_path}adm/style/acp_groups.html")) {
                            $error = 'FILESYSTEM_NOT_WRITABLE';
                        }
                    } else {
                        if ($write_method == WRITE_FTP) {
                            // check the correctness of FTP infos
                            $test_ftp_connection = true;
                            $test_connection = false;
                            test_ftp_connection($ftp_method, $test_ftp_connection, $test_connection);
                            if ($test_connection !== true) {
                                $error = $test_connection;
                            }
                        } else {
                            if ($write_method == WRITE_MANUAL) {
                                // the compress class requires write access to the store/ dir
                                if (!is_writable($this->store_dir)) {
                                    $error = 'STORE_NOT_WRITABLE';
                                }
                            }
                        }
                    }
                    if (empty($error)) {
                        set_config('ftp_method', $ftp_method);
                        set_config('ftp_host', $ftp_host);
                        set_config('ftp_username', $ftp_username);
                        set_config('ftp_root_path', $ftp_root_path);
                        set_config('ftp_port', $ftp_port);
                        set_config('ftp_timeout', $ftp_timeout);
                        set_config('write_method', $write_method);
                        set_config('compress_method', $compress_method);
                        set_config('preview_changes', $preview_changes);
                        set_config('am_file_perms', $file_perms);
                        set_config('am_dir_perms', $dir_perms);
                        trigger_error($user->lang['MOD_CONFIG_UPDATED'] . adm_back_link($this->u_action));
                    } else {
                        $template->assign_var('ERROR', $user->lang[$error]);
                    }
                } else {
                    if (isset($_POST['submit']) && !check_form_key('acp_mods')) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
                    }
                }
                add_form_key('acp_mods');
                // implicit else
                include "{$phpbb_root_path}includes/functions_compress.{$phpEx}";
                foreach (compress::methods() as $compress_method) {
                    $template->assign_block_vars('compress', array('METHOD' => $compress_method));
                }
                $requested_data = call_user_func(array($ftp_method, 'data'));
                foreach ($requested_data as $data => $default) {
                    $default = !empty($config['ftp_' . $data]) ? $config['ftp_' . $data] : $default;
                    $template->assign_block_vars('data', array('DATA' => $data, 'NAME' => $user->lang[strtoupper($ftp_method . '_' . $data)], 'EXPLAIN' => $user->lang[strtoupper($ftp_method . '_' . $data) . '_EXPLAIN'], 'DEFAULT' => !empty($_REQUEST[$data]) ? request_var($data, '') : $default));
                }
                $template->assign_vars(array('S_CONFIG' => true, 'U_CONFIG' => $this->u_action . '&mode=config', 'UPLOAD_METHOD_FTP' => $config['ftp_method'] == 'ftp' ? ' checked="checked"' : '', 'UPLOAD_METHOD_FSOCK' => $config['ftp_method'] == 'ftp_fsock' ? ' checked="checked"' : '', 'WRITE_DIRECT' => $config['write_method'] == WRITE_DIRECT ? ' checked="checked"' : '', 'WRITE_FTP' => $config['write_method'] == WRITE_FTP ? ' checked="checked"' : '', 'WRITE_MANUAL' => $config['write_method'] == WRITE_MANUAL ? ' checked="checked"' : '', 'WRITE_METHOD_DIRECT' => WRITE_DIRECT, 'WRITE_METHOD_FTP' => WRITE_FTP, 'WRITE_METHOD_MANUAL' => WRITE_MANUAL, 'AUTOMOD_VERSION' => $config['automod_version'], 'COMPRESS_METHOD' => $config['compress_method'], 'DIR_PERMS' => $config['am_dir_perms'], 'FILE_PERMS' => $config['am_file_perms'], 'PREVIEW_CHANGES_YES' => $config['preview_changes'] ? ' checked="checked"' : '', 'PREVIEW_CHANGES_NO' => !$config['preview_changes'] ? ' checked="checked"' : '', 'S_HIDE_FTP' => $config['write_method'] == WRITE_FTP ? false : true));
                break;
            case 'frontend':
                if ($config['write_method'] == WRITE_FTP) {
                    $ftp_method = basename(request_var('method', $config['ftp_method']));
                    if (!$ftp_method || !class_exists($ftp_method)) {
                        $ftp_method = 'ftp';
                        $ftp_methods = transfer::methods();
                        if (!in_array('ftp', $ftp_methods)) {
                            $ftp_method = $ftp_methods[0];
                        }
                    }
                    $test_connection = false;
                    $test_ftp_connection = request_var('test_connection', '');
                    if (!empty($test_ftp_connection) || in_array($action, array('install', 'uninstall', 'upload_mod', 'delete_mod'))) {
                        test_ftp_connection($ftp_method, $test_ftp_connection, $test_connection);
                        // Make sure the login details are correct before continuing
                        if ($test_connection !== true || !empty($test_ftp_connection)) {
                            $action = 'pre_' . $action;
                        }
                    }
                }
                // store/ needs to be world-writable even when FTP is the write method,
                // for extracting uploaded mod zip files
                if (!is_writable($this->store_dir)) {
                    $template->assign_var('S_STORE_WRITABLE_WARN', true);
                } else {
                    if ($config['write_method'] != WRITE_FTP && !is_writable($this->mods_dir)) {
                        $template->assign_var('S_MODS_WRITABLE_WARN', true);
                    }
                }
                switch ($action) {
                    case 'pre_install':
                    case 'install':
                        $this->install($action, $mod_path, $parent);
                        break;
                    case 'pre_uninstall':
                    case 'uninstall':
                        $this->uninstall($action, $mod_id, $parent);
                        break;
                    case 'details':
                        $mod_ident = $mod_id ? $mod_id : $mod_path;
                        $this->list_details($mod_ident);
                        break;
                    case 'pre_delete_mod':
                    case 'delete_mod':
                        $this->delete_mod($action, $mod_path);
                        break;
                    case 'pre_upload_mod':
                    case 'upload_mod':
                    default:
                        $action = isset($action) ? $action : '';
                        if (!$this->upload_mod($action)) {
                            $this->list_installed();
                            $this->list_uninstalled();
                        }
                        break;
                    case 'download':
                        include $phpbb_root_path . "includes/functions_compress.{$phpEx}";
                        $editor = new editor_manual();
                        $time = request_var('time', 0);
                        // if for some reason the MOD isn't found in the DB...
                        $download_name = 'mod_' . $time;
                        $sql = 'SELECT mod_name FROM ' . MODS_TABLE . '
							WHERE mod_time = ' . $time;
                        $result = $db->sql_query($sql);
                        if ($row = $db->sql_fetchrow($result)) {
                            // Always use the English name except for showing the user.
                            $mod_name = localize_title($row['mod_name'], 'en');
                            $download_name = str_replace(' ', '_', $mod_name);
                        }
                        $editor->compress->download("{$this->store_dir}/mod_{$time}", $download_name);
                        exit;
                        break;
                }
                return;
                break;
        }
    }