Annotation of /mcore-src/trunk/mcore-tools/src/include/register.global.class.in
Parent Directory | Revision Log
Revision 2506 -
(hide annotations)
(download)
Fri Sep 11 09:53:49 2015 UTC (8 years, 8 months ago) by niro
File size: 2749 byte(s)
Fri Sep 11 09:53:49 2015 UTC (8 years, 8 months ago) by niro
File size: 2749 byte(s)
-import client version information on register
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 | 2457 | local serial_id |
10 | niro | 2506 | local os |
11 | local tools | ||
12 | niro | 2430 | |
13 | if [[ -z ${mac_address} ]] | ||
14 | then | ||
15 | eecho "Error: No mac_address given" | ||
16 | return 1 | ||
17 | fi | ||
18 | |||
19 | niro | 2442 | if [[ -z ${ip_address} ]] |
20 | then | ||
21 | eecho "Error: No ip_address given" | ||
22 | return 1 | ||
23 | fi | ||
24 | |||
25 | niro | 2439 | decho "registering mac_address='${mac_address}'" |
26 | niro | 2445 | decho "registering ip_address='${ip_address}'" |
27 | niro | 2439 | |
28 | niro | 2430 | # first check if mac is registered |
29 | serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'") | ||
30 | |||
31 | niro | 2476 | # current mtime |
32 | mtime=$(date +%s) | ||
33 | |||
34 | niro | 2430 | if [[ -z ${serial} ]] |
35 | then | ||
36 | # request a new serial; one command now (cause must be done in the same session) | ||
37 | niro | 2431 | serial=$(mysqldo "insert into client_serials (mtime, mac) values('${mtime}','${mac_address}'); select last_insert_id();") |
38 | niro | 2430 | fi |
39 | |||
40 | niro | 2433 | if [[ -z ${serial} ]] |
41 | then | ||
42 | return 1 | ||
43 | else | ||
44 | niro | 2441 | decho "serial='${serial}'" |
45 | rvecho "${serial}" | ||
46 | niro | 2442 | |
47 | niro | 2445 | SSLSAY_IP="${ip_address}" |
48 | niro | 2442 | SSLSAY_PORT="6666" |
49 | niro | 2447 | nsslsay_fingerprint "register '${serial}'" |
50 | niro | 2442 | |
51 | niro | 2457 | # register the client as online |
52 | serial_id=$(mysqldo "select serial from state_connected where serial=${serial};") | ||
53 | if [[ -n ${serial_id} ]] | ||
54 | then | ||
55 | mysqldo "update state_connected set ip='${ip_address}', mac='${mac_address}', mtime='${mtime}' where serial=${serial};" | ||
56 | else | ||
57 | mysqldo "insert into state_connected(serial,ip,mac,mtime) values('${serial}','${ip_address}','${mac_address}','${mtime}');" | ||
58 | fi | ||
59 | |||
60 | niro | 2506 | # update tools and os version info |
61 | nsslsay_queue_init | ||
62 | nsslsay_queue_add "nocolors" | ||
63 | nsslsay_queue_add "get version.os" | ||
64 | os=$(control_client "${serial}" run-queue) | ||
65 | import_resource client_version "${serial}" os "${os}" | ||
66 | nsslsay_queue_init | ||
67 | nsslsay_queue_add "nocolors" | ||
68 | nsslsay_queue_add "get version.tools" | ||
69 | os=$(control_client "${serial}" run-queue) | ||
70 | import_resource client_version "${serial}" utils "${tools}" | ||
71 | |||
72 | niro | 2497 | # run hardware detection |
73 | if is_provided hardware | ||
74 | then | ||
75 | niro | 2499 | run_hardware_detect "${serial}" |
76 | niro | 2497 | fi |
77 | |||
78 | niro | 2433 | return 0 |
79 | fi | ||
80 | niro | 2430 | } |
81 | |||
82 | register_client() | ||
83 | { | ||
84 | local control_server_ip | ||
85 | local iface_ip | ||
86 | local iface | ||
87 | local mac_address | ||
88 | |||
89 | control_server_ip=$(dns_to_ip ${MCORE_CONTROL_SERVER}) | ||
90 | iface_ip=$(iface_for_remote_addr ${control_server_ip}) | ||
91 | iface=$(iface_for_ip ${iface_ip}) | ||
92 | mac_address=$(mac_for_iface ${iface}) | ||
93 | |||
94 | niro | 2439 | decho "MCORE_CONTROL_SERVER='${MCORE_CONTROL_SERVER}'" |
95 | decho "iface_ip='${iface_ip}'" | ||
96 | decho "iface='${iface}'" | ||
97 | decho "mac_address='${mac_address}'" | ||
98 | niro | 2430 | |
99 | niro | 2439 | decho "register '${mac_address}'" |
100 | niro | 2447 | nsslsay_fingerprint "register '${mac_address}' '${iface_ip}'" |
101 | niro | 2430 | } |
102 | niro | 2442 | |
103 | register_client_local() | ||
104 | { | ||
105 | local serial="$1" | ||
106 | |||
107 | if [[ -z ${serial} ]] | ||
108 | then | ||
109 | eecho "No serial given" | ||
110 | return 1 | ||
111 | fi | ||
112 | |||
113 | niro | 2461 | install -d "${MCORE_CONFIG_PATH}" |
114 | niro | 2442 | CONFIG="${MCORE_CONFIG_PATH}/serial" |
115 | clearconfig | ||
116 | addconfig "CLIENT_SERIAL=\"${serial}\"" | ||
117 | } |