forked from dudw/serial_generator
-
Notifications
You must be signed in to change notification settings - Fork 4
/
script.js
88 lines (69 loc) · 2.53 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
$(function () {
$("#generate").click(function () {
$("#sn").val(generateSerial($("#model").val()));
});
$("#generate").click(function () {
$("#mac").val(generateMac($("#model").val()));
});
$.getJSON("synology.json", function(json) {
$("#model").empty();
$("#model").append($('<option>').text("Select model"));
$.each(json, function(i, obj){
$("#model").append($('<option>').text(obj.model).attr('value', obj.permanent));
});
});
});
function generateMac(permanent) {
if(permanent == "Select model")
return "Please select a model first!";
return "001132" + random(1048576, 16777215).toString(16).toUpperCase();
}
function generateSerial(permanent) {
if(permanent == "Select model") {
return "Please select a model first!";
}
if (permanent == "SJR" || permanent == "SBR") {
var beginArray = [
"2030",
"2040",
"20C0",
"2150"
];
return (beginArray[Math.floor(Math.random()*beginArray.length)] + permanent + generateRandomLetter() + generateRandomValue() + generateRandomValue() + generateRandomValue() + generateRandomValue() + generateRandomLetter()).toUpperCase();
}
else if (permanent == "RFR") {
var beginArray = [
"1930",
"1940"
];
return (beginArray[Math.floor(Math.random()*beginArray.length)] + permanent + generateRandomLetter() + generateRandomValue() + generateRandomValue() + generateRandomValue() + generateRandomValue() + generateRandomLetter()).toUpperCase();
}
else if (permanent == "PDN") {
var beginArray = [
"1780",
"1790",
"1860",
"1980"
];
return (beginArray[Math.floor(Math.random()*beginArray.length)] + permanent + padLeft(random(1,030000),6)).toUpperCase();
}
else {
return (random(11,14) + "30" + permanent + padLeft(random(1,030000),6)).toUpperCase();
}
}
function padLeft(nr, n) {
return Array(n - String(nr).length + 1).join('0') + nr;
}
function random(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function generateRandomLetter() {
const alphabet = "abcdefghjklmnpqrstvwxyz"
return alphabet[Math.floor(Math.random() * alphabet.length)]
}
function generateRandomValue() {
const alphabet = "0123456789abcdefghjklmnpqrstvwxyz"
return alphabet[Math.floor(Math.random() * alphabet.length)]
}