validate_client() { local mac_address="$1" local serial local mtime if [[ -z ${mac_address} ]] then eecho "Error: No mac_address given" return 1 fi # first check if mac is registered serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'") if [[ -z ${serial} ]] then mtime=$(date +%s) # request a new serial; one command now (cause must be done in the same session) serial=$(mysqldo "insert into client_serials (mtime, mac) values('${mtime}','${mac_address}'); select last_insert_id();") fi echo "serial='${serial}'" } register_client() { local control_server_ip local iface_ip local iface local mac_address control_server_ip=$(dns_to_ip ${MCORE_CONTROL_SERVER}) iface_ip=$(iface_for_remote_addr ${control_server_ip}) iface=$(iface_for_ip ${iface_ip}) mac_address=$(mac_for_iface ${iface}) echo "DEBUG: MCORE_CONTROL_SERVER='${MCORE_CONTROL_SERVER}'" echo "DEBUG: iface_ip='${iface_ip}'" echo "DEBUG: iface='${iface}'" echo "DEBUG: mac_address='${mac_address}'" echo "register '${mac_address}'" }