Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2447 - (hide annotations) (download)
Thu Sep 3 13:47:44 2015 UTC (8 years, 8 months ago) by niro
File size: 1716 byte(s)
-use oneline nsslsay cmds
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 2430
10     if [[ -z ${mac_address} ]]
11     then
12     eecho "Error: No mac_address given"
13     return 1
14     fi
15    
16 niro 2442 if [[ -z ${ip_address} ]]
17     then
18     eecho "Error: No ip_address given"
19     return 1
20     fi
21    
22 niro 2439 decho "registering mac_address='${mac_address}'"
23 niro 2445 decho "registering ip_address='${ip_address}'"
24 niro 2439
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 niro 2445 SSLSAY_IP="${ip_address}"
44 niro 2442 SSLSAY_PORT="6666"
45 niro 2447 nsslsay_fingerprint "register '${serial}'"
46 niro 2442
47 niro 2433 return 0
48     fi
49 niro 2430 }
50    
51     register_client()
52     {
53     local control_server_ip
54     local iface_ip
55     local iface
56     local mac_address
57    
58     control_server_ip=$(dns_to_ip ${MCORE_CONTROL_SERVER})
59     iface_ip=$(iface_for_remote_addr ${control_server_ip})
60     iface=$(iface_for_ip ${iface_ip})
61     mac_address=$(mac_for_iface ${iface})
62    
63 niro 2439 decho "MCORE_CONTROL_SERVER='${MCORE_CONTROL_SERVER}'"
64     decho "iface_ip='${iface_ip}'"
65     decho "iface='${iface}'"
66     decho "mac_address='${mac_address}'"
67 niro 2430
68 niro 2439 decho "register '${mac_address}'"
69 niro 2447 nsslsay_fingerprint "register '${mac_address}' '${iface_ip}'"
70 niro 2430 }
71 niro 2442
72     register_client_local()
73     {
74     local serial="$1"
75    
76     if [[ -z ${serial} ]]
77     then
78     eecho "No serial given"
79     return 1
80     fi
81    
82     CONFIG="${MCORE_CONFIG_PATH}/serial"
83     clearconfig
84     addconfig "CLIENT_SERIAL=\"${serial}\""
85     }