admin2.cgi 20 KB

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