admin2.cgi 20 KB

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