Exemplo n.º 1
0
function get_ftp_config($action, $post = array(), $allow_local = false, $show_error = '')
{
    global $template, $board_config, $db, $lang, $HTTP_POST_VARS, $HTTP_SERVER_VARS;
    $board_config['xs_ftp_local'] = false;
    // check if ftp can be used
    if (!@function_exists('ftp_connect')) {
        if ($allow_local && xs_dir_writable('../templates/')) {
            $board_config['xs_ftp_local'] = true;
            return true;
        }
        xs_error($lang['xs_ftp_error_fatal']);
    }
    // check if we have configuration
    if (!empty($HTTP_POST_VARS['get_ftp_config'])) {
        $vars = array('xs_ftp_host', 'xs_ftp_login', 'xs_ftp_path');
        for ($i = 0; $i < count($vars); $i++) {
            $var = $vars[$i];
            if ($board_config[$var] !== $HTTP_POST_VARS[$var]) {
                $board_config[$var] = stripslashes($HTTP_POST_VARS[$var]);
                $sql = "UPDATE " . CONFIG_TABLE . " SET config_value = '" . xs_sql($board_config[$var]) . "' WHERE config_name = '{$var}'";
                $db->sql_query($sql);
            }
        }
        $board_config['xs_ftp_pass'] = stripslashes($HTTP_POST_VARS['xs_ftp_pass']);
        $board_config['xs_ftp_local'] = empty($HTTP_POST_VARS['xs_ftp_local']) ? false : true;
        // recache config table
        if (defined('XS_MODS_CATEGORY_HIERARCHY210')) {
            global $config;
            if (!empty($config)) {
                $config->read(true);
            }
        }
        return true;
    }
    // check ftp configuration
    $xs_ftp_host = $board_config['xs_ftp_host'];
    if (empty($xs_ftp_host)) {
        $str = $HTTP_SERVER_VARS['HTTP_HOST'];
        $template->assign_vars(array('HOST_GUESS' => str_replace(array('{HOST}', '{CLICK}'), array($str, 'document.ftp.xs_ftp_host.value=\'' . $str . '\''), $lang['xs_ftp_host_guess'])));
    }
    $dir = getcwd();
    $xs_ftp_login = $board_config['xs_ftp_login'];
    if (empty($xs_ftp_login)) {
        if (substr($dir, 0, 6) === '/home/') {
            $str = substr($dir, 6);
            $pos = strpos($str, '/');
            if ($pos) {
                $str = substr($str, 0, $pos);
                $template->assign_vars(array('LOGIN_GUESS' => str_replace(array('{LOGIN}', '{CLICK}'), array($str, 'document.ftp.xs_ftp_login.value=\'' . $str . '\''), $lang['xs_ftp_login_guess'])));
            }
        }
    }
    $xs_ftp_path = $board_config['xs_ftp_path'];
    if (empty($xs_ftp_path)) {
        if (substr($dir, 0, 6) === '/home/') {
        }
        $str = substr($dir, 6);
        $pos = strpos($str, '/');
        if ($pos) {
            $str = substr($str, $pos + 1);
            $pos = strrpos($str, 'admin');
            if ($pos) {
                $str = substr($str, 0, $pos - 1);
                $template->assign_vars(array('PATH_GUESS' => str_replace(array('{PATH}', '{CLICK}'), array($str, 'document.ftp.xs_ftp_path.value=\'' . $str . '\''), $lang['xs_ftp_path_guess'])));
            }
        }
    }
    if ($allow_local && xs_dir_writable('../templates/')) {
        $template->assign_block_vars('xs_ftp_local', array());
    } else {
        $template->assign_block_vars('xs_ftp_nolocal', array());
    }
    $str = '<input type="hidden" name="get_ftp_config" value="1" />';
    foreach ($post as $var => $value) {
        $str .= '<input type="hidden" name="' . htmlspecialchars($var) . '" value="' . htmlspecialchars($value) . '" />';
    }
    $template->assign_vars(array('FORM_ACTION' => $action, 'S_EXTRA_FIELDS' => $str, 'XS_FTP_HOST' => $xs_ftp_host, 'XS_FTP_LOGIN' => $xs_ftp_login, 'XS_FTP_PATH' => $xs_ftp_path));
    if ($show_error) {
        $template->assign_block_vars('error', array('MSG' => $show_error));
    }
    $template->set_filenames(array('config' => XS_TPL_PATH . 'ftp.tpl'));
    $template->pparse('config');
    return false;
}
Exemplo n.º 2
0
$template->assign_block_vars('nav_left', array('ITEM' => '&raquo; <a href="' . append_sid('xs_config.' . $phpEx) . '">' . $lang['xs_configuration'] . '</a>'));
$template->assign_block_vars('nav_left', array('ITEM' => '&raquo; <a href="' . append_sid('xs_chmod.' . $phpEx) . '">' . $lang['xs_chmod'] . '</a>'));
$lang['xs_chmod_return'] = str_replace('{URL}', append_sid('xs_config.' . $phpEx), $lang['xs_chmod_return']);
$lang['xs_chmod_message1'] .= $lang['xs_chmod_return'];
$lang['xs_chmod_error1'] .= $lang['xs_chmod_return'];
if (defined('DEMO_MODE')) {
    xs_error($lang['xs_permission_denied']);
}
if (!get_ftp_config(append_sid('xs_chmod.' . $phpEx), array(), false)) {
    exit;
}
xs_ftp_connect(append_sid('xs_chmod.' . $phpEx), array(), true);
if ($ftp === XS_FTP_LOCAL) {
    @mkdir('../cache', 0777);
    @chmod('../cache', 0777);
    if (xs_dir_writable('../cache')) {
        xs_message($lang['Information'], $lang['xs_chmod_message1']);
    }
    xs_error($lang['xs_chmod_error1']);
}
$str = ftp_pwd($ftp);
if (strlen($str) && substr($str, strlen($str) - 1) !== '/') {
    $str .= '/';
}
$res = @ftp_site($ftp, "CHMOD 0777 {$str}cache");
if (!$res) {
    @ftp_mkdir($ftp, 'cache');
    $res = @ftp_site($ftp, "CHMOD 0777 {$str}cache");
}
@ftp_quit($ftp);
if ($res) {