admin2.cgi 20 KB

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