mirror of
https://github.com/SpacehuhnTech/esp8266_deauther.git
synced 2025-12-22 07:10:51 -08:00
v2.0.6
Rewritten LED classes and simplified config files
This commit is contained in:
@@ -23,15 +23,11 @@
|
||||
Adjust following settings for your type of LED
|
||||
you can ignore the rest of the #define's
|
||||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||
// === Settings for Digital LED === //
|
||||
#define LED_ENABLE_R true
|
||||
#define LED_ENABLE_G false
|
||||
#define LED_ENABLE_B true
|
||||
|
||||
// === Settings for Digital LED and RGB LED === //
|
||||
#define LED_CATHODE false // common ground (GND)
|
||||
#define LED_ANODE false // common vcc (+)
|
||||
#define LED_PIN_R 16 // NodeMCU on-board LED
|
||||
#define LED_PIN_G 0
|
||||
#define LED_PIN_G 255 // 255 = LED disabled
|
||||
#define LED_PIN_B 2 // ESP-12 LED
|
||||
|
||||
// === Settings for RGB LED and Neopixel LED === //
|
||||
@@ -42,16 +38,6 @@
|
||||
#define LED_NEOPIXEL_NUM 12
|
||||
#define LED_NEOPIXEL_PIN 15
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = Arduino pin number (most are valid)
|
||||
// Parameter 3 = pixel type flags, add together as needed:
|
||||
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
|
||||
|
||||
// ===================== DISPLAY CONFIG ==================== //
|
||||
#define USE_DISPLAY true // default display setting
|
||||
|
||||
|
||||
@@ -23,15 +23,11 @@
|
||||
Adjust following settings for your type of LED
|
||||
you can ignore the rest of the #define's
|
||||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||
// === Settings for Digital LED === //
|
||||
#define LED_ENABLE_R true
|
||||
#define LED_ENABLE_G false
|
||||
#define LED_ENABLE_B true
|
||||
|
||||
// === Settings for Digital LED and RGB LED === //
|
||||
#define LED_CATHODE false // common ground (GND)
|
||||
#define LED_ANODE false // common vcc (+)
|
||||
#define LED_PIN_R 16 // NodeMCU on-board LED
|
||||
#define LED_PIN_G 0
|
||||
#define LED_PIN_G 255 // 255 = LED disabled
|
||||
#define LED_PIN_B 2 // ESP-12 LED
|
||||
|
||||
// === Settings for RGB LED and Neopixel LED === //
|
||||
@@ -41,8 +37,6 @@
|
||||
// === Settings for Neopixel LED === //
|
||||
#define LED_NEOPIXEL_NUM 1
|
||||
#define LED_NEOPIXEL_PIN 15
|
||||
// if it doesn't work try changing NEO_GRB to NEO_GRBW
|
||||
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
|
||||
|
||||
// ===================== DISPLAY CONFIG ==================== //
|
||||
#define USE_DISPLAY true // default display setting
|
||||
|
||||
@@ -23,15 +23,11 @@
|
||||
Adjust following settings for your type of LED
|
||||
you can ignore the rest of the #define's
|
||||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||
// === Settings for Digital LED === //
|
||||
#define LED_ENABLE_R true
|
||||
#define LED_ENABLE_G false
|
||||
#define LED_ENABLE_B true
|
||||
|
||||
// === Settings for Digital LED and RGB LED === //
|
||||
#define LED_CATHODE false // common ground (GND)
|
||||
#define LED_ANODE false // common vcc (+)
|
||||
#define LED_PIN_R 16 // NodeMCU on-board LED
|
||||
#define LED_PIN_G 0
|
||||
#define LED_PIN_G 255 // 255 = LED disabled
|
||||
#define LED_PIN_B 2 // ESP-12 LED
|
||||
|
||||
// === Settings for RGB LED and Neopixel LED === //
|
||||
@@ -42,16 +38,6 @@
|
||||
#define LED_NEOPIXEL_NUM 1
|
||||
#define LED_NEOPIXEL_PIN 9
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = Arduino pin number (most are valid)
|
||||
// Parameter 3 = pixel type flags, add together as needed:
|
||||
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
|
||||
|
||||
// ===================== DISPLAY CONFIG ==================== //
|
||||
#define USE_DISPLAY true // default display setting
|
||||
|
||||
|
||||
@@ -23,15 +23,11 @@
|
||||
Adjust following settings for your type of LED
|
||||
you can ignore the rest of the #define's
|
||||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||
// === Settings for Digital LED === //
|
||||
#define LED_ENABLE_R true
|
||||
#define LED_ENABLE_G false
|
||||
#define LED_ENABLE_B true
|
||||
|
||||
// === Settings for Digital LED and RGB LED === //
|
||||
#define LED_CATHODE false // common ground (GND)
|
||||
#define LED_ANODE false // common vcc (+)
|
||||
#define LED_PIN_R 16 // NodeMCU on-board LED
|
||||
#define LED_PIN_G 0
|
||||
#define LED_PIN_G 255 // 255 = LED disabled
|
||||
#define LED_PIN_B 2 // ESP-12 LED
|
||||
|
||||
// === Settings for RGB LED and Neopixel LED === //
|
||||
@@ -42,16 +38,6 @@
|
||||
#define LED_NEOPIXEL_NUM 1
|
||||
#define LED_NEOPIXEL_PIN 9
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = Arduino pin number (most are valid)
|
||||
// Parameter 3 = pixel type flags, add together as needed:
|
||||
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
|
||||
|
||||
// ===================== DISPLAY CONFIG ==================== //
|
||||
#define USE_DISPLAY true // default display setting
|
||||
|
||||
|
||||
@@ -23,16 +23,12 @@
|
||||
Adjust following settings for your type of LED
|
||||
you can ignore the rest of the #define's
|
||||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||
// === Settings for Digital LED === //
|
||||
#define LED_ENABLE_R true
|
||||
#define LED_ENABLE_G false
|
||||
#define LED_ENABLE_B true
|
||||
|
||||
// === Settings for Digital LED and RGB LED === //
|
||||
#define LED_CATHODE false // common ground (GND)
|
||||
#define LED_PIN_R 2 // ESP-12 LED
|
||||
#define LED_PIN_G 0
|
||||
#define LED_PIN_B 16 // NodeMCU on-board LED
|
||||
#define LED_ANODE false // common vcc (+)
|
||||
#define LED_PIN_R 16 // NodeMCU on-board LED
|
||||
#define LED_PIN_G 255 // 255 = LED disabled
|
||||
#define LED_PIN_B 2 // ESP-12 LED
|
||||
|
||||
// === Settings for RGB LED and Neopixel LED === //
|
||||
#define LED_MODE_BRIGHTNESS 10 // brightness of LED modes
|
||||
@@ -42,16 +38,6 @@
|
||||
#define LED_NEOPIXEL_NUM 1
|
||||
#define LED_NEOPIXEL_PIN 15
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = Arduino pin number (most are valid)
|
||||
// Parameter 3 = pixel type flags, add together as needed:
|
||||
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
|
||||
|
||||
// ===================== DISPLAY CONFIG ==================== //
|
||||
#define USE_DISPLAY true // default display setting
|
||||
|
||||
|
||||
@@ -23,15 +23,11 @@
|
||||
Adjust following settings for your type of LED
|
||||
you can ignore the rest of the #define's
|
||||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||
// === Settings for Digital LED === //
|
||||
#define LED_ENABLE_R true
|
||||
#define LED_ENABLE_G false
|
||||
#define LED_ENABLE_B true
|
||||
|
||||
// === Settings for Digital LED and RGB LED === //
|
||||
#define LED_CATHODE false // common ground (GND)
|
||||
#define LED_ANODE false // common vcc (+)
|
||||
#define LED_PIN_R 16 // NodeMCU on-board LED
|
||||
#define LED_PIN_G 0
|
||||
#define LED_PIN_G 255 // 255 = LED disabled
|
||||
#define LED_PIN_B 2 // ESP-12 LED
|
||||
|
||||
// === Settings for RGB LED and Neopixel LED === //
|
||||
@@ -42,16 +38,6 @@
|
||||
#define LED_NEOPIXEL_NUM 1
|
||||
#define LED_NEOPIXEL_PIN 15
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = Arduino pin number (most are valid)
|
||||
// Parameter 3 = pixel type flags, add together as needed:
|
||||
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
|
||||
|
||||
// ===================== DISPLAY CONFIG ==================== //
|
||||
#define USE_DISPLAY false // default display setting
|
||||
|
||||
|
||||
@@ -23,15 +23,11 @@
|
||||
Adjust following settings for your type of LED
|
||||
you can ignore the rest of the #define's
|
||||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||
// === Settings for Digital LED === //
|
||||
#define LED_ENABLE_R true
|
||||
#define LED_ENABLE_G false
|
||||
#define LED_ENABLE_B true
|
||||
|
||||
// === Settings for Digital LED and RGB LED === //
|
||||
#define LED_CATHODE false // common ground (GND)
|
||||
#define LED_ANODE false // common vcc (+)
|
||||
#define LED_PIN_R 16 // NodeMCU on-board LED
|
||||
#define LED_PIN_G 0
|
||||
#define LED_PIN_G 255 // 255 = LED disabled
|
||||
#define LED_PIN_B 2 // ESP-12 LED
|
||||
|
||||
// === Settings for RGB LED and Neopixel LED === //
|
||||
@@ -42,16 +38,6 @@
|
||||
#define LED_NEOPIXEL_NUM 1
|
||||
#define LED_NEOPIXEL_PIN 4
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = Arduino pin number (most are valid)
|
||||
// Parameter 3 = pixel type flags, add together as needed:
|
||||
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
|
||||
|
||||
// ===================== DISPLAY CONFIG ==================== //
|
||||
#define USE_DISPLAY false // default display setting
|
||||
|
||||
|
||||
@@ -23,15 +23,11 @@
|
||||
Adjust following settings for your type of LED
|
||||
you can ignore the rest of the #define's
|
||||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||
// === Settings for Digital LED === //
|
||||
#define LED_ENABLE_R true
|
||||
#define LED_ENABLE_G false
|
||||
#define LED_ENABLE_B true
|
||||
|
||||
// === Settings for Digital LED and RGB LED === //
|
||||
#define LED_CATHODE false // common ground (GND)
|
||||
#define LED_ANODE false // common vcc (+)
|
||||
#define LED_PIN_R 16 // NodeMCU on-board LED
|
||||
#define LED_PIN_G 0
|
||||
#define LED_PIN_G 255 // 255 = LED disabled
|
||||
#define LED_PIN_B 2 // ESP-12 LED
|
||||
|
||||
// === Settings for RGB LED and Neopixel LED === //
|
||||
@@ -40,18 +36,7 @@
|
||||
|
||||
// === Settings for Neopixel LED === //
|
||||
#define LED_NEOPIXEL_NUM 1
|
||||
#define LED_NEOPIXEL_PIN 9
|
||||
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = Arduino pin number (most are valid)
|
||||
// Parameter 3 = pixel type flags, add together as needed:
|
||||
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
|
||||
#define LED_NEOPIXEL_PIN 15
|
||||
|
||||
// ===================== DISPLAY CONFIG ==================== //
|
||||
#define USE_DISPLAY false // default display setting
|
||||
|
||||
@@ -11,27 +11,24 @@
|
||||
// =========================== //
|
||||
|
||||
// ===================== LED CONFIG ==================== //
|
||||
|
||||
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
|
||||
Uncomment the type of LED you're using
|
||||
Only one of them can be defined at a time!
|
||||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||
#define DIGITAL_LED
|
||||
//#define RGB_LED
|
||||
//#define NEOPIXEL_LED
|
||||
// #define RGB_LED
|
||||
// #define NEOPIXEL_LED
|
||||
|
||||
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
|
||||
Adjust following settings for your type of LED
|
||||
you can ignore the rest of the #define's
|
||||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||
// === Settings for Digital LED === //
|
||||
#define LED_ENABLE_R true
|
||||
#define LED_ENABLE_G false
|
||||
#define LED_ENABLE_B true
|
||||
|
||||
// === Settings for Digital LED and RGB LED === //
|
||||
#define LED_CATHODE false // common ground (GND)
|
||||
#define LED_ANODE false // common vcc (+)
|
||||
#define LED_PIN_R 16 // NodeMCU on-board LED
|
||||
#define LED_PIN_G 0
|
||||
#define LED_PIN_G 255 // 255 = LED disabled
|
||||
#define LED_PIN_B 2 // ESP-12 LED
|
||||
|
||||
// === Settings for RGB LED and Neopixel LED === //
|
||||
@@ -40,17 +37,7 @@
|
||||
|
||||
// === Settings for Neopixel LED === //
|
||||
#define LED_NEOPIXEL_NUM 1
|
||||
#define LED_NEOPIXEL_PIN 9
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = Arduino pin number (most are valid)
|
||||
// Parameter 3 = pixel type flags, add together as needed:
|
||||
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
|
||||
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
|
||||
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
|
||||
#define LED_NEOPIXEL_PIN 15
|
||||
|
||||
// ===================== DISPLAY CONFIG ==================== //
|
||||
#define USE_DISPLAY false // default display setting
|
||||
@@ -63,28 +50,27 @@
|
||||
#define BUTTON_DOWN 12
|
||||
#define BUTTON_A 13
|
||||
|
||||
//#define BUTTON_LEFT 12
|
||||
//#define BUTTON_RIGHT 13
|
||||
//#define BUTTON_B 10
|
||||
// #define BUTTON_LEFT 12
|
||||
// #define BUTTON_RIGHT 13
|
||||
// #define BUTTON_B 10
|
||||
|
||||
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
|
||||
Uncomment the type of display you're using
|
||||
Only one of them can be defined at a time!
|
||||
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
|
||||
*/
|
||||
*/
|
||||
#define DEAUTHER_DISPLAY SSD1306Wire display = SSD1306Wire(0x3c, 5, 4); // for 0.96" OLED
|
||||
//#define DEAUTHER_DISPLAY SH1106Wire display = SH1106Wire(0x3c, 5, 4); // for 1.3" OLED
|
||||
// #define DEAUTHER_DISPLAY SH1106Wire display = SH1106Wire(0x3c, 5, 4); // for 1.3" OLED
|
||||
|
||||
/* RST = GPIO 5 (D1)
|
||||
DC = GPIO 4 (D2)
|
||||
CS = GPIO 15 (D8) or GND
|
||||
SCK/SCL = GPIO 14 (D5)
|
||||
SDA/MOSI = GPIO 13 (D7) */
|
||||
//#define DEAUTHER_DISPLAY SSD1306Spi display = SSD1306Spi display = SSD1306Spi(5, 4, 15); // for 0.96" OLED with SPI
|
||||
//#define DEAUTHER_DISPLAY SH1106Spi display = SH1106Spi(5, 4, 15); // for 1.3" OLED with SPI
|
||||
// #define DEAUTHER_DISPLAY SSD1306Spi display = SSD1306Spi display = SSD1306Spi(5, 4, 15); // for 0.96" OLED with SPI
|
||||
// #define DEAUTHER_DISPLAY SH1106Spi display = SH1106Spi(5, 4, 15); // for 1.3" OLED with SPI
|
||||
|
||||
//#define FLIP_DIPLAY // uncomment that to flip the display vertically
|
||||
// #define FLIP_DIPLAY // uncomment that to flip the display vertically
|
||||
// ========================================================= //
|
||||
|
||||
#endif
|
||||
|
||||
#endif // ifndef config_h
|
||||
@@ -5,43 +5,44 @@ Accesspoints::Accesspoints() {
|
||||
}
|
||||
|
||||
void Accesspoints::sort() {
|
||||
list->sort([](AP &a, AP &b) -> bool{
|
||||
list->sort([](AP& a, AP& b) -> bool {
|
||||
return WiFi.RSSI(a.id) < WiFi.RSSI(b.id);
|
||||
});
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Accesspoints::sortAfterChannel() {
|
||||
list->sort([](AP &a, AP &b) -> bool{
|
||||
list->sort([](AP& a, AP& b) -> bool {
|
||||
return WiFi.channel(a.id) > WiFi.channel(b.id);
|
||||
});
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Accesspoints::add(uint8_t id, bool selected) {
|
||||
list->add(AP{id, selected});
|
||||
list->add(AP{ id, selected });
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Accesspoints::printAll() {
|
||||
prntln(AP_HEADER);
|
||||
int c = count();
|
||||
if (c == 0)
|
||||
prntln(AP_LIST_EMPTY);
|
||||
|
||||
if (c == 0) prntln(AP_LIST_EMPTY);
|
||||
else
|
||||
for (int i = 0; i < c; i++)
|
||||
print(i, i == 0, i == c - 1);
|
||||
for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1);
|
||||
}
|
||||
|
||||
void Accesspoints::printSelected() {
|
||||
prntln(AP_HEADER);
|
||||
int max = selected();
|
||||
|
||||
if (selected() == 0) {
|
||||
prntln(AP_NO_AP_SELECTED);
|
||||
return;
|
||||
}
|
||||
int c = count();
|
||||
int j = 0;
|
||||
|
||||
for (int i = 0; i < c && j < max; i++) {
|
||||
if (getSelected(i)) {
|
||||
print(i, j == 0, j == max - 1);
|
||||
@@ -56,11 +57,12 @@ void Accesspoints::print(int num) {
|
||||
|
||||
void Accesspoints::print(int num, bool header, bool footer) {
|
||||
if (!check(num)) return;
|
||||
|
||||
if (header) {
|
||||
prntln(AP_TABLE_HEADER);
|
||||
prntln(AP_TABLE_DIVIDER);
|
||||
}
|
||||
prnt(buildString(String(),(String)num, 2));
|
||||
prnt(buildString(String(), (String)num, 2));
|
||||
prnt(buildString(String(SPACE) + getSSID(num), String(), 33));
|
||||
prnt(buildString(String(SPACE) + getNameStr(num), String(), 17));
|
||||
prnt(buildString(String(SPACE), (String)getCh(num), 3));
|
||||
@@ -77,11 +79,12 @@ void Accesspoints::print(int num, bool header, bool footer) {
|
||||
|
||||
String Accesspoints::getSSID(int num) {
|
||||
if (!check(num)) return String();
|
||||
if (getHidden(num)){
|
||||
|
||||
if (getHidden(num)) {
|
||||
return str(AP_HIDDEN);
|
||||
} else {
|
||||
String ssid = WiFi.SSID(getID(num));
|
||||
ssid = ssid.substring(0,32);
|
||||
ssid = ssid.substring(0, 32);
|
||||
ssid = fixUtf8(ssid);
|
||||
return ssid;
|
||||
}
|
||||
@@ -89,41 +92,55 @@ String Accesspoints::getSSID(int num) {
|
||||
|
||||
String Accesspoints::getNameStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
return names.find(getMac(num));
|
||||
}
|
||||
|
||||
uint8_t Accesspoints::getCh(int num) {
|
||||
if (!check(num)) return 0;
|
||||
|
||||
return WiFi.channel(getID(num));
|
||||
}
|
||||
|
||||
int Accesspoints::getRSSI(int num) {
|
||||
if (!check(num)) return 0;
|
||||
|
||||
return WiFi.RSSI(getID(num));
|
||||
}
|
||||
|
||||
uint8_t Accesspoints::getEnc(int num) {
|
||||
if (!check(num)) return 0;
|
||||
|
||||
return WiFi.encryptionType(getID(num));
|
||||
}
|
||||
|
||||
String Accesspoints::getEncStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
switch (getEnc(num)) {
|
||||
case ENC_TYPE_NONE:
|
||||
return String(DASH);
|
||||
|
||||
break;
|
||||
|
||||
case ENC_TYPE_WEP:
|
||||
return str(AP_WEP);
|
||||
|
||||
break;
|
||||
|
||||
case ENC_TYPE_TKIP:
|
||||
return str(AP_WPA);
|
||||
|
||||
break;
|
||||
|
||||
case ENC_TYPE_CCMP:
|
||||
return str(AP_WPA2);
|
||||
|
||||
break;
|
||||
|
||||
case ENC_TYPE_AUTO:
|
||||
return str(AP_AUTO);
|
||||
|
||||
break;
|
||||
}
|
||||
return String(QUESTIONMARK);
|
||||
@@ -135,32 +152,38 @@ String Accesspoints::getSelectedStr(int num) {
|
||||
|
||||
uint8_t* Accesspoints::getMac(int num) {
|
||||
if (!check(num)) return 0;
|
||||
|
||||
return WiFi.BSSID(getID(num));
|
||||
}
|
||||
|
||||
String Accesspoints::getMacStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
uint8_t* mac = getMac(num);
|
||||
return bytesToStr(mac, 6);
|
||||
}
|
||||
|
||||
String Accesspoints::getVendorStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
return searchVendor(getMac(num));
|
||||
}
|
||||
|
||||
bool Accesspoints::getHidden(int num) {
|
||||
if (!check(num)) return false;
|
||||
|
||||
return WiFi.isHidden(getID(num));
|
||||
}
|
||||
|
||||
bool Accesspoints::getSelected(int num) {
|
||||
if (!check(num)) return false;
|
||||
|
||||
return list->get(num).selected;
|
||||
}
|
||||
|
||||
uint8_t Accesspoints::getID(int num){
|
||||
uint8_t Accesspoints::getID(int num) {
|
||||
if (!check(num)) return -1;
|
||||
|
||||
return list->get(num).id;
|
||||
}
|
||||
|
||||
@@ -198,31 +221,28 @@ void Accesspoints::remove(int num) {
|
||||
}
|
||||
|
||||
void Accesspoints::selectAll() {
|
||||
for(int i=0;i<count();i++)
|
||||
list->replace(i,AP{list->get(i).id,true});
|
||||
for (int i = 0; i < count(); i++) list->replace(i, AP{ list->get(i).id, true });
|
||||
prntln(AP_SELECTED_ALL);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Accesspoints::deselectAll() {
|
||||
for(int i=0;i<count();i++)
|
||||
list->replace(i,AP{list->get(i).id,false});
|
||||
for (int i = 0; i < count(); i++) list->replace(i, AP{ list->get(i).id, false });
|
||||
prntln(AP_DESELECTED_ALL);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Accesspoints::removeAll() {
|
||||
while(count() > 0)
|
||||
internal_remove(0);
|
||||
while (count() > 0) internal_remove(0);
|
||||
prntln(AP_REMOVED_ALL);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
int Accesspoints::find(uint8_t id){
|
||||
int Accesspoints::find(uint8_t id) {
|
||||
int s = list->size();
|
||||
for(int i=0;i<s;i++){
|
||||
if(list->get(i).id == id)
|
||||
return i;
|
||||
|
||||
for (int i = 0; i < s; i++) {
|
||||
if (list->get(i).id == id) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -232,13 +252,15 @@ int Accesspoints::count() {
|
||||
}
|
||||
|
||||
int Accesspoints::selected() {
|
||||
return list->count([](AP &a)->bool{
|
||||
return a.selected;
|
||||
});
|
||||
int c = 0;
|
||||
|
||||
for (int i = 0; i < list->size(); i++) c += list->get(i).selected;
|
||||
return c;
|
||||
}
|
||||
|
||||
bool Accesspoints::check(int num) {
|
||||
if (internal_check(num)) return true;
|
||||
|
||||
prnt(AP_NO_AP_ERROR);
|
||||
prntln((String)num);
|
||||
return false;
|
||||
@@ -249,14 +271,13 @@ bool Accesspoints::internal_check(int num) {
|
||||
}
|
||||
|
||||
void Accesspoints::internal_select(int num) {
|
||||
list->replace(num,AP{list->get(num).id,true});
|
||||
list->replace(num, AP{ list->get(num).id, true });
|
||||
}
|
||||
|
||||
void Accesspoints::internal_deselect(int num) {
|
||||
list->replace(num,AP{list->get(num).id,false});
|
||||
list->replace(num, AP{ list->get(num).id, false });
|
||||
}
|
||||
|
||||
void Accesspoints::internal_remove(int num) {
|
||||
list->remove(num);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ extern String buildString(String left, String right, int maxLen);
|
||||
extern String fixUtf8(String str);
|
||||
extern String bytesToStr(uint8_t* b, uint32_t size);
|
||||
|
||||
struct AP{
|
||||
struct AP {
|
||||
uint8_t id;
|
||||
bool selected;
|
||||
};
|
||||
@@ -63,6 +63,7 @@ class Accesspoints {
|
||||
|
||||
bool check(int num);
|
||||
bool changed = false;
|
||||
|
||||
private:
|
||||
SimpleList<AP>* list;
|
||||
|
||||
@@ -72,7 +73,4 @@ class Accesspoints {
|
||||
void internal_remove(int num);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // ifndef Accesspoints_h
|
||||
44
esp8266_deauther/AnalogRGBLED.cpp
Normal file
44
esp8266_deauther/AnalogRGBLED.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "AnalogRGBLED.h"
|
||||
|
||||
AnalogRGBLED::AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode) {
|
||||
AnalogRGBLED::anode = anode;
|
||||
AnalogRGBLED::rPin = rPin;
|
||||
AnalogRGBLED::gPin = gPin;
|
||||
AnalogRGBLED::bPin = bPin;
|
||||
setBrightness(brightness);
|
||||
}
|
||||
|
||||
AnalogRGBLED::~AnalogRGBLED() {}
|
||||
|
||||
void AnalogRGBLED::setup() {
|
||||
analogWriteRange(0xff);
|
||||
|
||||
if (rPin < 255) pinMode(rPin, OUTPUT);
|
||||
|
||||
if (gPin < 255) pinMode(gPin, OUTPUT);
|
||||
|
||||
if (bPin < 255) pinMode(bPin, OUTPUT);
|
||||
}
|
||||
|
||||
void AnalogRGBLED::setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
if ((r > 0) && (brightness < 100)) r = r * brightness / 100;
|
||||
|
||||
if ((g > 0) && (brightness < 100)) g = g * brightness / 100;
|
||||
|
||||
if ((b > 0) && (brightness < 100)) b = b * brightness / 100;
|
||||
|
||||
if (anode) {
|
||||
r = 255 - r;
|
||||
g = 255 - g;
|
||||
b = 255 - b;
|
||||
}
|
||||
|
||||
analogWrite(rPin, r);
|
||||
analogWrite(gPin, g);
|
||||
analogWrite(bPin, b);
|
||||
}
|
||||
|
||||
void AnalogRGBLED::setBrightness(uint8_t brightness) {
|
||||
if (brightness > 100) brightness = 100;
|
||||
AnalogRGBLED::brightness = brightness;
|
||||
}
|
||||
23
esp8266_deauther/AnalogRGBLED.h
Normal file
23
esp8266_deauther/AnalogRGBLED.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef AnalogRGBLED_H
|
||||
#define AnalogRGBLED_H
|
||||
|
||||
#include "StatusLED.h"
|
||||
|
||||
class AnalogRGBLED : public StatusLED {
|
||||
public:
|
||||
AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode);
|
||||
~AnalogRGBLED();
|
||||
|
||||
void setup();
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
void setBrightness(uint8_t brightness);
|
||||
void setMode(uint8_t mode, bool force);
|
||||
|
||||
private:
|
||||
bool anode = true;
|
||||
uint8_t rPin = 255;
|
||||
uint8_t gPin = 255;
|
||||
uint8_t bPin = 255;
|
||||
uint8_t brightness = 0;
|
||||
};
|
||||
#endif // ifndef AnalogRGBLED_H
|
||||
@@ -37,7 +37,8 @@ void Attack::start(bool beacon, bool deauth, bool deauthAll, bool probe, bool ou
|
||||
Attack::output = output;
|
||||
Attack::timeout = timeout;
|
||||
|
||||
//if (((beacon || probe) && ssids.count() > 0) || (deauthAll && scan.countAll() > 0) || (deauth && scan.countSelected() > 0)){
|
||||
// if (((beacon || probe) && ssids.count() > 0) || (deauthAll && scan.countAll() > 0) || (deauth &&
|
||||
// scan.countSelected() > 0)){
|
||||
if (beacon || probe || deauthAll || deauth) {
|
||||
start();
|
||||
} else {
|
||||
@@ -74,7 +75,7 @@ bool Attack::isRunning() {
|
||||
|
||||
void Attack::updateCounter() {
|
||||
// stop when timeout is active and time is up
|
||||
if (timeout > 0 && currentTime - attackStartTime >= timeout) {
|
||||
if ((timeout > 0) && (currentTime - attackStartTime >= timeout)) {
|
||||
prntln(A_TIMEOUT);
|
||||
stop();
|
||||
return;
|
||||
@@ -82,8 +83,10 @@ void Attack::updateCounter() {
|
||||
|
||||
// deauth packets per second
|
||||
if (deauth.active) {
|
||||
if (deauthAll) deauth.maxPkts = settings.getDeauthsPerTarget() * (accesspoints.count() + stations.count()*2 - names.selected());
|
||||
else deauth.maxPkts = settings.getDeauthsPerTarget() * (accesspoints.selected() + stations.selected()*2 + names.selected() + names.stations());
|
||||
if (deauthAll) deauth.maxPkts = settings.getDeauthsPerTarget() *
|
||||
(accesspoints.count() + stations.count() * 2 - names.selected());
|
||||
else deauth.maxPkts = settings.getDeauthsPerTarget() *
|
||||
(accesspoints.selected() + stations.selected() * 2 + names.selected() + names.stations());
|
||||
} else {
|
||||
deauth.maxPkts = 0;
|
||||
}
|
||||
@@ -91,6 +94,7 @@ void Attack::updateCounter() {
|
||||
// beacon packets per second
|
||||
if (beacon.active) {
|
||||
beacon.maxPkts = ssids.count();
|
||||
|
||||
if (!settings.getBeaconInterval()) beacon.maxPkts *= 10;
|
||||
} else {
|
||||
beacon.maxPkts = 0;
|
||||
@@ -120,15 +124,22 @@ void Attack::updateCounter() {
|
||||
|
||||
void Attack::status() {
|
||||
char s[120];
|
||||
sprintf(s, str(A_STATUS).c_str(), packetRate, deauthPkts, deauth.maxPkts, beaconPkts, beacon.maxPkts, probePkts, probe.maxPkts);
|
||||
|
||||
sprintf(s, str(
|
||||
A_STATUS).c_str(), packetRate, deauthPkts, deauth.maxPkts, beaconPkts, beacon.maxPkts, probePkts,
|
||||
probe.maxPkts);
|
||||
prnt(String(s));
|
||||
}
|
||||
|
||||
String Attack::getStatusJSON() {
|
||||
String json = String(OPEN_BRACKET); // [
|
||||
json += String(OPEN_BRACKET) + b2s(deauth.active) + String(COMMA) + String(scan.countSelected()) + String(COMMA) + String(deauthPkts) + String(COMMA) + String(deauth.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0],
|
||||
json += String(OPEN_BRACKET) + b2s(beacon.active) + String(COMMA) + String(ssids.count()) + String(COMMA) + String(beaconPkts) + String(COMMA) + String(beacon.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0],
|
||||
json += String(OPEN_BRACKET) + b2s(probe.active) + String(COMMA) + String(ssids.count()) + String(COMMA) + String(probePkts) + String(COMMA) + String(probe.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0],
|
||||
|
||||
json += String(OPEN_BRACKET) + b2s(deauth.active) + String(COMMA) + String(scan.countSelected()) + String(COMMA) +
|
||||
String(deauthPkts) + String(COMMA) + String(deauth.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0],
|
||||
json += String(OPEN_BRACKET) + b2s(beacon.active) + String(COMMA) + String(ssids.count()) + String(COMMA) + String(
|
||||
beaconPkts) + String(COMMA) + String(beacon.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0],
|
||||
json += String(OPEN_BRACKET) + b2s(probe.active) + String(COMMA) + String(ssids.count()) + String(COMMA) + String(
|
||||
probePkts) + String(COMMA) + String(probe.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0],
|
||||
json += String(packetRate); // 0
|
||||
json += CLOSE_BRACKET; // ]
|
||||
|
||||
@@ -152,48 +163,49 @@ void Attack::update() {
|
||||
if (currentTime - attackTime > 1000) {
|
||||
attackTime = currentTime; // update time
|
||||
updateCounter();
|
||||
|
||||
if (output) status(); // status update
|
||||
getRandomMac(mac); // generate new random mac
|
||||
}
|
||||
}
|
||||
|
||||
void Attack::deauthUpdate() {
|
||||
if (!deauthAll && deauth.active && deauth.maxPkts > 0 && deauth.packetCounter < deauth.maxPkts) {
|
||||
if (!deauthAll && deauth.active && (deauth.maxPkts > 0) && (deauth.packetCounter < deauth.maxPkts)) {
|
||||
if (deauth.time <= currentTime - (1000 / deauth.maxPkts)) {
|
||||
// APs
|
||||
if (apCount > 0 && deauth.tc < apCount) {
|
||||
if ((apCount > 0) && (deauth.tc < apCount)) {
|
||||
if (accesspoints.getSelected(deauth.tc)) {
|
||||
deauth.tc += deauthAP(deauth.tc);
|
||||
} else deauth.tc++;
|
||||
}
|
||||
|
||||
// Stations
|
||||
else if (stCount > 0 && deauth.tc >= apCount && deauth.tc < stCount + apCount) {
|
||||
else if ((stCount > 0) && (deauth.tc >= apCount) && (deauth.tc < stCount + apCount)) {
|
||||
if (stations.getSelected(deauth.tc - apCount)) {
|
||||
deauth.tc += deauthStation(deauth.tc - apCount);
|
||||
} else deauth.tc++;
|
||||
}
|
||||
|
||||
// Names
|
||||
else if (nCount > 0 && deauth.tc >= apCount + stCount && deauth.tc < nCount + stCount + apCount) {
|
||||
else if ((nCount > 0) && (deauth.tc >= apCount + stCount) && (deauth.tc < nCount + stCount + apCount)) {
|
||||
if (names.getSelected(deauth.tc - stCount - apCount)) {
|
||||
deauth.tc += deauthName(deauth.tc - stCount - apCount);
|
||||
} else deauth.tc++;
|
||||
}
|
||||
|
||||
// reset counter
|
||||
if (deauth.tc >= nCount + stCount + apCount)
|
||||
deauth.tc = 0;
|
||||
if (deauth.tc >= nCount + stCount + apCount) deauth.tc = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Attack::deauthAllUpdate() {
|
||||
if (deauthAll && deauth.active && deauth.maxPkts > 0 && deauth.packetCounter < deauth.maxPkts) {
|
||||
if (deauthAll && deauth.active && (deauth.maxPkts > 0) && (deauth.packetCounter < deauth.maxPkts)) {
|
||||
if (deauth.time <= currentTime - (1000 / deauth.maxPkts)) {
|
||||
// APs
|
||||
if (apCount > 0 && deauth.tc < apCount) {
|
||||
if ((apCount > 0) && (deauth.tc < apCount)) {
|
||||
tmpID = names.findID(accesspoints.getMac(deauth.tc));
|
||||
|
||||
if (tmpID < 0) {
|
||||
deauth.tc += deauthAP(deauth.tc);
|
||||
} else if (!names.getSelected(tmpID)) {
|
||||
@@ -202,8 +214,9 @@ void Attack::deauthAllUpdate() {
|
||||
}
|
||||
|
||||
// Stations
|
||||
else if (stCount > 0 && deauth.tc >= apCount && deauth.tc < stCount + apCount) {
|
||||
else if ((stCount > 0) && (deauth.tc >= apCount) && (deauth.tc < stCount + apCount)) {
|
||||
tmpID = names.findID(stations.getMac(deauth.tc - apCount));
|
||||
|
||||
if (tmpID < 0) {
|
||||
deauth.tc += deauthStation(deauth.tc - apCount);
|
||||
} else if (!names.getSelected(tmpID)) {
|
||||
@@ -212,33 +225,34 @@ void Attack::deauthAllUpdate() {
|
||||
}
|
||||
|
||||
// Names
|
||||
else if (nCount > 0 && deauth.tc >= apCount + stCount && deauth.tc < apCount + stCount + nCount) {
|
||||
else if ((nCount > 0) && (deauth.tc >= apCount + stCount) && (deauth.tc < apCount + stCount + nCount)) {
|
||||
if (!names.getSelected(deauth.tc - apCount - stCount)) {
|
||||
deauth.tc += deauthName(deauth.tc - apCount - stCount);
|
||||
} else deauth.tc++;
|
||||
}
|
||||
|
||||
// reset counter
|
||||
if (deauth.tc >= nCount + stCount + apCount)
|
||||
deauth.tc = 0;
|
||||
if (deauth.tc >= nCount + stCount + apCount) deauth.tc = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Attack::probeUpdate() {
|
||||
if (probe.active && probe.maxPkts > 0 && probe.packetCounter < probe.maxPkts) {
|
||||
if (probe.active && (probe.maxPkts > 0) && (probe.packetCounter < probe.maxPkts)) {
|
||||
if (probe.time <= currentTime - (1000 / probe.maxPkts)) {
|
||||
if (settings.getBeaconChannel()) setWifiChannel(probe.tc % settings.getMaxCh());
|
||||
probe.tc += sendProbe(probe.tc);
|
||||
|
||||
if (probe.tc >= ssids.count()) probe.tc = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Attack:: beaconUpdate() {
|
||||
if (beacon.active && beacon.maxPkts > 0 && beacon.packetCounter < beacon.maxPkts) {
|
||||
void Attack::beaconUpdate() {
|
||||
if (beacon.active && (beacon.maxPkts > 0) && (beacon.packetCounter < beacon.maxPkts)) {
|
||||
if (beacon.time <= currentTime - (1000 / beacon.maxPkts)) {
|
||||
beacon.tc += sendBeacon(beacon.tc);
|
||||
|
||||
if (beacon.tc >= ssids.count()) beacon.tc = 0;
|
||||
}
|
||||
}
|
||||
@@ -263,7 +277,7 @@ bool Attack::deauthName(int num) {
|
||||
bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_t ch) {
|
||||
if (!stMac) return false; // exit when station mac is null
|
||||
|
||||
//Serial.println("Deauthing "+macToStr(apMac)+" -> "+macToStr(stMac)); // for debugging
|
||||
// Serial.println("Deauthing "+macToStr(apMac)+" -> "+macToStr(stMac)); // for debugging
|
||||
|
||||
bool success = false;
|
||||
|
||||
@@ -276,14 +290,16 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
|
||||
|
||||
// send deauth frame
|
||||
deauthPacket[0] = 0xc0;
|
||||
if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())){
|
||||
|
||||
if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) {
|
||||
success = true;
|
||||
deauth.packetCounter++;
|
||||
}
|
||||
|
||||
// send disassociate frame
|
||||
deauthPacket[0] = 0xa0;
|
||||
if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())){
|
||||
|
||||
if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) {
|
||||
success = true;
|
||||
deauth.packetCounter++;
|
||||
}
|
||||
@@ -297,21 +313,22 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
|
||||
|
||||
// send deauth frame
|
||||
deauthPacket[0] = 0xc0;
|
||||
if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())){
|
||||
|
||||
if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) {
|
||||
success = true;
|
||||
deauth.packetCounter++;
|
||||
}
|
||||
|
||||
// send disassociate frame
|
||||
deauthPacket[0] = 0xa0;
|
||||
if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())){
|
||||
|
||||
if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) {
|
||||
success = true;
|
||||
deauth.packetCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
if (success)
|
||||
deauth.time = currentTime;
|
||||
if (success) deauth.time = currentTime;
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -333,7 +350,8 @@ bool Attack::sendBeacon(uint8_t* mac, const char* ssid, uint8_t ch, bool wpa2) {
|
||||
}
|
||||
|
||||
int ssidLen = strlen(ssid);
|
||||
if(ssidLen > 32) ssidLen = 32;
|
||||
|
||||
if (ssidLen > 32) ssidLen = 32;
|
||||
|
||||
memcpy(&beaconPacket[10], mac, 6);
|
||||
memcpy(&beaconPacket[16], mac, 6);
|
||||
@@ -359,7 +377,8 @@ bool Attack::sendProbe(uint8_t tc) {
|
||||
bool Attack::sendProbe(uint8_t* mac, const char* ssid, uint8_t ch) {
|
||||
packetSize = sizeof(probePacket);
|
||||
int ssidLen = strlen(ssid);
|
||||
if(ssidLen > 32) ssidLen = 32;
|
||||
|
||||
if (ssidLen > 32) ssidLen = 32;
|
||||
|
||||
memcpy(&probePacket[10], mac, 6);
|
||||
memcpy(&probePacket[26], ssid, ssidLen);
|
||||
@@ -374,7 +393,7 @@ bool Attack::sendProbe(uint8_t* mac, const char* ssid, uint8_t ch) {
|
||||
}
|
||||
|
||||
bool Attack::sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries) {
|
||||
//Serial.println(bytesToStr(packet, packetSize));
|
||||
// Serial.println(bytesToStr(packet, packetSize));
|
||||
|
||||
// set channel
|
||||
setWifiChannel(ch);
|
||||
@@ -383,11 +402,9 @@ bool Attack::sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16
|
||||
bool sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0;
|
||||
|
||||
// try again until it's sent out
|
||||
for (int i = 0; i < tries && !sent; i++)
|
||||
sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0;
|
||||
for (int i = 0; i < tries && !sent; i++) sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0;
|
||||
|
||||
if(sent)
|
||||
tmpPacketRate ++;
|
||||
if (sent) tmpPacketRate++;
|
||||
|
||||
return sent;
|
||||
}
|
||||
@@ -426,6 +443,6 @@ uint32_t Attack::getProbeMaxPkts() {
|
||||
return probe.maxPkts;
|
||||
}
|
||||
|
||||
uint32_t Attack::getPacketRate(){
|
||||
uint32_t Attack::getPacketRate() {
|
||||
return packetRate;
|
||||
}
|
||||
@@ -29,8 +29,8 @@ extern void setOutputPower(float dBm);
|
||||
extern String macToStr(uint8_t* mac);
|
||||
extern String bytesToStr(uint8_t* b, uint32_t size);
|
||||
extern void setWifiChannel(uint8_t ch);
|
||||
extern bool writeFile(String path, String &buf);
|
||||
extern int8_t free80211_send(uint8_t *buffer, uint16_t len);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern int8_t free80211_send(uint8_t* buffer, uint16_t len);
|
||||
|
||||
class Attack {
|
||||
public:
|
||||
@@ -69,6 +69,7 @@ class Attack {
|
||||
uint32_t getProbeMaxPkts();
|
||||
|
||||
uint32_t getPacketRate();
|
||||
|
||||
private:
|
||||
void deauthUpdate();
|
||||
void deauthAllUpdate();
|
||||
@@ -80,7 +81,7 @@ class Attack {
|
||||
bool running = false;
|
||||
bool output = true;
|
||||
|
||||
struct AttackType{
|
||||
struct AttackType {
|
||||
bool active = false; // if attack is activated
|
||||
uint16_t packetCounter = 0; // how many packets are sent per second
|
||||
uint16_t maxPkts = 0; // how many packets should be sent per second
|
||||
@@ -112,16 +113,16 @@ class Attack {
|
||||
uint32_t timeout = 0;
|
||||
|
||||
// random mac address for making the beacon packets
|
||||
uint8_t mac[6] = {0xAA,0xBB,0xCC,0x00,0x11,0x22};
|
||||
uint8_t mac[6] = { 0xAA, 0xBB, 0xCC, 0x00, 0x11, 0x22 };
|
||||
|
||||
uint8_t deauthPacket[26] = {
|
||||
/* 0 - 1 */ 0xC0, 0x00, //type, subtype c0: deauth (a0: disassociate)
|
||||
/* 2 - 3 */ 0x00, 0x00, //duration (SDK takes care of that)
|
||||
/* 4 - 9 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,//reciever (target)
|
||||
/* 10 - 15 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, //source (ap)
|
||||
/* 16 - 21 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, //BSSID (ap)
|
||||
/* 22 - 23 */ 0x00, 0x00, //fragment & squence number
|
||||
/* 24 - 25 */ 0x01, 0x00 //reason code (1 = unspecified reason)
|
||||
/* 0 - 1 */ 0xC0, 0x00, // type, subtype c0: deauth (a0: disassociate)
|
||||
/* 2 - 3 */ 0x00, 0x00, // duration (SDK takes care of that)
|
||||
/* 4 - 9 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // reciever (target)
|
||||
/* 10 - 15 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, // source (ap)
|
||||
/* 16 - 21 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, // BSSID (ap)
|
||||
/* 22 - 23 */ 0x00, 0x00, // fragment & squence number
|
||||
/* 24 - 25 */ 0x01, 0x00 // reason code (1 = unspecified reason)
|
||||
};
|
||||
|
||||
uint8_t probePacket[68] = {
|
||||
@@ -140,7 +141,7 @@ class Attack {
|
||||
0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20,
|
||||
0x20, 0x20, 0x20, 0x20,
|
||||
/* 58 - 59 */ 0x01, 0x04, //Tag Number: Supported Rates (1), Tag length: 4
|
||||
/* 58 - 59 */ 0x01, 0x04, // Tag Number: Supported Rates (1), Tag length: 4
|
||||
/* 60 */ 0x82, // 1(B)
|
||||
/* 61 */ 0x84, // 2(B)
|
||||
/* 62 */ 0x8b, // 5.5(B)
|
||||
@@ -158,9 +159,11 @@ class Attack {
|
||||
/* 16 - 21 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
|
||||
|
||||
// Fixed parameters
|
||||
/* 22 - 23 */ 0x00, 0x00, // Fragment & sequence number (will be done by the SDK)
|
||||
/* 22 - 23 */ 0x00, 0x00, // Fragment & sequence number (will be done
|
||||
// by the SDK)
|
||||
/* 24 - 31 */ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, // Timestamp
|
||||
/* 32 - 33 */ 0x64, 0x00, // Interval: 0x64, 0x00 => every 100ms - 0xe8, 0x03 => every 1s
|
||||
/* 32 - 33 */ 0x64, 0x00, // Interval: 0x64, 0x00 => every 100ms -
|
||||
// 0xe8, 0x03 => every 1s
|
||||
/* 34 - 35 */ 0x31, 0x00, // capabilities Tnformation
|
||||
|
||||
// Tagged parameters
|
||||
@@ -203,8 +206,4 @@ class Attack {
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // ifndef Attack_h
|
||||
@@ -1,111 +1,36 @@
|
||||
#include "DigitalLed.h"
|
||||
|
||||
DigitalLed::DigitalLed() {
|
||||
#include "DigitalLED.h"
|
||||
|
||||
DigitalLED::DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode) {
|
||||
DigitalLED::anode = anode;
|
||||
DigitalLED::rPin = rPin;
|
||||
DigitalLED::gPin = gPin;
|
||||
DigitalLED::bPin = bPin;
|
||||
}
|
||||
|
||||
// setup pins
|
||||
void DigitalLed::setup(){
|
||||
if(!settings.getLedEnabled()) return;
|
||||
DigitalLED::~DigitalLED() {}
|
||||
|
||||
// ===== adjustable ===== //
|
||||
if(LED_ENABLE_R) pinMode(LED_PIN_R, OUTPUT);
|
||||
if(LED_ENABLE_G) pinMode(LED_PIN_G, OUTPUT);
|
||||
if(LED_ENABLE_B) pinMode(LED_PIN_B, OUTPUT);
|
||||
// ====================== //
|
||||
void DigitalLED::setup() {
|
||||
if (rPin < 255) pinMode(rPin, OUTPUT);
|
||||
|
||||
setMode(LED_MODE_OFF, true);
|
||||
if (gPin < 255) pinMode(gPin, OUTPUT);
|
||||
|
||||
if (bPin < 255) pinMode(bPin, OUTPUT);
|
||||
}
|
||||
|
||||
void DigitalLed::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output) {
|
||||
// debug output
|
||||
if (output){
|
||||
char s[30];
|
||||
sprintf(s,str(L_OUTPUT_A).c_str(), r, g, b);
|
||||
prnt(String(s));
|
||||
}
|
||||
void DigitalLED::setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
if (anode) {
|
||||
if (rPin < 255) digitalWrite(rPin, r > 0);
|
||||
|
||||
// ===== adjustable ===== //
|
||||
if(LED_CATHODE){
|
||||
r = r>0;
|
||||
g = g>0;
|
||||
b = b>0;
|
||||
}else{
|
||||
r = !(r>0);
|
||||
g = !(g>0);
|
||||
b = !(b>0);
|
||||
}
|
||||
if (gPin < 255) digitalWrite(gPin, g > 0);
|
||||
|
||||
if(LED_ENABLE_R) digitalWrite(LED_PIN_R, r);
|
||||
if(LED_ENABLE_G) digitalWrite(LED_PIN_G, g);
|
||||
if(LED_ENABLE_B) digitalWrite(LED_PIN_B, b);
|
||||
// ====================== //
|
||||
if (bPin < 255) digitalWrite(bPin, b > 0);
|
||||
} else {
|
||||
if (rPin < 255) digitalWrite(rPin, r == 0);
|
||||
|
||||
// debug output
|
||||
if (output){
|
||||
char s[30];
|
||||
sprintf(s,str(L_OUTPUT_B).c_str(), r?255:0, g?255:0, b?255:0);
|
||||
prnt(String(s));
|
||||
if (gPin < 255) digitalWrite(gPin, g == 0);
|
||||
|
||||
if (bPin < 255) digitalWrite(bPin, b == 0);
|
||||
}
|
||||
}
|
||||
|
||||
// customize color codes for different LED modes
|
||||
void DigitalLed::setMode(uint8_t mode, bool force) {
|
||||
// ===== adjustable ===== //
|
||||
if (mode != DigitalLed::mode || force) {
|
||||
DigitalLed::mode = mode;
|
||||
switch (mode) {
|
||||
case LED_MODE_OFF:
|
||||
setColor(0, 0, 0, 100, false);
|
||||
break;
|
||||
case LED_MODE_SCAN:
|
||||
setColor(0, 0, 255, 100, false);
|
||||
break;
|
||||
case LED_MODE_ATTACK:
|
||||
setColor(255, 255, 0, 100, false);
|
||||
break;
|
||||
case LED_MODE_DEAUTH:
|
||||
setColor(255, 0, 0, 100, false);
|
||||
break;
|
||||
case LED_MODE_IDLE:
|
||||
setColor(0, 255, 0, 100, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// ====================== //
|
||||
}
|
||||
|
||||
void DigitalLed::tempEnable() {
|
||||
tempEnabled = true;
|
||||
prntln(L_ENABLED);
|
||||
}
|
||||
|
||||
void DigitalLed::tempDisable() {
|
||||
tempEnabled = false;
|
||||
prntln(L_DISABLED);
|
||||
}
|
||||
|
||||
bool DigitalLed::getTempEnabled() {
|
||||
return tempEnabled;
|
||||
}
|
||||
|
||||
void DigitalLed::setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
setColor(r, g, b, 100, true);
|
||||
}
|
||||
|
||||
void DigitalLed::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness) {
|
||||
setColor(r, g, b, brightness, true);
|
||||
}
|
||||
|
||||
void DigitalLed::update() {
|
||||
if (!tempEnabled) return;
|
||||
if (!settings.getLedEnabled() && tempEnabled) tempDisable();
|
||||
|
||||
if (scan.isScanning() && scan.deauths < settings.getMinDeauths()) setMode(LED_MODE_SCAN, false);
|
||||
else if (scan.deauths >= settings.getMinDeauths()) setMode(LED_MODE_DEAUTH, false);
|
||||
else if (attack.isRunning()) setMode(LED_MODE_ATTACK, false);
|
||||
else setMode(LED_MODE_IDLE, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DigitalLED::setBrightness(uint8_t brightness) {}
|
||||
@@ -1,45 +1,23 @@
|
||||
#ifndef DigitalLed_h
|
||||
#define DigitalLed_h
|
||||
#ifndef DigitalLED_H
|
||||
#define DigitalLED_H
|
||||
|
||||
#include "Arduino.h"
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "language.h"
|
||||
#include "A_config.h"
|
||||
#include "Settings.h"
|
||||
#include "Attack.h"
|
||||
#include "Scan.h"
|
||||
#include "StatusLED.h"
|
||||
|
||||
#define LED_MODE_OFF 0
|
||||
#define LED_MODE_SCAN 1
|
||||
#define LED_MODE_ATTACK 2
|
||||
#define LED_MODE_DEAUTH 3
|
||||
#define LED_MODE_IDLE 4
|
||||
|
||||
extern Settings settings;
|
||||
extern Attack attack;
|
||||
extern Scan scan;
|
||||
extern Stations stations;
|
||||
|
||||
class DigitalLed {
|
||||
class DigitalLED : public StatusLED {
|
||||
public:
|
||||
DigitalLed();
|
||||
DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode);
|
||||
~DigitalLED();
|
||||
|
||||
void setup();
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness);
|
||||
void setBrightness(uint8_t brightness);
|
||||
void setMode(uint8_t mode, bool force);
|
||||
void update();
|
||||
void tempEnable();
|
||||
void tempDisable();
|
||||
bool getTempEnabled();
|
||||
|
||||
private:
|
||||
uint8_t mode;
|
||||
bool tempEnabled = true;
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output);
|
||||
bool anode = true;
|
||||
uint8_t rPin = 255;
|
||||
uint8_t gPin = 255;
|
||||
uint8_t bPin = 255;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // ifndef DigitalLED_H
|
||||
@@ -1,13 +1,12 @@
|
||||
#include "DisplayUI.h"
|
||||
|
||||
DisplayUI::DisplayUI() {
|
||||
|
||||
}
|
||||
DisplayUI::DisplayUI() {}
|
||||
|
||||
void DisplayUI::setupDisplay() {
|
||||
// ===== adjustable ===== //
|
||||
// initialize display
|
||||
display.init();
|
||||
|
||||
/*
|
||||
In case of a compiler (conversion char/uint8_t) error,
|
||||
make sure to have version 4 of the display library installed
|
||||
@@ -17,7 +16,7 @@ void DisplayUI::setupDisplay() {
|
||||
display.setContrast(255);
|
||||
#ifndef FLIP_DIPLAY
|
||||
display.flipScreenVertically();
|
||||
#endif
|
||||
#endif // ifndef FLIP_DIPLAY
|
||||
display.clear();
|
||||
display.display();
|
||||
// ====================== //
|
||||
@@ -54,44 +53,44 @@ void DisplayUI::setupButtons() {
|
||||
#ifdef BUTTON_UP
|
||||
buttonUp.enabled = true;
|
||||
buttonUp.gpio = BUTTON_UP;
|
||||
#else
|
||||
#else // ifdef BUTTON_UP
|
||||
buttonUp.enabled = false;
|
||||
#endif
|
||||
#endif // ifdef BUTTON_UP
|
||||
|
||||
#ifdef BUTTON_DOWN
|
||||
buttonDown.enabled = true;
|
||||
buttonDown.gpio = BUTTON_DOWN;
|
||||
#else
|
||||
#else // ifdef BUTTON_DOWN
|
||||
buttonDown.enabled = false;
|
||||
#endif
|
||||
#endif // ifdef BUTTON_DOWN
|
||||
|
||||
#ifdef BUTTON_LEFT
|
||||
buttonLeft.enabled = true;
|
||||
buttonLeft.gpio = BUTTON_LEFT;
|
||||
#else
|
||||
#else // ifdef BUTTON_LEFT
|
||||
buttonLeft.enabled = false;
|
||||
#endif
|
||||
#endif // ifdef BUTTON_LEFT
|
||||
|
||||
#ifdef BUTTON_RIGHT
|
||||
buttonRight.enabled = true;
|
||||
buttonRight.gpio = BUTTON_RIGHT;
|
||||
#else
|
||||
#else // ifdef BUTTON_RIGHT
|
||||
buttonRight.enabled = false;
|
||||
#endif
|
||||
#endif // ifdef BUTTON_RIGHT
|
||||
|
||||
#ifdef BUTTON_A
|
||||
buttonA.enabled = true;
|
||||
buttonA.gpio = BUTTON_A;
|
||||
#else
|
||||
#else // ifdef BUTTON_A
|
||||
buttonA.enabled = false;
|
||||
#endif
|
||||
#endif // ifdef BUTTON_A
|
||||
|
||||
#ifdef BUTTON_B
|
||||
buttonB.enabled = true;
|
||||
buttonB.gpio = BUTTON_B;
|
||||
#else
|
||||
#else // ifdef BUTTON_B
|
||||
buttonB.enabled = false;
|
||||
#endif
|
||||
#endif // ifdef BUTTON_B
|
||||
|
||||
// ====================== //
|
||||
// setup and read functions
|
||||
@@ -137,7 +136,7 @@ void DisplayUI::setupButtons() {
|
||||
};
|
||||
|
||||
buttonB.setup = [this]() {
|
||||
if (buttonB.gpio != 2 ) pinMode(buttonB.gpio, INPUT_PULLUP);
|
||||
if (buttonB.gpio != 2) pinMode(buttonB.gpio, INPUT_PULLUP);
|
||||
buttonB.time = currentTime;
|
||||
};
|
||||
buttonB.read = [this]() {
|
||||
@@ -155,7 +154,8 @@ void DisplayUI::setup() {
|
||||
|
||||
// === BUTTON UP === //
|
||||
buttonUp.push = [this]() {
|
||||
if(buttonUp.time > currentTime - BUTTON_DELAY) return;
|
||||
if (buttonUp.time > currentTime - BUTTON_DELAY) return;
|
||||
|
||||
buttonUp.pushed = true;
|
||||
buttonUp.time = currentTime;
|
||||
scrollCounter = 0;
|
||||
@@ -170,12 +170,14 @@ void DisplayUI::setup() {
|
||||
|
||||
buttonUp.release = [this]() {
|
||||
if (!buttonUp.pushed) return;
|
||||
|
||||
buttonUp.pushed = false;
|
||||
};
|
||||
|
||||
// === BUTTON DOWN === //
|
||||
buttonDown.push = [this]() {
|
||||
if(buttonDown.time > currentTime - BUTTON_DELAY) return;
|
||||
if (buttonDown.time > currentTime - BUTTON_DELAY) return;
|
||||
|
||||
buttonDown.pushed = true;
|
||||
buttonDown.time = currentTime;
|
||||
scrollCounter = 0;
|
||||
@@ -190,12 +192,14 @@ void DisplayUI::setup() {
|
||||
|
||||
buttonDown.release = [this]() {
|
||||
if (!buttonDown.pushed) return;
|
||||
|
||||
buttonDown.pushed = false;
|
||||
};
|
||||
|
||||
// === BUTTON LEFT === //
|
||||
buttonLeft.push = [this]() {
|
||||
if(buttonLeft.time > currentTime - BUTTON_DELAY) return;
|
||||
if (buttonLeft.time > currentTime - BUTTON_DELAY) return;
|
||||
|
||||
buttonLeft.pushed = true;
|
||||
buttonLeft.time = currentTime;
|
||||
scrollCounter = 0;
|
||||
@@ -203,12 +207,14 @@ void DisplayUI::setup() {
|
||||
|
||||
buttonLeft.release = [this]() {
|
||||
if (!buttonLeft.pushed) return;
|
||||
|
||||
buttonLeft.pushed = false;
|
||||
};
|
||||
|
||||
// === BUTTON RIGHT === //
|
||||
buttonRight.push = [this]() {
|
||||
if(buttonRight.time > currentTime - BUTTON_DELAY) return;
|
||||
if (buttonRight.time > currentTime - BUTTON_DELAY) return;
|
||||
|
||||
buttonRight.pushed = true;
|
||||
buttonRight.time = currentTime;
|
||||
scrollCounter = 0;
|
||||
@@ -216,18 +222,20 @@ void DisplayUI::setup() {
|
||||
|
||||
buttonRight.release = [this]() {
|
||||
if (!buttonRight.pushed) return;
|
||||
|
||||
buttonRight.pushed = false;
|
||||
};
|
||||
|
||||
// === BUTTON A === //
|
||||
buttonA.push = [this]() {
|
||||
if(!buttonA.pushed){ // first push
|
||||
if (!buttonA.pushed) { // first push
|
||||
buttonA.pushed = true;
|
||||
buttonA.time = currentTime;
|
||||
scrollCounter = 0;
|
||||
}else{ // holding button
|
||||
if(currentTime - buttonA.time > 800 && !buttonA.hold){
|
||||
if(currentMenu->list->get(currentMenu->selected).hold) currentMenu->list->get(currentMenu->selected).hold();
|
||||
} else { // holding button
|
||||
if ((currentTime - buttonA.time > 800) && !buttonA.hold) {
|
||||
if (currentMenu->list->get(currentMenu->selected).hold) currentMenu->list->get(
|
||||
currentMenu->selected).hold();
|
||||
buttonA.hold = true;
|
||||
}
|
||||
}
|
||||
@@ -236,13 +244,15 @@ void DisplayUI::setup() {
|
||||
buttonA.release = [this]() {
|
||||
if (!buttonA.pushed) return; // exit when button wasn't pushed before
|
||||
|
||||
if(!buttonA.hold && currentTime - buttonA.time > 80){
|
||||
switch(mode){
|
||||
if (!buttonA.hold && (currentTime - buttonA.time > 80)) {
|
||||
switch (mode) {
|
||||
case SCREEN_MODE_MENU:
|
||||
if( currentMenu->list->get(currentMenu->selected).click){
|
||||
|
||||
if (currentMenu->list->get(currentMenu->selected).click) {
|
||||
currentMenu->list->get(currentMenu->selected).click();
|
||||
}
|
||||
break;
|
||||
|
||||
case SCREEN_MODE_PACKETMONITOR:
|
||||
case SCREEN_MODE_LOADSCAN:
|
||||
scan.stop();
|
||||
@@ -257,7 +267,8 @@ void DisplayUI::setup() {
|
||||
|
||||
// === BUTTON B === //
|
||||
buttonB.push = [this]() {
|
||||
if(!buttonB.pushed && buttonB.time > currentTime - BUTTON_DELAY) return;
|
||||
if (!buttonB.pushed && (buttonB.time > currentTime - BUTTON_DELAY)) return;
|
||||
|
||||
buttonB.pushed = true;
|
||||
buttonB.time = currentTime;
|
||||
scrollCounter = 0;
|
||||
@@ -266,10 +277,11 @@ void DisplayUI::setup() {
|
||||
buttonB.release = [this]() {
|
||||
if (!buttonB.pushed) return;
|
||||
|
||||
switch(mode){
|
||||
switch (mode) {
|
||||
case SCREEN_MODE_MENU:
|
||||
goBack();
|
||||
break;
|
||||
|
||||
case SCREEN_MODE_PACKETMONITOR:
|
||||
case SCREEN_MODE_LOADSCAN:
|
||||
scan.stop();
|
||||
@@ -283,10 +295,15 @@ void DisplayUI::setup() {
|
||||
// === RUN SETUPS === //
|
||||
// setting pin modes for buttons
|
||||
if (buttonUp.enabled && buttonUp.setup) buttonUp.setup();
|
||||
|
||||
if (buttonDown.enabled && buttonDown.setup) buttonDown.setup();
|
||||
|
||||
if (buttonLeft.enabled && buttonLeft.setup) buttonLeft.setup();
|
||||
|
||||
if (buttonRight.enabled && buttonRight.setup) buttonRight.setup();
|
||||
|
||||
if (buttonA.enabled && buttonA.setup) buttonA.setup();
|
||||
|
||||
if (buttonB.enabled && buttonB.setup) buttonB.setup();
|
||||
|
||||
// ===== MENUS ===== //
|
||||
@@ -321,16 +338,16 @@ void DisplayUI::setup() {
|
||||
// SHOW MENU
|
||||
createMenu(&showMenu, &mainMenu, [this]() {
|
||||
addMenuNode(&showMenu, []() { // Accesspoints 0 [0]
|
||||
return buildString(str(D_ACCESSPOINTS),(String)accesspoints.count(),CHARS_PER_LINE);
|
||||
return buildString(str(D_ACCESSPOINTS), (String)accesspoints.count(), CHARS_PER_LINE);
|
||||
}, &apListMenu);
|
||||
addMenuNode(&showMenu, []() { // Stations 0 [0]
|
||||
return buildString(str(D_STATIONS),(String)stations.count(),CHARS_PER_LINE);
|
||||
return buildString(str(D_STATIONS), (String)stations.count(), CHARS_PER_LINE);
|
||||
}, &stationListMenu);
|
||||
addMenuNode(&showMenu, []() { // Names 0 [0]
|
||||
return buildString(str(D_NAMES),(String)names.count(),CHARS_PER_LINE);
|
||||
return buildString(str(D_NAMES), (String)names.count(), CHARS_PER_LINE);
|
||||
}, &nameListMenu);
|
||||
addMenuNode(&showMenu, []() { // SSIDs 0
|
||||
return buildString(str(D_SSIDS),(String)ssids.count(),CHARS_PER_LINE);
|
||||
return buildString(str(D_SSIDS), (String)ssids.count(), CHARS_PER_LINE);
|
||||
}, &ssidListMenu);
|
||||
});
|
||||
|
||||
@@ -338,12 +355,13 @@ void DisplayUI::setup() {
|
||||
createMenu(&apListMenu, &showMenu, [this]() {
|
||||
// add APs to list
|
||||
int c = accesspoints.count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
addMenuNode(&apListMenu, [i]() {
|
||||
return b2a(accesspoints.getSelected(i)) + accesspoints.getSSID(i);
|
||||
}, [this, i]() {
|
||||
accesspoints.getSelected(i) ? accesspoints.deselect(i) : accesspoints.select(i);
|
||||
}, [this, i](){
|
||||
}, [this, i]() {
|
||||
selectedID = i;
|
||||
changeMenu(&apMenu);
|
||||
});
|
||||
@@ -366,9 +384,11 @@ void DisplayUI::setup() {
|
||||
createMenu(&stationListMenu, &showMenu, [this]() {
|
||||
// add stations to list
|
||||
int c = stations.count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
addMenuNode(&stationListMenu, [i]() {
|
||||
return b2a(stations.getSelected(i)) + (stations.hasName(i) ? stations.getNameStr(i) : stations.getMacVendorStr(i));
|
||||
return b2a(stations.getSelected(i)) +
|
||||
(stations.hasName(i) ? stations.getNameStr(i) : stations.getMacVendorStr(i));
|
||||
}, [this, i]() {
|
||||
stations.getSelected(i) ? stations.deselect(i) : stations.select(i);
|
||||
}, [this, i]() {
|
||||
@@ -395,6 +415,7 @@ void DisplayUI::setup() {
|
||||
createMenu(&nameListMenu, &showMenu, [this]() {
|
||||
// add device names to list
|
||||
int c = names.count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
addMenuNode(&nameListMenu, [i]() {
|
||||
return names.getSelectedStr(i) + names.getName(i);
|
||||
@@ -426,16 +447,17 @@ void DisplayUI::setup() {
|
||||
changeMenu(&ssidListMenu);
|
||||
ssids.save(false);
|
||||
});
|
||||
addMenuNode(&ssidListMenu, [this](){
|
||||
addMenuNode(&ssidListMenu, [this]() {
|
||||
return b2a(ssids.getRandom()) + str(D_RANDOM_MODE); // *RANDOM MODE
|
||||
}, [this]() {
|
||||
if(ssids.getRandom()) ssids.disableRandom();
|
||||
if (ssids.getRandom()) ssids.disableRandom();
|
||||
else ssids.enableRandom(10);
|
||||
changeMenu(&ssidListMenu);
|
||||
});
|
||||
|
||||
// add ssids to list
|
||||
int c = ssids.count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
addMenuNode(&ssidListMenu, [i]() {
|
||||
return ssids.getName(i).substring(0, ssids.getLen(i));
|
||||
@@ -497,7 +519,9 @@ void DisplayUI::setup() {
|
||||
// STATION MENU
|
||||
createMenu(&stationMenu, &stationListMenu, [this]() {
|
||||
addMenuNode(&stationMenu, [this]() {
|
||||
return stations.getSelectedStr(selectedID) + (stations.hasName(selectedID) ? stations.getNameStr(selectedID) : stations.getMacVendorStr(selectedID)); // <station name>
|
||||
return stations.getSelectedStr(selectedID) +
|
||||
(stations.hasName(selectedID) ? stations.getNameStr(selectedID) : stations.getMacVendorStr(selectedID)); // <station
|
||||
// name>
|
||||
}, [this]() {
|
||||
stations.getSelected(selectedID) ? stations.deselect(selectedID) : stations.select(selectedID);
|
||||
});
|
||||
@@ -511,7 +535,8 @@ void DisplayUI::setup() {
|
||||
return str(D_AP) + stations.getAPStr(selectedID); // AP: someAP
|
||||
}, [this]() {
|
||||
int apID = accesspoints.find(stations.getAP(selectedID));
|
||||
if(apID >= 0){
|
||||
|
||||
if (apID >= 0) {
|
||||
selectedID = apID;
|
||||
changeMenu(&apMenu);
|
||||
}
|
||||
@@ -573,7 +598,7 @@ void DisplayUI::setup() {
|
||||
// SSID MENU
|
||||
createMenu(&ssidMenu, &ssidListMenu, [this]() {
|
||||
addMenuNode(&ssidMenu, [this]() {
|
||||
return ssids.getName(selectedID).substring(0,ssids.getLen(selectedID));
|
||||
return ssids.getName(selectedID).substring(0, ssids.getLen(selectedID));
|
||||
}, NULL); // SSID
|
||||
addMenuNode(&ssidMenu, [this]() {
|
||||
return str(D_ENCRYPTION) + ssids.getEncStr(selectedID); // WPA2
|
||||
@@ -590,37 +615,51 @@ void DisplayUI::setup() {
|
||||
// ATTACK MENU
|
||||
createMenu(&attackMenu, &mainMenu, [this]() {
|
||||
addMenuNode(&attackMenu, [this]() { // *DEAUTH 0/0
|
||||
if(attack.isRunning()) return buildString(b2a(deauthSelected) + str(D_DEAUTH), (String)attack.getDeauthPkts() + SLASH + (String)attack.getDeauthMaxPkts(), CHARS_PER_LINE);
|
||||
else return buildString(b2a(deauthSelected) + str(D_DEAUTH) , (String)scan.countSelected(), CHARS_PER_LINE);
|
||||
if (attack.isRunning()) return buildString(b2a(deauthSelected) + str(D_DEAUTH),
|
||||
(String)attack.getDeauthPkts() + SLASH +
|
||||
(String)attack.getDeauthMaxPkts(), CHARS_PER_LINE);
|
||||
else return buildString(b2a(deauthSelected) + str(D_DEAUTH), (String)scan.countSelected(), CHARS_PER_LINE);
|
||||
}, [this]() { // deauth
|
||||
deauthSelected = !deauthSelected;
|
||||
|
||||
if (attack.isRunning()) {
|
||||
attack.start(beaconSelected, deauthSelected, false, probeSelected, true, settings.getAttackTimeout() * 1000);
|
||||
attack.start(beaconSelected, deauthSelected, false, probeSelected, true,
|
||||
settings.getAttackTimeout() * 1000);
|
||||
}
|
||||
});
|
||||
addMenuNode(&attackMenu, [this]() { // *BEACON 0/0
|
||||
if(attack.isRunning()) return buildString(b2a(beaconSelected) + str(D_BEACON), (String)attack.getBeaconPkts() + SLASH + (String)attack.getBeaconMaxPkts(), CHARS_PER_LINE);
|
||||
if (attack.isRunning()) return buildString(b2a(beaconSelected) + str(D_BEACON),
|
||||
(String)attack.getBeaconPkts() + SLASH +
|
||||
(String)attack.getBeaconMaxPkts(), CHARS_PER_LINE);
|
||||
else return buildString(b2a(beaconSelected) + str(D_BEACON), (String)ssids.count(), CHARS_PER_LINE);
|
||||
}, [this]() { // beacon
|
||||
beaconSelected = !beaconSelected;
|
||||
|
||||
if (attack.isRunning()) {
|
||||
attack.start(beaconSelected, deauthSelected, false, probeSelected, true, settings.getAttackTimeout() * 1000);
|
||||
attack.start(beaconSelected, deauthSelected, false, probeSelected, true,
|
||||
settings.getAttackTimeout() * 1000);
|
||||
}
|
||||
});
|
||||
addMenuNode(&attackMenu, [this]() { // *PROBE 0/0
|
||||
if(attack.isRunning()) return buildString(b2a(probeSelected) + str(D_PROBE), (String)attack.getProbePkts() + SLASH + (String)attack.getProbeMaxPkts(), CHARS_PER_LINE);
|
||||
if (attack.isRunning()) return buildString(b2a(probeSelected) + str(D_PROBE),
|
||||
(String)attack.getProbePkts() + SLASH +
|
||||
(String)attack.getProbeMaxPkts(), CHARS_PER_LINE);
|
||||
else return buildString(b2a(probeSelected) + str(D_PROBE), (String)ssids.count(), CHARS_PER_LINE);
|
||||
}, [this]() { // probe
|
||||
probeSelected = !probeSelected;
|
||||
|
||||
if (attack.isRunning()) {
|
||||
attack.start(beaconSelected, deauthSelected, false, probeSelected, true, settings.getAttackTimeout() * 1000);
|
||||
attack.start(beaconSelected, deauthSelected, false, probeSelected, true,
|
||||
settings.getAttackTimeout() * 1000);
|
||||
}
|
||||
});
|
||||
addMenuNode(&attackMenu, []() { // START
|
||||
return buildString(str(attack.isRunning() ? D_STOP_ATTACK : D_START_ATTACK), attack.getPacketRate() > 0 ? (String)attack.getPacketRate() : String(), CHARS_PER_LINE);
|
||||
return buildString(str(attack.isRunning() ? D_STOP_ATTACK : D_START_ATTACK),
|
||||
attack.getPacketRate() > 0 ? (String)attack.getPacketRate() : String(), CHARS_PER_LINE);
|
||||
}, [this]() {
|
||||
if (attack.isRunning()) attack.stop();
|
||||
else attack.start(beaconSelected, deauthSelected, false, probeSelected, true, settings.getAttackTimeout() * 1000);
|
||||
else attack.start(beaconSelected, deauthSelected, false, probeSelected, true,
|
||||
settings.getAttackTimeout() * 1000);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -637,7 +676,7 @@ void DisplayUI::update() {
|
||||
|
||||
// when display is off
|
||||
if (mode == SCREEN_MODE_OFF) {
|
||||
if (updateButton(&buttonA)){
|
||||
if (updateButton(&buttonA)) {
|
||||
on();
|
||||
buttonA.hold = true; // to make sure you don't double click
|
||||
}
|
||||
@@ -645,14 +684,16 @@ void DisplayUI::update() {
|
||||
|
||||
else {
|
||||
// timeout to save display life
|
||||
if (mode == SCREEN_MODE_MENU && settings.getDisplayTimeout() > 0 && currentTime > settings.getDisplayTimeout() * 1000) {
|
||||
if ((mode == SCREEN_MODE_MENU) && (settings.getDisplayTimeout() > 0) &&
|
||||
(currentTime > settings.getDisplayTimeout() * 1000)) {
|
||||
uint32_t buttonTimeout = currentTime - settings.getDisplayTimeout() * 1000;
|
||||
if (buttonUp.time < buttonTimeout
|
||||
&& buttonDown.time < buttonTimeout
|
||||
&& buttonLeft.time < buttonTimeout
|
||||
&& buttonRight.time < buttonTimeout
|
||||
&& buttonA.time < buttonTimeout
|
||||
&& buttonB.time < buttonTimeout) {
|
||||
|
||||
if ((buttonUp.time < buttonTimeout)
|
||||
&& (buttonDown.time < buttonTimeout)
|
||||
&& (buttonLeft.time < buttonTimeout)
|
||||
&& (buttonRight.time < buttonTimeout)
|
||||
&& (buttonA.time < buttonTimeout)
|
||||
&& (buttonB.time < buttonTimeout)) {
|
||||
off();
|
||||
}
|
||||
}
|
||||
@@ -669,7 +710,7 @@ void DisplayUI::update() {
|
||||
}
|
||||
|
||||
void DisplayUI::draw() {
|
||||
if (currentTime - drawTime > DRAW_INTERVAL && currentMenu) {
|
||||
if ((currentTime - drawTime > DRAW_INTERVAL) && currentMenu) {
|
||||
drawTime = currentTime;
|
||||
|
||||
// ===== adjustable ===== //
|
||||
@@ -681,17 +722,22 @@ void DisplayUI::draw() {
|
||||
case SCREEN_MODE_BUTTON_TEST:
|
||||
drawButtonTest();
|
||||
break;
|
||||
|
||||
case SCREEN_MODE_MENU:
|
||||
drawMenu();
|
||||
break;
|
||||
|
||||
case SCREEN_MODE_LOADSCAN:
|
||||
drawLoadingScan();
|
||||
break;
|
||||
|
||||
case SCREEN_MODE_PACKETMONITOR:
|
||||
drawPacketMonitor();
|
||||
break;
|
||||
|
||||
case SCREEN_MODE_INTRO:
|
||||
if(currentTime - startTime >= SCREEN_INTRO_TIME){
|
||||
|
||||
if (currentTime - startTime >= SCREEN_INTRO_TIME) {
|
||||
mode = SCREEN_MODE_MENU;
|
||||
}
|
||||
drawIntro();
|
||||
@@ -706,18 +752,23 @@ void DisplayUI::draw() {
|
||||
|
||||
void DisplayUI::drawString(int x, int y, String str) {
|
||||
// ===== adjustable ===== //
|
||||
display.drawString(x, y, replaceUtf8(str,String(QUESTIONMARK)));
|
||||
display.drawString(x, y, replaceUtf8(str, String(QUESTIONMARK)));
|
||||
// ====================== //
|
||||
}
|
||||
|
||||
void DisplayUI::drawButtonTest() {
|
||||
// ===== adjustable ===== //
|
||||
if(buttonUp.enabled) display.drawString(0, 0, str(D_UP) + b2s(buttonUp.pushed));
|
||||
if(buttonDown.enabled) display.drawString(0, 9, str(D_DOWN) + b2s(buttonDown.pushed));
|
||||
if(buttonLeft.enabled) display.drawString(0, 18, str(D_LEFT) + b2s(buttonLeft.pushed));
|
||||
if(buttonRight.enabled) display.drawString(0, 27, str(D_RIGHT) + b2s(buttonRight.pushed));
|
||||
if(buttonA.enabled) display.drawString(0, 36, str(D_A) + b2s(buttonA.pushed));
|
||||
if(buttonB.enabled) display.drawString(0, 45, str(D_B) + b2s(buttonB.pushed));
|
||||
if (buttonUp.enabled) display.drawString(0, 0, str(D_UP) + b2s(buttonUp.pushed));
|
||||
|
||||
if (buttonDown.enabled) display.drawString(0, 9, str(D_DOWN) + b2s(buttonDown.pushed));
|
||||
|
||||
if (buttonLeft.enabled) display.drawString(0, 18, str(D_LEFT) + b2s(buttonLeft.pushed));
|
||||
|
||||
if (buttonRight.enabled) display.drawString(0, 27, str(D_RIGHT) + b2s(buttonRight.pushed));
|
||||
|
||||
if (buttonA.enabled) display.drawString(0, 36, str(D_A) + b2s(buttonA.pushed));
|
||||
|
||||
if (buttonB.enabled) display.drawString(0, 45, str(D_B) + b2s(buttonB.pushed));
|
||||
// ====================== //
|
||||
}
|
||||
|
||||
@@ -736,9 +787,10 @@ void DisplayUI::drawMenu() {
|
||||
tmpLen = tmp.length();
|
||||
|
||||
// horizontal scrolling
|
||||
if (currentMenu->selected == i && tmpLen > CHARS_PER_LINE) {
|
||||
if ((currentMenu->selected == i) && (tmpLen > CHARS_PER_LINE)) {
|
||||
tmp = tmp.substring(scrollCounter / SCROLL_SPEED);
|
||||
scrollCounter++;
|
||||
|
||||
if (scrollCounter / SCROLL_SPEED > tmpLen - CHARS_PER_LINE) scrollCounter = 0;
|
||||
}
|
||||
|
||||
@@ -750,12 +802,14 @@ void DisplayUI::drawMenu() {
|
||||
void DisplayUI::drawLoadingScan() {
|
||||
// ===== adjustable ===== //
|
||||
if (scan.isScanning()) {
|
||||
if(scan.isSniffing()){ // Scanning for Stations
|
||||
display.drawString(2, 0, buildString(str(D_LOADING_SCREEN_0), (String)scan.getPercentage() + PERCENT, CHARS_PER_LINE));
|
||||
if (scan.isSniffing()) { // Scanning for Stations
|
||||
display.drawString(2, 0,
|
||||
buildString(str(D_LOADING_SCREEN_0), (String)scan.getPercentage() + PERCENT,
|
||||
CHARS_PER_LINE));
|
||||
display.drawProgressBar(5, 22, 118, 8, scan.getPercentage());
|
||||
display.drawString(2, 36, str(D_LOADING_SCREEN_1) + (String)accesspoints.count());
|
||||
display.drawString(2, 50, str(D_LOADING_SCREEN_2) + (String)stations.count());
|
||||
}else{ // Scanning for APs
|
||||
} else { // Scanning for APs
|
||||
display.drawString(2, 10, str(D_LOADING_SCREEN_3));
|
||||
display.drawString(2, 24, str(D_LOADING_SCREEN_4));
|
||||
}
|
||||
@@ -769,21 +823,23 @@ void DisplayUI::drawLoadingScan() {
|
||||
void DisplayUI::drawPacketMonitor() {
|
||||
// ===== adjustable ===== //
|
||||
double scale = scan.getScaleFactor(50);
|
||||
|
||||
display.drawString(0, 0, str(D_CH) + String(wifi_channel));
|
||||
display.drawString(40, 0, str(D_PKTS) + String(scan.getPacketRate()));
|
||||
display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display.drawString(128, 0, String(scan.deauths));
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
|
||||
if (scan.getMaxPacket() > 0) {
|
||||
for (int i = 0; i < SCAN_PACKET_LIST_SIZE * 2; i += 2) {
|
||||
display.drawLine(i, 64, i, 64 - scan.getPackets(i / 2)*scale);
|
||||
display.drawLine(i + 1, 64, i + 1, 64 - scan.getPackets(i / 2)*scale);
|
||||
display.drawLine(i, 64, i, 64 - scan.getPackets(i / 2) * scale);
|
||||
display.drawLine(i + 1, 64, i + 1, 64 - scan.getPackets(i / 2) * scale);
|
||||
}
|
||||
}
|
||||
// ====================== //
|
||||
}
|
||||
|
||||
void DisplayUI::drawIntro(){
|
||||
void DisplayUI::drawIntro() {
|
||||
// ===== adjustable ===== //
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display.drawString(64, 6, String(F("ESP8266 Deauther")));
|
||||
@@ -798,10 +854,10 @@ bool DisplayUI::updateButton(Button* button) {
|
||||
if (!button->enabled || !button->read) return false;
|
||||
|
||||
// read pin
|
||||
if(button->read()){
|
||||
if(button->push) button->push();
|
||||
}else{
|
||||
if(button->release) button->release();
|
||||
if (button->read()) {
|
||||
if (button->push) button->push();
|
||||
} else {
|
||||
if (button->release) button->release();
|
||||
}
|
||||
|
||||
return button->pushed;
|
||||
@@ -816,20 +872,24 @@ void DisplayUI::clearMenu(Menu* menu) {
|
||||
void DisplayUI::changeMenu(Menu* menu) {
|
||||
if (menu) {
|
||||
// only open list menu if it has nodes
|
||||
if((menu == &apListMenu && accesspoints.count() == 0) ||
|
||||
(menu == &stationListMenu && stations.count() == 0) ||
|
||||
(menu == &nameListMenu && names.count() == 0)){
|
||||
if (((menu == &apListMenu) && (accesspoints.count() == 0)) ||
|
||||
((menu == &stationListMenu) && (stations.count() == 0)) ||
|
||||
((menu == &nameListMenu) && (names.count() == 0))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentMenu) clearMenu(currentMenu);
|
||||
currentMenu = menu;
|
||||
currentMenu->selected = 0;
|
||||
buttonA.time = currentTime;
|
||||
if(selectedID < 0) selectedID = 0;
|
||||
|
||||
if (selectedID < 0) selectedID = 0;
|
||||
|
||||
if (currentMenu->parentMenu) {
|
||||
addMenuNode(currentMenu, D_BACK, currentMenu->parentMenu); // add [BACK]
|
||||
currentMenu->selected = 1;
|
||||
}
|
||||
|
||||
if (currentMenu->build) currentMenu->build();
|
||||
}
|
||||
}
|
||||
@@ -838,28 +898,29 @@ void DisplayUI::goBack() {
|
||||
if (currentMenu->parentMenu) changeMenu(currentMenu->parentMenu);
|
||||
}
|
||||
|
||||
void DisplayUI::createMenu(Menu* menu, Menu* parent, std::function<void()> build) {
|
||||
void DisplayUI::createMenu(Menu* menu, Menu* parent, std::function<void()>build) {
|
||||
menu->list = new SimpleList<MenuNode>;
|
||||
menu->parentMenu = parent;
|
||||
menu->selected = 0;
|
||||
menu->build = build;
|
||||
}
|
||||
|
||||
void DisplayUI::addMenuNode(Menu* menu, std::function<String()> getStr, std::function<void()> click, std::function<void()> hold) {
|
||||
menu->list->add(MenuNode{getStr, click, hold});
|
||||
void DisplayUI::addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click,
|
||||
std::function<void()>hold) {
|
||||
menu->list->add(MenuNode{ getStr, click, hold });
|
||||
}
|
||||
|
||||
void DisplayUI::addMenuNode(Menu* menu, std::function<String()> getStr, std::function<void()> click) {
|
||||
void DisplayUI::addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click) {
|
||||
addMenuNode(menu, getStr, click, NULL);
|
||||
}
|
||||
|
||||
void DisplayUI::addMenuNode(Menu* menu, std::function<String()> getStr, Menu* next) {
|
||||
void DisplayUI::addMenuNode(Menu* menu, std::function<String()>getStr, Menu* next) {
|
||||
addMenuNode(menu, getStr, [this, next]() {
|
||||
changeMenu(next);
|
||||
});
|
||||
}
|
||||
|
||||
void DisplayUI::addMenuNode(Menu* menu, const char* ptr, std::function<void()> click) {
|
||||
void DisplayUI::addMenuNode(Menu* menu, const char* ptr, std::function<void()>click) {
|
||||
addMenuNode(menu, [ptr]() {
|
||||
return str(ptr);
|
||||
}, click);
|
||||
@@ -870,5 +931,3 @@ void DisplayUI::addMenuNode(Menu* menu, const char* ptr, Menu* next) {
|
||||
return str(ptr);
|
||||
}, next);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ extern "C" {
|
||||
#include "Attack.h"
|
||||
|
||||
|
||||
|
||||
extern Settings settings;
|
||||
extern Names names;
|
||||
extern SSIDs ssids;
|
||||
@@ -55,21 +54,21 @@ struct Button {
|
||||
bool pushed; // currently pushed
|
||||
bool hold; // if button was hold (only used for buttonA at the moment)
|
||||
uint32_t time; // last time it was pushed
|
||||
std::function<bool()> read; // function to return if button is pushed
|
||||
std::function<void()> setup; // function to enable/setup the button, if needed
|
||||
std::function<void()> push; // function that is executed when button is pushed
|
||||
std::function<void()> release; // function that is executed when button is released
|
||||
std::function<bool()>read; // function to return if button is pushed
|
||||
std::function<void()>setup; // function to enable/setup the button, if needed
|
||||
std::function<void()>push; // function that is executed when button is pushed
|
||||
std::function<void()>release; // function that is executed when button is released
|
||||
};
|
||||
|
||||
struct Menu {
|
||||
SimpleList<MenuNode>* list;
|
||||
Menu* parentMenu;
|
||||
Menu * parentMenu;
|
||||
uint8_t selected;
|
||||
std::function<void()> build; // function that is executed when button is clicked
|
||||
};
|
||||
|
||||
struct MenuNode {
|
||||
std::function<String()> getStr; // function used to create the displayed string
|
||||
std::function<String()>getStr; // function used to create the displayed string
|
||||
std::function<void()> click; // function that is executed when node is clicked
|
||||
std::function<void()> hold; // function that is executed when node is pressed for > 800ms
|
||||
};
|
||||
@@ -83,6 +82,7 @@ class DisplayUI {
|
||||
void off();
|
||||
|
||||
uint8_t mode = SCREEN_MODE_MENU;
|
||||
|
||||
private:
|
||||
DEAUTHER_DISPLAY // see config.h
|
||||
|
||||
@@ -123,12 +123,13 @@ class DisplayUI {
|
||||
// menu functions
|
||||
void changeMenu(Menu* menu);
|
||||
void goBack();
|
||||
void createMenu(Menu* menu, Menu* parent, std::function<void()> build);
|
||||
void createMenu(Menu* menu, Menu* parent, std::function<void()>build);
|
||||
|
||||
void addMenuNode(Menu* menu, std::function<String()> getStr, std::function<void()> click, std::function<void()> hold);
|
||||
void addMenuNode(Menu* menu, std::function<String()> getStr, std::function<void()> click);
|
||||
void addMenuNode(Menu* menu, std::function<String()> getStr, Menu* next);
|
||||
void addMenuNode(Menu* menu, const char* ptr, std::function<void()> click);
|
||||
void addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click,
|
||||
std::function<void()>hold);
|
||||
void addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click);
|
||||
void addMenuNode(Menu* menu, std::function<String()>getStr, Menu* next);
|
||||
void addMenuNode(Menu* menu, const char* ptr, std::function<void()>click);
|
||||
void addMenuNode(Menu* menu, const char* ptr, Menu* next);
|
||||
|
||||
// menus
|
||||
@@ -611,5 +612,4 @@ const uint8_t DejaVu_Sans_Mono_12[] PROGMEM = {
|
||||
0x00, 0x00, 0x60, 0x40, 0x88, 0x67, 0x00, 0x1C, 0x88, 0x03, 0x60 // 255
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif // ifndef DisplayUI_h
|
||||
103
esp8266_deauther/LEDController.cpp
Normal file
103
esp8266_deauther/LEDController.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include "LEDController.h"
|
||||
|
||||
LEDController::LEDController() {}
|
||||
|
||||
LEDController::~LEDController() {
|
||||
if (led) delete led;
|
||||
}
|
||||
|
||||
void LEDController::setup() {
|
||||
#ifdef DIGITAL_LED
|
||||
led = new DigitalLED(LED_PIN_R, LED_PIN_G, LED_PIN_B, LED_ANODE);
|
||||
led->setup();
|
||||
return;
|
||||
|
||||
#endif // ifdef DIGITAL_LED
|
||||
|
||||
#ifdef RGB_LED
|
||||
led = new AnalogRGBLED(LED_PIN_R, LED_PIN_G, LED_PIN_B, LED_MODE_BRIGHTNESS, LED_ANODE);
|
||||
led->setup();
|
||||
return;
|
||||
|
||||
#endif // ifdef RGB_LED
|
||||
|
||||
#ifdef NEOPIXEL_LED
|
||||
led = new NeopixelLED(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, LED_MODE_BRIGHTNESS);
|
||||
led->setup();
|
||||
return;
|
||||
|
||||
#endif // ifdef NEOPIXEL_LED
|
||||
|
||||
prntln(L_NOT_CONFIGURED);
|
||||
}
|
||||
|
||||
void LEDController::update() {
|
||||
if (!tempEnabled || !led) return;
|
||||
|
||||
if (!settings.getLedEnabled() && tempEnabled) tempDisable();
|
||||
|
||||
if (scan.isScanning() && (scan.deauths < settings.getMinDeauths())) setMode(LED_MODE::SCAN, false);
|
||||
else if (scan.deauths >= settings.getMinDeauths()) setMode(LED_MODE::DEAUTH, false);
|
||||
else if (attack.isRunning()) setMode(LED_MODE::ATTACK, false);
|
||||
else setMode(LED_MODE::IDLE, false);
|
||||
}
|
||||
|
||||
void LEDController::setMode(uint8_t mode, bool force) {
|
||||
if (!led) return;
|
||||
|
||||
if ((mode != LEDController::mode) || force) {
|
||||
LEDController::mode = mode;
|
||||
|
||||
switch (mode) {
|
||||
case LED_MODE::OFF:
|
||||
led->setColor(0, 0, 0);
|
||||
break;
|
||||
|
||||
case LED_MODE::SCAN:
|
||||
led->setColor(0, 0, 255);
|
||||
break;
|
||||
|
||||
case LED_MODE::ATTACK:
|
||||
led->setColor(255, 255, 0);
|
||||
break;
|
||||
|
||||
case LED_MODE::DEAUTH:
|
||||
led->setColor(255, 0, 0);
|
||||
break;
|
||||
|
||||
case LED_MODE::IDLE:
|
||||
led->setColor(0, 255, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LEDController::setColor(uint8_t r, uint8_t g, uint8_t b, bool output) {
|
||||
// debug output
|
||||
if (output) {
|
||||
char s[30];
|
||||
sprintf_P(s, L_OUTPUT, r, g, b);
|
||||
prnt(String(s));
|
||||
}
|
||||
|
||||
led->setColor(r, g, b);
|
||||
}
|
||||
|
||||
void LEDController::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output) {
|
||||
led->setBrightness(brightness);
|
||||
setColor(r, g, b, output);
|
||||
}
|
||||
|
||||
void LEDController::tempEnable() {
|
||||
tempEnabled = true;
|
||||
prntln(L_ENABLED);
|
||||
}
|
||||
|
||||
void LEDController::tempDisable() {
|
||||
tempEnabled = false;
|
||||
prntln(L_DISABLED);
|
||||
}
|
||||
|
||||
bool LEDController::getTempEnabled() {
|
||||
return tempEnabled;
|
||||
}
|
||||
49
esp8266_deauther/LEDController.h
Normal file
49
esp8266_deauther/LEDController.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef LEDController_h
|
||||
#define LEDController_h
|
||||
|
||||
#include "Arduino.h"
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "language.h"
|
||||
#include "A_config.h"
|
||||
#include "Settings.h"
|
||||
#include "Attack.h"
|
||||
#include "Scan.h"
|
||||
|
||||
#include "StatusLED.h"
|
||||
#include "DigitalLED.h"
|
||||
#include "NeopixelLED.h"
|
||||
#include "AnalogRGBLED.h"
|
||||
|
||||
extern Settings settings;
|
||||
extern Attack attack;
|
||||
extern Scan scan;
|
||||
extern Stations stations;
|
||||
|
||||
class LEDController {
|
||||
public:
|
||||
enum LED_MODE { OFF = 0, SCAN = 1, ATTACK = 2, DEAUTH = 3, IDLE = 4 };
|
||||
|
||||
LEDController();
|
||||
~LEDController();
|
||||
|
||||
void setup();
|
||||
void update();
|
||||
|
||||
void setMode(uint8_t mode, bool force);
|
||||
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b, bool output);
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output);
|
||||
|
||||
void tempEnable();
|
||||
void tempDisable();
|
||||
bool getTempEnabled();
|
||||
|
||||
private:
|
||||
bool tempEnabled = true;
|
||||
uint8_t mode = LED_MODE::OFF;
|
||||
StatusLED* led = NULL;
|
||||
};
|
||||
|
||||
#endif // ifndef LEDController_h
|
||||
@@ -10,11 +10,12 @@ void Names::load() {
|
||||
DynamicJsonBuffer jsonBuffer(4000);
|
||||
|
||||
checkFile(FILE_PATH, String(OPEN_BRACKET) + String(CLOSE_BRACKET));
|
||||
JsonArray &arr = parseJSONFile(FILE_PATH, jsonBuffer);
|
||||
JsonArray& arr = parseJSONFile(FILE_PATH, jsonBuffer);
|
||||
|
||||
for (uint32_t i = 0; i < arr.size() && i < NAME_LIST_SIZE; i++) {
|
||||
JsonArray &tmpArray = arr.get<JsonVariant>(i);
|
||||
internal_add(tmpArray.get<String>(0), tmpArray.get<String>(2), tmpArray.get<String>(3), tmpArray.get<uint8_t>(4), false);
|
||||
JsonArray& tmpArray = arr.get<JsonVariant>(i);
|
||||
internal_add(tmpArray.get<String>(0), tmpArray.get<String>(2), tmpArray.get<String>(3), tmpArray.get<uint8_t>(
|
||||
4), false);
|
||||
sort();
|
||||
}
|
||||
|
||||
@@ -24,6 +25,7 @@ void Names::load() {
|
||||
|
||||
void Names::load(String filepath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filepath;
|
||||
load();
|
||||
FILE_PATH = tmp;
|
||||
@@ -32,6 +34,7 @@ void Names::load(String filepath) {
|
||||
void Names::save(bool force) {
|
||||
if (!force && !changed) {
|
||||
return;
|
||||
|
||||
prntln(N_SAVED);
|
||||
}
|
||||
|
||||
@@ -57,9 +60,10 @@ void Names::save(bool force) {
|
||||
buf += String(DOUBLEQUOTES) + getBssidStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "00:11:22:00:11:22",
|
||||
buf += String(getCh(i)) + String(COMMA); // 1,
|
||||
buf += b2s(getSelected(i)) + String(CLOSE_BRACKET); // false]
|
||||
if(i < c-1) buf += COMMA; // ,
|
||||
|
||||
if(buf.length() >= 1024){
|
||||
if (i < c - 1) buf += COMMA; // ,
|
||||
|
||||
if (buf.length() >= 1024) {
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
@@ -85,13 +89,14 @@ void Names::save(bool force) {
|
||||
|
||||
void Names::save(bool force, String filepath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filepath;
|
||||
save(force);
|
||||
FILE_PATH = tmp;
|
||||
}
|
||||
|
||||
void Names::sort() {
|
||||
list->sort([](Device & a, Device & b) -> bool{
|
||||
list->sort([](Device& a, Device& b) -> bool {
|
||||
return memcmp(a.mac, b.mac, 6) > 0;
|
||||
});
|
||||
}
|
||||
@@ -104,23 +109,23 @@ void Names::removeAll() {
|
||||
|
||||
bool Names::check(int num) {
|
||||
if (internal_check(num)) return true;
|
||||
|
||||
prnt(N_ERROR_NOT_FOUND);
|
||||
prntln(num);
|
||||
return false;
|
||||
}
|
||||
|
||||
int Names::findID(uint8_t* mac) {
|
||||
return list->binSearch([mac](Device &a) -> int{
|
||||
return list->binSearch([mac](Device& a) -> int {
|
||||
return memcmp(mac, a.mac, 6);
|
||||
},0,count()-1);
|
||||
});
|
||||
}
|
||||
|
||||
String Names::find(uint8_t* mac) {
|
||||
int num = findID(mac);
|
||||
if (num >= 0)
|
||||
return getName(num);
|
||||
else
|
||||
return String();
|
||||
|
||||
if (num >= 0) return getName(num);
|
||||
else return String();
|
||||
}
|
||||
|
||||
void Names::print(int num) {
|
||||
@@ -129,6 +134,7 @@ void Names::print(int num) {
|
||||
|
||||
void Names::print(int num, bool header, bool footer) {
|
||||
if (!check(num)) return;
|
||||
|
||||
if (header) {
|
||||
prntln(N_TABLE_HEADER);
|
||||
prntln(N_TABLE_DIVIDER);
|
||||
@@ -142,18 +148,16 @@ void Names::print(int num, bool header, bool footer) {
|
||||
prnt(buildString(String(SPACE), (String)getCh(num), 3));
|
||||
prntln(buildString(String(SPACE) + getSelectedStr(num), String(), 9));
|
||||
|
||||
if (footer)
|
||||
prntln(N_TABLE_DIVIDER);
|
||||
if (footer) prntln(N_TABLE_DIVIDER);
|
||||
}
|
||||
|
||||
void Names::printAll() {
|
||||
prntln(N_HEADER);
|
||||
int c = count();
|
||||
if (c == 0)
|
||||
prntln(N_ERROR_LIST_EMPTY);
|
||||
|
||||
if (c == 0) prntln(N_ERROR_LIST_EMPTY);
|
||||
else
|
||||
for (int i = 0; i < c; i++)
|
||||
print(i, i == 0, i == c - 1);
|
||||
for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1);
|
||||
}
|
||||
|
||||
void Names::printSelected() {
|
||||
@@ -176,8 +180,7 @@ void Names::printSelected() {
|
||||
|
||||
void Names::add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch, bool selected, bool force) {
|
||||
if (count() >= NAME_LIST_SIZE) {
|
||||
if (force)
|
||||
internal_remove(0);
|
||||
if (force) internal_remove(0);
|
||||
else {
|
||||
prntln(N_ERROR_LIST_FULL);
|
||||
return;
|
||||
@@ -196,8 +199,7 @@ void Names::add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch, bool sele
|
||||
|
||||
void Names::add(String macStr, String name, String bssidStr, uint8_t ch, bool selected, bool force) {
|
||||
if (count() >= NAME_LIST_SIZE) {
|
||||
if (force)
|
||||
internal_remove(0);
|
||||
if (force) internal_remove(0);
|
||||
else {
|
||||
prntln(N_ERROR_LIST_FULL);
|
||||
return;
|
||||
@@ -214,8 +216,9 @@ void Names::add(String macStr, String name, String bssidStr, uint8_t ch, bool se
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Names::replace(int num, String macStr, String name, String bssidStr, uint8_t ch, bool selected){
|
||||
void Names::replace(int num, String macStr, String name, String bssidStr, uint8_t ch, bool selected) {
|
||||
if (!check(num)) return;
|
||||
|
||||
remove(num);
|
||||
|
||||
internal_add(macStr, name, bssidStr, ch, selected);
|
||||
@@ -227,6 +230,7 @@ void Names::replace(int num, String macStr, String name, String bssidStr, uint8_
|
||||
|
||||
void Names::remove(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
prnt(N_REMOVED);
|
||||
prntln(getName(num));
|
||||
internal_remove(num);
|
||||
@@ -235,6 +239,7 @@ void Names::remove(int num) {
|
||||
|
||||
void Names::setName(int num, String name) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_add(getMac(num), name, getBssid(num), getCh(num), getSelected(num));
|
||||
|
||||
prntln(N_CHANGED_NAME);
|
||||
@@ -246,6 +251,7 @@ void Names::setName(int num, String name) {
|
||||
|
||||
void Names::setMac(int num, String macStr) {
|
||||
if (!check(num)) return;
|
||||
|
||||
uint8_t mac[6];
|
||||
strToMac(macStr, mac);
|
||||
internal_add(mac, getName(num), getBssid(num), getCh(num), getSelected(num));
|
||||
@@ -257,6 +263,7 @@ void Names::setMac(int num, String macStr) {
|
||||
|
||||
void Names::setCh(int num, uint8_t ch) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_add(getMac(num), getName(num), getBssid(num), ch, getSelected(num));
|
||||
prntln(N_CHANGED_CH);
|
||||
internal_remove(num);
|
||||
@@ -266,6 +273,7 @@ void Names::setCh(int num, uint8_t ch) {
|
||||
|
||||
void Names::setBSSID(int num, String bssidStr) {
|
||||
if (!check(num)) return;
|
||||
|
||||
uint8_t mac[6];
|
||||
strToMac(bssidStr, mac);
|
||||
internal_add(getMac(num), getName(num), mac, getCh(num), getSelected(num));
|
||||
@@ -277,6 +285,7 @@ void Names::setBSSID(int num, String bssidStr) {
|
||||
|
||||
void Names::select(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_select(num);
|
||||
prnt(N_SELECTED);
|
||||
prntln(getName(num));
|
||||
@@ -285,6 +294,7 @@ void Names::select(int num) {
|
||||
|
||||
void Names::select(String name) {
|
||||
int c = count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
if (getName(i).equals(name)) {
|
||||
select(i);
|
||||
@@ -297,6 +307,7 @@ void Names::select(String name) {
|
||||
|
||||
void Names::deselect(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_deselect(num);
|
||||
prnt(N_DESELECTED);
|
||||
prntln(getName(num));
|
||||
@@ -305,6 +316,7 @@ void Names::deselect(int num) {
|
||||
|
||||
void Names::deselect(String name) {
|
||||
int c = count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
if (getName(i).equals(name)) {
|
||||
deselect(i);
|
||||
@@ -317,46 +329,53 @@ void Names::deselect(String name) {
|
||||
|
||||
void Names::selectAll() {
|
||||
int c = count();
|
||||
for (int i = 0; i < c; i++)
|
||||
internal_select(i);
|
||||
|
||||
for (int i = 0; i < c; i++) internal_select(i);
|
||||
prntln(N_SELECTED_ALL);
|
||||
}
|
||||
|
||||
void Names::deselectAll() {
|
||||
int c = count();
|
||||
for (int i = 0; i < c; i++)
|
||||
internal_deselect(i);
|
||||
|
||||
for (int i = 0; i < c; i++) internal_deselect(i);
|
||||
prntln(N_DESELECTED_ALL);
|
||||
}
|
||||
|
||||
uint8_t* Names::getMac(int num) {
|
||||
if (!check(num)) return NULL;
|
||||
|
||||
return list->get(num).mac;
|
||||
}
|
||||
|
||||
uint8_t* Names::getBssid(int num) {
|
||||
if (!check(num)) return NULL;
|
||||
|
||||
return list->get(num).apBssid;
|
||||
}
|
||||
|
||||
String Names::getMacStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
uint8_t* mac = getMac(num);
|
||||
return bytesToStr(mac, 6);
|
||||
}
|
||||
|
||||
String Names::getVendorStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
return searchVendor(list->get(num).mac);
|
||||
}
|
||||
|
||||
String Names::getBssidStr(int num) {
|
||||
String value;
|
||||
|
||||
if (getBssid(num) != NULL) {
|
||||
uint8_t* mac = getBssid(num);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (mac[i] < 0x10) value += ZERO;
|
||||
value += String(mac[i], HEX);
|
||||
|
||||
if (i < 5) value += DOUBLEPOINT;
|
||||
}
|
||||
}
|
||||
@@ -365,6 +384,7 @@ String Names::getBssidStr(int num) {
|
||||
|
||||
String Names::getName(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
return String(list->get(num).name);
|
||||
}
|
||||
|
||||
@@ -374,11 +394,13 @@ String Names::getSelectedStr(int num) {
|
||||
|
||||
uint8_t Names::getCh(int num) {
|
||||
if (!check(num)) return 1;
|
||||
|
||||
return list->get(num).ch;
|
||||
}
|
||||
|
||||
bool Names::getSelected(int num) {
|
||||
if (!check(num)) return false;
|
||||
|
||||
return list->get(num).selected;
|
||||
}
|
||||
|
||||
@@ -392,6 +414,7 @@ int Names::count() {
|
||||
|
||||
int Names::selected() {
|
||||
int num = 0;
|
||||
|
||||
for (int i = 0; i < count(); i++)
|
||||
if (getSelected(i)) num++;
|
||||
return num;
|
||||
@@ -399,6 +422,7 @@ int Names::selected() {
|
||||
|
||||
int Names::stations() {
|
||||
int num = 0;
|
||||
|
||||
for (int i = 0; i < count(); i++)
|
||||
if (isStation(i)) num++;
|
||||
return num;
|
||||
@@ -410,18 +434,21 @@ bool Names::internal_check(int num) {
|
||||
|
||||
void Names::internal_select(int num) {
|
||||
Device newDevice = list->get(num);
|
||||
|
||||
newDevice.selected = true;
|
||||
list->replace(num, newDevice);
|
||||
}
|
||||
|
||||
void Names::internal_deselect(int num) {
|
||||
Device newDevice = list->get(num);
|
||||
|
||||
newDevice.selected = false;
|
||||
list->replace(num, newDevice);
|
||||
}
|
||||
|
||||
void Names::internal_add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch, bool selected) {
|
||||
uint8_t* deviceMac = (uint8_t*)malloc(6);
|
||||
|
||||
if (name.length() > NAME_MAX_LENGTH) name = name.substring(0, NAME_MAX_LENGTH);
|
||||
char* deviceName = (char*)malloc(name.length() + 1);
|
||||
uint8_t* deviceBssid = NULL;
|
||||
@@ -436,7 +463,7 @@ void Names::internal_add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch,
|
||||
memcpy(deviceBssid, bssid, 6);
|
||||
}
|
||||
|
||||
if (ch < 1 || ch > 14) ch = 1;
|
||||
if ((ch < 1) || (ch > 14)) ch = 1;
|
||||
|
||||
Device newDevice;
|
||||
newDevice.mac = deviceMac;
|
||||
@@ -450,6 +477,7 @@ void Names::internal_add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch,
|
||||
|
||||
void Names::internal_add(String macStr, String name, String bssidStr, uint8_t ch, bool selected) {
|
||||
uint8_t mac[6];
|
||||
|
||||
if (!strToMac(macStr, mac)) return;
|
||||
|
||||
if (bssidStr.length() == 17) {
|
||||
@@ -464,20 +492,17 @@ void Names::internal_add(String macStr, String name, String bssidStr, uint8_t ch
|
||||
void Names::internal_remove(int num) {
|
||||
free(list->get(num).mac);
|
||||
free(list->get(num).name);
|
||||
if (list->get(num).apBssid)
|
||||
free(list->get(num).apBssid);
|
||||
|
||||
if (list->get(num).apBssid) free(list->get(num).apBssid);
|
||||
list->remove(num);
|
||||
}
|
||||
|
||||
void Names::internal_removeAll() {
|
||||
while(count() > 0){
|
||||
while (count() > 0) {
|
||||
free(list->get(0).mac);
|
||||
free(list->get(0).name);
|
||||
if (list->get(0).apBssid)
|
||||
free(list->get(0).apBssid);
|
||||
|
||||
if (list->get(0).apBssid) free(list->get(0).apBssid);
|
||||
list->remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include <ArduinoJson.h>
|
||||
#include "ArduinoJson.h"
|
||||
#include "language.h"
|
||||
#include "SimpleList.h"
|
||||
|
||||
@@ -15,9 +15,9 @@ extern "C" {
|
||||
#define NAME_MAX_LENGTH 16
|
||||
|
||||
extern void checkFile(String path, String data);
|
||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer &jsonBuffer);
|
||||
extern bool writeFile(String path, String &buf);
|
||||
extern bool appendFile(String path, String &buf);
|
||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern bool appendFile(String path, String& buf);
|
||||
extern bool strToMac(String macStr, uint8_t* mac);
|
||||
extern String searchVendor(uint8_t* mac);
|
||||
extern String fixUtf8(String str);
|
||||
@@ -32,7 +32,7 @@ class Names {
|
||||
void load();
|
||||
void load(String filepath);
|
||||
void save(bool force);
|
||||
void save(bool force,String filepath);
|
||||
void save(bool force, String filepath);
|
||||
void sort();
|
||||
|
||||
String find(uint8_t* mac);
|
||||
@@ -76,13 +76,14 @@ class Names {
|
||||
int stations();
|
||||
|
||||
bool check(int num);
|
||||
|
||||
private:
|
||||
String FILE_PATH = "/names.json";
|
||||
bool changed = false;
|
||||
|
||||
struct Device{
|
||||
struct Device {
|
||||
uint8_t* mac; // mac address
|
||||
char* name; // name of saved device
|
||||
char * name; // name of saved device
|
||||
uint8_t* apBssid; // mac address of AP (if saved device is a station)
|
||||
uint8_t ch; // Wi-Fi channel of Device
|
||||
bool selected; // select for attacking
|
||||
@@ -100,7 +101,4 @@ class Names {
|
||||
void internal_removeAll();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // ifndef Names_h
|
||||
@@ -1,110 +1,27 @@
|
||||
#include "Neopixel.h"
|
||||
|
||||
Neopixel::Neopixel() {
|
||||
#include "NeopixelLED.h"
|
||||
|
||||
NeopixelLED::NeopixelLED(int num, uint8_t dataPin, uint8_t brightness) {
|
||||
strip = new Adafruit_NeoPixel(num, dataPin, NEO_GRB + NEO_KHZ800);
|
||||
setBrightness(brightness);
|
||||
}
|
||||
|
||||
// setup pins
|
||||
void Neopixel::setup(){
|
||||
if(!settings.getLedEnabled()) return;
|
||||
|
||||
// ===== adjustable ===== //
|
||||
strip.setBrightness(100);
|
||||
strip.begin();
|
||||
strip.show();
|
||||
// ====================== //
|
||||
|
||||
setMode(LED_MODE_OFF, true);
|
||||
NeopixelLED::~NeopixelLED() {
|
||||
delete strip;
|
||||
}
|
||||
|
||||
void Neopixel::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output) {
|
||||
// debug output
|
||||
if (output){
|
||||
char s[30];
|
||||
sprintf(s,str(L_OUTPUT_A).c_str(), r, g, b);
|
||||
prnt(String(s));
|
||||
}
|
||||
|
||||
// ===== adjustable ===== //
|
||||
if (brightness > 0 && brightness < 100) {
|
||||
if (r > 0 && brightness < 100) r = r * brightness / 100;
|
||||
if (g > 0 && brightness < 100) g = g * brightness / 100;
|
||||
if (b > 0 && brightness < 100) b = b * brightness / 100;
|
||||
}
|
||||
|
||||
for(uint16_t i=0;i<LED_NEOPIXEL_NUM;i++){
|
||||
strip.setPixelColor(i,strip.Color(r,g,b,brightness));
|
||||
}
|
||||
strip.show();
|
||||
// ====================== //
|
||||
|
||||
// debug output
|
||||
if (output){
|
||||
char s[30];
|
||||
sprintf(s,str(L_OUTPUT_B).c_str(), r?255:0, g?255:0, b?255:0);
|
||||
prnt(String(s));
|
||||
}
|
||||
void NeopixelLED::setup() {
|
||||
strip->begin();
|
||||
strip->show();
|
||||
}
|
||||
|
||||
// customize color codes for different LED modes
|
||||
void Neopixel::setMode(uint8_t mode, bool force) {
|
||||
// ===== adjustable ===== //
|
||||
if (mode != Neopixel::mode || force) {
|
||||
Neopixel::mode = mode;
|
||||
switch (mode) {
|
||||
case LED_MODE_OFF:
|
||||
setColor(0, 0, 0, LED_MODE_BRIGHTNESS, false);
|
||||
break;
|
||||
case LED_MODE_SCAN:
|
||||
if(LED_DYNAMIC_BRIGHTNESS) setColor(0, 0, 255, (uint8_t)(scan.getScaleFactor(100)*scan.getPacketRate()), false); // change color depending on packet rate
|
||||
else setColor(0, 0, 255, LED_MODE_BRIGHTNESS, false);
|
||||
break;
|
||||
case LED_MODE_ATTACK:
|
||||
setColor(255, 255, 0, LED_MODE_BRIGHTNESS, false);
|
||||
break;
|
||||
case LED_MODE_DEAUTH:
|
||||
if(LED_DYNAMIC_BRIGHTNESS) setColor(255, 0, 0, scan.deauths > 255 ? 255 : scan.deauths , false); // brightness depending on how many deauths/s
|
||||
else setColor(255, 0, 0, LED_MODE_BRIGHTNESS, false);
|
||||
break;
|
||||
case LED_MODE_IDLE:
|
||||
setColor(0, 255, 0, LED_MODE_BRIGHTNESS, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// ====================== //
|
||||
void NeopixelLED::setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
int num = strip->numPixels();
|
||||
|
||||
for (uint16_t i = 0; i < num; i++) strip->setPixelColor(i, strip->Color(r, g, b));
|
||||
strip->show();
|
||||
}
|
||||
|
||||
void Neopixel::tempEnable() {
|
||||
tempEnabled = true;
|
||||
prntln(L_ENABLED);
|
||||
void NeopixelLED::setBrightness(uint8_t brightness) {
|
||||
if (brightness > 100) brightness = 100;
|
||||
strip->setBrightness(brightness);
|
||||
}
|
||||
|
||||
void Neopixel::tempDisable() {
|
||||
tempEnabled = false;
|
||||
prntln(L_DISABLED);
|
||||
}
|
||||
|
||||
bool Neopixel::getTempEnabled() {
|
||||
return tempEnabled;
|
||||
}
|
||||
|
||||
void Neopixel::setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
setColor(r, g, b, 100, true);
|
||||
}
|
||||
|
||||
void Neopixel::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness) {
|
||||
setColor(r, g, b, brightness, true);
|
||||
}
|
||||
|
||||
void Neopixel::update() {
|
||||
if (!tempEnabled) return;
|
||||
if (!settings.getLedEnabled() && tempEnabled) tempDisable();
|
||||
|
||||
if (scan.isScanning() && scan.deauths < settings.getMinDeauths()) setMode(LED_MODE_SCAN, false);
|
||||
else if (scan.deauths >= settings.getMinDeauths()) setMode(LED_MODE_DEAUTH, false);
|
||||
else if (attack.isRunning()) setMode(LED_MODE_ATTACK, false);
|
||||
else setMode(LED_MODE_IDLE, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
21
esp8266_deauther/NeopixelLED.h
Normal file
21
esp8266_deauther/NeopixelLED.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef NeopixelLED_H
|
||||
#define NeopixelLED_H
|
||||
|
||||
#include "StatusLED.h"
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
class NeopixelLED : public StatusLED {
|
||||
public:
|
||||
NeopixelLED(int num, uint8_t dataPin, uint8_t brightness);
|
||||
~NeopixelLED();
|
||||
|
||||
void setup();
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
void setBrightness(uint8_t brightness);
|
||||
void setMode(uint8_t mode, bool force);
|
||||
|
||||
private:
|
||||
Adafruit_NeoPixel* strip;
|
||||
};
|
||||
|
||||
#endif // ifndef NeopixelLED_H
|
||||
@@ -9,11 +9,11 @@ void SSIDs::load() {
|
||||
DynamicJsonBuffer jsonBuffer(4000);
|
||||
|
||||
checkFile(FILE_PATH, str(SS_JSON_DEFAULT));
|
||||
JsonObject &obj = parseJSONFile(FILE_PATH, jsonBuffer);
|
||||
JsonArray &arr = obj.get<JsonArray>(str(SS_JSON_SSIDS));
|
||||
JsonObject& obj = parseJSONFile(FILE_PATH, jsonBuffer);
|
||||
JsonArray & arr = obj.get<JsonArray>(str(SS_JSON_SSIDS));
|
||||
|
||||
for (uint32_t i = 0; i < arr.size() && i < SSID_LIST_SIZE; i++) {
|
||||
JsonArray &tmpArray = arr.get<JsonVariant>(i);
|
||||
JsonArray& tmpArray = arr.get<JsonVariant>(i);
|
||||
internal_add(tmpArray.get<String>(0), tmpArray.get<bool>(1), tmpArray.get<int>(2));
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ void SSIDs::load() {
|
||||
|
||||
void SSIDs::load(String filepath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filepath;
|
||||
load();
|
||||
FILE_PATH = tmp;
|
||||
@@ -38,8 +39,10 @@ void SSIDs::save(bool force) {
|
||||
if (!force && !changed) return;
|
||||
|
||||
String buf = String(); // create buffer
|
||||
buf += String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SS_JSON_RANDOM) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + b2s(randomMode) + String(COMMA); // {"random":false,
|
||||
buf += String(DOUBLEQUOTES) + str(SS_JSON_SSIDS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + String(OPEN_BRACKET); // "ssids":[
|
||||
buf += String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SS_JSON_RANDOM) + String(DOUBLEQUOTES) + String(
|
||||
DOUBLEPOINT) + b2s(randomMode) + String(COMMA); // {"random":false,
|
||||
buf += String(DOUBLEQUOTES) + str(SS_JSON_SSIDS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) +
|
||||
String(OPEN_BRACKET); // "ssids":[
|
||||
|
||||
if (!writeFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
@@ -57,9 +60,10 @@ void SSIDs::save(bool force) {
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + name + String(DOUBLEQUOTES) + String(COMMA); // ["name",
|
||||
buf += b2s(getWPA2(i)) + String(COMMA); // false,
|
||||
buf += String(getLen(i)) + String(CLOSE_BRACKET); // 12]
|
||||
if(i < c-1) buf += COMMA; // ,
|
||||
|
||||
if(buf.length() >= 1024){
|
||||
if (i < c - 1) buf += COMMA; // ,
|
||||
|
||||
if (buf.length() >= 1024) {
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
@@ -85,6 +89,7 @@ void SSIDs::save(bool force) {
|
||||
|
||||
void SSIDs::save(bool force, String filepath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filepath;
|
||||
save(force);
|
||||
FILE_PATH = tmp;
|
||||
@@ -92,26 +97,23 @@ void SSIDs::save(bool force, String filepath) {
|
||||
|
||||
void SSIDs::update() {
|
||||
if (randomMode) {
|
||||
if (currentTime - randomTime > randomInterval*1000) {
|
||||
if (currentTime - randomTime > randomInterval * 1000) {
|
||||
prntln(SS_RANDOM_INFO);
|
||||
|
||||
for (int i = 0; i < SSID_LIST_SIZE; i++) {
|
||||
SSID newSSID;
|
||||
|
||||
if (check(i))
|
||||
newSSID = list->get(i);
|
||||
if (check(i)) newSSID = list->get(i);
|
||||
|
||||
newSSID.name = String();
|
||||
newSSID.len = 32;
|
||||
for (int i = 0; i < 32; i++)
|
||||
newSSID.name += char(random(32, 127));
|
||||
|
||||
for (int i = 0; i < 32; i++) newSSID.name += char(random(32, 127));
|
||||
|
||||
newSSID.wpa2 = random(0, 2);
|
||||
|
||||
if (check(i))
|
||||
list->replace(i, newSSID);
|
||||
else
|
||||
list->add(newSSID);
|
||||
if (check(i)) list->replace(i, newSSID);
|
||||
else list->add(newSSID);
|
||||
}
|
||||
|
||||
randomTime = currentTime;
|
||||
@@ -128,12 +130,13 @@ bool SSIDs::getWPA2(int num) {
|
||||
return check(num) ? list->get(num).wpa2 : false;
|
||||
}
|
||||
|
||||
int SSIDs::getLen(int num){
|
||||
int SSIDs::getLen(int num) {
|
||||
return check(num) ? list->get(num).len : 0;
|
||||
}
|
||||
|
||||
void SSIDs::setWPA2(int num, bool wpa2) {
|
||||
SSID newSSID = list->get(num);
|
||||
|
||||
newSSID.wpa2 = wpa2;
|
||||
list->replace(num, newSSID);
|
||||
}
|
||||
@@ -145,6 +148,7 @@ String SSIDs::getEncStr(int num) {
|
||||
|
||||
void SSIDs::remove(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_remove(num);
|
||||
prnt(SS_REMOVED);
|
||||
prntln(getName(num));
|
||||
@@ -153,16 +157,19 @@ void SSIDs::remove(int num) {
|
||||
|
||||
String SSIDs::randomize(String name) {
|
||||
int ssidlen = name.length();
|
||||
|
||||
if (ssidlen > 32) name = name.substring(0, 32);
|
||||
|
||||
if (ssidlen < 32) {
|
||||
for (int i = ssidlen; i < 32; i++) {
|
||||
int rnd = random(3);
|
||||
if (i < 29 && rnd == 0) { // ZERO WIDTH SPACE
|
||||
|
||||
if ((i < 29) && (rnd == 0)) { // ZERO WIDTH SPACE
|
||||
name += char(0xE2);
|
||||
name += char(0x80);
|
||||
name += char(0x8B);
|
||||
i += 2;
|
||||
} else if (i < 30 && rnd == 1) { // NO-BREAK SPACE
|
||||
} else if ((i < 30) && (rnd == 1)) { // NO-BREAK SPACE
|
||||
name += char(0xC2);
|
||||
name += char(0xA0);
|
||||
i += 1;
|
||||
@@ -188,6 +195,7 @@ void SSIDs::add(String name, bool wpa2, int clones, bool force) {
|
||||
|
||||
for (int i = 0; i < clones; i++) {
|
||||
internal_add(name, wpa2, name.length());
|
||||
|
||||
if (list->size() > SSID_LIST_SIZE) internal_remove(0);
|
||||
}
|
||||
|
||||
@@ -196,35 +204,36 @@ void SSIDs::add(String name, bool wpa2, int clones, bool force) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void SSIDs::cloneSelected(bool force){
|
||||
if(accesspoints.selected() > 0){
|
||||
void SSIDs::cloneSelected(bool force) {
|
||||
if (accesspoints.selected() > 0) {
|
||||
int clones = SSID_LIST_SIZE;
|
||||
if(!force) clones -= list->size();
|
||||
|
||||
if (!force) clones -= list->size();
|
||||
clones /= accesspoints.selected();
|
||||
|
||||
int apCount = accesspoints.count();
|
||||
for(int i=0;i<apCount;i++){
|
||||
if(accesspoints.getSelected(i))
|
||||
add(accesspoints.getSSID(i), accesspoints.getEnc(i) != 0, clones, force);
|
||||
|
||||
for (int i = 0; i < apCount; i++) {
|
||||
if (accesspoints.getSelected(i)) add(accesspoints.getSSID(i), accesspoints.getEnc(i) != 0, clones, force);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SSIDs::getRandom(){
|
||||
bool SSIDs::getRandom() {
|
||||
return randomMode;
|
||||
}
|
||||
|
||||
void SSIDs::replace(int num, String name, bool wpa2){
|
||||
if(!check(num)) return;
|
||||
void SSIDs::replace(int num, String name, bool wpa2) {
|
||||
if (!check(num)) return;
|
||||
|
||||
int len = name.length();
|
||||
if(len > 32)
|
||||
len = 32;
|
||||
|
||||
if (len > 32) len = 32;
|
||||
SSID newSSID;
|
||||
newSSID.name = randomize(name);
|
||||
newSSID.wpa2 = wpa2;
|
||||
newSSID.len = (uint8_t)len;
|
||||
list->replace(num,newSSID);
|
||||
list->replace(num, newSSID);
|
||||
|
||||
prnt(SS_REPLACED);
|
||||
prntln(name);
|
||||
@@ -237,6 +246,7 @@ void SSIDs::print(int num) {
|
||||
|
||||
void SSIDs::print(int num, bool header, bool footer) {
|
||||
if (!check(num)) return;
|
||||
|
||||
if (header) {
|
||||
prntln(SS_TABLE_HEADER);
|
||||
prntln(SS_TABLE_DIVIDER);
|
||||
@@ -252,11 +262,10 @@ void SSIDs::print(int num, bool header, bool footer) {
|
||||
void SSIDs::printAll() {
|
||||
prntln(SS_HEADER);
|
||||
int c = count();
|
||||
if (c == 0)
|
||||
prntln(SS_ERROR_EMPTY);
|
||||
|
||||
if (c == 0) prntln(SS_ERROR_EMPTY);
|
||||
else
|
||||
for (int i = 0; i < c; i++)
|
||||
print(i, i == 0, i == c - 1);
|
||||
for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1);
|
||||
}
|
||||
|
||||
int SSIDs::count() {
|
||||
@@ -281,8 +290,8 @@ void SSIDs::disableRandom() {
|
||||
}
|
||||
|
||||
void SSIDs::internal_add(String name, bool wpa2, int len) {
|
||||
if(len > 32) {
|
||||
name = name.substring(0,32);
|
||||
if (len > 32) {
|
||||
name = name.substring(0, 32);
|
||||
len = 32;
|
||||
} else if (len < 32) {
|
||||
name = randomize(name);
|
||||
@@ -305,6 +314,3 @@ void SSIDs::internal_remove(int num) {
|
||||
void SSIDs::internal_removeAll() {
|
||||
list->clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include <ArduinoJson.h>
|
||||
#include "ArduinoJson.h"
|
||||
#include "language.h"
|
||||
#include "SimpleList.h"
|
||||
#include "Settings.h"
|
||||
@@ -20,9 +20,9 @@ extern uint32_t currentTime;
|
||||
extern Accesspoints accesspoints;
|
||||
|
||||
extern void checkFile(String path, String data);
|
||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer &jsonBuffer);
|
||||
extern bool appendFile(String path, String &buf);
|
||||
extern bool writeFile(String path, String &buf);
|
||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer);
|
||||
extern bool appendFile(String path, String& buf);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern void readFileToSerial(String path);
|
||||
extern String fixUtf8(String str);
|
||||
extern String buildString(String left, String right, int maxLen);
|
||||
@@ -59,13 +59,14 @@ class SSIDs {
|
||||
void removeAll();
|
||||
|
||||
int count();
|
||||
|
||||
private:
|
||||
bool changed = false;
|
||||
bool randomMode = false;
|
||||
uint32_t randomInterval = 2000;
|
||||
uint32_t randomTime = 0;
|
||||
|
||||
struct SSID{
|
||||
struct SSID {
|
||||
String name; // SSID
|
||||
bool wpa2; // WPA2 encrypted or not
|
||||
uint8_t len; // original length (before editing it to be 32 characters)
|
||||
@@ -83,7 +84,4 @@ class SSIDs {
|
||||
void internal_removeAll();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // ifndef SSIDs_h
|
||||
@@ -11,13 +11,13 @@ void Scan::sniffer(uint8_t* buf, uint16_t len) {
|
||||
|
||||
if (len < 28) return; // drop frames that are too short to have a valid MAC header
|
||||
|
||||
if (buf[12] == 0xc0 || buf[12] == 0xa0) {
|
||||
if ((buf[12] == 0xc0) || (buf[12] == 0xa0)) {
|
||||
tmpDeauths++;
|
||||
return;
|
||||
}
|
||||
|
||||
// drop beacon frames, probe requests/responses and deauth/disassociation frames
|
||||
if (buf[12] == 0x80 || buf[12] == 0x40 || buf[12] == 0x50/* || buf[12] == 0xc0 || buf[12] == 0xa0*/) return;
|
||||
if ((buf[12] == 0x80) || (buf[12] == 0x40) || (buf[12] == 0x50) /* || buf[12] == 0xc0 || buf[12] == 0xa0*/) return;
|
||||
|
||||
// only allow data frames
|
||||
// if(buf[12] != 0x08 && buf[12] != 0x88) return;
|
||||
@@ -25,13 +25,16 @@ void Scan::sniffer(uint8_t* buf, uint16_t len) {
|
||||
uint8_t* macTo = &buf[16];
|
||||
uint8_t* macFrom = &buf[22];
|
||||
|
||||
if (macBroadcast(macTo) || macBroadcast(macFrom) || !macValid(macTo) || !macValid(macFrom) || macMulticast(macTo) || macMulticast(macFrom)) return;
|
||||
if (macBroadcast(macTo) || macBroadcast(macFrom) || !macValid(macTo) || !macValid(macFrom) || macMulticast(macTo) ||
|
||||
macMulticast(macFrom)) return;
|
||||
|
||||
int accesspointNum = findAccesspoint(macFrom);
|
||||
|
||||
if (accesspointNum >= 0) {
|
||||
stations.add(macTo, accesspoints.getID(accesspointNum));
|
||||
} else {
|
||||
accesspointNum = findAccesspoint(macTo);
|
||||
|
||||
if (accesspointNum >= 0) {
|
||||
stations.add(macFrom, accesspoints.getID(accesspointNum));
|
||||
}
|
||||
@@ -49,8 +52,9 @@ void Scan::start(uint8_t mode) {
|
||||
start(mode, sniffTime, scan_continue_mode, continueTime, channelHop, wifi_channel);
|
||||
}
|
||||
|
||||
void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continueTime, bool channelHop, uint8_t channel) {
|
||||
if(mode != SCAN_MODE_OFF) stop();
|
||||
void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continueTime, bool channelHop,
|
||||
uint8_t channel) {
|
||||
if (mode != SCAN_MODE_OFF) stop();
|
||||
|
||||
setWifiChannel(channel);
|
||||
Scan::continueStartTime = currentTime;
|
||||
@@ -62,12 +66,13 @@ void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continu
|
||||
Scan::scanMode = mode;
|
||||
Scan::scan_continue_mode = nextmode;
|
||||
|
||||
if(sniffTime > 0 && sniffTime < 1000) sniffTime = 1000;
|
||||
if ((sniffTime > 0) && (sniffTime < 1000)) sniffTime = 1000;
|
||||
|
||||
// Serial.printf("mode: %u, time: %u, continue-mode: %u, continueTime: %u, channelHop: %u, channel: %u\r\n", mode, time, scan_continue_mode, continueTime, channelHop, channel);
|
||||
// Serial.printf("mode: %u, time: %u, continue-mode: %u, continueTime: %u, channelHop: %u, channel: %u\r\n", mode,
|
||||
// time, scan_continue_mode, continueTime, channelHop, channel);
|
||||
|
||||
/* AP Scan */
|
||||
if (mode == SCAN_MODE_APS || mode == SCAN_MODE_ALL) {
|
||||
if ((mode == SCAN_MODE_APS) || (mode == SCAN_MODE_ALL)) {
|
||||
// remove old results
|
||||
accesspoints.removeAll();
|
||||
stations.removeAll();
|
||||
@@ -81,14 +86,16 @@ void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continu
|
||||
// start station scan
|
||||
if (accesspoints.count() < 1) {
|
||||
start(SCAN_MODE_ALL);
|
||||
//Serial.println(str(SC_ERROR_NO_AP));
|
||||
// Serial.println(str(SC_ERROR_NO_AP));
|
||||
return;
|
||||
}
|
||||
snifferStartTime = currentTime;
|
||||
prnt(SC_START_CLIENT);
|
||||
|
||||
if (sniffTime > 0) prnt(String(sniffTime / 1000) + S);
|
||||
else prnt(SC_INFINITELY);
|
||||
if(!channelHop){
|
||||
|
||||
if (!channelHop) {
|
||||
prnt(SC_ON_CHANNEL);
|
||||
prnt(wifi_channel);
|
||||
}
|
||||
@@ -104,10 +111,11 @@ void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continu
|
||||
tmpDeauths = 0;
|
||||
snifferStartTime = currentTime;
|
||||
prnt(SS_START_SNIFFER);
|
||||
|
||||
if (sniffTime > 0) prnt(String(sniffTime / 1000) + S);
|
||||
else prnt(SC_INFINITELY);
|
||||
prnt(SC_ON_CHANNEL);
|
||||
prntln(channelHop ? str(SC_ONE_TO) +(String)settings.getMaxCh() : (String)wifi_channel);
|
||||
prntln(channelHop ? str(SC_ONE_TO) + (String)settings.getMaxCh() : (String)wifi_channel);
|
||||
|
||||
// enable sniffer
|
||||
stopAP();
|
||||
@@ -117,9 +125,11 @@ void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continu
|
||||
/* Stop scan */
|
||||
else if (mode == SCAN_MODE_OFF) {
|
||||
wifi_promiscuous_enable(false);
|
||||
if(settings.getWebInterface()) resumeAP();
|
||||
|
||||
if (settings.getWebInterface()) resumeAP();
|
||||
prntln(SC_STOPPED);
|
||||
save(true);
|
||||
|
||||
if (scan_continue_mode != SCAN_MODE_OFF) {
|
||||
prnt(SC_RESTART);
|
||||
prnt(int(continueTime / 1000));
|
||||
@@ -145,12 +155,13 @@ void Scan::update() {
|
||||
}
|
||||
|
||||
// sniffer
|
||||
if(isSniffing()){
|
||||
if (isSniffing()) {
|
||||
// update packet list every 1s
|
||||
if(currentTime - snifferPacketTime > 1000){
|
||||
if (currentTime - snifferPacketTime > 1000) {
|
||||
snifferPacketTime = currentTime;
|
||||
list->add(packets);
|
||||
if(list->size() > SCAN_PACKET_LIST_SIZE) list->remove(0);
|
||||
|
||||
if (list->size() > SCAN_PACKET_LIST_SIZE) list->remove(0);
|
||||
deauths = tmpDeauths;
|
||||
tmpDeauths = 0;
|
||||
packets = 0;
|
||||
@@ -159,33 +170,37 @@ void Scan::update() {
|
||||
// print status every 3s
|
||||
if (currentTime - snifferOutputTime > 3000) {
|
||||
char s[100];
|
||||
if(sniffTime > 0){
|
||||
sprintf(s,str(SC_OUTPUT_A).c_str(), getPercentage(), packets, stations.count(), deauths);
|
||||
} else{
|
||||
sprintf(s,str(SC_OUTPUT_B).c_str(), packets, stations.count(), deauths);
|
||||
|
||||
if (sniffTime > 0) {
|
||||
sprintf(s, str(SC_OUTPUT_A).c_str(), getPercentage(), packets, stations.count(), deauths);
|
||||
} else {
|
||||
sprintf(s, str(SC_OUTPUT_B).c_str(), packets, stations.count(), deauths);
|
||||
}
|
||||
prnt(String(s));
|
||||
snifferOutputTime = currentTime;
|
||||
}
|
||||
|
||||
// channel hopping
|
||||
if(channelHop && currentTime - snifferChannelTime > settings.getChTime()) {
|
||||
if (channelHop && (currentTime - snifferChannelTime > settings.getChTime())) {
|
||||
snifferChannelTime = currentTime;
|
||||
if(scanMode == SCAN_MODE_STATIONS) nextChannel(); // go to next channel an AP is on
|
||||
|
||||
if (scanMode == SCAN_MODE_STATIONS) nextChannel(); // go to next channel an AP is on
|
||||
else setChannel(wifi_channel + 1); // go to next channel
|
||||
}
|
||||
}
|
||||
|
||||
// APs
|
||||
if (scanMode == SCAN_MODE_APS || scanMode == SCAN_MODE_ALL) {
|
||||
if ((scanMode == SCAN_MODE_APS) || (scanMode == SCAN_MODE_ALL)) {
|
||||
int16_t results = WiFi.scanComplete();
|
||||
|
||||
if (results >= 0) {
|
||||
for (int16_t i = 0; i < results && i < 256; i++) {
|
||||
if(channelHop || WiFi.channel(i) == wifi_channel) accesspoints.add(i, false);
|
||||
if (channelHop || (WiFi.channel(i) == wifi_channel)) accesspoints.add(i, false);
|
||||
}
|
||||
accesspoints.sort();
|
||||
accesspoints.printAll();
|
||||
if (scanMode == SCAN_MODE_ALL){
|
||||
|
||||
if (scanMode == SCAN_MODE_ALL) {
|
||||
delay(30);
|
||||
start(SCAN_MODE_STATIONS);
|
||||
}
|
||||
@@ -194,9 +209,10 @@ void Scan::update() {
|
||||
}
|
||||
|
||||
// Stations
|
||||
else if (sniffTime > 0 && currentTime > snifferStartTime + sniffTime) {
|
||||
else if ((sniffTime > 0) && (currentTime > snifferStartTime + sniffTime)) {
|
||||
wifi_promiscuous_enable(false);
|
||||
if(scanMode == SCAN_MODE_STATIONS){
|
||||
|
||||
if (scanMode == SCAN_MODE_STATIONS) {
|
||||
stations.sort();
|
||||
stations.printAll();
|
||||
}
|
||||
@@ -204,7 +220,7 @@ void Scan::update() {
|
||||
}
|
||||
}
|
||||
|
||||
void Scan::setup(){
|
||||
void Scan::setup() {
|
||||
save(true);
|
||||
}
|
||||
|
||||
@@ -225,8 +241,10 @@ void Scan::setChannel(uint8_t ch) {
|
||||
void Scan::nextChannel() {
|
||||
if (accesspoints.count() > 1) {
|
||||
uint8_t ch = wifi_channel;
|
||||
|
||||
do {
|
||||
ch++;
|
||||
|
||||
if (ch > settings.getMaxCh()) ch = 1;
|
||||
} while (!apWithChannel(ch));
|
||||
setChannel(ch);
|
||||
@@ -236,23 +254,26 @@ void Scan::nextChannel() {
|
||||
bool Scan::apWithChannel(uint8_t ch) {
|
||||
for (int i = 0; i < accesspoints.count(); i++)
|
||||
if (accesspoints.getCh(i) == ch) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Scan::save(bool force, String filePath){
|
||||
void Scan::save(bool force, String filePath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filePath;
|
||||
save(true);
|
||||
FILE_PATH = tmp;
|
||||
}
|
||||
|
||||
void Scan::save(bool force) {
|
||||
if(!(accesspoints.changed || stations.changed) && !force) return;
|
||||
if (!(accesspoints.changed || stations.changed) && !force) return;
|
||||
|
||||
// Accesspoints
|
||||
String buf = String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SC_JSON_APS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + String(OPEN_BRACKET); // {"aps":[
|
||||
String buf = String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SC_JSON_APS) + String(DOUBLEQUOTES) + String(
|
||||
DOUBLEPOINT) + String(OPEN_BRACKET); // {"aps":[
|
||||
|
||||
if(!writeFile(FILE_PATH, buf)) { // overwrite old file
|
||||
if (!writeFile(FILE_PATH, buf)) { // overwrite old file
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
@@ -262,7 +283,8 @@ void Scan::save(bool force) {
|
||||
uint32_t apCount = accesspoints.count();
|
||||
|
||||
for (uint32_t i = 0; i < apCount; i++) {
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + escape(accesspoints.getSSID(i)) + String(DOUBLEQUOTES) + String(COMMA); // ["ssid",
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + escape(accesspoints.getSSID(i)) + String(DOUBLEQUOTES) +
|
||||
String(COMMA); // ["ssid",
|
||||
buf += String(DOUBLEQUOTES) + escape(accesspoints.getNameStr(i)) + String(DOUBLEQUOTES) + String(COMMA); // "name",
|
||||
buf += String(accesspoints.getCh(i)) + String(COMMA); // 1,
|
||||
buf += String(accesspoints.getRSSI(i)) + String(COMMA); // -30,
|
||||
@@ -270,10 +292,11 @@ void Scan::save(bool force) {
|
||||
buf += String(DOUBLEQUOTES) + accesspoints.getMacStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "00:11:22:00:11:22",
|
||||
buf += String(DOUBLEQUOTES) + accesspoints.getVendorStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "vendor",
|
||||
buf += b2s(accesspoints.getSelected(i)) + String(CLOSE_BRACKET); // false]
|
||||
if(i < apCount - 1) buf += String(COMMA); // ,
|
||||
|
||||
if(buf.length() >= 1024){
|
||||
if(!appendFile(FILE_PATH, buf)) {
|
||||
if (i < apCount - 1) buf += String(COMMA); // ,
|
||||
|
||||
if (buf.length() >= 1024) {
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
@@ -284,11 +307,13 @@ void Scan::save(bool force) {
|
||||
}
|
||||
|
||||
// Stations
|
||||
buf += String(CLOSE_BRACKET) + String(COMMA) + String(DOUBLEQUOTES) + str(SC_JSON_STATIONS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + String(OPEN_BRACKET); // ],"stations":[;
|
||||
buf += String(CLOSE_BRACKET) + String(COMMA) + String(DOUBLEQUOTES) + str(SC_JSON_STATIONS) + String(DOUBLEQUOTES) +
|
||||
String(DOUBLEPOINT) + String(OPEN_BRACKET); // ],"stations":[;
|
||||
uint32_t stationCount = stations.count();
|
||||
|
||||
for (uint32_t i = 0; i < stationCount; i++) {
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + stations.getMacStr(i) + String(DOUBLEQUOTES) + String(COMMA); // ["00:11:22:00:11:22",
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + stations.getMacStr(i) + String(DOUBLEQUOTES) +
|
||||
String(COMMA); // ["00:11:22:00:11:22",
|
||||
buf += String(stations.getCh(i)) + String(COMMA); // 1,
|
||||
buf += String(DOUBLEQUOTES) + stations.getNameStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "name",
|
||||
buf += String(DOUBLEQUOTES) + stations.getVendorStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "vendor",
|
||||
@@ -296,10 +321,11 @@ void Scan::save(bool force) {
|
||||
buf += String(stations.getAP(i)) + String(COMMA); // 0,
|
||||
buf += String(DOUBLEQUOTES) + stations.getTimeStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "<1min",
|
||||
buf += b2s(stations.getSelected(i)) + String(CLOSE_BRACKET); // false]
|
||||
if(i < stationCount - 1) buf += String(COMMA); // ,
|
||||
|
||||
if(buf.length() >= 1024){
|
||||
if(!appendFile(FILE_PATH, buf)) {
|
||||
if (i < stationCount - 1) buf += String(COMMA); // ,
|
||||
|
||||
if (buf.length() >= 1024) {
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
@@ -311,7 +337,7 @@ void Scan::save(bool force) {
|
||||
|
||||
buf += String(CLOSE_BRACKET) + String(CLOSE_CURLY_BRACKET); // ]}
|
||||
|
||||
if(!appendFile(FILE_PATH, buf)) {
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
@@ -324,11 +350,11 @@ void Scan::save(bool force) {
|
||||
}
|
||||
|
||||
uint32_t Scan::countSelected() {
|
||||
return (accesspoints.selected() + stations.selected() + names.selected());
|
||||
return accesspoints.selected() + stations.selected() + names.selected();
|
||||
}
|
||||
|
||||
uint32_t Scan::countAll() {
|
||||
return (accesspoints.count() + stations.count() + names.count());
|
||||
return accesspoints.count() + stations.count() + names.count();
|
||||
}
|
||||
|
||||
bool Scan::isScanning() {
|
||||
@@ -339,8 +365,9 @@ bool Scan::isSniffing() {
|
||||
return scanMode == SCAN_MODE_STATIONS || scanMode == SCAN_MODE_SNIFFER;
|
||||
}
|
||||
|
||||
uint8_t Scan::getPercentage(){
|
||||
if(!isSniffing()) return 0;
|
||||
uint8_t Scan::getPercentage() {
|
||||
if (!isSniffing()) return 0;
|
||||
|
||||
return (currentTime - snifferStartTime) / (sniffTime / 100);
|
||||
}
|
||||
|
||||
@@ -369,30 +396,31 @@ void Scan::printSelected() {
|
||||
names.printSelected();
|
||||
}
|
||||
|
||||
uint32_t Scan::getPackets(int i){
|
||||
if(list->size() < SCAN_PACKET_LIST_SIZE){
|
||||
uint32_t Scan::getPackets(int i) {
|
||||
if (list->size() < SCAN_PACKET_LIST_SIZE) {
|
||||
uint8_t translatedNum = SCAN_PACKET_LIST_SIZE - list->size();
|
||||
if(i >= translatedNum) return list->get(i-translatedNum);
|
||||
|
||||
if (i >= translatedNum) return list->get(i - translatedNum);
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
return list->get(i);
|
||||
}
|
||||
}
|
||||
|
||||
double Scan::getScaleFactor(uint8_t height){
|
||||
return (double)height/(double)getMaxPacket();
|
||||
double Scan::getScaleFactor(uint8_t height) {
|
||||
return (double)height / (double)getMaxPacket();
|
||||
}
|
||||
|
||||
uint32_t Scan::getMaxPacket(){
|
||||
uint32_t Scan::getMaxPacket() {
|
||||
uint16_t max = 0;
|
||||
for(uint8_t i=0;i<list->size();i++){
|
||||
if(list->get(i) > max) max = list->get(i);
|
||||
|
||||
for (uint8_t i = 0; i < list->size(); i++) {
|
||||
if (list->get(i) > max) max = list->get(i);
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
uint32_t Scan::getPacketRate(){
|
||||
return list->get(list->size()-1);
|
||||
uint32_t Scan::getPacketRate() {
|
||||
return list->get(list->size() - 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ extern Settings settings;
|
||||
extern uint8_t wifiMode;
|
||||
|
||||
extern void setWifiChannel(uint8_t ch);
|
||||
extern bool appendFile(String path, String &buf);
|
||||
extern bool writeFile(String path, String &buf);
|
||||
extern bool appendFile(String path, String& buf);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern void readFileToSerial(const String path);
|
||||
extern void resumeAP();
|
||||
extern void stopAP();
|
||||
@@ -39,7 +39,8 @@ class Scan {
|
||||
Scan();
|
||||
|
||||
void sniffer(uint8_t* buf, uint16_t len);
|
||||
void start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continueTime, bool channelHop, uint8_t channel);
|
||||
void start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continueTime, bool channelHop,
|
||||
uint8_t channel);
|
||||
void start(uint8_t mode);
|
||||
|
||||
void setup();
|
||||
@@ -69,6 +70,7 @@ class Scan {
|
||||
|
||||
uint16_t deauths = 0;
|
||||
uint16_t packets = 0;
|
||||
|
||||
private:
|
||||
SimpleList<uint16_t>* list; // packet list
|
||||
|
||||
@@ -93,7 +95,4 @@ class Scan {
|
||||
String FILE_PATH = "/scan.json";
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // ifndef Scan_h
|
||||
@@ -4,12 +4,15 @@
|
||||
A short introduction for the reader:
|
||||
This class is a huuuuuuuge mess of if statements!!!!!1!eleven
|
||||
But it works and I tried to make it as compact as possible.
|
||||
If someone was able to make an Arduino framework for parsing an input string in different commands with certain rules,
|
||||
required- and optional parameters of different datatypes to run different callback functions... shoot me a quick message on GitHub or Twitter: @spacehuhn!
|
||||
If someone was able to make an Arduino framework for parsing an input string in different commands with certain
|
||||
rules,
|
||||
required- and optional parameters of different datatypes to run different callback functions... shoot me a quick
|
||||
message on GitHub or Twitter: @spacehuhn!
|
||||
PS: the framework has to be good in both CPU performance and RAM usage, otherwise it's useless. Good luck!
|
||||
I already wasted way too much time trying to come up with the best way of programming this, so I will just keep it that way for now.
|
||||
I already wasted way too much time trying to come up with the best way of programming this, so I will just keep it
|
||||
that way for now.
|
||||
Also: NEVER CHANGE A RUNNING SYSTEM!
|
||||
*/
|
||||
*/
|
||||
|
||||
SerialInterface::SerialInterface() {
|
||||
list = new SimpleList<String>;
|
||||
@@ -47,29 +50,28 @@ void SerialInterface::parameterError(String parameter) {
|
||||
}
|
||||
|
||||
bool SerialInterface::isInt(String str) {
|
||||
if (eqls(str,STR_TRUE) || eqls(str,STR_FALSE))
|
||||
return true;
|
||||
if (eqls(str, STR_TRUE) || eqls(str, STR_FALSE)) return true;
|
||||
|
||||
for (uint32_t i = 0; i < str.length(); i++)
|
||||
if (!isDigit(str.charAt(i))) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int SerialInterface::toInt(String str) {
|
||||
if (eqls(str,STR_TRUE))
|
||||
return 1;
|
||||
else if (eqls(str,STR_FALSE))
|
||||
return 0;
|
||||
else
|
||||
return str.toInt();
|
||||
if (eqls(str, STR_TRUE)) return 1;
|
||||
else if (eqls(str, STR_FALSE)) return 0;
|
||||
else return str.toInt();
|
||||
}
|
||||
|
||||
uint32_t SerialInterface::getTime(String time) {
|
||||
int value = time.toInt();
|
||||
|
||||
if (value < 0) value = -value;
|
||||
if (time.substring(time.length() - 1).equalsIgnoreCase(String(S)))
|
||||
value *= 1000;
|
||||
else if (time.substring(time.length() - 3).equalsIgnoreCase(str(STR_MIN)) || time.charAt(time.length() - 1) == M)
|
||||
value *= 60000;
|
||||
|
||||
if (time.substring(time.length() - 1).equalsIgnoreCase(String(S))) value *= 1000;
|
||||
else if (time.substring(time.length() - 3).equalsIgnoreCase(str(STR_MIN)) ||
|
||||
(time.charAt(time.length() - 1) == M)) value *= 60000;
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -90,16 +92,18 @@ void SerialInterface::stopScript() {
|
||||
|
||||
void SerialInterface::update() {
|
||||
if (executing) {
|
||||
if (execPath.charAt(0) != SLASH)
|
||||
execPath = SLASH + execPath;
|
||||
if (execPath.charAt(0) != SLASH) execPath = SLASH + execPath;
|
||||
prnt(CLI_EXECUTING);
|
||||
prntln(execPath);
|
||||
File f = SPIFFS.open(execPath, "r");
|
||||
|
||||
if (f.size() > 0) {
|
||||
String line;
|
||||
char tmp;
|
||||
|
||||
while (f.available()) {
|
||||
tmp = f.read();
|
||||
|
||||
if (tmp == NEWLINE) {
|
||||
runCommands(line);
|
||||
line = String();
|
||||
@@ -113,16 +117,15 @@ void SerialInterface::update() {
|
||||
f.close();
|
||||
executing = false;
|
||||
|
||||
if(continuously) prntln(CLI_SCRIPT_DONE_CONTINUE);
|
||||
if (continuously) prntln(CLI_SCRIPT_DONE_CONTINUE);
|
||||
else prntln(CLI_SCRIPT_DONE);
|
||||
|
||||
loopTime = currentTime;
|
||||
} else {
|
||||
if (enabled && Serial.available() > 0)
|
||||
runCommands(Serial.readStringUntil(NEWLINE));
|
||||
if (enabled && (Serial.available() > 0)) runCommands(Serial.readStringUntil(NEWLINE));
|
||||
|
||||
if (continuously) {
|
||||
if (currentTime - loopTime > continueTime)
|
||||
executing = true;
|
||||
if (currentTime - loopTime > continueTime) executing = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,7 +135,8 @@ void SerialInterface::runCommands(String input) {
|
||||
|
||||
for (uint32_t i = 0; i < input.length(); i++) {
|
||||
// when 2 semicolons in a row without a backslash escaping the first
|
||||
if (input.charAt(i) == SEMICOLON && input.charAt(i + 1) == SEMICOLON && input.charAt(i - 1) != BACKSLASH) {
|
||||
if ((input.charAt(i) == SEMICOLON) && (input.charAt(i + 1) == SEMICOLON) &&
|
||||
(input.charAt(i - 1) != BACKSLASH)) {
|
||||
runCommand(tmp);
|
||||
tmp = String();
|
||||
i++;
|
||||
@@ -142,6 +146,7 @@ void SerialInterface::runCommands(String input) {
|
||||
}
|
||||
|
||||
tmp.replace(BACKSLASH + SEMICOLON + SEMICOLON, SEMICOLON + SEMICOLON);
|
||||
|
||||
if (tmp.length() > 0) runCommand(tmp);
|
||||
}
|
||||
|
||||
@@ -156,28 +161,31 @@ void SerialInterface::runCommand(String input) {
|
||||
bool withinQuotes = false;
|
||||
bool escaped = false;
|
||||
char c;
|
||||
|
||||
for (uint32_t i = 0; i < input.length() && i < 512; i++) {
|
||||
c = input.charAt(i);
|
||||
|
||||
// when char is an unescaped
|
||||
if(!escaped && c == BACKSLASH){
|
||||
if (!escaped && (c == BACKSLASH)) {
|
||||
escaped = true;
|
||||
}
|
||||
|
||||
// (when char is a unescaped space AND it's not within quotes) OR char is \r or \n
|
||||
else if ((c == SPACE && !escaped && !withinQuotes) || c == CARRIAGERETURN || c == NEWLINE) {
|
||||
else if (((c == SPACE) && !escaped && !withinQuotes) || (c == CARRIAGERETURN) || (c == NEWLINE)) {
|
||||
// when tmp string isn't empty, add it to the list
|
||||
if (tmp.length() > 0){
|
||||
if (tmp.length() > 0) {
|
||||
list->add(tmp);
|
||||
tmp = String(); // reset tmp string
|
||||
}
|
||||
}
|
||||
|
||||
// when char is an unescaped "
|
||||
else if(c == DOUBLEQUOTES && !escaped){
|
||||
else if ((c == DOUBLEQUOTES) && !escaped) {
|
||||
// update wheter or not the following chars are within quotes or not
|
||||
withinQuotes = !withinQuotes;
|
||||
if(tmp.length() == 0 && !withinQuotes) tmp += SPACE; // when exiting quotes and tmp string is empty, add a space
|
||||
|
||||
if ((tmp.length() == 0) && !withinQuotes) tmp += SPACE; // when exiting quotes and tmp string is empty, add
|
||||
// a space
|
||||
}
|
||||
|
||||
// add character to tmp string
|
||||
@@ -199,7 +207,7 @@ void SerialInterface::runCommand(String input) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(settings.getSerialEcho()){
|
||||
if (settings.getSerialEcho()) {
|
||||
// print command
|
||||
prnt(CLI_INPUT_PREFIX);
|
||||
prntln(input);
|
||||
@@ -286,7 +294,8 @@ void SerialInterface::runCommand(String input) {
|
||||
continueTime = getTime(list->get(i));
|
||||
} else if (eqlsCMD(i, CLI_CHANNEL)) {
|
||||
i++;
|
||||
if(!eqlsCMD(i, CLI_ALL)){
|
||||
|
||||
if (!eqlsCMD(i, CLI_ALL)) {
|
||||
channelHop = false;
|
||||
channel = list->get(i).toInt();
|
||||
}
|
||||
@@ -340,12 +349,12 @@ void SerialInterface::runCommand(String input) {
|
||||
int mode = 0; // aps = 0, stations = 1, names = 2
|
||||
int id = -1; // -1 = all, -2 name string
|
||||
|
||||
if (list->size() == 1 || eqlsCMD(1, CLI_ALL)) {
|
||||
if ((list->size() == 1) || eqlsCMD(1, CLI_ALL)) {
|
||||
select ? scan.selectAll() : scan.deselectAll();
|
||||
return;
|
||||
}
|
||||
|
||||
if (list->size() == 2 || eqlsCMD(2, CLI_ALL)) id = -1;
|
||||
if ((list->size() == 2) || eqlsCMD(2, CLI_ALL)) id = -1;
|
||||
else if (!isInt(list->get(2))) id = -2;
|
||||
else id = list->get(2).toInt();
|
||||
|
||||
@@ -362,7 +371,7 @@ void SerialInterface::runCommand(String input) {
|
||||
if (mode == 0) select ? accesspoints.selectAll() : accesspoints.deselectAll();
|
||||
else if (mode == 1) select ? stations.selectAll() : stations.deselectAll();
|
||||
else if (mode == 2) select ? names.selectAll() : names.deselectAll();
|
||||
} else if (id == -2 && mode == 2) {
|
||||
} else if ((id == -2) && (mode == 2)) {
|
||||
select ? names.select(list->get(2)) : names.deselect(list->get(2));
|
||||
} else {
|
||||
parameterError(list->get(1) + SPACE + list->get(2));
|
||||
@@ -370,17 +379,16 @@ void SerialInterface::runCommand(String input) {
|
||||
}
|
||||
|
||||
// ===== ADD ===== //
|
||||
else if (list->size() >= 3 && eqlsCMD(0, CLI_ADD) && eqlsCMD(1, CLI_SSID)) {
|
||||
|
||||
else if ((list->size() >= 3) && eqlsCMD(0, CLI_ADD) && eqlsCMD(1, CLI_SSID)) {
|
||||
// add ssid -s [-f]
|
||||
if(eqlsCMD(2, CLI_SELECT)){
|
||||
if (eqlsCMD(2, CLI_SELECT)) {
|
||||
bool force = eqlsCMD(3, CLI_FORCE);
|
||||
ssids.cloneSelected(force);
|
||||
}
|
||||
|
||||
// add ssid <ssid> [-wpa2] [-cl <clones>] [-f]
|
||||
// add ssid -ap <id> [-cl <clones>] [-f]
|
||||
else{
|
||||
else {
|
||||
String ssid = list->get(2);
|
||||
bool wpa2 = false;
|
||||
bool force = false;
|
||||
@@ -410,7 +418,7 @@ void SerialInterface::runCommand(String input) {
|
||||
// add name <name> [-ap <id>] [-s] [-f]
|
||||
// add name <name> [-st <id>] [-s] [-f]
|
||||
// add name <name> [-m <mac>] [-ch <channel>] [-b <bssid>] [-s] [-f]
|
||||
else if (list->size() >= 3 && eqlsCMD(0, CLI_ADD) && eqlsCMD(1, CLI_NAME)) {
|
||||
else if ((list->size() >= 3) && eqlsCMD(0, CLI_ADD) && eqlsCMD(1, CLI_NAME)) {
|
||||
String name = list->get(2);
|
||||
String mac;
|
||||
uint8_t channel = wifi_channel;
|
||||
@@ -427,10 +435,10 @@ void SerialInterface::runCommand(String input) {
|
||||
}
|
||||
else if (eqlsCMD(i, CLI_CHANNEL)) channel = (uint8_t)list->get(i + 1).toInt();
|
||||
else if (eqlsCMD(i, CLI_BSSID)) bssid = list->get(i + 1);
|
||||
else if (eqlsCMD(i, CLI_SELECT)){
|
||||
else if (eqlsCMD(i, CLI_SELECT)) {
|
||||
selected = true;
|
||||
i--;
|
||||
} else if (eqlsCMD(i, CLI_FORCE)){
|
||||
} else if (eqlsCMD(i, CLI_FORCE)) {
|
||||
force = true;
|
||||
i--;
|
||||
} else {
|
||||
@@ -447,13 +455,13 @@ void SerialInterface::runCommand(String input) {
|
||||
|
||||
// ===== SET NAME ==== //
|
||||
// set name <id> <newname>
|
||||
else if (list->size() == 4 && eqlsCMD(0, CLI_SET) && eqlsCMD(1, CLI_NAME)) {
|
||||
else if ((list->size() == 4) && eqlsCMD(0, CLI_SET) && eqlsCMD(1, CLI_NAME)) {
|
||||
names.setName(list->get(2).toInt(), list->get(3));
|
||||
}
|
||||
|
||||
// ===== REPLACE ===== //
|
||||
// replace name <id> [-n <name>} [-m <mac>] [-ch <channel>] [-b <bssid>] [-s]
|
||||
else if (list->size() >= 4 && eqlsCMD(0, CLI_REPLACE) && eqlsCMD(1, CLI_NAME)) {
|
||||
else if ((list->size() >= 4) && eqlsCMD(0, CLI_REPLACE) && eqlsCMD(1, CLI_NAME)) {
|
||||
int id = list->get(2).toInt();
|
||||
String name = names.getName(id);
|
||||
String mac = names.getMacStr(id);
|
||||
@@ -466,7 +474,7 @@ void SerialInterface::runCommand(String input) {
|
||||
else if (eqlsCMD(i, CLI_MAC)) mac = list->get(i + 1);
|
||||
else if (eqlsCMD(i, CLI_CHANNEL)) channel = (uint8_t)list->get(i + 1).toInt();
|
||||
else if (eqlsCMD(i, CLI_BSSID)) bssid = list->get(i + 1);
|
||||
else if (eqlsCMD(i, CLI_SELECT)){
|
||||
else if (eqlsCMD(i, CLI_SELECT)) {
|
||||
selected = true;
|
||||
i--;
|
||||
} else {
|
||||
@@ -476,32 +484,32 @@ void SerialInterface::runCommand(String input) {
|
||||
i++;
|
||||
}
|
||||
|
||||
names.replace(id,mac, name, bssid, channel, selected);
|
||||
names.replace(id, mac, name, bssid, channel, selected);
|
||||
}
|
||||
|
||||
// replace ssid <id> [-n <name>} [-wpa2]
|
||||
else if (list->size() >= 3 && eqlsCMD(0, CLI_REPLACE) && eqlsCMD(1, CLI_SSID)) {
|
||||
else if ((list->size() >= 3) && eqlsCMD(0, CLI_REPLACE) && eqlsCMD(1, CLI_SSID)) {
|
||||
int id = list->get(2).toInt();
|
||||
String name = ssids.getName(id);
|
||||
bool wpa2 = false;
|
||||
|
||||
for (int i = 3; i < list->size(); i++) {
|
||||
if (eqlsCMD(i, CLI_NAME)){
|
||||
if (eqlsCMD(i, CLI_NAME)) {
|
||||
name = list->get(i + 1);
|
||||
i++;
|
||||
}else if(eqlsCMD(i, CLI_WPA2)){
|
||||
} else if (eqlsCMD(i, CLI_WPA2)) {
|
||||
wpa2 = true;
|
||||
}
|
||||
}
|
||||
|
||||
ssids.replace(id,name, wpa2);
|
||||
ssids.replace(id, name, wpa2);
|
||||
}
|
||||
|
||||
// ===== REMOVE ===== //
|
||||
// remove <type> [-a]
|
||||
// remove <type> <id>
|
||||
else if (list->size() >= 2 && eqlsCMD(0, CLI_REMOVE)) {
|
||||
if (list->size() == 2 || (eqlsCMD(2, CLI_ALL))) {
|
||||
else if ((list->size() >= 2) && eqlsCMD(0, CLI_REMOVE)) {
|
||||
if ((list->size() == 2) || (eqlsCMD(2, CLI_ALL))) {
|
||||
if (eqlsCMD(1, CLI_SSID)) ssids.removeAll();
|
||||
else if (eqlsCMD(1, CLI_NAME)) names.removeAll();
|
||||
else if (eqlsCMD(1, CLI_AP)) accesspoints.removeAll();
|
||||
@@ -518,7 +526,7 @@ void SerialInterface::runCommand(String input) {
|
||||
|
||||
// ===== RANDOM ===== //
|
||||
// enable random <interval>
|
||||
else if (eqlsCMD(0, CLI_ENABLE) && eqlsCMD(1, CLI_RANDOM) && list->size() == 3) {
|
||||
else if (eqlsCMD(0, CLI_ENABLE) && eqlsCMD(1, CLI_RANDOM) && (list->size() == 3)) {
|
||||
ssids.enableRandom(getTime(list->get(2)));
|
||||
}
|
||||
|
||||
@@ -535,18 +543,22 @@ void SerialInterface::runCommand(String input) {
|
||||
uint32_t i = 0;
|
||||
uint8_t multi = 1;
|
||||
uint8_t end = random(80, 99);
|
||||
|
||||
if (list->get(1).toInt() > 1) multi = list->get(1).toInt();
|
||||
|
||||
while (true) {
|
||||
if (i % 10 == 0 && i > 0) {
|
||||
if ((i % 10 == 0) && (i > 0)) {
|
||||
char s[100];
|
||||
sprintf(s,str(CLI_RICE_OUTPUT).c_str(), i / 10);
|
||||
sprintf(s, str(CLI_RICE_OUTPUT).c_str(), i / 10);
|
||||
prnt(String(s));
|
||||
|
||||
if ((i / 10) == end) {
|
||||
prnt(CLI_RICE_ERROR);
|
||||
prnt(String(random(16, 255), HEX));
|
||||
prnt(String(random(16, 255), HEX));
|
||||
prnt(String(random(16, 255), HEX));
|
||||
prntln(String(random(16, 255), HEX));
|
||||
|
||||
for (int i = 1; i <= 32; i++) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int i = 1; i <= 8; i++) {
|
||||
@@ -575,14 +587,15 @@ void SerialInterface::runCommand(String input) {
|
||||
// ===== LOAD/SAVE ===== //
|
||||
// save [<type>] [<file>]
|
||||
// load [<type>] [<file>]
|
||||
else if ((eqlsCMD(0, CLI_LOAD) || eqlsCMD(0, CLI_SAVE)) && list->size() >= 1 && list->size() <= 3) {
|
||||
else if ((eqlsCMD(0, CLI_LOAD) || eqlsCMD(0, CLI_SAVE)) && (list->size() >= 1) && (list->size() <= 3)) {
|
||||
bool load = eqlsCMD(0, CLI_LOAD);
|
||||
|
||||
if (list->size() == 1 || eqlsCMD(1, CLI_ALL)) {
|
||||
if ((list->size() == 1) || eqlsCMD(1, CLI_ALL)) {
|
||||
load ? ssids.load() : ssids.save(false);
|
||||
load ? names.load() : names.save(false);
|
||||
load ? settings.load() : settings.save(false);
|
||||
if(!load) scan.save(false);
|
||||
|
||||
if (!load) scan.save(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -640,12 +653,12 @@ void SerialInterface::runCommand(String input) {
|
||||
|
||||
// ===== GET/SET ===== //
|
||||
// get <setting>
|
||||
else if (eqlsCMD(0, CLI_GET) && list->size() == 2) {
|
||||
else if (eqlsCMD(0, CLI_GET) && (list->size() == 2)) {
|
||||
prntln(settings.get(list->get(1).c_str()));
|
||||
}
|
||||
|
||||
// set <setting> <value>
|
||||
else if (eqlsCMD(0, CLI_SET) && list->size() == 3) {
|
||||
else if (eqlsCMD(0, CLI_SET) && (list->size() == 3)) {
|
||||
settings.set(list->get(1).c_str(), list->get(2));
|
||||
}
|
||||
|
||||
@@ -657,10 +670,9 @@ void SerialInterface::runCommand(String input) {
|
||||
// ===== STOP ===== //
|
||||
// stop [<mode>]
|
||||
else if (eqlsCMD(0, CLI_STOP)) {
|
||||
#ifdef DIGITAL_LED
|
||||
led.setMode(LED_MODE_IDLE, true);
|
||||
#endif
|
||||
if (list->size() >= 2 && !(eqlsCMD(1, CLI_ALL))) {
|
||||
led->setMode(led->LED_MODE::IDLE, true);
|
||||
|
||||
if ((list->size() >= 2) && !(eqlsCMD(1, CLI_ALL))) {
|
||||
for (int i = 1; i < list->size(); i++) {
|
||||
if (eqlsCMD(i, CLI_SCAN)) scan.stop();
|
||||
else if (eqlsCMD(i, CLI_ATTACK)) attack.stop();
|
||||
@@ -679,7 +691,9 @@ void SerialInterface::runCommand(String input) {
|
||||
else if (eqlsCMD(0, CLI_SYSINFO)) {
|
||||
prntln(CLI_SYSTEM_INFO);
|
||||
char s[150];
|
||||
sprintf(s,str(CLI_SYSTEM_OUTPUT).c_str(), 81920 - system_get_free_heap_size(), 100 - system_get_free_heap_size() / (81920 / 100), system_get_free_heap_size(), system_get_free_heap_size() / (81920 / 100), 81920);
|
||||
sprintf(s, str(CLI_SYSTEM_OUTPUT).c_str(), 81920 - system_get_free_heap_size(),
|
||||
100 - system_get_free_heap_size() / (81920 / 100), system_get_free_heap_size(),
|
||||
system_get_free_heap_size() / (81920 / 100), 81920);
|
||||
prntln(String(s));
|
||||
|
||||
prnt(CLI_SYSTEM_CHANNEL);
|
||||
@@ -697,12 +711,15 @@ void SerialInterface::runCommand(String input) {
|
||||
|
||||
FSInfo fs_info;
|
||||
SPIFFS.info(fs_info);
|
||||
sprintf(s,str(CLI_SYSTEM_RAM_OUT).c_str(), fs_info.usedBytes, fs_info.usedBytes / (fs_info.totalBytes / 100), fs_info.totalBytes - fs_info.usedBytes, (fs_info.totalBytes - fs_info.usedBytes) / (fs_info.totalBytes / 100), fs_info.totalBytes);
|
||||
sprintf(s, str(
|
||||
CLI_SYSTEM_RAM_OUT).c_str(), fs_info.usedBytes, fs_info.usedBytes / (fs_info.totalBytes / 100), fs_info.totalBytes - fs_info.usedBytes,
|
||||
(fs_info.totalBytes - fs_info.usedBytes) / (fs_info.totalBytes / 100), fs_info.totalBytes);
|
||||
prnt(String(s));
|
||||
sprintf(s,str(CLI_SYSTEM_SPIFFS_OUT).c_str(), fs_info.blockSize, fs_info.pageSize);
|
||||
sprintf(s, str(CLI_SYSTEM_SPIFFS_OUT).c_str(), fs_info.blockSize, fs_info.pageSize);
|
||||
prnt(String(s));
|
||||
prntln(CLI_FILES);
|
||||
Dir dir = SPIFFS.openDir(String(SLASH));
|
||||
|
||||
while (dir.next()) {
|
||||
prnt(String(SPACE) + String(SPACE) + dir.fileName() + String(SPACE));
|
||||
File f = dir.openFile("r");
|
||||
@@ -722,10 +739,9 @@ void SerialInterface::runCommand(String input) {
|
||||
// ===== CLEAR ===== //
|
||||
// clear
|
||||
else if (eqlsCMD(0, CLI_CLEAR)) {
|
||||
for (int i = 0; i < 100; i++)
|
||||
prnt(HASHSIGN);
|
||||
for (int i = 0; i < 60; i++)
|
||||
prntln();
|
||||
for (int i = 0; i < 100; i++) prnt(HASHSIGN);
|
||||
|
||||
for (int i = 0; i < 60; i++) prntln();
|
||||
}
|
||||
|
||||
// ===== REBOOT ===== //
|
||||
@@ -744,7 +760,7 @@ void SerialInterface::runCommand(String input) {
|
||||
|
||||
// ===== DELETE ==== //
|
||||
// delete <file> [<lineFrom>] [<lineTo>]
|
||||
else if (list->size() >= 2 && eqlsCMD(0, CLI_DELETE)) {
|
||||
else if ((list->size() >= 2) && eqlsCMD(0, CLI_DELETE)) {
|
||||
if (list->size() == 2) {
|
||||
// remove whole file
|
||||
if (removeFile(list->get(1))) {
|
||||
@@ -758,6 +774,7 @@ void SerialInterface::runCommand(String input) {
|
||||
// remove certain lines
|
||||
int beginLine = list->get(2).toInt();
|
||||
int endLine = list->size() == 4 ? list->get(3).toInt() : beginLine;
|
||||
|
||||
if (removeLines(list->get(1), beginLine, endLine)) {
|
||||
prnt(CLI_REMOVING_LINES);
|
||||
prnt(beginLine);
|
||||
@@ -773,33 +790,35 @@ void SerialInterface::runCommand(String input) {
|
||||
|
||||
// ===== COPY ==== //
|
||||
// delete <file> <newfile>
|
||||
else if (list->size() == 3 && eqlsCMD(0, CLI_COPY)) {
|
||||
if(copyFile(list->get(1), list->get(2))){
|
||||
else if ((list->size() == 3) && eqlsCMD(0, CLI_COPY)) {
|
||||
if (copyFile(list->get(1), list->get(2))) {
|
||||
prntln(CLI_COPIED_FILES);
|
||||
}else{
|
||||
} else {
|
||||
prntln(CLI_ERROR_COPYING);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== RENAME ==== //
|
||||
// delete <file> <newfile>
|
||||
else if (list->size() == 3 && eqlsCMD(0, CLI_RENAME)) {
|
||||
if(renameFile(list->get(1), list->get(2))){
|
||||
else if ((list->size() == 3) && eqlsCMD(0, CLI_RENAME)) {
|
||||
if (renameFile(list->get(1), list->get(2))) {
|
||||
prntln(CLI_RENAMED_FILE);
|
||||
}else{
|
||||
} else {
|
||||
prntln(CLI_ERROR_RENAMING_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== WRITE ==== //
|
||||
// write <file> <commands>
|
||||
else if (list->size() >= 3 && eqlsCMD(0, CLI_WRITE)) {
|
||||
else if ((list->size() >= 3) && eqlsCMD(0, CLI_WRITE)) {
|
||||
String path = list->get(1);
|
||||
String buf = String();
|
||||
|
||||
int listSize = list->size();
|
||||
|
||||
for (int i = 2; i < listSize; i++) {
|
||||
buf += list->get(i);
|
||||
|
||||
if (i < listSize - 1) buf += SPACE;
|
||||
}
|
||||
|
||||
@@ -814,13 +833,16 @@ void SerialInterface::runCommand(String input) {
|
||||
|
||||
// ===== REPLACE ==== //
|
||||
// replace <file> <line> <new-content>
|
||||
else if (list->size() >= 4 && eqlsCMD(0, CLI_REPLACE)) {
|
||||
else if ((list->size() >= 4) && eqlsCMD(0, CLI_REPLACE)) {
|
||||
int line = list->get(2).toInt();
|
||||
String tmp = String();
|
||||
|
||||
for (int i = 3; i < list->size(); i++) {
|
||||
tmp += list->get(i);
|
||||
|
||||
if (i < list->size() - 1) tmp += SPACE;
|
||||
}
|
||||
|
||||
if (replaceLine(list->get(1), line, tmp)) {
|
||||
prnt(CLI_REPLACED_LINE);
|
||||
prnt(line);
|
||||
@@ -834,22 +856,25 @@ void SerialInterface::runCommand(String input) {
|
||||
|
||||
// ===== RUN ==== //
|
||||
// run <file> [continue <num>]
|
||||
else if (!executing && list->size() >= 2 && eqlsCMD(0, CLI_RUN)) {
|
||||
else if (!executing && (list->size() >= 2) && eqlsCMD(0, CLI_RUN)) {
|
||||
executing = true;
|
||||
execPath = list->get(1);
|
||||
|
||||
if (eqlsCMD(2, CLI_CONTINUE)) {
|
||||
continuously = true;
|
||||
continueTime = 10000;
|
||||
if(list->size() == 3){
|
||||
|
||||
if (list->size() == 3) {
|
||||
continueTime = getTime(list->get(3));
|
||||
if(continueTime < 1000) continueTime = 1000;
|
||||
|
||||
if (continueTime < 1000) continueTime = 1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===== PRINT ==== //
|
||||
// print <file> [<lines>]
|
||||
else if (list->size() >= 2 && eqlsCMD(0, CLI_PRINT)) {
|
||||
else if ((list->size() >= 2) && eqlsCMD(0, CLI_PRINT)) {
|
||||
readFileToSerial(list->get(1), eqlsCMD(2, CLI_LINE));
|
||||
prntln();
|
||||
}
|
||||
@@ -868,7 +893,7 @@ void SerialInterface::runCommand(String input) {
|
||||
|
||||
// ===== SEND ===== //
|
||||
// send deauth <apMac> <stMac> <rason> <channel>
|
||||
else if (eqlsCMD(0, CLI_SEND) && list->size() == 6 && eqlsCMD(1, CLI_DEAUTH)) {
|
||||
else if (eqlsCMD(0, CLI_SEND) && (list->size() == 6) && eqlsCMD(1, CLI_DEAUTH)) {
|
||||
uint8_t apMac[6];
|
||||
uint8_t stMac[6];
|
||||
strToMac(list->get(2), apMac);
|
||||
@@ -883,13 +908,13 @@ void SerialInterface::runCommand(String input) {
|
||||
}
|
||||
|
||||
// send beacon <mac> <ssid> <ch> [wpa2]
|
||||
else if (eqlsCMD(0, CLI_SEND) && list->size() >= 5 && eqlsCMD(1, CLI_BEACON)) {
|
||||
else if (eqlsCMD(0, CLI_SEND) && (list->size() >= 5) && eqlsCMD(1, CLI_BEACON)) {
|
||||
uint8_t mac[6];
|
||||
strToMac(list->get(2), mac);
|
||||
uint8_t channel = list->get(4).toInt();
|
||||
String ssid = list->get(3);
|
||||
for (int i = ssid.length(); i < 32; i++)
|
||||
ssid += SPACE;
|
||||
|
||||
for (int i = ssid.length(); i < 32; i++) ssid += SPACE;
|
||||
prnt(CLI_SENDING_BEACON);
|
||||
prnt(list->get(3));
|
||||
prntln(DOUBLEQUOTES);
|
||||
@@ -897,13 +922,13 @@ void SerialInterface::runCommand(String input) {
|
||||
}
|
||||
|
||||
// send probe <mac> <ssid> <ch>
|
||||
else if (eqlsCMD(0, CLI_SEND) && list->size() == 5 && eqlsCMD(1, CLI_PROBE)) {
|
||||
else if (eqlsCMD(0, CLI_SEND) && (list->size() == 5) && eqlsCMD(1, CLI_PROBE)) {
|
||||
uint8_t mac[6];
|
||||
strToMac(list->get(2), mac);
|
||||
uint8_t channel = list->get(4).toInt();
|
||||
String ssid = list->get(3);
|
||||
for (int i = ssid.length(); i < 32; i++)
|
||||
ssid += SPACE;
|
||||
|
||||
for (int i = ssid.length(); i < 32; i++) ssid += SPACE;
|
||||
prnt(CLI_SENDING_PROBE);
|
||||
prnt(list->get(3));
|
||||
prntln(DOUBLEQUOTES);
|
||||
@@ -918,65 +943,55 @@ void SerialInterface::runCommand(String input) {
|
||||
uint16_t packetSize = packetStr.length() / 2;
|
||||
uint8_t packet[packetSize];
|
||||
|
||||
for (int i = 0; i < packetSize; i++)
|
||||
packet[i] = strtoul((packetStr.substring(i * 2, i * 2 + 2)).c_str(), NULL, 16);
|
||||
for (int i = 0; i < packetSize; i++) packet[i] = strtoul((packetStr.substring(i * 2,
|
||||
i * 2 + 2)).c_str(), NULL, 16);
|
||||
|
||||
if (attack.sendPacket(packet, packetSize, wifi_channel, 10)){
|
||||
if (attack.sendPacket(packet, packetSize, wifi_channel, 10)) {
|
||||
prntln(CLI_CUSTOM_SENT);
|
||||
counter++;
|
||||
} else{
|
||||
} else {
|
||||
prntln(CLI_CUSTOM_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== LED ===== //
|
||||
// led <r> <g> <b> [<brightness>]
|
||||
else if (list->size() >= 4 && list->size() <= 5 && eqlsCMD(0, CLI_LED)) {
|
||||
else if ((list->size() >= 4) && (list->size() <= 5) && eqlsCMD(0, CLI_LED)) {
|
||||
if (list->size() == 4) {
|
||||
#ifdef DIGITAL_LED
|
||||
led.setColor(list->get(1).toInt(), list->get(2).toInt(), list->get(3).toInt());
|
||||
#endif
|
||||
led->setColor(list->get(1).toInt(), list->get(2).toInt(), list->get(3).toInt(), true);
|
||||
} else {
|
||||
#ifdef DIGITAL_LED
|
||||
led.setColor(list->get(1).toInt(), list->get(2).toInt(), list->get(3).toInt(), list->get(4).toInt());
|
||||
#endif
|
||||
led->setColor(list->get(1).toInt(), list->get(2).toInt(), list->get(3).toInt(), list->get(4).toInt(), true);
|
||||
}
|
||||
}
|
||||
|
||||
// led <#rrggbb> [<brightness>]
|
||||
else if (list->size() >= 2 && list->size() <= 3 && eqlsCMD(0, CLI_LED) && list->get(1).charAt(0) == HASHSIGN) {
|
||||
else if ((list->size() >= 2) && (list->size() <= 3) &&
|
||||
eqlsCMD(0, CLI_LED) && (list->get(1).charAt(0) == HASHSIGN)) {
|
||||
uint8_t c[3];
|
||||
strToColor(list->get(1), c);
|
||||
|
||||
if (list->size() == 2) {
|
||||
#ifdef DIGITAL_LED
|
||||
led.setColor(c[0], c[1], c[2]);
|
||||
#endif
|
||||
led->setColor(c[0], c[1], c[2], true);
|
||||
} else {
|
||||
#ifdef DIGITAL_LED
|
||||
led.setColor(c[0], c[1], c[2], list->get(2).toInt());
|
||||
#endif
|
||||
led->setColor(c[0], c[1], c[2], list->get(2).toInt(), true);
|
||||
}
|
||||
}
|
||||
|
||||
// led <enable/disable>
|
||||
else if (list->size() == 2 && eqlsCMD(0, CLI_LED)) {
|
||||
else if ((list->size() == 2) && eqlsCMD(0, CLI_LED)) {
|
||||
if (eqlsCMD(1, CLI_ENABLE)) {
|
||||
#ifdef DIGITAL_LED
|
||||
led.tempEnable();
|
||||
#endif
|
||||
led->tempEnable();
|
||||
} else if (eqlsCMD(1, CLI_DISABLE)) {
|
||||
#ifdef DIGITAL_LED
|
||||
led.tempDisable();
|
||||
#endif
|
||||
led->tempDisable();
|
||||
} else {
|
||||
parameterError(list->get(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ===== DELAY ===== //
|
||||
else if (list->size() == 2 && eqlsCMD(0, CLI_DELAY)) {
|
||||
else if ((list->size() == 2) && eqlsCMD(0, CLI_DELAY)) {
|
||||
uint32_t endTime = currentTime + getTime(list->get(1));
|
||||
|
||||
while (currentTime < endTime) {
|
||||
// ------- loop function ----- //
|
||||
currentTime = millis();
|
||||
@@ -985,12 +1000,10 @@ void SerialInterface::runCommand(String input) {
|
||||
scan.update(); // run scan
|
||||
attack.update(); // run attacks
|
||||
ssids.update(); // run random mode, if enabled
|
||||
#ifdef DIGITAL_LED
|
||||
led.update(); // update LED color
|
||||
#endif
|
||||
led->update(); // update LED color
|
||||
|
||||
// auto-save
|
||||
if (settings.getAutosave() && currentTime - autosaveTime > settings.getAutosaveTime()) {
|
||||
if (settings.getAutosave() && (currentTime - autosaveTime > settings.getAutosaveTime())) {
|
||||
autosaveTime = currentTime;
|
||||
names.save(false);
|
||||
ssids.save(false);
|
||||
@@ -1005,11 +1018,14 @@ void SerialInterface::runCommand(String input) {
|
||||
else if (eqlsCMD(0, CLI_DRAW)) {
|
||||
int height = 25;
|
||||
int width = 2;
|
||||
|
||||
if (list->size() >= 2) height = list->get(1).toInt();
|
||||
|
||||
if (list->size() >= 3) width = list->get(2).toInt();
|
||||
double scale = scan.getScaleFactor(height);
|
||||
|
||||
prnt(String(DASH) + String(DASH) + String(DASH) + String(DASH) + String(VERTICALBAR)); // ----|
|
||||
|
||||
for (int j = 0; j < SCAN_PACKET_LIST_SIZE; j++) {
|
||||
for (int k = 0; k < width; k++) prnt(EQUALS);
|
||||
}
|
||||
@@ -1017,10 +1033,14 @@ void SerialInterface::runCommand(String input) {
|
||||
|
||||
for (int i = height; i >= 0; i--) {
|
||||
char s[200];
|
||||
if (i == height) sprintf(s,str(CLI_DRAW_OUTPUT).c_str(), scan.getMaxPacket() > (uint32_t)height ? scan.getMaxPacket() : (uint32_t)height);
|
||||
else if (i == height / 2) sprintf(s,str(CLI_DRAW_OUTPUT).c_str(), scan.getMaxPacket() > (uint32_t)height ? scan.getMaxPacket()/2 : (uint32_t)height/2);
|
||||
else if (i == 0) sprintf(s,str(CLI_DRAW_OUTPUT).c_str(), 0);
|
||||
else{
|
||||
|
||||
if (i == height) sprintf(s, str(CLI_DRAW_OUTPUT).c_str(),
|
||||
scan.getMaxPacket() > (uint32_t)height ? scan.getMaxPacket() : (uint32_t)height);
|
||||
else if (i == height / 2) sprintf(s, str(CLI_DRAW_OUTPUT).c_str(),
|
||||
scan.getMaxPacket() >
|
||||
(uint32_t)height ? scan.getMaxPacket() / 2 : (uint32_t)height / 2);
|
||||
else if (i == 0) sprintf(s, str(CLI_DRAW_OUTPUT).c_str(), 0);
|
||||
else {
|
||||
s[0] = SPACE;
|
||||
s[1] = SPACE;
|
||||
s[2] = SPACE;
|
||||
@@ -1030,8 +1050,9 @@ void SerialInterface::runCommand(String input) {
|
||||
prnt(String(s));
|
||||
|
||||
prnt(VERTICALBAR);
|
||||
|
||||
for (int j = 0; j < SCAN_PACKET_LIST_SIZE; j++) {
|
||||
if (scan.getPackets(j)*scale > i) {
|
||||
if (scan.getPackets(j) * scale > i) {
|
||||
for (int k = 0; k < width; k++) prnt(HASHSIGN);
|
||||
} else {
|
||||
for (int k = 0; k < width; k++) prnt(SPACE);
|
||||
@@ -1048,14 +1069,17 @@ void SerialInterface::runCommand(String input) {
|
||||
prntln(VERTICALBAR);
|
||||
|
||||
prnt(String(SPACE) + String(SPACE) + String(SPACE) + String(SPACE) + String(VERTICALBAR));
|
||||
|
||||
for (int j = 0; j < SCAN_PACKET_LIST_SIZE; j++) {
|
||||
char s[6];
|
||||
String helper = String(PERCENT)+DASH+(String)width+D;
|
||||
if(j==0) sprintf(s,helper.c_str(),SCAN_PACKET_LIST_SIZE-1);
|
||||
else if(j==SCAN_PACKET_LIST_SIZE/2) sprintf(s,helper.c_str(),SCAN_PACKET_LIST_SIZE/2);
|
||||
else if(j==SCAN_PACKET_LIST_SIZE-1) sprintf(s,helper.c_str(),0);
|
||||
else{
|
||||
String helper = String(PERCENT) + DASH + (String)width + D;
|
||||
|
||||
if (j == 0) sprintf(s, helper.c_str(), SCAN_PACKET_LIST_SIZE - 1);
|
||||
else if (j == SCAN_PACKET_LIST_SIZE / 2) sprintf(s, helper.c_str(), SCAN_PACKET_LIST_SIZE / 2);
|
||||
else if (j == SCAN_PACKET_LIST_SIZE - 1) sprintf(s, helper.c_str(), 0);
|
||||
else {
|
||||
int k;
|
||||
|
||||
for (k = 0; k < width; k++) s[k] = SPACE;
|
||||
s[k] = ENDOFLINE;
|
||||
}
|
||||
@@ -1072,7 +1096,7 @@ void SerialInterface::runCommand(String input) {
|
||||
String password = settings.getPassword();
|
||||
int ch = wifi_channel;
|
||||
bool hidden = settings.getHidden();
|
||||
bool captivePortal = settings.getCaptivePortal();;
|
||||
bool captivePortal = settings.getCaptivePortal();
|
||||
|
||||
for (int i = 1; i < list->size(); i++) {
|
||||
if (eqlsCMD(i, CLI_PATH)) {
|
||||
@@ -1099,27 +1123,27 @@ void SerialInterface::runCommand(String input) {
|
||||
startAP(path, ssid, password, ch, hidden, captivePortal);
|
||||
}
|
||||
|
||||
//stopap
|
||||
// stopap
|
||||
else if (eqlsCMD(0, CLI_STOPAP)) {
|
||||
stopAP();
|
||||
}
|
||||
|
||||
// ===== SCREEN ===== //
|
||||
// screen mode <menu/packetmonitor/buttontest/loading>
|
||||
else if(eqlsCMD(0, CLI_SCREEN) && eqlsCMD(1,CLI_MODE)){
|
||||
if(eqlsCMD(2,CLI_MODE_BUTTONTEST)) displayUI.mode = SCREEN_MODE_BUTTON_TEST;
|
||||
else if(eqlsCMD(2,CLI_MODE_PACKETMONITOR)) displayUI.mode = SCREEN_MODE_PACKETMONITOR;
|
||||
else if(eqlsCMD(2,CLI_MODE_LOADINGSCREEN)) displayUI.mode = SCREEN_MODE_LOADSCAN;
|
||||
else if(eqlsCMD(2,CLI_MODE_MENU)) displayUI.mode = SCREEN_MODE_MENU;
|
||||
else if (eqlsCMD(0, CLI_SCREEN) && eqlsCMD(1, CLI_MODE)) {
|
||||
if (eqlsCMD(2, CLI_MODE_BUTTONTEST)) displayUI.mode = SCREEN_MODE_BUTTON_TEST;
|
||||
else if (eqlsCMD(2, CLI_MODE_PACKETMONITOR)) displayUI.mode = SCREEN_MODE_PACKETMONITOR;
|
||||
else if (eqlsCMD(2, CLI_MODE_LOADINGSCREEN)) displayUI.mode = SCREEN_MODE_LOADSCAN;
|
||||
else if (eqlsCMD(2, CLI_MODE_MENU)) displayUI.mode = SCREEN_MODE_MENU;
|
||||
else parameterError(list->get(2));
|
||||
prntln(CLI_CHANGED_SCREEN);
|
||||
}
|
||||
|
||||
// screen <on/off>
|
||||
else if(eqlsCMD(0, CLI_SCREEN) && (eqlsCMD(1,CLI_ON) || eqlsCMD(1,CLI_OFF))){
|
||||
if(eqlsCMD(1,CLI_ON)){
|
||||
else if (eqlsCMD(0, CLI_SCREEN) && (eqlsCMD(1, CLI_ON) || eqlsCMD(1, CLI_OFF))) {
|
||||
if (eqlsCMD(1, CLI_ON)) {
|
||||
displayUI.on();
|
||||
} else if(eqlsCMD(1,CLI_OFF)){
|
||||
} else if (eqlsCMD(1, CLI_OFF)) {
|
||||
displayUI.off();
|
||||
}
|
||||
}
|
||||
@@ -1130,6 +1154,7 @@ void SerialInterface::runCommand(String input) {
|
||||
prnt(input);
|
||||
prntln(CLI_ERROR_NOT_FOUND_B);
|
||||
// some debug stuff
|
||||
|
||||
/*
|
||||
Serial.println(list->get(0));
|
||||
for(int i=0;i<input.length();i++){
|
||||
@@ -1139,5 +1164,3 @@ void SerialInterface::runCommand(String input) {
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,22 +16,9 @@ extern "C" {
|
||||
#include "Scan.h"
|
||||
#include "Attack.h"
|
||||
#include "DisplayUI.h"
|
||||
#include "DigitalLed.h"
|
||||
#include "RGBLed.h"
|
||||
#include "Neopixel.h"
|
||||
|
||||
#ifdef DIGITAL_LED
|
||||
extern DigitalLed led;
|
||||
#endif
|
||||
|
||||
#ifdef RGB_LED
|
||||
extern RGBLed led;
|
||||
#endif
|
||||
|
||||
#ifdef NEOPIXEL_LED
|
||||
extern Neopixel led;
|
||||
#endif
|
||||
#include "LEDController.h"
|
||||
|
||||
extern LEDController* led;
|
||||
extern Settings settings;
|
||||
extern Names names;
|
||||
extern SSIDs ssids;
|
||||
@@ -49,9 +36,9 @@ extern void readFileToSerial(String path, bool showLineNum);
|
||||
extern bool removeFile(String path);
|
||||
extern bool copyFile(String pathFrom, String pathTo);
|
||||
extern bool renameFile(String pathFrom, String pathTo);
|
||||
extern bool appendFile(String path, String &buf);
|
||||
extern bool appendFile(String path, String& buf);
|
||||
extern bool removeLines(String path, int lineFrom, int lineTo);
|
||||
extern bool replaceLine(String path, int line, String &buf);
|
||||
extern bool replaceLine(String path, int line, String& buf);
|
||||
extern bool equalsKeyword(const char* str, const char* keyword);
|
||||
extern void printWifiStatus();
|
||||
extern void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal);
|
||||
@@ -82,7 +69,7 @@ class SerialInterface {
|
||||
uint32_t loopTime = 0;
|
||||
String execPath = "/autostart.txt";
|
||||
|
||||
struct Keyword{
|
||||
struct Keyword {
|
||||
const char* name;
|
||||
const char* shortName;
|
||||
const char* alt;
|
||||
@@ -94,7 +81,4 @@ class SerialInterface {
|
||||
bool eqlsCMD(int i, const char* keyword);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // ifndef SerialInterface_h
|
||||
@@ -10,48 +10,72 @@ void Settings::load() {
|
||||
|
||||
// check & read file
|
||||
String json = getJsonStr();
|
||||
|
||||
checkFile(FILE_PATH, json);
|
||||
JsonObject &data = parseJSONFile(FILE_PATH, jsonBuffer);
|
||||
JsonObject& data = parseJSONFile(FILE_PATH, jsonBuffer);
|
||||
|
||||
// VERSION
|
||||
version = data.get<String>("version");
|
||||
|
||||
// AP
|
||||
if(data.containsKey(keyword(S_SSID))) setSSID(data.get<String>(keyword(S_SSID)));
|
||||
if(data.containsKey(keyword(S_PASSWORD))) setPassword(data.get<String>(keyword(S_PASSWORD)));
|
||||
if(data.containsKey(keyword(S_CHANNEL))) setChannel(data.get<uint8_t>(keyword(S_CHANNEL)));
|
||||
if(data.containsKey(keyword(S_HIDDEN))) setHidden(data.get<bool>(keyword(S_HIDDEN)));
|
||||
if(data.containsKey(keyword(S_CAPTIVEPORTAL))) setCaptivePortal(data.get<bool>(keyword(S_CAPTIVEPORTAL)));
|
||||
if (data.containsKey(keyword(S_SSID))) setSSID(data.get<String>(keyword(S_SSID)));
|
||||
|
||||
if (data.containsKey(keyword(S_PASSWORD))) setPassword(data.get<String>(keyword(S_PASSWORD)));
|
||||
|
||||
if (data.containsKey(keyword(S_CHANNEL))) setChannel(data.get<uint8_t>(keyword(S_CHANNEL)));
|
||||
|
||||
if (data.containsKey(keyword(S_HIDDEN))) setHidden(data.get<bool>(keyword(S_HIDDEN)));
|
||||
|
||||
if (data.containsKey(keyword(S_CAPTIVEPORTAL))) setCaptivePortal(data.get<bool>(keyword(S_CAPTIVEPORTAL)));
|
||||
|
||||
// GENERAL
|
||||
if(data.containsKey(keyword(S_LANG))) setLang(data.get<String>(keyword(S_LANG)));
|
||||
if(data.containsKey(keyword(S_DISPLAYINTERFACE))) setDisplayInterface(data.get<bool>(keyword(S_DISPLAYINTERFACE)));
|
||||
if(data.containsKey(keyword(S_DISPLAY_TIMEOUT))) setDisplayTimeout(data.get<uint32_t>(keyword(S_DISPLAY_TIMEOUT)));
|
||||
if(data.containsKey(keyword(S_SERIALINTERFACE))) setSerialInterface(data.get<bool>(keyword(S_SERIALINTERFACE)));
|
||||
if(data.containsKey(keyword(S_SERIAL_ECHO))) setSerialEcho(data.get<bool>(keyword(S_SERIAL_ECHO)));
|
||||
if(data.containsKey(keyword(S_WEBINTERFACE))) setWebInterface(data.get<bool>(keyword(S_WEBINTERFACE)));
|
||||
if(data.containsKey(keyword(S_WEB_SPIFFS))) setWebSpiffs(data.get<bool>(keyword(S_WEB_SPIFFS)));
|
||||
if(data.containsKey(keyword(S_LEDENABLED))) setLedEnabled(data.get<bool>(keyword(S_LEDENABLED)));
|
||||
if(data.containsKey(keyword(S_MAXCH))) setMaxCh(data.get<uint8_t>(keyword(S_MAXCH)));
|
||||
if(data.containsKey(keyword(S_MACAP))) setMacAP(data.get<String>(keyword(S_MACAP)));
|
||||
if(data.containsKey(keyword(S_MACST))) setMacSt(data.get<String>(keyword(S_MACST)));
|
||||
if (data.containsKey(keyword(S_LANG))) setLang(data.get<String>(keyword(S_LANG)));
|
||||
|
||||
if (data.containsKey(keyword(S_DISPLAYINTERFACE))) setDisplayInterface(data.get<bool>(keyword(S_DISPLAYINTERFACE)));
|
||||
|
||||
if (data.containsKey(keyword(S_DISPLAY_TIMEOUT))) setDisplayTimeout(data.get<uint32_t>(keyword(S_DISPLAY_TIMEOUT)));
|
||||
|
||||
if (data.containsKey(keyword(S_SERIALINTERFACE))) setSerialInterface(data.get<bool>(keyword(S_SERIALINTERFACE)));
|
||||
|
||||
if (data.containsKey(keyword(S_SERIAL_ECHO))) setSerialEcho(data.get<bool>(keyword(S_SERIAL_ECHO)));
|
||||
|
||||
if (data.containsKey(keyword(S_WEBINTERFACE))) setWebInterface(data.get<bool>(keyword(S_WEBINTERFACE)));
|
||||
|
||||
if (data.containsKey(keyword(S_WEB_SPIFFS))) setWebSpiffs(data.get<bool>(keyword(S_WEB_SPIFFS)));
|
||||
|
||||
if (data.containsKey(keyword(S_LEDENABLED))) setLedEnabled(data.get<bool>(keyword(S_LEDENABLED)));
|
||||
|
||||
if (data.containsKey(keyword(S_MAXCH))) setMaxCh(data.get<uint8_t>(keyword(S_MAXCH)));
|
||||
|
||||
if (data.containsKey(keyword(S_MACAP))) setMacAP(data.get<String>(keyword(S_MACAP)));
|
||||
|
||||
if (data.containsKey(keyword(S_MACST))) setMacSt(data.get<String>(keyword(S_MACST)));
|
||||
|
||||
// SCAN
|
||||
if(data.containsKey(keyword(S_CHTIME))) setChTime(data.get<uint16_t>(keyword(S_CHTIME)));
|
||||
if(data.containsKey(keyword(S_MIN_DEAUTHS))) setMinDeauths(data.get<uint16_t>(keyword(S_MIN_DEAUTHS)));
|
||||
if (data.containsKey(keyword(S_CHTIME))) setChTime(data.get<uint16_t>(keyword(S_CHTIME)));
|
||||
|
||||
if (data.containsKey(keyword(S_MIN_DEAUTHS))) setMinDeauths(data.get<uint16_t>(keyword(S_MIN_DEAUTHS)));
|
||||
|
||||
// ATTACK
|
||||
if(data.containsKey(keyword(S_ATTACKTIMEOUT))) setAttackTimeout(data.get<uint32_t>(keyword(S_ATTACKTIMEOUT)));
|
||||
if(data.containsKey(keyword(S_FORCEPACKETS))) setForcePackets(data.get<uint8_t>(keyword(S_FORCEPACKETS)));
|
||||
if(data.containsKey(keyword(S_DEAUTHSPERTARGET))) setDeauthsPerTarget(data.get<uint16_t>(keyword(S_DEAUTHSPERTARGET)));
|
||||
if(data.containsKey(keyword(S_DEAUTHREASON))) setDeauthReason(data.get<uint8_t>(keyword(S_DEAUTHREASON)));
|
||||
if(data.containsKey(keyword(S_BEACONCHANNEL))) setBeaconChannel(data.get<bool>(keyword(S_BEACONCHANNEL)));
|
||||
if(data.containsKey(keyword(S_BEACONINTERVAL))) setBeaconInterval(data.get<bool>(keyword(S_BEACONINTERVAL)));
|
||||
if(data.containsKey(keyword(S_RANDOMTX))) setRandomTX(data.get<bool>(keyword(S_RANDOMTX)));
|
||||
if(data.containsKey(keyword(S_PROBESPERSSID))) setProbesPerSSID(data.get<uint8_t>(keyword(S_PROBESPERSSID)));
|
||||
if (data.containsKey(keyword(S_ATTACKTIMEOUT))) setAttackTimeout(data.get<uint32_t>(keyword(S_ATTACKTIMEOUT)));
|
||||
|
||||
if (version != VERSION){
|
||||
//reset();
|
||||
if (data.containsKey(keyword(S_FORCEPACKETS))) setForcePackets(data.get<uint8_t>(keyword(S_FORCEPACKETS)));
|
||||
|
||||
if (data.containsKey(keyword(S_DEAUTHSPERTARGET))) setDeauthsPerTarget(data.get<uint16_t>(keyword(
|
||||
S_DEAUTHSPERTARGET)));
|
||||
|
||||
if (data.containsKey(keyword(S_DEAUTHREASON))) setDeauthReason(data.get<uint8_t>(keyword(S_DEAUTHREASON)));
|
||||
|
||||
if (data.containsKey(keyword(S_BEACONCHANNEL))) setBeaconChannel(data.get<bool>(keyword(S_BEACONCHANNEL)));
|
||||
|
||||
if (data.containsKey(keyword(S_BEACONINTERVAL))) setBeaconInterval(data.get<bool>(keyword(S_BEACONINTERVAL)));
|
||||
|
||||
if (data.containsKey(keyword(S_RANDOMTX))) setRandomTX(data.get<bool>(keyword(S_RANDOMTX)));
|
||||
|
||||
if (data.containsKey(keyword(S_PROBESPERSSID))) setProbesPerSSID(data.get<uint8_t>(keyword(S_PROBESPERSSID)));
|
||||
|
||||
if (version != VERSION) {
|
||||
// reset();
|
||||
copyWebFiles(true);
|
||||
version = VERSION;
|
||||
changed = true;
|
||||
@@ -61,14 +85,16 @@ void Settings::load() {
|
||||
prntln(FILE_PATH);
|
||||
|
||||
// check and fix mac
|
||||
if(!macValid(macSt)) getRandomMac(macSt);
|
||||
if(!macValid(macAP)) getRandomMac(macAP);
|
||||
if (!macValid(macSt)) getRandomMac(macSt);
|
||||
|
||||
if (!macValid(macAP)) getRandomMac(macAP);
|
||||
|
||||
save(true); // force saving
|
||||
}
|
||||
|
||||
void Settings::load(String filepath){
|
||||
void Settings::load(String filepath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filepath;
|
||||
load();
|
||||
FILE_PATH = tmp;
|
||||
@@ -119,7 +145,7 @@ void Settings::reset() {
|
||||
|
||||
String Settings::getJsonStr() {
|
||||
DynamicJsonBuffer jsonBuffer(4000);
|
||||
JsonObject &data = jsonBuffer.createObject();
|
||||
JsonObject& data = jsonBuffer.createObject();
|
||||
|
||||
// Version
|
||||
data.set("version", VERSION);
|
||||
@@ -169,11 +195,12 @@ String Settings::getJsonStr() {
|
||||
void Settings::save(bool force) {
|
||||
if (force || changed) {
|
||||
String buf = getJsonStr();
|
||||
if(writeFile(FILE_PATH, buf)){
|
||||
|
||||
if (writeFile(FILE_PATH, buf)) {
|
||||
prnt(S_SETTINGS_SAVED);
|
||||
prntln(FILE_PATH);
|
||||
changed = false;
|
||||
}else{
|
||||
} else {
|
||||
prnt(F("ERROR: saving "));
|
||||
prntln(FILE_PATH);
|
||||
}
|
||||
@@ -182,6 +209,7 @@ void Settings::save(bool force) {
|
||||
|
||||
void Settings::save(bool force, String filepath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filepath;
|
||||
save(force);
|
||||
FILE_PATH = tmp;
|
||||
@@ -189,6 +217,7 @@ void Settings::save(bool force, String filepath) {
|
||||
|
||||
void Settings::print() {
|
||||
String settingsJson = getJsonStr();
|
||||
|
||||
settingsJson.replace("{", "{\r\n");
|
||||
settingsJson.replace("}", "\r\n}");
|
||||
settingsJson.replace(",", "\r\n");
|
||||
@@ -230,7 +259,7 @@ void Settings::set(const char* str, String value) {
|
||||
else if (eqls(str, S_PASSWORD)) setPassword(value);
|
||||
else if (eqls(str, S_MACAP)) setMacAP(value);
|
||||
else if (eqls(str, S_MACST)) setMacSt(value);
|
||||
else if (eqls(str, S_MAC) && value.equalsIgnoreCase("random")){
|
||||
else if (eqls(str, S_MAC) && value.equalsIgnoreCase("random")) {
|
||||
setMacSt(value);
|
||||
setMacAP(value);
|
||||
}
|
||||
@@ -390,23 +419,23 @@ bool Settings::getCaptivePortal() {
|
||||
return captivePortal;
|
||||
}
|
||||
|
||||
uint16_t Settings::getMinDeauths(){
|
||||
uint16_t Settings::getMinDeauths() {
|
||||
return minDeauths;
|
||||
}
|
||||
|
||||
uint32_t Settings::getDisplayTimeout(){
|
||||
uint32_t Settings::getDisplayTimeout() {
|
||||
return displayTimeout;
|
||||
}
|
||||
|
||||
String Settings::getLang(){
|
||||
String Settings::getLang() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
bool Settings::getSerialEcho(){
|
||||
bool Settings::getSerialEcho() {
|
||||
return serialEcho;
|
||||
}
|
||||
|
||||
bool Settings::getWebSpiffs(){
|
||||
bool Settings::getWebSpiffs() {
|
||||
return webSpiffs;
|
||||
}
|
||||
|
||||
@@ -428,7 +457,7 @@ void Settings::setBeaconChannel(bool beaconChannel) {
|
||||
}
|
||||
|
||||
void Settings::setForcePackets(uint8_t forcePackets) {
|
||||
if(forcePackets > 0){
|
||||
if (forcePackets > 0) {
|
||||
Settings::forcePackets = forcePackets;
|
||||
changed = true;
|
||||
}
|
||||
@@ -455,7 +484,7 @@ void Settings::setBeaconInterval(bool beaconInterval) {
|
||||
}
|
||||
|
||||
void Settings::setChannel(uint8_t channel) {
|
||||
if (channel >= 1 && channel <= maxCh) {
|
||||
if ((channel >= 1) && (channel <= maxCh)) {
|
||||
Settings::channel = channel;
|
||||
setWifiChannel(channel);
|
||||
changed = true;
|
||||
@@ -468,7 +497,7 @@ void Settings::setChannel(uint8_t channel) {
|
||||
}
|
||||
|
||||
void Settings::setSSID(String ssid) {
|
||||
if (ssid.length() > 0 && ssid.length() <= 32) {
|
||||
if ((ssid.length() > 0) && (ssid.length() <= 32)) {
|
||||
ssid = fixUtf8(ssid);
|
||||
Settings::ssid = ssid;
|
||||
changed = true;
|
||||
@@ -478,7 +507,7 @@ void Settings::setSSID(String ssid) {
|
||||
}
|
||||
|
||||
void Settings::setPassword(String password) {
|
||||
if (password.length() >= 8 && password.length() <= 32) {
|
||||
if ((password.length() >= 8) && (password.length() <= 32)) {
|
||||
password = fixUtf8(password);
|
||||
Settings::password = password;
|
||||
changed = true;
|
||||
@@ -510,16 +539,14 @@ void Settings::setChTime(uint16_t chTime) {
|
||||
void Settings::setMacSt(String macStr) {
|
||||
uint8_t mac[6];
|
||||
|
||||
if(eqls(macStr, S_RANDOM))
|
||||
getRandomMac(mac);
|
||||
else
|
||||
strToMac(macStr, mac);
|
||||
if (eqls(macStr, S_RANDOM)) getRandomMac(mac);
|
||||
else strToMac(macStr, mac);
|
||||
|
||||
setMacSt(mac);
|
||||
}
|
||||
|
||||
bool Settings::setMacSt(uint8_t* macSt){
|
||||
if(macSt[0] % 2 == 0){
|
||||
bool Settings::setMacSt(uint8_t* macSt) {
|
||||
if (macSt[0] % 2 == 0) {
|
||||
memcpy(Settings::macSt, macSt, 6);
|
||||
changed = true;
|
||||
return true;
|
||||
@@ -527,19 +554,17 @@ bool Settings::setMacSt(uint8_t* macSt){
|
||||
return false;
|
||||
}
|
||||
|
||||
void Settings::setMacAP(String macStr){
|
||||
void Settings::setMacAP(String macStr) {
|
||||
uint8_t mac[6];
|
||||
|
||||
if(eqls(macStr, S_RANDOM))
|
||||
getRandomMac(mac);
|
||||
else
|
||||
strToMac(macStr, mac);
|
||||
if (eqls(macStr, S_RANDOM)) getRandomMac(mac);
|
||||
else strToMac(macStr, mac);
|
||||
|
||||
setMacAP(mac);
|
||||
}
|
||||
|
||||
bool Settings::setMacAP(uint8_t* macAP){
|
||||
if(macAP[0] % 2 == 0){
|
||||
bool Settings::setMacAP(uint8_t* macAP) {
|
||||
if (macAP[0] % 2 == 0) {
|
||||
memcpy(Settings::macAP, macAP, 6);
|
||||
changed = true;
|
||||
return true;
|
||||
@@ -547,12 +572,12 @@ bool Settings::setMacAP(uint8_t* macAP){
|
||||
return false;
|
||||
}
|
||||
|
||||
void Settings::setRandomTX(bool randomTX){
|
||||
void Settings::setRandomTX(bool randomTX) {
|
||||
Settings::randomTX = randomTX;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Settings::setAttackTimeout(uint32_t attackTimeout){
|
||||
void Settings::setAttackTimeout(uint32_t attackTimeout) {
|
||||
Settings::attackTimeout = attackTimeout;
|
||||
changed = true;
|
||||
}
|
||||
@@ -563,7 +588,7 @@ void Settings::setLedEnabled(bool ledEnabled) {
|
||||
}
|
||||
|
||||
void Settings::setProbesPerSSID(uint8_t probesPerSSID) {
|
||||
if(probesPerSSID > 0){
|
||||
if (probesPerSSID > 0) {
|
||||
Settings::probesPerSSID = probesPerSSID;
|
||||
changed = true;
|
||||
}
|
||||
@@ -574,33 +599,32 @@ void Settings::setHidden(bool hidden) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Settings::setCaptivePortal(bool captivePortal){
|
||||
void Settings::setCaptivePortal(bool captivePortal) {
|
||||
Settings::captivePortal = captivePortal;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Settings::setMinDeauths(uint16_t minDeauths){
|
||||
void Settings::setMinDeauths(uint16_t minDeauths) {
|
||||
Settings::minDeauths = minDeauths;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Settings::setDisplayTimeout(uint32_t displayTimeout){
|
||||
void Settings::setDisplayTimeout(uint32_t displayTimeout) {
|
||||
Settings::displayTimeout = displayTimeout;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Settings::setLang(String lang){
|
||||
void Settings::setLang(String lang) {
|
||||
Settings::lang = lang;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Settings::setSerialEcho(bool serialEcho){
|
||||
void Settings::setSerialEcho(bool serialEcho) {
|
||||
Settings::serialEcho = serialEcho;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Settings::setWebSpiffs(bool webSpiffs){
|
||||
void Settings::setWebSpiffs(bool webSpiffs) {
|
||||
Settings::webSpiffs = webSpiffs;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include <ArduinoJson.h>
|
||||
#include "ArduinoJson.h"
|
||||
#include "language.h"
|
||||
#include "A_config.h"
|
||||
|
||||
#define VERSION "v2.0.5"
|
||||
#define VERSION "v2.0.6"
|
||||
|
||||
extern void checkFile(String path, String data);
|
||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer &jsonBuffer);
|
||||
extern bool writeFile(String path, String &buf);
|
||||
extern void saveJSONFile(String path, JsonObject &root);
|
||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern void saveJSONFile(String path, JsonObject& root);
|
||||
extern String macToStr(uint8_t* mac);
|
||||
extern void getRandomMac(uint8_t* mac);
|
||||
extern bool strToMac(String macStr, uint8_t* mac);
|
||||
@@ -30,7 +30,7 @@ class Settings {
|
||||
void load();
|
||||
void load(String filepath);
|
||||
void save(bool force);
|
||||
void save(bool force,String filepath);
|
||||
void save(bool force, String filepath);
|
||||
void reset();
|
||||
void print();
|
||||
|
||||
@@ -97,6 +97,7 @@ class Settings {
|
||||
void setLang(String lang);
|
||||
void setSerialEcho(bool serialEcho);
|
||||
void setWebSpiffs(bool webSpiffs);
|
||||
|
||||
private:
|
||||
bool changed = false;
|
||||
|
||||
@@ -138,7 +139,4 @@ class Settings {
|
||||
String getJsonStr();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // ifndef Settings_h
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
template<class T>
|
||||
struct Node {
|
||||
T data;
|
||||
Node<T> *next;
|
||||
Node<T>* next;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class SimpleList{
|
||||
class SimpleList {
|
||||
public:
|
||||
SimpleList();
|
||||
~SimpleList();
|
||||
@@ -24,14 +24,15 @@ class SimpleList{
|
||||
virtual T shift();
|
||||
virtual T pop();
|
||||
virtual T get(int index);
|
||||
virtual int search(std::function<bool(T &a)> cmp);
|
||||
virtual int searchNext(std::function<bool(T &a)> cmp);
|
||||
virtual int binSearch(std::function<int(T &a)> cmp, int lowerEnd, int upperEnd);
|
||||
virtual int binSearch(std::function<int(T &a)> cmp);
|
||||
virtual int count(std::function<bool(T &a)> cmp);
|
||||
virtual int search(std::function<bool(T& a)>cmp);
|
||||
virtual int searchNext(std::function<bool(T& a)>cmp);
|
||||
virtual int binSearch(std::function<int(T& a)>cmp, int lowerEnd, int upperEnd);
|
||||
virtual int binSearch(std::function<int(T& a)>cmp);
|
||||
virtual int count(std::function<bool(T& a)>cmp);
|
||||
virtual void clear();
|
||||
virtual void sort(std::function<bool(T &a, T &b)> cmp);
|
||||
virtual void sort(std::function<bool(T& a, T& b)>cmp);
|
||||
virtual void swap(int x, int y);
|
||||
|
||||
protected:
|
||||
int listSize;
|
||||
Node<T>* listBegin;
|
||||
@@ -46,7 +47,7 @@ class SimpleList{
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
SimpleList<T>::SimpleList(){
|
||||
SimpleList<T>::SimpleList() {
|
||||
listBegin = NULL;
|
||||
listEnd = NULL;
|
||||
listSize = 0;
|
||||
@@ -58,7 +59,7 @@ SimpleList<T>::SimpleList(){
|
||||
|
||||
// Clear Nodes and free Memory
|
||||
template<typename T>
|
||||
SimpleList<T>::~SimpleList(){
|
||||
SimpleList<T>::~SimpleList() {
|
||||
clear();
|
||||
listBegin = NULL;
|
||||
listEnd = NULL;
|
||||
@@ -70,24 +71,23 @@ SimpleList<T>::~SimpleList(){
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Node<T>* SimpleList<T>::getNode(int index){
|
||||
if(index < 0 || index >= listSize)
|
||||
return NULL;
|
||||
Node<T>* SimpleList<T>::getNode(int index) {
|
||||
if ((index < 0) || (index >= listSize)) return NULL;
|
||||
|
||||
Node<T>* hNode = listBegin;
|
||||
int c = 0;
|
||||
|
||||
if(isCached && index >= lastIndexGot){
|
||||
if (isCached && (index >= lastIndexGot)) {
|
||||
c = lastIndexGot;
|
||||
hNode = lastNodeGot;
|
||||
}
|
||||
|
||||
while(hNode != NULL && c < index){
|
||||
while (hNode != NULL && c < index) {
|
||||
hNode = hNode->next;
|
||||
c++;
|
||||
}
|
||||
|
||||
if(hNode){
|
||||
if (hNode) {
|
||||
isCached = true;
|
||||
lastIndexGot = c;
|
||||
lastNodeGot = hNode;
|
||||
@@ -97,20 +97,19 @@ Node<T>* SimpleList<T>::getNode(int index){
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int SimpleList<T>::size(){
|
||||
int SimpleList<T>::size() {
|
||||
return listSize;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SimpleList<T>::add(T obj){
|
||||
Node<T> *node = new Node<T>();
|
||||
void SimpleList<T>::add(T obj) {
|
||||
Node<T>* node = new Node<T>();
|
||||
node->data = obj;
|
||||
node->next = NULL;
|
||||
|
||||
if(!listBegin)
|
||||
listBegin = node;
|
||||
if (!listBegin) listBegin = node;
|
||||
|
||||
if(listEnd){
|
||||
if (listEnd) {
|
||||
listEnd->next = node;
|
||||
listEnd = node;
|
||||
} else {
|
||||
@@ -121,19 +120,18 @@ void SimpleList<T>::add(T obj){
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SimpleList<T>::add(int index, T obj){
|
||||
if(index < 0 || index >= listSize){
|
||||
void SimpleList<T>::add(int index, T obj) {
|
||||
if ((index < 0) || (index >= listSize)) {
|
||||
add(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
Node<T> *nodeNew = new Node<T>();
|
||||
Node<T>* nodeNew = new Node<T>();
|
||||
nodeNew->data = obj;
|
||||
nodeNew->next = NULL;
|
||||
|
||||
if(index == 0)
|
||||
listBegin = nodeNew;
|
||||
else{
|
||||
if (index == 0) listBegin = nodeNew;
|
||||
else {
|
||||
Node<T>* nodePrev = getNode(index - 1);
|
||||
nodeNew->next = nodePrev->next;
|
||||
nodePrev->next = nodeNew;
|
||||
@@ -143,26 +141,25 @@ void SimpleList<T>::add(int index, T obj){
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SimpleList<T>::replace(int index, T obj){
|
||||
if(index >= 0 && index < listSize){
|
||||
void SimpleList<T>::replace(int index, T obj) {
|
||||
if ((index >= 0) && (index < listSize)) {
|
||||
getNode(index)->data = obj;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SimpleList<T>::remove(int index){
|
||||
if (index < 0 || index >= listSize)
|
||||
return;
|
||||
void SimpleList<T>::remove(int index) {
|
||||
if ((index < 0) || (index >= listSize)) return;
|
||||
|
||||
Node<T>* nodePrev = getNode(index - 1);
|
||||
Node<T>* nodeToDelete = getNode(index);
|
||||
|
||||
if(index == 0) {
|
||||
if (index == 0) {
|
||||
listBegin = nodeToDelete->next;
|
||||
} else {
|
||||
nodePrev->next = nodeToDelete->next;
|
||||
if(!nodePrev->next)
|
||||
listEnd = nodePrev;
|
||||
|
||||
if (!nodePrev->next) listEnd = nodePrev;
|
||||
}
|
||||
|
||||
delete nodeToDelete;
|
||||
@@ -173,18 +170,19 @@ void SimpleList<T>::remove(int index){
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T SimpleList<T>::get(int index){
|
||||
Node<T> *hNode = getNode(index);
|
||||
return (hNode ? hNode->data : T());
|
||||
T SimpleList<T>::get(int index) {
|
||||
Node<T>* hNode = getNode(index);
|
||||
return hNode ? hNode->data : T();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int SimpleList<T>::search(std::function<bool(T &a)> cmp){
|
||||
int SimpleList<T>::search(std::function<bool(T& a)>cmp) {
|
||||
int i = 0;
|
||||
|
||||
Node<T>* hNode = getNode(i);
|
||||
bool found = cmp(hNode->data);
|
||||
|
||||
while(!found && i < listSize){
|
||||
while (!found && i < listSize) {
|
||||
i++;
|
||||
hNode = getNode(i);
|
||||
found = cmp(hNode->data);
|
||||
@@ -194,12 +192,13 @@ int SimpleList<T>::search(std::function<bool(T &a)> cmp){
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int SimpleList<T>::searchNext(std::function<bool(T &a)> cmp){
|
||||
int SimpleList<T>::searchNext(std::function<bool(T& a)>cmp) {
|
||||
int i = lastIndexGot;
|
||||
|
||||
Node<T>* hNode = lastNodeGot;
|
||||
bool found = cmp(hNode->data);
|
||||
|
||||
while(!found && i < listSize){
|
||||
while (!found && i < listSize) {
|
||||
i++;
|
||||
hNode = getNode(i);
|
||||
found = cmp(hNode->data);
|
||||
@@ -209,9 +208,10 @@ int SimpleList<T>::searchNext(std::function<bool(T &a)> cmp){
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int SimpleList<T>::binSearch(std::function<int(T &a)> cmp, int lowerEnd, int upperEnd){
|
||||
int SimpleList<T>::binSearch(std::function<int(T& a)>cmp, int lowerEnd, int upperEnd) {
|
||||
int res;
|
||||
int mid = (lowerEnd + upperEnd) / 2;
|
||||
|
||||
Node<T>* hNode = listBegin;
|
||||
int hIndex = 0;
|
||||
|
||||
@@ -240,15 +240,15 @@ int SimpleList<T>::binSearch(std::function<int(T &a)> cmp, int lowerEnd, int upp
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int SimpleList<T>::binSearch(std::function<int(T &a)> cmp){
|
||||
return binSearch(cmp,0,listSize-1);
|
||||
int SimpleList<T>::binSearch(std::function<int(T& a)>cmp) {
|
||||
return binSearch(cmp, 0, listSize - 1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int SimpleList<T>::count(std::function<bool(T &a)> cmp){
|
||||
int SimpleList<T>::count(std::function<bool(T& a)>cmp) {
|
||||
int c = 0;
|
||||
|
||||
for(int i=0;i<listSize;i++){
|
||||
for (int i = 0; i < listSize; i++) {
|
||||
c += cmp(getNode(i)->data);
|
||||
}
|
||||
|
||||
@@ -256,19 +256,17 @@ int SimpleList<T>::count(std::function<bool(T &a)> cmp){
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T SimpleList<T>::pop(){
|
||||
if(listSize <= 0)
|
||||
return T();
|
||||
T SimpleList<T>::pop() {
|
||||
if (listSize <= 0) return T();
|
||||
|
||||
T data = listEnd->data;
|
||||
remove(listSize-1);
|
||||
remove(listSize - 1);
|
||||
return data;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T SimpleList<T>::shift(){
|
||||
if(listSize <= 0)
|
||||
return T();
|
||||
T SimpleList<T>::shift() {
|
||||
if (listSize <= 0) return T();
|
||||
|
||||
T data = listBegin->data;
|
||||
remove(0);
|
||||
@@ -276,23 +274,22 @@ T SimpleList<T>::shift(){
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SimpleList<T>::clear(){
|
||||
while(listSize > 0)
|
||||
remove(0);
|
||||
void SimpleList<T>::clear() {
|
||||
while (listSize > 0) remove(0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SimpleList<T>::swap(int x, int y){
|
||||
void SimpleList<T>::swap(int x, int y) {
|
||||
// only continue when the index numbers are unequal and at least 0
|
||||
if(x != y && x >= 0 && y >= 0){
|
||||
if(x > y){ // the first index should be smaller than the second. If not, swap them!
|
||||
if ((x != y) && (x >= 0) && (y >= 0)) {
|
||||
if (x > y) { // the first index should be smaller than the second. If not, swap them!
|
||||
int h = x;
|
||||
x = y;
|
||||
y = h;
|
||||
}
|
||||
|
||||
// When data is small, copy it
|
||||
if(sizeof(T) < 24){
|
||||
if (sizeof(T) < 24) {
|
||||
Node<T>* nodeA = getNode(x);
|
||||
Node<T>* nodeB = getNode(y);
|
||||
T h = nodeA->data;
|
||||
@@ -312,45 +309,45 @@ void SimpleList<T>::swap(int x, int y){
|
||||
Node<T>* nodeI = getNode(y + 1); // y.next
|
||||
|
||||
// a -> h -> i b -> c -> ... -> g -> h -> i
|
||||
if(nodeA)
|
||||
nodeA->next = nodeH;
|
||||
else
|
||||
listBegin = nodeH;
|
||||
if (nodeA) nodeA->next = nodeH;
|
||||
else listBegin = nodeH;
|
||||
|
||||
// a -> h -> c -> ... -> g -> h -> i b -> i
|
||||
if(nodeH != nodeC) // when nodes between b and h exist
|
||||
if (nodeH != nodeC) // when nodes between b and h exist
|
||||
nodeH->next = nodeC;
|
||||
else
|
||||
nodeH->next = nodeB;
|
||||
else nodeH->next = nodeB;
|
||||
|
||||
// a -> h -> i b -> i
|
||||
nodeB->next = nodeI;
|
||||
if(!nodeI)
|
||||
listEnd = nodeB;
|
||||
|
||||
if (!nodeI) listEnd = nodeB;
|
||||
|
||||
// a -> h -> c -> ... -> g -> b -> i
|
||||
if(nodeG != nodeB) // when more than 1 nodes between b and h exist
|
||||
if (nodeG != nodeB) // when more than 1 nodes between b and h exist
|
||||
nodeG->next = nodeB;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SimpleList<T>::sort(std::function<bool(T &a, T &b)> cmp) {
|
||||
void SimpleList<T>::sort(std::function<bool(T& a, T& b)>cmp) {
|
||||
// selection sort
|
||||
|
||||
int indexH; // index of node i
|
||||
int indexMin; // index of next minimum node
|
||||
|
||||
Node<T>* nodeMin; // next minimum node
|
||||
Node<T>* nodeH; // helper node at index j
|
||||
|
||||
for(int i=0; i<listSize-1; i++){
|
||||
for (int i = 0; i < listSize - 1; i++) {
|
||||
nodeMin = getNode(i);
|
||||
indexH = i;
|
||||
indexMin = i;
|
||||
for(int j=i+1; j<listSize; j++){
|
||||
|
||||
for (int j = i + 1; j < listSize; j++) {
|
||||
nodeH = getNode(j);
|
||||
if(cmp(nodeMin->data, nodeH->data)){
|
||||
|
||||
if (cmp(nodeMin->data, nodeH->data)) {
|
||||
nodeMin = nodeH;
|
||||
indexMin = j;
|
||||
}
|
||||
@@ -359,4 +356,4 @@ void SimpleList<T>::sort(std::function<bool(T &a, T &b)> cmp) {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // ifndef SimpleList_h
|
||||
@@ -9,7 +9,7 @@ void Stations::add(uint8_t* mac, int accesspointNum) {
|
||||
|
||||
if (stationNum < 0) {
|
||||
internal_add(mac, accesspointNum);
|
||||
//print(list->size() - 1, list->size() == 1, false);
|
||||
// print(list->size() - 1, list->size() == 1, false);
|
||||
} else {
|
||||
*getPkts(stationNum) += 1;
|
||||
*getTime(stationNum) = currentTime;
|
||||
@@ -19,22 +19,22 @@ void Stations::add(uint8_t* mac, int accesspointNum) {
|
||||
|
||||
int Stations::findStation(uint8_t* mac) {
|
||||
int c = count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
if (memcmp(getMac(i), mac, 6) == 0)
|
||||
return i;
|
||||
if (memcmp(getMac(i), mac, 6) == 0) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Stations::sort() {
|
||||
list->sort([](Station &a, Station &b) -> bool{
|
||||
return (*a.pkts < *b.pkts);
|
||||
list->sort([](Station& a, Station& b) -> bool {
|
||||
return *a.pkts < *b.pkts;
|
||||
});
|
||||
}
|
||||
|
||||
void Stations::sortAfterChannel() {
|
||||
list->sort([](Station &a, Station &b) -> bool{
|
||||
return (a.ch > b.ch);
|
||||
list->sort([](Station& a, Station& b) -> bool {
|
||||
return a.ch > b.ch;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ void Stations::removeAll() {
|
||||
|
||||
void Stations::remove(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_remove(num);
|
||||
prnt(ST_REMOVED_STATION);
|
||||
prntln(num);
|
||||
@@ -55,9 +56,9 @@ void Stations::remove(int num) {
|
||||
void Stations::removeOldest() {
|
||||
int oldest = 0;
|
||||
int c = count();
|
||||
|
||||
for (int i = 1; i < c; i++) {
|
||||
if (*getTime(i) > *getTime(oldest))
|
||||
oldest = i;
|
||||
if (*getTime(i) > *getTime(oldest)) oldest = i;
|
||||
}
|
||||
internal_remove(oldest);
|
||||
changed = true;
|
||||
@@ -66,11 +67,10 @@ void Stations::removeOldest() {
|
||||
void Stations::printAll() {
|
||||
prntln(ST_HEADER);
|
||||
int c = count();
|
||||
if (c == 0)
|
||||
prntln(ST_LIST_EMPTY);
|
||||
|
||||
if (c == 0) prntln(ST_LIST_EMPTY);
|
||||
else
|
||||
for (int i = 0; i < c; i++)
|
||||
print(i, i == 0, i == c - 1);
|
||||
for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1);
|
||||
}
|
||||
|
||||
void Stations::printSelected() {
|
||||
@@ -97,75 +97,86 @@ void Stations::print(int num) {
|
||||
|
||||
void Stations::print(int num, bool header, bool footer) {
|
||||
if (!check(num)) return;
|
||||
|
||||
if (header) {
|
||||
prntln(ST_TABLE_HEADER);
|
||||
prntln(ST_TABLE_DIVIDER);
|
||||
}
|
||||
|
||||
prnt(buildString(String(),(String)num, 2));
|
||||
prnt(buildString(String(), (String)num, 2));
|
||||
prnt(buildString(String(SPACE) + getMacStr(num), String(), 18));
|
||||
prnt(buildString(String(SPACE), (String)getCh(num), 3));
|
||||
prnt(buildString(String(SPACE) + getNameStr(num), String(), 17));
|
||||
prnt(buildString(String(SPACE) + getVendorStr(num), String(), 9));
|
||||
prnt(buildString(String(SPACE), (String)*getPkts(num), 9));
|
||||
prnt(buildString(String(SPACE), (String) * getPkts(num), 9));
|
||||
prnt(buildString(String(SPACE) + getAPStr(num), String(), 33));
|
||||
prnt(buildString(String(SPACE) + getTimeStr(num), String(), 10));
|
||||
prntln(buildString(String(SPACE) + getSelectedStr(num), String(), 9));
|
||||
|
||||
if (footer)
|
||||
prntln(ST_TABLE_DIVIDER);
|
||||
if (footer) prntln(ST_TABLE_DIVIDER);
|
||||
}
|
||||
|
||||
String Stations::getAPStr(int num) {
|
||||
if (getAP(num) < 0) return String();
|
||||
|
||||
return accesspoints.getSSID(getAP(num));
|
||||
}
|
||||
|
||||
uint8_t* Stations::getAPMac(int num){
|
||||
uint8_t* Stations::getAPMac(int num) {
|
||||
if (!check(num)) return 0;
|
||||
|
||||
return WiFi.BSSID(list->get(num).ap);
|
||||
}
|
||||
|
||||
String Stations::getAPMacStr(int num){
|
||||
String Stations::getAPMacStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
uint8_t* mac = getAPMac(num);
|
||||
return bytesToStr(mac, 6);
|
||||
}
|
||||
|
||||
int Stations::getAP(int num) {
|
||||
if (!check(num)) return -1;
|
||||
|
||||
return accesspoints.find(list->get(num).ap);
|
||||
}
|
||||
|
||||
String Stations::getNameStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
return names.find(getMac(num));
|
||||
}
|
||||
|
||||
bool Stations::hasName(int num) {
|
||||
if (!check(num)) return false;
|
||||
|
||||
return names.findID(getMac(num)) >= 0;
|
||||
}
|
||||
|
||||
uint8_t* Stations::getMac(int num) {
|
||||
if (!check(num)) return 0;
|
||||
|
||||
return list->get(num).mac;
|
||||
}
|
||||
|
||||
String Stations::getMacStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
uint8_t* mac = getMac(num);
|
||||
return bytesToStr(mac, 6);
|
||||
}
|
||||
|
||||
String Stations::getMacVendorStr(int num) {
|
||||
String value;
|
||||
if (check(num)){
|
||||
|
||||
if (check(num)) {
|
||||
value = getVendorStr(num) + ":";
|
||||
uint8_t* mac = getMac(num);
|
||||
|
||||
for (int i = 3; i < 6; i++) {
|
||||
if (mac[i] < 0x10) value += "0";
|
||||
value += String(mac[i], HEX);
|
||||
|
||||
if (i < 5) value += ":";
|
||||
}
|
||||
}
|
||||
@@ -174,6 +185,7 @@ String Stations::getMacVendorStr(int num) {
|
||||
|
||||
String Stations::getVendorStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
return searchVendor(list->get(num).mac);
|
||||
}
|
||||
|
||||
@@ -183,44 +195,46 @@ String Stations::getSelectedStr(int num) {
|
||||
|
||||
uint32_t* Stations::getPkts(int num) {
|
||||
if (!check(num)) return NULL;
|
||||
|
||||
return list->get(num).pkts;
|
||||
}
|
||||
|
||||
uint32_t* Stations::getTime(int num) {
|
||||
if (!check(num)) return NULL;
|
||||
|
||||
return list->get(num).time;
|
||||
}
|
||||
|
||||
String Stations::getTimeStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
uint32_t difference = currentTime - *getTime(num);
|
||||
|
||||
if (difference < 1000)
|
||||
return str(ST_SMALLER_ONESEC);
|
||||
else if (difference < 60000)
|
||||
return str(ST_SMALLER_ONEMIN);
|
||||
if (difference < 1000) return str(ST_SMALLER_ONESEC);
|
||||
else if (difference < 60000) return str(ST_SMALLER_ONEMIN);
|
||||
else {
|
||||
uint32_t minutes = difference / 60000;
|
||||
if (minutes > 60)
|
||||
return str(ST_BIGER_ONEHOUR);
|
||||
else
|
||||
return (String)minutes + str(STR_MIN);
|
||||
}
|
||||
|
||||
if (minutes > 60) return str(ST_BIGER_ONEHOUR);
|
||||
else return (String)minutes + str(STR_MIN);
|
||||
}
|
||||
}
|
||||
|
||||
bool Stations::getSelected(int num) {
|
||||
if (!check(num)) return false;
|
||||
|
||||
return list->get(num).selected;
|
||||
}
|
||||
|
||||
uint8_t Stations::getCh(int num) {
|
||||
if (!check(num)) return 0;
|
||||
|
||||
return list->get(num).ch;
|
||||
}
|
||||
|
||||
void Stations::select(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_select(num);
|
||||
prnt(ST_SELECTED_STATION);
|
||||
prntln(num);
|
||||
@@ -229,6 +243,7 @@ void Stations::select(int num) {
|
||||
|
||||
void Stations::deselect(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_deselect(num);
|
||||
prnt(ST_DESELECTED_STATION);
|
||||
prntln(num);
|
||||
@@ -236,15 +251,13 @@ void Stations::deselect(int num) {
|
||||
}
|
||||
|
||||
void Stations::selectAll() {
|
||||
for (int i = 0; i < count(); i++)
|
||||
internal_select(i);
|
||||
for (int i = 0; i < count(); i++) internal_select(i);
|
||||
prntln(ST_SELECTED_ALL);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::deselectAll() {
|
||||
for (int i = 0; i < count(); i++)
|
||||
internal_deselect(i);
|
||||
for (int i = 0; i < count(); i++) internal_deselect(i);
|
||||
prntln(ST_DESELECTED_ALL);
|
||||
changed = true;
|
||||
}
|
||||
@@ -255,15 +268,16 @@ int Stations::count() {
|
||||
|
||||
int Stations::selected() {
|
||||
int num = 0;
|
||||
|
||||
for (int i = 0; i < count(); i++)
|
||||
if (getSelected(i)) num++;
|
||||
return num;
|
||||
}
|
||||
|
||||
bool Stations::check(int num) {
|
||||
if (internal_check(num)){
|
||||
if (internal_check(num)) {
|
||||
return true;
|
||||
} else{
|
||||
} else {
|
||||
prnt(ST_ERROR_ID);
|
||||
prntln(num);
|
||||
return false;
|
||||
@@ -276,12 +290,14 @@ bool Stations::internal_check(int num) {
|
||||
|
||||
void Stations::internal_select(int num) {
|
||||
Station changedStation = list->get(num);
|
||||
|
||||
changedStation.selected = true;
|
||||
list->replace(num, changedStation);
|
||||
}
|
||||
|
||||
void Stations::internal_deselect(int num) {
|
||||
Station changedStation = list->get(num);
|
||||
|
||||
changedStation.selected = false;
|
||||
list->replace(num, changedStation);
|
||||
}
|
||||
@@ -294,8 +310,7 @@ void Stations::internal_remove(int num) {
|
||||
}
|
||||
|
||||
void Stations::internal_add(uint8_t* mac, int accesspointNum) {
|
||||
if (count() >= STATION_LIST_SIZE)
|
||||
removeOldest();
|
||||
if (count() >= STATION_LIST_SIZE) removeOldest();
|
||||
|
||||
Station newStation;
|
||||
newStation.ap = accesspointNum;
|
||||
@@ -314,6 +329,7 @@ void Stations::internal_add(uint8_t* mac, int accesspointNum) {
|
||||
|
||||
void Stations::internal_removeAll() {
|
||||
int c = count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
free(getMac(i));
|
||||
free(getPkts(i));
|
||||
@@ -321,6 +337,3 @@ void Stations::internal_removeAll() {
|
||||
}
|
||||
list->clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class Stations {
|
||||
|
||||
void select(int num);
|
||||
void deselect(int num);
|
||||
void add(uint8_t* mac,int accesspointNum);
|
||||
void add(uint8_t* mac, int accesspointNum);
|
||||
|
||||
void selectAll();
|
||||
void deselectAll();
|
||||
@@ -66,11 +66,12 @@ class Stations {
|
||||
|
||||
bool check(int num);
|
||||
bool changed = false;
|
||||
|
||||
private:
|
||||
struct Station{
|
||||
struct Station {
|
||||
uint8_t ap;
|
||||
uint8_t ch;
|
||||
uint8_t* mac;
|
||||
uint8_t * mac;
|
||||
uint32_t* pkts;
|
||||
uint32_t* time;
|
||||
bool selected;
|
||||
@@ -89,7 +90,4 @@ class Stations {
|
||||
void internal_removeAll();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // ifndef Stations_h
|
||||
16
esp8266_deauther/StatusLED.h
Normal file
16
esp8266_deauther/StatusLED.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef StatusLED_H
|
||||
#define StatusLED_H
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
class StatusLED {
|
||||
public:
|
||||
virtual ~StatusLED() = default;
|
||||
|
||||
virtual void setup() = 0;
|
||||
|
||||
virtual void setColor(uint8_t r, uint8_t g, uint8_t b) = 0;
|
||||
virtual void setBrightness(uint8_t brightness) = 0;
|
||||
};
|
||||
|
||||
#endif // ifndef StatusLED_H
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
/*
|
||||
===========================================
|
||||
Copyright (c) 2018 Stefan Kremser
|
||||
github.com/spacehuhn
|
||||
===========================================
|
||||
*/
|
||||
*/
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
@@ -18,25 +18,13 @@ extern "C" {
|
||||
#include "Attack.h"
|
||||
#include "SerialInterface.h"
|
||||
#include "DisplayUI.h"
|
||||
#include "DigitalLed.h"
|
||||
#include "RGBLed.h"
|
||||
#include "Neopixel.h"
|
||||
#include "A_config.h"
|
||||
#include "webfiles.h"
|
||||
|
||||
#ifdef DIGITAL_LED
|
||||
DigitalLed led;
|
||||
#endif
|
||||
|
||||
#ifdef RGB_LED
|
||||
RGBLed led;
|
||||
#endif
|
||||
|
||||
#ifdef NEOPIXEL_LED
|
||||
Neopixel led;
|
||||
#endif
|
||||
#include "LEDController.h"
|
||||
|
||||
// Run-Time Variables //
|
||||
LEDController* led;
|
||||
Settings settings;
|
||||
Names names;
|
||||
SSIDs ssids;
|
||||
@@ -55,9 +43,6 @@ uint32_t currentTime = 0;
|
||||
bool booted = false;
|
||||
|
||||
void setup() {
|
||||
// "fix" for RGB LEDs
|
||||
analogWriteRange(0xff);
|
||||
|
||||
// for random generator
|
||||
randomSeed(os_random());
|
||||
|
||||
@@ -74,11 +59,12 @@ void setup() {
|
||||
|
||||
// auto repair when in boot-loop
|
||||
uint8_t bootCounter = EEPROM.read(0);
|
||||
if(bootCounter >= 3){
|
||||
|
||||
if (bootCounter >= 3) {
|
||||
prnt(SETUP_FORMAT_SPIFFS);
|
||||
SPIFFS.format();
|
||||
prntln(SETUP_OK);
|
||||
}else{
|
||||
} else {
|
||||
EEPROM.write(0, bootCounter + 1); // add 1 to the boot counter
|
||||
EEPROM.commit();
|
||||
}
|
||||
@@ -103,7 +89,7 @@ void setup() {
|
||||
wifi_set_macaddr(STATION_IF, settings.getMacSt());
|
||||
|
||||
// start display
|
||||
if (settings.getDisplayInterface()){
|
||||
if (settings.getDisplayInterface()) {
|
||||
displayUI.setup();
|
||||
displayUI.mode = SCREEN_MODE_INTRO;
|
||||
}
|
||||
@@ -119,10 +105,9 @@ void setup() {
|
||||
// create scan.json
|
||||
scan.setup();
|
||||
|
||||
// set LED
|
||||
#ifdef DIGITAL_LED
|
||||
led.setup();
|
||||
#endif
|
||||
// setup LED
|
||||
led = new LEDController();
|
||||
led->setup();
|
||||
|
||||
// set channel
|
||||
setWifiChannel(settings.getChannel());
|
||||
@@ -159,27 +144,20 @@ void loop() {
|
||||
serialInterface.update(); // read and run serial input
|
||||
scan.update(); // run scan
|
||||
ssids.update(); // run random mode, if enabled
|
||||
#ifdef DIGITAL_LED
|
||||
led.update(); // update LED color
|
||||
#endif
|
||||
led->update(); // update LED color
|
||||
|
||||
// auto-save
|
||||
if (settings.getAutosave() && currentTime - autosaveTime > settings.getAutosaveTime()) {
|
||||
if (settings.getAutosave() && (currentTime - autosaveTime > settings.getAutosaveTime())) {
|
||||
autosaveTime = currentTime;
|
||||
names.save(false);
|
||||
ssids.save(false);
|
||||
settings.save(false);
|
||||
}
|
||||
|
||||
if(!booted){
|
||||
if (!booted) {
|
||||
// reset boot counter
|
||||
EEPROM.write(0, 0);
|
||||
EEPROM.commit();
|
||||
booted = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,49 +6,54 @@
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include <ArduinoJson.h>
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
/*
|
||||
Here is a collection of useful functions and variables.
|
||||
They are used globally via an 'extern' reference in every class.
|
||||
Making everything static will lead to problems with the Arduino ESP8266 2.0.0 SDK,
|
||||
there were some fixed in later version but we need to use the old version for injecting deauth packets.
|
||||
*/
|
||||
*/
|
||||
|
||||
uint8_t broadcast[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
uint8_t broadcast[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
uint8_t wifi_channel = 1;
|
||||
|
||||
// ===== UTF8 FIX ===== //
|
||||
String escape(String str){
|
||||
String escape(String str) {
|
||||
str.replace(String(BACKSLASH), String(BACKSLASH) + String(BACKSLASH));
|
||||
str.replace(String(DOUBLEQUOTES), String(BACKSLASH) + String(DOUBLEQUOTES));
|
||||
return str;
|
||||
}
|
||||
bool ascii(char c){
|
||||
|
||||
bool ascii(char c) {
|
||||
return c >= 0 && c <= 127;
|
||||
}
|
||||
|
||||
bool printableAscii(char c){
|
||||
bool printableAscii(char c) {
|
||||
return c >= 32 && c <= 126;
|
||||
}
|
||||
|
||||
bool getBit(uint8_t b, uint8_t n){
|
||||
bool getBit(uint8_t b, uint8_t n) {
|
||||
return (b >> n) % 2 != 0;
|
||||
}
|
||||
|
||||
uint8_t utf8(uint8_t c){
|
||||
if(!getBit(c,7)) return 1;
|
||||
if(getBit(c,7) && getBit(c,6) && !getBit(c,5)) return 2;
|
||||
if(getBit(c,7) && getBit(c,6) && getBit(c,5) && !getBit(c,4)) return 3;
|
||||
if(getBit(c,7) && getBit(c,6) && getBit(c,5) && getBit(c,4) && !getBit(c,3)) return 4;
|
||||
uint8_t utf8(uint8_t c) {
|
||||
if (!getBit(c, 7)) return 1;
|
||||
|
||||
if (getBit(c, 7) && getBit(c, 6) && !getBit(c, 5)) return 2;
|
||||
|
||||
if (getBit(c, 7) && getBit(c, 6) && getBit(c, 5) && !getBit(c, 4)) return 3;
|
||||
|
||||
if (getBit(c, 7) && getBit(c, 6) && getBit(c, 5) && getBit(c, 4) && !getBit(c, 3)) return 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool utf8Part(uint8_t c){
|
||||
return getBit(c,7) && !getBit(c,6);
|
||||
bool utf8Part(uint8_t c) {
|
||||
return getBit(c, 7) && !getBit(c, 6);
|
||||
}
|
||||
|
||||
String fixUtf8(String str){
|
||||
String fixUtf8(String str) {
|
||||
int size = str.length();
|
||||
|
||||
String result = String();
|
||||
@@ -56,26 +61,29 @@ String fixUtf8(String str){
|
||||
uint8_t len;
|
||||
bool ok;
|
||||
|
||||
for(int i=0;i<size;i++){
|
||||
for (int i = 0; i < size; i++) {
|
||||
c = str.charAt(i); // get character
|
||||
len = utf8(c); // get utf8 char len
|
||||
|
||||
if(len <= 1){
|
||||
if (len <= 1) {
|
||||
result += c; // when 1 byte char, add it :)
|
||||
}
|
||||
else if(i + len > size){ // when char bigger than remaining string, end loop
|
||||
i = size+1;
|
||||
else if (i + len > size) { // when char bigger than remaining string, end loop
|
||||
i = size + 1;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
ok = true;
|
||||
for(int j=1;j<len && ok;j++){
|
||||
ok = utf8Part(str.charAt(i+j)); // if following char is compliant or not
|
||||
|
||||
for (int j = 1; j < len && ok; j++) {
|
||||
ok = utf8Part(str.charAt(i + j)); // if following char is compliant or not
|
||||
}
|
||||
if(ok) result += c; // everything is ok, add char and continue
|
||||
|
||||
if (ok) result += c; // everything is ok, add char and continue
|
||||
else { // utf8 char is broken
|
||||
for(int j=1;j<len;j++){ // go through the next bytes
|
||||
c = str.charAt(i+j);
|
||||
if(utf8(c) == 1) result += c; // when byte is ascii, add it :)
|
||||
for (int j = 1; j < len; j++) { // go through the next bytes
|
||||
c = str.charAt(i + j);
|
||||
|
||||
if (utf8(c) == 1) result += c; // when byte is ascii, add it :)
|
||||
}
|
||||
i += len - 1; // skip utf8 char because we already managed it
|
||||
}
|
||||
@@ -84,7 +92,7 @@ String fixUtf8(String str){
|
||||
return result;
|
||||
}
|
||||
|
||||
String removeUtf8(String str){
|
||||
String removeUtf8(String str) {
|
||||
str = fixUtf8(str); // fix it in case a utf char is broken
|
||||
int size = str.length();
|
||||
|
||||
@@ -92,34 +100,36 @@ String removeUtf8(String str){
|
||||
char c;
|
||||
uint8_t len;
|
||||
|
||||
for(int i=0;i<size;i++){
|
||||
for (int i = 0; i < size; i++) {
|
||||
c = str.charAt(i); // get character
|
||||
len = utf8(c); // get utf8 char len
|
||||
|
||||
if(len <= 1) result += c; // when 1 byte char, add it :)
|
||||
else i += len-1; // skip other chars
|
||||
if (len <= 1) result += c; // when 1 byte char, add it :)
|
||||
else i += len - 1; // skip other chars
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int utf8Len(String str){
|
||||
int utf8Len(String str) {
|
||||
int size = str.length();
|
||||
|
||||
int result = 0;
|
||||
char c;
|
||||
uint8_t len;
|
||||
|
||||
for(int i=0;i<size;i++){
|
||||
for (int i = 0; i < size; i++) {
|
||||
c = str.charAt(i); // get character
|
||||
len = utf8(c); // get utf8 char len
|
||||
|
||||
if(len <= 1) result++; // when 1 byte char, add 1 :)
|
||||
else{
|
||||
if (len <= 1) result++; // when 1 byte char, add 1 :)
|
||||
else {
|
||||
result++;
|
||||
for(int j=1;j<len;j++){
|
||||
c = str.charAt(i+j);
|
||||
if(!utf8Part(c) && utf8(c) == 1){
|
||||
|
||||
for (int j = 1; j < len; j++) {
|
||||
c = str.charAt(i + j);
|
||||
|
||||
if (!utf8Part(c) && (utf8(c) == 1)) {
|
||||
Serial.println(c, HEX);
|
||||
result++; // if following char is compliant or not
|
||||
}
|
||||
@@ -131,7 +141,7 @@ int utf8Len(String str){
|
||||
return result;
|
||||
}
|
||||
|
||||
String replaceUtf8(String str, String r){
|
||||
String replaceUtf8(String str, String r) {
|
||||
str = fixUtf8(str); // fix it in case a utf char is broken
|
||||
int size = str.length();
|
||||
|
||||
@@ -139,14 +149,14 @@ String replaceUtf8(String str, String r){
|
||||
char c;
|
||||
uint8_t len;
|
||||
|
||||
for(int i=0;i<size;i++){
|
||||
for (int i = 0; i < size; i++) {
|
||||
c = str.charAt(i); // get character
|
||||
len = utf8(c); // get utf8 char len
|
||||
|
||||
if(len <= 1) result += c; // when 1 byte char, add it :)
|
||||
else{
|
||||
if (len <= 1) result += c; // when 1 byte char, add it :)
|
||||
else {
|
||||
result += r;
|
||||
i += len-1; // skip other chars
|
||||
i += len - 1; // skip other chars
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,22 +166,24 @@ String replaceUtf8(String str, String r){
|
||||
// ===== LANGUAGE STRING FUNCTIONS ===== //
|
||||
|
||||
// for reading Strings from the PROGMEM
|
||||
String str(const char* ptr){
|
||||
String str(const char* ptr) {
|
||||
char keyword[strlen_P(ptr)];
|
||||
|
||||
strcpy_P(keyword, ptr);
|
||||
return String(keyword);
|
||||
}
|
||||
|
||||
// for converting keywords
|
||||
String keyword(const char* keywordPtr){
|
||||
String keyword(const char* keywordPtr) {
|
||||
char keyword[strlen_P(keywordPtr)];
|
||||
|
||||
strcpy_P(keyword, keywordPtr);
|
||||
|
||||
String str = "";
|
||||
uint8_t len = strlen(keyword);
|
||||
uint8_t i = 0;
|
||||
|
||||
while(i<len && keyword[i] != SLASH && keyword[i] != COMMA){
|
||||
while (i < len && keyword[i] != SLASH && keyword[i] != COMMA) {
|
||||
str += keyword[i];
|
||||
i++;
|
||||
}
|
||||
@@ -180,24 +192,29 @@ String keyword(const char* keywordPtr){
|
||||
}
|
||||
|
||||
// equals function
|
||||
bool eqls(const char* str, const char* keywordPtr){
|
||||
if(strlen(str) > 255) return false; // when string too long
|
||||
bool eqls(const char* str, const char* keywordPtr) {
|
||||
if (strlen(str) > 255) return false; // when string too long
|
||||
|
||||
char keyword[strlen_P(keywordPtr) + 1];
|
||||
strcpy_P(keyword, keywordPtr);
|
||||
|
||||
uint8_t lenStr = strlen(str);
|
||||
uint8_t lenKeyword = strlen(keyword);
|
||||
if(lenStr > lenKeyword) return false; // string can't be longer than keyword (but can be smaller because of '/' and ',')
|
||||
|
||||
if (lenStr > lenKeyword) return false; // string can't be longer than keyword (but can be smaller because of '/'
|
||||
// and ',')
|
||||
|
||||
uint8_t a = 0;
|
||||
uint8_t b = 0;
|
||||
bool result = true;
|
||||
while(a < lenStr && b < lenKeyword){
|
||||
if(keyword[b] == SLASH || keyword[b] == COMMA) b++;
|
||||
if(tolower(str[a]) != tolower(keyword[b])) result = false;
|
||||
if((a == lenStr && !result) || !result){ // fast forward to next comma
|
||||
while(b < lenKeyword && keyword[b] != COMMA) b++;
|
||||
|
||||
while (a < lenStr && b < lenKeyword) {
|
||||
if ((keyword[b] == SLASH) || (keyword[b] == COMMA)) b++;
|
||||
|
||||
if (tolower(str[a]) != tolower(keyword[b])) result = false;
|
||||
|
||||
if (((a == lenStr) && !result) || !result) { // fast forward to next comma
|
||||
while (b < lenKeyword && keyword[b] != COMMA) b++;
|
||||
result = true;
|
||||
a = 0;
|
||||
} else {
|
||||
@@ -209,64 +226,73 @@ bool eqls(const char* str, const char* keywordPtr){
|
||||
return result && a == lenStr && (keyword[b] == COMMA || keyword[b] == SLASH || keyword[b] == ENDOFLINE);
|
||||
}
|
||||
|
||||
bool eqls(String str, const char* keywordPtr){
|
||||
bool eqls(String str, const char* keywordPtr) {
|
||||
return eqls(str.c_str(), keywordPtr);
|
||||
}
|
||||
|
||||
// boolean to string
|
||||
String b2s(bool input){
|
||||
String b2s(bool input) {
|
||||
return str(input ? STR_TRUE : STR_FALSE);
|
||||
}
|
||||
|
||||
// boolean to asterix *
|
||||
String b2a(bool input){
|
||||
return (input ? String(ASTERIX) : String(SPACE));
|
||||
String b2a(bool input) {
|
||||
return input ? String(ASTERIX) : String(SPACE);
|
||||
}
|
||||
|
||||
// string to boolean
|
||||
bool s2b(String input){
|
||||
bool s2b(String input) {
|
||||
return eqls(input, STR_TRUE);
|
||||
}
|
||||
|
||||
// ===== PRINT FUNCTIONS ===== //
|
||||
void prnt(String s){
|
||||
void prnt(String s) {
|
||||
Serial.print(s);
|
||||
}
|
||||
void prnt(bool b){
|
||||
|
||||
void prnt(bool b) {
|
||||
Serial.print(b2s(b));
|
||||
}
|
||||
void prnt(char c){
|
||||
|
||||
void prnt(char c) {
|
||||
Serial.print(c);
|
||||
}
|
||||
void prnt(const char* ptr){
|
||||
|
||||
void prnt(const char* ptr) {
|
||||
Serial.print(FPSTR(ptr));
|
||||
}
|
||||
void prnt(int i){
|
||||
|
||||
void prnt(int i) {
|
||||
Serial.print((String)i);
|
||||
}
|
||||
|
||||
void prntln(){
|
||||
void prntln() {
|
||||
Serial.println();
|
||||
}
|
||||
void prntln(String s){
|
||||
|
||||
void prntln(String s) {
|
||||
Serial.println(s);
|
||||
}
|
||||
void prntln(bool b){
|
||||
|
||||
void prntln(bool b) {
|
||||
Serial.println(b2s(b));
|
||||
}
|
||||
void prntln(char c){
|
||||
|
||||
void prntln(char c) {
|
||||
Serial.println(c);
|
||||
}
|
||||
void prntln(const char* ptr){
|
||||
|
||||
void prntln(const char* ptr) {
|
||||
Serial.println(FPSTR(ptr));
|
||||
}
|
||||
void prntln(int i){
|
||||
|
||||
void prntln(int i) {
|
||||
Serial.println((String)i);
|
||||
}
|
||||
|
||||
/* ===== WiFi ===== */
|
||||
void setWifiChannel(uint8_t ch){
|
||||
if(ch != wifi_channel && ch > 0 && ch < 15){
|
||||
void setWifiChannel(uint8_t ch) {
|
||||
if ((ch != wifi_channel) && (ch > 0) && (ch < 15)) {
|
||||
wifi_channel = ch;
|
||||
wifi_set_channel(wifi_channel);
|
||||
}
|
||||
@@ -287,23 +313,35 @@ void setOutputPower(float dBm) {
|
||||
bool macBroadcast(uint8_t* mac) {
|
||||
for (uint8_t i = 0; i < 6; i++)
|
||||
if (mac[i] != broadcast[i]) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool macValid(uint8_t* mac) {
|
||||
for (uint8_t i = 0; i < 6; i++)
|
||||
if (mac[i] != 0x00) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool macMulticast(uint8_t* mac) {
|
||||
// see https://en.wikipedia.org/wiki/Multicast_address
|
||||
if (mac[0] == 0x33 && mac[1] == 0x33) return true;
|
||||
if (mac[0] == 0x01 && mac[1] == 0x80 && mac[2] == 0xC2) return true;
|
||||
if (mac[0] == 0x01 && mac[1] == 0x00 && (mac[2] == 0x5E || mac[2] == 0x0C)) return true;
|
||||
if (mac[0] == 0x01 && mac[1] == 0x0C && mac[2] == 0xCD && (mac[3] == 0x01 || mac[3] == 0x02 || mac[3] == 0x04) && (mac[4] == 0x00 || mac[4] == 0x01)) return true;
|
||||
if (mac[0] == 0x01 && mac[1] == 0x00 && mac[2] == 0x0C && mac[3] == 0xCC && mac[4] == 0xCC && (mac[5] == 0xCC || mac[5] == 0xCD)) return true;
|
||||
if (mac[0] == 0x01 && mac[1] == 0x1B && mac[2] == 0x19 && mac[3] == 0x00 && mac[4] == 0x00 && mac[5] == 0x00) return true;
|
||||
if ((mac[0] == 0x33) && (mac[1] == 0x33)) return true;
|
||||
|
||||
if ((mac[0] == 0x01) && (mac[1] == 0x80) && (mac[2] == 0xC2)) return true;
|
||||
|
||||
if ((mac[0] == 0x01) && (mac[1] == 0x00) && ((mac[2] == 0x5E) || (mac[2] == 0x0C))) return true;
|
||||
|
||||
if ((mac[0] == 0x01) && (mac[1] == 0x0C) && (mac[2] == 0xCD) &&
|
||||
((mac[3] == 0x01) || (mac[3] == 0x02) || (mac[3] == 0x04)) &&
|
||||
((mac[4] == 0x00) || (mac[4] == 0x01))) return true;
|
||||
|
||||
if ((mac[0] == 0x01) && (mac[1] == 0x00) && (mac[2] == 0x0C) && (mac[3] == 0xCC) && (mac[4] == 0xCC) &&
|
||||
((mac[5] == 0xCC) || (mac[5] == 0xCD))) return true;
|
||||
|
||||
if ((mac[0] == 0x01) && (mac[1] == 0x1B) && (mac[2] == 0x19) && (mac[3] == 0x00) && (mac[4] == 0x00) &&
|
||||
(mac[5] == 0x00)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -311,7 +349,9 @@ bool macMulticast(uint8_t* mac) {
|
||||
void getRandomMac(uint8_t* mac) {
|
||||
int num = random(sizeof(data_vendors) / 11 - 1);
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < 3; i++) mac[i] = pgm_read_byte_near(data_macs + num * 5 + i);
|
||||
|
||||
for (i = 3; i < 6; i++) mac[i] = random(256);
|
||||
}
|
||||
|
||||
@@ -321,7 +361,6 @@ int binSearchVendors(uint8_t* searchBytes, int lowerEnd, int upperEnd) {
|
||||
int mid = (lowerEnd + upperEnd) / 2;
|
||||
|
||||
while (lowerEnd <= upperEnd) {
|
||||
|
||||
listBytes[0] = pgm_read_byte_near(data_macs + mid * 5);
|
||||
listBytes[1] = pgm_read_byte_near(data_macs + mid * 5 + 1);
|
||||
listBytes[2] = pgm_read_byte_near(data_macs + mid * 5 + 2);
|
||||
@@ -337,7 +376,6 @@ int binSearchVendors(uint8_t* searchBytes, int lowerEnd, int upperEnd) {
|
||||
lowerEnd = mid + 1;
|
||||
mid = (lowerEnd + upperEnd) / 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -346,13 +384,15 @@ int binSearchVendors(uint8_t* searchBytes, int lowerEnd, int upperEnd) {
|
||||
String searchVendor(uint8_t* mac) {
|
||||
String vendorName = String();
|
||||
int pos = binSearchVendors(mac, 0, sizeof(data_macs) / 5 - 1);
|
||||
int realPos = pgm_read_byte_near(data_macs + pos*5 + 3) | pgm_read_byte_near(data_macs + pos*5 + 4) << 8;
|
||||
int realPos = pgm_read_byte_near(data_macs + pos * 5 + 3) | pgm_read_byte_near(data_macs + pos * 5 + 4) << 8;
|
||||
|
||||
if (pos >= 0) {
|
||||
char tmp;
|
||||
for (int i = 0; i < 8; i++){
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
tmp = (char)pgm_read_byte_near(data_vendors + realPos * 8 + i);
|
||||
if(tmp != ENDOFLINE) vendorName += tmp;
|
||||
|
||||
if (tmp != ENDOFLINE) vendorName += tmp;
|
||||
tmp += SPACE;
|
||||
}
|
||||
}
|
||||
@@ -360,14 +400,15 @@ String searchVendor(uint8_t* mac) {
|
||||
return vendorName;
|
||||
}
|
||||
|
||||
|
||||
/* ===== STRING ===== */
|
||||
String bytesToStr(uint8_t* b, uint32_t size) {
|
||||
String str;
|
||||
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
if (b[i] < 0x10) str += ZERO;
|
||||
str += String(b[i], HEX);
|
||||
if (i < size-1) str += DOUBLEPOINT;
|
||||
|
||||
if (i < size - 1) str += DOUBLEPOINT;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
@@ -376,44 +417,43 @@ String macToStr(uint8_t* mac) {
|
||||
return bytesToStr(mac, 6);
|
||||
}
|
||||
|
||||
bool strToMac(String macStr, uint8_t* mac){
|
||||
bool strToMac(String macStr, uint8_t* mac) {
|
||||
macStr.replace(String(DOUBLEPOINT), String()); // ":" -> ""
|
||||
macStr.replace("0x", String()); // "0x" -> ""
|
||||
macStr.replace(String(COMMA), String()); // "," -> ""
|
||||
macStr.replace(String(DOUBLEQUOTES), String()); // "\"" -> ""
|
||||
macStr.toUpperCase();
|
||||
|
||||
if(macStr.length() != 12){
|
||||
if (macStr.length() != 12) {
|
||||
prntln(F_ERROR_MAC);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < 6; i++)
|
||||
mac[i] = strtoul((macStr.substring(i * 2, i * 2 + 2)).c_str(), NULL, 16);
|
||||
for (uint8_t i = 0; i < 6; i++) mac[i] = strtoul((macStr.substring(i * 2, i * 2 + 2)).c_str(), NULL, 16);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void strToColor(String str, uint8_t* buf){
|
||||
void strToColor(String str, uint8_t* buf) {
|
||||
str.replace(":", "");
|
||||
str.replace("0x", "");
|
||||
str.replace(",", "");
|
||||
str.replace("#", "");
|
||||
str.toUpperCase();
|
||||
|
||||
if(str.length() != 6){
|
||||
if (str.length() != 6) {
|
||||
prntln(F_COLOR_INVALID);
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < 3; i++)
|
||||
buf[i] = strtoul((str.substring(i * 2, i * 2 + 2)).c_str(), NULL, 16);
|
||||
for (uint8_t i = 0; i < 3; i++) buf[i] = strtoul((str.substring(i * 2, i * 2 + 2)).c_str(), NULL, 16);
|
||||
}
|
||||
|
||||
String buildString(String left, String right, int maxLen){
|
||||
String buildString(String left, String right, int maxLen) {
|
||||
String result = left;
|
||||
int spacesToAdd = maxLen - left.length()/*utf8Len(left)*/ - right.length()/*utf8Len(right)*/;
|
||||
for(int i=0;i<spacesToAdd;i++){
|
||||
int spacesToAdd = maxLen - left.length() /*utf8Len(left)*/ - right.length() /*utf8Len(right)*/;
|
||||
|
||||
for (int i = 0; i < spacesToAdd; i++) {
|
||||
result += SPACE;
|
||||
}
|
||||
result += right;
|
||||
@@ -424,7 +464,8 @@ String buildString(String left, String right, int maxLen){
|
||||
bool progmemToSpiffs(const char* adr, int len, String path) {
|
||||
prnt(str(SETUP_COPYING) + path + str(SETUP_PROGMEM_TO_SPIFFS));
|
||||
File f = SPIFFS.open(path, "w+");
|
||||
if (!f){
|
||||
|
||||
if (!f) {
|
||||
prntln(SETUP_ERROR);
|
||||
return false;
|
||||
}
|
||||
@@ -439,10 +480,12 @@ bool progmemToSpiffs(const char* adr, int len, String path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool readFile(String path, String &buf) {
|
||||
bool readFile(String path, String& buf) {
|
||||
if (path.charAt(0) != SLASH) path = String(SLASH) + path;
|
||||
File f = SPIFFS.open(path, "r");
|
||||
|
||||
if (!f) return false;
|
||||
|
||||
if (f.size() == 0) return false;
|
||||
|
||||
while (f.available()) buf += (char)f.read();
|
||||
@@ -455,6 +498,7 @@ bool readFile(String path, String &buf) {
|
||||
void readFileToSerial(String path, bool showLineNum) {
|
||||
if (path.charAt(0) != SLASH) path = String(SLASH) + path;
|
||||
File f = SPIFFS.open(path, "r");
|
||||
|
||||
if (!f) {
|
||||
prnt(F_ERROR_READING_FILE);
|
||||
prntln(path);
|
||||
@@ -463,27 +507,30 @@ void readFileToSerial(String path, bool showLineNum) {
|
||||
|
||||
uint32_t c = 0;
|
||||
char tmp;
|
||||
if(showLineNum){
|
||||
prnt(buildString(String(),(String)c + String(VERTICALBAR),6));
|
||||
|
||||
if (showLineNum) {
|
||||
prnt(buildString(String(), (String)c + String(VERTICALBAR), 6));
|
||||
}
|
||||
|
||||
while (f.available()){
|
||||
while (f.available()) {
|
||||
tmp = f.read();
|
||||
prnt(tmp);
|
||||
if(tmp == NEWLINE && showLineNum){
|
||||
|
||||
if ((tmp == NEWLINE) && showLineNum) {
|
||||
c++;
|
||||
prnt(buildString(String(),(String)c + String(VERTICALBAR),6));
|
||||
prnt(buildString(String(), (String)c + String(VERTICALBAR), 6));
|
||||
}
|
||||
}
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
bool copyFile(String pathFrom, String pathTo){
|
||||
if(pathFrom.charAt(0) != SLASH) pathFrom = String(SLASH) + pathFrom;
|
||||
if(pathTo.charAt(0) != SLASH) pathTo = String(SLASH) + pathTo;
|
||||
bool copyFile(String pathFrom, String pathTo) {
|
||||
if (pathFrom.charAt(0) != SLASH) pathFrom = String(SLASH) + pathFrom;
|
||||
|
||||
if(!SPIFFS.exists(pathFrom)){
|
||||
if (pathTo.charAt(0) != SLASH) pathTo = String(SLASH) + pathTo;
|
||||
|
||||
if (!SPIFFS.exists(pathFrom)) {
|
||||
prnt(F_ERROR_FILE);
|
||||
prntln(pathFrom);
|
||||
return false;
|
||||
@@ -492,20 +539,21 @@ bool copyFile(String pathFrom, String pathTo){
|
||||
File f1 = SPIFFS.open(pathFrom, "r");
|
||||
File f2 = SPIFFS.open(pathTo, "w+");
|
||||
|
||||
if(!f1 || !f2) return false;
|
||||
if (!f1 || !f2) return false;
|
||||
|
||||
while (f1.available()){
|
||||
while (f1.available()) {
|
||||
f2.write(f1.read());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool renameFile(String pathFrom, String pathTo){
|
||||
if(pathFrom.charAt(0) != SLASH) pathFrom = String(SLASH) + pathFrom;
|
||||
if(pathTo.charAt(0) != SLASH) pathTo = String(SLASH) + pathTo;
|
||||
bool renameFile(String pathFrom, String pathTo) {
|
||||
if (pathFrom.charAt(0) != SLASH) pathFrom = String(SLASH) + pathFrom;
|
||||
|
||||
if(!SPIFFS.exists(pathFrom)){
|
||||
if (pathTo.charAt(0) != SLASH) pathTo = String(SLASH) + pathTo;
|
||||
|
||||
if (!SPIFFS.exists(pathFrom)) {
|
||||
prnt(F_ERROR_FILE);
|
||||
prntln(pathFrom);
|
||||
return false;
|
||||
@@ -515,27 +563,29 @@ bool renameFile(String pathFrom, String pathTo){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool writeFile(String path, String &buf) {
|
||||
bool writeFile(String path, String& buf) {
|
||||
if (path.charAt(0) != SLASH) path = String(SLASH) + path;
|
||||
File f = SPIFFS.open(path, "w+");
|
||||
|
||||
if (!f) return false;
|
||||
|
||||
uint32_t len = buf.length();
|
||||
for (uint32_t i = 0; i < len; i++)
|
||||
f.write(buf.charAt(i));
|
||||
|
||||
for (uint32_t i = 0; i < len; i++) f.write(buf.charAt(i));
|
||||
f.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool appendFile(String path, String &buf) {
|
||||
bool appendFile(String path, String& buf) {
|
||||
if (path.charAt(0) != SLASH) path = String(SLASH) + path;
|
||||
File f = SPIFFS.open(path, "a+");
|
||||
|
||||
if (!f) return false;
|
||||
|
||||
uint32_t len = buf.length();
|
||||
for (uint32_t i = 0; i < len; i++)
|
||||
f.write(buf[i]);
|
||||
|
||||
for (uint32_t i = 0; i < len; i++) f.write(buf[i]);
|
||||
f.close();
|
||||
|
||||
return true;
|
||||
@@ -543,27 +593,29 @@ bool appendFile(String path, String &buf) {
|
||||
|
||||
void checkFile(String path, String data) {
|
||||
if (path.charAt(0) != SLASH) path = String(SLASH) + path;
|
||||
if (!SPIFFS.exists(path))
|
||||
writeFile(path, data);
|
||||
|
||||
if (!SPIFFS.exists(path)) writeFile(path, data);
|
||||
}
|
||||
|
||||
bool removeLines(String path, int lineFrom, int lineTo){
|
||||
bool removeLines(String path, int lineFrom, int lineTo) {
|
||||
int c = 0;
|
||||
char tmp;
|
||||
|
||||
if (path.charAt(0) != SLASH) path = String(SLASH) + path;
|
||||
|
||||
String tmpPath = str(F_TMP)+path+str(F_COPY);
|
||||
String tmpPath = str(F_TMP) + path + str(F_COPY);
|
||||
|
||||
File f = SPIFFS.open(path, "r");
|
||||
File f2 = SPIFFS.open(tmpPath, "w");
|
||||
|
||||
if (!f || !f2) return false;
|
||||
|
||||
while (f.available()){
|
||||
while (f.available()) {
|
||||
tmp = f.read();
|
||||
if(c < lineFrom || c > lineTo)
|
||||
f2.write(tmp);
|
||||
if(tmp == NEWLINE) c++;
|
||||
|
||||
if ((c < lineFrom) || (c > lineTo)) f2.write(tmp);
|
||||
|
||||
if (tmp == NEWLINE) c++;
|
||||
}
|
||||
|
||||
f.close();
|
||||
@@ -574,28 +626,31 @@ bool removeLines(String path, int lineFrom, int lineTo){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool replaceLine(String path, int line, String &buf){
|
||||
bool replaceLine(String path, int line, String& buf) {
|
||||
int c = 0;
|
||||
char tmp;
|
||||
|
||||
if (path.charAt(0) != SLASH) path = String(SLASH) + path;
|
||||
|
||||
String tmpPath = "/tmp"+path+"_copy";
|
||||
String tmpPath = "/tmp" + path + "_copy";
|
||||
|
||||
File f = SPIFFS.open(path, "r");
|
||||
File f2 = SPIFFS.open(tmpPath, "w");
|
||||
|
||||
if (!f || !f2) return false;
|
||||
|
||||
while (f.available()){
|
||||
while (f.available()) {
|
||||
tmp = f.read();
|
||||
if(c != line)
|
||||
f2.write(tmp);
|
||||
else{
|
||||
|
||||
if (c != line) f2.write(tmp);
|
||||
else {
|
||||
f2.println(buf);
|
||||
while(f.read() != NEWLINE && f.available()){}
|
||||
|
||||
while (f.read() != NEWLINE && f.available()) {}
|
||||
c++;
|
||||
}
|
||||
if(tmp == NEWLINE) c++;
|
||||
|
||||
if (tmp == NEWLINE) c++;
|
||||
}
|
||||
|
||||
f.close();
|
||||
@@ -606,26 +661,26 @@ bool replaceLine(String path, int line, String &buf){
|
||||
return true;
|
||||
}
|
||||
|
||||
JsonVariant parseJSONFile(String path, DynamicJsonBuffer &jsonBuffer) {
|
||||
JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer) {
|
||||
if (path.charAt(0) != SLASH) path = String(SLASH) + path;
|
||||
|
||||
//create JSON Variant
|
||||
// create JSON Variant
|
||||
JsonVariant root;
|
||||
|
||||
//create buffer
|
||||
// create buffer
|
||||
String buf = "";
|
||||
|
||||
//read file into buffer
|
||||
if (!readFile(path, buf)) { //if file couldn't be opened, send 404 error
|
||||
// read file into buffer
|
||||
if (!readFile(path, buf)) { // if file couldn't be opened, send 404 error
|
||||
prnt(F_ERROR_OPEN);
|
||||
prntln(path);
|
||||
buf = "{}";
|
||||
}
|
||||
|
||||
//parse file-buffer into a JSON Variant
|
||||
// parse file-buffer into a JSON Variant
|
||||
root = jsonBuffer.parse(buf);
|
||||
|
||||
//if parsing unsuccessful
|
||||
// if parsing unsuccessful
|
||||
if (!root.success()) {
|
||||
prnt(F_ERROR_PARSING_JSON);
|
||||
prntln(path);
|
||||
@@ -640,45 +695,45 @@ bool removeFile(String path) {
|
||||
return SPIFFS.remove(path);
|
||||
}
|
||||
|
||||
void saveJSONFile(String path, JsonObject &root) {
|
||||
void saveJSONFile(String path, JsonObject& root) {
|
||||
if (path.charAt(0) != SLASH) path = String(SLASH) + path;
|
||||
|
||||
//create buffer
|
||||
// create buffer
|
||||
String buf;
|
||||
|
||||
//convert JSON object into string and write it into buffer
|
||||
// convert JSON object into string and write it into buffer
|
||||
root.printTo(buf);
|
||||
|
||||
//if buffer too big
|
||||
// if buffer too big
|
||||
if (buf.length() > 2048) {
|
||||
prntln(F_ERROR_TO_BIG );
|
||||
prntln(F_ERROR_TO_BIG);
|
||||
prntln(path);
|
||||
prntln(buf);
|
||||
return;
|
||||
}
|
||||
|
||||
//write buffer into SPIFFS file
|
||||
// write buffer into SPIFFS file
|
||||
writeFile(path, buf);
|
||||
}
|
||||
|
||||
void saveJSONFile(String path, JsonArray &root) {
|
||||
void saveJSONFile(String path, JsonArray& root) {
|
||||
if (path.charAt(0) != SLASH) path = String(SLASH) + path;
|
||||
|
||||
//create buffer
|
||||
// create buffer
|
||||
String buf;
|
||||
|
||||
//convert JSON object into string and write it into buffer
|
||||
// convert JSON object into string and write it into buffer
|
||||
root.printTo(buf);
|
||||
|
||||
//if buffer too big
|
||||
// if buffer too big
|
||||
if (buf.length() > 2048) {
|
||||
prntln(F_ERROR_TO_BIG );
|
||||
prntln(F_ERROR_TO_BIG);
|
||||
prntln(path);
|
||||
prntln(buf);
|
||||
return;
|
||||
}
|
||||
|
||||
//write buffer into SPIFFS file
|
||||
// write buffer into SPIFFS file
|
||||
writeFile(path, buf);
|
||||
}
|
||||
|
||||
@@ -689,7 +744,4 @@ String formatBytes(size_t bytes) {
|
||||
else return String(bytes / 1024.0 / 1024.0 / 1024.0) + "GB";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // ifndef functions_h
|
||||
File diff suppressed because one or more lines are too long
@@ -19,7 +19,7 @@ extern "C" {
|
||||
/*
|
||||
This file contains all necessary functions for hosting and connecting to an access point.
|
||||
For compatibility and simplicity, all those functions are global.
|
||||
*/
|
||||
*/
|
||||
|
||||
// Important strings
|
||||
const char W_DEAUTHER[] PROGMEM = "deauth.me"; // captive portal domain (alternative to 192.168.4.1)
|
||||
@@ -83,7 +83,7 @@ void stopAP() {
|
||||
}
|
||||
|
||||
void wifiUpdate() {
|
||||
if (wifiMode != WIFI_MODE_OFF && !scan.isScanning()) {
|
||||
if ((wifiMode != WIFI_MODE_OFF) && !scan.isScanning()) {
|
||||
server.handleClient();
|
||||
dnsServer.processNextRequest();
|
||||
}
|
||||
@@ -93,36 +93,51 @@ String getWifiMode() {
|
||||
switch (wifiMode) {
|
||||
case WIFI_MODE_OFF:
|
||||
return W_MODE_OFF;
|
||||
|
||||
break;
|
||||
|
||||
case WIFI_MODE_AP:
|
||||
return W_MODE_AP;
|
||||
|
||||
break;
|
||||
|
||||
case WIFI_MODE_STATION:
|
||||
return W_MODE_ST;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return String();
|
||||
}
|
||||
}
|
||||
|
||||
String getContentType(String filename) {
|
||||
if (server.hasArg("download"))
|
||||
return String(F("application/octet-stream"));
|
||||
if (server.hasArg("download")) return String(F("application/octet-stream"));
|
||||
|
||||
if (filename.endsWith(str(W_DOT_GZIP)))
|
||||
filename = filename.substring(0, filename.length() - 3);
|
||||
if (filename.endsWith(str(W_DOT_GZIP))) filename = filename.substring(0, filename.length() - 3);
|
||||
|
||||
if (filename.endsWith(str(W_DOT_HTM))) return str(W_HTML);
|
||||
|
||||
if (filename.endsWith(str(W_DOT_HTML))) return str(W_HTML);
|
||||
|
||||
if (filename.endsWith(str(W_DOT_CSS))) return str(W_CSS);
|
||||
|
||||
if (filename.endsWith(str(W_DOT_JS))) return str(W_JS);
|
||||
|
||||
if (filename.endsWith(str(W_DOT_PNG))) return str(W_PNG);
|
||||
|
||||
if (filename.endsWith(str(W_DOT_GIF))) return str(W_GIF);
|
||||
|
||||
if (filename.endsWith(str(W_DOT_JPG))) return str(W_JPG);
|
||||
|
||||
if (filename.endsWith(str(W_DOT_ICON))) return str(W_ICON);
|
||||
|
||||
if (filename.endsWith(str(W_DOT_XML))) return str(W_XML);
|
||||
|
||||
if (filename.endsWith(str(W_DOT_PDF))) return str(W_XPDF);
|
||||
|
||||
if (filename.endsWith(str(W_DOT_ZIP))) return str(W_XZIP);
|
||||
|
||||
if (filename.endsWith(str(W_DOT_JSON))) return str(W_JSON);
|
||||
|
||||
return str(W_TXT);
|
||||
@@ -133,6 +148,7 @@ bool handleFileRead(String path) {
|
||||
prnt(path);
|
||||
|
||||
if (!path.charAt(0) == SLASH) path = String(SLASH) + path;
|
||||
|
||||
if (path.charAt(path.length() - 1) == SLASH) path += String(F("index.html"));
|
||||
|
||||
String contentType = getContentType(path);
|
||||
@@ -140,7 +156,8 @@ bool handleFileRead(String path) {
|
||||
if (!SPIFFS.exists(path)) {
|
||||
if (SPIFFS.exists(path + str(W_DOT_GZIP))) path += str(W_DOT_GZIP);
|
||||
else if (SPIFFS.exists(wifi_config_path + path)) path = wifi_config_path + path;
|
||||
else if (SPIFFS.exists(wifi_config_path + path + str(W_DOT_GZIP))) path = wifi_config_path + path + str(W_DOT_GZIP);
|
||||
else if (SPIFFS.exists(wifi_config_path + path + str(W_DOT_GZIP))) path = wifi_config_path + path + str(
|
||||
W_DOT_GZIP);
|
||||
else {
|
||||
prntln(W_NOT_FOUND);
|
||||
return false;
|
||||
@@ -155,8 +172,9 @@ bool handleFileRead(String path) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
void handleFileUpload() {
|
||||
void handleFileUpload() {
|
||||
// only allow uploads on /edit address
|
||||
if (server.uri() != "/edit")
|
||||
return;
|
||||
@@ -180,9 +198,10 @@ void handleFileUpload() {
|
||||
//Serial.print("handleFileUpload Size: ");
|
||||
//Serial.println(upload.totalSize);
|
||||
}
|
||||
}*/
|
||||
}*/
|
||||
|
||||
/*
|
||||
void handleFileDelete() {
|
||||
void handleFileDelete() {
|
||||
if (server.args() == 0)
|
||||
return server.send(500, str(W_TXT), str(W_BAD_ARGS));
|
||||
|
||||
@@ -194,9 +213,10 @@ void handleFileDelete() {
|
||||
return server.send(404, str(W_TXT), str(W_FILE_NOT_FOUND));
|
||||
SPIFFS.remove(path);
|
||||
server.send(200, str(W_TXT), String());
|
||||
}*/
|
||||
}*/
|
||||
|
||||
/*
|
||||
void handleFileCreate() {
|
||||
void handleFileCreate() {
|
||||
if (server.args() == 0)
|
||||
return server.send(500, str(W_TXT), str(W_BAD_ARGS));
|
||||
|
||||
@@ -212,8 +232,7 @@ void handleFileCreate() {
|
||||
else
|
||||
return server.send(500, str(W_TXT), "CREATE FAILED");
|
||||
server.send(200, str(W_TXT), "");
|
||||
}*/
|
||||
|
||||
}*/
|
||||
void handleFileList() {
|
||||
if (!server.hasArg("dir")) {
|
||||
server.send(500, str(W_TXT), str(W_BAD_ARGS));
|
||||
@@ -221,19 +240,18 @@ void handleFileList() {
|
||||
}
|
||||
|
||||
String path = server.arg("dir");
|
||||
//Serial.println("handleFileList: " + path);
|
||||
// Serial.println("handleFileList: " + path);
|
||||
Dir dir = SPIFFS.openDir(path);
|
||||
|
||||
String output = String(OPEN_BRACKET); // {
|
||||
File entry;
|
||||
bool first = true;
|
||||
|
||||
while (dir.next()) {
|
||||
entry = dir.openFile("r");
|
||||
|
||||
if(first)
|
||||
first = false;
|
||||
else
|
||||
output += COMMA; // ,
|
||||
if (first) first = false;
|
||||
else output += COMMA; // ,
|
||||
|
||||
output += OPEN_BRACKET; // [
|
||||
output += String(DOUBLEQUOTES) + entry.name() + String(DOUBLEQUOTES); // "filename"
|
||||
@@ -252,7 +270,8 @@ void sendProgmem(const char* ptr, size_t size, const char* type) {
|
||||
server.send_P(200, str(type).c_str(), ptr, size);
|
||||
}
|
||||
|
||||
// path = folder of web files, ssid = name of network, password = password ("0" => no password), hidden = if the network is visible, captivePortal = enable a captive portal
|
||||
// path = folder of web files, ssid = name of network, password = password ("0" => no password), hidden = if the network
|
||||
// is visible, captivePortal = enable a captive portal
|
||||
void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal) {
|
||||
if (password.length() < 8) {
|
||||
prntln(W_ERROR_PASSWORD);
|
||||
@@ -260,6 +279,7 @@ void startAP(String path, String ssid, String password, uint8_t ch, bool hidden,
|
||||
}
|
||||
|
||||
if (!path.charAt(0) == SLASH) path = String(SLASH) + path;
|
||||
|
||||
if (password == String(ZERO)) password = String(NEWLINE);
|
||||
|
||||
wifi_config_path = path;
|
||||
@@ -277,96 +297,95 @@ void startAP(String path, String ssid, String password, uint8_t ch, bool hidden,
|
||||
|
||||
MDNS.begin(str(W_DEAUTHER).c_str());
|
||||
|
||||
server.on(String(F("/list")).c_str(), HTTP_GET, handleFileList); //list directory
|
||||
server.on(String(F("/list")).c_str(), HTTP_GET, handleFileList); // list directory
|
||||
|
||||
|
||||
// ================================================================
|
||||
// post here the output of the webConverter.py
|
||||
// ================================================================
|
||||
// post here the output of the webConverter.py
|
||||
|
||||
if(!settings.getWebSpiffs()){
|
||||
server.on(String(SLASH).c_str(), HTTP_GET, [](){
|
||||
if (!settings.getWebSpiffs()) {
|
||||
server.on(String(SLASH).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/attack.html")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/attack.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(attackhtml, sizeof(attackhtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/index.html")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/index.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/info.html")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/info.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(infohtml, sizeof(infohtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/scan.html")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/scan.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(scanhtml, sizeof(scanhtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/settings.html")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/settings.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(settingshtml, sizeof(settingshtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/ssids.html")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/ssids.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(ssidshtml, sizeof(ssidshtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/style.css")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/style.css")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(stylecss, sizeof(stylecss), W_CSS);
|
||||
});
|
||||
server.on(String(F("/js/attack.js")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/js/attack.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(attackjs, sizeof(attackjs), W_JS);
|
||||
});
|
||||
server.on(String(F("/js/scan.js")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/js/scan.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(scanjs, sizeof(scanjs), W_JS);
|
||||
});
|
||||
server.on(String(F("/js/settings.js")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/js/settings.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(settingsjs, sizeof(settingsjs), W_JS);
|
||||
});
|
||||
server.on(String(F("/js/site.js")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/js/site.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(sitejs, sizeof(sitejs), W_JS);
|
||||
});
|
||||
server.on(String(F("/js/ssids.js")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/js/ssids.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(ssidsjs, sizeof(ssidsjs), W_JS);
|
||||
});
|
||||
server.on(String(F("/lang/cn.lang")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/lang/cn.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(cnlang, sizeof(cnlang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/cs.lang")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/lang/cs.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(cslang, sizeof(cslang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/de.lang")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/lang/de.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(delang, sizeof(delang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/en.lang")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/lang/en.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(enlang, sizeof(enlang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/fr.lang")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/lang/fr.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(frlang, sizeof(frlang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/it.lang")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/lang/it.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(itlang, sizeof(itlang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/ru.lang")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/lang/ru.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(rulang, sizeof(rulang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/tlh.lang")).c_str(), HTTP_GET, [](){
|
||||
});
|
||||
server.on(String(F("/lang/tlh.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
|
||||
});
|
||||
|
||||
}
|
||||
server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, [](){
|
||||
if(!settings.getWebSpiffs()){
|
||||
if(settings.getLang() == String(F("cn"))) sendProgmem(cnlang, sizeof(cnlang), W_JSON);
|
||||
else if(settings.getLang() == String(F("cs"))) sendProgmem(cslang, sizeof(cslang), W_JSON);
|
||||
else if(settings.getLang() == String(F("de"))) sendProgmem(delang, sizeof(delang), W_JSON);
|
||||
else if(settings.getLang() == String(F("en"))) sendProgmem(enlang, sizeof(enlang), W_JSON);
|
||||
else if(settings.getLang() == String(F("fr"))) sendProgmem(frlang, sizeof(frlang), W_JSON);
|
||||
else if(settings.getLang() == String(F("it"))) sendProgmem(itlang, sizeof(itlang), W_JSON);
|
||||
else if(settings.getLang() == String(F("ru"))) sendProgmem(rulang, sizeof(rulang), W_JSON);
|
||||
else if(settings.getLang() == String(F("tlh"))) sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
|
||||
|
||||
else handleFileRead(String(F("/web/lang/"))+settings.getLang()+String(F(".lang")));
|
||||
} else {
|
||||
handleFileRead(String(F("/web/lang/"))+settings.getLang()+String(F(".lang")));
|
||||
});
|
||||
}
|
||||
});
|
||||
server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, []() {
|
||||
if (!settings.getWebSpiffs()) {
|
||||
if (settings.getLang() == String(F("cn"))) sendProgmem(cnlang, sizeof(cnlang), W_JSON);
|
||||
else if (settings.getLang() == String(F("cs"))) sendProgmem(cslang, sizeof(cslang), W_JSON);
|
||||
else if (settings.getLang() == String(F("de"))) sendProgmem(delang, sizeof(delang), W_JSON);
|
||||
else if (settings.getLang() == String(F("en"))) sendProgmem(enlang, sizeof(enlang), W_JSON);
|
||||
else if (settings.getLang() == String(F("fr"))) sendProgmem(frlang, sizeof(frlang), W_JSON);
|
||||
else if (settings.getLang() == String(F("it"))) sendProgmem(itlang, sizeof(itlang), W_JSON);
|
||||
else if (settings.getLang() == String(F("ru"))) sendProgmem(rulang, sizeof(rulang), W_JSON);
|
||||
else if (settings.getLang() == String(F("tlh"))) sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
|
||||
|
||||
// ================================================================
|
||||
else handleFileRead(String(F("/web/lang/")) + settings.getLang() + String(F(".lang")));
|
||||
} else {
|
||||
handleFileRead(String(F("/web/lang/")) + settings.getLang() + String(F(".lang")));
|
||||
}
|
||||
});
|
||||
|
||||
// ================================================================
|
||||
|
||||
server.on(String(F("/run")).c_str(), HTTP_GET, []() {
|
||||
server.send(200, str(W_TXT), str(W_OK).c_str());
|
||||
@@ -396,8 +415,8 @@ server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, [](){
|
||||
// aggressively caching static assets
|
||||
server.serveStatic("/js", SPIFFS, String(wifi_config_path + "/js").c_str(), "max-age=86400");
|
||||
|
||||
//called when the url is not defined here
|
||||
//use it to load content from SPIFFS
|
||||
// called when the url is not defined here
|
||||
// use it to load content from SPIFFS
|
||||
server.onNotFound([]() {
|
||||
if (!handleFileRead(server.uri())) {
|
||||
server.send(404, str(W_TXT), str(W_FILE_NOT_FOUND));
|
||||
@@ -411,18 +430,20 @@ server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, [](){
|
||||
printWifiStatus();
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
prnt(String(F("[WiFi] Path: '")));
|
||||
prnt(wifi_config_path);
|
||||
prnt(String(F("', Mode: '")));
|
||||
switch(wifiMode){
|
||||
|
||||
switch (wifiMode) {
|
||||
case WIFI_MODE_OFF:
|
||||
prnt(W_MODE_OFF);
|
||||
break;
|
||||
|
||||
case WIFI_MODE_AP:
|
||||
prnt(W_AP);
|
||||
break;
|
||||
|
||||
case WIFI_MODE_STATION:
|
||||
prnt(W_STATION);
|
||||
break;
|
||||
@@ -439,8 +460,9 @@ void printWifiStatus() {
|
||||
prntln(b2s(wifi_config_captivePortal));
|
||||
}
|
||||
|
||||
void startAP(){
|
||||
startAP(wifi_config_path.c_str(), wifi_config_ssid.c_str(), wifi_config_password.c_str(), wifi_channel, wifi_config_hidden, wifi_config_captivePortal);
|
||||
void startAP() {
|
||||
startAP(wifi_config_path.c_str(), wifi_config_ssid.c_str(),
|
||||
wifi_config_password.c_str(), wifi_channel, wifi_config_hidden, wifi_config_captivePortal);
|
||||
}
|
||||
|
||||
void startAP(String path) {
|
||||
@@ -466,5 +488,4 @@ void resumeAP() {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // ifndef WifiManager_h
|
||||
Reference in New Issue
Block a user