Exemplo n.º 1
0
 /**
  * APC UPS ajax status controller
  *
  * @return view
  */
 function status()
 {
     // Load libraries
     //---------------
     $this->lang->load('apcups');
     $this->load->library('apcups/Apc');
     header('Cache-Control: no-cache, must-revalidate');
     header('Content-type: application/json');
     try {
         echo json_encode(array('code' => 0, 'status' => $this->apc->get_status()));
     } catch (Exception $e) {
         echo json_encode(array('code' => clearos_exception_code($e), 'errmsg' => clearos_exception_message($e)));
     }
 }
Exemplo n.º 2
0
 /**
  * Returns connection status.
  *
  * @return JSON
  */
 function get_status()
 {
     // Load dependencies
     //------------------
     $this->load->library('web_proxy/Squid');
     // Run synchronize
     //----------------
     try {
         sleep(2);
         $data['error_code'] = 0;
         $data['status_code'] = $this->squid->get_connection_status();
         $data['status_message'] = $this->squid->get_connection_status_message();
     } catch (Exception $e) {
         $data['error_code'] = clearos_exception_code($e);
         $data['error_message'] = clearos_exception_message($e);
     }
     // Return status message
     //----------------------
     $this->output->set_header("Content-Type: application/json");
     $this->output->set_output(json_encode($data));
 }
Exemplo n.º 3
0
 /**
  * Apc view/edit controller
  *
  * @param string $mode mode
  *
  * @return view
  */
 function _view_edit($mode = 'view')
 {
     // Load dependencies
     //------------------
     $this->load->library('apcups/Apc');
     $this->lang->load('apcups');
     // Set validation rules
     //---------------------
     $this->form_validation->set_policy('powerdown', 'apcups/Apc', 'validate_powerdown', TRUE);
     $this->form_validation->set_policy('control_email', 'apcups/Apc', 'validate_email', TRUE);
     $form_ok = $this->form_validation->run();
     // Handle form submit
     //-------------------
     if ($this->input->post('submit') && $form_ok) {
         try {
             $this->apc->set_powerdown($this->input->post('powerdown'));
             $this->apc->set_email($this->input->post('control_email'));
             if ($this->apc->is_reset_required()) {
                 $this->apc->reset();
             }
             $this->page->set_status_updated();
             redirect('/apcups');
         } catch (Exception $e) {
             $this->page->view_exception($e);
             return;
         }
     }
     // Load view data
     //---------------
     try {
         $data = $this->apc->get_status();
         $data['is_found'] = TRUE;
     } catch (Engine_Exception $e) {
         $data['error'] = clearos_exception_message($e);
         $data['is_found'] = FALSE;
         if ($mode == 'edit') {
             redirect('/apcups');
         }
     }
     $data['powerdown_options'] = $this->apc->get_powerdown_options();
     $data['control_email'] = $this->apc->get_email();
     $data['mode'] = $mode;
     // Load views
     //-----------
     $this->page->view_form('overview', $data, lang('apcups_app_name'));
 }
Exemplo n.º 4
0
 /**
  * Set the APC notification email.
  *
  * @param string $email a valid email
  *
  * @return void
  * @throws Engine_Exception Validation_Exception
  */
 function set_email($email)
 {
     clearos_profile(__METHOD__, __LINE__);
     // Validation
     // ----------
     Validation_Exception::is_valid($this->validate_email($email));
     $file = new File(self::FILE_APC_CONTROL, TRUE);
     try {
         $file->replace_lines('/^export SYSADMIN=.*/', 'export SYSADMIN=' . $email . "\n");
     } catch (Exception $e) {
         throw new Engine_Exception(clearos_exception_message($e), CLEAROS_ERROR);
     }
 }