File manager - Edit - /home/wwwroot/camplus.hk/master.camplus.hk/public_html/application/modules/core/controllers/Core.php
Back
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Core extends MY_Controller { function __construct() { parent::__construct(); } function set_language($language) { $cookie = array( 'name' => 'language', 'value' => $language, 'expire' => '2629743' // One month ); $this->input->set_cookie($cookie); redirect($_SERVER['HTTP_REFERER']); } public function info() { phpinfo(); } public function index() { //echo Modules::run('core/welcome/getSideMenu', 'dashboard'); if($this->session->userdata("user_id")) { echo Modules::run('core/welcome'); } else { redirect("core/welcome"); } } function login() { $settings = $this->User_model->get_site_settings(); if (is_null(get_cookie('language'))) { $this->set_language($settings['site_lang']); redirect("core/login"); } $apiUser = $settings['api_user']; $apiPassword = $settings['api_password']; $apiUrl = $settings['api_url']; $clientId = $settings['google-client-id']; $clientSecret = $settings['google-client-secret']; $redirectUrl = base_url() . 'core/User_Authentication'; $apiUrl = parse_url($apiUrl, PHP_URL_HOST); if (!empty($apiUrl) && !empty($_SERVER['HTTP_REFERER']) && !empty($apiUser) && !empty($apiPassword)) { $referer = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); if($referer == $apiUrl) { $this->User_model->login($apiUser, $apiPassword,'1','1'); } } if (!empty($apiUrl) && !empty($_SERVER['REMOTE_ADDR']) && !empty($apiUser) && !empty($apiPassword)) { if($_SERVER['REMOTE_ADDR'] == "218.190.226.201") { $this->User_model->login($apiUser, $apiPassword,'1','1'); } } if(!$this->session->userdata("user_id")) { $data = $this->data; $dir = FCPATH . 'files/login_slides/'; if(file_exists($dir)) { $images = glob("$dir/*.{jpg,png,JPG,PNG}", GLOB_BRACE); if(count($images)> 0) { foreach ($images as $image) { $img = explode('/',$image); $data['images'][] = 'files/login_slides/' . $img[count($img)-1]; } } } $this->form_validation->set_rules('username','Username','required'); $this->form_validation->set_rules('password','Password','required|xss_clean|trim'); $dir = array(); array_push($dir, realpath(dirname(__FILE__)) . '/../../../../files/tmp_upload',realpath(dirname(__FILE__)) . '/../../../../files/appraisal_files',realpath(dirname(__FILE__)) . '/../../../../files/event_files',realpath(dirname(__FILE__)) . '/../../../../files/logo',realpath(dirname(__FILE__)) . '/../../../../files/quotation_files',realpath(dirname(__FILE__)) . '/../../../../files/reference_quotation_files',realpath(dirname(__FILE__)) . '/../../../../files/tmp_upload'); $err_string = ""; foreach ($dir as $folder) { $newFileName = $folder . '/file.txt'; if ( ! is_writable(dirname($newFileName))) { $err_string .= $folder . ' not writtable<br/>'; } } if($err_string!="") $this->session->set_flashdata('error', $err_string . 'Please contact system adminsitrator for further details.'); if(!$this->form_validation->run()) { if(!empty($clientId) && !empty($clientSecret)) { $data['url'] = "https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=" . htmlentities($redirectUrl) . '&client_id=' . $clientId . '&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&'; } $data['_view'] = 'login'; $this->load->view('basetemplate', $data); } else { $remember = 0; if($this->input->post('remember_me')) $remember = 1; $username = $this->input->post('username'); $password = $this->input->post('password'); $this->User_model->login($username, $password,$remember); } } else { redirect("core/welcome"); } } function logout() { include_once APPPATH."libraries/google-api-php-client/Google_Client.php"; include_once APPPATH."libraries/google-api-php-client/contrib/Google_Oauth2Service.php"; // Google Project API Credentials $settings = $this->User_model->get_site_settings(); //$settings['google-redirect']; $clientId = $settings['google-client-id']; $clientSecret = $settings['google-client-secret']; $redirectUrl = base_url() . 'core/User_Authentication'; unset($_SESSION['token']); $this->load->helper('cookie'); delete_cookie("remember_me"); $this->session->unset_userdata('token'); $this->session->unset_userdata('userData'); $this->session->sess_destroy(); if($clientSecret!="") { header('Location: https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=' . $redirectUrl); } else { redirect("login"); } } function welcome() { if($this->session->userdata("user_id")) { $data = $this->data; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "welcome"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "welcome"; $this->load->view('basetemplate', $data); } else { redirect("login"); } } function change_password() { if($this->session->userdata("user_id")) { $data = $this->data; $data['user'] = $this->User_model->getUser($this->session->userdata('id')); $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "change_password"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "change_password"; $this->load->view('basetemplate', $data); } else { redirect("login"); } } public function check_password() { if($this->session->userdata("user_id")) echo json_encode($this->User_model->check_password(array('password' => md5($this->input->post('password')),'id' => $this->session->userdata('id')))); else redirect("login"); } public function update_password() { if($this->session->userdata("user_id")) { if($this->User_model->check_password(array('password' => md5($this->input->post('password')),'id' => $this->session->userdata('id')))) { $this->User_model->update_password(array('password' => md5($this->input->post('new_password')),'id' => $this->session->userdata('id'))); } } else { redirect("login"); } } public function forgot_password() { if($this->session->userdata("user_id")) { redirect('user/dashboard'); } else { $this->form_validation->set_rules('email','Email','required|trim|valid_email'); if($this->form_validation->run() == FALSE) { $this->session->set_flashdata('error','Something went wrong...'); redirect('login'); } else { if($this->User_model->forgot_password($this->input->post())) $this->session->set_flashdata('success','Please check your mail for reset password link.'); else $this->session->set_flashdata('error','Email id not found'); redirect('login'); } } } function reset_password($str = '') { if($this->session->userdata("user_id")) { redirect('user/dashboard'); } else { $this->form_validation->set_rules('password','Password','required|trim|xss_clean|matches[c_password]'); $this->form_validation->set_rules('c_password','Confirm Password','required|trim|xss_clean'); if($this->form_validation->run() == FALSE) { $result = $this->User_model->reset_password(urldecode($str)); if($result){ $data['header'] = false; $data['sidebar'] = false; $data['_view'] = "reset_password"; $data['footer'] = false; $data['top_menu'] = "resetPassword"; $data['pagetitle'] = "Reset Password"; $data['site_settings'] = $this->User_model->get_site_settings(); $this->load->view('basetemplate', $data); } else{ $this->session->set_flashdata('error','Something went wrong'); redirect('login'); } } else { $str = base64_decode(urldecode($str)); $arr = explode('|',$str); $user_id = $arr[0]; $email = $arr[1]; $randomString = $arr[2]; $hash = $arr[3]; if($this->User_model->set_password($this->input->post('password'),$user_id)) $this->session->set_flashdata('success','Password changed successfully'); else $this->session->set_flashdata('error','Something went wrong'); redirect('login'); } } } function get_site_settings() { $this->load->model('User_model'); return $this->User_model->get_site_settings(); } function preference() { if($this->session->userdata("user_id")) { $postData = $this->input->post(); if(!empty($postData)) { if($this->User_model->savePreference($this->session->userdata('id'),$postData)) $this->session->set_flashdata('success', $this->lang->line('success')); else $this->session->set_flashdata('error', $this->lang->line('error')); redirect($_SERVER['HTTP_REFERER']); } $data = $this->data; $data['user'] = $this->User_model->getUser($this->session->userdata('id')); $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "preference"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "preference"; $this->load->view('basetemplate', $data); } else { redirect("login"); } } function site_settings() { if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('MANAGE_SITE_SETTING')) show_error($this->lang->line('no_permission_error')); $this->form_validation->set_rules('site_name', 'Site Name', 'required'); $this->form_validation->set_rules('school_name', 'School Name', 'required'); if(!$this->form_validation->run()){ $data = $this->data; $dir = FCPATH . 'files/login_slides/'; if(file_exists($dir)) { $images = glob("$dir/*.{jpg,png,JPG,PNG}", GLOB_BRACE); foreach ($images as $image) { $img = explode('/',$image); $data['images'][] = 'files/login_slides/' . $img[count($img)-1]; } } $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "site_settings"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "common_top"; $data['sub_menu'] = "core_setting"; $data['pagetitle'] = $this->lang->line('site_settings'); $data['site_settings'] = $this->User_model->get_site_settings(); $this->load->view('basetemplate', $data); } else { if($this->User_model->update_site_settings($this->input->post(),$_FILES)) $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); else $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); redirect('core/site_settings'); } } else { redirect("login"); } } function images() { $dir = FCPATH . 'files/login_slides/'; if (!file_exists($dir)) { mkdir($dir, 0777, true); } $data = []; if(file_exists($dir)) { $images = glob("$dir/*.{jpg,png,JPG,PNG}", GLOB_BRACE); foreach ($images as $image) { $img = explode('/',$image); $data[] = 'files/login_slides/' . $img[count($img)-1]; } } echo json_encode($data); } function remove_image() { if($this->session->userdata("user_id")) { $dir = FCPATH . 'files/login_slides/'; unlink($dir . $_POST['file']); echo json_encode(['success'=>true]); } else { redirect("login"); } } function img_upload() { $target_dir = FCPATH."files/login_slides/"; if (!file_exists($target_dir)) { mkdir($target_dir, 0777, true); } foreach($_FILES["files"]["name"] as $key => $files) { if($_FILES["files"]["name"][$key]!='' && !empty($_FILES["files"]["name"][$key])) { $target_file = $target_dir . basename($_FILES["files"]["name"][$key]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image or fake image $check = getimagesize($_FILES["files"]["tmp_name"][$key]); if($check !== false) { // echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { // echo "File is not an image."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["files"]["tmp_name"][$key], $target_file)) { } else { echo json_encode(array('error'=>"Sorry, there was an error uploading your file.")); } } } } echo json_encode(array('success'=>true));//echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; } function modules() { if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('MANAGE_MODULE')) show_error($this->lang->line('no_permission_error')); $modules = array(); $this->load->helper('file'); $files = get_dir_file_info(APPPATH.'modules', TRUE); foreach (array_keys($files) as $file) { $modules[] = str_replace(EXT, '', $file); } $data = $this->data; $data['modules'] = $modules; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "modules"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "common_top"; $data['sub_menu'] = "core_module"; $data['pagetitle'] = "Enable Disable Modules"; $this->load->view('basetemplate', $data); } else { redirect("login"); } } function saveModule() { if($this->session->userdata("user_id")) { if($this->User_model->saveModule($this->input->post())) $return = TRUE; else $return = FALSE; echo json_encode($return); } else { redirect("login"); } } function setEducation() { if($this->session->userdata("user_id")) { /*if(!$this->acl->hasPermission('HR_SETTING')) show_error($this->lang->line('no_permission_error'));*/ //pr($this->input->post('data'));exit; if($this->User_model->setEducation($this->input->post('data'))) $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); else $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } else { redirect("login"); } } function getEBSettings() { $array = $this->db->get('eb_settings')->result_array(); $ret = array(); foreach ($array as $setting) { $ret[$setting['key']] = unserialize($setting['val']); } return $ret; } public function create_user() { $this->db->select('id as user_id'); $item = $this->db->get_where('users')->result_array(); if(empty($item)){ $this->load->view('install/create_user'); }else{ redirect(base_url(), 'refresh'); } } public function save_user(){ $data['name'] = $this->input->post('name'); $data['user_name'] = $this->input->post('user_name'); $data['email'] = $this->input->post('email'); $data['flag'] = 1; $data['password'] = $this->encryption->hash($this->input->post('password')); $this->db->insert('users', $data); unset($_SESSION["install_flag"]); redirect(base_url(), 'refresh'); } public function act($username) { if($this->session->userdata("user_id")) { if($this->session->userdata("id")!=1) { show_error($this->lang->line('no_permission_error')); } else { $replace = $this->db->get_where('users',['username' => $username])->row(); if(!empty($replace)) { $this->User_model->login($username, $replace->password,'1','1'); $this->session->set_userdata('acting', '1'); } else { show_error('User do not exist'); } } } else { redirect("login"); } } public function upgrade() { $path = getcwd(); echo 'Current Path:' . $path . '<br/>'; chdir($path); $text = exec("git pull https://camplus:BRGg5ctN2LWjMQXPHGwQFMgTNVi46WZP4TvpyVwm@git.proedge.hk/devel-team/camplus2.git", $output, $retval); echo "Returned with status $retval and output:\n"; echo "<pre>"; print_r($output); echo "</pre>"; } public function testmail() { email(1,'Camplus Email PR notice','Testing message','https://llcst.camplus.hk/','PR'); } public function backup_db() { $this->load->dbutil(); $prefs = array( 'format' => 'zip', 'filename' => 'my_db_backup.sql' ); $backup = $this->dbutil->backup($prefs); $db_name = 'backup-on-'. date("Y-m-d-H-i-s") .'.zip'; $path = FCPATH . 'backup/'; $save = $path . $db_name; if (!file_exists($path)) { mkdir($path, 0777, true); } $this->load->helper('file'); write_file($save, $backup); $this->load->helper('download'); $target_url = "http://mon.cyberarts.com.hk/backup/db/"; $post = array('upfile'=> curl_file_create($save),'site'=>$_SERVER['HTTP_HOST']); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_URL,$target_url); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $result=curl_exec ($ch); //echo $result; curl_close ($ch); if(!$this->acl->hasPermission('BACKUP_DB')) show_error($this->lang->line('no_permission_error')); else force_download($db_name, $backup); } function mail_log() { if($this->session->userdata("user_id")) { /* if(!$this->acl->hasPermission('MANAGE_MODULE')) show_error($this->lang->line('no_permission_error')); $modules = array(); $this->load->helper('file'); $files = get_dir_file_info(APPPATH.'modules', TRUE); foreach (array_keys($files) as $file) { $modules[] = str_replace(EXT, '', $file); } */ $data = $this->data; $data['modules'] = $modules; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "mail_log"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "common_top"; $data['sub_menu'] = "core_module"; $data['pagetitle'] = "Enable Disable Modules"; $this->load->view('basetemplate', $data); } else { redirect("login"); } } }
| ver. 1.4 |
Github
|
.
| PHP 7.2.34 | Generation time: 0.17 |
proxy
|
phpinfo
|
Settings