Contents of /mcore-src/trunk/mcore-tools/src/include/register.global.class.in
Parent Directory | Revision Log
Revision 2476 -
(show annotations)
(download)
Thu Sep 10 08:04:33 2015 UTC (8 years, 7 months ago) by niro
File size: 2198 byte(s)
Thu Sep 10 08:04:33 2015 UTC (8 years, 7 months ago) by niro
File size: 2198 byte(s)
-mtime should be always the actual timestamp
1 | # $Id$ |
2 | |
3 | validate_client() |
4 | { |
5 | local mac_address="$1" |
6 | local ip_address="$2" |
7 | local serial |
8 | local mtime |
9 | local serial_id |
10 | |
11 | if [[ -z ${mac_address} ]] |
12 | then |
13 | eecho "Error: No mac_address given" |
14 | return 1 |
15 | fi |
16 | |
17 | if [[ -z ${ip_address} ]] |
18 | then |
19 | eecho "Error: No ip_address given" |
20 | return 1 |
21 | fi |
22 | |
23 | decho "registering mac_address='${mac_address}'" |
24 | decho "registering ip_address='${ip_address}'" |
25 | |
26 | # first check if mac is registered |
27 | serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'") |
28 | |
29 | # current mtime |
30 | mtime=$(date +%s) |
31 | |
32 | if [[ -z ${serial} ]] |
33 | then |
34 | # request a new serial; one command now (cause must be done in the same session) |
35 | serial=$(mysqldo "insert into client_serials (mtime, mac) values('${mtime}','${mac_address}'); select last_insert_id();") |
36 | fi |
37 | |
38 | if [[ -z ${serial} ]] |
39 | then |
40 | return 1 |
41 | else |
42 | decho "serial='${serial}'" |
43 | rvecho "${serial}" |
44 | |
45 | SSLSAY_IP="${ip_address}" |
46 | SSLSAY_PORT="6666" |
47 | nsslsay_fingerprint "register '${serial}'" |
48 | |
49 | # register the client as online |
50 | serial_id=$(mysqldo "select serial from state_connected where serial=${serial};") |
51 | if [[ -n ${serial_id} ]] |
52 | then |
53 | mysqldo "update state_connected set ip='${ip_address}', mac='${mac_address}', mtime='${mtime}' where serial=${serial};" |
54 | else |
55 | mysqldo "insert into state_connected(serial,ip,mac,mtime) values('${serial}','${ip_address}','${mac_address}','${mtime}');" |
56 | fi |
57 | |
58 | return 0 |
59 | fi |
60 | } |
61 | |
62 | register_client() |
63 | { |
64 | local control_server_ip |
65 | local iface_ip |
66 | local iface |
67 | local mac_address |
68 | |
69 | control_server_ip=$(dns_to_ip ${MCORE_CONTROL_SERVER}) |
70 | iface_ip=$(iface_for_remote_addr ${control_server_ip}) |
71 | iface=$(iface_for_ip ${iface_ip}) |
72 | mac_address=$(mac_for_iface ${iface}) |
73 | |
74 | decho "MCORE_CONTROL_SERVER='${MCORE_CONTROL_SERVER}'" |
75 | decho "iface_ip='${iface_ip}'" |
76 | decho "iface='${iface}'" |
77 | decho "mac_address='${mac_address}'" |
78 | |
79 | decho "register '${mac_address}'" |
80 | nsslsay_fingerprint "register '${mac_address}' '${iface_ip}'" |
81 | } |
82 | |
83 | register_client_local() |
84 | { |
85 | local serial="$1" |
86 | |
87 | if [[ -z ${serial} ]] |
88 | then |
89 | eecho "No serial given" |
90 | return 1 |
91 | fi |
92 | |
93 | install -d "${MCORE_CONFIG_PATH}" |
94 | CONFIG="${MCORE_CONFIG_PATH}/serial" |
95 | clearconfig |
96 | addconfig "CLIENT_SERIAL=\"${serial}\"" |
97 | } |