admin2.cgi 20 KB

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