Newer
Older
ubFramework / Provisioning / include / voip_device.php
@Christopher W. Olsen Christopher W. Olsen on 10 Dec 2017 3 KB iSinc
<?php

/* VoIP Device Class */
class VoIP_Device {

  public $deviceFamily;

  public $model;

  public $modelNo;

  public $bootStatus;

  public $userAgent;

  public $deviceSerial;

  public $appType;

  function __construct () {}

  function __construct1 ($agent) {
    
    // Here we need to determine what type of device is querying the provisioning system
    $devAgent = explode(' ', $agent);
    
    switch ($devAgent[0]) {
      case 'FileTransport':
        $eC = count($devAgent);
        
        system("echo 'Polycom Device: " . $eC . "' >> /tmp/AGENT.log");
        
        /*
         * By Default Will Consider It A Cold Boot Unless We Determine Non Boot
         * Loader Requested Information
         */
        $this->bootStatus = 'Cold';
        
        /*
         * The Secnd Part Of The Agent Is Uniform Through All Polycom UC
         * Firmware
         */
        preg_match("/((?:[a-zA-Z][a-zA-Z]+))-((?:[a-zA-Z][a-zA-Z]+))_(\d+)-((?:[a-zA-Z][a-zA-Z]+))\/((?:[\w\.\-]+)+)/", $devAgent[1], $dI);
        
        $this->deviceFamily = $dI[1];
        $this->model = $dI[2];
        $this->modelNo = $dI[3];
        // $cDev [$dI [4]] = $dI [5];
        $this->userAgent = $dI[5];
        
        if ($eC == 4) {
          system("echo 'Device Information Contains SN' >> /tmp/AGENT.log");
          
          /* Get Devices Serial Number AKA MAC */
          preg_match("/\(((?:[a-zA-Z][a-zA-Z]+)):((?:[\w\.\-]+)+)\)/", $devAgent[2], $dI);
          // $cDev [$dI [1]] = $dI [2];
          $this->deviceSerial = $dI[2];
          
          /* Get Loader Type Boot/App */
          preg_match("/((?:[a-zA-Z][a-zA-Z]+))\/((?:[a-zA-Z][a-zA-Z]+))/", $devAgent[3], $dI);
          if ($dI[1] == 'Application')
            $this->bootStatus = 'Warm';
          
          $this->appType = $dI[2];
          // $cDev [$dI [1]] = $dI [2];
        }
        else 
          if ($eC == 3) {
            // MrOlsen (2015-12-09) - I'm not happy with this and want to change
            // how
            // I detect
            
            /* Get Devices Serial Number AKA MAC */
            if ($devAgent[2][0] == '(') {
              system("echo 'Device Information Contains SN With No Type' >> /tmp/AGENT.log");
              preg_match("/\(((?:[a-zA-Z][a-zA-Z]+)):((?:[\w\.\-]+)+)\)/", $devAgent[2], $dI);
              // $cDev [$dI [1]] = $dI [2];
              $this->deviceSerial = $dI[2];
              $this->appType = 'Unknown'; // Updater';
            }
            else {
              /* Get Loader Type Boot/App */
              system("echo 'Device Information Does Not Contain SN' >> /tmp/AGENT.log");
              preg_match("/((?:[a-zA-Z][a-zA-Z]+))\/((?:[a-zA-Z][a-zA-Z]+))/", $devAgent[2], $dI);
              if ($dI[1] == 'Application')
                $this->bootStatus = 'Warm';
              
              $this->appType = $dI[2];
            }
          }
          else 
            if ($eC == 2) {
              $this->appType = 'Updater';
            }
            else {
              $this->bootStatus = 'Invalid';
              
              throw new Exception("echo 'Invalid Device Information' >> /tmp/AGENT.log");
            }
        break;
      default:
        throw new Exception('Unsupported Device');
        break;
    }
    
    system("echo 'cDev[" . $data['mode'] . "]: " . json_encode($cDev) . "' >> /tmp/AGENT.log");
  }
}

?>