Advertisement
Guest User

fogmanreg

a guest
Jun 15th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.85 KB | None | 0 0
  1. #!/bin/bash
  2. . /usr/share/fog/lib/funcs.sh
  3. . /bin/fog.donate
  4. clearScreen
  5. displayBanner
  6. disks=""
  7. disk=""
  8. hd=""
  9. getHardDisk
  10. sysman=""
  11. sysman64=""
  12. sysproduct=""
  13. sysproduct64=""
  14. sysversion=""
  15. sysversion64=""
  16. sysserial=""
  17. systype=""
  18. biosversion=""
  19. biosvendor=""
  20. biosdate=""
  21. mbman=""
  22. mbproductname=""
  23. mbversion=""
  24. mbserial=""
  25. mbasset=""
  26. cpuman=""
  27. cpuversion=""
  28. cpucurrent=""
  29. cpumax=""
  30. mem=""
  31. hdinfo=""
  32. caseman=""
  33. casever=""
  34. caseserial=""
  35. casesasset=""
  36. sysserial64=""
  37. systype64=""
  38. biosversion64=""
  39. biosvendor64=""
  40. biosdate64=""
  41. mbman64=""
  42. mbproductname64=""
  43. mbversion64=""
  44. mbserial64=""
  45. mbasset64=""
  46. cpuman64=""
  47. cpuversion64=""
  48. cpucurrent64=""
  49. cpumax64=""
  50. mem64=""
  51. hdinfo64=""
  52. caseman64=""
  53. casever64=""
  54. caseserial64=""
  55. casesasset64=""
  56. dots "Using disk device"
  57. echo $hd
  58. echo " * Starting host registration"
  59. mac=$(getMACAddresses | base64)
  60. exists=$(wget --post-data="mac=$mac" -qO - http://${web}service/man.hostexists.php 2>/dev/null)
  61. checkAndSet() {
  62. local testvar="$1"
  63. local onlynum="$2"
  64. [[ -z $testvar ]] && return
  65. if [[ $onlynum =~ [Tt][Rr][Uu][Ee] && $testvar =~ ^[0-9]+$ ]]; then
  66. echo $testvar | base64
  67. elif [[ $testvar =~ ^[0-9,]+$ ]]; then
  68. echo $testvar | base64
  69. else
  70. return
  71. fi
  72. }
  73. setIDs() {
  74. local varVar="$1"
  75. local str="$2"
  76. local csvstyle="$3"
  77. local dummy="$4"
  78. local max="$5"
  79. local res=""
  80. local url=""
  81. local oIFS=$IFS
  82. local line=""
  83. while [[ -z ${!varVar} ]]; do
  84. [[ $csvstyle =~ [Tt][Rr][Uu][Ee] ]] && echo -n " Enter the $str IDs separated with , to associate with computer (? for listing): " || echo -n " Enter the $str ID to associate with computer (? for listing): "
  85. read dummy
  86. dummy=$(echo $dummy | sed -e 's/^,//' -e 's/,$//')
  87. case $dummy in
  88. [?])
  89. url="http://${web}service/${str}listing.php"
  90. clearScreen
  91. res=$(echo -e $(wget -qO - $url 2>/dev/null))
  92. i=0
  93. IFS=$'\n'
  94. for line in $res; do
  95. let i+=1
  96. echo $line
  97. if [[ $i -eq $max ]]; then
  98. [[ $csvstyle =~ [Tt][Rr][Uu][Ee] ]] && echo -n " Press [Enter] to proceed or enter the $str IDs separated with , to associate with computer: " || echo -n " Press [Enter] to proceed or enter the $str ID to associate with computer: "
  99. read dummy
  100. case $dummy in
  101. [?]|"")
  102. i=0
  103. clearScreen
  104. continue
  105. ;;
  106. esac
  107. case $csvstyle in
  108. [Tt][Rr][Uu][Ee])
  109. [[ $dummy =~ ^[0-9,]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy) || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max"
  110. break
  111. ;;
  112. *)
  113. [[ $dummy =~ ^[0-9]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy "true") || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max"
  114. break
  115. ;;
  116. esac
  117. i=0
  118. dummy=$(echo $dummy | sed -e 's/^,//' -e 's/,$//')
  119. clearScreen
  120. fi
  121. done
  122. ;;
  123. ""|0)
  124. printf -v "$varVar" 0
  125. ;;
  126. *)
  127. dummy=$(echo $dummy | sed -e 's/^,//' -e 's/,$//')
  128. [[ -z $dummy ]] && setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max"
  129. case $csvstyle in
  130. [Tt][Rr][Uu][Ee])
  131. [[ $dummy =~ ^[0-9,]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy) || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max"
  132. ;;
  133. *)
  134. [[ $dummy =~ ^[0-9]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy "true") || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max"
  135. ;;
  136. esac
  137. ;;
  138. esac
  139. done
  140. IFS=$oIFS
  141. }
  142. [[ $exists != "#!ok" ]] && handleError "Unable to register host: $exists ($0)\n Args Passed: $*"
  143. host=""
  144. ip=""
  145. productKey=""
  146. imageid=""
  147. primaryuser=""
  148. other1=""
  149. other2=""
  150. blImage=""
  151. blDoAddGroup=""
  152. blDoAddSnapin=""
  153. keyEnter=""
  154. blDoAD=""
  155. res=""
  156. while [[ $res != "#!ok" ]]; do
  157. echo -n " * Enter hostname for this computer: "
  158. read host
  159. if [[ ${#host} -gt 15 ]]; then
  160. host=${host:0:15}
  161. echo " | Truncated to 15 characters: $host"
  162. usleep 2000000
  163. fi
  164. host=$(echo $host | base64)
  165. res=$(wget --post-data="host=$host" -qO - http://${web}service/hostnameloop.php 2>/dev/null)
  166. [[ $res != "#!ok" ]] && echo "$res"
  167. done
  168. imageid=""
  169. setIDs "imageid" "image" "" "" 20
  170. if [[ $(wget -qO - http://${web}service/locationcheck.php 2>/dev/null) == "##" ]]; then
  171. while [[ -z $askme ]]; do
  172. echo -n " Would you like to assign a location for this host? (y/N) "
  173. read askme
  174. case $askme in
  175. [Nn]|[Nn][Oo]|"")
  176. askme="N"
  177. ;;
  178. [Yy]|[Yy][Ee][Ss])
  179. setIDs "locationid" "location" "" "" 20
  180. location64=$locationid
  181. ;;
  182. *)
  183. askme=""
  184. echo " * Invalid input, please try again"
  185. ;;
  186. esac
  187. done
  188. fi
  189. askme=""
  190. while [[ -z $askme ]]; do
  191. echo -n " Would you like to associate this host with groups? (y/N) "
  192. read askme
  193. case $askme in
  194. [Nn]|[Nn][Oo]|"")
  195. askme="N"
  196. ;;
  197. [Yy]|[Yy][Ee][Ss])
  198. setIDs "groupid" "group" "true" "" 20
  199. group64=$groupid
  200. ;;
  201. *)
  202. askme=""
  203. echo " * Invalid input, please try again"
  204. ;;
  205. esac
  206. done
  207. askme=""
  208. while [[ -z $askme ]]; do
  209. echo -n " Would you like to associate this host with snapins? (y/N) "
  210. read askme
  211. case $askme in
  212. [Nn]|[Nn][Oo]|"")
  213. askme="N"
  214. ;;
  215. [Yy]|[Yy][Ee][Ss])
  216. setIDs "snapinid" "snapin" "true" "" 20
  217. snapin64=$snapinid
  218. ;;
  219. *)
  220. askme=""
  221. echo " * Invalid input, please try again"
  222. ;;
  223. esac
  224. done
  225. askme=""
  226. while [[ -z $askme ]]; do
  227. echo -n " Would you like to associate a product key to this host? (y/N) "
  228. read askme
  229. case $askme in
  230. [Nn]|[Nn][Oo]|"")
  231. askme="N"
  232. ;;
  233. [Yy]|[Yy][Ee][Ss])
  234. echo -n " * Enter the product key for this computer: "
  235. read productKey
  236. productKey=$(echo $productKey | base64)
  237. ;;
  238. *)
  239. askme=""
  240. echo " * Invalid input, please try again"
  241. ;;
  242. esac
  243. done
  244. askme=""
  245. while [[ -z $askme ]]; do
  246. echo -n " Would you like this host to join a domain, (using default settings)? (y/N) "
  247. read askme
  248. case $askme in
  249. [Nn]|[Nn][Oo]|"")
  250. askme="N"
  251. ;;
  252. [Yy]|[Yy][Ee][Ss])
  253. blDoAD=$(echo -n 1 | base64)
  254. askme="Y"
  255. ;;
  256. *)
  257. askme=""
  258. echo " * Invalid input, please try again"
  259. ;;
  260. esac
  261. done
  262. echo -n " * Enter the primary user for this computer: "
  263. read primaryuser
  264. primaryuser=$(echo $primaryuser | base64)
  265. echo -n " * Enter the other tag #1 for this computer: "
  266. read other1
  267. other1=$(echo $other1 | base64)
  268. echo -n " * Enter the other tag #2 for this computer: "
  269. read other2
  270. other2=$(echo $other2 | base64)
  271. echo " * You entered all required information, "
  272. askme=""
  273. while [[ -z $askme ]]; do
  274. echo -n " Would you like to image this computer now? (y/N) "
  275. read askme
  276. case $askme in
  277. [Nn]|[Nn][Oo]|"")
  278. askme="N"
  279. ;;
  280. [Yy]|[Yy][Ee][Ss])
  281. tmp=""
  282. ret=""
  283. retry=3
  284. while [[ $ret != "#!ok" && ! $retry -eq 0 ]]; do
  285. echo " * Enter FOG GUI Username and Password"
  286. echo -n " Username: "
  287. read username
  288. echo -n " Password: "
  289. read -s password
  290. user64=$(echo $username | tr -d '\012' | base64)
  291. pass64=$(echo $password | tr -d '\012' | base64)
  292. ret=$(wget --post-data="mac=$mac&username=$user64&password=$pass64" -qO - http://${web}service/checkcredentials.php 2>/dev/null)
  293. case $ret in
  294. '#!ok')
  295. echo " * This host will reboot and imaging will start!"
  296. ret=$tmp
  297. realdoimage=$(echo -n 1 | base64)
  298. break
  299. ;;
  300. '#!il')
  301. echo " * Error: Invalid Login! ($retry remaining)"
  302. let retry-=1
  303. ;;
  304. esac
  305. done
  306. askme="Y"
  307. ;;
  308. *)
  309. askme=""
  310. echo " * Invalid input, please try again"
  311. ;;
  312. esac
  313. done
  314. dots "Attempting to register host"
  315. res=""
  316. while [[ -z $res ]]; do
  317. res=$(wget --post-data="mac=$mac&advanced=$(echo -n 1 | base64)&host=$host&imageid=$imageid&primaryuser=$primaryuser&other1=$other1&other2=$other2&doimage=$realdoimage&doad=$blDoAD&location=$location64&username=$user64&groupid=$group64&snapinid=$snapin64&productKey=$productKey" -qO - http://${web}service/auto.register.php 2>/dev/null)
  318. echo "$res"
  319. usleep 2000000
  320. done
  321. . /bin/fog.inventory
  322. usleep 2000000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement