admin2.cgi 19 KB

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