Magellan Linux

Annotation of /mcore-src/trunk/mcore-tools/src/include/register.global.class.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2499 - (hide annotations) (download)
Fri Sep 11 07:36:40 2015 UTC (8 years, 8 months ago) by niro
File size: 2299 byte(s)
-renamed set_hardware_detect() to run_hardware_detect() and provide a new set class to run the hardware detection to fix run_clasS() evaluation issues
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 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 niro 2445 decho "registering ip_address='${ip_address}'"
25 niro 2439
26 niro 2430 # first check if mac is registered
27     serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'")
28    
29 niro 2476 # current mtime
30     mtime=$(date +%s)
31    
32 niro 2430 if [[ -z ${serial} ]]
33     then
34     # request a new serial; one command now (cause must be done in the same session)
35 niro 2431 serial=$(mysqldo "insert into client_serials (mtime, mac) values('${mtime}','${mac_address}'); select last_insert_id();")
36 niro 2430 fi
37    
38 niro 2433 if [[ -z ${serial} ]]
39     then
40     return 1
41     else
42 niro 2441 decho "serial='${serial}'"
43     rvecho "${serial}"
44 niro 2442
45 niro 2445 SSLSAY_IP="${ip_address}"
46 niro 2442 SSLSAY_PORT="6666"
47 niro 2447 nsslsay_fingerprint "register '${serial}'"
48 niro 2442
49 niro 2457 # 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 niro 2497 # run hardware detection
59     if is_provided hardware
60     then
61 niro 2499 run_hardware_detect "${serial}"
62 niro 2497 fi
63    
64 niro 2433 return 0
65     fi
66 niro 2430 }
67    
68     register_client()
69     {
70     local control_server_ip
71     local iface_ip
72     local iface
73     local mac_address
74    
75     control_server_ip=$(dns_to_ip ${MCORE_CONTROL_SERVER})
76     iface_ip=$(iface_for_remote_addr ${control_server_ip})
77     iface=$(iface_for_ip ${iface_ip})
78     mac_address=$(mac_for_iface ${iface})
79    
80 niro 2439 decho "MCORE_CONTROL_SERVER='${MCORE_CONTROL_SERVER}'"
81     decho "iface_ip='${iface_ip}'"
82     decho "iface='${iface}'"
83     decho "mac_address='${mac_address}'"
84 niro 2430
85 niro 2439 decho "register '${mac_address}'"
86 niro 2447 nsslsay_fingerprint "register '${mac_address}' '${iface_ip}'"
87 niro 2430 }
88 niro 2442
89     register_client_local()
90     {
91     local serial="$1"
92    
93     if [[ -z ${serial} ]]
94     then
95     eecho "No serial given"
96     return 1
97     fi
98    
99 niro 2461 install -d "${MCORE_CONFIG_PATH}"
100 niro 2442 CONFIG="${MCORE_CONFIG_PATH}/serial"
101     clearconfig
102     addconfig "CLIENT_SERIAL=\"${serial}\""
103     }