added: improvement on captiveflask plugin, added new module for install custom captiveflask

This commit is contained in:
mh4x0f 2022-06-30 22:33:31 -03:00
parent 818a93944f
commit f0f1dc7b70
22 changed files with 190 additions and 145 deletions

View File

@ -1,50 +0,0 @@
<!DOCTYPE html>
<html lang="fr-FR">
<head>
<title>Authentification</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/util.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/main.css') }}">
</head>
<style>
.content {
max-width: 500px;
margin: auto;
}
.align {
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
</style>
<body class="align">
<div class="container">
<!-- Page content -->
<form method="POST" >
Login:<br>
<input type="text" name="login">
<br>
Password:<br>
<input type="text" name="password">
<br><br>
<input type="submit" value="Envoyer">
</form>
</div>
</body>
</html>

View File

@ -1,12 +0,0 @@
<!DOCTYPE html>
<html lang="fr-FR">
<head>
<title>Authentification</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/util.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/main.css') }}">
</head>
<h1>Login successful</h1>
</body>
</html>

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -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

View File

@ -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

View File

@ -20,18 +20,10 @@ import wifipumpkin3.core.utility.constants as C
class DarkLogin(CaptiveTemplatePlugin): class DarkLogin(CaptiveTemplatePlugin):
meta = { Name = "DarkLogin"
"Name": "DarkLogin", Version = "1.0"
"Version": "1.0", Description = "Example is a simple portal default page"
"Description": "Example is a simple portal default page", Author = "Pumpkin-Dev"
"Author": "Pumpkin-Dev", TemplatePath = C.TEMPLATES_FLASK + "templates/DarkLogin"
"TemplatePath": C.TEMPLATES_FLASK + "templates/DarkLogin", StaticPath = C.TEMPLATES_FLASK + "templates/DarkLogin/static"
"StaticPath": C.TEMPLATES_FLASK + "templates/DarkLogin/static", Preview = C.TEMPLATES_FLASK + "templates/DarkLogin/preview.png"
"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

View File

@ -20,27 +20,11 @@ import wifipumpkin3.core.utility.constants as C
class FlaskDemo(CaptiveTemplatePlugin): class FlaskDemo(CaptiveTemplatePlugin):
meta = { Name = "FlaskDemo"
"Name": "FlaskDemo", Version = "1.0"
"Version": "1.0", Description = "Example is a simple portal default page"
"Description": "Example is a simple portal default page", Author = "Pumpkin-Dev"
"Author": "Pumpkin-Dev", TemplatePath = C.TEMPLATES_FLASK + "templates/Flask"
"TemplatePath": C.TEMPLATES_FLASK + "templates/Flask", StaticPath = C.TEMPLATES_FLASK + "templates/Flask/static"
"StaticPath": C.TEMPLATES_FLASK + "templates/Flask/static", Preview = C.TEMPLATES_FLASK + "templates/Flask/preview.png"
"Preview": "plugins/captivePortal/templates/Flask/preview.png", Languages = ["En", "ptBr"]
}
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

View File

@ -4,7 +4,7 @@ import wifipumpkin3.core.utility.constants as C
# This file is part of the wifipumpkin3 Open Source Project. # This file is part of the wifipumpkin3 Open Source Project.
# wifipumpkin3 is licensed under the Apache 2.0. # 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"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with 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): class LoginPage(CaptiveTemplatePlugin):
meta = { Name = "loginPage"
"Name": "loginPage", Version = "1.0"
"Version": "1.0", Description = "Example is a simple portal default page"
"Description": "Example is a simple portal default page", Author = "Pumpkin-Dev"
"Author": "Pumpkin-Dev", TemplatePath = C.TEMPLATES_FLASK + "templates/loginPage"
"Language": "En", StaticPath = C.TEMPLATES_FLASK + "templates/loginPage/static"
"TemplatePath": C.TEMPLATES_FLASK + "templates/loginPage", Preview = C.TEMPLATES_FLASK + "templates/loginPage/preview.png"
"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

View File

@ -20,19 +20,10 @@ import wifipumpkin3.core.utility.constants as C
class Loginv4(CaptiveTemplatePlugin): class Loginv4(CaptiveTemplatePlugin):
meta = { Name = "Login_v4"
"Name": "Login_v4", Version = "1.0"
"Version": "1.0", Description = "Example is a simple portal default page"
"Description": "Example is a simple portal default page", Author = "Pumpkin-Dev"
"Author": "Pumpkin-Dev", TemplatePath = C.TEMPLATES_FLASK + "templates/Login_v4"
"Language": "En", StaticPath = C.TEMPLATES_FLASK + "templates/Login_v4/static"
"TemplatePath": C.TEMPLATES_FLASK + "templates/Login_v4", Preview = C.TEMPLATES_FLASK + "templates/Login_v4/preview.png"
"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

View File

@ -1,3 +1,4 @@
from typing import Optional
from wifipumpkin3.core.utility.collection import SettingsINI from wifipumpkin3.core.utility.collection import SettingsINI
import wifipumpkin3.core.utility.constants as C import wifipumpkin3.core.utility.constants as C
@ -20,20 +21,38 @@ import wifipumpkin3.core.utility.constants as C
class CaptiveTemplatePlugin(object): class CaptiveTemplatePlugin(object):
Name = "plugin template captive-portal" Name: str = "CaptiveTemplatePlugin"
version = "1.0" Version: str = "1.1"
config = SettingsINI(C.CONFIG_CP_INI) Description: str = "Example is a simple portal default page"
loggers = {} 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): def init_language(self, lang: Optional[str]):
pass if lang:
self.TemplatePath = (
C.TEMPLATES_FLASK + "templates/{}/templates/{}".format(self.Name, lang)
)
def getSellectedLanguage(self): def getActivatedLanguage(self) -> Optional[str]:
selected_lang, key = None, "set_{}".format(self.Name) key = "set_{}".format(self.Name)
for lang in self.config.get_all_childname(key): for lang in self.config.get_all_childname(key):
if self.config.get(key, lang, format=bool): if self.config.get(key, lang, format=bool):
selected_lang = lang return lang
return selected_lang return None
def initialize(self): def initialize(self):
self.init_language(self.getSellectedLanguage()) self.init_language(self.getActivatedLanguage())