-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
140 lines (111 loc) · 4.1 KB
/
index.html
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>iTalcConfigGenerator</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<style>
body {
padding-top: 10px;
}
</style>
<body class="container">
<div class="jumbotron">
<h1>iTalcConfigGenerator</h1>
<p>A small tool to generate the GlobalConfig.xml file for <a href="http://italc.sourceforge.net" target="_blank">iTalc</a> classroom configuration.</p>
</div>
<form id="form">
<div class="form-group row">
<label for="nbComputer" class="col-sm-3 col-form-label">Number of student computers:</label>
<div class="col-sm-3">
<input type="number" min="1" step="1" value="20" id="nbComputer" class="form-control" />
</div>
</div>
<div class="form-group row">
<label for="classroomName" class="col-sm-3 col-form-label">Classroom name:</label>
<div class="col-sm-3">
<input type="text" placeholder="B100" id="classroomName" class="form-control" />
</div>
<small class="col-sm-6 form-text text-muted">
also prefix of computer name
</small>
</div>
<div class="form-group row">
<label for="ipPrefix" class="col-sm-3 col-form-label">IP address prefix:</label>
<div class="col-sm-3">
<input type="text" id="ipPrefix" placeholder="10.0.5." class="form-control" />
</div>
</div>
<div class="offset-sm-3">
<button type="submit" class="btn btn-primary">Generate !</button>
</div>
</form>
<br />
<p>
Save this file on your teacher computer and define the global configuration path in the <i>iTalc Management Console</i>.
</p>
<br /><br />
<div class="text-center">
<small>
Available on <a href="https://github.com/philippemilink/iTalcConfigGenerator">GitHub</a>.
</small>
</div>
<script src="https://cdn.rawgit.com/eligrey/FileSaver.js/b4a918669accb81f184c610d741a4a8e1306aa27/FileSaver.min.js" type="text/javascript"></script>
<script type="text/javascript">
function getRandomId() {
return Math.floor(((Math.random() * (1 << 20)) + 1));
}
function getPossibleRandomId(impossibles) {
var tempRandom;
do {
tempRandom = getRandomId();
var found = false;
for (var i = 0, limit = impossibles.length; i < limit; i++) {
if (impossibles[i] == tempRandom) {
found = true;
break;
}
}
} while(found);
return tempRandom;
}
function generateClients(nbClients, classroomName, ipPrefix) {
var clientIds = [];
var clients = "";
for (var i = 1; i <= nbClients; i++) {
var random = getPossibleRandomId(clientIds);
clientIds.push(random);
clients += '\t\t\t<client hostname="' + ipPrefix + i + '" name="' + classroomName + '-';
if (i < 10) {
clients += '0';
}
clients += i + '" mac="" id="' + random + '" type="0"/>\n';
}
return clients;
}
var fileHeader = '<?xml version="1.0"?>\n' +
'<!DOCTYPE italc-config-file>\n' +
'<globalclientconfig version="3.0.3">\n' +
'\t<body>\n';
var fileFooter = '\t\t</classroom>\n' +
'\t</body>\n' +
'</globalclientconfig>'
var form = document.getElementById("form");
var nbComputerField = document.getElementById("nbComputer");
var classroomNameField = document.getElementById("classroomName");
var ipPrefixField = document.getElementById("ipPrefix");
form.addEventListener("submit", (e) => {
e.preventDefault();
var classroomName = classroomNameField.value;
var nbComputer = parseInt(nbComputerField.value);
var ipPrefix = ipPrefixField.value;
var generated = '\t\t<classroom name="' + classroomName + '">\n';
generated += generateClients(nbComputer, classroomName, ipPrefix);
var blob = new Blob([fileHeader + generated + fileFooter], {type: "text/plain;charset=utf-8"});
saveAs(blob, "GlobalConfig.xml");
});
</script>
</body>
</html>