Ejemplo n.º 1
0
 /**
  * Hash check script for clients
  *
  * Clients check in hashes using $_POST
  * This script returns a JSON array with
  * hashes that are different
  *
  * @author AvB
  **/
 function hash_check()
 {
     // Check if we have a serial and data
     if (!isset($_POST['serial'])) {
         $this->error("Serial is missing");
     }
     if (!trim($_POST['serial'])) {
         $this->error("Serial is empty");
     }
     if (!isset($_POST['items'])) {
         $this->error("Items are missing");
     }
     $itemarr = array('error' => '');
     // Try to register client and lookup hashes in db
     try {
         // Register check and group in reportdata
         $report = new Reportdata_model($_POST['serial']);
         $report->machine_group = $this->group;
         $report->register()->save();
         $req_items = unserialize($_POST['items']);
         //Todo: check if array
         // Get stored hashes from db
         $hash = new Hash();
         $hashes = $hash->all($_POST['serial']);
         // Compare sent hashes with stored hashes
         foreach ($req_items as $name => $val) {
             // All models are lowercase
             $lkey = strtolower($name);
             // Rename legacy InventoryItem to inventory
             $lkey = str_replace('inventoryitem', 'inventory', $lkey);
             // Remove _model legacy
             if (substr($lkey, -6) == '_model') {
                 $lkey = substr($lkey, 0, -6);
             }
             if (!(isset($hashes[$lkey]) && $hashes[$lkey] == $val['hash'])) {
                 $itemarr[$name] = 1;
             }
         }
     } catch (Exception $e) {
         error('hash_check: ' . $e->getMessage());
     }
     // Handle errors
     foreach ($GLOBALS['alerts'] as $type => $list) {
         foreach ($list as $msg) {
             $itemarr['error'] .= "{$type}: {$msg}\n";
         }
     }
     // Return list of changed hashes
     echo serialize($itemarr);
 }
Ejemplo n.º 2
0
 /**
  * Report broken client
  *
  * Use this method to report on client-side
  * errors that prevent the client to
  * report properly
  *
  * @author AvB
  **/
 function broken_client()
 {
     // At least, we need a serial number
     if (!isset($_POST['serial'])) {
         $this->msg("Serial is missing", TRUE);
     }
     // Register check in reportdata
     $report = new Reportdata_model($_POST['serial']);
     $report->register()->save();
     // Clean POST data
     $data['module'] = isset($_POST['module']) ? $_POST['module'] : 'generic';
     $data['type'] = isset($_POST['type']) ? $_POST['type'] : 'danger';
     $data['msg'] = isset($_POST['msg']) ? $_POST['msg'] : 'Unknown';
     $data['timestamp'] = time();
     // Store event
     store_event($_POST['serial'], $data['module'], $data['type'], $data['msg']);
     echo "Recorded this message: " . $data['msg'] . "\n";
 }