--- mcore-src/trunk/mcore-tools/src/include/register.global.class.in 2015/09/03 13:01:47 2441 +++ mcore-src/trunk/mcore-tools/src/include/register.global.class.in 2015/12/16 14:42:45 2701 @@ -3,8 +3,13 @@ validate_client() { local mac_address="$1" + local ip_address="$2" local serial local mtime + local serial_id + local os + local tools + local netboot if [[ -z ${mac_address} ]] then @@ -12,15 +17,23 @@ return 1 fi + if [[ -z ${ip_address} ]] + then + eecho "Error: No ip_address given" + return 1 + fi + decho "registering mac_address='${mac_address}'" + decho "registering ip_address='${ip_address}'" # first check if mac is registered serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'") + # current mtime + mtime=$(date +%s) + 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 @@ -31,6 +44,44 @@ else decho "serial='${serial}'" rvecho "${serial}" + + SSLSAY_IP="${ip_address}" + SSLSAY_PORT="6666" + nsslsay_fingerprint "register '${serial}'" + + # get netboot state + nsslsay_queue_init + nsslsay_queue_add "nocolors" + nsslsay_queue_add "get version.netboot" + netboot=$(control_client "${serial}" run-queue) + + # register the client as online + serial_id=$(mysqldo "select serial from state_connected where serial=${serial};") + if [[ -n ${serial_id} ]] + then + mysqldo "update state_connected set ip='${ip_address}', mac='${mac_address}', mtime='${mtime}', netboot='${netboot}' where serial=${serial};" + else + mysqldo "insert into state_connected(serial,ip,mac,mtime,netboot) values('${serial}','${ip_address}','${mac_address}','${mtime}', '${netboot}');" + fi + + # update tools and os version info + nsslsay_queue_init + nsslsay_queue_add "nocolors" + nsslsay_queue_add "get version.os" + os=$(control_client "${serial}" run-queue) + import_resource client_version "${serial}" os "${os}" + nsslsay_queue_init + nsslsay_queue_add "nocolors" + nsslsay_queue_add "get version.tools" + tools=$(control_client "${serial}" run-queue) + import_resource client_version "${serial}" utils "${tools}" + + # run hardware detection + if is_provided hardware + then + run_hardware_detect "${serial}" + fi + return 0 fi } @@ -53,5 +104,21 @@ decho "mac_address='${mac_address}'" decho "register '${mac_address}'" - nsslsay_fingerprint "register '${mac_address}'" + nsslsay_fingerprint "register '${mac_address}' '${iface_ip}'" +} + +register_client_local() +{ + local serial="$1" + + if [[ -z ${serial} ]] + then + eecho "No serial given" + return 1 + fi + + install -d "${MCORE_CONFIG_PATH}" + CONFIG="${MCORE_CONFIG_PATH}/serial" + clearconfig + addconfig "CLIENT_SERIAL=\"${serial}\"" }