Viewing file: updateversion_old.php (18.74 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php include_once('ver_controller.php'); class Updateversion extends Ver_controller { function config_server () { $this->load->model($this->config->item("ver_folder").'m_ver_config','cfg'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); $this->form_validation->set_rules('server_name', ' ', 'trim|required|xss_clean'); if($this->form_validation->run() == TRUE) { if($this->input->server('REQUEST_METHOD') == TRUE) { $this->db->trans_begin(); $this->cfg->cfg_id = 1; $this->cfg->get_by_key(TRUE); $this->cfg->cfg_server_version = 'http://'.$this->input->post('server_name'); $this->cfg->update(); if($this->db->trans_status() == FALSE) { $this->db->trans_rollback(); } else { $this->db->trans_commit(); $this->data['success'] = 1; $this->data['new_name'] = $this->input->post('server_name'); } } redirect($this->config->item('ver_folder').'updateversion/config_server'); } else { $qu_cfg = $this->cfg->get_all()->row(); $this->data['server_name'] = $qu_cfg->cfg_server_version; $this->ver_view = $this->load->view($this->config->item("ver_folder").'v_config_server',$this->data); $this->ver_popup(); } } function chk_update () { $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); $this->form_validation->set_rules('system_select', ' ', 'callback_checkselect'); $this->form_validation->set_rules('ag_path', ' ', 'trim|required|xss_clean'); if($this->form_validation->run() == TRUE) { $flag = ''; $ag_path = $this->input->post('ag_path'); $sys_id = $this->input->post('system_select'); $this->load->model($this->config->item("ver_folder").'m_ver_config','cfg'); $this->cfg->update_ag_path($ag_path, 1); $this->load->model($this->config->item("ver_folder").'m_ver_package','pkg'); $last_pkg = $this->pkg->get_lastpkg($sys_id); $ag_cfg = $this->cfg->get_all(); $ag_id = $ag_cfg->row()->cfg_ag_id; $ag_path = $ag_cfg->row()->cfg_ag_path; if(!file_exists($ag_path)){ $flag = 2; } else { if(!is_writable($ag_path)) { $flag = 1; } else { $request = "ag_id=".$ag_id."&sys_id=".$sys_id."&last_pkg=".$last_pkg->row()->pkg_id; $url = $ag_cfg->row()->cfg_server_version.'chk_update'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_HEADER, true); // Display headers //curl_setopt($ch, CURLOPT_VERBOSE, true); $response = curl_exec($ch); curl_close($ch); $flag = 0; $this->data['pkg_upd'] = simplexml_load_string($response); } } $qu_cfg = $this->cfg->get_all()->row(); $this->data['server_name'] = $qu_cfg->cfg_server_version;
$this->data['ag_path'] = $qu_cfg->cfg_ag_path; $this->load->model($this->config->item("ver_folder").'m_ver_client_system','cls'); $this->cls->csys_id = $sys_id; $this->data['qu_sys'] = $this->cls->get_by_key(); $this->data['system'] = $this->cls->get_options(); $this->data['flag'] = $flag; $this->ver_view = $this->load->view($this->config->item("ver_folder").'v_download_pkg',$this->data,TRUE); $this->ver_out(); } else { $this->select_sys_update(); $this->load->model($this->config->item("ver_folder").'m_ver_config','cfg'); $qu_cfg = $this->cfg->get_all(); $this->load->model($this->config->item("ver_folder").'m_ver_client_system','cls'); $this->data['server_name'] = $qu_cfg->row()->cfg_server_version; $this->data['system'] = $this->cls->get_options(); $this->data['flag'] = 0; $this->ver_view = $this->load->view($this->config->item("ver_folder").'v_download_pkg',$this->data,TRUE); $this->ver_out(); } } function select_sys_update(){ $this->load->model($this->ver_path.'m_ver_client_system','mcs'); $this->load->model($this->ver_path.'m_ver_config','mcf'); $qu_cf = $this->mcf->get_all()->row(); $server_url = $qu_cf->cfg_server_name; $this->load->library('xmlrpc'); //$this->xmlrpc->set_debug(TRUE); $this->xmlrpc->server($server_url,80); $this->xmlrpc->method('get_sys_list'); $arr = array($qu_cf->cfg_ag_id); $request = array($arr); $this->xmlrpc->request($request); if(!$this->xmlrpc->send_request()) { echo $this->xmlrpc->display_error(); redirect($this->config->item("ver_folder").'ver_client/update_server'); } else { $res = $this->xmlrpc->display_response(); $len = count($res); $res; for( $i=0; $i<$len; $i++) { $this->mcs->csys_id = $res[$i][0]; $qu = $this->mcs->get_by_key(); $num = $qu->num_rows(); if($num > 0) $this->mcs->get_by_key(TRUE); $this->mcs->csys_en_name = $res[$i][1]; $this->mcs->csys_th_name = $res[$i][2]; ($num > 0 )?$this->mcs->update():$this->mcs->insert(); } } } function download_pkg (){ if($this->input->post() != "") { $this->load->model($this->config->item("ver_folder").'m_ver_package','pkg'); $this->load->model($this->config->item("ver_folder").'m_ver_config','cfg'); $pkg_id = $this->input->post('pkg_id'); $sys_id = $this->input->post('sys_id'); $ag_cfg = $this->cfg->get_all(); $ag_id = $ag_cfg->row()->cfg_ag_id; $last_pkg_id = $this->pkg->get_lastpkg($sys_id); // start request pkg $url = $ag_cfg->row()->cfg_server_version.'download_pkg'; $request_pkg = "ag_id=".$ag_id."&pkg_id=".$pkg_id."&last_pkg_id=".$last_pkg_id->row()->pkg_id."&sys_id=".$sys_id; //echo $request_pkg;die; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request_pkg); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_HEADER, 1); // Display headers // curl_setopt($ch, CURLOPT_VERBOSE, 1);
$response_pkg = curl_exec($ch); curl_close($ch); // end request pkg
/*if($response_pkg == ''){ echo "NO"; }*/ //////// CREATE FILE //////// //echo $response_pkg."<br />"; //$obj = json_decode($response_pkg); //echo $obj; //die; $arr = unserialize($response_pkg); //echo "aa".$arr; //var_dump($arr); $flag = ''; foreach($arr as $index => $row){ $pkg_id = $row['pkg_id']; $pkg_sys_id = $row['pkg_sys_id']; $pkg_upload_date = $row['pkg_upload_date']; $pkg_version = $row['pkg_version']; $pkg_name = $row['pkg_name']; $pkg_text_en = $row['pkg_text_en']; $pkg_detail = $row['pkg_detail']; $pkg_by = $row['pkg_by']; if(isset($row['readfile'])){ $contents = base64_decode($row['readfile']); } $path = "uploads/temp/"; $filename = $path.$pkg_name; if(isset($row['readfile'])){ $handle = fopen($filename,'w'); fwrite($handle, $contents); fclose($handle); $checksum_newfile = sha1_file($filename); if($checksum_newfile == $row['pkg_text_en']){ $this->pkg->pkg_id = $pkg_id; $this->pkg->pkg_sys_id = $pkg_sys_id; $this->pkg->pkg_upload_date = $pkg_upload_date; $this->pkg->pkg_download_date = date('Y-m-d'); $this->pkg->pkg_update_date = ''; $this->pkg->pkg_version = $pkg_version; $this->pkg->pkg_name = $pkg_name; $this->pkg->pkg_text_en = $pkg_text_en; $this->pkg->pkg_detail = $pkg_detail; $this->pkg->pkg_by = $pkg_by; $this->pkg->pkg_download_status = '2'; //ดาวน์โหลดแพ็คเกจสำเร็จ $this->pkg->pkg_update_status = 'N'; //รอปรับปรุงระบบ $this->pkg->insert(); $url_file = $ag_cfg->row()->cfg_server_version.'download_file'; $request_file = "ag_id=".$ag_id."&pkg_id=".$pkg_id; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url_file); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request_file); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_HEADER, 1); // Display headers // curl_setopt($ch, CURLOPT_VERBOSE, 1); $response_file = curl_exec($ch); curl_close($ch); //var_dump(simplexml_load_string($response_file)); $this->load->model($this->config->item("ver_folder").'m_ver_file','file'); foreach(simplexml_load_string($response_file) as $row) { $this->file->file_id = ''.$row->file_id; $this->file->file_pkg_id = ''.$row->file_pkg_id; $this->file->file_org_name = ''.$row->file_org_name; $this->file->file_name = ''.$row->file_name; $this->file->file_size = ''.$row->file_size; $this->file->file_path = ''.$row->file_path; $this->file->file_update_status = 'N'; //รอปรับปรุงไฟล์ $this->file->insert(); } $flag = 1; } else { unlink($filename); $flag = 0; } }else{ $this->pkg->pkg_id = $pkg_id; $this->pkg->pkg_sys_id = $pkg_sys_id; $this->pkg->pkg_upload_date = $pkg_upload_date; $this->pkg->pkg_download_date = date('Y-m-d'); $this->pkg->pkg_update_date = ''; $this->pkg->pkg_version = $pkg_version; $this->pkg->pkg_name = $pkg_name; $this->pkg->pkg_text_en = $pkg_text_en; $this->pkg->pkg_detail = $pkg_detail; $this->pkg->pkg_by = $pkg_by; $this->pkg->pkg_download_status = '2'; //ดาวน์โหลดแพ็คเกจสำเร็จ $this->pkg->pkg_update_status = 'N'; //รอปรับปรุงระบบ $this->pkg->insert(); $url_file = $ag_cfg->row()->cfg_server_version.'download_file'; $request_file = "ag_id=".$ag_id."&pkg_id=".$pkg_id; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url_file); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request_file); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_HEADER, 1); // Display headers // curl_setopt($ch, CURLOPT_VERBOSE, 1); $response_file = curl_exec($ch); curl_close($ch); $this->load->model($this->config->item("ver_folder").'m_ver_file','file'); foreach(simplexml_load_string($response_file) as $row) { $this->file->file_id = ''.$row->file_id; $this->file->file_pkg_id = ''.$row->file_pkg_id; $this->file->file_org_name = ''.$row->file_org_name; $this->file->file_name = ''.$row->file_name; $this->file->file_size = ''.$row->file_size; $this->file->file_path = ''.$row->file_path; $this->file->file_update_status = 'D'; //รอปรับปรุงไฟล์ $this->file->insert(); } $flag = 1; } } $this->confirm_update($flag); } else { $this->confirm_update(1); } } function chk_path () { if($this->input->post() != "") { $go_path = array(); $num = 0; $this->load->model($this->config->item("ver_folder").'m_ver_package','pkg'); $this->load->model($this->config->item("ver_folder").'m_ver_config','cfg'); $this->load->model($this->config->item("ver_folder").'m_ver_file','file'); $ag_cfg = $this->cfg->get_all(); $ag_path = $ag_cfg->row()->cfg_ag_path; $root_path = getcwd(); chdir($ag_path);
$flag = ''; if(!file_exists($ag_path)){ $flag = 2; $this->data['ag_path'] = $ag_path; } else if(!is_writable($ag_path)){ $flag = 3; //echo $ag_path." no";die; $this->data['user_group'] = $this->chk_config(); } else { $list_path1 = $this->input->post('path'); //print_r($list_path1);die; foreach($list_path1 as $key => $value1){ chdir('/'); //echo getcwd() . "<br />"; //echo "pwd = ".getcwd()."<br>"; //echo $value1."<br>"; $_flag = 0; //$path2 = end(explode($ag_path, $value1)); //$path2 = end(explode('/', $path2)); //echo "path2 = ".$path2."<br>"; if(!file_exists($value1)){ //echo "ไม่มี<br>"; //echo $value1."<br>"; $t_path2 = end(explode($ag_path, $value1)); $list_path2 = explode('/', $t_path2); chdir($ag_path); foreach($list_path2 as $i => $value){ if($i==0)continue; //echo "folder = ".$value."<br>"; if ($value != "") { if ($handle = opendir(getcwd())) { while (false !== ($file = readdir($handle))) { if ($file == $value) { if(is_writable($value)) { //echo "found = ".getcwd()."/".$value."<br>"; $checkfound = 1; break; } else { //echo "not write<br>"; $checkfound = 1; $_flag = 1; break; } } else { //echo "not found = ".getcwd()."/".$value."<br>"; $checkfound = 0; $newfolder = $value; } } //echo "checkfound = ".$checkfound."<br>"; //echo "_flag = ".$_flag."<br>"; if ($_flag == 1) { //echo "_flag1";die; $_flag = 2; break; } if ($checkfound == 0) { $mk_path = getcwd()."/".$newfolder; //echo "mkdir = ".$mk_path."<br>"; mkdir($mk_path, 0755); chmod($mk_path, 0755); $checkfound = 1; } closedir($handle); } chdir($value); //echo getcwd()."<br>"; } else { break; } } } if($_flag == 2){ $flag = 3; //$this->data['user_group'] = $this->chk_config(); break; } else //echo "111<br>"; //echo $value1."<br>"; chdir('/'); $path2 = end(explode($ag_path, $value1)); //echo "pwd2 = ".getcwd()."<br>"; //echo $ag_path.'/'.$path2."<br>"; if(!is_writable($ag_path.'/'.$path2)){ //echo $path2." no <br>"; $flag = 3; break; } else { //echo $path2." yes <br>"; $flag = 4; continue; } } } //die; chdir($root_path); $this->confirm_update($flag); } else { $this->confirm_update(1); } } function confirm_update($flag) { $this->load->model($this->config->item("ver_folder").'m_ver_file','file'); $this->load->model($this->config->item("ver_folder").'m_ver_config','cfg'); $qu_cfg = $this->cfg->get_all(); $file_download = $this->file->get_filedownload(); $this->data['flag'] = $flag; $this->data['file_download'] = $file_download; $this->data['ag_path'] = $qu_cfg->row()->cfg_ag_path; $this->ver_view = $this->load->view($this->config->item("ver_folder").'v_confirm_update',$this->data,TRUE); $this->ver_out(); } function install_pkg() { $arr = array(); $pkg_id = $this->input->post('pkg_id'); $dup_pkg_id = array_unique($pkg_id); $index = 0; $this->load->model($this->config->item("ver_folder").'m_ver_file','file'); $this->load->model($this->config->item("ver_folder").'m_ver_config','cfg'); $qu_cfg = $this->cfg->get_all(); $ag_path = $qu_cfg->row()->cfg_ag_path; $key = 0; foreach($dup_pkg_id as $index => $row_pkg) { $ver_path = getcwd(); $up_path = "uploads/temp/"; $file_detail = $this->file->get_byPkgId($row_pkg); $ext = $this->get_extension($file_detail->row()->file_name); if($file_detail->row()->file_update_status!="D"){ if($ext == '.gz'){ exec('cd '.$up_path.';mkdir '.$row_pkg.';cd '.$row_pkg.';tar -xvf ../'.$file_detail->row()->file_name); } else { exec('cd '.$up_path.';tar -xzf '.$row_pkg.'.tar.gz',$output); } } foreach($file_detail->result() as $row_file){ $file_path = $row_file->file_path; $rest = substr($file_path, 1); if($file_detail->row()->file_update_status!="D"){ if($ext == '.gz'){ $from_path = $ver_path.'/'.$up_path.$row_pkg.'/*'; $to_path = $ag_path.'/'.$rest.'/'; exec('mv '.$from_path.' '.$to_path); //move to -> } else { $from_path = $ver_path.'/'.$up_path.$row_file->file_name; $to_path = $ag_path.'/'.$rest.'/'.$row_file->file_org_name; exec('mv '.$from_path.' '.$to_path); //move to -> } }else if($file_detail->row()->file_update_status=="D"){ $to_path = $ag_path.'/'.$rest.'/'.$row_file->file_org_name; exec('rm '.$to_path); //remove to -> } if($file_detail->row()->file_update_status!="D"){ if(!file_exists($to_path)){ $file_update_status = 'N'; //ปรับปรุงไฟล์สำเร็จ $this->file->update_upd_status($file_update_status, $row_file->file_pkg_id); } else { $file_update_status = 'Y'; //ปรับปรุงไฟล์สำเร็จ $this->file->update_upd_status($file_update_status, $row_file->file_pkg_id); } }else{ if(!file_exists($to_path)){ $file_update_status = 'Y'; //ปรับปรุงไฟล์สำเร็จ $this->file->update_upd_status($file_update_status, $row_file->file_pkg_id); } } } $file_update = $this->file->get_filebyPkgIdJoin($row_pkg); if($file_update->row()->file_update_status == 'Y'){ $this->load->model($this->config->item("ver_folder").'m_ver_package','pkg'); $pkg_update_date = date('Y-m-d'); $pkg_update_status = 'Y'; //ปรับปรุงแพ็คเกจสำเร็จ $this->pkg->update_upd_status($pkg_update_date, $pkg_update_status, $row_file->file_pkg_id); $this->load->model($this->config->item("ver_folder").'m_ver_config','cfg'); $ag_cfg = $this->cfg->get_all(); $ag_id = $ag_cfg->row()->cfg_ag_id; $url_upd = $ag_cfg->row()->cfg_server_version.'update_status'; $request = "ag_id=".$ag_id."&pkg_id=".$row_pkg; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url_upd); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); curl_close($ch); } foreach($file_update->result() as $row){ $arr[$key]['pkg_version'] = $row->pkg_version; $arr[$key]['csys_th_name'] = $row->csys_th_name; $arr[$key]['file_id'] = $row->file_id; $arr[$key]['file_pkg_id'] = $row->file_pkg_id; $arr[$key]['file_org_name'] = $row->file_org_name; $arr[$key]['file_name'] = $row->file_name; $arr[$key]['file_size'] = $row->file_size; $arr[$key]['file_path'] = $row->file_path; $arr[$key++]['file_update_status'] = $row->file_update_status; if($row->file_update_status == 'Y'){ if($ext == '.gz'){ exec('rm -rf '.$up_path.$row->file_pkg_id); exec('rm -rf '.$up_path.$row->file_org_name); } else { exec('rm -rf '.$up_path.$row->file_pkg_id.'.tar.gz'); exec('rm -rf '.$up_path.$row->file_org_name); } } } } $this->data['chk_upd'] = $arr; $this->ver_view = $this->load->view($this->config->item("ver_folder").'v_chk_update',$this->data,TRUE); $this->ver_out(); } function get_extension($filename) { $x = explode('.', $filename); return '.'.end($x); } function chk_config(){ exec('id', $output); print_r($output); } } ?>
|