160 |
161 |
162 |
163 |
--------------------------------------------------------------------------------
/module/api/api.js:
--------------------------------------------------------------------------------
1 | const ip = require('ip');
2 | const mysql = require('mysql');
3 | // Standard MD5 hashing algorithm
4 | const md5 = require('./../md5/md5.js');
5 | // Standard FIPS 202 SHA-3 implementation
6 | const { SHA3 } = require('sha3');
7 | // The Keccak hash function is also available
8 | const { Keccak } = require('sha3');
9 |
10 | // Generate timestamp: if full argument is false/undefined,
11 | // timestamp is divided by 1000 to generate linux-length timestamp
12 | function timestamp(full) {
13 | let date = new Date();
14 | let timestamp = date.getTime();
15 | return full ? Math.floor(timestamp) : Math.floor(timestamp / 1000);
16 | }
17 |
18 | // Generate string "1s", "2h", etc between now and "time" argument
19 | function elapsed( time ) {
20 | const $SECONDS = Math.abs(timestamp() - time);
21 | const $iv_table = ["s","min","h","d","mo","y","s","min","h","d","mo","y"];
22 | const $iv = [$SECONDS,
23 | ($SECONDS-($SECONDS%60))/60,
24 | ($SECONDS-($SECONDS%3600))/3600,
25 | ($SECONDS-($SECONDS%(3600*24)))/(3600*24),
26 | ($SECONDS-($SECONDS%(3600*24*30)))/(3600*24*30),
27 | ($SECONDS-($SECONDS%(3600*24*30*12)))/(3600*24*30*12)];
28 | for (let $i = 5; $i >= 0; $i--) {
29 | $r = $iv[$i];
30 | if ($r > 0) {
31 | if (($r > 1 || $r == 0))
32 | $i += 6;
33 | return $r + "" + $iv_table[$i];
34 | }
35 | }
36 | }
37 |
38 | // Check if property with value exists on an object
39 | Object.prototype.exists = function(property_name, value) {
40 | for (let i = 0; i < this.length; i++) {
41 | let o = this[i];
42 | if (o[property_name] != undefined)
43 | if (o[property_name] == value)
44 | return true;
45 | }
46 | return false;
47 | }
48 |
49 | // Check if value exists in array
50 | Array.prototype.exists = function(value) {
51 | for (let i = 0; i < this.length; i++)
52 | if (this[i] == value)
53 | return true;
54 | return false;
55 | }
56 |
57 | class database {
58 | constructor() { }
59 | static create() {
60 | let message = "Creating MySQL connection...";
61 | this.connection = mysql.createConnection({
62 | host : 'XX.XX.XX.XXX', // or localhost
63 | user : 'root',
64 | password : 'PassWord123!',
65 | database : 'databasename'
66 | });
67 | this.connection.connect();
68 | console.log(message + "Ok.");
69 | }
70 | }
71 |
72 | // Requires payload.email_address =