Skip to content

Commit

Permalink
2.4.0 update codefactor (#130)
Browse files Browse the repository at this point in the history
## Pull Request Template

### Prerequisites

<!-- Take a couple of minutes to help our maintainers work faster by
checking of the pre-requisites. -->
<!-- To tick the checkboxes replace the space with an 'x', so [ ]
becomes [x] . -->

- [x] I have
[searched](https://github.com/DefinetlyNotAI/Logicytics/pulls) for
duplicate or closed issues.
- [x] I have read the [contributing
guidelines](https://github.com/DefinetlyNotAI/Logicytics/blob/main/CONTRIBUTING.md).
- [x] I have followed the instructions in the
[wiki](https://github.com/DefinetlyNotAI/Logicytics/wiki) about
contributions.
- [ ] I have updated the documentation accordingly, if required.
- [ ] I have added tests to cover my changes, and they have passed, if
required.
- [ ] I have tested my code with the `--dev` flag, if required.

### PR Type

<!-- Take a couple of minutes to help our maintainers work faster by
telling us what is the PR guided on. -->
<!-- To tick the checkboxes replace the space with an 'x', so [ ]
becomes [x] . -->

- [x] Bug fix <!-- Non-Breaking Bug Fix - Usually relates to fixing an
issue -->
- [ ] New feature <!-- Non-Breaking Change that adds a new feature -->
- [ ] Refactoring <!-- Non-Breaking Change that modifies existing code
to refactor it to become more organised -->
- [ ] Documentation
update <!-- Non-Breaking Change that modifies existing documentation to
refactor it or add extra comments - either wiki, md files or code is
included here -->
- [ ] ⚠️ Breaking change ⚠️ <!-- Breaking Bug Fix / New Addition that
changes how Logicytics works -->

### Description

Fixed some issues, deprecated website, made minor changes

### Motivation and Context

Bug issues, and security vulnerabilities

### Binaries

<!-- If you have any binaries built from the AIP, Upload them here -->
<!-- OPTIONAL for patch updates - To leave empty just type _N/A_ -->

_N/A_

### Credit

<!-- If this PR is a contribution, please mention the contributors here
using the appropriate syntax. -->
_N/A_
<!--
### File-Created/CONTRIBUTION by MAIN-Username
What you did, created, removed, refactored, fixed, or discovered.
- [Your GitHub Username](https://github.com/YourGitHubLink)
- [Your GitHub Username](https://github.com/YourGitHubLink) etc...
-->

### Issues Fixed

<!-- REQUIRED: What issues will be fixed? (Format: "#50, #23" etc.) if
none exist type _N/A_ -->
[Security Advisory
GHSA-5wvr-vvqf-668m](GHSA-5wvr-vvqf-668m)
  • Loading branch information
DefinetlyNotAI authored Oct 28, 2024
2 parents 0e826bf + dd248b0 commit 8f59424
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 222 deletions.
2 changes: 1 addition & 1 deletion .bandit
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# FILE: .bandit
[bandit]
skips: ['B607', 'B605']
skips: ['B607', 'B605']
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,4 @@ $RECYCLE.BIN/
*.pyc
/CODE/SysInternal_Suite/.sys.ignore
/ACCESS/
/todo.txt
4 changes: 3 additions & 1 deletion CODE/__lib_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,6 @@ def __run_other_script(script: str):

DEBUG, VERSION, API_KEY, CURRENT_FILES = Actions.read_config()
if __name__ == "__main__":
Log().exception("This is a library file and should not be executed directly.", Exception)
Log().exception(
"This is a library file and should not be executed directly.", Exception
)
91 changes: 61 additions & 30 deletions CODE/__lib_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def __init__(self, config: dict = None):
self.filename = config.get("filename", "../ACCESS/LOGS/Logicytics.log")
if self.color:
logger = colorlog.getLogger()
logger.setLevel(
getattr(logging, config["log_level"].upper(), logging.INFO)
)
logger.setLevel(getattr(logging, config["log_level"].upper(), logging.INFO))
handler = colorlog.StreamHandler()
log_colors = {
"INTERNAL": "cyan",
Expand All @@ -54,7 +52,10 @@ def __init__(self, config: dict = None):
}

formatter = colorlog.ColoredFormatter(
config.get("colorlog_fmt_parameters", "%(log_color)s%(levelname)-8s%(reset)s %(blue)s%(message)s"),
config.get(
"colorlog_fmt_parameters",
"%(log_color)s%(levelname)-8s%(reset)s %(blue)s%(message)s",
),
log_colors=log_colors,
)

Expand All @@ -63,11 +64,19 @@ def __init__(self, config: dict = None):
try:
getattr(logging, config["log_level"].upper())
except AttributeError as AE:
self.__internal(f"Log Level {config['log_level']} not found, setting default level to INFO -> {AE}")
self.__internal(
f"Log Level {config['log_level']} not found, setting default level to INFO -> {AE}"
)

if not os.path.exists(self.filename):
self.newline()
self.raw("| Timestamp | LOG Level |" + " " * 71 + "LOG Messages" + " " * 71 + "|")
self.raw(
"| Timestamp | LOG Level |"
+ " " * 71
+ "LOG Messages"
+ " " * 71
+ "|"
)
self.newline()

@staticmethod
Expand All @@ -77,7 +86,7 @@ def __timestamp() -> str:
:return: Current timestamp in 'YYYY-MM-DD HH:MM:SS' format.
"""
return datetime.now().strftime('%Y-%m-%d %H:%M:%S')
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")

@staticmethod
def __pad_message(message: str) -> str:
Expand All @@ -87,7 +96,11 @@ def __pad_message(message: str) -> str:
:param message: The log message to be padded or truncated.
:return: The padded or truncated message.
"""
return (message + " " * (153 - len(message)) if len(message) < 153 else message[:150] + "...") + "|"
return (
message + " " * (153 - len(message))
if len(message) < 153
else message[:150] + "..."
) + "|"

def raw(self, message):
"""
Expand All @@ -97,9 +110,12 @@ def raw(self, message):
"""
frame = inspect.stack()[1]
if frame.function == "<module>":
self.__internal(f"Raw message called from a non-function - This is not recommended")
with open(self.filename, "a") as f:
f.write(f"{str(message)}\n")
self.__internal(
f"Raw message called from a non-function - This is not recommended"
)
if message != "None" and message is not None:
with open(self.filename, "a") as f:
f.write(f"{str(message)}\n")

def newline(self):
"""
Expand All @@ -114,39 +130,47 @@ def info(self, message):
:param message: The info message to be logged.
"""
if self.color:
if self.color and message != "None" and message is not None:
colorlog.info(str(message))
self.raw(f"[{self.__timestamp()}] > INFO: | {self.__pad_message(str(message))}")
self.raw(
f"[{self.__timestamp()}] > INFO: | {self.__pad_message(str(message))}"
)

def warning(self, message):
"""
Logs a warning message.
:param message: The warning message to be logged.
"""
if self.color:
if self.color and message != "None" and message is not None:
colorlog.warning(str(message))
self.raw(f"[{self.__timestamp()}] > WARNING: | {self.__pad_message(str(message))}")
self.raw(
f"[{self.__timestamp()}] > WARNING: | {self.__pad_message(str(message))}"
)

def error(self, message):
"""
Logs an error message.
:param message: The error message to be logged.
"""
if self.color:
if self.color and message != "None" and message is not None:
colorlog.error(str(message))
self.raw(f"[{self.__timestamp()}] > ERROR: | {self.__pad_message(str(message))}")
self.raw(
f"[{self.__timestamp()}] > ERROR: | {self.__pad_message(str(message))}"
)

def critical(self, message):
"""
Logs a critical message.
:param message: The critical message to be logged.
"""
if self.color:
if self.color and message != "None" and message is not None:
colorlog.critical(str(message))
self.raw(f"[{self.__timestamp()}] > CRITICAL: | {self.__pad_message(str(message))}")
self.raw(
f"[{self.__timestamp()}] > CRITICAL: | {self.__pad_message(str(message))}"
)

@staticmethod
def debug(message):
Expand All @@ -155,7 +179,8 @@ def debug(message):
:param message: The debug message to be logged.
"""
colorlog.debug(str(message))
if message != "None" and message is not None:
colorlog.debug(str(message))

def string(self, message, type: str):
"""
Expand All @@ -165,13 +190,14 @@ def string(self, message, type: str):
:param message: The message to be logged.
:param type: The type of the log message.
"""
type_map = {"err": "error", "warn": "warning", "crit": "critical"}
type = type_map.get(type.lower(), type)
try:
getattr(self, type.lower())(str(message))
except AttributeError as AE:
self.__internal(f"A wrong Log Type was called: {type} not found. -> {AE}")
getattr(self, "Debug".lower())(str(message))
if self.color and message != "None" and message is not None:
type_map = {"err": "error", "warn": "warning", "crit": "critical"}
type = type_map.get(type.lower(), type)
try:
getattr(self, type.lower())(str(message))
except AttributeError as AE:
self.__internal(f"A wrong Log Type was called: {type} not found. -> {AE}")
getattr(self, "Debug".lower())(str(message))

def exception(self, message, exception_type: Type = Exception):
"""
Expand All @@ -180,7 +206,10 @@ def exception(self, message, exception_type: Type = Exception):
:param message: The exception message to be logged.
:param exception_type: The type of exception to raise.
"""
self.raw(f"[{self.__timestamp()}] > EXCEPTION:| {self.__pad_message(f'{message} -> Exception provoked: {str(exception_type)}')}")
if self.color and message != "None" and message is not None:
self.raw(
f"[{self.__timestamp()}] > EXCEPTION:| {self.__pad_message(f'{message} -> Exception provoked: {str(exception_type)}')}"
)
raise exception_type(message)

def __internal(self, message):
Expand All @@ -189,9 +218,11 @@ def __internal(self, message):
:param message: The internal message to be logged.
"""
if self.color:
if self.color and message != "None" and message is not None:
colorlog.log(self.INTERNAL_LOG_LEVEL, str(message))


if __name__ == "__main__":
Log().exception("This is a library file and should not be executed directly.", Exception)
Log().exception(
"This is a library file and should not be executed directly.", Exception
)
41 changes: 21 additions & 20 deletions CODE/wifi_stealer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

from __lib_class import *

if __name__ == "__main__":
log = Log({"log_level": DEBUG})


def get_password(ssid: str) -> str:
def get_password(ssid: str) -> str | None:
"""
Retrieves the password associated with a given Wi-Fi SSID.
Expand All @@ -21,19 +23,25 @@ def get_password(ssid: str) -> str:
command_output = Actions.run_command(
f'netsh wlan show profile name="{ssid}" key=clear'
)
if command_output is None:
return "None"
key_content = command_output.splitlines()
for line in key_content:
if "Key Content" in line:
return line.split(":")[1].strip()
return "None"
except UnicodeDecodeError as err:
log.error(err)
return "None"
if command_output:
key_content = command_output.splitlines()
for line in key_content:
if "Key Content" in line:
return line.split(":")[1].strip()
except Exception as err:
log.error(err)
return "None"


def parse_wifi_names(command_output: str) -> list:
wifi_names = []

for line in command_output.split("\n"):
if "All User Profile" in line:
start_index = line.find("All User Profile") + len("All User Profile")
wifi_name = line[start_index:].strip()
wifi_names.append(wifi_name)

return wifi_names


def get_wifi_names() -> list:
Expand All @@ -49,14 +57,7 @@ def get_wifi_names() -> list:
"""
try:
log.info("Retrieving Wi-Fi names...")
command_output = Actions.run_command("netsh wlan show profile")
wifi_names = []

for line in command_output.split("\n"):
if "All User Profile" in line:
start_index = line.find("All User Profile") + len("All User Profile")
wifi_name = line[start_index:].strip()
wifi_names.append(wifi_name)
wifi_names = parse_wifi_names(Actions.run_command("netsh wlan show profile"))
log.info(f"Retrieved {len(wifi_names)} Wi-Fi names.")
return wifi_names
except Exception as err:
Expand Down
11 changes: 11 additions & 0 deletions WEB/footer-styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.footer-content {
background-color: #333;
color: #fff;
text-align: center;
padding: 20px 0;
}

.footer-content p {
margin: 5px 0;
font-size: 14px;
}
Loading

0 comments on commit 8f59424

Please sign in to comment.