00001 <?php
00002 require_once dirname(__FILE__) . '/controllerbase.cls.php';
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 class CommandsBaseController extends ControllerBase {
00038
00039
00040
00041 public function get_routes() {
00042 return array(
00043 new ExactMatchRoute('https://post_command', $this, 'commands_post', new NoCacheCacheManager()),
00044 );
00045 }
00046
00047
00048
00049
00050 public function action_commands_post($page_data) {
00051 $page_data->in_history = false;
00052 $err = new Status();
00053
00054 if ($page_data->has_post_data() == true) {
00055 $err = $this->redirect_to_handler($page_data);
00056 }
00057 else {
00058 $err->append(tr('No command data was send', 'core'));
00059 }
00060
00061 History::go_to(0, $err);
00062 exit;
00063 }
00064
00065
00066
00067
00068
00069
00070 private function redirect_to_handler(PageData $page_data) {
00071 $post = $page_data->get_post();
00072 foreach($post->get_array() as $key => $value) {
00073 $arr = explode(GYRO_COMMAND_SEP, $key);
00074 if (count($arr) >= 2 && $arr[0] == 'cmd') {
00075 array_shift($arr);
00076 $path = Config::get_url(Config::URL_BASEDIR) . 'process_commands/' . implode('/', $arr);
00077 $from = $page_data->get_post()->get_item('command_form_source');
00078 $data = $page_data->get_post()->get_item('command_data');
00079
00080 Url::current()->set_path($path)
00081 ->replace_query_parameter('from', $from)
00082 ->replace_query_parameter('data', $data)
00083 ->replace_query_parameter(Config::get_value(Config::FORMVALIDATION_FIELD_NAME), $post->get_item(Config::get_value(Config::FORMVALIDATION_FIELD_NAME)))
00084 ->replace_query_parameter(Config::get_value(Config::FORMVALIDATION_HANDLER_NAME), $post->get_item(Config::get_value(Config::FORMVALIDATION_HANDLER_NAME)))
00085 ->redirect();
00086 exit;
00087 }
00088 }
00089
00090 return new Status(tr('Unknown Command', 'default'));
00091 }
00092 }