Example #1
0
     }
     $ftp->close();
     die('ERROR|' . $lang_module['ftp_error_detect_root']);
 }
 if ($nv_Request->isset_request('ftp_server', 'post')) {
     $array_config['ftp_check_login'] = 0;
     if (!empty($array_config['ftp_server']) and !empty($array_config['ftp_user_name']) and !empty($array_config['ftp_user_pass'])) {
         $ftp_server = nv_unhtmlspecialchars($array_config['ftp_server']);
         $ftp_port = intval($array_config['ftp_port']);
         $ftp_user_name = nv_unhtmlspecialchars($array_config['ftp_user_name']);
         $ftp_user_pass = nv_unhtmlspecialchars($array_config['ftp_user_pass']);
         $ftp_path = nv_unhtmlspecialchars($array_config['ftp_path']);
         if (!defined('NV_FTP_CLASS')) {
             require NV_ROOTDIR . '/includes/class/ftp.class.php';
         }
         $ftp = new NVftp($ftp_server, $ftp_user_name, $ftp_user_pass, array('timeout' => 10), $ftp_port);
         if (!empty($ftp->error)) {
             $array_config['ftp_check_login'] = 3;
             $error = (string) $ftp->error;
         } elseif ($ftp->chdir($ftp_path) === false) {
             $array_config['ftp_check_login'] = 2;
             $error = $lang_global['ftp_error_path'];
         } else {
             $check_files = array(NV_CACHEDIR, NV_DATADIR, "images", "includes", "index.php", "js", "language", NV_LOGS_DIR, "mainfile.php", "modules", NV_SESSION_SAVE_PATH, "themes", NV_TEMP_DIR, NV_UPLOADS_DIR);
             $list_files = $ftp->listDetail($ftp_path, 'all');
             $a = 0;
             if (!empty($list_files)) {
                 foreach ($list_files as $filename) {
                     if (in_array($filename['name'], $check_files)) {
                         ++$a;
                     }
/**
 * nv_deletefile()
 *
 * @param mixed $file
 * @param bool $delsub
 * @return
 */
function nv_deletefile($file, $delsub = false)
{
    global $lang_global, $sys_info, $global_config;
    // Kiem tra ten file
    $realpath = realpath($file);
    if (empty($realpath)) {
        return array(0, sprintf($lang_global['error_non_existent_file'], $file));
    }
    $realpath = str_replace('\\', '/', $realpath);
    $realpath = rtrim($realpath, '\\/');
    $preg_match = preg_match('/^(' . nv_preg_quote(NV_ROOTDIR) . ')(\\/[\\S]+)/', $realpath, $path);
    if (empty($preg_match)) {
        return array(0, sprintf($lang_global['error_delete_forbidden'], $file));
    }
    $ftp_check_login = 0;
    if ($sys_info['ftp_support'] and intval($global_config['ftp_check_login']) == 1) {
        $ftp_server = nv_unhtmlspecialchars($global_config['ftp_server']);
        $ftp_port = intval($global_config['ftp_port']);
        $ftp_user_name = nv_unhtmlspecialchars($global_config['ftp_user_name']);
        $ftp_user_pass = nv_unhtmlspecialchars($global_config['ftp_user_pass']);
        $ftp_path = nv_unhtmlspecialchars($global_config['ftp_path']);
        // Goi file Class xu ly
        if (!defined('NV_FTP_CLASS')) {
            require NV_ROOTDIR . '/includes/class/ftp.class.php';
        }
        // Ket noi, dang nhap
        $ftp = new NVftp($ftp_server, $ftp_user_name, $ftp_user_pass, array('timeout' => 10), $ftp_port);
        // Chuyen thu muc
        if ($ftp->chdir($ftp_path) === true) {
            $ftp_check_login = 1;
        } else {
            $ftp->close();
        }
    }
    $filename = str_replace(NV_ROOTDIR . '/', '', str_replace('\\', '/', $realpath));
    // Tinh chinh lai file cho phu hop voi chdir
    if ($ftp_check_login == 1) {
        if (is_dir($realpath)) {
            $check = nv_ftp_del_dir($ftp, $filename, $delsub);
            if ($check !== true) {
                return array(0, $check);
            }
        } elseif ($ftp->unlink($realpath) === false) {
            @unlink($realpath);
        }
        $ftp->close();
    } elseif (is_dir($realpath)) {
        $files = scandir($realpath);
        $files2 = array_diff($files, array('.', '..', '.htaccess', 'index.html'));
        if (sizeof($files2) and !$delsub) {
            return array(0, sprintf($lang_global['error_delete_subdirectories_not_empty'], $path[2]));
        } else {
            $files = array_diff($files, array('.', '..'));
            if (sizeof($files)) {
                foreach ($files as $f) {
                    $unlink = nv_deletefile($realpath . '/' . $f, true);
                    if (empty($unlink[0])) {
                        $filename = str_replace(NV_ROOTDIR, '', str_replace('\\', '/', $realpath . '/' . $f));
                        return array(0, sprintf($lang_global['error_delete_failed'], $filename));
                    }
                }
            }
            if (!@rmdir($realpath)) {
                return array(0, sprintf($lang_global['error_delete_subdirectories_failed'], $path[2]));
            } else {
                return array(1, sprintf($lang_global['directory_deleted'], $path[2]));
            }
        }
    } else {
        @unlink($realpath);
    }
    if (file_exists($realpath)) {
        return array(0, sprintf($lang_global['error_delete_failed'], $filename));
    } else {
        return array(1, sprintf($lang_global['file_deleted'], $filename));
    }
}
Example #3
0
 /**
  * NvUpdate::move_file()
  *
  * @param mixed $nv_update_config
  * @param mixed $files
  * @return
  */
 public function move_file($nv_update_config, $files)
 {
     if (empty($files)) {
         return true;
     }
     global $global_config;
     $is_ftp = false;
     if ($global_config['ftp_check_login'] == 1) {
         $ftp_server = nv_unhtmlspecialchars($global_config['ftp_server']);
         $ftp_port = intval($global_config['ftp_port']);
         $ftp_user_name = nv_unhtmlspecialchars($global_config['ftp_user_name']);
         $ftp_user_pass = nv_unhtmlspecialchars($global_config['ftp_user_pass']);
         $ftp_path = nv_unhtmlspecialchars($global_config['ftp_path']);
         $ftp = new NVftp($ftp_server, $ftp_user_name, $ftp_user_pass, array('timeout' => 20), $ftp_port);
         if (empty($ftp->error) and $ftp->chdir($ftp_path)) {
             $is_ftp = true;
         }
     }
     // Nhat ki
     $logs_message = array();
     $logs_status = array();
     // Bat dau tao thu muc
     foreach ($files as $file_i) {
         $cp = '';
         $e = explode('/', $file_i);
         foreach ($e as $p) {
             if (!empty($p) and is_dir(NV_ROOTDIR . '/install/update/' . $cp . $p) and !is_dir(NV_ROOTDIR . '/' . $cp . $p)) {
                 // Neu khong tao thu muc theo cach thong thuong thi tao bang FTP (neu co)
                 if (@mkdir(NV_ROOTDIR . '/' . $cp . $p) == false and $is_ftp === true) {
                     $ftp->mkdir($cp . $p);
                 }
                 if (!is_dir(NV_ROOTDIR . '/' . $cp . $p)) {
                     // Nhat ki that bai
                     $logs_message[] = $this->lang['update_log_creat_dir'] . ' ' . $cp . $p;
                     $logs_status[] = false;
                     // Luu nhat ki
                     $this->log($nv_update_config, $logs_message, $logs_status);
                     if ($is_ftp === true) {
                         $ftp->close();
                     }
                     return $this->lang['update_error_creat_dir'] . ' ' . $cp . $p;
                 }
                 // Nhat ki thanh cong
                 $logs_message[] = $this->lang['update_log_creat_dir'] . ' ' . $cp . $p;
                 $logs_status[] = true;
             }
             $cp .= $p . '/';
         }
     }
     // Di chuyen cac file
     foreach ($files as $file_i) {
         if (is_file(NV_ROOTDIR . '/install/update/' . $file_i)) {
             // Neu ton tai thi xoa truoc
             if (file_exists(NV_ROOTDIR . '/' . $file_i)) {
                 if (@unlink(NV_ROOTDIR . '/' . $file_i) == false and $is_ftp === true) {
                     // Dung ftp de xoa
                     $ftp->unlink($file_i);
                 }
             }
             // Di chuyen bang cach doi ten duong dan
             if (@rename(NV_ROOTDIR . '/install/update/' . $file_i, NV_ROOTDIR . '/' . $file_i) == false and $is_ftp === true) {
                 // Dung ftp di chuyen
                 $ftp->rename('install/update/' . $file_i, $file_i);
             }
             if (file_exists(NV_ROOTDIR . '/install/update/' . $file_i)) {
                 // Nhat ki that bai
                 $logs_message[] = $this->lang['update_log_move_file'] . ' ' . $file_i;
                 $logs_status[] = false;
                 // Luu nhat ki
                 $this->log($nv_update_config, $logs_message, $logs_status);
                 if ($is_ftp === true) {
                     $ftp->close();
                 }
                 return $this->lang['update_error_move_file'] . ' ' . $file_i;
             }
             // Nhat ki thanh cong
             $logs_message[] = $this->lang['update_log_move_file'] . ' ' . $file_i;
             $logs_status[] = true;
         }
     }
     // Luu nhat ki
     $this->log($nv_update_config, $logs_message, $logs_status);
     return true;
 }
Example #4
0
    if ($step < 2) {
        $nv_Request->set_Session('maxstep', 2);
    }
    $title = $lang_module['select_language'];
    $contents = nv_step_1();
} elseif ($step == 2) {
    // Tu dong nhan dang Remove Path
    if ($nv_Request->isset_request('tetectftp', 'post')) {
        $ftp_server = nv_unhtmlspecialchars($nv_Request->get_title('ftp_server', 'post', '', 1));
        $ftp_port = intval($nv_Request->get_title('ftp_port', 'post', '21', 1));
        $ftp_user_name = nv_unhtmlspecialchars($nv_Request->get_title('ftp_user_name', 'post', '', 1));
        $ftp_user_pass = nv_unhtmlspecialchars($nv_Request->get_title('ftp_user_pass', 'post', '', 1));
        if (!$ftp_server or !$ftp_user_name or !$ftp_user_pass) {
            die('ERROR|' . $lang_module['ftp_error_empty']);
        }
        $ftp = new NVftp($ftp_server, $ftp_user_name, $ftp_user_pass, array('timeout' => 10), $ftp_port);
        if (!empty($ftp->error)) {
            $ftp->close();
            die('ERROR|' . (string) $ftp->error);
        } else {
            $list_valid = array(NV_CACHEDIR, NV_DATADIR, 'images', 'includes', 'js', 'language', NV_LOGS_DIR, 'modules', 'themes', NV_TEMP_DIR, NV_UPLOADS_DIR);
            $ftp_root = $ftp->detectFtpRoot($list_valid, NV_ROOTDIR);
            if ($ftp_root === false) {
                $ftp->close();
                die('ERROR|' . (empty($ftp->error) ? $lang_module['ftp_error_detect_root'] : (string) $ftp->error));
            }
            $ftp->close();
            die('OK|' . $ftp_root);
        }
        $ftp->close();
        die('ERROR|' . $lang_module['ftp_error_detect_root']);