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