Пример #1
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));
 }
Пример #2
0
 /**
  * Get some data for serial_number
  *
  * @author AvB
  **/
 function get_data($serial_number = '')
 {
     $obj = new View();
     if (authorized_for_serial($serial_number)) {
         $machine = new Machine_model();
         new Reportdata_model();
         new Disk_report_model();
         new Warranty_model();
         new Localadmin_model();
         $sql = "SELECT m.*, r.*, w.purchase_date, w.end_date, w.status,\n                    l.users, d.TotalSize, d.FreeSpace, d.SMARTStatus, d.CoreStorageEncrypted\n                FROM machine m \n                LEFT JOIN reportdata r ON (m.serial_number = r.serial_number)\n                LEFT JOIN warranty w ON (m.serial_number = w.serial_number)\n                LEFT JOIN localadmin l ON (m.serial_number = l.serial_number)\n                LEFT JOIN diskreport d ON (m.serial_number = d.serial_number AND d.MountPoint = '/')\n                WHERE m.serial_number = ?\n                ";
         $obj->view('json', array('msg' => $machine->query($sql, $serial_number)));
     } else {
         $obj->view('json', array('msg' => array()));
     }
 }
Пример #3
0
 /**
  * Get some data for serial_number
  *
  * @author AvB
  **/
 function get_data($serial_number = '')
 {
     $obj = new View();
     if (authorized_for_serial($serial_number)) {
         $machine = new Machine_model();
         new Reportdata_model();
         new Disk_report_model();
         new Warranty_model();
         new Localadmin_model();
         new Security_model();
         $sql = "SELECT m.*, r.console_user, r.long_username, r.remote_ip,\n\t\t\t\t\t\tr.uptime, r.reg_timestamp, r.machine_group, r.timestamp,\n\t\t\t\t\t\ts.gatekeeper, s.sip, w.purchase_date, w.end_date,\n\t\t\t\t\t\tw.status, l.users, d.TotalSize, d.FreeSpace,\n\t\t\t\t\t\td.SMARTStatus, d.CoreStorageEncrypted\n                FROM machine m \n\t\t\t\tLEFT JOIN reportdata r ON (m.serial_number = r.serial_number)\n\t\t\t\tLEFT JOIN security s ON (m.serial_number = s.serial_number)\n                LEFT JOIN warranty w ON (m.serial_number = w.serial_number)\n                LEFT JOIN localadmin l ON (m.serial_number = l.serial_number)\n                LEFT JOIN diskreport d ON (m.serial_number = d.serial_number AND d.MountPoint = '/')\n                WHERE m.serial_number = ?\n                ";
         $obj->view('json', array('msg' => $machine->query($sql, $serial_number)));
     } else {
         $obj->view('json', array('msg' => array()));
     }
 }
Пример #4
0
/**
 * Unfortunately we have to scrape the page as Apple discontinued the json api
 *
 * @param object warranty model instance
 * @author AvB
 **/
function check_warranty_status(&$warranty_model)
{
    // Error message
    $error = '';
    // Check if virtual machine
    // We assume vmware serials contain upper and lower chars
    // There are actual macs with a serial starting with VM
    // Todo: make this check more robust/support other VMs
    if (strtoupper($warranty_model->serial_number) != $warranty_model->serial_number) {
        $warranty_model->status = "Virtual Machine";
        // Use reg_timestamp as purchase_date
        $report = new Reportdata_model($warranty_model->serial_number);
        $warranty_model->purchase_date = date('Y-m-d', $report->reg_timestamp);
        $warranty_model->end_date = date('Y-m-d', strtotime('+10 year'));
        $machine = new Machine_model($warranty_model->serial_number);
        //$machine->img_url = $matches[1]; Todo: get image url for VM
        $machine->machine_desc = 'VMware virtual machine';
        $machine->save();
        return;
    }
    // Previous entry
    if ($warranty_model->end_date) {
        if ($warranty_model->end_date < date('Y-m-d')) {
            $warranty_model->status = 'Expired';
        }
    } else {
        // As of 19 oct 2015 warranty information is behind a Captcha
        // so we can't do any automated lookup anymore
        $warranty_model->status = "Can't lookup warranty";
        $warranty_model->purchase_date = estimate_manufactured_date($warranty_model->serial_number);
        // Calculate time to expire
        $max_applecare_years = sprintf('+%s year', conf('max_applecare', 3));
        $purchase_time = strtotime($warranty_model->purchase_date);
        $warranty_model->end_date = date('Y-m-d', strtotime($max_applecare_years, $purchase_time));
    }
    // Get machine model from apple (only when not set or failed)
    $machine = new Machine_model($warranty_model->serial_number);
    $lookup_failed = array('model_lookup_failed', 'unknown_model');
    if (!$machine->machine_desc or in_array($machine->machine_desc, $lookup_failed)) {
        $machine->machine_desc = model_description_lookup($warranty_model->serial_number);
        $machine->save();
    }
    return $error;
}
		<div class="col-lg-4 col-md-6">

			<div class="panel panel-default">

				<div class="panel-heading" data-container="body" title="Clients registered this week">

					<h3 class="panel-title"><i class="fa fa-star-o"></i> New clients <span id="new-clients" class="badge pull-right"></span></h3>

				</div>

				<div class="list-group scroll-box">
				  	<?php 
$queryobj = new Machine_model();
// Generic queryobject
?>

				  	<?php 
$lastweek = time() - 60 * 60 * 24 * 7;
$cnt = 0;
$sql = "SELECT machine.serial_number, computer_name, reg_timestamp FROM machine LEFT JOIN reportdata USING (serial_number) WHERE reg_timestamp > {$lastweek} ORDER BY reg_timestamp DESC";
?>
					<?php 
foreach ($queryobj->query($sql) as $obj) {
    ?>
 
					<a class="list-group-item" href="<?php 
    echo url('clients/detail/' . $obj->serial_number);
    ?>
"><?php 
    echo $obj->computer_name;
    ?>
Пример #6
0
/**
 * Unfortunately we have to scrape the page as Apple discontinued the json api
 *
 * @param object warranty model instance
 * @author AvB
 **/
function check_warranty_status(&$warranty_model)
{
    // Error message
    $error = '';
    // Check if virtual machine
    // We assume vmware serials contain upper and lower chars
    // There are actual macs with a serial starting with VM
    // Todo: make this check more robust/support other VMs
    if (strtoupper($warranty_model->serial_number) != $warranty_model->serial_number) {
        $warranty_model->status = "Virtual Machine";
        // Use reg_timestamp as purchase_date
        $report = new Reportdata_model($warranty_model->serial_number);
        $warranty_model->purchase_date = date('Y-m-d', $report->reg_timestamp);
        $warranty_model->end_date = date('Y-m-d', strtotime('+10 year'));
        $machine = new Machine_model($warranty_model->serial_number);
        //$machine->img_url = $matches[1]; Todo: get image url for VM
        $machine->machine_desc = 'VMware virtual machine';
        $machine->save();
        return;
    }
    $url = 'https://selfsolve.apple.com/wcResults.do';
    $opts['data'] = array('sn' => $warranty_model->serial_number, 'num' => '0');
    $opts['method'] = 'POST';
    // Get est. manufacture date
    $est_manufacture_date = estimate_manufactured_date($warranty_model->serial_number);
    // Get data
    $result = get_url($url, $opts);
    if ($result === FALSE) {
        $warranty_model->status = 'Lookup failed';
        $error = 'Lookup failed';
    } elseif (preg_match('/invalidserialnumber/', $result)) {
        // Check invalid serial
        $warranty_model->status = 'Invalid serial number';
    } elseif (preg_match("/RegisterProduct.do\\?productRegister=Y/", $result)) {
        // Check registration
        $warranty_model->status = 'Unregistered serialnumber';
    } elseif (preg_match('/warrantyPage.warrantycheck.displayHWSupportInfo\\(false/', $result)) {
        // Get expired status
        $warranty_model->status = 'Expired';
        //$warranty_model->end_date = '0000-00-00';
    } elseif (preg_match('/warrantyPage.warrantycheck.displayHWSupportInfo\\(true([^\\)])+/', $result, $matches)) {
        // Get support status
        if (preg_match('/Limited Warranty\\./', $matches[0])) {
            $warranty_model->status = 'No Applecare';
        } else {
            $warranty_model->status = 'Supported';
        }
        // Get estimated exp date
        if (preg_match('/Estimated Expiration Date: ([^<]+)</', $matches[0], $matches)) {
            $exp_time = strtotime($matches[1]);
            $warranty_model->end_date = date('Y-m-d', $exp_time);
            if ($warranty_model->status == 'Supported') {
                // There are 3, 4 and 5 year AppleCare contracts
                // We're checking how many years there are
                // between exp date and manufacture date
                $est_man_time = strtotime($est_manufacture_date);
                // For the next calculation take manufacture time minus half year
                // to fix an issue where the est_man_time is later than
                // the est_purchase date (a half year should be enough to compensate for the
                // estimation)
                $adjusted_man_time = $est_man_time - 60 * 60 * 24 * 180;
                // Get difference between expiration time and manufacture time divided by year seconds
                $years = sprintf('%d', intval($exp_time - $adjusted_man_time) / (60 * 60 * 24 * 365));
                // Estimated purchase date
                $warranty_model->purchase_date = date('Y-m-d', strtotime("-{$years} years", $exp_time));
            } else {
                $warranty_model->purchase_date = date('Y-m-d', strtotime('-1 year', $exp_time));
            }
        }
    } else {
        $warranty_model->status = 'No information found';
        $error = 'No information found';
    }
    // No valid purchase date, use the estimated manufacture date
    if (!$warranty_model->purchase_date or !preg_match('/\\d{4}-\\d{2}-\\d{2}/', $warranty_model->purchase_date)) {
        $warranty_model->purchase_date = $est_manufacture_date;
    }
    // No expiration date, use the estimated manufacture date + n year
    if (!$warranty_model->end_date) {
        $man_time = strtotime($warranty_model->purchase_date);
        // If we're within 3 years, after man_date we did not have AppleCare
        // So end_date = man_date + 1 year
        if (strtotime('+3 years', $man_time) > time()) {
            $warranty_model->end_date = date('Y-m-d', strtotime('+1 year', $man_time));
        } else {
            $warranty_model->end_date = date('Y-m-d', strtotime('+3 years', $man_time));
        }
    }
    // Get machine model from apple (only when not set or failed)
    $machine = new Machine_model($warranty_model->serial_number);
    $lookup_failed = array('model_lookup_failed', 'unknown_model');
    if (!$machine->machine_desc or in_array($machine->machine_desc, $lookup_failed)) {
        $machine->machine_desc = model_description_lookup($warranty_model->serial_number);
        $machine->save();
    }
    return $error;
}
		<div class="col-lg-4 col-md-6">

			<div class="panel panel-default">

			  <div class="panel-heading" data-container="body" title="HD SMART Status">

			    <h3 class="panel-title"><i class="fa fa-exclamation-circle"></i> HD SMART Status</h3>

			  </div>

			  <div class="panel-body text-center">

			  <?php 
$queryobj = new Machine_model();
$sql = "SELECT COUNT(CASE WHEN SMARTStatus='Failing' THEN 1 END) AS Failing,\n\t\t\t\t\t\t\t\t\t\tCOUNT(CASE WHEN SMARTStatus='Verified' THEN 1 END) AS Verified,\n\t\t\t\t\t\t\t\t\t\tCOUNT(CASE WHEN SMARTStatus='Not Supported' THEN 1 END) AS Not_Supported\n\t\t\t\t\t\t\t \t\t\tFROM diskreport;";
$obj = current($queryobj->query($sql));
?>

				<?php 
if ($obj->Failing > 0) {
    ?>

					<a href="<?php 
    echo url('show/listing/disk#failing');
    ?>
" class="btn btn-danger">
						<span class="bigger-150"> <?php 
    echo $obj->Failing;
    ?>
 </span><br>
						Failing!
 		<div class="col-lg-4 col-md-6">

			<div class="panel panel-default">

				<div class="panel-heading">

					<h3 class="panel-title"><i class="fa fa-laptop"></i> Hardware model breakdown</h3>

				</div>

				<div class="list-group scroll-box">

				<?php 
$machine = new Machine_model();
$filter = get_machine_group_filter();
$sql = "SELECT count(*) AS count, machine_desc \n\t\t\t\t\t\t\tFROM machine\n\t\t\t\t\t\t\tLEFT JOIN reportdata USING (serial_number)\n\t\t\t\t\t\t\t{$filter}\n\t\t\t\t\t\t\tGROUP BY machine_desc \n\t\t\t\t\t\t\tORDER BY count DESC";
?>
					<?php 
foreach ($machine->query($sql) as $obj) {
    ?>
					<?php 
    $obj->machine_desc = $obj->machine_desc ? $obj->machine_desc : 'Unknown';
    ?>
					<a href="<?php 
    echo url('show/listing/hardware/#' . rawurlencode($obj->machine_desc));
    ?>
" class="list-group-item"><?php 
    echo $obj->machine_desc;
    ?>
						<span class="badge pull-right"><?php 
    echo $obj->count;
Пример #9
0
 /**
  * Return json array with os breakdown
  *
  * @author AvB
  **/
 function os()
 {
     $out = array();
     $machine = new Machine_model();
     $sql = "SELECT count(1) as count, os_version \n\t\t\t\tFROM machine\n\t\t\t\tLEFT JOIN reportdata USING (serial_number)\n\t\t\t\t" . get_machine_group_filter() . "\n\t\t\t\tGROUP BY os_version\n\t\t\t\tORDER BY os_version ASC";
     $os_array = array();
     foreach ($machine->query($sql) as $obj) {
         $obj->os_version = $obj->os_version ? $obj->os_version : '0.0.0';
         $os_array[$obj->os_version] = $obj->count;
     }
     // Convert to flotr array
     $cnt = 0;
     foreach ($os_array as $os => $count) {
         $os = $os == '0' ? 'Unknown' : $os;
         $out[] = array('label' => $os, 'data' => array(array(intval($count), $cnt++)));
     }
     $obj = new View();
     $obj->view('json', array('msg' => $out));
 }
Пример #10
0
 /**
  * Return json array with os breakdown
  *
  * @author AvB
  **/
 function os()
 {
     $out = array();
     $machine = new Machine_model();
     $sql = "SELECT count(1) as count, os_version \n\t\t\t\tFROM machine\n\t\t\t\tGROUP BY os_version";
     $os_array = array();
     foreach ($machine->query($sql) as $obj) {
         $obj->os_version = $obj->os_version ? $obj->os_version : '0.0.0';
         $os_array[$obj->os_version] = $obj->count;
     }
     // Sort OS versions
     uksort($os_array, 'version_compare');
     // Convert to flotr array
     $cnt = 0;
     foreach ($os_array as $os => $count) {
         $os = $os == '0.0.0' ? 'Unknown' : $os;
         $out[] = array('label' => $os, 'data' => array(array(intval($count), $cnt++)));
     }
     $obj = new View();
     $obj->view('json', array('msg' => $out));
 }
Пример #11
0
function get_gsx_stats(&$gsx_model)
{
    // Error message
    $error = '';
    // Import gsxlib - https://github.com/filipp/gsxlib
    // Set up variables
    include_once conf('application_path') . 'lib/gsxlib/gsxlib.php';
    $_ENV['GSX_CERT'] = conf('gsx_cert');
    $_ENV['GSX_KEYPASS'] = conf('gsx_cert_keypass');
    $sold_to = conf('gsx_sold_to');
    $username = conf('gsx_username');
    // Pull from gsxlib
    $gsx = GsxLib::getInstance($sold_to, $username);
    try {
        $result = $gsx->warrantyStatus($gsx_model->serial_number);
    } catch (Exception $e) {
        // If obsolete, process and run stock warranty lookup
        if ($e->getMessage() === "The serial number entered has been marked as obsolete. If you feel this is in error, please verify and re-enter the serial number.") {
            // Load warranty_helper and run stock warranty functions
            require_once conf('application_path') . 'helpers/warranty_helper.php';
            $gsx_model->productdescription = model_description_lookup($gsx_model->serial_number);
            $gsx_model->warrantystatus = 'Obsolete';
            $gsx_model->warrantymod = 'Expired';
            $gsx_model->partcovered = 'No';
            $gsx_model->laborcovered = 'No';
            $gsx_model->daysremaining = '0';
            $gsx_model->isloaner = 'No';
            $gsx_model->isobsolete = 'Yes';
            $gsx_model->isvintage = 'No';
            // Don't overwrite actual GSX data with guessed data
            // For recently obsoleted machines
            if (is_null($gsx_model->estimatedpurchasedate) || $gsx_model->estimatedpurchasedate === "") {
                $gsx_model->estimatedpurchasedate = estimate_manufactured_date($gsx_model->serial_number);
            }
            if (is_null($gsx_model->coveragestartdate) || $gsx_model->coveragestartdate === "") {
                $gsx_model->coveragestartdate = $gsx_model->estimatedpurchasedate;
            }
            if (is_null($gsx_model->registrationdate) || $gsx_model->registrationdate === "") {
                $gsx_model->registrationdate = $gsx_model->estimatedpurchasedate;
            }
            if (is_null($gsx_model->coverageenddate) || $gsx_model->coverageenddate === "") {
                $gsx_model->coverageenddate = date("Y-m-d", strtotime(date("Y-m-d", strtotime($gsx_model->estimatedpurchasedate)) . " + 365 day"));
            }
            $gsx_model->save();
            $error = 'GSX Lookup failed - machine is Obsolete - running stock warranty lookup';
            //check_status();
            return $error;
        } else {
            return $e->getMessage();
        }
    }
    // Catch GSX lookup fails
    if ($result === FALSE) {
        // Load warranty_helper and run stock warranty functions
        require_once conf('application_path') . 'helpers/warranty_helper.php';
        $gsx_model->warrantystatus = 'GSX lookup failed';
        $gsx_model->productdescription = model_description_lookup($gsx_model->serial_number);
        $gsx_model->warrantymod = "Lookup failed";
        // Don't overwrite actual GSX data with guessed data
        if (is_null($gsx_model->estimatedpurchasedate) || $gsx_model->estimatedpurchasedate === "") {
            $gsx_model->estimatedpurchasedate = estimate_manufactured_date($gsx_model->serial_number);
        }
        if (is_null($gsx_model->coveragestartdate) || $gsx_model->coveragestartdate === "") {
            $gsx_model->coveragestartdate = $gsx_model->estimatedpurchasedate;
        }
        if (is_null($gsx_model->registrationdate) || $gsx_model->registrationdate === "") {
            $gsx_model->registrationdate = $gsx_model->estimatedpurchasedate;
        }
        if (is_null($gsx_model->coverageenddate) || $gsx_model->coverageenddate === "") {
            $gsx_model->coverageenddate = date("Y-m-d", strtotime(date("Y-m-d", strtotime($gsx_model->estimatedpurchasedate)) . " + 365 day"));
        }
        $gsx_model->save();
        $error = 'GSX Lookup failed - running stock warranty lookup';
        return $error;
    } else {
        // Rename warranty status for stock warranty stuff
        $local_warrantyStatus = str_replace(array('AppleCare Protection Plan', 'Out Of Warranty (No Coverage)', 'Apple Limited Warranty'), array('Supported', 'Expired', 'No Applecare'), $result->warrantyStatus);
        // Coverage Status
        if (empty($result->contractType)) {
            $gsx_model->contracttype = "";
        } else {
            $gsx_model->contracttype = str_replace(array('LI', 'LP', 'RP', 'IR', 'LS', 'CC', 'CS', 'DO', 'MU', 'OO', 'PA', 'QP', 'RE', 'G9', 'RA', 'PP', 'C1', 'C2', 'C3', 'C4', 'C5', 'TC', 'PT', 'EC', 'CL', 'CP', 'CI', 'CW', 'VW', 'VP', 'RI', 'RW'), array('Apple Limited Warranty', 'Apple Limited Warranty', 'Repeat Service', 'Internal Repairs', 'Lost Shipments (Coverage)', 'Custom Bid Contracts', 'Customer Satisfaction (CS) Code', 'DOA Coverage', 'Missing Upon 1st Use', 'Out Of Warranty (No Coverage)', 'AppleCare Parts Agreement', 'Quality Program', 'Repeat Service', 'Pending Coverage Check', 'AppleCare Repair Agreement', 'AppleCare Protection Plan', 'AppleCare Protection Plan', 'AppleCare Parts Agreement', 'AppleCare Repair Agreement', 'Custom Bid Contracts', 'Extended Contract', 'Edu/Govt Warranty (Australia)', 'Additional Part Coverage', 'Additional Service Coverage', 'Consumer Law Coverage', 'Consumer Law Coverage', 'Consumer Law Repeat Coverage', 'Consumer Law Repeat Coverage', 'Variable Warranty', 'Variable Warranty', 'Variable Warranty Repeat', 'Variable Warranty Repeat'), $result->contractType);
        }
        // Fix for non-AppleCare machines
        if (empty($result->contractCoverageEndDate)) {
            $gsx_model->contractcoverageenddate = '';
        } else {
            $gsx_model->contractcoverageenddate = date('Y-m-d', strtotime($result->contractCoverageEndDate));
        }
        if (empty($result->contractCoverageStartDate)) {
            $gsx_model->contractcoveragestartdate = '';
        } else {
            $gsx_model->contractcoveragestartdate = date('Y-m-d', strtotime($result->contractCoverageStartDate));
        }
        if (empty($result->laborCovered)) {
            $gsx_model->laborcovered = 'No';
        } else {
            $gsx_model->laborcovered = str_replace(array('Y', 'N'), array('Yes', 'No'), $result->laborCovered);
        }
        if (empty($result->partCovered)) {
            $gsx_model->partcovered = 'No';
        } else {
            $gsx_model->partcovered = str_replace(array('Y', 'N'), array('Yes', 'No'), $result->partCovered);
        }
        // Update the stock machine tables
        $machine = new Machine_model($gsx_model->serial_number);
        //$machine->img_url = $matches[1]; Todo: get image url for VM
        $machine->machine_desc = $result->productDescription;
        $machine->save();
        // Translate gsxlib to MunkiReport DB
        $gsx_model->warrantymod = $local_warrantyStatus;
        $gsx_model->warrantystatus = $result->warrantyStatus;
        $gsx_model->daysremaining = $result->daysRemaining;
        $gsx_model->estimatedpurchasedate = date('Y-m-d', strtotime($result->estimatedPurchaseDate));
        $gsx_model->purchasecountry = $result->purchaseCountry;
        $gsx_model->registrationdate = date('Y-m-d', strtotime($result->registrationDate));
        $gsx_model->productdescription = $result->productDescription;
        $gsx_model->configdescription = $result->configDescription;
        $gsx_model->isloaner = str_replace(array('Y', 'N'), array('Yes', 'No'), $result->isLoaner);
        $gsx_model->isobsolete = 'No';
        // Check if Vintage and write flag
        $vintageCheck = substr($gsx_model->configdescription, 0, 3);
        if ($vintageCheck === "VIN") {
            $gsx_model->isvintage = 'Yes';
        } else {
            $gsx_model->isvintage = 'No';
        }
        // Fix for non-obsolete and out of warranty machines
        if (empty($result->coverageEndDate)) {
            if ($result->warrantyStatus === "Out Of Warranty (No Coverage)") {
                if (empty($result->contractCoverageEndDate)) {
                    $gsx_model->coverageenddate = date("Y-m-d", strtotime(date("Y-m-d", strtotime($result->registrationDate)) . " + 365 day"));
                } else {
                    $gsx_model->coverageenddate = date('Y-m-d', strtotime($result->contractCoverageEndDate));
                }
            } else {
                $gsx_model->coverageenddate = date("Y-m-d", strtotime(date("Y-m-d", strtotime($result->registrationDate)) . " + 365 day"));
            }
        } else {
            $gsx_model->coverageenddate = date('Y-m-d', strtotime($result->coverageEndDate));
        }
        if (empty($result->coverageStartDate)) {
            if ($result->warrantyStatus === "Out Of Warranty (No Coverage)") {
                $gsx_model->coveragestartdate = date('Y-m-d', strtotime($result->registrationDate));
            } else {
                $gsx_model->coveragestartdate = '';
            }
        } else {
            $gsx_model->coveragestartdate = date('Y-m-d', strtotime($result->coverageStartDate));
        }
        // Service Level Agreement
        // Fix for different warranty type returns from GSX
        if (empty($result->warrantyReferenceNo)) {
            $gsx_model->warrantyreferenceno = $result->slaGroupDescription;
        } else {
            $gsx_model->warrantyreferenceno = $result->warrantyReferenceNo;
        }
        // Update the stock warranty tables
        $warranty = new Warranty_model($gsx_model->serial_number);
        $warranty->purchase_date = $gsx_model->estimatedpurchasedate;
        $warranty->end_date = $gsx_model->contractcoverageenddate;
        $warranty->status = $local_warrantyStatus;
        $warranty->save();
        // Save that stuff :D
        $gsx_model->save();
        $error = 'GSX data processed';
        return $error;
    }
    return $error;
}