-
Notifications
You must be signed in to change notification settings - Fork 0
/
ws-node-add
executable file
·48 lines (42 loc) · 1.29 KB
/
ws-node-add
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
#!/bin/php
<?php
# WildlifeSystems
#
# This script is part of the WildlifeSystems project. For further information
# please refer to https://docs.wildlife.systems, or for more information on
# the project itself, please refer to https://wildlife.systems.
#Include database file in user's home directory
$home = getenv("HOME");
if (!file_exists($home."/.ws-db.php")) {
print(".ws-db.php does not exist.\nSee https://github.com/Wildlife-Systems/wildlife.systems-tools/wiki/.ws-db.php-does-not-exist\n\n");
exit(1);
}
include($home."/.ws-db.php");
$mode = null;
if (!isset($argv[1]) || in_array($argv[1], array("help", "-h"))) {
$mode = "help";
}
switch($mode) {
case "help":
print("Usage:\n");
print(" ws-node-add <node_id>\n");
print("\n");
break;
default:
$sql = "INSERT INTO `nodes` VALUES('"
. $db->real_escape_string($argv[1])
. "', UUID());";
if (!$result = $db->query($sql)) {
print("Add node failed.\n\n");
exit(2);
} else {
$sql = "SELECT `node_token` FROM `nodes` WHERE `node_id` = '"
. $db->real_escape_string($argv[1])
. "';";
if ($result = $db->query($sql)) {
$res_arr = $result->fetch_assoc();
print("Node token: ");
print($res_arr["node_token"]."\n\n");
}
}
}