/** * 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; }
$a = 0; if (!empty($list_files)) { foreach ($list_files as $filename) { if (in_array($filename['name'], $check_files)) { ++$a; } } } if ($a == sizeof($check_files)) { $array_config['ftp_check_login'] = 1; } else { $array_config['ftp_check_login'] = 2; $error = $lang_global['ftp_error_path']; } } $ftp->close(); } foreach ($array_config as $config_name => $config_value) { $db->sql_query("UPDATE `" . NV_CONFIG_GLOBALTABLE . "` \n\t\t\tSET `config_value`=" . $db->dbescape_string($config_value) . " \n\t\t\tWHERE `config_name` = " . $db->dbescape_string($config_name) . " \n\t\t\tAND `lang` = 'sys' AND `module`='global' \n\t\t\tLIMIT 1"); } nv_save_file_config_global(); if (empty($error)) { Header('Location: ' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $op . '&rand=' . nv_genpass()); exit; } } $xtpl->assign('VALUE', $array_config); $xtpl->assign('DETECT_FTP', NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $op); if (!empty($error)) { $xtpl->assign('ERROR', $error); $xtpl->parse('main.error');
/** * 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)); } }