From f0f1dc7b70995fba492e7e80d7392df2abad0466 Mon Sep 17 00:00:00 2001 From: mh4x0f Date: Thu, 30 Jun 2022 22:33:31 -0300 Subject: [PATCH] added: improvement on captiveflask plugin, added new module for install custom captiveflask --- config/templates/Flask/templates/login.html | 50 -------- .../Flask/templates/login_successful.html | 12 -- .../{Flask => FlaskDemo}/preview.png | Bin .../static/css/bootstrap.min.css | 0 .../{Flask => FlaskDemo}/static/css/main.css | 0 .../static/css/styles.css | 0 .../{Flask => FlaskDemo}/static/css/util.css | 0 .../static/fonts/google_fonts.css | 0 .../static/js/bootstrap.min.js | 0 .../static/js/jquery-1.11.1.min.js | 0 .../{Flask => FlaskDemo}/static/js/main.js | 0 .../templates}/En/templates/login.html | 0 .../En/templates/login_successful.html | 0 .../templates}/ptBr/templates/login.html | 0 .../ptBr/templates/login_successful.html | 0 helps/help_install_customcaptiveflask.txt | 13 ++ .../modules/misc/custom_captiveflask.py | 117 ++++++++++++++++++ .../plugins/captiveflask/DarkLogin.py | 22 ++-- .../plugins/captiveflask/flask_demo.py | 32 ++--- .../plugins/captiveflask/loginPage.py | 25 ++-- wifipumpkin3/plugins/captiveflask/login_v4.py | 23 ++-- wifipumpkin3/plugins/captiveflask/plugin.py | 41 ++++-- 22 files changed, 190 insertions(+), 145 deletions(-) delete mode 100644 config/templates/Flask/templates/login.html delete mode 100644 config/templates/Flask/templates/login_successful.html rename config/templates/{Flask => FlaskDemo}/preview.png (100%) rename config/templates/{Flask => FlaskDemo}/static/css/bootstrap.min.css (100%) rename config/templates/{Flask => FlaskDemo}/static/css/main.css (100%) rename config/templates/{Flask => FlaskDemo}/static/css/styles.css (100%) rename config/templates/{Flask => FlaskDemo}/static/css/util.css (100%) rename config/templates/{Flask => FlaskDemo}/static/fonts/google_fonts.css (100%) rename config/templates/{Flask => FlaskDemo}/static/js/bootstrap.min.js (100%) rename config/templates/{Flask => FlaskDemo}/static/js/jquery-1.11.1.min.js (100%) rename config/templates/{Flask => FlaskDemo}/static/js/main.js (100%) rename config/templates/{Flask/language => FlaskDemo/templates}/En/templates/login.html (100%) rename config/templates/{Flask/language => FlaskDemo/templates}/En/templates/login_successful.html (100%) rename config/templates/{Flask/language => FlaskDemo/templates}/ptBr/templates/login.html (100%) rename config/templates/{Flask/language => FlaskDemo/templates}/ptBr/templates/login_successful.html (100%) create mode 100644 helps/help_install_customcaptiveflask.txt create mode 100644 wifipumpkin3/modules/misc/custom_captiveflask.py diff --git a/config/templates/Flask/templates/login.html b/config/templates/Flask/templates/login.html deleted file mode 100644 index 84f4106..0000000 --- a/config/templates/Flask/templates/login.html +++ /dev/null @@ -1,50 +0,0 @@ - - - -Authentification - - - - - - - -
- -
- Login:
- -
- Password:
- -

- -
-
- - - - \ No newline at end of file diff --git a/config/templates/Flask/templates/login_successful.html b/config/templates/Flask/templates/login_successful.html deleted file mode 100644 index fb90626..0000000 --- a/config/templates/Flask/templates/login_successful.html +++ /dev/null @@ -1,12 +0,0 @@ - - - -Authentification - - - - -

Login successful

- - - \ No newline at end of file diff --git a/config/templates/Flask/preview.png b/config/templates/FlaskDemo/preview.png similarity index 100% rename from config/templates/Flask/preview.png rename to config/templates/FlaskDemo/preview.png diff --git a/config/templates/Flask/static/css/bootstrap.min.css b/config/templates/FlaskDemo/static/css/bootstrap.min.css similarity index 100% rename from config/templates/Flask/static/css/bootstrap.min.css rename to config/templates/FlaskDemo/static/css/bootstrap.min.css diff --git a/config/templates/Flask/static/css/main.css b/config/templates/FlaskDemo/static/css/main.css similarity index 100% rename from config/templates/Flask/static/css/main.css rename to config/templates/FlaskDemo/static/css/main.css diff --git a/config/templates/Flask/static/css/styles.css b/config/templates/FlaskDemo/static/css/styles.css similarity index 100% rename from config/templates/Flask/static/css/styles.css rename to config/templates/FlaskDemo/static/css/styles.css diff --git a/config/templates/Flask/static/css/util.css b/config/templates/FlaskDemo/static/css/util.css similarity index 100% rename from config/templates/Flask/static/css/util.css rename to config/templates/FlaskDemo/static/css/util.css diff --git a/config/templates/Flask/static/fonts/google_fonts.css b/config/templates/FlaskDemo/static/fonts/google_fonts.css similarity index 100% rename from config/templates/Flask/static/fonts/google_fonts.css rename to config/templates/FlaskDemo/static/fonts/google_fonts.css diff --git a/config/templates/Flask/static/js/bootstrap.min.js b/config/templates/FlaskDemo/static/js/bootstrap.min.js similarity index 100% rename from config/templates/Flask/static/js/bootstrap.min.js rename to config/templates/FlaskDemo/static/js/bootstrap.min.js diff --git a/config/templates/Flask/static/js/jquery-1.11.1.min.js b/config/templates/FlaskDemo/static/js/jquery-1.11.1.min.js similarity index 100% rename from config/templates/Flask/static/js/jquery-1.11.1.min.js rename to config/templates/FlaskDemo/static/js/jquery-1.11.1.min.js diff --git a/config/templates/Flask/static/js/main.js b/config/templates/FlaskDemo/static/js/main.js similarity index 100% rename from config/templates/Flask/static/js/main.js rename to config/templates/FlaskDemo/static/js/main.js diff --git a/config/templates/Flask/language/En/templates/login.html b/config/templates/FlaskDemo/templates/En/templates/login.html similarity index 100% rename from config/templates/Flask/language/En/templates/login.html rename to config/templates/FlaskDemo/templates/En/templates/login.html diff --git a/config/templates/Flask/language/En/templates/login_successful.html b/config/templates/FlaskDemo/templates/En/templates/login_successful.html similarity index 100% rename from config/templates/Flask/language/En/templates/login_successful.html rename to config/templates/FlaskDemo/templates/En/templates/login_successful.html diff --git a/config/templates/Flask/language/ptBr/templates/login.html b/config/templates/FlaskDemo/templates/ptBr/templates/login.html similarity index 100% rename from config/templates/Flask/language/ptBr/templates/login.html rename to config/templates/FlaskDemo/templates/ptBr/templates/login.html diff --git a/config/templates/Flask/language/ptBr/templates/login_successful.html b/config/templates/FlaskDemo/templates/ptBr/templates/login_successful.html similarity index 100% rename from config/templates/Flask/language/ptBr/templates/login_successful.html rename to config/templates/FlaskDemo/templates/ptBr/templates/login_successful.html diff --git a/helps/help_install_customcaptiveflask.txt b/helps/help_install_customcaptiveflask.txt new file mode 100644 index 0000000..cd1ae24 --- /dev/null +++ b/helps/help_install_customcaptiveflask.txt @@ -0,0 +1,13 @@ +install new template on captiveflask: + + Usage: install plugin_name file_complete_path.zip + param plugin_name: the plugin_name name is the same [plugin_name].py + file_complete_path.zip: complete file path with .zip + + Description: + Install a custom captiveflask templates from command line + require restart the wifipumpkin3 for load all plugins + + +Referencies: + https://wifipumpkin3.github.io/docs/getting-started#creating-captive-portal-template \ No newline at end of file diff --git a/wifipumpkin3/modules/misc/custom_captiveflask.py b/wifipumpkin3/modules/misc/custom_captiveflask.py new file mode 100644 index 0000000..10b5161 --- /dev/null +++ b/wifipumpkin3/modules/misc/custom_captiveflask.py @@ -0,0 +1,117 @@ +from wifipumpkin3.core.common.terminal import ModuleUI +from wifipumpkin3.core.config.globalimport import * +from wifipumpkin3.core.utility.printer import ( + display_messages, + setcolor +) +import tempfile +from os import path +from zipfile import ZipFile +import wifipumpkin3.core.utility.constants as C +from wifipumpkin3.core.utility.collection import SettingsINI +from distutils.dir_util import copy_tree +from shutil import copyfile + +# This file is part of the wifipumpkin3 Open Source Project. +# wifipumpkin3 is licensed under the Apache 2.0. + +# Copyright 2020 P0cL4bs Team - Marcos Bomfim (mh4x0f) + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +class ModPump(ModuleUI): + """Install custom captiveflask templates""" + + name = "custom_captiveflask" + + temp_path = tempfile.gettempdir() + captiveflask_setup_path = C.wp3_setup_packager_path + "/plugins/captiveflask" + + config_default = SettingsINI(C.CONFIG_CP_INI_ROOT) + + def __init__(self, parse_args=None, root=None): + self.parse_args = parse_args + self.root = root + self.name_module = self.name + + self.plugins_remote = {} + self.table_headers = ["Name", "Author", "Installed", "Preview"] + super(ModPump, self).__init__(parse_args=self.parse_args, root=self.root) + + def do_install(self, args): + """install captiveflask template by zip file""" + if args: + try: + plugin_name, file_path = args.split()[0], args.split()[1] + except Exception as e: + return print(display_messages("the argument is invalid please type ?install for more information", error=True)) + if not path.isfile(file_path): + return print( + display_messages( + "the file {} not found ".format(file_path), error=True + ) + ) + head, tail = os.path.split(file_path) + dest = copyfile(file_path, "{}/{}".format(self.temp_path, tail)) + print(display_messages("copy content file .zip to {}".format(dest), info=True)) + + path_to_zip_file = tempfile.gettempdir() + "/{}".format(tail) + with ZipFile(path_to_zip_file, "r") as zip_ref: + zip_ref.extractall(tempfile.gettempdir()) + temp_path_file_extracted = "{}/{}.py".format(self.temp_path, plugin_name) + print( + display_messages( + "extracted files on : {}".format(temp_path_file_extracted), info=True + ) + ) + if not path.isfile(temp_path_file_extracted): + return print( + display_messages( + "the file {} not found ".format(temp_path_file_extracted), error=True + ) + ) + temp_templates_path = "{}/{}".format(self.temp_path, plugin_name) + if not path.isdir(temp_templates_path): + return print( + display_messages( + "the directory template {} not found ".format(temp_templates_path), error=True + ) + ) + source = temp_path_file_extracted + destination = "{}/{}.py".format(self.captiveflask_setup_path, plugin_name) + dest = copyfile(source, destination) + print(display_messages("copy content file to {}".format(dest), info=True)) + + copy_tree( + temp_templates_path, C.config_dir + "/config/templates/{}".format(plugin_name) + ) + print( + display_messages( + "plugin {} install {}".format( plugin_name,setcolor("sucessful", color="green")), + info=True, + ) + ) + return + print( + display_messages("unknown command: {} ".format(args), error=True) + ) + + def help_install(self): + self.show_help_command("help_install_customcaptiveflask") + + def do_options(self, line): + pass + + def do_set(self, args): + pass diff --git a/wifipumpkin3/plugins/captiveflask/DarkLogin.py b/wifipumpkin3/plugins/captiveflask/DarkLogin.py index d225693..b162d86 100644 --- a/wifipumpkin3/plugins/captiveflask/DarkLogin.py +++ b/wifipumpkin3/plugins/captiveflask/DarkLogin.py @@ -20,18 +20,10 @@ import wifipumpkin3.core.utility.constants as C class DarkLogin(CaptiveTemplatePlugin): - meta = { - "Name": "DarkLogin", - "Version": "1.0", - "Description": "Example is a simple portal default page", - "Author": "Pumpkin-Dev", - "TemplatePath": C.TEMPLATES_FLASK + "templates/DarkLogin", - "StaticPath": C.TEMPLATES_FLASK + "templates/DarkLogin/static", - "Preview": "plugins/captivePortal/templates/DarkLogin/preview.png", - } - - def __init__(self): - for key, value in self.meta.items(): - self.__dict__[key] = value - self.dict_domain = {} - self.ConfigParser = False + Name = "DarkLogin" + Version = "1.0" + Description = "Example is a simple portal default page" + Author = "Pumpkin-Dev" + TemplatePath = C.TEMPLATES_FLASK + "templates/DarkLogin" + StaticPath = C.TEMPLATES_FLASK + "templates/DarkLogin/static" + Preview = C.TEMPLATES_FLASK + "templates/DarkLogin/preview.png" diff --git a/wifipumpkin3/plugins/captiveflask/flask_demo.py b/wifipumpkin3/plugins/captiveflask/flask_demo.py index 0b05fce..b50623f 100644 --- a/wifipumpkin3/plugins/captiveflask/flask_demo.py +++ b/wifipumpkin3/plugins/captiveflask/flask_demo.py @@ -20,27 +20,11 @@ import wifipumpkin3.core.utility.constants as C class FlaskDemo(CaptiveTemplatePlugin): - meta = { - "Name": "FlaskDemo", - "Version": "1.0", - "Description": "Example is a simple portal default page", - "Author": "Pumpkin-Dev", - "TemplatePath": C.TEMPLATES_FLASK + "templates/Flask", - "StaticPath": C.TEMPLATES_FLASK + "templates/Flask/static", - "Preview": "plugins/captivePortal/templates/Flask/preview.png", - } - - def __init__(self): - for key, value in self.meta.items(): - self.__dict__[key] = value - self.dict_domain = {} - self.ConfigParser = True - - def init_language(self, lang): - if lang.lower() != "default": - self.TemplatePath = ( - C.TEMPLATES_FLASK + "templates/Flask/language/{}".format(lang) - ) - return - for key, value in self.meta.items(): - self.__dict__[key] = value + Name = "FlaskDemo" + Version = "1.0" + Description = "Example is a simple portal default page" + Author = "Pumpkin-Dev" + TemplatePath = C.TEMPLATES_FLASK + "templates/Flask" + StaticPath = C.TEMPLATES_FLASK + "templates/Flask/static" + Preview = C.TEMPLATES_FLASK + "templates/Flask/preview.png" + Languages = ["En", "ptBr"] \ No newline at end of file diff --git a/wifipumpkin3/plugins/captiveflask/loginPage.py b/wifipumpkin3/plugins/captiveflask/loginPage.py index 34d6bbe..29841c9 100644 --- a/wifipumpkin3/plugins/captiveflask/loginPage.py +++ b/wifipumpkin3/plugins/captiveflask/loginPage.py @@ -4,7 +4,7 @@ import wifipumpkin3.core.utility.constants as C # This file is part of the wifipumpkin3 Open Source Project. # wifipumpkin3 is licensed under the Apache 2.0. -# Copyright 2020 P0cL4bs Team - Marcos Bomfim (mh4x0f) +# Copyright 2022 P0cL4bs Team - Marcos Bomfim (mh4x0f) # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,19 +20,10 @@ import wifipumpkin3.core.utility.constants as C class LoginPage(CaptiveTemplatePlugin): - meta = { - "Name": "loginPage", - "Version": "1.0", - "Description": "Example is a simple portal default page", - "Author": "Pumpkin-Dev", - "Language": "En", - "TemplatePath": C.TEMPLATES_FLASK + "templates/loginPage", - "StaticPath": C.TEMPLATES_FLASK + "templates/loginPage/static", - "Preview": "plugins/captivePortal/templates/loginPage/preview.png", - } - - def __init__(self): - for key, value in self.meta.items(): - self.__dict__[key] = value - self.dict_domain = {} - self.ConfigParser = False + Name = "loginPage" + Version = "1.0" + Description = "Example is a simple portal default page" + Author = "Pumpkin-Dev" + TemplatePath = C.TEMPLATES_FLASK + "templates/loginPage" + StaticPath = C.TEMPLATES_FLASK + "templates/loginPage/static" + Preview = C.TEMPLATES_FLASK + "templates/loginPage/preview.png" \ No newline at end of file diff --git a/wifipumpkin3/plugins/captiveflask/login_v4.py b/wifipumpkin3/plugins/captiveflask/login_v4.py index ba0159a..fdba5a3 100644 --- a/wifipumpkin3/plugins/captiveflask/login_v4.py +++ b/wifipumpkin3/plugins/captiveflask/login_v4.py @@ -20,19 +20,10 @@ import wifipumpkin3.core.utility.constants as C class Loginv4(CaptiveTemplatePlugin): - meta = { - "Name": "Login_v4", - "Version": "1.0", - "Description": "Example is a simple portal default page", - "Author": "Pumpkin-Dev", - "Language": "En", - "TemplatePath": C.TEMPLATES_FLASK + "templates/Login_v4", - "StaticPath": C.TEMPLATES_FLASK + "templates/Login_v4/static", - "Preview": "plugins/captivePortal/templates/Login_v4/preview.png", - } - - def __init__(self): - for key, value in self.meta.items(): - self.__dict__[key] = value - self.dict_domain = {} - self.ConfigParser = False + Name = "Login_v4" + Version = "1.0" + Description = "Example is a simple portal default page" + Author = "Pumpkin-Dev" + TemplatePath = C.TEMPLATES_FLASK + "templates/Login_v4" + StaticPath = C.TEMPLATES_FLASK + "templates/Login_v4/static" + Preview = C.TEMPLATES_FLASK + "templates/Login_v4/preview.png" \ No newline at end of file diff --git a/wifipumpkin3/plugins/captiveflask/plugin.py b/wifipumpkin3/plugins/captiveflask/plugin.py index 734c151..16f118f 100644 --- a/wifipumpkin3/plugins/captiveflask/plugin.py +++ b/wifipumpkin3/plugins/captiveflask/plugin.py @@ -1,3 +1,4 @@ +from typing import Optional from wifipumpkin3.core.utility.collection import SettingsINI import wifipumpkin3.core.utility.constants as C @@ -20,20 +21,38 @@ import wifipumpkin3.core.utility.constants as C class CaptiveTemplatePlugin(object): - Name = "plugin template captive-portal" - version = "1.0" - config = SettingsINI(C.CONFIG_CP_INI) - loggers = {} + Name: str = "CaptiveTemplatePlugin" + Version: str = "1.1" + Description: str = "Example is a simple portal default page" + Author: str = "Pumpkin-Dev" + TemplatePath: str = None + StaticPath: str = None + Preview: str = None + Languages: Optional[list] = [] + config: SettingsINI = SettingsINI(C.CONFIG_CP_INI) + + def __init__(self) -> None: + if self.Languages: + key = "set_{}".format(self.Name) + if not self.config.get_all_childname(key): + for lang in self.Languages: + self.config.set(key, lang, False) + self.config.set(key, self.Languages[0], True) + if not self.Name in self.config.get_all_childname("plugins"): + self.config.set("plugins", self.Name, False) - def init_language(self, lang): - pass + def init_language(self, lang: Optional[str]): + if lang: + self.TemplatePath = ( + C.TEMPLATES_FLASK + "templates/{}/templates/{}".format(self.Name, lang) + ) - def getSellectedLanguage(self): - selected_lang, key = None, "set_{}".format(self.Name) + def getActivatedLanguage(self) -> Optional[str]: + key = "set_{}".format(self.Name) for lang in self.config.get_all_childname(key): if self.config.get(key, lang, format=bool): - selected_lang = lang - return selected_lang + return lang + return None def initialize(self): - self.init_language(self.getSellectedLanguage()) + self.init_language(self.getActivatedLanguage())