admin2.cgi 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. #!/usr/bin/haserl --shell=/bin/bash --upload-limit=32768 --upload-dir=/tmp
  2. <%# upload limit: 32Mb %>
  3. <%
  4. ## SuperGlue project | http://superglue.it | 2014-2015 | GPLv3
  5. ## http://git.superglue.it/superglue/serverfiles
  6. ##
  7. ## admin2.cgi - control panel for Superglue personal server
  8. ##
  9. ## example POST request:
  10. ## curl --data-urlencode 'key=value' http://host/uri
  11. ##
  12. ## returns: 200 (+ output of operation) on success
  13. ## 406 (+ error message in debug mode) on error
  14. readonly _WWW='/www'
  15. readonly _PWDFILE="/opt/lib/htpasswd"
  16. readonly _TMP='/tmp'
  17. readonly _LOG="${_WWW}/log/admin.log"
  18. readonly _SCRIPTS='/opt/lib/scripts'
  19. readonly _DEBUG=1
  20. readonly _IFS=$IFS
  21. err() {
  22. _ERR="$?"
  23. [[ "$_ERR" -gt 0 ]] || return 0
  24. logThis "$1"
  25. headerPrint "${2:='400'}"
  26. exit "$_ERR"
  27. }
  28. logThis() {
  29. [[ "$_DEBUG" -gt 0 ]] || return 0
  30. local _TYPE='I:'
  31. [[ "$_ERR" -gt 0 ]] && _TYPE='E:'
  32. local _TIME; printf -v _TIME '%(%d.%m.%Y %H:%M:%S)T' -1
  33. printf '%b\n' "$_TIME $_TYPE ${@} " >> "$_LOG"
  34. [[ "$_DEBUG" -gt 1 ]] && printf '%b\n' "[verbose] $_TYPE ${1}"
  35. return $_ERR
  36. }
  37. headerPrint() {
  38. case "$1" in
  39. 200|'') printf '%b' 'Status: 200 OK\r\n';;
  40. 301) printf '%b' "Status: 301 Moved Permanently\r\nLocation: $HTTP_REFERER\r\n";;
  41. 403) printf '%b' 'Status: 403 Forbidden\r\n';;
  42. 405) printf '%b' 'Status: 405 Method Not Allowed\r\n';;
  43. 406) printf '%b' 'Status: 406 Not Acceptable\r\n';;
  44. *) printf '%b' 'Status: 400 Bad Request\r\n';;
  45. esac
  46. printf '%b' 'Content-Type: text/html\r\n\r\n';
  47. }
  48. ## faster echo
  49. _echo() {
  50. printf "%b" "${*}"
  51. }
  52. urlDec() {
  53. local value=${*//+/%20}
  54. for part in ${value//%/ \\x}; do
  55. printf "%b%s" "${part:0:4}" "${part:4}"
  56. done
  57. }
  58. setQueryVars() {
  59. _VARS=( ${!POST_*} )
  60. # local v
  61. # for v in ${_VARS[@]}; do
  62. # echo $v
  63. # v=$(urlDec "${v}")
  64. # eval "_${v//POST_/}=${!v}";
  65. # done
  66. local v
  67. for v in ${_VARS[@]}; do
  68. logThis "$v=${!v}"
  69. done
  70. #echo $POST_lanssid
  71. #env
  72. }
  73. getQueryFile() {
  74. # setQueryVars
  75. local _UPLD="${HASERL_fwupload_path##*/}"
  76. logThis "'multipart': decoding stream"
  77. mv "$_TMP/$_UPLD" "$_TMP/fwupload.bin" 2>/dev/null || _ERR=$?
  78. if [[ $_ERR -gt 0 ]]; then
  79. showMesg 'Firmware upload has failed' '60' 'Reboot your Superglue server and try again'
  80. fi
  81. }
  82. validIp() {
  83. local _IP=$1
  84. local _RET=1
  85. if [[ $_IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
  86. OIFS=$IFS
  87. IFS='.'
  88. _IP=($_IP)
  89. IFS=$OIFS
  90. [[ ${_IP[0]} -le 255 && ${_IP[1]} -le 255 && ${_IP[2]} -le 255 && ${_IP[3]} -le 255 ]]
  91. _RET=$?
  92. fi
  93. return $_RET
  94. }
  95. pwdChange() {
  96. local _USER='admin'
  97. local _REALM='superglue'
  98. [[ -e $_PWDFILE ]] || showMesg 'Password file not found'
  99. [[ -z "${POST_pwd##$POST_pwdd}" ]] || showMesg 'Passwords did not match'
  100. [[ ${#POST_pwd} -ge 6 ]] || showMesg 'Password must be at least 6 characters long'
  101. local _HASH=$(printf '%s' "$_USER:$_REALM:${POST_pwd}" | md5sum | cut -b -32) &&
  102. printf '%b' "${POST_pwd}\n${POST_pwd}\n" | passwd root &&
  103. printf '%b' "$_USER:$_REALM:$_HASH\n" > $_PWDFILE &&
  104. showMesg 'Password is changed' '2' ||
  105. showMesg 'Password change failed!' '5'
  106. }
  107. lanAddr() {
  108. logThis "new LAN addr is: $POST_lanipaddr"
  109. validIp $POST_lanipaddr || showMesg 'Not valid network address'
  110. doUci set lanipaddr $POST_lanipaddr &&
  111. doUci commit network &&
  112. dtach -n -zE $_SCRIPTS/net-restart.sh &>/dev/null &&
  113. showMesg 'New network address is set' '30' "Your server is now accessible under <a href='http://superglue.local/admin'>http://superglue.local/admin</a>" ||
  114. showMesg 'Setting network address failed'
  115. }
  116. wanSet() {
  117. if [[ ! -z $POST_wanifname ]]; then
  118. ## eth and wlan wan cases are different!
  119. ## eth wan requires:
  120. ## config interface 'wan'
  121. ## option proto 'dhcp'
  122. ## option ifname 'eth0'
  123. ##
  124. ## wlan wan requires:
  125. ## config interface 'wan'
  126. ## option proto 'dhcp' (and no 'option ifname' specified!)
  127. logThis "wan.ifname=$POST_wanifname"
  128. if [[ $POST_wanifname == 'eth0' ]]; then
  129. doUci set wanifname $POST_wanifname
  130. doUci set wanwifacedis '1'
  131. elif [[ $POST_wanifname == 'wlan1' ]]; then
  132. doUci set wanifname ''
  133. doUci set wanwifacedis ''
  134. fi
  135. if [[ $POST_wanproto == 'dhcp' ]]; then
  136. doUci set wanproto dhcp
  137. doUci set wanipaddr ''
  138. doUci set wanmask ''
  139. doUci set wangw ''
  140. doUci set wandns ''
  141. elif [[ $POST_wanproto == 'static' ]]; then
  142. logThis "wan.ipaddr=$POST_wanipaddr"
  143. validIp $POST_wanipaddr || showMesg 'Our IP address is not valid' '3' 'make sure to use correct address notation'
  144. validIp $POST_wangw || showMesg 'Gateway is not a valid IP address' '3' 'make sure to use correct address notation'
  145. validIp $POST_wandns || showMesg 'DNS is not a valid IP address' '3' 'make sure to use correct address notation'
  146. doUci set wanproto static
  147. doUci set wanipaddr $POST_wanipaddr
  148. doUci set wanmask '255.255.255.0' ## fix me
  149. doUci set wangw $POST_wangw
  150. doUci set wandns $POST_wandns
  151. fi
  152. if [[ $POST_wanifname == 'wlan1' ]]; then
  153. ssidChange || showMesg 'wanSet: Wireless configuration failed'
  154. else
  155. doUci commit network &&
  156. doUci commit wireless &&
  157. dtach -n -zE $_SCRIPTS/net-restart.sh &>/dev/null
  158. fi
  159. _ERR=$?
  160. [[ $_ERR -eq 0 ]] &&
  161. showMesg 'Internet connection is being configured' '25' 'check your Internet connection on completion' ||
  162. showMesg 'Configuring Internet connection failed' '5'
  163. fi
  164. }
  165. ssidChange() {
  166. ## check for iface
  167. [[ $POST_iface =~ ^('wan'|'lan')$ ]] || showMesg 'Error changing wireless settings' '5' 'unknown or unconfigured interface'
  168. logThis "$POST_iface is being set"
  169. _p=$POST_iface
  170. ## default enc for now
  171. local _enc='psk2'
  172. if [[ $POST_iface == 'wan' ]]; then
  173. local _mode='sta'
  174. local _ssid="${POST_wanssid}"
  175. local _key="${POST_wankey}"
  176. else
  177. local _mode='ap'
  178. local _ssid="${POST_lanssid}"
  179. local _key="${POST_lankey}"
  180. fi
  181. #logThis "ssid: $_ssid [$_mode], key: $_key [$_enc]"
  182. #logThis $POST_wanssid
  183. [[ ${#_ssid} -ge 3 ]] || showMesg 'SSID must be at least 3 characters long'
  184. doUci set $_p'ssid' "${_ssid}"
  185. if [[ -z $_key ]]; then
  186. ## if key is empty set encryption to none and remove key
  187. doUci set $_p'key' && doUci set $_p'enc' 'none'
  188. _ERR=$?
  189. else
  190. [[ ${#_key} -ge 8 ]] || showMesg 'Passphrase must be at least 8 characters long'
  191. doUci set $_p'key' "${_key}" && doUci set $_p'enc' "${_enc}"
  192. fi
  193. [[ $_ERR -eq 0 ]] || showMesg 'ssidChange: Wireless configuration failed'
  194. if [[ $POST_iface == 'lan' ]]; then
  195. if [[ "$(doUci get lanipaddr)" != "${POST_lanipaddr}" ]]; then
  196. logThis 'local IP was changed'
  197. lanAddr
  198. fi
  199. fi
  200. doUci commit wireless
  201. _ERR=$?
  202. [[ $_ERR -eq 0 ]] &&
  203. dtach -n -zE $_SCRIPTS/net-restart.sh &>/dev/null ||
  204. showMesg 'Wireless configuration failed' '5'
  205. [[ $POST_iface == 'lan' ]] &&
  206. showMesg 'Local network configuration is progress' '30' 'check your connection on completion' || return 0
  207. ## in this case wanSet() handles success message
  208. }
  209. showMesg() {
  210. local _RET=$?
  211. local _MSG=$1
  212. local _TIMEOUT=$2
  213. local _SUBMSG=$3
  214. ## if set, global _ERR value prevails
  215. [[ $_ERR -gt $_RET ]] && _RET=$_ERR
  216. _MSG=${_MSG:='Configuration'}
  217. _TIMEOUT=${_TIMEOUT:='5'}
  218. _SUBMSG="${_SUBMSG} <span id='timeout'>${_TIMEOUT}</span> seconds to get ready.."
  219. if [[ $_RET -gt 0 ]]; then
  220. local _TYPE='ERROR: '
  221. headerPrint 406
  222. else
  223. local _TYPE='OK: '
  224. headerPrint 200
  225. fi
  226. htmlHead "<meta http-equiv='refresh' content='${_TIMEOUT};url=http://${HTTP_HOST}/admin'>"
  227. _echo "<body>
  228. <h1>Superglue control panel</h1>
  229. <img src='http://${HTTP_HOST}/resources/img/superglueLogo.png' class='logo'>
  230. <hr>
  231. <h2 style='display:inline'>$_TYPE $_MSG</h2>
  232. <span style='display:block'>$_SUBMSG</span>
  233. <hr>
  234. </body>
  235. <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')
  236. </script>
  237. </html>"
  238. exit $_RET
  239. }
  240. updateFw() {
  241. local _FWFILE="${_TMP}/fwupload.bin"
  242. _OUT="$(sysupgrade -T $_FWFILE 2>&1)" ||
  243. { _ERR=$?; rm -rf $_FWFILE; showMesg 'This is not a firmware!' '3' "$_OUT"; }
  244. [[ $POST_fwreset == 'on' ]] && { _FWRESET='-n'; logThis 'fw reset requested'; }
  245. ## using dtach to prevent sysupgrade getting killed
  246. dtach -n -zE sysupgrade $_FWRESET $_FWFILE 2>&1 &&
  247. showMesg 'Firmware update is in progress..' '120' 'DO NOT INTERRUPT!' ||
  248. { _ERR=$?; rm -rf $_FWFILE; showMesg 'Firmware update failed..' '3'; }
  249. }
  250. usbInit() {
  251. . $_SCRIPTS/usb-part.sh
  252. _OUT="$(usbPart)" &&
  253. showMesg 'USB storage initialization is completed' '30' ||
  254. showMesg "USB init failed!\n$_OUT"
  255. # logThis 'usb init..'
  256. }
  257. rebootNow() {
  258. logThis "reboot: now!"
  259. reboot
  260. showMesg 'Rebooting..' '60'
  261. }
  262. upTime() {
  263. local _T="$(uptime)" &&
  264. { headerPrint 200; printf '%b' "$_T\n"; exit 0; } ||
  265. headerPrint 406
  266. }
  267. iwScan() {
  268. . $_SCRIPTS/iw-scan.sh
  269. headerPrint 200
  270. iwScan
  271. exit 0
  272. }
  273. findUsbstor() {
  274. local _P='/sys/block/'
  275. local _D _DEV
  276. for _D in ${_P}sd*; do
  277. _DEV=$(readlink -f ${_D}/device)
  278. if [[ ${_DEV/usb} != $_DEV ]]; then
  279. _USBDEV="/dev/${_D/$_P}"
  280. fi
  281. done
  282. [[ $_USBDEV ]] || return 1
  283. }
  284. storageInfo() {
  285. if mountpoint -q $_WWW; then
  286. IFS=$'\n' _STOR=( $(df -h $_WWW) ) IFS=$_IFS
  287. _STOR=( ${_STOR[1]} )
  288. else
  289. return 1
  290. fi
  291. }
  292. swapInfo() {
  293. IFS=$'\n' _SWAP=( $(swapon -s) ) IFS=$_IFS
  294. if [[ ${_SWAP[1]} ]]; then
  295. IFS=$'\t' _SWAP=( ${_SWAP[1]} ) IFS=$_IFS
  296. ## for the lack of floats add trailing 0
  297. ## divide by 1023 and split last digit by a period
  298. _SWAP[1]="$((${_SWAP[1]}0/1023))"
  299. _SWAP[1]="${_SWAP[1]%?}.${_SWAP[1]/??}M"
  300. else
  301. unset _SWAP
  302. return 1
  303. fi
  304. }
  305. trimSpaces() {
  306. local v="$*"
  307. v="${v#"${v%%[![:space:]]*}"}"
  308. v="${v%"${v##*[![:space:]]}"}"
  309. return "$v"
  310. }
  311. dynDns() {
  312. ## curently only http://freedns.afraid.org is supported
  313. [[ $POST_dyndnsname && $POST_dyndnsuser && $POST_dyndnspass ]] || showMesg 'All values must be set!'
  314. doUci set dyndnsname "$POST_dyndnsname" &&
  315. doUci set dyndnsuser "$POST_dyndnsuser" &&
  316. doUci set dyndnspass "$POST_dyndnspass" || showMesg 'DynDNS settings failed..'
  317. ## create sha1 string per http://freedns.afraid.org/api
  318. local _DURL
  319. local _AFRAID='http://freedns.afraid.org/api/?action=getdyndns&sha='
  320. _DURL=$(_echo "$POST_dyndnsuser|$POST_dyndnspass" | sha1sum)
  321. _DURL="$_AFRAID${_DURL/ -/}"
  322. _DURL="$(wget -q $_DURL -O -)"
  323. local _L
  324. local _RES
  325. for _L in $_DURL
  326. do case $_L in
  327. "${POST_dyndnsname}|"*) IFS='|' _RES=( $_L ); break;;
  328. 'ERROR'*) _RES=0; break;;
  329. *) unset _RES;;
  330. esac;
  331. done
  332. [[ $_RES ]] || showMesg 'Domain name is not found' '10' 'Make sure you entered correct domain name -'
  333. [[ $_RES -eq 0 ]] || showMesg 'Authentication failed' '10' 'Check your username and password and try again -'
  334. logThis "${_RES[@]}"
  335. doUci set dyndnsurl "${_RES[2]}" &&
  336. doUci set dyndnsdis '' &&
  337. doUci commit
  338. showMesg 'DynDNS configuration is in progress..' '10' 'After completion, your URL will become available with in 10-15 minutes'
  339. }
  340. doUci() {
  341. local _CMD=''
  342. local _ARG=''
  343. case $1 in
  344. get|set|commit) _CMD=$1;;
  345. *) logThis 'bad UCI command'; headerPrint 405; echo 'bad UCI command'; exit 1 ;;
  346. esac
  347. case $2 in
  348. lanssid) _ARG='wireless.@wifi-iface[0].ssid';;
  349. lanenc) _ARG='wireless.@wifi-iface[0].encryption';;
  350. lankey) _ARG='wireless.@wifi-iface[0].key';;
  351. lanipaddr) _ARG='network.lan.ipaddr';;
  352. wanifname) _ARG='network.wan.ifname';;
  353. wanproto) _ARG='network.wan.proto';;
  354. wanipaddr) _ARG='network.wan.ipaddr';;
  355. wanmask) _ARG='network.wan.netmask';;
  356. wangw) _ARG='network.wan.gateway';;
  357. wandns) _ARG='network.wan.dns';;
  358. wanwifacedis) _ARG='wireless.@wifi-iface[1].disabled';;
  359. wanssid) _ARG='wireless.@wifi-iface[1].ssid';;
  360. wanenc) _ARG='wireless.@wifi-iface[1].encryption';;
  361. wankey) _ARG='wireless.@wifi-iface[1].key';;
  362. dyndnsdis) _ARG='superglue.dyndns.disabled';;
  363. dyndnsurl) _ARG='superglue.dyndns.updateurl';;
  364. dyndnsname) _ARG='superglue.dyndns.domainname';;
  365. dyndnsuser) _ARG='superglue.dyndns.username';;
  366. dyndnspass) _ARG='superglue.dyndns.password';;
  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. /sbin/uci delete $_ARG || ( echo "uci delete $_ARG: error"; exit 1; )
  385. fi
  386. if [ ! -z $_ARG ]; then
  387. logThis "setting $_ARG value"
  388. /sbin/uci set $_ARG=$_VAL || ( echo "uci set $_ARG: error"; exit 1; )
  389. fi
  390. fi
  391. if [[ $_CMD == 'commit' ]]; then
  392. /sbin/uci commit $_ARG || echo "uci commit $_ARG: error"
  393. fi
  394. }
  395. ## call with argument to inject additional lines
  396. ## ie: htmlhead "<meta http-equiv='refresh' content='2;URL=http://${HTTP_REFERER}'>"
  397. htmlHead() {
  398. _echo "<!-- obnoxious code below, keep your ports tight -->
  399. <!doctype html>
  400. <html>
  401. <head>
  402. <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
  403. <meta http-equiv='Cache-Control' content='no-cache, no-store, must-revalidate' />
  404. <meta http-equiv='Pragma' content='no-cache' />
  405. <meta http-equiv='Expires' content='0' />
  406. <link rel='icon' href='http://${HTTP_HOST}/resources/img/favicon.ico' type='image/x-icon' />
  407. <title>Superglue | Control panel</title>
  408. <link rel='stylesheet' type='text/css' href='http://${HTTP_HOST}/resources/admin/admin.css' />
  409. $@
  410. </head>"
  411. }
  412. footerBody() {
  413. _echo "</body>
  414. <script type='text/javascript' src='http://${HTTP_HOST}/resources/admin/admin.js'></script>
  415. </html>"
  416. }
  417. if [[ "${REQUEST_METHOD^^}" == "POST" ]]; then
  418. [[ $CONTENT_LENGTH -gt 0 ]] || err 'content length is zero, 301 back to referer' '301'
  419. case "${CONTENT_TYPE^^}" in
  420. APPLICATION/X-WWW-FORM-URLENCODED*) setQueryVars;;
  421. MULTIPART/FORM-DATA*) getQueryFile;;
  422. *) _ERR=1; _OUT='this is not a post';;
  423. esac
  424. case $REQUEST_URI in
  425. *pwdchange) pwdChange;;
  426. *ssidchange) ssidChange;;
  427. *lanaddr) lanAddr;;
  428. *updatefw) updateFw;;
  429. *usbinit) usbInit;;
  430. *rebootnow) rebootNow;;
  431. *wan) wanSet;;
  432. *uptime) upTime;;
  433. *iwscan) iwScan;;
  434. *dyndns) dynDns;;
  435. *) logThis 'bad action'; headerPrint 405;
  436. echo 'no such thing'; exit 1;;
  437. esac
  438. fi
  439. headerPrint '200'
  440. htmlHead
  441. read sgver < /etc/superglue_version
  442. read devmod < /etc/superglue_model
  443. read openwrt < /etc/openwrt_version
  444. . /opt/lib/scripts/jshn-helper.sh
  445. ## this does not work when iface isn't configured
  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. %>
  458. <body>
  459. <h1>Superglue control panel</h1>
  460. <img src='http://<% _echo "${HTTP_HOST}" %>/resources/img/superglueLogo.png' class='logo'>
  461. <section class='inert'>
  462. <span style='display:block;'><% printf "System version: %s | Device: %s | OpenWRT: %s" "$sgver" "$devmod" "$openwrt" %></span>
  463. <span style='display:block;' id='uptime'><% uptime %></span>
  464. </section>
  465. <section>
  466. <h2>Internet connection:</h2>
  467. <form method='post' action='/admin/wan' name='wan' class='elem' id='wanconf'>
  468. <div style='display:inline-flex'>
  469. <div style='display:inline-block;'>
  470. <select name='wanifname' id='wanifname' style='display:block'>
  471. <option value='eth0' id='eth' <% ( [[ $wanifname =~ ('eth') ]] && _echo 'selected' ) %> >Wired (WAN port)</option>
  472. <option value='wlan1' id='wlan' <% ( [[ $wanifname =~ ('wlan') ]] && _echo 'selected' ) %> >Wireless (WiFi)</option>
  473. </select>
  474. <fieldset id='wanwifi' <% ( [[ $wanifname =~ ('wlan') ]] && _echo "class='show elem'" || _echo "class='hide elem'" ) %>>
  475. <select name='wanssid' id='wanssid' class='elem' style='display:block'>
  476. <% if [[ -z $wanssid ]]; then
  477. _echo "<option id='scan' disabled>select a network..</option>"
  478. else
  479. _echo "<option id=$wanssid selected>$wanssid</option>"
  480. fi %>
  481. </select>
  482. <input type='password' name='wankey' placeholder='passphrase' value='<% _echo $wankey %>'>
  483. </fieldset>
  484. <span class='help'>help</span>
  485. </div>
  486. <div style='display:inline-block;'>
  487. <select name='wanproto' id='wanproto' style='display:block'>
  488. <option value='dhcp' name='dhcp' id='dhcp' <% ([[ $wanproto == 'dhcp' ]] && _echo 'selected') %>>Automatic (DHCP)</option>
  489. <option value='static' name='stat' id='stat' <% ([[ $wanproto == 'static' ]] && _echo 'selected') %>>Manual (Static IP)</option>
  490. </select>
  491. <fieldset id='wanaddr' class='elem'>
  492. <input type='text' name='wanipaddr' id='wanipaddr' value='<% _echo $wanipaddr %>' <% ( [[ $wanproto =~ ('dhcp') ]] && _echo "readonly" ) %> placeholder='ip address'>
  493. <input type='text' name='wangw' id='wangw' value='<% _echo $wangw %>' <% ( [[ $wanproto =~ ('dhcp') ]] && _echo "readonly" ) %> placeholder='gateway/router'>
  494. <input type='text' name='wandns' id='wandns' value='<% _echo $wandns %>' <% ( [[ $wanproto =~ ('dhcp') ]] && _echo "readonly" ) %> placeholder='dns server'>
  495. </fieldset>
  496. </div>
  497. </div>
  498. <input type='hidden' name='iface' value='wan' class='inline'>
  499. <input type='submit' id='wansubmit' value='Apply'>
  500. </form>
  501. <span class='help'>help</span>
  502. </section>
  503. <section>
  504. <h2>Domain name:</h2>
  505. <form method='post' action='/admin/dyndns' name='dyndns' id='afraid'>
  506. <div style='display:inline-flex'>
  507. <div style='display:inline-block;'>
  508. <input type='text' name='dyndnsname' id='dyndnsname' value='<% _echo $dyndnsname %>' placeholder='domain name' class='block'>
  509. </div>
  510. <div style='display:inline-block;'>
  511. <input type='text' name='dyndnsuser' id='dyndnsuser' value='<% _echo $dyndnsuser %>' placeholder='dyndns username' class='block'>
  512. <input type='password' name='dyndnspass' id='dyndnspass' value='<% _echo $dyndnspass %>' placeholder='dyndns password' class='block'>
  513. </div>
  514. </div>
  515. <input type='hidden' name='dns' value='apply' class='inline'>
  516. <input type='submit' value='Apply'>
  517. </form>
  518. <h2>Dynamic 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. <div style='display:inline-flex'>
  522. <div style='display:inline-block;'>
  523. <input type='text' name='subdomain' placeholder='yourname' class='inline'>
  524. </div>
  525. <div style='display:inline-block;'>
  526. <select name='edit_domain_id' class='inline'>
  527. <option value='1035903'>spgl.cc</option>
  528. <option value='1035903'>spgl.it</option>
  529. </select>
  530. </div>
  531. </div>
  532. <input type='submit' name='submit' value="next &gt;&gt;">
  533. <input type='hidden' name='web_panel' value='1'>
  534. <input type='hidden' name='ref' value='750930'>
  535. </form>
  536. <span class='help'>help</span>
  537. </section>
  538. <section>
  539. <h2>Local wireless network:</h2>
  540. <form method='post' action='/admin/ssidchange'>
  541. <div style='display:inline-flex'>
  542. <div style='display:inline-block;'>
  543. <input type='text' name='lanssid' value='<% doUci get lanssid %>'>
  544. <input type='password' name='lankey' value='<% doUci get lankey %>'>
  545. </div>
  546. <div style='display:inline-block;'>
  547. <input type='text' name='lanipaddr' value='<% doUci get lanipaddr %>'>
  548. <input type='hidden' name='iface' value='lan'>
  549. </div>
  550. </div>
  551. <input type='submit' value='Apply' data-wait='Configuring..'>
  552. </form>
  553. <span class='help'>help</span>
  554. </section>
  555. <section>
  556. <h2>Storage:</h2>
  557. <% if findUsbstor; then %>
  558. <% if storageInfo; then %>
  559. <div>File storage: <% _echo "${_STOR[2]} used, ${_STOR[3]} available" %></div>
  560. <div>Swap: <% swapInfo && _echo "${_SWAP[1]}" || _echo '<b>n/a</b>' %></div>
  561. <% else %>
  562. <div>USB storage device must be initialized</div>
  563. <form method='post' action='/admin/usbinit'>
  564. <input type='hidden' name='dev' value='<% _echo $_USBDEV %>'>
  565. <input type='submit' value='Initialize'>
  566. </form>
  567. <% fi %>
  568. <% else %>
  569. <div><h3>USB storage device not found!</h3>Please check and try again</div>
  570. <% fi %>
  571. <span class='help'>help</span>
  572. </section>
  573. <section>
  574. <h2>Change password:</h2>
  575. <form method='post' action='/admin/pwdchange'>
  576. <div style='display:inline-flex'>
  577. <div style='display:inline-block;'>
  578. <input type='text' name='usr' value='admin' readonly>
  579. </div>
  580. <div style='display:inline-block;'>
  581. <input type='password' name='pwd' placeholder='password' value=''>
  582. <input type='password' name='pwdd' placeholder='password again' value=''>
  583. </div>
  584. </div>
  585. <input type='submit' value='Apply'>
  586. </form>
  587. <span class='help'>help</span>
  588. </section>
  589. <section>
  590. <h2>Firmware upgrade:</h2>
  591. <form method='post' action='/admin/updatefw' enctype='multipart/form-data'>
  592. <div id='uploadbox'>
  593. <input id='uploadfile' placeholder='Select a file..' class='elem' disabled='disabled'>
  594. <input id='uploadbtn' class='elem' name='fwupload' type='file'>
  595. </div>
  596. <div style='display:inline-block;'>
  597. <input type='checkbox' name='fwreset' id='fw-resetbox' />
  598. <label for='fw-resetbox'>Reset all settings</label>
  599. </div>
  600. <input type='submit' value='Upload' data-wait='Uploading, do NOT interrupt!'>
  601. </form>
  602. <span class='help'>help</span>
  603. </section>
  604. <section>
  605. <h2></h2>
  606. <form action='/admin/rebootnow' method='post' class='inline'>
  607. <input type='hidden' name='reboot' value='now' class='inline'>
  608. <input type='submit' value='Reboot' class='inline'>
  609. </form>
  610. <form action='http://logout@<% _echo ${HTTP_HOST} %>/admin' method='get' class='inline'>
  611. <input type='submit' value='Logout' class='inline'>
  612. </form>
  613. </section>
  614. <div style='height:200px'></div>
  615. <hr>
  616. Memory:
  617. <pre><% free %></pre>
  618. <hr>
  619. Storage:
  620. <pre><% df -h %></pre>
  621. <hr>
  622. Environment:
  623. <pre><% env %></pre>
  624. <hr>
  625. <%
  626. footerBody
  627. exit 0
  628. %>