/**
  * Get WiFi information for serial_number
  *
  * @param string $serial serial number
  **/
 public function get_wifi_data($serial_number = '')
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => 'Not authorized'));
     }
     $wifi = new wifi_model($serial_number);
     $obj->view('json', array('msg' => $wifi->rs));
 }
 /**
  * Retrieve data in json format
  *
  * @return void
  * @author 
  **/
 function get_data($serial_number = '')
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => 'Not authorized'));
     }
     $service = new Service_model();
     $obj->view('json', array('msg' => $service->retrieve_records($serial_number)));
 }
示例#3
0
 /**
  * Retrieve data in json format
  *
  **/
 function get_data($serial_number = '')
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => 'Not authorized'));
     }
     $ard = new Ard_model($serial_number);
     $obj->view('json', array('msg' => $ard->rs));
 }
 /**
  * Get low battery devices
  *
  *
  **/
 public function get_low()
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => 'Not authorized'));
     }
     $bt = new Bluetooth_model();
     $obj->view('json', array('msg' => $bt->get_low()));
 }
 function get_map_data()
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => 'Not authorized'));
         return;
     }
     $location = new Location_model();
     $obj->view('json', array('msg' => $location->get_map_data()));
 }
 /**
  * Get stats
  *
  **/
 function get_stats()
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => 'Not authorized'));
         return;
     }
     $cert = new Certificate_model();
     $obj->view('json', array('msg' => $cert->get_stats()));
 }
 /**
  * Get printer information for printer widget
  *
  * @return void
  * @author John Eberle (tuxudo)
  **/
 public function get_printers()
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => array('error' => 'Not authenticated')));
         return;
     }
     $printers = new Printer_model();
     $obj->view('json', array('msg' => $printers->get_printers()));
 }
 /**
  * Get Modified Computer names
  *
  *
  **/
 public function get_modified_computernames()
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => array('error' => 'Not authenticated')));
         return;
     }
     $dm = new Directory_service_model();
     $obj->view('json', array('msg' => $dm->get_modified_computernames()));
 }
 /**
  * Get count of  displays
  *
  *
  * @param int $type type 1 is external, type 0 is internal
  **/
 public function get_count($type = 1)
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => array('error' => 'Not authenticated')));
         return;
     }
     $dim = new Displays_info_model();
     $obj->view('json', array('msg' => $dim->get_count($type)));
 }
 /**
  * Get timemachine stats
  *
  * @return void
  * @author 
  **/
 function get_stats($hours = 24)
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => 'Not authorized'));
         return;
     }
     $timemachine = new Timemachine_model();
     $obj->view('json', array('msg' => $timemachine->get_stats($hours)));
 }
 /**
  * Get statistics
  *
  * Get statistics grouped by type
  *
  * @param String type group by region_name or site_name
  **/
 public function get_groups($type = '')
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => 'Not authorized'));
         return;
     }
     $site_info = new Site_info_model();
     $obj->view('json', array('msg' => $site_info->get_groups($type)));
 }
 /**
  * Retrieve data in json format
  *
  * @return void
  * @author 
  **/
 function get_data($serial_number = '')
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => 'Not authorized'));
     }
     $out = array();
     $model = new Crashplan_model();
     foreach ($model->retrieve_records($serial_number) as $record) {
         $out[] = $record->rs;
     }
     $obj->view('json', array('msg' => $out));
 }
 /**
  * Get statistics
  *
  * @return void
  * @author
  **/
 function get_stats($mount_point = '/')
 {
     $obj = new View();
     if (!$this->authorized()) {
         $obj->view('json', array('msg' => array('error' => 'Not authenticated')));
         return;
     }
     $disk_report = new Disk_report_model();
     $out = array();
     $thresholds = conf('disk_thresholds', array('danger' => 5, 'warning' => 10));
     $out['thresholds'] = $thresholds;
     $out['stats'] = $disk_report->get_stats($mount_point, $thresholds['danger'], $thresholds['warning']);
     $obj->view('json', array('msg' => $out));
 }
示例#14
0
 public static function init($viewtype, $config)
 {
     self::$view = new $viewtype();
     foreach ($config as $key => $value) {
         self::$view->{$key} = $value;
     }
 }
 /**
  * Generate age data for age widget
  *
  * @author AvB
  **/
 function age()
 {
     // Authenticate
     if (!$this->authorized()) {
         die('Authenticate first.');
         // Todo: return json?
     }
     $out = array();
     $warranty = new Warranty_model();
     // Time calculations differ between sql implementations
     switch ($warranty->get_driver()) {
         case 'sqlite':
             $agesql = "CAST(strftime('%Y.%m%d', 'now') - strftime('%Y.%m%d', purchase_date) AS INT)";
             break;
         case 'mysql':
             $agesql = "TIMESTAMPDIFF(YEAR,purchase_date,CURDATE())";
             break;
         default:
             // FIXME for other DB engines
             $agesql = "SUBSTR(purchase_date, 1, 4)";
     }
     $sql = "SELECT count(1) as count, \n\t\t\t\t{$agesql} AS age \n\t\t\t\tFROM warranty\n\t\t\t\tGROUP by age \n\t\t\t\tORDER BY age DESC";
     $cnt = 0;
     foreach ($warranty->query($sql) as $obj) {
         $obj->age = $obj->age ? $obj->age : '<1';
         $out[] = array('label' => $obj->age, 'data' => array(array(intval($obj->count), $cnt++)));
     }
     $obj = new View();
     $obj->view('json', array('msg' => $out));
 }
 function items($name = '', $version = '')
 {
     $data['inventory_items'] = array();
     $data['name'] = 'No item';
     if ($name) {
         $name = rawurldecode($name);
         $inventory_item_obj = new Inventory_model();
         $data['name'] = $name;
         if ($version) {
             $version = rawurldecode($version);
             $items = $inventory_item_obj->retrieve_many('name = ? AND version = ?', array($name, $version));
         } else {
             $items = $inventory_item_obj->retrieve_many('name = ?', array($name));
         }
         foreach ($items as $item) {
             $machine = new Machine_model($item->serial);
             $reportdata = new Reportdata_model($item->serial);
             $instance['serial'] = $item->serial;
             $instance['hostname'] = $machine->computer_name;
             $instance['username'] = $reportdata->console_user;
             $instance['version'] = $item->version;
             $instance['bundleid'] = $item->bundleid;
             $instance['bundlename'] = $item->bundlename;
             $instance['path'] = $item->path;
             $data['inventory_items'][] = $instance;
         }
     }
     $obj = new View();
     $obj->view('inventory/inventoryitem_detail', $data);
 }
示例#17
0
 /**
  * List of machines
  *
  * @param string name of view
  * @return void
  * @author abn290
  **/
 function show($view = '')
 {
     $data['page'] = 'clients';
     // TODO: Check if view exists
     $obj = new View();
     $obj->view('client/' . $view, $data);
 }
 function items($name = '', $payload = '')
 {
     // Protect this handler
     if (!$this->authorized()) {
         redirect('auth/login');
     }
     $data['profile_items'] = array();
     $data['name'] = 'No item';
     if ($name) {
         $name = rawurldecode($name);
         $profile_item_obj = new Profile_model();
         $data['profile_name'] = $name;
         if ($payload) {
             $payload = rawurldecode($payload);
             $items = $profile_item_obj->retrieve_many('payload_name = ? GROUP BY serial_number', array($payload));
             $data['name'] = $payload;
         } else {
             $items = $profile_item_obj->retrieve_many('profile_name = ? GROUP BY serial_number', array($name));
             $data['name'] = $name;
         }
         foreach ($items as $item) {
             $machine = new Machine_model($item->serial_number);
             $instance['serial'] = $item->serial_number;
             $instance['hostname'] = $machine->computer_name;
             $instance['payload'] = $item->profile_name;
             $data['profile_items'][] = $instance;
         }
     }
     $obj = new View();
     $obj->view('profile/profileitem_detail', $data);
 }
示例#19
0
 function delete_machine($serial_number = '')
 {
     $status = array('status' => 'undefined', 'rowcount' => 0);
     if (!$this->authorized('delete_machine')) {
         $status['status'] = 'unauthorized';
     } else {
         // Delete machine entry from all tables
         $machine = new Machine_model();
         // List tables (unfortunately this is not db-agnostic)
         switch ($machine->get_driver()) {
             case 'sqlite':
                 $tbl_query = "SELECT name FROM sqlite_master \n\t\t\t\t\t\tWHERE type = 'table' AND name NOT LIKE 'sqlite_%'";
                 break;
             default:
                 // Get database name from dsn string
                 if (conf('dbname')) {
                     $tbl_query = "SELECT TABLE_NAME AS name FROM information_schema.TABLES \n\t\t\t\t\t\tWHERE TABLE_TYPE='BASE TABLE' AND TABLE_SCHEMA='" . conf('dbname') . "'";
                 } else {
                     die('Admin:delete_machine: Cannot find database name.');
                 }
         }
         // Get tables
         $tables = array();
         foreach ($machine->query($tbl_query) as $obj) {
             $tables[] = $obj->name;
         }
         // Get database handle
         $dbh = getdbh();
         $dbh->beginTransaction();
         // Affected rows counter
         $cnt = 0;
         // Delete entries
         foreach ($tables as $table) {
             // Migration has no serial number
             if ($table == 'migration') {
                 continue;
             }
             // hash and inventoryitem use serial FIXME
             if ($table == 'hash' or $table == 'inventoryitem') {
                 $serial = 'serial';
             } else {
                 $serial = 'serial_number';
             }
             $sql = "DELETE FROM {$table} WHERE `{$serial}`=?";
             if (!($stmt = $dbh->prepare($sql))) {
                 die('Prepare ' . $sql . ' failed');
             }
             $stmt->bindValue(1, $serial_number);
             $stmt->execute();
             $cnt += $stmt->rowCount();
         }
         $dbh->commit();
         // Return status
         $status['status'] = 'success';
         $status['rowcount'] = $cnt;
     }
     $obj = new View();
     $obj->view('json', array('msg' => $status));
 }
 /**
  * Show detail information
  *
  * @author AvB
  **/
 function pending()
 {
     if (!$this->authorized()) {
         redirect('auth/login');
     }
     $data['page'] = '';
     $obj = new View();
     $obj->view('pending', $data, $this->view_path);
 }
示例#21
0
 public static function get_view()
 {
     // if do not have any object view, create one
     if (is_null(View::$view)) {
         View::$view = new View();
     }
     //return view
     return View::$view;
 }
示例#22
0
 function request_not_found($msg = '', $status_code = 404)
 {
     $data = array('status_code' => $status_code, 'msg' => '');
     // Don't show a detailed message when not in debug mode
     conf('debug') && ($data['msg'] = $msg);
     $obj = new View();
     $obj->view('error/client_error', $data);
     exit;
 }
 /**
  * Show report
  *
  * @author AvB
  **/
 function report($serial_number = '')
 {
     if (!$this->authorized()) {
         redirect('auth/login');
     }
     $data['page'] = '';
     $data['serial_number'] = $serial_number;
     $obj = new View();
     $obj->view('report', $data, $this->view_path);
 }
示例#24
0
 /**
  * Get conditions
  *
  * @return void
  * @author AvB
  **/
 function conditions()
 {
     if (!$this->authorized()) {
         die('Authenticate first.');
         // Todo: return json
     }
     $queryobj = new Power_model();
     $sql = "SELECT COUNT(CASE WHEN `condition` = 'Normal' THEN 1 END) AS normal,\n\t\t\t\t\t\tCOUNT(CASE WHEN `condition` = 'Replace Soon' THEN 1 END) AS soon,\n\t\t\t\t\t\tCOUNT(CASE WHEN `condition` = 'Service Battery' THEN 1 END) AS service,\n\t\t\t\t\t\tCOUNT(CASE WHEN `condition` = 'Replace Now' THEN 1 END) AS now,\n\t\t\t\t\t\tCOUNT(CASE WHEN `condition` = 'No Battery' THEN 1 END) AS missing\n\t\t\t \t\t\tFROM power\n\t\t\t \t\t\tLEFT JOIN reportdata USING (serial_number)\n\t\t\t \t\t\t" . get_machine_group_filter();
     $obj = new View();
     $obj->view('json', array('msg' => current($queryobj->query($sql))));
 }
 /**
  * undocumented function summary
  *
  * Undocumented function long description
  *
  * @param type var Description
  **/
 public function get_stats($hours = 24)
 {
     $out = array();
     if (!$this->authorized()) {
         $out['error'] = 'Not authorized';
     } else {
         $mr = new Munkireport_model();
         $out = $mr->get_stats($hours);
     }
     $obj = new View();
     $obj->view('json', array('msg' => $out));
 }
示例#26
0
 /**
  * Get Event
  *
  * @author AvB
  **/
 function get($minutes = 60, $type = 'all', $module = 'all')
 {
     $queryobj = new Event_model();
     $queryobj = new Reportdata_model();
     $fromtime = time() - 60 * $minutes;
     $out['items'] = array();
     $out['error'] = '';
     $sql = "SELECT m.serial_number, module, type, msg, data, m.timestamp,\n\t\t\t\t\tmachine.computer_name\n\t\t\t\tFROM event m \n\t\t\t\tLEFT JOIN reportdata USING (serial_number) \n\t\t\t\tLEFT JOIN machine USING (serial_number) \n\t\t\t\tWHERE m.timestamp > {$fromtime} \n\t\t\t\t" . get_machine_group_filter('AND') . "\n\t\t\t\tORDER BY m.timestamp DESC";
     foreach ($queryobj->query($sql) as $obj) {
         $out['items'][] = $obj;
     }
     $obj = new View();
     $obj->view('json', array('msg' => $out));
 }
示例#27
0
 function custom($which = 'default')
 {
     if ($which) {
         $data['args'] = func_get_args();
         $view = $which;
         $viewpath = APP_ROOT . 'custom/views/';
     } else {
         $data = array('status_code' => 404);
         $view = 'error/client_error';
         $viewpath = VIEW_PATH;
     }
     $obj = new View();
     $obj->view($view, $data, $viewpath);
 }
 /**
  * Get security for serial_number
  *
  * @param string $serial serial number
  **/
 public function get_data($serial = '')
 {
     $out = array();
     if (!$this->authorized()) {
         $out['error'] = 'Not authorized';
     } else {
         $prm = new Security_model();
         foreach ($prm->retrieve_records($serial) as $security) {
             $out[] = $security->rs;
         }
     }
     $obj = new View();
     $obj->view('json', array('msg' => $out));
 }
示例#29
0
 public function view()
 {
     $V = null;
     if (is_null($this->view)) {
         logtrace("Controller: view(): {$this->template}, " . $this->controller_class() . ", {$this->method}, {$this->action}", null);
         $V = new View($this->template, $this->controller_class(), $this->method, $this->action);
         $V->__setttings = $this->settings;
     } else {
         logtrace("Controller: view(): {$this->template}, " . $this->controller_class() . ", {$this->method}, {$this->action}", null);
         $V = new View($this->template, $this->controller_class(), $this->method, $this->action);
         $V->__setttings = $this->settings;
     }
     logtrace("Controller view(): data, {$this->kingdom}", $this->data);
     $CONTENT = $V->view($this->data, $this->kingdom);
     return $CONTENT;
 }
 /**
  * Obtém a string HTML de uma View que será renderizada.
  * 
  * @param type $view
  * @param type $vars
  * @param type $layout
  * 
  * @return <string>
  */
 private static function get_html($view, $vars = array(), $layout = null)
 {
     # iniciamos uma sessão de buffer para obter o resultado HTML compremido.
     ob_start();
     if ($layout !== null) {
         self::$view = $view;
         self::$vars = $vars;
         self::render_if_exists('@elements/layouts/' . $layout);
     } else {
         self::render_if_exists($view, $vars);
     }
     # obtemos o HTML e finalizamos a sessão de buffer
     $html = ob_get_contents();
     ob_end_clean();
     return $html;
 }