public static function check_signature($client_sig) { $user = Loader::get_user(); if (!$client_sig) { return FALSE; } if (!$user->get_module(User::M_SECRET_KEY)->check_secret_key()) { $user->get_module(User::M_SECRET_KEY)->unset_secret_key(); Session::destroy(Session::get_sid(), Session::ST_INCORRECT); return FALSE; } //Создаём серверную сигнатуру //1. получаем все параметры и удаляем параметр с сигнатурой $all_params = Buffer::get_post(); unset($all_params['sig']); $elements_sig = array(); //2. извлекаем значения из пришедших параметров в обязательный список параметров на серврере $params = config('web', 'sig_params'); foreach ($params as $param) { //некоторые параметрый дублируем в ручную, по тем правилам, по которомы они дложны были создаваться на клиенте switch ($param) { case Session::COOKIE_ID: $elements_sig[$param] = Session::get_sid(); break; case 'location': $elements_sig[$param] = get_full_url(); $elements_sig[$param] = str_replace('/www.', '/', $elements_sig[$param]); break; default: $elements_sig[$param] = isset($all_params[$param]) ? $all_params[$param] : ''; } if (isset($all_params[$param])) { unset($all_params[$param]); } } //Если в запросе остались какие-то параметры то добавляем их в конец массива if (!empty($all_params)) { $elements_sig = array_merge($elements_sig, $all_params); } //3. получаем секретный ключ текущего пользователя $elements_sig[self::NAME_SECRET_KEY] = $user->get_secret_key(); //4. Сортируем и собираем в строку элементы запроса $server_sig = array(); ksort($elements_sig); foreach ($elements_sig as $key => $value) { $server_sig[] = $key . '=' . $value; } //5. Формируем сигнатуру сервера $server_sig = md5(implode('&', $server_sig)); //6. Сравниваем результаты if ($server_sig == $client_sig) { return TRUE; } return FALSE; }
public function execute() { $ap_name = Buffer::get(URL_AP); $controller_name = Buffer::get(URL_CONTROLLER); $query_param = Buffer::get(self::QUERY_PARAM, 'post'); $command = Buffer::get('command', 'post'); $client_format = Buffer::get('format', 'post'); $action = Buffer::get('action', 'post'); $access_zone = config(URL_AP, 'access', 'zone'); $server_format = config('settings', 'web_format'); if ($client_format != $server_format) { throw new Exception_wx(4060002, $client_format); } $command = Security::sanitize_string($command); $action = Security::sanitize_string($action); $command_path = APPPATH . 'commands/' . "{$ap_name}/{$command}" . EXT; if (!file_exists($command_path)) { $command_path = APPPATH . "modules/{$ap_name}/{$controller_name}/commands/{$command}" . EXT; } if (!file_exists($command_path)) { throw new Exception_wx(4040000, $command_path); } if ($access_zone != Z_PUBLIC and !Security::check_signature(Buffer::get_post('sig'))) { throw new Exception_wx(4030001); } include_once $command_path; if (!class_exists($action)) { throw new Exception_wx(4040002, $command_path, $action); } $query_param = Format::converter($query_param, $server_format, TRUE); $command_object = new $action($query_param); if (!is_a($command_object, self::COMMAND_CLASS)) { throw new Exception_wx(5000002, $command_path, $command_object); } $command_object->set_module(Buffer::get(URL_CONTROLLER)); try { $command_object->execute(); } catch (Command_exception $exc) { Command::set_result(FALSE); $message =& $exc->client_message; if (!empty($message)) { $options = array('message' => $message, 'type' => 'error'); Command::set_client_command('show_message', $options); } Log::log_error($exc, 'command_exception'); $this->_to_client(); } if (!Command::isset_result()) { Command::set_result(TRUE); } $this->_to_client(); }