"; # echo "Start Date - $startDate"; # echo "
"; # echo "End Date - $endDate"; # echo "
"; # echo "Status is - $status"; # echo "
"; # echo "Rows Returned - $num_rows"; # echo "
"; # echo "Calling IP - $callingip"; # echo "
"; # echo "Free90 is - $free90"; # echo "
"; # echo "Exempt is - $Exempt"; # echo "
"; # exit(); } function collect_vars($serial, $ver, $build, $datecollected, $free90, $free180, $startDate, $endDate, $username, $Exempt){ $insert = "insert into entitlement_info_collect (sn, ver, build, datecollected, free90, startdate, enddate) values ('$serial','$ver','$build','$datecollected','$free90','$startDate','$endDate')"; $result = mysql_query($insert) or die(mysql_error()); } function collect_parameters() { global $daserial, $ver, $build, $hasserial, $evar; if(isset($_GET["sn"])) { //$daserial = $_GET["sn"]; $daserial = filter_var($_GET["sn"], FILTER_SANITIZE_STRING); $ver = filter_var($_GET["ver"],FILTER_SANITIZE_STRING); $build = filter_var($_GET["build"],FILTER_SANITIZE_STRING); if(isset($_GET["evar"])) { $evar = filter_var($_GET["evar"],FILTER_SANITIZE_STRING); } $hasserial = TRUE; } } function collect_visited($serial) { global $latest_visited; $visited = mysql_query("select * from visitedsn where sn = '$serial'") or trigger_error(mysql_error().$visited); //$visited = mysql_query("select * from entitlement_info_collect where sn = '$serial' ORDER BY datecollected DESC") or trigger_error(mysql_error().$visited); $visisted_count = mysql_num_rows($visited); if($visisted_count > 0) { $latest_visited = mysql_fetch_array($visited); } return $visisted_count; } function record_visited($serial) { $insert_visit = "insert into visitedsn (sn) values ('$serial')"; $result = mysql_query($insert_visit) or die(mysql_error()); } function collect_rows($serial) { $querystring = "select * from entitlement_validate_mv where serial_number = '$serial' ORDER BY Field(Entitlement_Status, 'Active', 'Inactive', 'Expired') ASC, Entitlement_End_Date DESC"; wh_log($serial . "collect rows querystring: " . $querystring ); $checkit = mysql_query($querystring) or trigger_error(mysql_error().$checkit); wh_log($serial . "collect rows results: " . mysql_num_rows($checkit) ); return $checkit; } function get_valid_entitlements($checkit, $evar) { global $entitlements, $supports; $has_any = FALSE; $skipped = FALSE; while ($erow = mysql_fetch_assoc($checkit)) { extract($erow); if($Entitlement_Class_Type == "Support Entitlement") { if($Entitlement_End_Date >= $today) { $has_any = TRUE; array_push($entitlements, $erow); if(isset($evar)) { if(!$skipped) { $skipped = TRUE; } else { array_push($supports, $erow); } } } } } mysql_data_seek($checkit, 0); if(!$has_any) { while ($erow = mysql_fetch_assoc($checkit)) { extract($erow); if($Entitlement_Class_Type == "Support Entitlement") { $has_any = TRUE; array_push($entitlements, $erow); break; } } } return $has_any; } function get_valid_licenses($checkit, $evar, $serial) { $has_any = FALSE; global $licenses; global $licenses_mysql; global $has_url_filtering; $non_filtering_row_array = array(); $non_filtering_mysql_array = array(); $filtering_mysql_array = array(); $filtering_row_array = array(); wh_log($serial . " license checkit: " . $checkit); //if(isset($evar)) { mysql_data_seek($checkit, 0); while ($erow = mysql_fetch_assoc($checkit)) { wh_log($serial . " has License found (pre extract): " . $Entitlement_Class_Type); extract($erow); if($Entitlement_Class_Type != "Support Entitlement") { $has_any = TRUE; wh_log($serial . " has License found: " . $Entitlement_Class_Type); $row = array($Serial_Number, $Warranty, $Entitlement_Status, $Entitlement_Start_date, $Entitlement_End_Date, $Warranty_End_Date, $Install_Date, $Entitlement_Type, $Exempt, $AP_Count, $Entitlement_Class_Type); if($Entitlement_Class_Type == "URL Filtering License") { $has_url_filtering = TRUE; array_push($non_filtering_row_array, $row); } array_push($non_filtering_mysql_array, $erow); if ($Entitlement_Class_Type != "URL Filtering License") { array_push($filtering_mysql_array, $erow); } else { array_push($filtering_mysql_array, $erow); array_push($filtering_row_array, $row); } } } if ($has_url_filtering) { wh_log("URL-F Detection -------"); $licenses = $filtering_row_array; $licenses_mysql = $filtering_mysql_array; } else { $licenses = $non_filtering_row_array; $licenses_mysql = $non_filtering_mysql_array; } //} return $has_any; } function generate_spt($serial, $startDate, $endDate, $evar, $supports, $licenses, $has_url_filtering) { $licenses_data = array(); for($i = 0; $i < count($licenses); $i++) { array_push($licenses_data, implode("|", $licenses[$i])); } $licenses_args = "\"".implode(";", $licenses_data)."\""; $supports_data = array(); for($i = 0; $i < count($supports); $i++) { array_push($supports_data, implode("|", $supports[$i])); } $supports_args = "\"".implode(";", $supports_data)."\""; wh_log("Support -: " . $serial . " --> " . $supports_args); wh_log("License: " . $serial . " --> " . $licenses_args); if (substr($serial,0,2) === "un") { wh_log('URL-F plus UNLEASHED-URL-F +++++++'); if(!isset($evar)) { wh_log("sudo /var/www/ga/gen_entitle_ul.sh " . $serial . " 904 licensed 8 " . $endDate . " " . $startDate. " " . " UNLEASHED-URL-F"); exec ("sudo /var/www/ga/gen_entitle_ul.sh $serial 904 licensed 8 $endDate $startDate"); } else { wh_log("sudo /var/www/ga/gen_entitle_ul.sh " . $serial . " 904 licensed 8 " . $endDate . " " . $startDate . " " . $supports_args . " " . $licenses_args . " UNLEASHED-URL-F"); exec ("sudo /var/www/ga/gen_entitle_ul.sh $serial 904 licensed 8 $endDate $startDate $supports_args $licenses_args"); } } else { if(!isset($evar)) { wh_log("sudo /var/www/ga/gen_entitle.sh " . $serial . " 904 licensed 8 " . $endDate . " " . $startDate); exec ("sudo /var/www/ga/gen_entitle.sh $serial 904 licensed 8 $endDate $startDate"); } else { wh_log("sudo /var/www/ga/gen_entitle.sh " . $serial . " 904 licensed 8 " . $endDate . " " . $startDate . " " . $supports_args . " " . $licenses_args); exec ("sudo /var/www/ga/gen_entitle.sh $serial 904 licensed 8 $endDate $startDate $supports_args $licenses_args"); } } } function wh_log($log_msg) { $log_filename = "/var/log/wh_log"; if (!file_exists($log_filename)) { // create directory/folder uploads. // mkdir($log_filename, 0777, true); } // $log_file_data = $log_filename.'/log_' . date('d-M-Y') . '.log'; // file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND); } function download_spt($serial) { header('Content-type: text/plain'); $file="/var/www/ga/generated/$serial.spt"; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); } $today = date('Y-m-d'); $today30 = date('Y-m-d', strtotime("+30 days")); $today90 = date('Y-m-d', strtotime("+90 days")); $today180 = date('Y-m-d', strtotime("+180 days")); $timestamp = date('Y-m-d H:i:s'); $freefix = "2018-01-31"; $free90 = "N"; $free180 = "N"; $status = "Entitled"; $startDate = $today; $hasserial = FALSE; $daserial = NULL; $ver = NULL; $build = NULL; $evar = NULL; $latest_visited = NULL; $entitlements = array(); $licenses = array(); $licenses_mysql = array(); $has_url_filtering = FALSE; $supports = array(); collect_parameters(); if ($hasserial) { $serial = mysql_real_escape_string($daserial); $isvisited = collect_visited($serial); $datecollected = $timestamp; $checkit = collect_rows($serial); $has_entitlement = get_valid_entitlements($checkit, $evar); $has_license = get_valid_licenses($checkit, $evar, $serial); $file="/var/www/html/wip/$serial"; $file_spt = "/var/www/ga/generated/$serial.spt"; wh_log($serial . " --> " . $evar); wh_log($serial . " has Entitlement: " . $has_entitlement); wh_log($serial . " has License: " . $has_license); if ($has_entitlement || $has_license || $isvisited < 1 || !file_exists($file_spt)) { wh_log(count($supports)); exec("echo _wip > $file"); $entitlement = NULL; if($has_entitlement) { $entitlement = $entitlements[0]; extract($entitlement); if ($Entitlement_End_Date < $today) { // echo "Serial already claimed and no entitlemt active"; wh_log("Fixing security bug - set to 180 days"); $endDate = $today30; $status = "Fixing security bug - set to 180 days"; $free180 = "Y"; // exit(); } if ($isvisited > 0 && $Entitlement_End_Date < $today) { $endDate = $freefix; } else { if($Entitlement_Status == "Active" || $Entitlement_Status == "Inactive") { $startDate = $Entitlement_Start_date; $endDate = $Entitlement_End_Date; } elseif($Warranty == "Y") { $startDate = $Install_Date; $endDate = $Warranty_End_Date; $status = "Warranty Ok"; } elseif($Exempt == "Y") { $endDate = $today180; $status = "No Entitlement or Warranty active and is Exempt - set to 180 days"; $free180 = "Y"; }elseif($Entitlement_Status == "Expired" || $Entitlement_End_Date < $today){ $endDate = $today30; $status = "No Entitlement or Warranty active and is Exempt - set to 180 days"; $free180 = "Y"; } } collect_vars($serial, $ver, $build, $datecollected, $free90, $free180, $startDate, $endDate, $username, $Exempt); } elseif ($has_license) { $license = $licenses_mysql[0]; extract($license); wh_log("Support: Entitlement_Status: " . $Entitlement_Status . ", Entitlement_Start_date: " . $Entitlement_Start_date . ", Entitlement_End_Date: " . $Entitlement_End_Date); if ($Entitlement_End_Date < $today) { // echo "Serial already claimed and no entitlemt active"; // exit(); } if (count($licenses_mysql) == 0) { $endDate = $today90; $free90 = "Y"; } else if ($isvisited > 0 && $Entitlement_End_Date < $today) { $endDate = $freefix; } else { if($Entitlement_Status == "Active" || $Entitlement_Status == "Inactive") { $startDate = $Entitlement_Start_date; $endDate = $Entitlement_End_Date; } elseif($Warranty == "Y") { $startDate = $Install_Date; $endDate = $Warranty_End_Date; $status = "Warranty Ok"; } elseif($Exempt == "Y") { $endDate = $today180; $status = "No Entitlement or Warranty active and is Exempt - set to 180 days"; $free180 = "Y"; } elseif($Entitlement_Status == "Expired" || $Entitlement_End_Date < $today){ wh_log("Fixing security bug - set to 180 day ++s"); $endDate = $today30; $status = "No Entitlement or Warranty active and is Exempt - set to 180 days"; $free180 = "Y"; } } collect_vars($serial, $ver, $build, $datecollected, $free90, $free180, $startDate, $endDate, $username, $Exempt); } else { if($isvisited < 1) { // $endDate = $today90; $endDate = $today30; $status = "No Entitlement or Warranty active - set the default 90 days"; $free90 = "Y"; collect_vars($serial, $ver, $build, $datecollected, $free90, $free180, $startDate, $endDate, $username, $Exempt); record_visited($serial); } elseif($Entitlement_Status == "Expired"){ wh_log("Fixing security bug - set to 180 days --"); $endDate = $today180; $status = "No Entitlement or Warranty active and is Exempt - set to 180 days"; $free180 = "Y"; } else { //extract($latest_visited); $endDate = "SKIP"; //$enddate; $startDate = "SKIP"; //$startdate; } } generate_spt($serial, $startDate, $endDate, $evar, $supports, $licenses, $has_url_filtering); download_spt($serial); exit(); } else { wh_log("Has Pre Existing Spt: " . $serial); download_spt($serial); exit(); } } else { showForm(); exit(); } ?>