admin2.cgi 19 KB

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