Skip to content

Commit a9ab6ee

Browse files
ramzcodeRam
and
Ram
authored
Dev to Stable (#4)
* User Mgmt&RBAC * NEW UI and UI Improvements * RedirecttodashboardSectionAfterLogin * Flash Message Type based colours * SessionTimeout * LogginMech * File Listing * FileBrowser&Downloader * UI Changes * backup * datastoreImplemention * AddedScheduleFileCreationMech * CoreCodeCoreData * BugFix * Backup_RecordsViewer * AdhocRunForJobs * FetchJobStatusStillNotWorking * LiveJobStatusUpdates * FixedStatusColumn * Supporting Data * Perfect Multi site job status working * Updated file * done * updated * FullyIntegratedandJobLogTested * BackedBakupCodesTest * Updated New Packages * icons&logos * UI Changes, added Favicon and Logo * External Route for Widgets * widgetsCoreFunctinons * WidgetConfigs * WidgetAlignmentForSmallScreens * BulkImportDeviceFromCSV * enhancement * AlertBannerLoginPOage * ImportFIleFormat * KeepItEmptyAlways * FlaskStructure * SingleBinaryMacOSx * ConfigFiles * WrongPath * ConfigUI * addedDashboardURL * WidgetsRequestReducedFrom4to1 * PopUpNotifications * AddedRequiredForm * NOtifications * UpdateUIwithcurrentdata * BeforeTetingSetupModule * FullyWorkingSetupModule * FooterforLoginPage * ValidateDBOnStartup * Create pylint.yml linter * Update pylint.yml check only the master file * ignore * ConfigVarsAndSessionBugFixed * EmailAndRoleAdded * DB+CacheBasedRBAC * FullRBACImplemented * MajorUIIntegration * UI Implementaion --------- Co-authored-by: Ram <[email protected]>
1 parent 1c5a20d commit a9ab6ee

File tree

88 files changed

+11188
-549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+11188
-549
lines changed

.github/workflows/pylint.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Pylint
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.8", "3.9", "3.10"]
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Set up Python ${{ matrix.python-version }}
14+
uses: actions/setup-python@v3
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install pylint
21+
- name: Analysing the code with pylint
22+
run: |
23+
pylint $(git ls-files 'webappLatest.py')

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__pycache__
2+
AirBackupX_messages.log.*
3+
.DS_Store
4+
flask_session

AirBackupX_InportFormat.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
username,device,encrypted_password,group_name,type
2+
user1,TESTTTTTTT,hashed_password_1,group1,type1
3+
user2,OKAAAAAAA,hashed_password_2,group2,type2

AirBackupX_messages.log

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[2023-10-02 00:11:35,065] [10.10.8.2] [INFO]: User admin logged in Successfully
2+
[2023-10-02 00:55:26,649] [10.10.8.2] [INFO]: User 2222 logged in Successfully
3+
[2023-10-02 01:30:32,294] [10.10.8.2] [INFO]: User 2222 logged in Successfully
4+
[2023-10-02 01:39:25,397] [10.10.8.2] [INFO]: User 2222 logged in Successfully
5+
[2023-10-02 01:47:32,654] [10.10.8.2] [INFO]: User 2222 logged in Successfully
6+
[2023-10-02 02:08:38,637] [10.10.8.2] [INFO]: User 2222 logged in Successfully
7+
[2023-10-02 02:12:12,869] [10.10.8.2] [INFO]: User 2222 logged in Successfully
8+
[2023-10-02 05:21:29,888] [10.10.8.2] [INFO]: User 2222 logged in Successfully
9+
[2023-10-02 05:30:17,001] [10.10.8.2] [INFO]: User 2222 logged in Successfully
10+
[2023-10-02 05:37:33,304] [10.10.8.2] [INFO]: User 2222 logged in Successfully
11+
[2023-10-02 06:24:53,629] [10.10.8.2] [INFO]: User 2222 logged in Successfully
12+
[2023-10-02 07:15:13,953] [10.10.8.2] [INFO]: User admin logged in Successfully

App_structure.txt

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Structuring your Flask application properly is essential for maintaining a clean and organized codebase. Although Flask does not enforce a specific structure, there are common practices that can help you organize your application effectively. Here's a recommended way to structure a Flask application:
2+
3+
### Basic Structure:
4+
5+
```
6+
myapp/
7+
├── app/
8+
│ ├── static/
9+
│ │ ├── style.css
10+
│ │ └── ...
11+
│ ├── templates/
12+
│ │ ├── index.html
13+
│ │ └── ...
14+
│ ├── __init__.py
15+
│ ├── routes.py
16+
│ ├── models.py (optional, for database models)
17+
│ ├── forms.py (optional, for WTForms)
18+
│ └── config.py (optional, configuration settings)
19+
├── venv/ (virtual environment, optional but recommended)
20+
├── run.py (entry point to run the application)
21+
└── config.py (configuration settings for development and production)
22+
```
23+
24+
### Explanation:
25+
26+
1. **`app/`**: This directory contains your Flask application.
27+
28+
- **`static/`**: Static files such as CSS, JavaScript, images, etc., are stored here.
29+
- **`templates/`**: HTML templates rendered by Flask are stored here.
30+
31+
- **`__init__.py`**: This file initializes your Flask application and can also contain setup code.
32+
- **`routes.py`**: Define your application routes (URL endpoints) in this file.
33+
- **`models.py`**: Define your database models (if you're using a database) in this file.
34+
- **`forms.py`**: Define your forms using WTForms (if applicable) in this file.
35+
- **`config.py`**: Store configuration settings for your Flask app. Separate configurations for development, testing, and production environments can be managed here.
36+
37+
2. **`venv/`** (Optional): This is a virtual environment folder where you can install your project-specific dependencies.
38+
39+
3. **`run.py`**: This file serves as the entry point for running your Flask application. It imports the Flask app instance from the `app/__init__.py` file and runs the app.
40+
41+
4. **`config.py`**: This file contains configuration settings for different environments like development, testing, and production. It can store sensitive information like API keys, database URIs, etc. This file should not be included in version control, and you can use environment variables to manage sensitive information securely.
42+
43+
### Additional Considerations:
44+
45+
- **Blueprints**: As your application grows, you might want to use Flask blueprints to organize your code into reusable components.
46+
47+
- **Error Handling**: Create a custom error handling mechanism to handle different HTTP errors and exceptions elegantly.
48+
49+
- **Logging**: Implement logging to track errors, debug information, and application activities.
50+
51+
- **Tests**: Include a `tests/` directory to write unit tests for your application. Organize tests based on the functionality they are testing.
52+
53+
- **Documentation**: Maintain proper documentation for your code, especially if you are working in a team.
54+
55+
Remember that these are general guidelines, and you can adjust the structure based on the specific needs of your application.

GNS3-Local_runner.log

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
GNS3-Local:running
2+
GNS3-Local:completed
3+
GNS3-Local:running
4+
GNS3-Local:completed
5+
GNS3-Local:running
6+
GNS3-Local:completed
7+
GNS3-Local:running
8+
GNS3-Local:completed
9+
GNS3-Local:running
10+
GNS3-Local:completed
11+
GNS3-Local:running
12+
GNS3-Local:completed
13+
GNS3-Local:running
14+
GNS3-Local:completed
15+
GNS3-Local:running
16+
GNS3-Local:completed
17+
GNS3-Local:running
18+
GNS3-Local:completed
19+
GNS3-Local:running
20+
GNS3-Local:completed
21+
GNS3-Local:running
22+
GNS3-Local:completed
23+
GNS3-Local:running
24+
GNS3-Local:GNSDATA
25+
GNS3-Local:VollaGNSDATA
26+
GNS3-Local:running
27+
GNS3-Local:completed
28+
GNS3-Local:running
29+
GNS3-Local:completed
30+
GNS3-Local:running
31+
GNS3-Local:completed

app.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from flask import Flask, render_template, send_from_directory, abort, url_for, jsonify
2+
import os
3+
4+
app = Flask(__name__)
5+
6+
# Define your local directory here
7+
local_directory = '/root' # Replace with the path to your local directory
8+
9+
@app.route('/')
10+
def explore_root():
11+
contents = list_directory_contents(local_directory)
12+
return render_template('explorer.html', folder_path=local_directory, contents=contents)
13+
14+
15+
@app.route('/download/<path:file_path>')
16+
def download_file(file_path):
17+
full_file_path = os.path.join(local_directory, file_path)
18+
19+
# Check if the file exists
20+
if os.path.exists(full_file_path):
21+
try:
22+
# Use send_from_directory to serve the file as an attachment
23+
return send_from_directory(local_directory, file_path, as_attachment=True)
24+
except Exception as e:
25+
return f"Error downloading file: {str(e)}"
26+
else:
27+
abort(404)
28+
29+
@app.route('/explore/<path:folder_path>')
30+
def explore_directory(folder_path):
31+
full_folder_path = os.path.join(local_directory, folder_path)
32+
contents = list_directory_contents(full_folder_path)
33+
return render_template('explorer.html', folder_path=folder_path, contents=contents)
34+
35+
@app.route('/get_contents/<path:folder_path>')
36+
def get_contents(folder_path):
37+
full_folder_path = os.path.join(local_directory, folder_path)
38+
contents = list_directory_contents(full_folder_path)
39+
return jsonify(contents)
40+
41+
def list_directory_contents(directory_path):
42+
try:
43+
contents = []
44+
for item in os.listdir(directory_path):
45+
full_item_path = os.path.join(directory_path, item)
46+
is_directory = os.path.isdir(full_item_path)
47+
timestamp = get_timestamp(full_item_path)
48+
relative_path = os.path.relpath(full_item_path, local_directory)
49+
contents.append((relative_path, is_directory, timestamp))
50+
return contents
51+
except Exception as e:
52+
return [str(e)]
53+
54+
def get_timestamp(file_path):
55+
try:
56+
timestamp = os.path.getmtime(file_path)
57+
return timestamp
58+
except Exception as e:
59+
return None
60+
61+
if __name__ == '__main__':
62+
app.run(host='0.0.0.0', port=3030)
63+
app.debug = True
64+

config/config.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CONFIG = {
2+
"Admin": {
3+
"emailID": "[email protected]"
4+
},
5+
"Datastore": {
6+
"BackupPath": "/tmp"
7+
},
8+
"Encrypt": {
9+
"flask_enc_key": "b'RcuXnVW1AfQS3xn9dRJN461Et_1F4vihNOlOOh1h1II='"
10+
},
11+
"FlaskSession": {
12+
"key": "7f43ba0a51706dfd1b91eb58989f3cb09fd82501e7ac0ee4",
13+
"prefix": "airbackupx"
14+
},
15+
"SMTP": {
16+
"server": "dummy",
17+
"port": "dummy",
18+
"username": "dummy"
19+
},
20+
"Database": {
21+
"host": "127.0.0.1",
22+
"port": "3306",
23+
"username": "root",
24+
"password": "hack",
25+
"database": "passwords_db"
26+
}
27+
}

core_codeSimulator.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import mysql.connector
2+
from cryptography.fernet import Fernet, InvalidToken
3+
import os
4+
5+
# Function to load the encryption key
6+
def get_or_generate_key():
7+
key_file = 'encryption_key.key'
8+
if os.path.exists(key_file):
9+
with open(key_file, 'rb') as file:
10+
key = file.read()
11+
return key
12+
else:
13+
print('DecryptionKey Not Found')
14+
raise FileNotFoundError('Decryption key file not found. Please save the key and save it in "encryption_key.key".')
15+
16+
# Initialize Fernet cipher with the key
17+
encryption_key = get_or_generate_key()
18+
cipher_suite = Fernet(encryption_key)
19+
20+
# Function to decrypt a password
21+
def decrypt_password(encrypted_password):
22+
try:
23+
decrypted_password = cipher_suite.decrypt(encrypted_password).decode()
24+
return decrypted_password
25+
except InvalidToken:
26+
return "Invalid token (possibly corrupted or tampered data)"
27+
28+
29+
# Establish a connection to the MySQL database
30+
connection = mysql.connector.connect(
31+
host='localhost',
32+
user='root',
33+
password='hack',
34+
database='passwords_db'
35+
)
36+
37+
# Create a cursor object to interact with the database
38+
cursor = connection.cursor(dictionary=True)
39+
40+
41+
# Specify the group you want to filter
42+
group_name = 'testt'
43+
44+
# Query to retrieve devices based on group name
45+
query = ("SELECT * FROM passwords WHERE group_name = %s")
46+
values = (group_name,)
47+
48+
# Execute the query
49+
cursor.execute(query, values)
50+
51+
# Retrieve the devices
52+
devices = cursor.fetchall()
53+
54+
# Process devices
55+
for device in devices:
56+
username = device['username']
57+
device_name = device['device']
58+
encrypted_password = device['encrypted_password']
59+
decrypted_password = decrypt_password(encrypted_password) # Decrypt the password
60+
device_type = device['type']
61+
62+
# Process devices based on their type
63+
if device_type == 'ASA':
64+
# Process devices of type 'asdad'
65+
print(f"Processing device {device_name} of type 'ASA' with username {username} and decrypted password {decrypted_password}")
66+
elif device_type == 'IOS':
67+
# Process devices of type 'IOS'
68+
print(f"Processing device {device_name} of type 'IOS' with username {username} and decrypted password {decrypted_password}")
69+
70+
# Close the cursor and connection
71+
cursor.close()
72+
connection.close()
73+

dist/.DS_Store

12 KB
Binary file not shown.
150 Bytes
Binary file not shown.

dist/gunicorn_config.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bind = '0.0.0.0:8000' # Replace with your desired IP and port
2+
workers = 2 # Adjust as needed
3+

dist/webappLatest

17.7 MB
Binary file not shown.

dummy_backuprecord.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import mysql.connector
2+
from datetime import datetime
3+
4+
# Establish a connection to the MySQL database
5+
connection = mysql.connector.connect(
6+
host='localhost',
7+
user='root',
8+
password='hack',
9+
database='passwords_db'
10+
)
11+
12+
# Create a cursor object to interact with the database
13+
cursor = connection.cursor()
14+
15+
# Sample backup information
16+
backup_info = {
17+
'device_name': 'CiscoRouter2',
18+
'site_name': 'SiteBB',
19+
'type': 'Router',
20+
'username': 'admin',
21+
'exit_status': 'Failed',
22+
'file_name': 'backup_file_20231002.txt'
23+
}
24+
25+
# Insert backup record into the database
26+
insert_query = """
27+
INSERT INTO backup_records (backup_date, device_name, site_name, type, username, exit_status, file_name)
28+
VALUES (%s, %s, %s, %s, %s, %s, %s)
29+
"""
30+
31+
values = (datetime.now(), backup_info['device_name'], backup_info['site_name'], backup_info['type'],
32+
backup_info['username'], backup_info['exit_status'], backup_info['file_name'])
33+
34+
cursor.execute(insert_query, values)
35+
36+
# Commit the changes and close the connection
37+
connection.commit()
38+
cursor.close()
39+
connection.close()
40+

encryption_key.key

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RcuXnVW1AfQS3xn9dRJN461Et_1F4vihNOlOOh1h1II=

0 commit comments

Comments
 (0)