diff --git a/.gitignore b/.gitignore index 4a2de0c9..acab9ea7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ bin/* data/* !data/edit.htm +!data/main.js !data/edit.htm.gz !data/openhasp.ttf !data/style.css diff --git a/data/edit.htm b/data/edit.htm index d28420dd..cd185e2c 100644 --- a/data/edit.htm +++ b/data/edit.htm @@ -1 +1,665 @@ -File Editor
\ No newline at end of file + + + + + + + + + + + + + openHASP + + + + + + + + + + + + +
+
+
+
+ +
+
+
+
+
+
+ + +
+ + + +
+ + config.jsonl + + +
+
+
+ +
+
+ +
+
+ + + + + diff --git a/data/main.js b/data/main.js new file mode 100644 index 00000000..faad72b7 --- /dev/null +++ b/data/main.js @@ -0,0 +1 @@ +import{createApp,reactive,createI18n}from"/static/petite-vue.hasp.js?COMMIT_HASH";const languages=[{code:"en",name:"English"},{code:"nl",name:"Nederlands"},{code:"fr",name:"Français"}];var locations={af:["Abidjan","Algiers","Bissau","Cairo","Casablanca","El_Aaiun","Johannesburg","Juba","Khartoum","Lagos","Maputo","Monrovia","Nairobi","Ndjamena","Sao_Tome","Tripoli","Tunis","Windhoek","Cape_Verde","Mauritius"],eu:["Ceuta","Danmarkshavn","Nuuk","Scoresbysund","Thule","Anadyr","Barnaul","Chita","Irkutsk","Kamchatka","Khandyga","Krasnoyarsk","Magadan","Novokuznetsk","Novosibirsk","Omsk","Sakhalin","Srednekolymsk","Tomsk","Ust-Nera","Vladivostok","Yakutsk","Yekaterinburg","Azores","Canary","Faroe","Madeira","Andorra","Astrakhan","Athens","Belgrade","Berlin","Brussels","Bucharest","Budapest","Chisinau","Dublin","Gibraltar","Helsinki","Istanbul","Kaliningrad","Kirov","Kyiv","Lisbon","London","Madrid","Malta","Minsk","Moscow","Paris","Prague","Riga","Rome","Samara","Saratov","Sofia","Tallinn","Tirane","Ulyanovsk","Vienna","Vilnius","Volgograd","Warsaw","Zurich"],as:["Almaty","Amman","Aqtau","Aqtobe","Ashgabat","Atyrau","Baghdad","Baku","Bangkok","Beirut","Bishkek","Choibalsan","Colombo","Damascus","Dhaka","Dili","Dubai","Dushanbe","Famagusta","Gaza","Hebron","Ho_Chi_Minh","Hong_Kong","Hovd","Jakarta","Jayapura","Jerusalem","Kabul","Karachi","Kathmandu","Kolkata","Kuching","Macau","Makassar","Manila","Nicosia","Oral","Pontianak","Pyongyang","Qatar","Qostanay","Qyzylorda","Riyadh","Samarkand","Seoul","Shanghai","Singapore","Taipei","Tashkent","Tbilisi","Tehran","Thimphu","Tokyo","Ulaanbaatar","Urumqi","Yangon","Yerevan","Chagos","Maldives"],au:["Perth","Eucla","Adelaide","Broken_Hill","Darwin","Brisbane","Hobart","Lindeman","Melbourne","Sydney","Lord_Howe"],na:["Adak","Anchorage","Bahia_Banderas","Barbados","Belize","Boise","Cambridge_Bay","Cancun","Chicago","Chihuahua","Ciudad_Juarez","Costa_Rica","Dawson","Dawson_Creek","Denver","Detroit","Edmonton","El_Salvador","Fort_Nelson","Glace_Bay","Goose_Bay","Grand_Turk","Guatemala","Halifax","Havana","Hermosillo","Indiana/Indianapolis","Indiana/Knox","Indiana/Marengo","Indiana/Petersburg","Indiana/Tell_City","Indiana/Vevay","Indiana/Vincennes","Indiana/Winamac","Inuvik","Iqaluit","Jamaica","Juneau","Kentucky/Louisville","Kentucky/Monticello","Los_Angeles","Managua","Martinique","Matamoros","Mazatlan","Menominee","Merida","Metlakatla","Mexico_City","Miquelon","Moncton","Monterrey","New_York","Nome","North_Dakota/Beulah","North_Dakota/Center","North_Dakota/New_Salem","Ojinaga","Panama","Phoenix","Port-au-Prince","Puerto_Rico","Rankin_Inlet","Regina","Resolute","Santo_Domingo","Sitka","St_Johns","Swift_Current","Tegucigalpa","Tijuana","Toronto","Vancouver","Whitehorse","Winnipeg","Yakutat","Yellowknife","Bermuda","Honolulu"],sa:["Araguaina","Argentina/Buenos_Aires","Argentina/Catamarca","Argentina/Cordoba","Argentina/Jujuy","Argentina/La_Rioja","Argentina/Mendoza","Argentina/Rio_Gallegos","Argentina/Salta","Argentina/San_Juan","Argentina/San_Luis","Argentina/Tucuman","Argentina/Ushuaia","Asuncion","Bahia","Belem","Boa_Vista","Bogota","Campo_Grande","Caracas","Cayenne","Cuiaba","Eirunepe","Fortaleza","Guayaquil","Guyana","La_Paz","Lima","Maceio","Manaus","Montevideo","Noronha","Paramaribo","Porto_Velho","Punta_Arenas","Recife","Rio_Branco","Santarem","Santiago","Sao_Paulo","Palmer","South_Georgia","Stanley","Easter","Galapagos"],at:["Cape_Verde","Canary","Faroe","Madeira","Azores","Bermuda","South_Georgia","Stanley"],in:["Mauritius","Maldives","Chagos"],pa:["Palau","Guam","Port_Moresby","Bougainville","Efate","Guadalcanal","Kosrae","Norfolk","Noumea","Auckland","Fiji","Kwajalein","Nauru","Tarawa","Chatham","Apia","Fakaofo","Kanton","Tongatapu","Kiritimati","Pitcairn","Gambier","Marquesas","Rarotonga","Tahiti","Niue","Pago_Pago","Honolulu","Easter","Galapagos"],aq:["Troll","Mawson","Davis","Casey","Rothera","Macquarie","Palmer"],etc:["Greenwich","Universal","Zulu","GMT-14","GMT-13","GMT-12","GMT-11","GMT-10","GMT-9","GMT-8","GMT-7","GMT-6","GMT-5","GMT-4","GMT-3","GMT-2","GMT-1","GMT","GMT+1","GMT+2","GMT+3","GMT+4","GMT+5","GMT+6","GMT+7","GMT+8","GMT+9","GMT+10","GMT+11","GMT+12","UCT","UTC"]};const regions={etc:"Etc",af:"Africa",as:"Asia",au:"Australia",aq:"Antarctica",eu:"Europe",na:"America",sa:"America",at:"Atlantic",in:"Indian",pa:"Pacific"},licenseData=[],licenseApp=[{t:"Petite Vue",y:2021,a:"Yuxi (Evan) You",l:"mit"},{t:"Petite Vue I18n Lite",y:2021,a:"Front Labs",l:"mit"},{t:"Ace Editor",y:2010,a:"Ajax.org B.V.",r:1,l:"bsd"},{t:"MaterialDesign Icons",y:2022,a:"Google",l:"apache2"}];function Credits(a){return{$template:"#credit-template",model:a}}function RegionItem(a,e,t){return{$template:"#region-template",model:a,region:e,i18n:t,list(t){if(a[t]&&e[t]){for(var n="etc"===t?a[t]:a[t].sort(),o=[],i=0;it.t(a).toString().replace(/_/g," ")}}fetch("/static/en.json?COMMIT_HASH").then((a=>a.json())).then((a=>{const e=reactive(createI18n({locale:"en",fallbackLocale:"en",messages:{en:a.en}}));createApp({i18n:e,languages:languages,RegionItem:RegionItem,regions:regions,locations:locations,licenseData:licenseData,licenseApp:licenseApp,Credits:Credits,hostname:null,title:null,config:{hasp:null,wifi:null,mqtt:null,http:null,gui:null,gpio:null,debug:null,time:null,ota:null},info:null,files:null,show:null,t(a){return this.i18n.t(a)},fetchConfig(a){fetch("/api/config/"+a+"/").then((a=>a.json())).then((e=>{this.config[a]=e,this.show=a,document.title=a}))},submitConfig(){let a=this.show;fetch("/api/config/"+a+"/",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(this.config[a])}).then((a=>a.json())).then((e=>{this.config[a]=e,window.history.pushState({},"","/config/"),window.dispatchEvent(new Event("popstate"))}))},submitOldConfig(a){fetch("/api/config/"+a+"/",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(this.config[a])}).then((a=>a.json())).then((a=>{window.location.href="/config"}))},fetchLang(a){fetch("/static/"+a+".json?COMMIT_HASH").then((a=>a.json())).then((e=>{let t=e[a]?e[a]:{};this.i18n.setLocaleMessage(a,t),this.i18n.changeLocale(a)}))},fetchInfo(){fetch("/api/info/").then((a=>a.json())).then((a=>{this.info=a,this.show="info",document.title="Info"}))},fetchAbout(){fetch("/api/credits/").then((a=>a.json())).then((a=>{this.licenseData=a,this.show="about",document.title="About"}))},showPage(a){this.show=a,document.title=a,""!=a&&(a+="/")},showInfo(){this.fetchInfo(),document.title="Info"},showConfig(a){this.fetchConfig(a),document.title=a},showEditor(){fetch("/api/files/").then((a=>a.json())).then((a=>{this.files=a,this.show="edit";var e=document.getElementsByClassName("container__editor")[0];e&&(e.style.display="flex"),document.title="Editor"}))},handleLocation(a,e){const t={"/":()=>{this.showPage("")},"/hasp.htm":()=>{this.showPage("")},"/config/":()=>{this.showPage("config")},"/config/hasp/":()=>{this.showConfig("hasp")},"/config/wifi/":()=>{this.showConfig("wifi")},"/config/http/":()=>{this.showConfig("http")},"/config/mqtt/":()=>{this.showConfig("mqtt")},"/config/gui/":()=>{this.showConfig("gui")},"/config/ftp/":()=>{this.showConfig("ftp")},"/config/time/":()=>{this.showConfig("time")},"/config/debug/":()=>{this.showConfig("debug")},"/config/reset/":()=>{this.showPage("reset")},"/firmware/":()=>{this.showConfig("ota")},"/info/":()=>{this.showInfo()},"/screenshot/":()=>{this.showPage("screenshot")},"/about/":()=>{this.fetchAbout()},"/edit/":()=>{this.showEditor()},"/edit":()=>{},"/static/editor.htm":()=>{},"/reboot/":()=>{this.showPage("reboot")}};"function"==typeof t[a]?t[a]():"/"!==a.slice(-1)&&"function"==typeof t[a+"/"]?t[a+"/"]():t["/"];const n=document.getElementsByClassName("container__editor")[0];n&&(n.style.display=a.includes("/edit")?"flex":"none"),window.scrollTo({top:e})},mounted(){let a=decodeURIComponent(document.cookie).split(";");for(let e=0;e{const e=window.location.pathname;var t=a.state,n=0;t&&(n=t.scrollTop),this.handleLocation(e,n)};const e=window.location.pathname;this.handleLocation(e,0)},route(a){(a=a||window.event).preventDefault();const e=a.currentTarget.href||a.target.parentNode.href,t=new URL(e).pathname;if(window.location.pathname!=t){var n={path:window.location.href||a.target.href,scrollTop:document.body.scrollTop};window.history.replaceState(n,"",document.location.pathname),n={path:window.location.href,scrollTop:0},window.history.pushState(n,"",t),window.dispatchEvent(new Event("popstate"))}},goto(a){if(window.location.pathname!=a){var e={path:window.location.href,scrollTop:document.body.scrollTop};window.history.replaceState(e,"",document.location.pathname),e={path:window.location.href,scrollTop:0},window.history.pushState(e,"",a),window.dispatchEvent(new Event("popstate"))}},ref(a){},aref(a){setTimeout((function(){}),1e3*a)},upd(a){var e=(new Date).getTime();document.getElementById("bmp").src="/screenshot?a="+a+"&q="+e}}).directive("t",(({el:a,get:t,effect:n})=>n((()=>a.textContent=e.t(t()))))).directive("ts",(({el:a,get:t,effect:n})=>n((()=>a.textContent=e.t(t()).replace(/_/g," "))))).mount()})); \ No newline at end of file diff --git a/data/script.js b/data/script.js index 62ab6fb0..9a9fcc6f 100644 --- a/data/script.js +++ b/data/script.js @@ -17,7 +17,7 @@ function ihtm(id, html) { } function about() { ihtm("lic",'

openHASP

Copyright© 2019-2022 Francis Van Roie
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

'); - ihtm("pkg","

Based on the previous work of the following open source developers:

HASwitchPlate

Copyright© 2019 Allen Derusha allen @derusha.org
MIT License

LVGL

Copyright© 2021 LVGL Kft
MIT License

LovyanGFX

Copyright© 2020 lovyan03 (https://github.com/lovyan03) All rights reserved.
FreeBSD License

TFT_eSPI

Copyright© 2020 Bodmer (https://github.com/Bodmer) All rights reserved.
FreeBSD License

Adafruit_GFX

Copyright© 2012 Adafruit Industries. All rights reserved
BSD License

ArduinoJson

Copyright© 2014-2021 Benoit BLANCHON
MIT License

ArduinoLog

Copyright© 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, dhylands, Josha blemasle, mfalkvidd
MIT License

QR Code generator

Copyright© Project Nayuki
MIT License

SimpleFTPServer

Copyright© 2017 Renzo Mischianti www.mischianti.org All right reserved.
MIT License

AceButton

Copyright© 2018 Brian T. Park
MIT License

"); + ihtm("pkg","

Based on the previous work of the following open source developers:

HASwitchPlate

Copyright© 2019 Allen Derusha allen @derusha.org
MIT License

LVGL

Copyright© 2021 LVGL Kft
MIT License

LovyanGFX

Copyright© 2020 lovyan03 (https://github.com/lovyan03) All rights reserved.
FreeBSD License

TFT_eSPI

Copyright© 2020 Bodmer (https://github.com/Bodmer) All rights reserved.
FreeBSD License

Adafruit_GFX

Copyright© 2012 Adafruit Industries. All rights reserved
BSD License

ArduinoJson

Copyright© 2014-2021 Benoit BLANCHON
MIT License

PubSubClient

Copyright© 2008-2015 Nicholas O'Leary
MIT License

ArduinoLog

Copyright© 2017,2018 Thijs Elenbaas, MrRobot62, rahuldeo2047, NOX73, dhylands, Josha blemasle, mfalkvidd
MIT License

QR Code generator

Copyright© Project Nayuki
MIT License

SimpleFTPServer

Copyright© 2017 Renzo Mischianti www.mischianti.org All right reserved.
MIT License

AceButton

Copyright© 2018 Brian T. Park
MIT License

"); } function handleSubmit(e) { e.preventDefault(); @@ -126,7 +126,7 @@ function populate(e, t, o) { window.addEventListener('load', (event) => { - console.log('The page has fully loaded'); + // console.log('The page has fully loaded'); forms(); info(); about(); diff --git a/data/static/edit.htm.gz b/data/static/edit.htm.gz index 5a6eae02..cbea9b3c 100644 Binary files a/data/static/edit.htm.gz and b/data/static/edit.htm.gz differ diff --git a/data/static/en.json.gz b/data/static/en.json.gz index 9278e158..4c8f258b 100644 Binary files a/data/static/en.json.gz and b/data/static/en.json.gz differ diff --git a/data/static/fr.json.gz b/data/static/fr.json.gz new file mode 100644 index 00000000..84db85ac Binary files /dev/null and b/data/static/fr.json.gz differ diff --git a/data/static/hasp.htm.gz b/data/static/hasp.htm.gz index 7fb75272..391bb860 100644 Binary files a/data/static/hasp.htm.gz and b/data/static/hasp.htm.gz differ diff --git a/data/static/logo.svg b/data/static/logo.svg deleted file mode 100644 index c76e44b3..00000000 --- a/data/static/logo.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/data/static/main.js.gz b/data/static/main.js.gz index 77268994..d5feb9cf 100644 Binary files a/data/static/main.js.gz and b/data/static/main.js.gz differ diff --git a/data/static/nl.json.gz b/data/static/nl.json.gz new file mode 100644 index 00000000..744beee7 Binary files /dev/null and b/data/static/nl.json.gz differ diff --git a/data/static/script.js.gz b/data/static/script.js.gz index 3e7738bf..3fc28f3e 100644 Binary files a/data/static/script.js.gz and b/data/static/script.js.gz differ diff --git a/data/static/style.css.gz b/data/static/style.css.gz index 8466e9d6..d7ed0ac6 100644 Binary files a/data/static/style.css.gz and b/data/static/style.css.gz differ diff --git a/data/style.css b/data/style.css index df574e3a..eea45e82 100644 --- a/data/style.css +++ b/data/style.css @@ -8,9 +8,35 @@ --cog: url('data:image/svg+xml,'); --star: url('data:image/svg+xml,'); --trash: url('data:image/svg+xml,'); - --download: url('data:image/svg+xml,') + --download: url('data:image/svg+xml,'); + --file: url('data:image/svg+xml,'); + --dir: url('data:image/svg+xml,'); + --diropen: url('data:image/svg+xml,'); + --html: url('data:image/svg+xml,'); + --image: url('data:image/svg+xml,'); + --zip: url('data:image/svg+xml,'); + --cmd: url('data:image/svg+xml,'); + --css: url('data:image/svg+xml,'); + --eye: url('data:image/svg+xml,'); + --json: url('data:image/svg+xml,'); } +.fn:hover { + text-decoration: underline; +} +.fi { + display: inline-block; + vertical-align: middle; + width: 1.1rem; + height: 1.25rem; + mask-size: auto; + mask-repeat: no-repeat; + mask-position: center; + -webkit-mask-size: auto; + -webkit-mask-repeat: no-repeat; + -webkit-mask-position: center; + background-color: var(--txt); +} .fa { display: block; text-indent: -9999px; @@ -37,28 +63,17 @@ .fa-shot { mask-image: var(--shot); -webkit-mask-image: var(--shot)} .fa-star { mask-image: var(--star); -webkit-mask-image: var(--star)} .fa-trash { mask-image: var(--trash); -webkit-mask-image: var(--trask)} - -#ctx { - display: none; - top: 10px; - left: 50px; - position: absolute; - background: #fff; - z-index: 10; - padding: 0.75rem; - border-radius: 0.5rem; - box-shadow: 0 0.5rem 0.75rem rgba(0,0,0,0.25); -} -#ctx > ul { - padding-left: 0px; -} -#ctx > ul > li, -.sub_div > ul > li { - cursor: pointer; -} -#ctx > ul > li:hover { - background: #ccc; -} +.fa-file { mask-image: var(--file); -webkit-mask-image: var(--file)} +.fa-dir { mask-image: var(--dir); -webkit-mask-image: var(--dir)} +.fa-diropen { mask-image: var(--diropen); -webkit-mask-image: var(--diropen)} +.fa-eye { mask-image: var(--eye); -webkit-mask-image: var(--eye)} +.fa-zip { mask-image: var(--zip); -webkit-mask-image: var(--zip)} +.fa-css { mask-image: var(--css); -webkit-mask-image: var(--css)} +.fa-cmd { mask-image: var(--cmd); -webkit-mask-image: var(--cmd)} +.fa-json { mask-image: var(--json); -webkit-mask-image: var(--json)} +.fa-jsonl { mask-image: var(--json); -webkit-mask-image: var(--json)} +.fa-image { mask-image: var(--image); -webkit-mask-image: var(--image)} +.fa-html { mask-image: var(--html); -webkit-mask-image: var(--html)} .nav-list { font-size: var(--fs-nav); @@ -114,7 +129,7 @@ margin: 0px; padding: 0px; } -P { +p { margin: 1em 0px; } @@ -156,30 +171,27 @@ button, .warning{ color: #9F6000; background-color: #FEEFB3 } .error { color: #D8000C; background-color: #FFD2D2 } - -/* Navigation bar */ - -#filebrowser { - display: none -} +.left { float: left } +.right { float: right } +.bold { font-weight: bold } /* Main Page */ #doc { text-align: left; margin: 0 auto; - display: inline-block; + /* display: inline-block; + display: table; */ color: var(--txt); width: 80%; min-width: 300px; max-width: 600px; - display: table } #doc>a, .dist>a, #doc button, #doc input[type=submit] { - // padding: 12px; + /* padding: 12px; */ height: 3rem; border: 1px solid var(--btnbrd); border-radius: .6rem; @@ -245,7 +257,7 @@ button, padding-top: 0 } #doc th { - padding-top: .5em + padding-top: .5rem } #doc input, @@ -262,7 +274,7 @@ button, background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.7' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"); background-repeat: no-repeat; background-position: right .8rem center; - background-size: 1em + background-size: 1rem } #doc label { @@ -271,34 +283,30 @@ button, display: inline-block } +#bmp { + max-width: 100%; + height: auto; +} + .required { background-image: var(--star); background-position: right; background-repeat: no-repeat; - background-size: 1.5em 1.5em; + background-size: 1.5rem 1.5rem; } .icon { - background-size: 1.05em 1.05em; + background-size: 1.25rem 1.25rem; background-position: left; background-repeat: no-repeat; - width: 1.5em; + width: 1.5rem; display: inline-block; text-decoration: none } -.icon:before { - content: "\0000a0" -} -.edit { - background-image: var(--browse); -} -.trash { - background-image: var(--trash); -} -.download { - background-image: var(--download); -} +.icon:before{content: "\0000a0"} +.edit{background-image: var(--browse)} +.trash{background-image: var(--trash)} /* Forms */ .container { @@ -336,7 +344,7 @@ button, } .row { - // font-size: .833rem; + /* font-size: .833rem; */ margin: 5px } @@ -346,15 +354,15 @@ button, } .col-25 { - // float: left; - // width: 25%; + /* float: left; + width: 25%; */ text-align: left; } -.col-75 { - // float: left; - // width: 75% -} +/* .col-75 { + float: left; + width: 75% +} */ #doc label, #doc legend { @@ -363,6 +371,9 @@ button, #doc fieldset { display: contents } +[v-cloak] > * { display:none } +/* [v-cloak]::before { content: "Loading…"; margin: auto; } */ + @media screen and (min-width:800px) { .row { @@ -405,13 +416,13 @@ button, } */ -/* Page Footer */ +/* ********** Page Footer ********** */ .foot { background-color: transparent !important; all: revert; float: right; margin: 0; - font-size: .6em + font-size: .6rem } a.foot:link, a.foot:visited { @@ -421,19 +432,21 @@ a.foot:visited { clear: both } -/* File Editor */ +/* ********** File Editor ********** */ .container__editor { - display: none; + /* display: none; */ + display: flex; /* Misc */ border: 0; width: 100vw; height: 100vh; - background-color: burlywood; + background-color: var(--bg); } .container__left { /* Initially, the left takes 3/4 width */ - width: clamp(10rem, 15vw, 20rem); + width: 10rem; + min-width: 6rem; max-width: 20rem; /* Misc */ @@ -467,18 +480,14 @@ a.foot:visited { align-items: center; display: flex; justify-content: center; - background-color: brown; + background-color: var(--grpbg) } .toolbar { - /* Take the remaining width */ - height: 3rem; - background-color: gray; - - /* Misc */ - align-items: center; - display: flex; - justify-content: center; + text-align: center; width: 100%; + padding: 0.5rem; + color: var(--btnfg); + background-color: var(--toolbg) } .container__bottom { /* Take the remaining width */ @@ -495,4 +504,63 @@ a.foot:visited { } #sizeList { width: 4rem; -} \ No newline at end of file +} +#ctx { + display: none; + top: 10px; + left: 50px; + position: absolute; + background: #fff; + z-index: 10; + padding: 0.75rem; + border-radius: 0.5rem; + box-shadow: 0 0.5rem 0.75rem rgba(0,0,0,0.25); +} +#ctx > ul { + padding-left: 0px; +} +#ctx > ul > li, +.sub_div > ul > li { + cursor: pointer; + white-space: nowrap +} +#ctx > ul > li:hover { + background: #ccc; +} +#fontsize, #page { + width: 3rem +} +#preview { + background-color: #888; + padding: 5px; + overflow: scroll; +} +#preview > img { + max-width:100%; + max-height:100%; + height: 100%; + margin: auto; + display: block +} +#download-frame, +#preview { + display:none; +} +#tree { + width: 100%; + line-height: 1.3rem; + font-size: 0.95rem; + background-color: var(--treebg) +} +.download{background-image: var(--download)} +.eye{background-image: var(--eye)} +.file{background-image: var(--file)} +.zip{background-image: var(--zip)} +.css{background-image: var(--css)} +.cmd{background-image: var(--cmd)} +.json{background-image: var(--json)} +.jsonl{background-image: var(--json)} +.image{background-image: var(--image)} +.html{background-image: var(--html)} +.dir{background-image: var(--dir)} +.diropen{background-image: var(--diropen)} diff --git a/src/hasp_config.h b/src/hasp_config.h index 5b4e0d72..00d24d58 100644 --- a/src/hasp_config.h +++ b/src/hasp_config.h @@ -36,40 +36,47 @@ void configSetConfig(JsonObject& settings); void configGetConfig(JsonDocument& settings); /* json keys used in the configfile */ -const char FP_CONFIG_STARTPAGE[] PROGMEM = "startpage"; -const char FP_CONFIG_STARTDIM[] PROGMEM = "startdim"; -const char FP_CONFIG_THEME[] PROGMEM = "theme"; -const char FP_CONFIG_HUE[] PROGMEM = "hue"; -const char FP_CONFIG_ZIFONT[] PROGMEM = "font"; -const char FP_CONFIG_PAGES[] PROGMEM = "pages"; -const char FP_CONFIG_COLOR1[] PROGMEM = "color1"; -const char FP_CONFIG_COLOR2[] PROGMEM = "color2"; -const char FP_CONFIG_ENABLE[] PROGMEM = "enable"; -const char FP_CONFIG_HOST[] PROGMEM = "host"; -const char FP_CONFIG_PORT[] PROGMEM = "port"; -const char FP_CONFIG_PASV[] PROGMEM = "pasv"; -const char FP_CONFIG_NAME[] PROGMEM = "name"; -const char FP_CONFIG_USER[] PROGMEM = "user"; -const char FP_CONFIG_PASS[] PROGMEM = "pass"; -const char FP_CONFIG_SSID[] PROGMEM = "ssid"; -const char FP_CONFIG_NODE[] PROGMEM = "node"; -const char FP_CONFIG_GROUP[] PROGMEM = "group"; -const char FP_CONFIG_BROADCAST[] PROGMEM = "group"; -const char FP_CONFIG_BAUD[] PROGMEM = "baud"; -const char FP_CONFIG_LOG[] PROGMEM = "log"; -const char FP_CONFIG_PROTOCOL[] PROGMEM = "proto"; -const char FP_GUI_ROTATION[] PROGMEM = "rotate"; -const char FP_GUI_INVERT[] PROGMEM = "invert"; -const char FP_GUI_TICKPERIOD[] PROGMEM = "tick"; -const char FP_GUI_IDLEPERIOD1[] PROGMEM = "idle1"; -const char FP_GUI_IDLEPERIOD2[] PROGMEM = "idle2"; -const char FP_GUI_CALIBRATION[] PROGMEM = "calibration"; -const char FP_GUI_BACKLIGHTPIN[] PROGMEM = "bckl"; -const char FP_GUI_BACKLIGHTINVERT[] PROGMEM = "bcklinv"; -const char FP_GUI_POINTER[] PROGMEM = "cursor"; -const char FP_DEBUG_TELEPERIOD[] PROGMEM = "tele"; -const char FP_DEBUG_ANSI[] PROGMEM = "ansi"; -const char FP_GPIO_CONFIG[] PROGMEM = "config"; +const char FP_CONFIG_STARTPAGE[] PROGMEM = "startpage"; +const char FP_CONFIG_STARTDIM[] PROGMEM = "startdim"; +const char FP_CONFIG_THEME[] PROGMEM = "theme"; +const char FP_CONFIG_HUE[] PROGMEM = "hue"; +const char FP_CONFIG_ZIFONT[] PROGMEM = "font"; +const char FP_CONFIG_PAGES[] PROGMEM = "pages"; +const char FP_CONFIG_COLOR1[] PROGMEM = "color1"; +const char FP_CONFIG_COLOR2[] PROGMEM = "color2"; +const char FP_CONFIG_ENABLE[] PROGMEM = "enable"; +const char FP_CONFIG_HOST[] PROGMEM = "host"; +const char FP_CONFIG_PORT[] PROGMEM = "port"; +const char FP_CONFIG_PASV[] PROGMEM = "pasv"; +const char FP_CONFIG_NAME[] PROGMEM = "name"; +const char FP_CONFIG_USER[] PROGMEM = "user"; +const char FP_CONFIG_PASS[] PROGMEM = "pass"; +const char FP_CONFIG_SSID[] PROGMEM = "ssid"; +const char FP_CONFIG_NODE[] PROGMEM = "node"; +const char FP_CONFIG_NODE_TOPIC[] PROGMEM = "node_t"; +const char FP_CONFIG_HASS[] PROGMEM = "hass"; +const char FP_CONFIG_HASS_TOPIC[] PROGMEM = "hass_t"; +const char FP_CONFIG_GROUP[] PROGMEM = "group"; +const char FP_CONFIG_GROUP_TOPIC[] PROGMEM = "group_t"; +const char FP_CONFIG_BROADCAST[] PROGMEM = "broadcast"; +const char FP_CONFIG_BROADCAST_TOPIC[] PROGMEM = "broadcast_t"; +const char FP_CONFIG_BAUD[] PROGMEM = "baud"; +const char FP_CONFIG_LOG[] PROGMEM = "log"; +const char FP_CONFIG_PROTOCOL[] PROGMEM = "proto"; +const char FP_GUI_ROTATION[] PROGMEM = "rotate"; +const char FP_GUI_INVERT[] PROGMEM = "invert"; +const char FP_GUI_TICKPERIOD[] PROGMEM = "tick"; +const char FP_GUI_IDLEPERIOD1[] PROGMEM = "idle1"; +const char FP_GUI_IDLEPERIOD2[] PROGMEM = "idle2"; +const char FP_GUI_CALIBRATION[] PROGMEM = "calibration"; +const char FP_GUI_BACKLIGHTPIN[] PROGMEM = "bckl"; +const char FP_GUI_BACKLIGHTINVERT[] PROGMEM = "bcklinv"; +const char FP_GUI_POINTER[] PROGMEM = "cursor"; +const char FP_GUI_LONG_TIME[] PROGMEM = "long"; +const char FP_GUI_REPEAT_TIME[] PROGMEM = "repeat"; +const char FP_DEBUG_TELEPERIOD[] PROGMEM = "tele"; +const char FP_DEBUG_ANSI[] PROGMEM = "ansi"; +const char FP_GPIO_CONFIG[] PROGMEM = "config"; const char FP_HASP_CONFIG_FILE[] PROGMEM = "/config.json"; diff --git a/src/sys/svc/hasp_http.cpp b/src/sys/svc/hasp_http.cpp index 6f44023e..37047f23 100644 --- a/src/sys/svc/hasp_http.cpp +++ b/src/sys/svc/hasp_http.cpp @@ -100,33 +100,39 @@ HTTPUpload* upload; const char MAIN_MENU_BUTTON[] PROGMEM = "" D_HTTP_MAIN_MENU ""; const char HTTP_DOCTYPE[] PROGMEM = - "" + "" // "" ""; const char HTTP_META_GO_BACK[] PROGMEM = ""; -const char HTTP_STYLESHEET[] PROGMEM = ""; +const char HTTP_STYLESHEET[] PROGMEM = ""; const char HTTP_HEADER[] PROGMEM = "%s"; -const char HTTP_HEADER_END[] PROGMEM = "" - "
"; -const char HTTP_FOOTER[] PROGMEM = ""; -const uint8_t HTTP_VARS_CSS[] PROGMEM = ":root{" - "--txt:" D_HTTP_COLOR_TEXT ";" - "--bg:" D_HTTP_COLOR_BACKGROUND ";" - "--btnfg:" D_HTTP_COLOR_BUTTON_TEXT ";" - "--btnbg:" D_HTTP_COLOR_BUTTON ";" - "--btnbghi:" D_HTTP_COLOR_BUTTON_HOVER ";" - "--btnred:" D_HTTP_COLOR_BUTTON_RESET ";" - "--btnredhi:" D_HTTP_COLOR_BUTTON_RESET_HOVER ";" - "--btnbrd: transparent;" - "--grpfg:" D_HTTP_COLOR_GROUP_TEXT ";" - "--grpbg:" D_HTTP_COLOR_GROUP ";" - "--fldbg:" D_HTTP_COLOR_INPUT ";" - "--fldfg:" D_HTTP_COLOR_INPUT_TEXT ";" - "--fldred:" D_HTTP_COLOR_INPUT_WARNING ";" - "--footfg:" D_HTTP_COLOR_FOOTER_TEXT ";" - "}"; +const char HTTP_HEADER_END[] PROGMEM = + "" + "" + "" + R"(
)"; +const char HTTP_FOOTER[] PROGMEM = ""; +const uint8_t HTTP_VARS_CSS[] PROGMEM = ":root{" + "--txt:" D_HTTP_COLOR_TEXT ";" + "--bg:" D_HTTP_COLOR_BACKGROUND ";" + "--btnfg:" D_HTTP_COLOR_BUTTON_TEXT ";" + "--btnbg:" D_HTTP_COLOR_BUTTON ";" + "--btnbghi:" D_HTTP_COLOR_BUTTON_HOVER ";" + "--btnred:" D_HTTP_COLOR_BUTTON_RESET ";" + "--btnredhi:" D_HTTP_COLOR_BUTTON_RESET_HOVER ";" + "--btnbrd: transparent;" + "--grpfg:" D_HTTP_COLOR_GROUP_TEXT ";" + "--grpbg:" D_HTTP_COLOR_GROUP ";" + "--fldbg:" D_HTTP_COLOR_INPUT ";" + "--fldfg:" D_HTTP_COLOR_INPUT_TEXT ";" + "--fldred:" D_HTTP_COLOR_INPUT_WARNING ";" + "--footfg:" D_HTTP_COLOR_FOOTER_TEXT ";" + "--toolbg:" D_HTTP_COLOR_TOOLBAR ";" + "--treebg:" D_HTTP_COLOR_TREE ";" + "--preeviewbg:" D_HTTP_COLOR_PREVIEW ";" + "}"; //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -165,18 +171,21 @@ static void add_form_button(String& str, const __FlashStringHelper* label, const static String http_get_content_type(const String& path) { - char buff[sizeof(mime::mimeTable[0].mimeType)]; - // Check all entries but last one for match, return if found - for(size_t i = 0; i < sizeof(mime::mimeTable) / sizeof(mime::mimeTable[0]) - 1; i++) { - strcpy_P(buff, mime::mimeTable[i].endsWith); - if(path.endsWith(buff)) { - strcpy_P(buff, mime::mimeTable[i].mimeType); - return String(buff); + char buffer[sizeof(mime::mimeTable[0].mimeType)]; + int len = sizeof(mime::mimeTable) / sizeof(mime::mimeTable[0]) - 1; + + // Check all entries except the last one for match, return if found + for(size_t i = 0; i < len; i++) { + strcpy_P(buffer, mime::mimeTable[i].endsWith); + if(path.endsWith(buffer)) { + strcpy_P(buffer, mime::mimeTable[i].mimeType); + return String(buffer); } } - // Fall-through and just return default type - strcpy_P(buff, mime::mimeTable[sizeof(mime::mimeTable) / sizeof(mime::mimeTable[0]) - 1].mimeType); - return String(buff); + + // Fall-through and return default (=last) mime-type + strcpy_P(buffer, mime::mimeTable[len].mimeType); + return String(buffer); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -230,7 +239,7 @@ static void webSendFooter() static void http_send_cache_header(int size, int age = 3600) { - webServer.sendHeader(F("Content-Length"), (String)(size)); + webServer.sendHeader("Content-Length", (String)(size)); webServer.sendHeader(F("Cache-Control"), (String)(F("public, max-age=")) + (String)(age)); } @@ -258,52 +267,68 @@ static int http_send_static_gzip_file(const uint8_t* start, const uint8_t* end, return http_send_static_file(start, end, contentType); } -static void webSendHtmlHeader(const char* nodename, uint32_t httpdatalength, uint8_t gohome = 0) +static void webSendHtmlHeader(const char* title, uint32_t httpdatalength, uint8_t gohome = 0) { - { - char buffer[64]; + char buffer[64]; - /* Calculate Content Length upfront */ - uint32_t contentLength = strlen(haspDevice.get_version()); // version length - contentLength += sizeof(HTTP_DOCTYPE) - 1; - contentLength += sizeof(HTTP_HEADER) - 1 - 2 + strlen(nodename); // -2 for %s - contentLength += sizeof(HTTP_STYLESHEET) - 1 - 2 + strlen("vars"); // -2 for %s - if(gohome > 0) { - snprintf_P(buffer, sizeof(buffer), HTTP_META_GO_BACK, gohome); - contentLength += strlen(buffer); // gohome - } else { - buffer[0] = '\0'; - } - contentLength += sizeof(HTTP_HEADER_END) - 1; - contentLength += sizeof(HTTP_FOOTER) - 1; - contentLength += sizeof(HTTP_END) - 1; - - if(httpdatalength > HTTP_PAGE_SIZE) { - LOG_WARNING(TAG_HTTP, F("Sending page with %u static and %u dynamic bytes"), contentLength, httpdatalength); - } - - webServer.setContentLength(contentLength + httpdatalength); -#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - webServer.send_P(200, PSTR("text/html"), HTTP_DOCTYPE); // 122 -#else - webServer.send(200, ("text/html"), HTTP_DOCTYPE); // 122 -#endif - webServer.sendContent(buffer); // gohome - - snprintf_P(buffer, sizeof(buffer), HTTP_STYLESHEET, "vars"); - webServer.sendContent(buffer); // stylesheet - - snprintf_P(buffer, sizeof(buffer), HTTP_HEADER, nodename); - webServer.sendContent(buffer); // 17-2+len + /* Calculate Content Length upfront */ + uint32_t contentLength = strlen(haspDevice.get_version()); // version length + contentLength += sizeof(HTTP_DOCTYPE) - 1; + contentLength += sizeof(HTTP_HEADER) - 1 - 2 + strlen(title); // -2 for %s + contentLength += sizeof(HTTP_STYLESHEET) - 1 - 2 + strlen("static/vars"); // -2 for %s + if(gohome > 0) { + snprintf_P(buffer, sizeof(buffer), HTTP_META_GO_BACK, gohome); + contentLength += strlen(buffer); // gohome + } else { + buffer[0] = '\0'; } + contentLength += sizeof(HTTP_HEADER_END) - 1; + contentLength += sizeof(HTTP_FOOTER) - 1; + contentLength += sizeof(HTTP_END) - 1; + + if(httpdatalength > HTTP_PAGE_SIZE) { + LOG_WARNING(TAG_HTTP, F("Sending page with %u static and %u dynamic bytes"), contentLength, httpdatalength); + } + + webServer.setContentLength(contentLength + httpdatalength); + // webServer.sendHeader("Set-Cookie", "lang=nl; SameSite=None; path=/"); +#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) + webServer.send_P(200, PSTR("text/html"), HTTP_DOCTYPE); // 122 +#else + webServer.send(200, ("text/html"), HTTP_DOCTYPE); // 122 +#endif + webServer.sendContent(buffer); // gohome + + snprintf_P(buffer, sizeof(buffer), HTTP_STYLESHEET, "static/vars"); + webServer.sendContent(buffer); // stylesheet + + snprintf_P(buffer, sizeof(buffer), HTTP_HEADER, title); + webServer.sendContent(buffer); // 17-2+len #if defined(STM32F4xx) webServer.sendContent(HTTP_HEADER_END); // 80 #else - webServer.sendContent_P(HTTP_HEADER_END); // 80 + webServer.sendContent_P(HTTP_HEADER_END); // 80 #endif } +static void http_send_content(const char* form[], int count, uint8_t gohome = 0) +{ + size_t total = 0; + size_t len[count]; + for(int i = 0; i < count; i++) { + if(form[i]) { + len[i] = strlen(form[i]); + total += len[i]; + } + } + webSendHtmlHeader(haspDevice.get_hostname(), total, gohome); + for(int i = 0; i < count; i++) { + if(form[i]) webServer.sendContent(form[i], len[i]); + } + webSendFooter(); +} + // Allows caching of this file, BUT browser must validate Etag before using cached versions static void http_send_etag(String& etag) { @@ -321,13 +346,13 @@ bool http_save_config() { bool updated = false; - if(webServer.method() == HTTP_POST && webServer.hasArg(PSTR("save"))) { - String save = webServer.arg(PSTR("save")); + if(webServer.method() == HTTP_POST && webServer.hasArg("save")) { + String save = webServer.arg("save"); StaticJsonDocument<256> settings; for(int i = 0; i < webServer.args(); i++) settings[webServer.argName(i)] = webServer.arg(i); - if(save == String(PSTR("hasp"))) { + if(save == FP_HASP) { updated = haspSetConfig(settings.as()); #if HASP_USE_MQTT > 0 @@ -339,24 +364,24 @@ bool http_save_config() updated = ftpSetConfig(settings.as()); #endif - } else if(save == String(PSTR("gui"))) { - settings[FPSTR(FP_GUI_POINTER)] = webServer.hasArg(PSTR("cursor")); - settings[FPSTR(FP_GUI_INVERT)] = webServer.hasArg(PSTR("invert")); - settings[FPSTR(FP_GUI_BACKLIGHTINVERT)] = webServer.hasArg(PSTR("bcklinv")); + } else if(save == FP_GUI) { + settings[FPSTR(FP_GUI_POINTER)] = webServer.hasArg("cursor"); + settings[FPSTR(FP_GUI_INVERT)] = webServer.hasArg("invert"); + settings[FPSTR(FP_GUI_BACKLIGHTINVERT)] = webServer.hasArg("bcklinv"); updated = guiSetConfig(settings.as()); - } else if(save == String(PSTR("debug"))) { - settings[FPSTR(FP_DEBUG_ANSI)] = webServer.hasArg(PSTR("ansi")); + } else if(save == FP_DEBUG) { + settings[FPSTR(FP_DEBUG_ANSI)] = webServer.hasArg("ansi"); updated = debugSetConfig(settings.as()); - } else if(save == String(PSTR(FP_HTTP))) { + } else if(save == FP_HTTP) { updated = httpSetConfig(settings.as()); // Password might have changed if(!http_is_authenticated(F("config"))) return updated; #if HASP_USE_WIFI > 0 - } else if(save == String(PSTR("wifi"))) { + } else if(save == FP_WIFI) { updated = wifiSetConfig(settings.as()); #endif } @@ -365,73 +390,56 @@ bool http_save_config() return updated; } -static void webHandleRoot() +static void http_handle_root() { if(!http_is_authenticated(F("root"))) return; bool updated = http_save_config(); - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; - if(updated) { - httpMessage += F("

" D_HTTP_CONFIG_CHANGED "

"); - } - - httpMessage += F("
" D_HTTP_HASP_DESIGN ""); - httpMessage += F("" D_HTTP_SCREENSHOT ""); - httpMessage += F("" D_HTTP_INFORMATION ""); - httpMessage += F("" D_HTTP_CONFIGURATION ""); - httpMessage += F("" D_HTTP_FIRMWARE_UPGRADE ""); - -#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 -#ifdef ARDUINO_ARCH_ESP32 - bool flashfile = true; -#else - bool flashfile = false; -#endif - if(flashfile || HASP_FS.exists(F("/edit.htm.gz")) || HASP_FS.exists(F("/edit.htm"))) { - httpMessage += F("" D_HTTP_FILE_BROWSER ""); - } -#endif - - httpMessage += F("" D_HTTP_REBOOT ""); - - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 0); - webServer.sendContent(httpMessage); + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; + if(updated) { + html[min(i++, len)] = R"(

" D_HTTP_CONFIG_CHANGED "

)"; } - webSendFooter(); + html[min(i++, len)] = R"()"; + html[min(i++, len)] = R"()"; + html[min(i++, len)] = R"()"; + html[min(i++, len)] = R"()"; + html[min(i++, len)] = R"()"; +#ifdef ARDUINO_ARCH_ESP32 + html[min(i++, len)] = R"()"; +#endif + html[min(i++, len)] = R"()"; + http_send_content(html, min(i, len)); } //////////////////////////////////////////////////////////////////////////////////////////////////// -static void httpHandleReboot() +static void http_handle_reboot() { // http://plate01/reboot if(!http_is_authenticated(F("reboot"))) return; - { // Send Content - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); - httpMessage = F(D_DISPATCH_REBOOT); + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 6); - webServer.sendContent(httpMessage); - } - webSendFooter(); + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; + html[min(i++, len)] = R"(

)"; + http_send_content(html, min(i, len), 10); { // Execute Actions - // delay(200); + // delay(200); dispatch_reboot(true); } } //////////////////////////////////////////////////////////////////////////////////////////////////// -static void webHandleScreenshot() +static void http_handle_screenshot() { // http://plate01/screenshot if(!http_is_authenticated(F("screenshot"))) return; @@ -465,44 +473,40 @@ static void webHandleScreenshot() LOG_DEBUG(TAG_HTTP, F("If-None-Match: %s"), etag.c_str()); if(modified > 0 && modified == atol(etag.c_str())) { // Not Changed http_send_etag(etag); // Reuse same ETag - webServer.send_P(304, PSTR("image/bmp"), ""); // Use correct mimetype - return; // 304 ot Modified + webServer.send(304, "image/bmp", ""); // Use correct mimetype + return; // 304 not Modified } } - etag = (String)(modified); - http_send_etag(etag); // Send new tag with modification version - // Send actual bitmap if(webServer.hasArg(F("q"))) { lv_disp_t* disp = lv_disp_get_default(); + etag = (String)(modified); + http_send_etag(etag); // Send new tag with modification version webServer.setContentLength(66 + disp->driver.hor_res * disp->driver.ver_res * sizeof(lv_color_t)); - webServer.send_P(200, PSTR("image/bmp"), ""); + webServer.send(200, "image/bmp", ""); guiTakeScreenshot(); webServer.client().stop(); return; } } - { // Send Content - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; - httpMessage += F("

"); // Automatic refresh - - httpMessage += F("
" D_HTTP_PREV_PAGE ""); - httpMessage += F("" D_HTTP_REFRESH ""); - httpMessage += F("" D_HTTP_NEXT_PAGE "
"); - httpMessage += FPSTR(MAIN_MENU_BUTTON); - - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 0); - webServer.sendContent(httpMessage); - } - webSendFooter(); + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; + html[min(i++, len)] = R"( +

+
+ + + +
)"; + html[min(i++, len)] = R"()"; + http_send_content(html, min(i, len)); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -537,10 +541,11 @@ static void webHandleApi() String endpoint((char*)0); endpoint = webServer.pathArg(0); - if(!strcasecmp_P(endpoint.c_str(), PSTR("files"))) { - webServer.send(200, contentType.c_str(), filesystem_list(HASP_FS, "/", 5).c_str()); + if(!strcasecmp(endpoint.c_str(), "files")) { + String path = webServer.arg(F("dir")); + webServer.send(200, contentType.c_str(), filesystem_list(HASP_FS, path.c_str(), 5).c_str()); - } else if(!strcasecmp_P(endpoint.c_str(), PSTR("info"))) { + } else if(!strcasecmp(endpoint.c_str(), "info")) { String jsondata((char*)0); jsondata.reserve(HTTP_PAGE_SIZE); jsondata = "{"; @@ -566,7 +571,7 @@ static void webHandleApi() webServer.send(200, contentType, jsondata); return; - } else if(!strcasecmp_P(endpoint.c_str(), PSTR("license"))) { + } else if(!strcasecmp(endpoint.c_str(), "credits")) { { JsonObject obj; @@ -612,7 +617,7 @@ static void webHandleApi() webServer.send(200, contentType.c_str(), output); } - } else if(!strcasecmp_P(endpoint.c_str(), PSTR("config"))) { + } else if(!strcasecmp(endpoint.c_str(), "config")) { JsonObject settings; String postBody((char*)0); @@ -720,7 +725,7 @@ static void webHandleApiConfig() StaticJsonDocument<1024> doc; JsonObject settings; - String contentType = http_get_content_type(F(".json")); + // String contentType = http_get_content_type(F(".json")); String endpoint((char*)0); endpoint = webServer.pathArg(0); const char* endpoint_key = endpoint.c_str(); @@ -739,44 +744,44 @@ static void webHandleApiConfig() } settings = doc.as(); } else { - webServer.send(400, contentType, "Bad Request"); + webServer.send(400, "application/json", "Bad Request"); return; } if(webServer.method() == HTTP_POST || webServer.method() == HTTP_PUT) { configOutput(settings, TAG_HTTP); // Log input JSON config - if(!strcasecmp_P(endpoint_key, PSTR("hasp"))) { + if(!strcasecmp(endpoint_key, FP_HASP)) { haspSetConfig(settings); - } else if(!strcasecmp_P(endpoint_key, PSTR("gui"))) { + } else if(!strcasecmp(endpoint_key, FP_GUI)) { guiSetConfig(settings); - } else if(!strcasecmp_P(endpoint_key, PSTR("debug"))) { + } else if(!strcasecmp(endpoint_key, FP_DEBUG)) { debugSetConfig(settings); } else #if HASP_USE_WIFI > 0 - if(!strcasecmp_P(endpoint_key, PSTR("wifi"))) { + if(!strcasecmp(endpoint_key, FP_WIFI)) { wifiSetConfig(settings); - } else if(!strcasecmp_P(endpoint_key, PSTR("time"))) { + } else if(!strcasecmp(endpoint_key, FP_TIME)) { timeSetConfig(settings); } else #endif #if HASP_USE_MQTT > 0 - if(!strcasecmp_P(endpoint_key, PSTR(FP_MQTT))) { + if(!strcasecmp(endpoint_key, FP_MQTT)) { mqttSetConfig(settings); } else #endif #if HASP_USE_FTP > 0 - if(!strcasecmp_P(endpoint_key, PSTR(FP_FTP))) { + if(!strcasecmp(endpoint_key, FP_FTP)) { ftpSetConfig(settings); } else #endif #if HASP_USE_HTTP > 0 - if(!strcasecmp_P(endpoint_key, PSTR(FP_HTTP))) { + if(!strcasecmp(endpoint_key, FP_HTTP)) { httpSetConfig(settings); } else #endif #if HASP_USE_ARDUINOOTA > 0 || HASP_USE_HTTP_UPDATE > 0 - if(!strcasecmp_P(endpoint_key, PSTR("ota"))) { + if(!strcasecmp(endpoint_key, FP_OTA)) { otaSetConfig(settings); } else #endif @@ -787,42 +792,42 @@ static void webHandleApiConfig() } settings = doc.to(); - if(!strcasecmp_P(endpoint_key, PSTR("hasp"))) { + if(!strcasecmp(endpoint_key, FP_HASP)) { haspGetConfig(settings); - } else if(!strcasecmp_P(endpoint_key, PSTR("gui"))) { + } else if(!strcasecmp(endpoint_key, FP_GUI)) { guiGetConfig(settings); - } else if(!strcasecmp_P(endpoint_key, PSTR("debug"))) { + } else if(!strcasecmp(endpoint_key, FP_DEBUG)) { debugGetConfig(settings); } else #if HASP_USE_WIFI > 0 - if(!strcasecmp_P(endpoint_key, PSTR("wifi"))) { + if(!strcasecmp(endpoint_key, FP_WIFI)) { wifiGetConfig(settings); - } else if(!strcasecmp_P(endpoint_key, PSTR("time"))) { + } else if(!strcasecmp(endpoint_key, FP_TIME)) { timeGetConfig(settings); } else #endif #if HASP_USE_MQTT > 0 - if(!strcasecmp_P(endpoint_key, PSTR(FP_MQTT))) { + if(!strcasecmp(endpoint_key, FP_MQTT)) { mqttGetConfig(settings); } else #endif #if HASP_USE_FTP > 0 - if(!strcasecmp_P(endpoint_key, PSTR(FP_FTP))) { + if(!strcasecmp(endpoint_key, FP_FTP)) { ftpGetConfig(settings); } else #endif #if HASP_USE_HTTP > 0 - if(!strcasecmp_P(endpoint_key, PSTR(FP_HTTP))) { + if(!strcasecmp(endpoint_key, FP_HTTP)) { httpGetConfig(settings); } else #endif #if HASP_USE_ARDUINOOTA > 0 || HASP_USE_HTTP_UPDATE > 0 - if(!strcasecmp_P(endpoint_key, PSTR("ota"))) { + if(!strcasecmp(endpoint_key, FP_OTA)) { otaGetConfig(settings); } else #endif { - webServer.send(400, contentType, "Bad Request"); + webServer.send(400, "application/json", "Bad Request"); return; } configOutput(settings, TAG_HTTP); // Log current JSON config @@ -836,7 +841,7 @@ static void webHandleApiConfig() LOG_DEBUG(TAG_HTTP, "%s - %d", __FILE__, __LINE__); // doc.shrinkToFit(); LOG_DEBUG(TAG_HTTP, "%s - %d", __FILE__, __LINE__); - const size_t size = measureJson(doc) + 1; + const size_t size = measureJson(doc); LOG_DEBUG(TAG_HTTP, "%s - %d", __FILE__, __LINE__); char jsondata[size]; LOG_DEBUG(TAG_HTTP, "%s - %d", __FILE__, __LINE__); @@ -844,50 +849,74 @@ static void webHandleApiConfig() LOG_DEBUG(TAG_HTTP, "%s - %d", __FILE__, __LINE__); serializeJson(doc, jsondata, size); LOG_DEBUG(TAG_HTTP, "%s - %d", __FILE__, __LINE__); - webServer.send(200, contentType, jsondata); + // webServer.send(200, contentType.c_str(), jsondata); + webServer.setContentLength(size); + LOG_DEBUG(TAG_HTTP, "%s - %d", __FILE__, __LINE__); + webServer.send(200, "application/json", ""); + LOG_DEBUG(TAG_HTTP, "%s - %d", __FILE__, __LINE__); + webServer.sendContent(jsondata, size); LOG_DEBUG(TAG_HTTP, "%s - %d", __FILE__, __LINE__); } //////////////////////////////////////////////////////////////////////////////////////////////////// -static void webHandleAbout() +static void http_handle_about() { // http://plate01/about if(!http_is_authenticated(F("about"))) return; - { // Send Content - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); + const char* form = R"( + - httpMessage += "
"; - httpMessage += FPSTR(MAIN_MENU_BUTTON); - httpMessage += "
"; - // TOREMOVE httpMessage += ""; - - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 0); - webServer.sendContent(httpMessage); - } - webSendFooter(); +

openHASP

Copyright 2019-2023 Francis Van Roie
MIT License

+

+

+

+ +
+

+
+

+
+

+
+)"; + http_send_content(&form, 1); } //////////////////////////////////////////////////////////////////////////////////////////////////// -static void webHandleInfoJson() +static void http_handle_info() { // http://plate01/ - if(!http_is_authenticated(F("infojson"))) return; + if(!http_is_authenticated(F("info"))) return; - { // Send Content - String htmldata((char*)0); - htmldata.reserve(HTTP_PAGE_SIZE); + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; - htmldata += F("

"); - htmldata += haspDevice.get_hostname(); - htmldata += F("


"); - - htmldata += "
"; - htmldata += FPSTR(MAIN_MENU_BUTTON); - - webSendHtmlHeader(haspDevice.get_hostname(), htmldata.length(), 0); - webServer.sendContent(htmldata); - } - webSendFooter(); + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; + html[min(i++, len)] = R"( + + + + + + + + + + + + + +
openHASP
{{ item }}
Device Memory
{{ item }}
LVGL Memory
{{ item }}
MQTT
{{ item }}
Wifi
{{ item }}
Module
{{ item }}
)"; + html[min(i++, len)] = R"()"; + http_send_content(html, min(i, len)); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -953,10 +982,10 @@ static void webUpdateReboot() { // Send Content String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); + httpMessage.reserve(256); + httpMessage += "

"; httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); + httpMessage += "
"; httpMessage += F("Upload complete. Rebooting device, please wait..."); webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 10); @@ -1129,27 +1158,33 @@ static void handleFileUpload() fsUploadFile = HASP_FS.open(filename, "w"); if(fsUploadFile) { if(!fsUploadFile || fsUploadFile.isDirectory()) { - LOG_WARNING(TAG_HTTP, F(D_FILE_SAVE_FAILED), filename.c_str()); + // Clear upload filesize, fix Response Content-Length + webServer.setContentLength(CONTENT_LENGTH_NOT_SET); webServer.send_P(400, PSTR("text/plain"), PSTR("Invalid filename")); fsUploadFile.close(); fsUploadFile = File(); + LOG_WARNING(TAG_HTTP, F(D_FILE_SAVE_FAILED), filename.c_str()); } else { LOG_TRACE(TAG_HTTP, F("handleFileUpload Name: %s"), filename.c_str()); haspProgressMsg(fsUploadFile.name()); } } else { - LOG_ERROR(TAG_HTTP, F("Could not open file %s for writing"), filename.c_str()); + // Clear upload filesize, fix Response Content-Length + webServer.setContentLength(CONTENT_LENGTH_NOT_SET); webServer.send_P(400, PSTR("text/plain"), PSTR("Could not open file for writing")); + LOG_ERROR(TAG_HTTP, F("Could not open file %s for writing"), filename.c_str()); } break; } case UPLOAD_FILE_WRITE: { if(fsUploadFile) { if(fsUploadFile.write(upload->buf, upload->currentSize) != upload->currentSize) { - LOG_ERROR(TAG_HTTP, F("Failed to write received data to file")); + // Clear upload filesize, fix Response Content-Length + webServer.setContentLength(CONTENT_LENGTH_NOT_SET); webServer.send_P(400, PSTR("text/plain"), PSTR("Failed to write received data to file")); fsUploadFile.close(); fsUploadFile = File(); + LOG_ERROR(TAG_HTTP, F("Failed to write received data to file")); } else { http_upload_progress(); // Moved to httpEverySecond Loop } @@ -1163,7 +1198,10 @@ static void handleFileUpload() // Redirect to /config/hasp page. This flushes the web buffer and frees the memory // webServer.sendHeader(String(F("Location")), String(F("/config/hasp")), true); - webServer.send_P(200, PSTR("text/plain"), "Upload OK"); + + // Clear upload filesize, fix Response Content-Length + webServer.setContentLength(CONTENT_LENGTH_NOT_SET); + webServer.send_P(200, PSTR("text/plain"), PSTR("Upload OK")); } haspProgressVal(255); break; @@ -1195,7 +1233,7 @@ static void handleFileDelete() return webServer.send_P(404, mimetype, PSTR("FileNotFound")); } HASP_FS.remove(path); - webServer.send_P(200, mimetype, PSTR("")); + webServer.send(200, mimetype, String("")); } static void handleFileCreate() @@ -1250,10 +1288,10 @@ static void handleFileList() String path = webServer.arg(F("dir")); // LOG_TRACE(TAG_HTTP, F("handleFileList: %s"), path.c_str()); - path.clear(); + // path.clear(); #if defined(ARDUINO_ARCH_ESP32) - File root = HASP_FS.open("/", FILE_READ); + File root = HASP_FS.open(path.c_str(), FILE_READ); File file = root.openNextFile(); String output((char*)0); output.reserve(HTTP_PAGE_SIZE); @@ -1312,7 +1350,7 @@ static void handleFileList() //////////////////////////////////////////////////////////////////////////////////////////////////// #if HASP_USE_CONFIG > 0 -static void webHandleConfig() +static void http_handle_config() { // http://plate01/config if(!http_is_authenticated(F("config"))) return; @@ -1321,212 +1359,188 @@ static void webHandleConfig() // Reboot after saving wifi config in AP mode #if HASP_USE_WIFI > 0 && !defined(STM32F4xx) if(WiFi.getMode() != WIFI_STA) { - httpHandleReboot(); + http_handle_reboot(); } #endif - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; - if(updated) { - httpMessage += F("

" D_HTTP_CONFIG_CHANGED "

"); - } + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; + if(updated) { + html[min(i++, len)] = R"(

)" D_HTTP_CONFIG_CHANGED "

"; + } #if HASP_USE_WIFI > 0 - httpMessage += F("" D_HTTP_WIFI_SETTINGS ""); + html[min(i++, len)] = R"()"; #endif #if HASP_USE_MQTT > 0 - httpMessage += F("" D_HTTP_MQTT_SETTINGS ""); + html[min(i++, len)] = R"()"; #endif - httpMessage += F("" D_HTTP_HTTP_SETTINGS ""); + html[min(i++, len)] = R"()"; #if HASP_USE_FTP > 0 - httpMessage += F("" D_HTTP_FTP_SETTINGS ""); + html[min(i++, len)] = R"()"; #endif - httpMessage += F("" D_HTTP_GUI_SETTINGS ""); - + html[min(i++, len)] = R"()"; #if HASP_USE_GPIO > 0 - httpMessage += F("" D_HTTP_GPIO_SETTINGS ""); + html[min(i++, len)] = R"()"; #endif - - httpMessage += F("" D_HTTP_DEBUG_SETTINGS ""); - httpMessage += F("" D_HTTP_FACTORY_RESET ""); - httpMessage += FPSTR(MAIN_MENU_BUTTON); - - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 0); - webServer.sendContent(httpMessage); - } - webSendFooter(); + html[min(i++, len)] = R"()"; + html[min(i++, len)] = R"()"; + html[min(i++, len)] = R"()"; + html[min(i++, len)] = R"()"; + http_send_content(html, min(i, len)); } //////////////////////////////////////////////////////////////////////////////////////////////////// #if HASP_USE_MQTT > 0 -static void webHandleMqttConfig() +static void http_handle_mqtt() { // http://plate01/config/mqtt if(!http_is_authenticated(F("config/mqtt"))) return; - { // Send Content - StaticJsonDocument<256> settings; - mqttGetConfig(settings.to()); + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); - httpMessage += F("

" D_HTTP_MQTT_SETTINGS "

"); + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; - // Form - httpMessage += F("
"); + html[min(i++, len)] = R"( +

+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- // Node Name - httpMessage += - F("
"); - httpMessage += F("
"); +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
)"; - // Group Name - httpMessage += F("
"); - httpMessage += F("
"); - - // Broker - httpMessage += F("
"); - httpMessage += F("
"); - - // Mqtt Port - httpMessage += F("
"); - httpMessage += F("
"); - - // Mqtt User - httpMessage += F("
"); - httpMessage += F("
"); - - // Mqtt Password - httpMessage += F("
"); - httpMessage += F("
"); - - // Submit & End Form - httpMessage += F(""); - httpMessage += F("
"); - - add_form_button(httpMessage, F(D_BACK_ICON D_HTTP_CONFIGURATION), F("/config")); - - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 0); - webServer.sendContent(httpMessage); - } - webSendFooter(); + html[min(i++, len)] = R"(
)"; + html[min(i++, len)] = R"()"; + http_send_content(html, min(i, len)); } #endif //////////////////////////////////////////////////////////////////////////////////////////////////// -static void webHandleGuiConfig() +static void http_handle_gui() { // http://plate01/config/wifi if(!http_is_authenticated(F("config/gui"))) return; - { // Send Content - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); - httpMessage += F("

" D_HTTP_GUI_SETTINGS "

"); + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; - // Form - httpMessage += F("
"); + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; + html[min(i++, len)] = R"( +

+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
"); - - // Long Idle - httpMessage += F("
"); - httpMessage += F("
"); - - // Rotation - httpMessage += F("
"); - httpMessage += F("
"); - - // Invert - httpMessage += F("
"); - httpMessage += F("
Invert Colors
"); - - // Cursor - httpMessage += F("
"); - httpMessage += F("
Show Pointer
"); - - // Backlight Pin - httpMessage += F("
"); - httpMessage += F("
"); - - // Backlight Invert - httpMessage += F("
"); - httpMessage += F("
Invert Backlight
"); - - // Submit & End Form - httpMessage += F(""); - httpMessage += F("
"); - -#if TOUCH_DRIVER == 0x2046 && defined(TOUCH_CS) - add_form_button(httpMessage, F(D_HTTP_CALIBRATE), F("/config/gui?cal=1")); -#endif - - add_form_button(httpMessage, F(D_HTTP_ANTIBURN), F("/config/gui?brn=1")); - add_form_button(httpMessage, F(D_BACK_ICON D_HTTP_CONFIGURATION), F("/config")); - - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 0); - webServer.sendContent(httpMessage); } - webSendFooter(); +#endif + html[min(i++, len)] = httpGpio.c_str(); + html[min(i++, len)] = R"( +
+
+
+
+
+
+
)"; + html[min(i++, len)] = R"(
)"; +#if TOUCH_DRIVER == 0x2046 && defined(TOUCH_CS) + html[min(i++, len)] = R"()"; +#endif + html[min(i++, len)] = R"()"; + html[min(i++, len)] = R"()"; + http_send_content(html, min(i, len)); { // Execute Actions if(webServer.hasArg(F("cal"))) dispatch_calibrate(NULL, NULL, TAG_HTTP); @@ -1539,91 +1553,138 @@ static void webHandleHttpConfig() { // http://plate01/config/http if(!http_is_authenticated(F("config/http"))) return; - { // Send Content - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); - httpMessage += F("

" D_HTTP_HTTP_SETTINGS "

"); + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; - // Form - httpMessage += F("
"); - - // Username - httpMessage += F("
"); - httpMessage += F("
"); - - // Password - httpMessage += F("
"); - httpMessage += F("
"); - - // Submit & End Form - httpMessage += F(""); - httpMessage += F("
"); - - httpMessage += F("" D_HTTP_CONFIGURATION ""); - - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 0); - webServer.sendContent(httpMessage); - } - webSendFooter(); + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; + html[min(i++, len)] = R"( +

+
+
+
+
+
+
+
+
+
+
)"; + html[min(i++, len)] = R"(
)"; + html[min(i++, len)] = R"()"; + http_send_content(html, min(i, len)); } //////////////////////////////////////////////////////////////////////////////////////////////////// -static void webHandleFtpConfig() +static void http_handle_ftp() { // http://plate01/config/http if(!http_is_authenticated(F("config/ftp"))) return; - { // Send Content - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); - httpMessage += F("

" D_HTTP_FTP_SETTINGS "

"); + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; - // Form - httpMessage += F("
"); - - // Username - httpMessage += F("
"); - httpMessage += F("
"); - - // Password - httpMessage += F("
"); - httpMessage += F("
"); - - // Ftp Port - httpMessage += F("
"); - httpMessage += F("
"); - - // Passiv Port - httpMessage += F("
"); - httpMessage += F("
"); - - // Submit & End Form - httpMessage += F(""); - httpMessage += F("
"); - - httpMessage += F("" D_HTTP_CONFIGURATION ""); - - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 0); - webServer.sendContent(httpMessage); - } - webSendFooter(); + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; + html[min(i++, len)] = R"( +

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
)"; + html[min(i++, len)] = R"(
)"; + html[min(i++, len)] = R"()"; + http_send_content(html, min(i, len)); } +//////////////////////////////////////////////////////////////////////////////////////////////////// +static void http_handle_time() +{ // http://plate01/config/time + if(!http_is_authenticated(F("config/time"))) return; + + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; + + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; + html[min(i++, len)] = R"( + + +

+
+
+
+
)"; + html[min(i++, len)] = R"()"; + http_send_content(html, min(i, len)); +} //////////////////////////////////////////////////////////////////////////////////////////////////// #if HASP_USE_GPIO > 0 @@ -1636,7 +1697,7 @@ static void webHandleGpioConfig() uint8_t id = webServer.arg(F("id")).toInt(); uint8_t pin = webServer.arg(F("pin")).toInt(); - if(webServer.hasArg(PSTR("save"))) { + if(webServer.hasArg("save")) { uint8_t type = webServer.arg(F("type")).toInt(); uint8_t group = webServer.arg(F("group")).toInt(); uint8_t pinfunc = webServer.arg(F("func")).toInt(); @@ -1644,7 +1705,7 @@ static void webHandleGpioConfig() gpioSavePinConfig(id, pin, type, group, pinfunc, inverted); } - if(webServer.hasArg(PSTR("del"))) { + if(webServer.hasArg("del")) { gpioSavePinConfig(id, pin, hasp_gpio_type_t::FREE, 0, 0, false); } } @@ -1652,9 +1713,9 @@ static void webHandleGpioConfig() { // Send Content String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); + httpMessage += "

"; httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); + httpMessage += "
"; httpMessage += F("

" D_HTTP_GPIO_SETTINGS "

"); httpMessage += F("
"); @@ -1786,7 +1847,7 @@ static void webHandleGpioConfig() httpMessage += id; httpMessage += ("&pin="); httpMessage += conf.pin; - httpMessage += ("' class='trash'>"); + httpMessage += ("' class='icon trash'>"); configCount++; } } @@ -1822,9 +1883,9 @@ static void webHandleGpioOutput() String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); + httpMessage += "

"; httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); + httpMessage += "
"; httpMessage += F(""); httpMessage += F(""); httpMessage += F(""); - - // Baudrate - httpMessage += F("
"); - httpMessage += F("
"); - - // Telemetry Period - httpMessage += F("
"); - httpMessage += F("
"); - - // Invert - httpMessage += F("
"); - httpMessage += F("
Use ANSI Colors
"); + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; + html[min(i++, len)] = R"( +

+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+)"; #if HASP_USE_SYSLOG > 0 - // Syslog host - httpMessage += F("
"); - httpMessage += F("
"); - - // Syslog Port - httpMessage += F("
"); - httpMessage += F("
"); - - // Syslog Facility - httpMessage += F("
"); - httpMessage += F("
"); - - // Syslog Protocol - httpMessage += F("
"); - httpMessage += F("
IETF (RFC 5424)   BSD (RFC 3164)"); - httpMessage += F("
"); + html[min(i++, len)] = R"( +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + +
+
)"; #endif - // Submit & End Form - httpMessage += F(""); - httpMessage += F("
"); - - // ******************************************************************* - - add_form_button(httpMessage, F(D_BACK_ICON D_HTTP_CONFIGURATION), F("/config")); - - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 0); - webServer.sendContent(httpMessage); - } - webSendFooter(); + html[min(i++, len)] = R"()"; + html[min(i++, len)] = R"()"; + http_send_content(html, min(i, len)); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2073,72 +2127,34 @@ static void webHandleHaspConfig() { // http://plate01/config/http if(!http_is_authenticated(F("config/hasp"))) return; - { // Send Content - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); - httpMessage += F("

" D_HTTP_HASP_DESIGN "

"); + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; -#if defined(ARDUINO_ARCH_ESP8266) - // Form - httpMessage += F("
"); + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; - // File - httpMessage += - F("
"); - httpMessage += F("
"); - - // Destination - httpMessage += F("
"); - httpMessage += - F("
Firmware   " - "Filesystem
"); - - // Submit & End Form - httpMessage += F(""); - httpMessage += F("
"); -#endif - - // Form - httpMessage += F("
"); - - // Theme - httpMessage += F("
"); - httpMessage += F("
"); + #endif - // Primary Color - httpMessage += F("
"); - httpMessage += F("
"); - - // Secondary Color - httpMessage += F("
"); - httpMessage += F("
"); - - // Font - httpMessage += F("
"); - httpMessage += F("
"); - - // Pages.jsonl - httpMessage += F("
"); - httpMessage += F("
"); - - // Startup Page - httpMessage += F("
"); - httpMessage += F("
"); - - // Startup Brightness - httpMessage += F("
"); - httpMessage += F("
"); - - // Submit & End Form - httpMessage += F(""); - httpMessage += F("
"); - - httpMessage += FPSTR(MAIN_MENU_BUTTON); - - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 0); - webServer.sendContent(httpMessage); - } - webSendFooter(); + html[min(i++, len)] = R"( +

+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
)"; + html[min(i++, len)] = R"(
)"; + html[min(i++, len)] = R"()"; + // html[min(i++, len)] = "
{{ config }}
/
"; + http_send_content(html, min(i, len)); } #endif // HASP_USE_CONFIG @@ -2189,53 +2220,50 @@ static void webHandleHaspConfig() //////////////////////////////////////////////////////////////////////////////////////////////////// #if HASP_USE_WIFI > 0 -static void webHandleWifiConfig() +static void http_handle_wifi() { // http://plate01/config/wifi if(!http_is_authenticated(F("config/wifi"))) return; - { // Send Content - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); - httpMessage += F("

" D_HTTP_WIFI_SETTINGS "

"); + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; - // Form - httpMessage += F("
"); - - // Wifi SSID - httpMessage += F("
"); - httpMessage += F("
"); - - // Wifi Password - httpMessage += F("
"); - httpMessage += F("
"); - - // Submit & End Form - httpMessage += F(""); - httpMessage += F("
"); + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; + html[min(i++, len)] = R"( +

+
+
+
+
+
+
+
+
+
+
+)"; + html[min(i++, len)] = R"(
)"; #if HASP_USE_WIFI > 0 && !defined(STM32F4xx) - if(WiFi.getMode() == WIFI_STA) { - add_form_button(httpMessage, F(D_BACK_ICON D_HTTP_CONFIGURATION), F("/config")); + if(WiFi.getMode() == WIFI_STA) { + html[min(i++, len)] = R"()"; #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - } else { - add_form_button(httpMessage, F(D_HTTP_FIRMWARE_UPGRADE), F("/firmware")); + } else { + html[min(i++, len)] = R"()"; #endif // ARDUINO_ARCH_ESP - } + } #endif // HASP_USE_WIFI - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 0); - webServer.sendContent(httpMessage); - } - webSendFooter(); + http_send_content(html, min(i, len)); } #endif // HASP_USE_WIFI @@ -2259,8 +2287,8 @@ static inline int handleFirmwareFile(String path) return http_send_static_gzip_file(STYLE_CSS_GZ_START, STYLE_CSS_GZ_END, contentType); } else if(path == F("/vars.css")) { return http_send_static_file(HTTP_VARS_CSS, HTTP_VARS_CSS + sizeof(HTTP_VARS_CSS) - 1, contentType); - } else if(path == F("/script.js")) { // 3 kB - return http_send_static_gzip_file(SCRIPT_JS_GZ_START, SCRIPT_JS_GZ_END, contentType); + // } else if(path == F("/script.js")) { // 3 kB + // return http_send_static_gzip_file(SCRIPT_JS_GZ_START, SCRIPT_JS_GZ_END, contentType); } else if(path == F("/en.json")) { // 2 kB return http_send_static_gzip_file(EN_JSON_GZ_START, EN_JSON_GZ_END, contentType); } else if(path == F("/main.js")) { // 9 kB @@ -2342,88 +2370,62 @@ static void webHandleFirmware() { if(!http_is_authenticated(F("firmware"))) return; - if(webServer.method() == HTTP_POST && webServer.hasArg(PSTR("url"))) { + const char* html[20]; + int i = 0; + int len = (sizeof(html) / sizeof(html[0])) - 1; + + html[min(i++, len)] = "

"; + html[min(i++, len)] = haspDevice.get_hostname(); + html[min(i++, len)] = "


"; + + if(webServer.method() == HTTP_POST && webServer.hasArg("url")) { StaticJsonDocument<512> settings; for(int i = 0; i < webServer.args(); i++) settings[webServer.argName(i)] = webServer.arg(i); bool updated = otaSetConfig(settings.as()); + String url = webServer.arg("url"); - String url = webServer.arg(PSTR("url")); - { - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); + html[min(i++, len)] = R"(

Updating firmware from: )"; + html[min(i++, len)] = url.c_str(); + html[min(i++, len)] = R"(

Please wait...

)"; + html[min(i++, len)] = R"()"; + http_send_content(html, min(i, len)); - httpMessage += F("

" D_HTTP_FIRMWARE_UPGRADE "

"); - httpMessage += F("

Updating firmware from: "); - httpMessage += url; - httpMessage += F("

Please wait...

"); - - httpMessage += FPSTR(MAIN_MENU_BUTTON); - - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 60); - webServer.sendContent(httpMessage); - } - - webSendFooter(); dispatch_web_update(NULL, url.c_str(), TAG_HTTP); - return; + } else { - // Send Firmware page - String httpMessage((char*)0); - httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); - httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); - httpMessage += F("

" D_HTTP_FIRMWARE_UPGRADE "

"); - // Form - httpMessage += - F("
"); - - // File - httpMessage += - F("
"); - httpMessage += F("
"); - - // Destination - httpMessage += F("
"); - httpMessage += - F("
Firmware   " - "Filesystem
"); - - // Submit & End Form - httpMessage += F(""); - httpMessage += F("
"); - - // Update from URL - // Form - httpMessage += F("
"); - - // URL - httpMessage += - F("
"); - httpMessage += F("
"); - - // Redirect - httpMessage += F("
"); - httpMessage += F("
"); - - // Submit & End Form - httpMessage += F(""); - httpMessage += F("
"); - - httpMessage += FPSTR(MAIN_MENU_BUTTON); - - webSendHtmlHeader(haspDevice.get_hostname(), httpMessage.length(), 0); - webServer.sendContent(httpMessage); + html[min(i++, len)] = R"( +

+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+)"; + html[min(i++, len)] = R"()"; + http_send_content(html, min(i, len)); } - webSendFooter(); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2438,9 +2440,9 @@ static void httpHandleResetConfig() { // Send Content String httpMessage((char*)0); httpMessage.reserve(HTTP_PAGE_SIZE); - httpMessage += F("

"); + httpMessage += "

"; httpMessage += haspDevice.get_hostname(); - httpMessage += F("


"); + httpMessage += "
"; httpMessage += F("

" D_HTTP_FACTORY_RESET "

"); if(resetConfirmed) { // User has confirmed, so reset everything @@ -2483,7 +2485,7 @@ static void httpHandleResetConfig() void httpStart() { - webServer.begin(); + webServer.begin(80); webServerStarted = true; #if HASP_USE_WIFI > 0 #if defined(STM32F4xx) @@ -2565,12 +2567,12 @@ static inline void webStartConfigPortal() dnsServer.start(DNS_PORT, "*", apIP); #endif // HASP_USE_CAPTIVE_PORTAL - webServer.on(F("/vars.css"), httpHandleFileUri); - webServer.on(F("/style.css"), httpHandleFileUri); - webServer.on(F("/script.js"), httpHandleFileUri); - // reply to all requests with same HTML + webServer.on("/vars.css", httpHandleFileUri); + webServer.on(UriBraces("/static/{}/"), httpHandleFileUri); + // webServer.on("/script.js", httpHandleFileUri); +// reply to all requests with same HTML #if HASP_USE_WIFI > 0 - webServer.onNotFound(webHandleWifiConfig); + webServer.onNotFound(http_handle_wifi); #endif LOG_TRACE(TAG_HTTP, F("Wifi access point")); } @@ -2584,21 +2586,23 @@ void httpSetup() LOG_DEBUG(TAG_HTTP, F(D_BULLET "Read %s => %s (%d bytes)"), FP_CONFIG_PASS, password.c_str(), password.length()); // ask server to track these headers - const char* headerkeys[] = {"Content-Length", "If-None-Match"}; // "Authentication" is automatically checked + const char* headerkeys[] = {"Content-Length", "If-None-Match", + "Cookie"}; // "Authentication" is automatically checked size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*); webServer.collectHeaders(headerkeys, headerkeyssize); // Shared pages between STA and AP - webServer.on(F("/about"), webHandleAbout); - // webServer.on(F("/vars.css"), webSendCssVars); - // webServer.on(F("/js"), webSendJavascript); - webServer.on(UriBraces(F("/api/{}/")), webHandleApi); - webServer.on(UriBraces(F("/api/config/{}/")), webHandleApiConfig); - webServer.on(UriBraces(F("/{}/")), HTTP_GET, []() { httpHandleFile(F("/hasp.htm")); }); - webServer.on(UriBraces(F("/config/{}/")), HTTP_GET, []() { httpHandleFile(F("/hasp.htm")); }); + webServer.on("/about", http_handle_about); + // webServer.on("/vars.css", webSendCssVars); + // webServer.on("/js", webSendJavascript); + webServer.on(UriBraces("/api/config/{}/"), webHandleApiConfig); + webServer.on(UriBraces("/api/{}/"), webHandleApi); + + webServer.on(UriBraces("/config/{}/"), HTTP_GET, []() { httpHandleFile(F("/hasp.htm")); }); // SPA Route + webServer.on(UriBraces("/{}/"), HTTP_GET, []() { httpHandleFile(F("/hasp.htm")); }); // SPA Route #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) - webServer.on(F("/firmware"), webHandleFirmware); + webServer.on("/firmware", webHandleFirmware); webServer.on( F("/update"), HTTP_POST, []() { @@ -2609,7 +2613,7 @@ void httpSetup() #endif #ifdef HTTP_LEGACY - webServer.on(F("/config"), webHandleConfig); + webServer.on("/config", http_handle_config); #endif #if HASP_USE_WIFI > 0 @@ -2626,7 +2630,7 @@ void httpSetup() #endif // HASP_USE_WIFI // The following endpoints are only needed in STA mode - webServer.on(F("/page/"), []() { + webServer.on("/page/", []() { String pageid = webServer.arg(F("page")); webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'"); dispatch_page(NULL, webServer.arg(F("page")).c_str(), TAG_HTTP); @@ -2634,51 +2638,53 @@ void httpSetup() }); #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0 - webServer.on(F("/list"), HTTP_GET, handleFileList); + webServer.on("/list", HTTP_GET, handleFileList); // load editor - webServer.on(F("/edit"), HTTP_GET, []() { httpHandleFile(F("/edit.htm")); }); - webServer.on(F("/edit"), HTTP_PUT, handleFileCreate); - webServer.on(F("/edit"), HTTP_DELETE, handleFileDelete); + webServer.on("/edit", HTTP_GET, []() { httpHandleFile(F("/edit.htm")); }); + webServer.on("/edit", HTTP_PUT, handleFileCreate); + webServer.on("/edit", HTTP_DELETE, handleFileDelete); // first callback is called after the request has ended with all parsed arguments // second callback handles file uploads at that location webServer.on( F("/edit"), HTTP_POST, []() { - webServer.send(200, "text/plain", ""); + webServer.setContentLength(CONTENT_LENGTH_NOT_SET); + webServer.send(200, "text/plain", "OK"); LOG_VERBOSE(TAG_HTTP, F("Headers: %d"), webServer.headers()); }, handleFileUpload); #endif - webServer.on(F("/"), webHandleRoot); - webServer.on(F("/screenshot"), webHandleScreenshot); + webServer.on("/", http_handle_root); + webServer.on("/screenshot", http_handle_screenshot); #ifdef HTTP_LEGACY - webServer.on(F("/info"), webHandleInfoJson); - webServer.on(F("/reboot"), httpHandleReboot); + webServer.on("/info", http_handle_info); + webServer.on("/reboot", http_handle_reboot); #endif #if HASP_USE_CONFIG > 0 #ifdef HTTP_LEGACY - webServer.on(F("/config/hasp"), webHandleHaspConfig); - webServer.on(F("/config/http"), webHandleHttpConfig); - webServer.on(F("/config/gui"), webHandleGuiConfig); - webServer.on(F("/config/debug"), webHandleDebugConfig); + webServer.on("/config/hasp", webHandleHaspConfig); + webServer.on("/config/http", webHandleHttpConfig); + webServer.on("/config/gui", http_handle_gui); + webServer.on("/config/time", http_handle_time); + webServer.on("/config/debug", http_handle_debug); #if HASP_USE_MQTT > 0 - webServer.on(F("/config/mqtt"), webHandleMqttConfig); + webServer.on("/config/mqtt", http_handle_mqtt); #endif #if HASP_USE_FTP > 0 - webServer.on(F("/config/ftp"), webHandleFtpConfig); + webServer.on("/config/ftp", http_handle_ftp); #endif #if HASP_USE_WIFI > 0 - webServer.on(F("/config/wifi"), webHandleWifiConfig); + webServer.on("/config/wifi", http_handle_wifi); #endif #if HASP_USE_GPIO > 0 - webServer.on(F("/config/gpio"), webHandleGpioConfig); - webServer.on(F("/config/gpio/options"), webHandleGpioOutput); - webServer.on(F("/config/gpio/input"), webHandleGpioInput); + webServer.on("/config/gpio", webHandleGpioConfig); + webServer.on("/config/gpio/options", webHandleGpioOutput); + webServer.on("/config/gpio/input", webHandleGpioInput); #endif #endif // HTTP_LEGACY - webServer.on(F("/config/reset"), httpHandleResetConfig); + webServer.on("/config/reset", httpHandleResetConfig); #endif // HASP_USE_CONFIG webServer.onNotFound(httpHandleFileUri); @@ -2757,7 +2763,7 @@ size_t httpClientWrite(const uint8_t* buf, size_t size) /***** Sending 16Kb at once freezes on STM32 EthernetClient *****/ size_t bytes_sent = 0; while(bytes_sent < size) { - if(!webServer.client()) return bytes_sent; + if(!webServer.client() || !webServer.client().connected()) return bytes_sent; if(size - bytes_sent >= 20480) { bytes_sent += webServer.client().write(buf + bytes_sent, 20480); // 2048 delay(1); // Fixes the freeze diff --git a/src/sys/svc/hasp_http.h b/src/sys/svc/hasp_http.h index a09fcf4b..bdbe13c4 100644 --- a/src/sys/svc/hasp_http.h +++ b/src/sys/svc/hasp_http.h @@ -77,6 +77,16 @@ bool httpSetConfig(const JsonObject& settings); #ifndef D_HTTP_COLOR_FOOTER_TEXT #define D_HTTP_COLOR_FOOTER_TEXT "#0083cc" // Text color of the page footer #endif +#ifndef D_HTTP_COLOR_TOOLBAR +#define D_HTTP_COLOR_TOOLBAR D_HTTP_COLOR_BUTTON +#endif +#ifndef D_HTTP_COLOR_TREE +#define D_HTTP_COLOR_TREE D_HTTP_COLOR_GROUP +#endif +#ifndef D_HTTP_COLOR_PREVIEW +#define D_HTTP_COLOR_PREVIEW "#888" +#endif + /* clang-format on */ #endif \ No newline at end of file diff --git a/tools/auto_firmware_version.py b/tools/auto_firmware_version.py index 6d6fc3a6..9a80b0d0 100644 --- a/tools/auto_firmware_version.py +++ b/tools/auto_firmware_version.py @@ -1,4 +1,4 @@ -import pkg_resources +import gzip, pkg_resources Import("env") @@ -33,4 +33,18 @@ def get_flash_size(): env.Append( BUILD_FLAGS=[get_firmware_commit_hash(),get_flash_size()] -) \ No newline at end of file +) + +r = Repo('.') +commit_hash = r.head().decode("utf-8")[0:7] +with open("data/editor.htm", "r", encoding="utf-8") as f: + html=f.read() +html = html.replace("COMMIT_HASH", commit_hash) +with gzip.open('data/static/edit.htm.gz', 'wb') as f: + f.write(html.encode('utf-8')) + +with open("data/main.js", "r", encoding="utf-8") as f: + html=f.read() +html = html.replace("COMMIT_HASH", commit_hash) +with gzip.open('data/static/main.js.gz', 'wb') as f: + f.write(html.encode('utf-8'))