ELS scanner 1.0

This commit is contained in:
massta 2019-11-24 19:02:22 +01:00
parent 03e337c236
commit 72a07c8a8b
10 changed files with 5695 additions and 0 deletions

55
lsscanner/new/addclasses.html Executable file
View File

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<meta charset="UTF-8">
<title>Add classes</title>
</head>
<body>
<div class="container">
<form>
<div>
<h5 class="center">Enter class data</h3>
<br /> Professor:
<input type="text" id="professor" required autofocus/>
<br /> Class name:
<input type="text" id="name" required autofocus/>
<br /> Date:
<input type="datetime-local" id="date" class="c-datepicker-input" required autofocus/>
</div>
<br />
<button class="btn waves-effect waves-light" type="submit">Add</button>
</form>
</div>
<script>
const electron = require('electron');
const {
ipcRenderer
} = electron;
const form = document.querySelector("form");
form.addEventListener("submit", submitForm);
function submitForm(e) {
e.preventDefault();
var name = document.querySelector("#name").value;
var professor = document.querySelector("#professor").value;
var date = document.querySelector("#date").value;
var item = [name, professor, date];
ipcRenderer.send("item:add_class", item);
}
</script>
</body>
</html>

42
lsscanner/new/addstudent.html Executable file
View File

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<meta charset="UTF-8">
<title>Add student</title>
</head>
<body>
<div class="container">
<form>
<div>
<h5 class="center">Enter student data</h3> <br />
Name: <input type="text" id="name" required autofocus/> <br />
Surname: <input type="text" id="surname" required autofocus/> <br />
Index: <input type="text" id="index" required autofocus/> <br />
</div>
<br />
<button class="btn waves-effect waves-light" type="submit">Add</button>
</form>
</div>
<script>
const electron = require('electron');
const {ipcRenderer} = electron;
const form = document.querySelector("form");
form.addEventListener("submit",submitForm);
function submitForm(e){
e.preventDefault();
var name = document.querySelector("#name").value;
var surname = document.querySelector("#surname").value;
var index = document.querySelector("#index").value;
const item = [name,surname,index];
ipcRenderer.send("item:add",item);
}
</script>
</body>
</html>

57
lsscanner/new/index.html Executable file
View File

@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<meta charset="UTF-8">
<title>Student counter</title>
</head>
<body>
<nav>
<div class="nav-wrapper">
<a class="brand-logo center">Student counter</a>
</div>
</nav>
<ul>
</ul>
<script>
const electron = require('electron');
const {ipcRenderer} = electron;
const ul = document.querySelector("ul");
ipcRenderer.on("item:add",function(e,item) {
console.log(item);
ul.className = "collection";
const li = document.createElement('li');
li.className = "collection-item";
var date = item[3] ? item[3] : Date.now();
const itemText = document.createTextNode(item[0] + " " + item[1] + " " + item[2] + " " + date);
li.appendChild(itemText);
li.id = item[2];
ul.appendChild(li);
});
ul.addEventListener('dblclick',removeItem);
function removeItem(item) {
ipcRenderer.send("item:delete",item.target.id);
item.target.remove();
if (ul.children.length == 0) {
ul.className = "";
}
}
</script>
</html>

BIN
lsscanner/new/info.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

365
lsscanner/new/main.js Executable file
View File

@ -0,0 +1,365 @@
//Get required packages
const electron = require('electron');
const path = require('path');
const url = require('url');
const fs = require('fs');
const asn1js = require('asn1js');
const util = require('util');
const notifier = require('node-notifier');
const smartcard = require('smartcard');
const {
app,
BrowserWindow,
Menu,
ipcMain
} = electron;
const Devices = smartcard.Devices;
const devices = new Devices();
const Iso7816Application = smartcard.Iso7816Application;
let mainWindow;
let AddWindow;
let AddClassesWindow;
let SelectClassesWindow;
var current_classes = -1;
//Listen for the app to be ready
app.on('ready', function () {
//Create new window
mainWindow = new BrowserWindow({
width: 500,
height: 600,
webPreferences: {
nodeIntegration: true
}});
//Load html into window
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
}));
//Quit app when closed
mainWindow.on("closed", function () {
app.quit();
})
//Menu from template
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
Menu.setApplicationMenu(mainMenu);
});
devices.on('device-activated', event => {
console.log('Smart card reader active');
const currentDevices = event.devices;
let device = event.device;
device.on('error', function (message) {
console.log(`Error '${message}' received`);
});
device.on('card-inserted', event => {
let card = event.card;
//console.log(`Card '${card.getAtr()}' inserted into '${event.device}'` + '\n');
const application = new Iso7816Application(card);
application.selectFile([0xD6, 0x16, 0x00, 0x00, 0x30, 0x01, 0x01])
.then(response => {
console.info(`Response: '${response}' '${response.meaning()}'`);
application.issueCommand([0x00, 0xA4, 0x02, 0x00, 0x02, 0x00, 0x02, 0x12])
.then(response => {
console.info(`Response: '${response}' '${response.meaning()}'`);
application.issueCommand([0x00, 0xB0, 0x00, 0x00, 0xF8])
.then(response => {
console.info(`Response: '${response}' '${response.meaning()}'`);
var response2 = `${response}`;
var start = response2.indexOf("2a8468016504010101") + 18;
response2 = response2.substring(start);
while (1) {
var type = response2.substring(0, 2);
if (type == "30") break;
if (parseInt(response2.substring(2, 4), 16) > 127) {
var count = parseInt(response2.substring(2, 4), 16) - 128;
var length = "";
var k = 1;
for (k = 1; k <= count; k++) {
length += response2.substring(2 + (k * 2), 4 + (k * 2));
}
var total_length = parseInt(length, 16) * 2;
response2 = response2.substr(4 + (k - 1) * 2, total_length);
} else {
var total_length = parseInt(response2.substring(2, 4), 16) * 2 + 4;
response2 = response2.substr(4, total_length);
}
}
//region How to work with ASN.1 strings
let bmp_string_encoded = new ArrayBuffer(response2.length / 2);
let bmp_string_view = new Uint8Array(bmp_string_encoded);
var kk = 0;
for (var i = 0; i < (response2.length / 2); i++) {
bmp_string_view[i] = "0x" + response2.substring(kk, kk + 2);
kk += 2;
}
let bmp_string_decoded = asn1js.fromBER(bmp_string_encoded);
if (bmp_string_decoded.offset === (-1)) return; // Error during decoding
let obj = bmp_string_decoded.result.valueBlock.value;
var names = obj[4].valueBlock.value[0].valueBlock.value;
var surnames = obj[3].valueBlock.value[0].valueBlock.value;
var index = obj[5].valueBlock.value;
var output = [names, surnames, index];
printStudent(output);
}).catch(error => {
//console.error('Error:', error, error.stack + '\n');
});
}).catch(error => {
//console.error('Error:', error, error.stack + '\n');
});
}).catch(error => {
//console.error('Error:', error, error.stack + '\n');
});
});
device.on('card-removed', event => {
console.log(`Card removed from '${event.name}' ` + '\n');
});
});
devices.on('device-deactivated', event => {
console.log(`Device '${event.device}' deactivated, devices: [${event.devices}]` + '\n');
});
//Add student manually
function createAddWindow() {
//Create new window
AddWindow = new BrowserWindow({
width: 300,
height: 400,
title: "Add student manually"
});
//Load html into window
AddWindow.loadURL(url.format({
pathname: path.join(__dirname, "addstudent.html"),
protocol: "file:",
slashes: true
}));
//Garbage
AddWindow.on("close", function () {
AddWindow = null;
});
}
function createAddClassesWindow() {
//Create new window
AddClassesWindow = new BrowserWindow({
width: 350,
height: 500,
title: "Add classes"
});
//Load html into window
AddClassesWindow.loadURL(url.format({
pathname: path.join(__dirname, "addclasses.html"),
protocol: "file:",
slashes: true
}));
//Garbage
AddClassesWindow.on("close", function () {
AddClassesWindow = null;
});
}
function createSelectClassesWindow() {
//Create new window
SelectClassesWindow = new BrowserWindow({
width: 500,
height: 475,
title: "Add classes"
});
//Load html into window
SelectClassesWindow.loadURL(url.format({
pathname: path.join(__dirname, "selectclasses.html"),
protocol: "file:",
slashes: true
}));
//Garbage
SelectClassesWindow.on("close", function () {
SelectClassesWindow = null;
});
}
function printStudent(item) {
var dateTime = require('node-datetime');
var dt = dateTime.create();
var formatted = dt.format('d-m-Y H:M:S');
item.push(formatted);
mainWindow.webContents.send("item:add", item);
notifier.notify({
title: "Student registered",
message: item[0] + " " + item[1],
icon: path.join(__dirname, 'ok.png')
});
/*
if (false) { //current_classes == -1
notifier.notify({
title: "No current classes selected",
message: "Adding student unsuccessful",
icon: path.join(__dirname, 'wrong.png')
});
} else {
if (true) {
var dateTime = require('node-datetime');
var dt = dateTime.create();
var formatted = dt.format('d-m-Y H:M:S');
item.push(formatted);
console.log(item);
mainWindow.webContents.send("item:add", item);
notifier.notify({
title: "Student registered",
message: item[0] + " " + item[1],
icon: path.join(__dirname, 'ok.png')
});
} else {
notifier.notify({
title: "Student already exists",
message: item[0] + " " + item[1],
icon: path.join(__dirname, 'wrong.png')
});
}
}*/
}
//Catch
ipcMain.on("item:add", function (e, item) {
printStudent(item);
AddWindow.close();
})
//Menu template
const mainMenuTemplate = [{
label: "Student",
submenu: [{
label: "Add student",
accelerator: process.platfrom == "darwin" ? "Command+E" : "Ctrl+E",
click() {
createAddWindow();
}
},
{
label: "Quit program",
accelerator: process.platfrom == "darwin" ? "Command+Q" : "Ctrl+Q",
click() {
app.quit();
}
}
]
}, {
label: "Classes",
submenu: [{
label: "Add classes",
click() {
createAddClassesWindow();
}
},
{
label: "Pick classes",
click() {
createSelectClassesWindow();
}
}
]
}];
//If mac psuh empty obj to Menu
if (process.platfrom == "darwin") {
mainMenuTemplate.unshift({});
}
//Add dev tools on DEV
if (process.env.NODE_ENV !== 'production') {
mainMenuTemplate.push({
label: "DEV",
submenu: [{
label: "Toggle dev tools",
accelerator: process.platfrom == "darwin" ? "Command+I" : "Ctrl+I",
click(item, focusedWindow) {
focusedWindow.toggleDevTools();
}
},
{
role: "reload"
}
]
});
}

BIN
lsscanner/new/ok.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

5102
lsscanner/new/package-lock.json generated Executable file

File diff suppressed because it is too large Load Diff

25
lsscanner/new/package.json Executable file
View File

@ -0,0 +1,25 @@
{
"name": "atcheck",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron ."
},
"author": "Me",
"license": "ISC",
"devDependencies": {
"electron": "^7.1.2",
"electron-rebuild": "^1.8.8"
},
"dependencies": {
"asn1js": "^2.0.26",
"fs": "0.0.1-security",
"node-datetime": "^2.1.2",
"node-notifier": "^6.0.0",
"npm": "^6.13.1",
"pcsclite": "^1.0.0",
"smartcard": "^1.0.32"
}
}

View File

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<meta charset="UTF-8">
<title>Student counter</title>
</head>
<body>
<nav>
<div class="nav-wrapper">
<a class="brand-logo center">Select classes</a>
</div>
</nav>
<ul>
</ul>
<script>
const electron = require('electron');
const {ipcRenderer} = electron;
const ul = document.querySelector("ul");
ipcRenderer.send("item:start");
ipcRenderer.on("item:add_select_classes",function(e,item) {
ul.className = "collection";
const li = document.createElement('li');
li.className = "collection-item";
li.id = item[3];
li.style.cursor = "pointer";
const itemText = document.createTextNode(item[0] + " " + item[1] + " " + item[2]);
li.appendChild(itemText);
ul.appendChild(li);
});
ul.addEventListener('click',selectItem);
function selectItem(item) {
ipcRenderer.send("item:select",item.target.id);
}
</script>
</html>

BIN
lsscanner/new/wrong.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB