/** * method checks if adm_my_files folder has all necessary rights * the method is designed to make as little as possible checks * @return bool if false than check the parameters $errorText, $errorPath */ public function checkSettings() { if (!is_writable($this->modulePath)) { if (!file_exists($this->modulePath)) { if (!is_writable(SERVER_PATH . '/adm_my_files')) { if (!file_exists(SERVER_PATH . '/adm_my_files')) { // create folder adm_my_files if (!@mkdir(SERVER_PATH . '/adm_my_files', 0777)) { $this->errorText = 'SYS_FOLDER_NOT_CREATED'; $this->errorPath = $this->webPath; return false; } } if (!is_writable(SERVER_PATH . '/adm_my_files')) { // set adm_my_files writable if (!@chmod(SERVER_PATH . '/adm_my_files', 0777)) { $this->errorText = 'SYS_FOLDER_WRITE_ACCESS'; $this->errorPath = $this->webPath; return false; } } } // create module folder if (@mkdir($this->modulePath, 0777)) { // create htaccess file for folder adm_my_files if necessary if (!file_exists(SERVER_PATH . '/adm_my_files/.htaccess')) { $protection = new Htaccess(SERVER_PATH . '/adm_my_files'); $protection->protectFolder(); } } else { $this->errorText = 'SYS_FOLDER_NOT_CREATED'; $this->errorPath = $this->webPath; return false; } } if (!is_writable($this->modulePath)) { // set module folder writable if (!@chmod($this->folderWithPath, 0777)) { $this->errorText = 'SYS_FOLDER_WRITE_ACCESS'; $this->errorPath = $this->webPath; return false; } } } $this->setFolder($this->modulePath); return true; }
function switchVersion($id, $version, $reason) { global $cfg, $data, $versions, $ext; $rt = array('result' => false, 'error' => 3); //验证参数 if ($id == '' || $version == '' || $reason == '') { return $rt; } $list = getList(false); $site = $list[$id]; if ($site != null) { $path = $site['root'] . $version; if ($site['current_version'] == $version) { //当前版本号等于目标版本号 $rt['error'] = 4; } else { if (!file_exists($path)) { //目标版本不存在 $rt['error'] = 5; $rt['debug'] = $path; } else { $ht = new Htaccess($site['root'] . $site['cfg'], $cfg['comments_start'], $cfg['comments_end']); if ($ht && $ht->errors() == 0) { $ht->add_rule(get_all_rules($cfg, $version)); $ht->save(); if ($ht->errors() == 0) { if ($data[$id] == null) { $data[$id] = array(); } array_push($data[$id], array($site['current_version'], $version, date("Y-m-d H:i:s", time()), $reason)); $rt['error'] = 0; $rt['result'] = true; } else { $rt['error'] = 6; } } else { $rt['error'] = 6; } } } } else { //3 switch 参数错误 $rt['error'] = 3; } save_records($data, $ext, $versions); return $rt; }