/**
  * Get estimate_manufactured_date
  *
  * @return void
  * @author 
  **/
 function estimate_manufactured_date($serial_number = '')
 {
     // Authenticate
     if (!$this->authorized()) {
         die('Authenticate first.');
         // Todo: return json?
     }
     require_once conf('application_path') . "helpers/warranty_helper.php";
     $out = array('date' => estimate_manufactured_date($serial_number));
     $obj = new View();
     $obj->view('json', array('msg' => $out));
 }
Esempio n. 2
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;
}
Esempio n. 3
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;
}
Esempio n. 4
0
echo humanreadablesize($disk->FreeSpace);
?>
</dd>
					<dt>SMART Status</dt>
					<dd><?php 
echo $disk->SMARTStatus == 'Failing' ? '<span class=text-danger>Failing</span>' : $disk->SMARTStatus;
?>
</dd>
				</dl>
				<?php 
require_once conf('application_path') . "helpers/warranty_helper.php";
?>
				<dl class="dl-horizontal">
					<dt>Est. Manufacture date</dt>
					<dd><?php 
echo estimate_manufactured_date($serial_number);
?>
</dd>
					<dt>Est. Purchase date</dt>
					<dd><?php 
echo $warranty->purchase_date;
?>
</dd>
				</dl>

				<dl class="dl-horizontal">
					<dt>Uptime</dt>
					<?php 
if ($report->uptime > 0) {
    ?>
					<dd><time class="absolutetime" title="Booted: <?php 
Esempio n. 5
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;
}