This commit is contained in:
Nur Mahmud Ul Alam Tasin 2023-01-03 13:02:47 +00:00 committed by GitHub
commit 769475fe85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 970 additions and 10 deletions

6
.gitignore vendored
View File

@ -10,3 +10,9 @@
*.pyc
utils/web_converter/css_html_js_minify/__pycache__/
utils/simple_web_converter/__pycache__
web_interface/gz/*
.vscode

View File

@ -8,6 +8,8 @@
#define DEFAULT_ESP8266
#define ENABLE_WEB_CONSOLE
// #define NODEMCU
// #define WEMOS_D1_MINI
// #define HACKHELD_VEGA
@ -727,4 +729,4 @@
// ========== ERROR CHECKS ========== //
#if LED_MODE_BRIGHTNESS == 0
#error LED_MODE_BRIGHTNESS must not be zero!
#endif /* if LED_MODE_BRIGHTNESS == 0 */
#endif /* if LED_MODE_BRIGHTNESS == 0 */

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -22,7 +22,8 @@ extern "C" {
#include "oui.h"
#include "language.h"
#include "functions.h"
//#include "functions.h"
#include <LittleFS.h>
#include "settings.h"
#include "Names.h"
#include "SSIDs.h"

View File

@ -1,6 +1,8 @@
/* This software is licensed under the MIT License: https://github.com/spacehuhntech/esp8266_deauther */
#pragma once
#ifndef __FUNCTIONS_H__
#define __FUNCTIONS_H__
#include "Arduino.h"
#include <LittleFS.h>
@ -8,7 +10,7 @@ extern "C" {
#include "user_interface.h"
}
#include "src/ArduinoJson-v5.13.5/ArduinoJson.h"
#include "A_config.h"
/*
Here is a collection of useful functions and variables.
They are used globally via an 'extern' reference in every class.
@ -247,22 +249,52 @@ String b2a(bool input) {
bool s2b(String input) {
return eqls(input, STR_TRUE);
}
// ===== WEBCONSOLE FUNCTIONS ===== //
#ifdef ENABLE_WEB_CONSOLE
String WebConsoleOutputCache="";
void WebConsoleMemoryHandler(){
//The main job of this funtion to clear the memory occupied by webconsole output cache
//If the cache uses memory more than 4kB, this function will clear the cache.
//This way we can limit the memory usage by webconsole
if(WebConsoleOutputCache.length()>4096){
//Clear the WebConsoleOutputCache
WebConsoleOutputCache="";
}
}
#endif
// ===== PRINT FUNCTIONS ===== //
void prnt(const String s) {
Serial.print(s);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=s;
#endif
}
void prnt(const bool b) {
Serial.print(b2s(b));
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=b2s(b);
#endif
}
void prnt(const char c) {
Serial.print(c);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=(String)c;
#endif
}
void prnt(const char* ptr) {
Serial.print(FPSTR(ptr));
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=FPSTR(ptr);
#endif
}
void prnt(const char* ptr, int len) {
@ -271,30 +303,64 @@ void prnt(const char* ptr, int len) {
void prnt(const int i) {
Serial.print((String)i);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=(String)i;
#endif
}
void prnt(const uint32_t i) {
Serial.printf("%u", i);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
char* s="";
sprintf(s,"%u",i);
WebConsoleOutputCache+=s;
#endif
}
void prntln() {
Serial.println();
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+='\n';
#endif
}
void prntln(const String s) {
Serial.println(s);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=s;
WebConsoleOutputCache+='\n';
#endif
}
void prntln(const bool b) {
Serial.println(b2s(b));
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=b2s(b);
WebConsoleOutputCache+='\n';
#endif
}
void prntln(const char c) {
Serial.println(c);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=(String)c;
WebConsoleOutputCache+='\n';
#endif
}
void prntln(const char* ptr) {
Serial.println(FPSTR(ptr));
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=FPSTR(ptr);
WebConsoleOutputCache+='\n';
#endif
}
void prntln(const char* ptr, int len) {
@ -304,10 +370,21 @@ void prntln(const char* ptr, int len) {
void prntln(const int i) {
Serial.println((String)i);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
WebConsoleOutputCache+=(String)i;
#endif
}
void prntln(const uint32_t i) {
Serial.printf("%u\r\n", i);
#ifdef ENABLE_WEB_CONSOLE
WebConsoleMemoryHandler();
char* s="";
sprintf(s,"%u",i);
WebConsoleOutputCache+=s;
WebConsoleOutputCache+='\n';
#endif
}
/* ===== WiFi ===== */
@ -331,6 +408,7 @@ void setOutputPower(float dBm) {
}
/* ===== MAC ADDRESSES ===== */
#include "oui.h"
bool macBroadcast(uint8_t* mac) {
for (uint8_t i = 0; i < 6; i++)
if (mac[i] != broadcast[i]) return false;
@ -401,7 +479,6 @@ int binSearchVendors(uint8_t* searchBytes, int lowerEnd, int upperEnd) {
return -1;
}
String searchVendor(uint8_t* mac) {
String vendorName = String();
int pos = binSearchVendors(mac, 0, sizeof(data_macs) / 5 - 1);
@ -828,4 +905,5 @@ String formatBytes(size_t bytes) {
else if (bytes < (1024 * 1024)) return String(bytes / 1024.0) + "KB";
else if (bytes < (1024 * 1024 * 1024)) return String(bytes / 1024.0 / 1024.0) + "MB";
else return String(bytes / 1024.0 / 1024.0 / 1024.0) + "GB";
}
}
#endif

View File

@ -39799,4 +39799,4 @@ const static uint8_t data_macs[] PROGMEM = {
0xFC, 0xFF, 0xAA, 0x57, 0x17
#endif
};
#endif
#endif

File diff suppressed because one or more lines are too long

View File

@ -19,6 +19,9 @@ extern "C" {
#include "CLI.h"
#include "Attack.h"
#include "Scan.h"
#ifdef ENABLE_WEB_CONSOLE
#include "functions.h"
#endif
extern bool progmemToSpiffs(const char* adr, int len, String path);
@ -295,6 +298,14 @@ namespace wifi {
server.on("/settings.html", HTTP_GET, []() {
sendProgmem(settingshtml, sizeof(settingshtml), W_HTML);
});
#ifdef ENABLE_WEB_CONSOLE
server.on("/webconsole.html", HTTP_GET, []() {
sendProgmem(webconsolehtml, sizeof(webconsolehtml), W_HTML);
});
server.on("/js/webconsole.js", HTTP_GET, []() {
sendProgmem(webconsolejs, sizeof(webconsolejs), W_JS);
});
#endif
server.on("/style.css", HTTP_GET, []() {
sendProgmem(stylecss, sizeof(stylecss), W_CSS);
});
@ -414,7 +425,13 @@ namespace wifi {
String input = server.arg("cmd");
cli.exec(input);
});
#ifdef ENABLE_WEB_CONSOLE
server.on("/console", HTTP_GET, []() {
server.send(200, str(W_TXT), WebConsoleOutputCache.c_str());
//Clearing the cache once it is sent
WebConsoleOutputCache="";
});
#endif
server.on("/attack.json", HTTP_GET, []() {
server.send(200, str(W_JSON), attack.getStatusJSON());
});
@ -462,4 +479,4 @@ namespace wifi {
dns.processNextRequest();
}
}
}
}

View File

@ -0,0 +1,344 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Created by: juancarlospaco
# GitHub Repo: https://github.com/juancarlospaco/css-html-js-minify
"""CSS Minifier functions for CSS-HTML-JS-Minify."""
import re
import itertools
import logging as log
from variables import EXTENDED_NAMED_COLORS, CSS_PROPS_TEXT
__all__ = ['css_minify', 'condense_semicolons']
def _compile_props(props_text, grouped=False):
"""Take a list of props and prepare them."""
props, prefixes = [], "-webkit-,-khtml-,-epub-,-moz-,-ms-,-o-,".split(",")
for propline in props_text.strip().lower().splitlines():
props += [pre + pro for pro in propline.split(" ") for pre in prefixes]
props = filter(lambda line: not line.startswith('#'), props)
if not grouped:
props = list(filter(None, props))
return props, [0]*len(props)
final_props, groups, g_id = [], [], 0
for prop in props:
if prop.strip():
final_props.append(prop)
groups.append(g_id)
else:
g_id += 1
return final_props, groups
def _prioritify(line_of_css, css_props_text_as_list):
"""Return args priority, priority is integer and smaller means higher."""
sorted_css_properties, groups_by_alphabetic_order = css_props_text_as_list
priority_integer, group_integer = 9999, 0
for css_property in sorted_css_properties:
if css_property.lower() == line_of_css.split(":")[0].lower().strip():
priority_integer = sorted_css_properties.index(css_property)
group_integer = groups_by_alphabetic_order[priority_integer]
break
return priority_integer, group_integer
def _props_grouper(props, pgs):
"""Return groups for properties."""
if not props:
return props
# props = sorted([
# _ if _.strip().endswith(";")
# and not _.strip().endswith("*/") and not _.strip().endswith("/*")
# else _.rstrip() + ";\n" for _ in props])
props_pg = zip(map(lambda prop: _prioritify(prop, pgs), props), props)
props_pg = sorted(props_pg, key=lambda item: item[0][1])
props_by_groups = map(
lambda item: list(item[1]),
itertools.groupby(props_pg, key=lambda item: item[0][1]))
props_by_groups = map(lambda item: sorted(
item, key=lambda item: item[0][0]), props_by_groups)
props = []
for group in props_by_groups:
group = map(lambda item: item[1], group)
props += group
props += ['\n']
props.pop()
return props
def sort_properties(css_unsorted_string):
"""CSS Property Sorter Function.
This function will read buffer argument, split it to a list by lines,
sort it by defined rule, and return sorted buffer if it's CSS property.
This function depends on '_prioritify' function.
"""
log.debug("Alphabetically Sorting all CSS / SCSS Properties.")
css_pgs = _compile_props(CSS_PROPS_TEXT, grouped=False) # Do Not Group.
pattern = re.compile(r'(.*?{\r?\n?)(.*?)(}.*?)|(.*)',
re.DOTALL + re.MULTILINE)
matched_patterns = pattern.findall(css_unsorted_string)
sorted_patterns, sorted_buffer = [], css_unsorted_string
re_prop = re.compile(r'((?:.*?)(?:;)(?:.*?\n)|(?:.*))',
re.DOTALL + re.MULTILINE)
if len(matched_patterns) != 0:
for matched_groups in matched_patterns:
sorted_patterns += matched_groups[0].splitlines(True)
props = map(lambda line: line.lstrip('\n'),
re_prop.findall(matched_groups[1]))
props = list(filter(lambda line: line.strip('\n '), props))
props = _props_grouper(props, css_pgs)
sorted_patterns += props
sorted_patterns += matched_groups[2].splitlines(True)
sorted_patterns += matched_groups[3].splitlines(True)
sorted_buffer = ''.join(sorted_patterns)
return sorted_buffer
def remove_comments(css):
"""Remove all CSS comment blocks."""
log.debug("Removing all Comments.")
iemac, preserve = False, False
comment_start = css.find("/*")
while comment_start >= 0: # Preserve comments that look like `/*!...*/`.
# Slicing is used to make sure we dont get an IndexError.
preserve = css[comment_start + 2:comment_start + 3] == "!"
comment_end = css.find("*/", comment_start + 2)
if comment_end < 0:
if not preserve:
css = css[:comment_start]
break
elif comment_end >= (comment_start + 2):
if css[comment_end - 1] == "\\":
# This is an IE Mac-specific comment; leave this one and the
# following one alone.
comment_start = comment_end + 2
iemac = True
elif iemac:
comment_start = comment_end + 2
iemac = False
elif not preserve:
css = css[:comment_start] + css[comment_end + 2:]
else:
comment_start = comment_end + 2
comment_start = css.find("/*", comment_start)
return css
def remove_unnecessary_whitespace(css):
"""Remove unnecessary whitespace characters."""
log.debug("Removing all unnecessary white spaces.")
def pseudoclasscolon(css):
"""Prevent 'p :link' from becoming 'p:link'.
Translates 'p :link' into 'p ___PSEUDOCLASSCOLON___link'.
This is translated back again later.
"""
regex = re.compile(r"(^|\})(([^\{\:])+\:)+([^\{]*\{)")
match = regex.search(css)
while match:
css = ''.join([
css[:match.start()],
match.group().replace(":", "___PSEUDOCLASSCOLON___"),
css[match.end():]])
match = regex.search(css)
return css
css = pseudoclasscolon(css)
# Remove spaces from before things.
css = re.sub(r"\s+([!{};:>\(\)\],])", r"\1", css)
# If there is a `@charset`, then only allow one, and move to beginning.
css = re.sub(r"^(.*)(@charset \"[^\"]*\";)", r"\2\1", css)
css = re.sub(r"^(\s*@charset [^;]+;\s*)+", r"\1", css)
# Put the space back in for a few cases, such as `@media screen` and
# `(-webkit-min-device-pixel-ratio:0)`.
css = re.sub(r"\band\(", "and (", css)
# Put the colons back.
css = css.replace('___PSEUDOCLASSCOLON___', ':')
# Remove spaces from after things.
css = re.sub(r"([!{}:;>\(\[,])\s+", r"\1", css)
return css
def remove_unnecessary_semicolons(css):
"""Remove unnecessary semicolons."""
log.debug("Removing all unnecessary semicolons.")
return re.sub(r";+\}", "}", css)
def remove_empty_rules(css):
"""Remove empty rules."""
log.debug("Removing all unnecessary empty rules.")
return re.sub(r"[^\}\{]+\{\}", "", css)
def normalize_rgb_colors_to_hex(css):
"""Convert `rgb(51,102,153)` to `#336699`."""
log.debug("Converting all rgba to hexadecimal color values.")
regex = re.compile(r"rgb\s*\(\s*([0-9,\s]+)\s*\)")
match = regex.search(css)
while match:
colors = map(lambda s: s.strip(), match.group(1).split(","))
hexcolor = '#%.2x%.2x%.2x' % tuple(map(int, colors))
css = css.replace(match.group(), hexcolor)
match = regex.search(css)
return css
def condense_zero_units(css):
"""Replace `0(px, em, %, etc)` with `0`."""
log.debug("Condensing all zeroes on values.")
return re.sub(r"([\s:])(0)(px|em|%|in|q|ch|cm|mm|pc|pt|ex|rem|s|ms|"
r"deg|grad|rad|turn|vw|vh|vmin|vmax|fr)", r"\1\2", css)
def condense_multidimensional_zeros(css):
"""Replace `:0 0 0 0;`, `:0 0 0;` etc. with `:0;`."""
log.debug("Condensing all multidimensional zeroes on values.")
return css.replace(":0 0 0 0;", ":0;").replace(
":0 0 0;", ":0;").replace(":0 0;", ":0;").replace(
"background-position:0;", "background-position:0 0;").replace(
"transform-origin:0;", "transform-origin:0 0;")
def condense_floating_points(css):
"""Replace `0.6` with `.6` where possible."""
log.debug("Condensing all floating point values.")
return re.sub(r"(:|\s)0+\.(\d+)", r"\1.\2", css)
def condense_hex_colors(css):
"""Shorten colors from #AABBCC to #ABC where possible."""
log.debug("Condensing all hexadecimal color values.")
regex = re.compile(
r"""([^\"'=\s])(\s*)#([0-9a-f])([0-9a-f])([0-9a-f])"""
r"""([0-9a-f])([0-9a-f])([0-9a-f])""", re.I | re.S)
match = regex.search(css)
while match:
first = match.group(3) + match.group(5) + match.group(7)
second = match.group(4) + match.group(6) + match.group(8)
if first.lower() == second.lower():
css = css.replace(
match.group(), match.group(1) + match.group(2) + '#' + first)
match = regex.search(css, match.end() - 3)
else:
match = regex.search(css, match.end())
return css
def condense_whitespace(css):
"""Condense multiple adjacent whitespace characters into one."""
log.debug("Condensing all unnecessary white spaces.")
return re.sub(r"\s+", " ", css)
def condense_semicolons(css):
"""Condense multiple adjacent semicolon characters into one."""
log.debug("Condensing all unnecessary multiple adjacent semicolons.")
return re.sub(r";;+", ";", css)
def wrap_css_lines(css, line_length=80):
"""Wrap the lines of the given CSS to an approximate length."""
log.debug("Wrapping lines to ~{0} max line lenght.".format(line_length))
lines, line_start = [], 0
for i, char in enumerate(css):
# Its safe to break after } characters.
if char == '}' and (i - line_start >= line_length):
lines.append(css[line_start:i + 1])
line_start = i + 1
if line_start < len(css):
lines.append(css[line_start:])
return '\n'.join(lines)
def condense_font_weight(css):
"""Condense multiple font weights into shorter integer equals."""
log.debug("Condensing font weights on values.")
return css.replace('font-weight:normal;', 'font-weight:400;').replace(
'font-weight:bold;', 'font-weight:700;')
def condense_std_named_colors(css):
"""Condense named color values to shorter replacement using HEX."""
log.debug("Condensing standard named color values.")
for color_name, color_hexa in iter(tuple({
':aqua;': ':#0ff;', ':blue;': ':#00f;',
':fuchsia;': ':#f0f;', ':yellow;': ':#ff0;'}.items())):
css = css.replace(color_name, color_hexa)
return css
def condense_xtra_named_colors(css):
"""Condense named color values to shorter replacement using HEX."""
log.debug("Condensing extended named color values.")
for k, v in iter(tuple(EXTENDED_NAMED_COLORS.items())):
same_color_but_rgb = 'rgb({0},{1},{2})'.format(v[0], v[1], v[2])
if len(k) > len(same_color_but_rgb):
css = css.replace(k, same_color_but_rgb)
return css
def remove_url_quotes(css):
"""Fix for url() does not need quotes."""
log.debug("Removing quotes from url.")
return re.sub(r'url\((["\'])([^)]*)\1\)', r'url(\2)', css)
def condense_border_none(css):
"""Condense border:none; to border:0;."""
log.debug("Condense borders values.")
return css.replace("border:none;", "border:0;")
def add_encoding(css):
"""Add @charset 'UTF-8'; if missing."""
log.debug("Adding encoding declaration if needed.")
return "@charset utf-8;" + css if "@charset" not in css.lower() else css
def restore_needed_space(css):
"""Fix CSS for some specific cases where a white space is needed."""
return css.replace("!important", " !important").replace( # !important
"@media(", "@media (").replace( # media queries # jpeg > jpg
"data:image/jpeg;base64,", "data:image/jpg;base64,").rstrip("\n;")
def unquote_selectors(css):
"""Fix CSS for some specific selectors where Quotes is not needed."""
log.debug("Removing unnecessary Quotes on selectors of CSS classes.")
return re.compile('([a-zA-Z]+)="([a-zA-Z0-9-_\.]+)"]').sub(r'\1=\2]', css)
def css_minify(css, wrap=False, comments=False, sort=False, noprefix=False):
"""Minify CSS main function."""
log.info("Compressing CSS...")
css = remove_comments(css) if not comments else css
css = sort_properties(css) if sort else css
css = unquote_selectors(css)
css = condense_whitespace(css)
css = remove_url_quotes(css)
css = condense_xtra_named_colors(css)
css = condense_font_weight(css)
css = remove_unnecessary_whitespace(css)
css = condense_std_named_colors(css)
css = remove_unnecessary_semicolons(css)
css = condense_zero_units(css)
css = condense_multidimensional_zeros(css)
css = condense_floating_points(css)
css = normalize_rgb_colors_to_hex(css)
css = condense_hex_colors(css)
css = condense_border_none(css)
css = wrap_css_lines(css, 80) if wrap else css
css = condense_semicolons(css)
css = add_encoding(css) if not noprefix else css
css = restore_needed_space(css)
log.info("Finished compressing CSS !.")
return css.strip()

View File

@ -0,0 +1,157 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Created by: juancarlospaco
# GitHub Repo: https://github.com/juancarlospaco/css-html-js-minify
"""HTML Minifier functions for CSS-HTML-JS-Minify."""
import re
import logging as log
__all__ = ['html_minify']
def condense_html_whitespace(html):
"""Condense HTML, but be safe first if it have textareas or pre tags.
>>> condense_html_whitespace('<i> <b> <a> test </a> </b> </i><br>')
'<i><b><a> test </a></b></i><br>'
""" # first space between tags, then empty new lines and in-between.
log.debug("Removing unnecessary HTML White Spaces and Empty New Lines.")
tagsStack = []
split = re.split('(<\\s*pre.*>|<\\s*/\\s*pre\\s*>|<\\s*textarea.*>|<\\s*/\\s*textarea\\s*>)', html, flags=re.IGNORECASE)
for i in range(0, len(split)):
#if we are on a tag
if (i + 1) % 2 == 0:
tag = rawtag(split[i])
if tag.startswith('/'):
if not tagsStack or '/' + tagsStack.pop() != tag:
raise Exception("Some tag is not closed properly")
else:
tagsStack.append(tag)
continue
#else check if we are outside any nested <pre>/<textarea> tag
if not tagsStack:
temp = re.sub(r'>\s+<', '> <', split[i])
split[i] = re.sub(r'\s{2,}|[\r\n]', ' ', temp)
return ''.join(split)
def rawtag(str):
if re.match('<\\s*pre.*>', str, flags=re.IGNORECASE):
return 'pre'
if re.match('<\\s*textarea.*>', str, flags=re.IGNORECASE):
return 'txt'
if re.match('<\\s*/\\s*pre\\s*>', str, flags=re.IGNORECASE):
return '/pre'
if re.match('<\\s*/\\s*textarea\\s*>', str, flags=re.IGNORECASE):
return '/txt'
def condense_style(html):
"""Condense style html tags.
>>> condense_style('<style type="text/css">*{border:0}</style><p>a b c')
'<style>*{border:0}</style><p>a b c'
""" # May look silly but Emmet does this and is wrong.
log.debug("Condensing HTML Style CSS tags.")
return html.replace('<style type="text/css">', '<style>').replace(
"<style type='text/css'>", '<style>').replace(
"<style type=text/css>", '<style>')
def condense_script(html):
"""Condense script html tags.
>>> condense_script('<script type="text/javascript"> </script><p>a b c')
'<script> </script><p>a b c'
""" # May look silly but Emmet does this and is wrong.
log.debug("Condensing HTML Script JS tags.")
return html.replace('<script type="text/javascript">', '<script>').replace(
"<style type='text/javascript'>", '<script>').replace(
"<style type=text/javascript>", '<script>')
def clean_unneeded_html_tags(html):
"""Clean unneeded optional html tags.
>>> clean_unneeded_html_tags('a<body></img></td>b</th></tr></hr></br>c')
'abc'
"""
log.debug("Removing unnecessary optional HTML tags.")
for tag_to_remove in ("""</area> </base> <body> </body> </br> </col>
</colgroup> </dd> </dt> <head> </head> </hr> <html> </html> </img>
</input> </li> </link> </meta> </option> </param> <tbody> </tbody>
</td> </tfoot> </th> </thead> </tr> </basefont> </isindex> </param>
""".split()):
html = html.replace(tag_to_remove, '')
return html # May look silly but Emmet does this and is wrong.
def remove_html_comments(html):
"""Remove all HTML comments, Keep all for Grunt, Grymt and IE.
>>> _="<!-- build:dev -->a<!-- endbuild -->b<!--[if IE 7]>c<![endif]--> "
>>> _+= "<!-- kill me please -->keep" ; remove_html_comments(_)
'<!-- build:dev -->a<!-- endbuild -->b<!--[if IE 7]>c<![endif]--> keep'
""" # Grunt uses comments to as build arguments, bad practice but still.
log.debug("""Removing all unnecessary HTML comments; Keep all containing:
'build:', 'endbuild', '<!--[if]>', '<![endif]-->' for Grunt/Grymt, IE.""")
return re.compile('<!-- [^(build|endbuild)].*? -->', re.I).sub('', html)
def unquote_html_attributes(html):
"""Remove all HTML quotes on attibutes if possible.
>>> unquote_html_attributes('<img width="9" height="5" data-foo="0" >')
'<img width=9 height=5 data-foo=0 >'
""" # data-foo=0> might cause errors on IE, we leave 1 space data-foo=0 >
log.debug("Removing unnecessary Quotes on attributes of HTML tags.")
# cache all regular expressions on variables before we enter the for loop.
any_tag = re.compile(r"<\w.*?>", re.I | re.MULTILINE | re.DOTALL)
space = re.compile(r' \s+|\s +', re.MULTILINE)
space1 = re.compile(r'\w\s+\w', re.MULTILINE)
space2 = re.compile(r'"\s+>', re.MULTILINE)
space3 = re.compile(r"'\s+>", re.MULTILINE)
space4 = re.compile('"\s\s+\w+="|\'\s\s+\w+=\'|"\s\s+\w+=|\'\s\s+\w+=',
re.MULTILINE)
space6 = re.compile(r"\d\s+>", re.MULTILINE)
quotes_in_tag = re.compile('([a-zA-Z]+)="([a-zA-Z0-9-_\.]+)"')
# iterate on a for loop cleaning stuff up on the html markup.
for tag in iter(any_tag.findall(html)):
# exceptions of comments and closing tags
if tag.startswith('<!') or tag.find('</') > -1:
continue
original = tag
# remove white space inside the tag itself
tag = space2.sub('" >', tag) # preserve 1 white space is safer
tag = space3.sub("' >", tag)
for each in space1.findall(tag) + space6.findall(tag):
tag = tag.replace(each, space.sub(' ', each))
for each in space4.findall(tag):
tag = tag.replace(each, each[0] + ' ' + each[1:].lstrip())
# remove quotes on some attributes
tag = quotes_in_tag.sub(r'\1=\2 ', tag) # See Bug #28
if original != tag: # has the tag been improved ?
html = html.replace(original, tag)
return html.strip()
def html_minify(html, comments=False):
"""Minify HTML main function.
>>> html_minify(' <p width="9" height="5" > <!-- a --> b </p> c <br> ')
'<p width=9 height=5 > b c <br>'
"""
log.info("Compressing HTML...")
html = remove_html_comments(html) if not comments else html
html = condense_style(html)
html = condense_script(html)
html = clean_unneeded_html_tags(html)
html = condense_html_whitespace(html)
html = unquote_html_attributes(html)
log.info("Finished compressing HTML !.")
return html.strip()

View File

@ -0,0 +1,213 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Created by: juancarlospaco
# GitHub Repo: https://github.com/juancarlospaco/css-html-js-minify
"""Variables for CSS processing for CSS-HTML-JS-Minify."""
# 'Color Name String': (R, G, B)
EXTENDED_NAMED_COLORS = {
'azure': (240, 255, 255),
'beige': (245, 245, 220),
'bisque': (255, 228, 196),
'blanchedalmond': (255, 235, 205),
'brown': (165, 42, 42),
'burlywood': (222, 184, 135),
'chartreuse': (127, 255, 0),
'chocolate': (210, 105, 30),
'coral': (255, 127, 80),
'cornsilk': (255, 248, 220),
'crimson': (220, 20, 60),
'cyan': (0, 255, 255),
'darkcyan': (0, 139, 139),
'darkgoldenrod': (184, 134, 11),
'darkgray': (169, 169, 169),
'darkgreen': (0, 100, 0),
'darkgrey': (169, 169, 169),
'darkkhaki': (189, 183, 107),
'darkmagenta': (139, 0, 139),
'darkolivegreen': (85, 107, 47),
'darkorange': (255, 140, 0),
'darkorchid': (153, 50, 204),
'darkred': (139, 0, 0),
'darksalmon': (233, 150, 122),
'darkseagreen': (143, 188, 143),
'darkslategray': (47, 79, 79),
'darkslategrey': (47, 79, 79),
'darkturquoise': (0, 206, 209),
'darkviolet': (148, 0, 211),
'deeppink': (255, 20, 147),
'dimgray': (105, 105, 105),
'dimgrey': (105, 105, 105),
'firebrick': (178, 34, 34),
'forestgreen': (34, 139, 34),
'gainsboro': (220, 220, 220),
'gold': (255, 215, 0),
'goldenrod': (218, 165, 32),
'gray': (128, 128, 128),
'green': (0, 128, 0),
'grey': (128, 128, 128),
'honeydew': (240, 255, 240),
'hotpink': (255, 105, 180),
'indianred': (205, 92, 92),
'indigo': (75, 0, 130),
'ivory': (255, 255, 240),
'khaki': (240, 230, 140),
'lavender': (230, 230, 250),
'lavenderblush': (255, 240, 245),
'lawngreen': (124, 252, 0),
'lemonchiffon': (255, 250, 205),
'lightcoral': (240, 128, 128),
'lightcyan': (224, 255, 255),
'lightgray': (211, 211, 211),
'lightgreen': (144, 238, 144),
'lightgrey': (211, 211, 211),
'lightpink': (255, 182, 193),
'lightsalmon': (255, 160, 122),
'lightseagreen': (32, 178, 170),
'lightslategray': (119, 136, 153),
'lightslategrey': (119, 136, 153),
'lime': (0, 255, 0),
'limegreen': (50, 205, 50),
'linen': (250, 240, 230),
'magenta': (255, 0, 255),
'maroon': (128, 0, 0),
'mediumorchid': (186, 85, 211),
'mediumpurple': (147, 112, 219),
'mediumseagreen': (60, 179, 113),
'mediumspringgreen': (0, 250, 154),
'mediumturquoise': (72, 209, 204),
'mediumvioletred': (199, 21, 133),
'mintcream': (245, 255, 250),
'mistyrose': (255, 228, 225),
'moccasin': (255, 228, 181),
'navy': (0, 0, 128),
'oldlace': (253, 245, 230),
'olive': (128, 128, 0),
'olivedrab': (107, 142, 35),
'orange': (255, 165, 0),
'orangered': (255, 69, 0),
'orchid': (218, 112, 214),
'palegoldenrod': (238, 232, 170),
'palegreen': (152, 251, 152),
'paleturquoise': (175, 238, 238),
'palevioletred': (219, 112, 147),
'papayawhip': (255, 239, 213),
'peachpuff': (255, 218, 185),
'peru': (205, 133, 63),
'pink': (255, 192, 203),
'plum': (221, 160, 221),
'purple': (128, 0, 128),
'rosybrown': (188, 143, 143),
'saddlebrown': (139, 69, 19),
'salmon': (250, 128, 114),
'sandybrown': (244, 164, 96),
'seagreen': (46, 139, 87),
'seashell': (255, 245, 238),
'sienna': (160, 82, 45),
'silver': (192, 192, 192),
'slategray': (112, 128, 144),
'slategrey': (112, 128, 144),
'snow': (255, 250, 250),
'springgreen': (0, 255, 127),
'teal': (0, 128, 128),
'thistle': (216, 191, 216),
'tomato': (255, 99, 71),
'turquoise': (64, 224, 208),
'violet': (238, 130, 238),
'wheat': (245, 222, 179)
}
# Do Not compact this string, new lines are used to Group up stuff.
CSS_PROPS_TEXT = '''
alignment-adjust alignment-baseline animation animation-delay
animation-direction animation-duration animation-iteration-count
animation-name animation-play-state animation-timing-function appearance
azimuth
backface-visibility background background-blend-mode background-attachment
background-clip background-color background-image background-origin
background-position background-position-block background-position-inline
background-position-x background-position-y background-repeat background-size
baseline-shift bikeshedding bookmark-label bookmark-level bookmark-state
bookmark-target border border-bottom border-bottom-color
border-bottom-left-radius border-bottom-parts border-bottom-right-radius
border-bottom-style border-bottom-width border-clip border-clip-top
border-clip-right border-clip-bottom border-clip-left border-collapse
border-color border-corner-shape border-image border-image-outset
border-image-repeat border-image-slice border-image-source border-image-width
border-left border-left-color border-left-style border-left-parts
border-left-width border-limit border-parts border-radius border-right
border-right-color border-right-style border-right-width border-right-parts
border-spacing border-style border-top border-top-color border-top-left-radius
border-top-parts border-top-right-radius border-top-style border-top-width
border-width bottom box-decoration-break box-shadow box-sizing
caption-side clear clip color column-count column-fill column-gap column-rule
column-rule-color column-rule-style column-rule-width column-span column-width
columns content counter-increment counter-reset corners corner-shape
cue cue-after cue-before cursor
direction display drop-initial-after-adjust drop-initial-after-align
drop-initial-before-adjust drop-initial-before-align drop-initial-size
drop-initial-value
elevation empty-cells
flex flex-basis flex-direction flex-flow flex-grow flex-shrink flex-wrap fit
fit-position float font font-family font-size font-size-adjust font-stretch
font-style font-variant font-weight
grid-columns grid-rows
justify-content
hanging-punctuation height hyphenate-character hyphenate-resource hyphens
icon image-orientation image-resolution inline-box-align
left letter-spacing line-height line-stacking line-stacking-ruby
line-stacking-shift line-stacking-strategy linear-gradient list-style
list-style-image list-style-position list-style-type
margin margin-bottom margin-left margin-right margin-top marquee-direction
marquee-loop marquee-speed marquee-style max-height max-width min-height
min-width
nav-index
opacity orphans outline outline-color outline-offset outline-style
outline-width overflow overflow-style overflow-x overflow-y
padding padding-bottom padding-left padding-right padding-top page
page-break-after page-break-before page-break-inside pause pause-after
pause-before perspective perspective-origin pitch pitch-range play-during
position presentation-level
quotes
resize rest rest-after rest-before richness right rotation rotation-point
ruby-align ruby-overhang ruby-position ruby-span
size speak speak-header speak-numeral speak-punctuation speech-rate src
stress string-set
table-layout target target-name target-new target-position text-align
text-align-last text-decoration text-emphasis text-indent text-justify
text-outline text-shadow text-transform text-wrap top transform
transform-origin transition transition-delay transition-duration
transition-property transition-timing-function
unicode-bidi unicode-range
vertical-align visibility voice-balance voice-duration voice-family
voice-pitch voice-range voice-rate voice-stress voice-volume volume
white-space widows width word-break word-spacing word-wrap
z-index
'''

View File

@ -0,0 +1,40 @@
import gzip
from os import path
import argparse
import css_minifier
import html_minifier
def CompressedGZipArray(data:bytes) -> list:
comp=gzip.compress(data)
return [hex(i) for i in comp]
def CompressedGZipArrayFromFile(fp) -> list:
data=fp.read()
if type(data)==type(b''):
return CompressedGZipArray(data)
else:
return CompressedGZipArray(bytes(data))
def ExportCompressedFile(infile:str,outpath:str='./gz/'):
with open(infile,'r') as plain:
if infile.endswith(".html"):
minified=html_minifier.html_minify(plain.read())
elif infile.endswith(".css"):
minified=css_minifier.css_minify(plain.read())
else:
minified=plain.read()
with gzip.open(path.join(path.dirname(infile),outpath,path.basename(infile))+'.gz','wb+') as compressed:
compressed.write(bytes(minified,encoding='utf-8'))
print("const char "+path.basename(infile).replace('.','').lower()+'[] PROGMEM = {'+' ,'.join(CompressedGZipArray(bytes(minified,encoding='utf-8')))+'};')
if __name__=="__main__":
parser=argparse.ArgumentParser("ESP8266 Deauther Simple Web Converter",description="Converts the html or css to ESP8266 Deauther Friendly GZip files and exports the GZip Array",usage="web_converter.py [-h] [-O OUT] FILE")
parser.add_argument("FILE",help="Path of the HTML or CSS file to convert")
parser.add_argument("-O","--out",help="Output path where the converted file will be stored")
arguments=parser.parse_args()
inputFile=arguments.FILE
outputPath=arguments.out if arguments.out else './gz/'
ExportCompressedFile(inputFile,outputPath)

View File

@ -0,0 +1,55 @@
Output=getE("Output")
Command=getE("Command")
CLIHistory=[]
HistoryPointer=0
Command.addEventListener('keyup',(ev)=>{
if(ev.keyCode==13){
//Enter is pressed
cmd=Command.value
if (cmd.length>0) {
if(cmd.trim()=="clear"){
Output.value=""
Command.value=""
}else{
getFile(`/run?cmd=${cmd}`,()=>{
CLIHistory.push(cmd)
Command.value=""
HistoryPointer=0
getFile("/console",(responseText)=>{
Output.value=responseText+Output.value
})
})
}
}
}
else if(ev.keyCode==38){
//Up arrow key presssed
if(CLIHistory.length>0){
len=CLIHistory.length
if(CLIHistory[len-HistoryPointer-1]){
Command.value=CLIHistory[len-HistoryPointer-1]
HistoryPointer++
}
}
}
else if(ev.keyCode==40){
//Down arrow key pressed
if(CLIHistory.length>0){
len=CLIHistory.length
if(CLIHistory[len-HistoryPointer+1]){
Command.value=CLIHistory[len-HistoryPointer+1]
HistoryPointer--
}
}
}
else{
HistoryPointer=0
}
})
setInterval(()=>{
getFile("/console",(responseText)=>{
Output.value=responseText+Output.value
})
},5000)

View File

@ -390,6 +390,15 @@ input[type="file"] {
min-height: 0.125rem;
}
/*Web Console*/
#Output{
width: 100%;
height: 80vh;
}
#Command{
width: 100%;
height: 10vh;
}
.col-1,
.col-2,
.col-3,

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./js/site.js"></script>
<link rel="stylesheet" href="./style.css">
<title>Console</title>
</head>
<body>
<div id="status"></div>
<textarea name="consoleOutPut" id="Output" readonly></textarea><br>
<input type="text" name="cmd" id="Command" placeholder="~/ $" autofocus>
<script src="./js/webconsole.js"></script>
</body>
</html>