CMXX - Update software downloader
This commit is contained in:
@@ -8,7 +8,7 @@ defined($security_key) or exit;
|
||||
// translated from JS (kevinboutin on 3/11/18) to PHP
|
||||
// https://gist.github.com/kevboutin/3ac029e336fc7cafd20c05adda42ffa5
|
||||
//------------------------------------------
|
||||
// Transliterate VIN characters for validation
|
||||
/* Transliterate VIN characters for validation
|
||||
function transliterate($c) {
|
||||
$index = strpos('0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ', $c);
|
||||
return $index % 10;
|
||||
@@ -27,6 +27,41 @@ function getCheckDigit($vin) {
|
||||
function validateVIN($vin) {
|
||||
if (strlen($vin) !== 17) return false;
|
||||
return getCheckDigit($vin) === $vin[8];
|
||||
}*/
|
||||
|
||||
function validateVIN($vin) {
|
||||
|
||||
$vin = strtolower($vin);
|
||||
if (!preg_match('/^[^\Wioq]{17}$/', $vin)) {
|
||||
return false;
|
||||
}
|
||||
$weights = array(8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2);
|
||||
$transliterations = array(
|
||||
"a" => 1, "b" => 2, "c" => 3, "d" => 4,
|
||||
"e" => 5, "f" => 6, "g" => 7, "h" => 8,
|
||||
"j" => 1, "k" => 2, "l" => 3, "m" => 4,
|
||||
"n" => 5, "p" => 7, "r" => 9, "s" => 2,
|
||||
"t" => 3, "u" => 4, "v" => 5, "w" => 6,
|
||||
"x" => 7, "y" => 8, "z" => 9
|
||||
);
|
||||
$sum = 0;
|
||||
for($i = 0 ; $i < strlen($vin) ; $i++ ) { // loop through characters of VIN
|
||||
// add transliterations * weight of their positions to get the sum
|
||||
$check_char = substr($vin, $i, 1);
|
||||
if(!is_numeric($check_char)) {
|
||||
$sum += $transliterations[$check_char] * $weights[$i];
|
||||
} else {
|
||||
$sum += $check_char * $weights[$i];
|
||||
}
|
||||
}
|
||||
|
||||
// find checkdigit by taking the mod of the sum
|
||||
$checkdigit = $sum % 11;
|
||||
if($checkdigit == 10) { // checkdigit of 10 is represented by "X"
|
||||
$checkdigit = "x";
|
||||
}
|
||||
$actual_checkdigit = substr($vin, 8, 1);
|
||||
return ($checkdigit == $actual_checkdigit);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
@@ -79,14 +114,15 @@ if (strlen($get_content) == 17){
|
||||
|
||||
$messages = [
|
||||
"VIN" => $vin,
|
||||
"IsValid" => (validateVIN($vin) ? "Yes" : "No"),
|
||||
"Manufacturer" => getManufacturer(getWMI($vin)),
|
||||
"year" => getYear(getVIS($vin))
|
||||
];
|
||||
}
|
||||
else {
|
||||
$messages = [
|
||||
"IsValid" => "No"
|
||||
"VIN" => $vin,
|
||||
"Manufacturer" => "Unknown",
|
||||
"year" => "Unknown"
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user