This commit is contained in:
parent
5fa1ec14e2
commit
51ed3b3b1c
4 changed files with 136 additions and 5 deletions
17
README.md
17
README.md
|
@ -69,3 +69,20 @@ In the project root run:
|
|||
nix-shell --option sandbox false
|
||||
make firmware -j$(nproc)
|
||||
```
|
||||
|
||||
|
||||
|
||||
>>> import htmlmin
|
||||
>>> input_html = '''
|
||||
<body style="background-color: tomato;">
|
||||
<h1> htmlmin rocks</h1>
|
||||
<pre>
|
||||
and rolls
|
||||
</pre>
|
||||
</body>'''
|
||||
>>> htmlmin.minify(input_html)
|
||||
u' <body style="background-color: tomato;"> <h1> htmlmin rocks</h1> <pre>\n and rolls\n </pre> </body>'
|
||||
>>> print htmlmin.minify(input_html)
|
||||
<body style="background-color: tomato;"> <h1> htmlmin rocks</h1> <pre>
|
||||
and rolls
|
||||
</pre> </body>
|
||||
|
|
|
@ -41,10 +41,6 @@ while($file = <FILES>) {
|
|||
print(HEADER "Content-type: image/jpeg\r\n");
|
||||
} elsif($file =~ /\.bmp$/) {
|
||||
print(HEADER "Content-type: image/bmp\r\n\r\n");
|
||||
} elsif($file =~ /\.class$/) {
|
||||
print(HEADER "Content-type: application/octet-stream\r\n");
|
||||
} elsif($file =~ /\.ram$/) {
|
||||
print(HEADER "Content-type: audio/x-pn-realaudio\r\n");
|
||||
} else {
|
||||
print(HEADER "Content-type: text/plain\r\n");
|
||||
}
|
||||
|
|
118
firmware/mkwebfs.py
Normal file
118
firmware/mkwebfs.py
Normal file
|
@ -0,0 +1,118 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
incHttpHeader = True
|
||||
|
||||
open(OUTPUT, "> fsdata.c");
|
||||
print(OUTPUT
|
||||
"#include \"httpd/fsdata.h\"\n\n");
|
||||
|
||||
chdir("fs");
|
||||
open(FILES, "find . -type f |");
|
||||
|
||||
while ($file = < FILES >) {
|
||||
|
||||
chop($file);
|
||||
|
||||
if incHttpHeader == 1:
|
||||
open(HEADER, "> /tmp/header") | | die $!;
|
||||
if ($file =~ / 404 /) {
|
||||
print(HEADER "HTTP/1.0 404 File not found\r\n");
|
||||
} else {
|
||||
print(HEADER "HTTP/1.0 200 OK\r\n");
|
||||
}
|
||||
print(HEADER "lwIP/1.4.1 (http://savannah.nongnu.org/projects/lwip)\r\n");
|
||||
if ($file =~ / \.html$ / | | $file =~ / \.htm$ / | | $file =~ / \.shtml$ / | | $file =~ / \.shtm$ / | | $file =~ / \.ssi$ / ) {
|
||||
print(HEADER "Content-type: text/html\r\n");
|
||||
} elsif($file =~ / \.js$ / ) {
|
||||
print(HEADER "Content-type: application/x-javascript\r\n\r\n");
|
||||
} elsif($file =~ / \.css$ / ) {
|
||||
print(HEADER "Content-type: text/css\r\n\r\n");
|
||||
} elsif($file =~ / \.ico$ / ) {
|
||||
print(HEADER "Content-type: image/x-icon\r\n\r\n");
|
||||
} elsif($file =~ / \.gif$ / ) {
|
||||
print(HEADER "Content-type: image/gif\r\n");
|
||||
} elsif($file =~ / \.png$ / ) {
|
||||
print(HEADER "Content-type: image/png\r\n");
|
||||
} elsif($file =~ / \.jpg$ / ) {
|
||||
print(HEADER "Content-type: image/jpeg\r\n");
|
||||
} elsif($file =~ / \.bmp$ / ) {
|
||||
print(HEADER "Content-type: image/bmp\r\n\r\n");
|
||||
} else {
|
||||
print(HEADER "Content-type: text/plain\r\n");
|
||||
}
|
||||
print(HEADER "\r\n");
|
||||
close(HEADER);
|
||||
|
||||
unless($file =~ / \.plain$ / | | $file =~ / cgi / ) {
|
||||
system("cat /tmp/header $file > /tmp/file");
|
||||
} else {
|
||||
system("cp $file /tmp/file");
|
||||
}
|
||||
} else {
|
||||
system("cp $file /tmp/file");
|
||||
}
|
||||
|
||||
open(FILE, "/tmp/file");
|
||||
unlink("/tmp/file");
|
||||
unlink("/tmp/header");
|
||||
|
||||
$file = ~ s /\.//;
|
||||
$fvar = $file;
|
||||
$fvar = ~ s - / -_ - g;
|
||||
$fvar = ~ s -\.-_ - g;
|
||||
|
||||
print(OUTPUT
|
||||
"static const unsigned char data".$fvar.
|
||||
"[] = {\n");
|
||||
print(OUTPUT
|
||||
"\t/* $file */\n\t");
|
||||
for ($j = 0; $j < length($file); $j++) {
|
||||
printf(OUTPUT "0x%02X, ", unpack("C", substr($file, $j, 1)));
|
||||
}
|
||||
printf(OUTPUT
|
||||
"0,\n");
|
||||
|
||||
|
||||
$i = 0;
|
||||
while (read(FILE, $data, 1)) {
|
||||
if ($i == 0) {
|
||||
print(OUTPUT "\t");
|
||||
}
|
||||
printf(OUTPUT "0x%02X, ", unpack("C", $data));
|
||||
$i++;
|
||||
if ($i == 10) {
|
||||
print(OUTPUT "\n");
|
||||
$i = 0;
|
||||
}
|
||||
}
|
||||
print(OUTPUT
|
||||
"};\n\n");
|
||||
close(FILE);
|
||||
push( @ fvars, $fvar);
|
||||
push( @ files, $file);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < @ fvars; $i++) {
|
||||
$file = $files[$i];
|
||||
$fvar = $fvars[$i];
|
||||
|
||||
if ($i == 0) {
|
||||
$prevfile = "NULL";
|
||||
} else {
|
||||
$prevfile = "file".$fvars[$i - 1];
|
||||
}
|
||||
print(OUTPUT
|
||||
"const struct fsdata_file file".$fvar.
|
||||
"[] = {{\n$prevfile,\ndata$fvar, ");
|
||||
print(OUTPUT
|
||||
"data$fvar + ".(length($file) + 1).",\n");
|
||||
print(OUTPUT
|
||||
"sizeof(data$fvar) - ".(length($file) + 1).",\n");
|
||||
print(OUTPUT $incHttpHeader.
|
||||
"\n}};\n\n");
|
||||
}
|
||||
|
||||
print(OUTPUT
|
||||
"#define FS_ROOT file$fvars[$i - 1]\n\n");
|
||||
print(OUTPUT
|
||||
"#define FS_NUMFILES $i\n");
|
|
@ -239,7 +239,7 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
|||
cmd = 'G';
|
||||
break;
|
||||
case 'F':
|
||||
togl = ~togl;
|
||||
togl = !togl;
|
||||
signal_led(togl);
|
||||
{
|
||||
auto *f = (fw_frame *) data;
|
||||
|
|
Loading…
Reference in a new issue