Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2435 by niro, Thu Sep 3 12:35:41 2015 UTC revision 2497 by niro, Thu Sep 10 14:08:40 2015 UTC
# Line 3  Line 3 
3  validate_client()  validate_client()
4  {  {
5   local mac_address="$1"   local mac_address="$1"
6     local ip_address="$2"
7   local serial   local serial
8   local mtime   local mtime
9     local serial_id
10    
11   if [[ -z ${mac_address} ]]   if [[ -z ${mac_address} ]]
12   then   then
# Line 12  validate_client() Line 14  validate_client()
14   return 1   return 1
15   fi   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   # first check if mac is registered
27   serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'")   serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'")
28    
29     # current mtime
30     mtime=$(date +%s)
31    
32   if [[ -z ${serial} ]]   if [[ -z ${serial} ]]
33   then   then
  mtime=$(date +%s)  
   
34   # request a new serial; one command now (cause must be done in the same session)   # 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();")   serial=$(mysqldo "insert into client_serials (mtime, mac) values('${mtime}','${mac_address}'); select last_insert_id();")
36   fi   fi
# Line 27  validate_client() Line 39  validate_client()
39   then   then
40   return 1   return 1
41   else   else
42   echo "serial='${serial}'"   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     # run hardware detection
59     if is_provided hardware
60     then
61     set_hardware_detect "${serial}"
62     fi
63    
64   return 0   return 0
65   fi   fi
66  }  }
# Line 44  register_client() Line 77  register_client()
77   iface=$(iface_for_ip ${iface_ip})   iface=$(iface_for_ip ${iface_ip})
78   mac_address=$(mac_for_iface ${iface})   mac_address=$(mac_for_iface ${iface})
79    
80   echo "DEBUG: MCORE_CONTROL_SERVER='${MCORE_CONTROL_SERVER}'"   decho "MCORE_CONTROL_SERVER='${MCORE_CONTROL_SERVER}'"
81   echo "DEBUG: iface_ip='${iface_ip}'"   decho "iface_ip='${iface_ip}'"
82   echo "DEBUG: iface='${iface}'"   decho "iface='${iface}'"
83   echo "DEBUG: mac_address='${mac_address}'"   decho "mac_address='${mac_address}'"
84    
85     decho "register '${mac_address}'"
86     nsslsay_fingerprint "register '${mac_address}' '${iface_ip}'"
87    }
88    
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   echo "register '${mac_address}'"   install -d "${MCORE_CONFIG_PATH}"
100   nsslsay_fingerprint "register '${mac_address}'"   CONFIG="${MCORE_CONFIG_PATH}/serial"
101     clearconfig
102     addconfig "CLIENT_SERIAL=\"${serial}\""
103  }  }

Legend:
Removed from v.2435  
changed lines
  Added in v.2497