Exemple #1
0
 /**
  * Redirect the page after a POST form is submitted and forward any user notices
  * @return mixed
  */
 public function check_for_redirect()
 {
     if (array_key_exists('no_redirect', $this->module_exec->handler_response) && $this->module_exec->handler_response['no_redirect']) {
         return 'noredirect';
     }
     if (!empty($this->request->post) && $this->request->type == 'HTTP') {
         $msgs = Hm_Msgs::get();
         if (!empty($msgs)) {
             $this->session->secure_cookie($this->request, 'hm_msgs', base64_encode(serialize($msgs)), 0);
         }
         $this->session->end();
         if (array_key_exists('REQUEST_URI', $this->request->server)) {
             Hm_Dispatch::page_redirect($this->request->server['REQUEST_URI']);
         }
         return 'redirect';
     } elseif (array_key_exists('hm_msgs', $this->request->cookie) && trim($this->request->cookie['hm_msgs'])) {
         $msgs = @unserialize(base64_decode($this->request->cookie['hm_msgs']));
         if (is_array($msgs)) {
             array_walk($msgs, function ($v) {
                 Hm_Msgs::add($v);
             });
         }
         $this->session->secure_cookie($this->request, 'hm_msgs', '', 0);
         return 'msg_forward';
     }
     return false;
 }
Exemple #2
0
 /**
  * @preserveGlobalState disabled
  * @runInSeparateProcess
  */
 public function test_get()
 {
     Hm_Msgs::add('test msg');
     $this->assertTrue(in_array('test msg', Hm_Msgs::get(), true));
     Hm_Msgs::add('msg two');
     $this->assertTrue(in_array('msg two', Hm_Msgs::get(), true));
 }
Exemple #3
0
 /**
  * Error level messages start with ERR and will be shown in red
  */
 protected function output()
 {
     $res = '';
     $msgs = Hm_Msgs::get();
     $logged_out_class = '';
     if (!$this->get('router_login_state') && !empty($msgs)) {
         $logged_out_class = ' logged_out';
     }
     $res .= '<div class="sys_messages' . $logged_out_class . '">';
     if (!empty($msgs)) {
         $res .= implode(',', array_map(function ($v) {
             if (preg_match("/ERR/", $v)) {
                 return sprintf('<span class="err">%s</span>', $this->trans(substr($v, 3)));
             } else {
                 return $this->trans($v);
             }
         }, $msgs));
     }
     $res .= '</div>';
     return $res;
 }
Exemple #4
0
 public function process()
 {
     if (array_key_exists('state', $this->request->get) && $this->request->get['state'] == 'github_authorization') {
         if (array_key_exists('code', $this->request->get)) {
             $details = github_connect_details($this->config);
             $oauth2 = new Hm_Oauth2($details['client_id'], $details['client_secret'], $details['redirect_uri']);
             $result = $oauth2->request_token($details['token_url'], $this->request->get['code']);
             if (!empty($result) && array_key_exists('access_token', $result)) {
                 Hm_Msgs::add('Github connection established');
                 $this->user_config->set('github_connect_details', $result);
                 $user_data = $this->user_config->dump();
                 $this->session->set('user_data', $user_data);
                 $this->session->record_unsaved('Github connection');
                 $this->session->secure_cookie($this->request, 'hm_reload_folders', '1');
                 $this->session->close_early();
             } else {
                 Hm_Msgs::add('ERRAn Error Occurred');
             }
         } elseif (array_key_exists('error', $this->request->get)) {
             Hm_Msgs::add('ERR' . ucwords(str_replace('_', ' ', $this->request->get['error'])));
         } else {
             Hm_Msgs::add('ERRAn Error Occurred');
         }
         $msgs = Hm_Msgs::get();
         $this->session->secure_cookie($this->request, 'hm_msgs', base64_encode(serialize($msgs)), 0);
         Hm_Dispatch::page_redirect('?page=servers');
     }
 }
Exemple #5
0
 /**
  * Run modules and merge + filter the result array
  * @param array $input data from the handler modules
  * @param array $lang_str langauge strings
  * @param array $allowed_output allowed fields for JSON responses
  * @return JSON encoded data to be sent to the browser
  */
 public function content($output, $allowed_output)
 {
     $output['router_user_msgs'] = Hm_Msgs::get();
     $output = $this->filter_output($output, $allowed_output);
     return json_encode($output, JSON_FORCE_OBJECT);
 }
Exemple #6
0
 public function process()
 {
     list($success, $form) = $this->process_form(array('nux_pass', 'nux_service', 'nux_email', 'nux_name'));
     if ($success) {
         if (Nux_Quick_Services::exists($form['nux_service'])) {
             $details = Nux_Quick_Services::details($form['nux_service']);
             $details['name'] = $form['nux_name'];
             Hm_IMAP_List::add(array('name' => $details['name'], 'server' => $details['server'], 'port' => $details['port'], 'tls' => $details['tls'], 'user' => $form['nux_email'], 'pass' => $form['nux_pass']));
             $servers = Hm_IMAP_List::dump(false, true);
             $ids = array_keys($servers);
             $new_id = array_pop($ids);
             $imap = Hm_IMAP_List::connect($new_id, false);
             if ($imap && $imap->get_state() == 'authenticated') {
                 if (isset($details['smtp'])) {
                     Hm_SMTP_List::add(array('name' => $details['name'], 'server' => $details['smtp']['server'], 'port' => $details['smtp']['port'], 'tls' => $details['smtp']['tls'], 'user' => $form['nux_email'], 'pass' => $form['nux_pass']));
                     $this->session->record_unsaved('SMTP server added');
                     $smtp_servers = Hm_SMTP_List::dump(false, true);
                     $this->user_config->set('smtp_servers', $smtp_servers);
                 }
                 $this->user_config->set('imap_servers', $servers);
                 Hm_IMAP_List::clean_up();
                 $user_data = $this->user_config->dump();
                 if (!empty($user_data)) {
                     $this->session->set('user_data', $user_data);
                 }
                 $this->session->record_unsaved('IMAP server added');
                 $this->session->record_unsaved('SMTP server added');
                 $this->session->secure_cookie($this->request, 'hm_reload_folders', '1');
                 Hm_Msgs::add('E-mail account successfully added');
                 $msgs = Hm_Msgs::get();
                 if (!empty($msgs)) {
                     $this->session->secure_cookie($this->request, 'hm_msgs', base64_encode(serialize($msgs)), 0);
                 }
                 $this->session->close_early();
                 $this->out('nux_account_added', true);
             } else {
                 Hm_IMAP_List::del($new_id);
                 Hm_Msgs::add('ERRAuthentication failed');
             }
         }
     }
 }