shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

security.php (3870B)


      1 <?php
      2 class ControllerCommonSecurity extends Controller {
      3 	public function index() {
      4 		$this->load->language('common/security');
      5 
      6 		$data['text_instruction'] = $this->language->get('text_instruction');
      7 	
      8 		$data['user_token'] = $this->session->data['user_token'];
      9 		
     10 		$data['storage'] = DIR_SYSTEM . 'storage/';
     11 		
     12 		$path = '';
     13 		
     14 		$data['paths'] = array();
     15 		
     16 		$parts = explode('/', str_replace('\\', '/', rtrim(DIR_SYSTEM, '/')));	
     17 		
     18 		foreach ($parts as $part) {
     19 			$path .= $part . '/';
     20 			
     21 			$data['paths'][] = $path;
     22 		}
     23 		
     24 		rsort($data['paths']);	
     25 			
     26 		$data['document_root'] = str_replace('\\', '/', realpath($this->request->server['DOCUMENT_ROOT'] . '/../') . '/');
     27 
     28 		return $this->load->view('common/security', $data);
     29 	}
     30 	
     31 	public function move() {
     32 		$this->load->language('common/security');
     33 
     34 		$json = array();
     35 		
     36 		if ($this->request->post['path']) {
     37 			$path = $this->request->post['path'];
     38 		} else {
     39 			$path = '';
     40 		}
     41 				
     42 		if ($this->request->post['directory']) {
     43 			$directory = $this->request->post['directory'];
     44 		} else {
     45 			$directory = '';
     46 		}
     47 		
     48 		if (!$this->user->hasPermission('modify', 'common/developer')) {
     49 			$json['error'] = $this->language->get('error_permission');
     50 		} else {
     51 			if (DIR_STORAGE != DIR_SYSTEM . 'storage/') {
     52 				$data['error'] = $this->language->get('error_path');		
     53 			}
     54 			
     55 			if (!$path || str_replace('\\', '/', realpath($path)) . '/' != str_replace('\\', '/', substr(DIR_SYSTEM, 0, strlen($path)))) {
     56 				$json['error'] = $this->language->get('error_path');
     57 			}
     58 					
     59 			if (!$directory || !preg_match('/^[a-zA-Z0-9_-]+$/', $directory)) {
     60 				$json['error'] = $this->language->get('error_directory');
     61 			}
     62 						
     63 			if (is_dir($path . $directory)) {
     64 				$json['error'] = $this->language->get('error_exists');
     65 			}
     66 			
     67 			if (!is_writable(realpath(DIR_APPLICATION . '/../') . '/config.php') || !is_writable(DIR_APPLICATION . 'config.php')) {
     68 				$json['error'] = $this->language->get('error_writable');
     69 			}
     70 									
     71 			if (!$json) {
     72 				$files = array();
     73 	
     74 				// Make path into an array
     75 				$source = array(DIR_SYSTEM . 'storage/');
     76 	
     77 				// While the path array is still populated keep looping through
     78 				while (count($source) != 0) {
     79 					$next = array_shift($source);
     80 	
     81 					foreach (glob($next) as $file) {
     82 						// If directory add to path array
     83 						if (is_dir($file)) {
     84 							$source[] = $file . '/*';
     85 						}
     86 	
     87 						// Add the file to the files to be deleted array
     88 						$files[] = $file;
     89 					}
     90 				}
     91 	
     92 				// Create the new storage folder
     93 				if (!is_dir($path . $directory)) {
     94 					mkdir($path . $directory, 0777);
     95 				}			
     96 	
     97 				// Copy the 
     98 				foreach ($files as $file) {
     99 					$destination = $path . $directory . substr($file, strlen(DIR_SYSTEM . 'storage/'));
    100 					
    101 					if (is_dir($file) && !is_dir($destination)) {
    102 						mkdir($destination, 0777);
    103 					}
    104 									
    105 					if (is_file($file)) {
    106 						copy($file, $destination);
    107 					}
    108 				}
    109 				
    110 				// Modify the config files
    111 				$files = array(
    112 					DIR_APPLICATION . 'config.php',
    113 					realpath(DIR_APPLICATION . '/../') . '/config.php'
    114 				);
    115 							
    116 				foreach ($files as $file) {
    117 					$output = '';
    118 					
    119 					$lines = file($file);
    120 					
    121 					foreach ($lines as $line_id => $line) {
    122 						if (strpos($line, 'define(\'DIR_STORAGE') !== false) {
    123 							$output .= 'define(\'DIR_STORAGE\', \'' . $path . $directory . '/\');' . "\n";
    124 						} else {
    125 							$output .= $line;
    126 						}
    127 					}
    128 		
    129 					$file = fopen($file, 'w');
    130 		
    131 					fwrite($file, $output);
    132 		
    133 					fclose($file);
    134 				}
    135 				
    136 				$json['success'] = $this->language->get('text_success');
    137 			}
    138 		}
    139 			
    140 		$this->response->addHeader('Content-Type: application/json');
    141 		$this->response->setOutput(json_encode($json));		
    142 	}
    143 }