admin2.cgi 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. #!/usr/bin/haserl --shell=/bin/bash --upload-limit=32768 --upload-dir=/tmp
  2. <%# upload limit: 32Mb %>
  3. <%
  4. ## SuperGlue project | http://superglue.it | 2014-2015 | GPLv3
  5. ## http://git.superglue.it/superglue/serverfiles
  6. ##
  7. ## admin2.cgi - control panel for Superglue personal server
  8. ##
  9. ## example POST request:
  10. ## curl --data-urlencode 'key=value' http://host/uri
  11. ##
  12. ## returns: 200 (+ output of operation) on success
  13. ## 406 (+ error message in debug mode) on error
  14. readonly _WWW='/www'
  15. readonly _PWDFILE="/opt/lib/htpasswd"
  16. readonly _TMP='/tmp'
  17. readonly _LOG="${_WWW}/log/admin.log"
  18. readonly _SCRIPTS='/opt/lib/scripts'
  19. readonly _DEBUG=1
  20. readonly _IFS=$IFS
  21. err() {
  22. _ERR="$?"
  23. [[ "$_ERR" -gt 0 ]] || return 0
  24. logThis "$1"
  25. headerPrint "${2:='400'}"
  26. exit "$_ERR"
  27. }
  28. logThis() {
  29. [[ "$_DEBUG" -gt 0 ]] || return 0
  30. local _TYPE='I:'
  31. [[ "$_ERR" -gt 0 ]] && _TYPE='E:'
  32. local _TIME; printf -v _TIME '%(%d.%m.%Y %H:%M:%S)T' -1
  33. printf '%b\n' "$_TIME $_TYPE ${@} " >> "$_LOG"
  34. [[ "$_DEBUG" -gt 1 ]] && printf '%b\n' "[verbose] $_TYPE ${1}"
  35. # exit 0
  36. }
  37. headerPrint() {
  38. case "$1" in
  39. 200|'') printf '%b' 'Status: 200 OK\r\n';;
  40. 301) printf '%b' "Status: 301 Moved Permanently\r\nLocation: $HTTP_REFERER\r\n";;
  41. 403) printf '%b' 'Status: 403 Forbidden\r\n';;
  42. 405) printf '%b' 'Status: 405 Method Not Allowed\r\n';;
  43. 406) printf '%b' 'Status: 406 Not Acceptable\r\n';;
  44. *) printf '%b' 'Status: 400 Bad Request\r\n';;
  45. esac
  46. printf '%b' 'Content-Type: text/html\r\n\r\n';
  47. }
  48. ## faster echo
  49. _echo() {
  50. printf "%b" "${*}"
  51. }
  52. urlDec() {
  53. local value=${*//+/%20}
  54. for part in ${value//%/ \\x}; do
  55. printf "%b%s" "${part:0:4}" "${part:4}"
  56. done
  57. }
  58. setQueryVars() {
  59. _VARS=( ${!POST_*} )
  60. # local v
  61. # for v in ${_VARS[@]}; do
  62. # echo $v
  63. # v=$(urlDec "${v}")
  64. # eval "_${v//POST_/}=${!v}";
  65. # done
  66. local v
  67. for v in ${_VARS[@]}; do
  68. logThis "$v=${!v}"
  69. done
  70. #echo $POST_lanssid
  71. #env
  72. }
  73. getQueryFile() {
  74. # setQueryVars
  75. local _UPLD="${HASERL_fwupload_path##*/}"
  76. logThis "'multipart': decoding stream"
  77. mv "$_TMP/$_UPLD" "$_TMP/fwupload.bin" 2>/dev/null || _ERR=$?
  78. if [[ $_ERR -gt 0 ]]; then
  79. showMesg 'Firmware upload has failed' '60' 'Reboot your Superglue server and try again'
  80. fi
  81. }
  82. validIp() {
  83. local _IP=$1
  84. local _RET=1
  85. if [[ $_IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
  86. OIFS=$IFS
  87. IFS='.'
  88. _IP=($_IP)
  89. IFS=$OIFS
  90. [[ ${_IP[0]} -le 255 && ${_IP[1]} -le 255 && ${_IP[2]} -le 255 && ${_IP[3]} -le 255 ]]
  91. _RET=$?
  92. fi
  93. return $_RET
  94. }
  95. pwdChange() {
  96. local _USER='admin'
  97. local _REALM='superglue'
  98. [[ -z "${POST_pwd##$POST_pwdd}" ]] || showMesg 'Passwords did not match'
  99. [[ ${#POST_pwd} -ge 6 ]] || showMesg 'Password must be at least 6 characters long'
  100. local _HASH=$(printf '%s' "$_USER:$_REALM:${POST_pwd}" | md5sum | cut -b -32)
  101. _OUT=$(printf '%b' "${POST_pwd}\n${POST_pwd}\n" | passwd root 2>&1) &&
  102. _OUT=$(printf '%b' "$_USER:$_REALM:$_HASH\n" > $_PWDFILE 2>&1)
  103. _ERR=$?
  104. if [[ $_ERR -gt 0 ]]; then
  105. showMesg 'Password change failed!' '5' "$_OUT -"
  106. else
  107. showMesg 'Password is changed' '2'
  108. fi
  109. }
  110. lanAddr() {
  111. logThis "new LAN addr is: $POST_lanipaddr"
  112. validIp $POST_lanipaddr || showMesg 'Not valid network address'
  113. doUci set lanipaddr $POST_lanipaddr &&
  114. doUci commit network &&
  115. dtach -n -zE $_SCRIPTS/net-restart.sh &&
  116. showMesg 'New network address is set' '30' "Your server is now accessible under <a href='http://superglue.local/admin'>http://superglue.local/admin</a>" ||
  117. { _ERR=1; showMesg 'Setting network address failed'; }
  118. }
  119. wanSet() {
  120. if [[ ! -z $POST_wanifname ]]; then
  121. ## eth and wlan wan cases are different!
  122. ## eth wan requires:
  123. ## config interface 'wan'
  124. ## option proto 'dhcp'
  125. ## option ifname 'eth0'
  126. ##
  127. ## wlan wan requires:
  128. ## config interface 'wan'
  129. ## option proto 'dhcp' (and no 'option ifname' specified!)
  130. logThis "wan.ifname=$POST_wanifname"
  131. if [[ $POST_wanifname == 'eth0' ]]; then
  132. doUci set wanifname $POST_wanifname
  133. doUci set wanwifacedis '1'
  134. elif [[ $POST_wanifname == 'wlan1' ]]; then
  135. doUci set wanifname ''
  136. doUci set wanwifacedis ''
  137. fi
  138. if [[ $POST_wanproto == 'dhcp' ]]; then
  139. doUci set wanproto dhcp
  140. doUci set wanipaddr ''
  141. doUci set wanmask ''
  142. doUci set wangw ''
  143. doUci set wandns ''
  144. elif [[ $POST_wanproto == 'static' ]]; then
  145. logThis "wan.ipaddr=$POST_wanipaddr"
  146. validIp $POST_wanipaddr || showMesg 'Our IP address is not valid' '3' 'make sure to use correct address notation'
  147. validIp $POST_wangw || showMesg 'Gateway is not a valid IP address' '3' 'make sure to use correct address notation'
  148. validIp $POST_wandns || showMesg 'DNS is not a valid IP address' '3' 'make sure to use correct address notation'
  149. doUci set wanproto static
  150. doUci set wanipaddr $POST_wanipaddr
  151. doUci set wanmask '255.255.255.0' ## fix me
  152. doUci set wangw $POST_wangw
  153. doUci set wandns $POST_wandns
  154. fi
  155. if [[ $POST_wanifname == 'wlan1' ]]; then
  156. ssidChange || showMesg 'wanSet: Wireless configuration failed'
  157. else
  158. doUci commit network
  159. doUci commit wireless
  160. dtach -n -zE $_SCRIPTS/net-restart.sh
  161. fi
  162. _ERR=$?
  163. # logThis "return: $? ; error: $_ERR"
  164. if [[ $_ERR -gt 0 ]]; then
  165. showMesg 'Internet connection is being configured' '25' 'check your Internet connection on completion'
  166. else
  167. showMesg 'Configuring Internet connection failed'
  168. fi
  169. fi
  170. }
  171. ssidChange() {
  172. ## check for iface
  173. [[ $POST_iface =~ ^('wan'|'lan')$ ]] || showMesg 'Error changing wireless settings' '5' 'unknown or unconfigured interface'
  174. logThis "$POST_iface is being set"
  175. _p=$POST_iface
  176. ## default enc for now
  177. local _enc='psk2'
  178. if [[ $POST_iface == 'wan' ]]; then
  179. local _mode='sta'
  180. local _ssid="${POST_wanssid}"
  181. local _key="${POST_wankey}"
  182. else
  183. local _mode='ap'
  184. local _ssid="${POST_lanssid}"
  185. local _key="${POST_lankey}"
  186. fi
  187. #logThis "ssid: $_ssid [$_mode], key: $_key [$_enc]"
  188. #logThis $POST_wanssid
  189. if [[ ${#_ssid} -lt 4 ]]; then
  190. _ERR=1
  191. showMesg 'SSID must be at least 4 characters long'
  192. fi
  193. doUci set $_p'ssid' "${_ssid}"
  194. _ERR=$?
  195. [[ $_ERR -gt 0 ]] && showMesg 'New SSID is not set'
  196. if [[ -z $_key ]]; then
  197. ## if key is empty set encryption to none and remove key
  198. doUci set $_p'key' && doUci set $_p'enc' 'none'
  199. _ERR=$?
  200. else
  201. if [[ ${#_key} -lt 8 ]]; then
  202. _ERR=1
  203. showMesg 'Passphrase must be at least 8 characters long'
  204. fi
  205. doUci set $_p'key' "${_key}" && doUci set $_p'enc' "${_enc}"
  206. _ERR=$?
  207. [[ $_ERR -gt 0 ]] && showMesg 'Passphrase is not set'
  208. fi
  209. [[ $_ERR -gt 0 ]] && showMesg 'ssidChange: Wireless configuration failed'
  210. if [[ $POST_iface == 'lan' ]]; then
  211. if [[ "$(doUci get lanipaddr)" != "${POST_lanipaddr}" ]]; then
  212. logThis 'local IP was changed'
  213. lanAddr
  214. fi
  215. fi
  216. doUci commit wireless
  217. _ERR=$?
  218. if [[ $_ERR -gt 0 ]]; then
  219. showMesg 'Configuration failed'
  220. else
  221. dtach -n -zE $_SCRIPTS/net-restart.sh &>/dev/null
  222. fi
  223. if [[ $POST_iface == 'lan' ]]; then
  224. showMesg 'Local network configuration is progress' '30' 'check your connection on completion - '
  225. fi
  226. ## in this case wanSet() handles success message
  227. }
  228. showMesg() {
  229. local _RET=$?
  230. local _MSG=$1
  231. local _TIMEOUT=$2
  232. local _SUBMSG=$3
  233. ## if set, global _ERR value prevails
  234. # logThis "return: $_RET , error: $_ERR"
  235. # if [[ ! -z $_ERR ]] && [[ $_ERR -ne $_RET ]]; then
  236. # _ERR=$_RET
  237. # logThis "forcing _ERR value: $_ERR"
  238. # fi
  239. _ERR=$_RET
  240. _MSG=${_MSG:='Configuration'}
  241. _TIMEOUT=${_TIMEOUT:='5'}
  242. _SUBMSG="${_SUBMSG} <span id='timeout'>${_TIMEOUT}</span> seconds to get ready.."
  243. if [[ $_ERR -gt 0 ]]; then
  244. local _TYPE='ERROR: '
  245. headerPrint 406
  246. else
  247. local _TYPE='OK: '
  248. headerPrint 200
  249. fi
  250. htmlHead "<meta http-equiv='refresh' content='${_TIMEOUT};url=http://${HTTP_HOST}/admin'>"
  251. _echo "<body>
  252. <h1>Superglue control panel</h1>
  253. <img src='http://${HTTP_HOST}/resources/img/superglueLogo.png' class='logo'>
  254. <hr>
  255. <h2 style='display:inline'>$_TYPE $_MSG</h2>
  256. <span style='display:block'>$_SUBMSG</span>
  257. <hr>
  258. </body>
  259. <script type='text/javascript'>(function(e){var t=document.getElementById(e);var n=t.innerHTML;var r=setInterval(function(){if(n==0){t.innerHTML='0';clearInterval(r);return}t.innerHTML=n;n--},1e3)})('timeout')
  260. </script>
  261. </html>"
  262. exit $_ERR
  263. }
  264. updateFw() {
  265. local _FWFILE="${_TMP}/fwupload.bin"
  266. _OUT="$(sysupgrade -T $_FWFILE 2>&1)" ||
  267. { _ERR=$?; rm -rf $_FWFILE; showMesg 'This is not a firmware!' '3' "$_OUT"; }
  268. [[ $POST_fwreset == 'on' ]] && { _FWRESET='-n'; logThis 'fw reset requested'; }
  269. ## using dtach to prevent sysupgrade getting killed
  270. dtach -n -zE sysupgrade $_FWRESET $_FWFILE >/dev/null &&
  271. showMesg 'Firmware update is in progress..' '120' 'DO NOT INTERRUPT!' ||
  272. { _ERR=$?; rm -rf $_FWFILE; showMesg 'Firmware update failed..' '3' "$_OUT"; }
  273. }
  274. usbInit() {
  275. . $_SCRIPTS/usb-part.sh
  276. _OUT="$(usbPart)" &&
  277. showMesg 'USB storage initialization is completed' '30' ||
  278. showMesg "USB init failed!\n$_OUT"
  279. # logThis 'usb init..'
  280. }
  281. rebootNow() {
  282. logThis "reboot: now!"
  283. reboot
  284. showMesg 'Rebooting..' '60'
  285. }
  286. upTime() {
  287. local _T="$(uptime)" &&
  288. { headerPrint 200; printf '%b' "$_T\n"; exit 0; } ||
  289. headerPrint 406
  290. }
  291. iwScan() {
  292. . $_SCRIPTS/iw-scan.sh
  293. headerPrint 200
  294. iwScan
  295. exit 0
  296. }
  297. findUsbstor() {
  298. local _P='/sys/block/'
  299. local _D _DEV
  300. for _D in ${_P}sd*; do
  301. _DEV=$(readlink -f ${_D}/device)
  302. if [[ ${_DEV/usb} != $_DEV ]]; then
  303. _USBDEV="/dev/${_D/$_P}"
  304. fi
  305. done
  306. [[ $_USBDEV ]] || return 1
  307. }
  308. storageInfo() {
  309. if mountpoint -q $_WWW; then
  310. IFS=$'\n' _STOR=( $(df -h $_WWW) ) IFS=$_IFS
  311. _STOR=( ${_STOR[1]} )
  312. else
  313. return 1
  314. fi
  315. }
  316. swapInfo() {
  317. IFS=$'\n' _SWAP=( $(swapon -s) ) IFS=$_IFS
  318. if [[ ${_SWAP[1]} ]]; then
  319. IFS=$'\t' _SWAP=( ${_SWAP[1]} ) IFS=$_IFS
  320. ## for the lack of floats add trailing 0
  321. ## divide by 1023 and split last digit by a period
  322. _SWAP[1]="$((${_SWAP[1]}0/1023))"
  323. _SWAP[1]="${_SWAP[1]%?}.${_SWAP[1]/??}M"
  324. else
  325. unset _SWAP
  326. return 1
  327. fi
  328. }
  329. trimSpaces() {
  330. local v="$*"
  331. v="${v#"${v%%[![:space:]]*}"}"
  332. v="${v%"${v##*[![:space:]]}"}"
  333. return "$v"
  334. }
  335. dynDns() {
  336. ## curently only http://freedns.afraid.org is supported
  337. [[ $POST_dyndnsname && $POST_dyndnsuser && $POST_dyndnspass ]] || showMesg 'All values must be set!'
  338. doUci set dyndnsname "$POST_dyndnsname" &&
  339. doUci set dyndnsuser "$POST_dyndnsuser" &&
  340. doUci set dyndnspass "$POST_dyndnspass" || showMesg 'DynDNS settings failed..'
  341. ## create sha1 string per http://freedns.afraid.org/api
  342. local _DURL
  343. local _AFRAID='http://freedns.afraid.org/api/?action=getdyndns&sha='
  344. _DURL=$(_echo "$POST_dyndnsuser|$POST_dyndnspass" | sha1sum)
  345. _DURL="$_AFRAID${_DURL/ -/}"
  346. _DURL="$(wget -q $_DURL -O -)"
  347. local _L
  348. local _RES
  349. for _L in $_DURL
  350. do case $_L in
  351. "${POST_dyndnsname}|"*) IFS='|' _RES=( $_L ); break;;
  352. 'ERROR'*) _RES=1; break;;
  353. *) unset _RES;;
  354. esac;
  355. done
  356. [[ ! $_RES ]] && showMesg 'Domain name is not found' '10' 'Make sure you entered correct domain name -'
  357. [[ $_RES -eq 1 ]] && showMesg 'Authentication failed' '10' 'Check your username and password and try again -'
  358. logThis "${_RES[@]}"
  359. doUci set dyndnsurl "${_RES[2]}" &&
  360. doUci set dyndnsdis '' &&
  361. doUci commit
  362. showMesg 'DynDNS configuration is in progress..' '10' 'After completion, your URL will become available with in 10-15 minutes -'
  363. }
  364. doUci() {
  365. local _CMD=''
  366. local _ARG=''
  367. case $1 in
  368. get|set|commit) _CMD=$1;;
  369. *) logThis 'bad UCI command'; headerPrint 405; echo 'bad UCI command'; exit 1 ;;
  370. esac
  371. case $2 in
  372. lanssid) _ARG='wireless.@wifi-iface[0].ssid';;
  373. lanenc) _ARG='wireless.@wifi-iface[0].encryption';;
  374. lankey) _ARG='wireless.@wifi-iface[0].key';;
  375. lanipaddr) _ARG='network.lan.ipaddr';;
  376. wanifname) _ARG='network.wan.ifname';;
  377. wanproto) _ARG='network.wan.proto';;
  378. wanipaddr) _ARG='network.wan.ipaddr';;
  379. wanmask) _ARG='network.wan.netmask';;
  380. wangw) _ARG='network.wan.gateway';;
  381. wandns) _ARG='network.wan.dns';;
  382. wanwifacedis) _ARG='wireless.@wifi-iface[1].disabled';;
  383. wanssid) _ARG='wireless.@wifi-iface[1].ssid';;
  384. wanenc) _ARG='wireless.@wifi-iface[1].encryption';;
  385. wankey) _ARG='wireless.@wifi-iface[1].key';;
  386. dyndnsdis) _ARG='superglue.dyndns.disabled';;
  387. dyndnsurl) _ARG='superglue.dyndns.updateurl';;
  388. dyndnsname) _ARG='superglue.dyndns.domainname';;
  389. dyndnsuser) _ARG='superglue.dyndns.username';;
  390. dyndnspass) _ARG='superglue.dyndns.password';;
  391. *) if [[ $_CMD == 'commit' ]]; then
  392. _ARG=$2
  393. else
  394. logThis "bad UCI entry: $2"
  395. _ERR=1
  396. showMesg 'bad UCI entry'
  397. fi ;;
  398. esac
  399. if [[ $_CMD == 'get' ]]; then
  400. if [ ! -z $_ARG ]; then
  401. /sbin/uci -q get $_ARG || return $?
  402. fi
  403. fi
  404. if [[ $_CMD == 'set' ]]; then
  405. local _VAL=$3
  406. if [ -z $_VAL ]; then
  407. logThis "empty $_ARG value, removing record"
  408. /sbin/uci delete $_ARG || ( echo "uci delete $_ARG: error"; exit 1; )
  409. fi
  410. if [ ! -z $_ARG ]; then
  411. logThis "setting $_ARG value"
  412. /sbin/uci set $_ARG=$_VAL || ( echo "uci set $_ARG: error"; exit 1; )
  413. fi
  414. fi
  415. if [[ $_CMD == 'commit' ]]; then
  416. /sbin/uci commit $_ARG || echo "uci commit $_ARG: error"
  417. fi
  418. }
  419. ## call with argument to inject additional lines
  420. ## ie: htmlhead "<meta http-equiv='refresh' content='2;URL=http://${HTTP_REFERER}'>"
  421. htmlHead() {
  422. _echo "<!-- obnoxious code below, keep your ports tight -->
  423. <!doctype html>
  424. <html>
  425. <head>
  426. <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
  427. <meta http-equiv='Cache-Control' content='no-cache, no-store, must-revalidate' />
  428. <meta http-equiv='Pragma' content='no-cache' />
  429. <meta http-equiv='Expires' content='0' />
  430. <link rel='icon' href='http://${HTTP_HOST}/resources/img/favicon.ico' type='image/x-icon' />
  431. <title>Superglue | Control panel</title>
  432. <link rel='stylesheet' type='text/css' href='http://${HTTP_HOST}/resources/admin/admin.css' />
  433. $@
  434. </head>"
  435. }
  436. footerBody() {
  437. _echo "</body>
  438. <script type='text/javascript' src='http://${HTTP_HOST}/resources/admin/admin.js'></script>
  439. </html>"
  440. }
  441. if [[ "${REQUEST_METHOD^^}" == "POST" ]]; then
  442. [[ $CONTENT_LENGTH -gt 0 ]] || err 'content length is zero, 301 back to referer' '301'
  443. case "${CONTENT_TYPE^^}" in
  444. APPLICATION/X-WWW-FORM-URLENCODED*) setQueryVars;;
  445. MULTIPART/FORM-DATA*) getQueryFile;;
  446. *) _ERR=1; _OUT='this is not a post';;
  447. esac
  448. case $REQUEST_URI in
  449. *pwdchange) pwdChange;;
  450. *ssidchange) ssidChange;;
  451. *lanaddr) lanAddr;;
  452. *updatefw) updateFw;;
  453. *usbinit) usbInit;;
  454. *rebootnow) rebootNow;;
  455. *wan) wanSet;;
  456. *uptime) upTime;;
  457. *iwscan) iwScan;;
  458. *dyndns) dynDns;;
  459. *) logThis 'bad action'; headerPrint 405;
  460. echo 'no such thing'; exit 1;;
  461. esac
  462. fi
  463. headerPrint '200'
  464. htmlHead
  465. read sgver < /etc/superglue_version
  466. read devmod < /etc/superglue_model
  467. read openwrt < /etc/openwrt_version
  468. . /opt/lib/scripts/jshn-helper.sh
  469. ## this does not work when iface isn't configured
  470. IFS=","
  471. wan=( $(ifaceStat wan) )
  472. IFS=$OFS
  473. wanifname=${wan[3]}
  474. wanproto=$(doUci get wanproto)
  475. wanipaddr=${wan[0]}
  476. wangw=${wan[2]}
  477. wandns=${wan[5]}
  478. wanuptime=${wan[4]}
  479. wanssid=$(doUci get wanssid)
  480. wankey=$(doUci get wankey)
  481. %>
  482. <body>
  483. <h1>Superglue control panel</h1>
  484. <img src='http://<% _echo "${HTTP_HOST}" %>/resources/img/superglueLogo.png' class='logo'>
  485. <section class='inert'>
  486. <span style='display:block;'><% printf "System version: %s | Device: %s | OpenWRT: %s" "$sgver" "$devmod" "$openwrt" %></span>
  487. <span style='display:block;' id='uptime'><% uptime %></span>
  488. </section>
  489. <section>
  490. <h2>Internet connection:</h2>
  491. <form method='post' action='/admin/wan' name='wan' class='elem' id='wanconf'>
  492. <div style='display:inline-flex'>
  493. <div style='display:inline-block;'>
  494. <select name='wanifname' id='wanifname' style='display:block'>
  495. <option value='eth0' id='eth' <% ( [[ $wanifname =~ ('eth') ]] && _echo 'selected' ) %> >Wired (WAN port)</option>
  496. <option value='wlan1' id='wlan' <% ( [[ $wanifname =~ ('wlan') ]] && _echo 'selected' ) %> >Wireless (WiFi)</option>
  497. </select>
  498. <fieldset id='wanwifi' <% ( [[ $wanifname =~ ('wlan') ]] && _echo "class='show elem'" || _echo "class='hide elem'" ) %>>
  499. <select name='wanssid' id='wanssid' class='elem' style='display:block'>
  500. <% if [[ -z $wanssid ]]; then
  501. _echo "<option id='scan' disabled>select a network..</option>"
  502. else
  503. _echo "<option id=$wanssid selected>$wanssid</option>"
  504. fi %>
  505. </select>
  506. <input type='password' name='wankey' placeholder='passphrase' value='<% _echo $wankey %>'>
  507. </fieldset>
  508. <span class='help'>help</span>
  509. </div>
  510. <div style='display:inline-block;'>
  511. <select name='wanproto' id='wanproto' style='display:block'>
  512. <option value='dhcp' name='dhcp' id='dhcp' <% ([[ $wanproto == 'dhcp' ]] && _echo 'selected') %>>Automatic (DHCP)</option>
  513. <option value='static' name='stat' id='stat' <% ([[ $wanproto == 'static' ]] && _echo 'selected') %>>Manual (Static IP)</option>
  514. </select>
  515. <fieldset id='wanaddr' class='elem'>
  516. <input type='text' name='wanipaddr' id='wanipaddr' value='<% _echo $wanipaddr %>' <% ( [[ $wanproto =~ ('dhcp') ]] && _echo "readonly" ) %> placeholder='ip address'>
  517. <input type='text' name='wangw' id='wangw' value='<% _echo $wangw %>' <% ( [[ $wanproto =~ ('dhcp') ]] && _echo "readonly" ) %> placeholder='gateway/router'>
  518. <input type='text' name='wandns' id='wandns' value='<% _echo $wandns %>' <% ( [[ $wanproto =~ ('dhcp') ]] && _echo "readonly" ) %> placeholder='dns server'>
  519. </fieldset>
  520. </div>
  521. </div>
  522. <input type='hidden' name='iface' value='wan' class='inline'>
  523. <input type='submit' id='wansubmit' value='Apply'>
  524. </form>
  525. <span class='help'>help</span>
  526. </section>
  527. <section>
  528. <h2>Domain name:</h2>
  529. <form method='post' action='/admin/dyndns' name='dyndns' id='afraid'>
  530. <div style='display:inline-flex'>
  531. <div style='display:inline-block;'>
  532. <input type='text' name='dyndnsname' id='dyndnsname' value='<% _echo $dyndnsname %>' placeholder='domain name' class='block'>
  533. </div>
  534. <div style='display:inline-block;'>
  535. <input type='text' name='dyndnsuser' id='dyndnsuser' value='<% _echo $dyndnsuser %>' placeholder='dyndns username' class='block'>
  536. <input type='password' name='dyndnspass' id='dyndnspass' value='<% _echo $dyndnspass %>' placeholder='dyndns password' class='block'>
  537. </div>
  538. </div>
  539. <input type='hidden' name='dns' value='apply' class='inline'>
  540. <input type='submit' value='Apply'>
  541. </form>
  542. <h2>Dynamic DNS:</h2>
  543. Register your free domain name (external <a target='_new' href='http://freedns.afraid.org/'>Free DNS</a> service, will open in a new tab)
  544. <form target='_new' action='http://freedns.afraid.org/subdomain/edit.php'>
  545. <div style='display:inline-flex'>
  546. <div style='display:inline-block;'>
  547. <input type='text' name='subdomain' placeholder='yourname' class='inline'>
  548. </div>
  549. <div style='display:inline-block;'>
  550. <select name='edit_domain_id' class='inline'>
  551. <option value='1035903'>spgl.cc</option>
  552. <option value='1035903'>spgl.it</option>
  553. </select>
  554. </div>
  555. </div>
  556. <input type='submit' name='submit' value="next &gt;&gt;">
  557. <input type='hidden' name='web_panel' value='1'>
  558. <input type='hidden' name='ref' value='750930'>
  559. </form>
  560. <span class='help'>help</span>
  561. </section>
  562. <section>
  563. <h2>Local wireless network:</h2>
  564. <form method='post' action='/admin/ssidchange'>
  565. <div style='display:inline-flex'>
  566. <div style='display:inline-block;'>
  567. <input type='text' name='lanssid' value='<% doUci get lanssid %>'>
  568. <input type='password' name='lankey' value='<% doUci get lankey %>'>
  569. </div>
  570. <div style='display:inline-block;'>
  571. <input type='text' name='lanipaddr' value='<% doUci get lanipaddr %>'>
  572. <input type='hidden' name='iface' value='lan'>
  573. </div>
  574. </div>
  575. <input type='submit' value='Apply' data-wait='Configuring..'>
  576. </form>
  577. <span class='help'>help</span>
  578. </section>
  579. <section>
  580. <h2>Storage:</h2>
  581. <% if findUsbstor; then %>
  582. <% if storageInfo; then %>
  583. <div>File storage: <% _echo "${_STOR[2]} used, ${_STOR[3]} available" %></div>
  584. <div>Swap: <% swapInfo && _echo "${_SWAP[1]}" || _echo '<b>n/a</b>' %></div>
  585. <% else %>
  586. <div>USB storage device must be initialized</div>
  587. <form method='post' action='/admin/usbinit'>
  588. <input type='hidden' name='dev' value='<% _echo $_USBDEV %>'>
  589. <input type='submit' value='Initialize'>
  590. </form>
  591. <% fi %>
  592. <% else %>
  593. <div><h3>USB storage device not found!</h3>Please check and try again</div>
  594. <% fi %>
  595. <span class='help'>help</span>
  596. </section>
  597. <section>
  598. <h2>Change password:</h2>
  599. <form method='post' action='/admin/pwdchange'>
  600. <div style='display:inline-flex'>
  601. <div style='display:inline-block;'>
  602. <input type='text' name='usr' value='admin' readonly>
  603. </div>
  604. <div style='display:inline-block;'>
  605. <input type='password' name='pwd' placeholder='password' value=''>
  606. <input type='password' name='pwdd' placeholder='password again' value=''>
  607. </div>
  608. </div>
  609. <input type='submit' value='Apply'>
  610. </form>
  611. <span class='help'>help</span>
  612. </section>
  613. <section>
  614. <h2>Firmware upgrade:</h2>
  615. <form method='post' action='/admin/updatefw' enctype='multipart/form-data'>
  616. <div id='uploadbox'>
  617. <input id='uploadfile' placeholder='Select a file..' class='elem' disabled='disabled'>
  618. <input id='uploadbtn' class='elem' name='fwupload' type='file'>
  619. </div>
  620. <div style='display:inline-block;'>
  621. <input type='checkbox' name='fwreset' id='fw-resetbox' />
  622. <label for='fw-resetbox'>Reset all settings</label>
  623. </div>
  624. <input type='submit' value='Upload' data-wait='Uploading, do NOT interrupt!'>
  625. </form>
  626. <span class='help'>help</span>
  627. </section>
  628. <section>
  629. <h2></h2>
  630. <form action='/admin/rebootnow' method='post' class='inline'>
  631. <input type='hidden' name='reboot' value='now' class='inline'>
  632. <input type='submit' value='Reboot' class='inline'>
  633. </form>
  634. <form action='http://logout@<% _echo ${HTTP_HOST} %>/admin' method='get' class='inline'>
  635. <input type='submit' value='Logout' class='inline'>
  636. </form>
  637. </section>
  638. <div style='height:200px'></div>
  639. <hr>
  640. Memory:
  641. <pre><% free %></pre>
  642. <hr>
  643. Storage:
  644. <pre><% df -h %></pre>
  645. <hr>
  646. Environment:
  647. <pre><% env %></pre>
  648. <hr>
  649. <%
  650. footerBody
  651. exit 0
  652. %>