Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/small fixes #180

Merged
merged 5 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions Agent/API/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import json
from dotenv import load_dotenv
import base64
import netifaces

load_dotenv()
app = FastAPI()
Expand Down Expand Up @@ -136,7 +137,7 @@ async def install():
session,
json.dumps(
{
"aip": socket.gethostbyname(socket.gethostname()),
"aip": findOpenPort()[0], # This will now be the public IP
"aport": 8010,
"capacity": capacity,
"storage": 290.4,
Expand All @@ -156,17 +157,29 @@ async def install():
print(server_ecdh)
return {"message": "success"}


@app.get("/findOpenPort")
def findOpenPort():
port = 8002
ip = socket.gethostbyname(socket.gethostname())

# Try to get the public IP address
try:
ip = requests.get('https://api.ipify.org').text.strip()
print(f"Public IP address: {ip}")
except Exception as e:
print(f"Error getting public IP: {e}")
# If we can't get the public IP, we'll use a placeholder
ip = '0.0.0.0'
print("Using placeholder IP: 0.0.0.0")

# Find an open port
while True:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
result = s.connect_ex((ip, port))
result = s.connect_ex(('localhost', port))
if result == 0:
port += 1
else:
break

return ip, port


Expand Down
Binary file modified Agent/requirements.txt
Binary file not shown.
32 changes: 32 additions & 0 deletions Backend/Django/testApp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Dev (cmd)

## To create a Virtual enviroment

- python -m venv backendVenv

## To activate it:

- backendVenv\Scripts\activate

## To deactivate:

- deactivate

## Install Dependencies:

- pip install -r Backend\requirements.txt
- pip list (To verify)

## run dev server:

- cd Backend\hvserve
- python manage.py runserver

# Deployment:

docker-compose up -d --build
docker-compose exec web alembic upgrade head
docker-compose exec web alembic revision --autogenerate -m "Initial migration"
docker-compose exec web alembic upgrade head
docker-compose down

8 changes: 5 additions & 3 deletions Backend/Django/testApp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ def uploadFile(request):

size = data.get("size")
message = {"size": size, "uid": uid, "utoken": utoken, "corporation": cid}

print("CORPORATION: ", cid)

print(message)

Expand Down Expand Up @@ -1030,7 +1032,7 @@ def send_invite(teamName, email, token):
from_email = "[email protected]"
from_password = os.getenv("APP_PASSWORD")
subject = "Join our team!"
body = f"Hello, you have been invited to join {teamName} on our platform. Please sign up and join us! \n\n Download the app here: http://" + HOST_IP + ":8000/download \n\n Use the following token to join the team: {token}"
body = f"Hello, you have been invited to join {teamName} on our platform. Please sign up and join us! \n\n Download the app here: http://" + HOST_IP + ":8000/download \n\n Use the following token to join the team: " + token
message = MIMEMultipart()
message["From"] = from_email
message["To"] = email
Expand Down Expand Up @@ -1102,7 +1104,7 @@ def getTeamMembers(request):
"uname": member.uname,
"uemail": member.uemail,
"is_admin": member.is_admin,
"last_signin": member.last_signin.strftime("%H:%M:%S %d-%m-%Y")
"last_signin": member.last_signin.strftime("%H:%M:%S %d-%m-%Y") if member.last_signin else "Never signed in"
})
return Response(
{"teamMembers": users}, status=status.HTTP_200_OK)
Expand Down Expand Up @@ -1438,4 +1440,4 @@ def getUserAgentConnections(request):

return Response(
{"agents": agents, "users": users}, status=status.HTTP_200_OK
)
)
2 changes: 1 addition & 1 deletion Broker/API/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async def brokerStore(request: Request):
avail = agent
break
if avail is None:
avail = {"aid": 1, "aport": 8001, "aip": HOST_IP, "corporation": "dev"}
avail = {"aid": 1, "aport": 8001, "aip": "localhost", "corporation": "dev"}

if not await charon.ping(avail["aip"], avail["aport"]):
return {"status": "no agents available"}
Expand Down
19 changes: 16 additions & 3 deletions Broker/API/package/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import json
from dotenv import load_dotenv
import base64
import netifaces

load_dotenv()
app = FastAPI()
Expand Down Expand Up @@ -136,7 +137,7 @@ async def install():
session,
json.dumps(
{
"aip": socket.gethostbyname(socket.gethostname()),
"aip": findOpenPort()[0], # This will now be the public IP
"aport": 8010,
"capacity": capacity,
"storage": 290.4,
Expand All @@ -159,14 +160,26 @@ async def install():

def findOpenPort():
port = 8002
ip = socket.gethostbyname(socket.gethostname())

# Try to get the public IP address
try:
ip = requests.get('https://api.ipify.org').text.strip()
print(f"Public IP address: {ip}")
except Exception as e:
print(f"Error getting public IP: {e}")
# If we can't get the public IP, we'll use a placeholder
ip = '0.0.0.0'
print("Using placeholder IP: 0.0.0.0")

# Find an open port
while True:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
result = s.connect_ex((ip, port))
result = s.connect_ex(('localhost', port))
if result == 0:
port += 1
else:
break

return ip, port


Expand Down
Binary file modified Broker/API/package/requirements.txt
Binary file not shown.
1 change: 1 addition & 0 deletions Broker/API/package/setup.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Section "MainSection" SEC01
File "start.bat"
File ".env"
File "cerberus.py"
File "python-3.12.4-amd64.exe"

; Write agent type and corporation name to the .env file
FileOpen $0 "$INSTDIR\.env" a
Expand Down
Binary file modified Broker/requirements.txt
Binary file not shown.
Binary file added Desktop/models/yolov8n.pt
Binary file not shown.
23 changes: 5 additions & 18 deletions Desktop/src/components/GallaryCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,14 @@
console.error("Error calling openFTP:", error);
}


await window.electronAPI.downloadToClient(aip, aport, VideoName, uid, size, token);
await window.electronAPI.downloadToClient(aip, aport, videoName, uid, size, token, videoSource);

// move the video to the download folder
let currentFilePath = VideoName;
let currentFilePath = videoName;
console.log("Current File Path: ", currentFilePath);
console.log("videoSource: ", VideoSource);

await window.electronAPI.moveVideo(currentFilePath, VideoName);

// try {
// const response = await window.electronAPI.downloadVideo(
// VideoName,
// VideoSource
// );
// console.log(response.success, response.filePath);
// } catch (error) {}
// setTimeout(() => {
// // isDownloading.set(false);
// }, 1000);
isDownloading = false;
console.log("videoSource: ", videoSource);

isDownloading = false;
showMoreModal = false;
isDownloaded = true;

Expand Down
8 changes: 4 additions & 4 deletions Desktop/src/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,11 +802,11 @@ ipcMain.handle('upload-to-agent', async (event, ip, port, filepath, uid, size, t



ipcMain.handle('download-to-client', async (event, ip, port, filepath, uid, size, token) => {
ipcMain.handle('download-to-client', async (event, ip, port, filepath, uid, size, token, videoDestination) => {
const scriptPath = 'src/routes/pythonDownload.py';
let rec = await LookupTable.findOne({where: {mname: filepath, uid: uid}});
const mid = rec.mid;
const args = [ip, port, filepath, uid, size, token, mid];
const args = [ip, port, filepath, uid, size, token, mid, videoDestination];

return new Promise((resolve, reject) => {
const {spawn} = require('child_process');
Expand Down Expand Up @@ -908,8 +908,8 @@ ipcMain.handle('get-video-frame', async (event, videoPath) => {
// IPC handler to move a video file from the Deleted folder to the Downloads folder
ipcMain.handle('move-deleted-video-to-downloads', async (event, videoName, filePath) => {
try {
const deletedDir = path.join(path.dirname(filePath), 'Deleted', path.basename(filePath, path.extname(filePath)));
const videoFilePath = path.join(deletedDir, `${videoName}`);
// const deletedDir = path.join(path.dirname(filePath), 'Deleted', path.basename(filePath, path.extname(filePath)));/
const videoFilePath = filePath;

if (!fs.existsSync(videoFilePath)) {
return {success: false, error: 'Video file does not exist'};
Expand Down
2 changes: 1 addition & 1 deletion Desktop/src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
fileExists: (filePath) => fs.existsSync(path.resolve(filePath)),
runPythonScript: (scriptPath, args) => ipcRenderer.invoke('run-python-script', scriptPath, args),
uploadToAgent: (ip, port, filepath, uid, size, token, mname) => ipcRenderer.invoke('upload-to-agent', ip, port, filepath, uid, size, token, mname),
downloadToClient: (ip, port, filepath, uid, size, token) => ipcRenderer.invoke('download-to-client', ip, port, filepath, uid, size, token),
downloadToClient: (ip, port, filepath, uid, size, token, videoDestination) => ipcRenderer.invoke('download-to-client', ip, port, filepath, uid, size, token, videoDestination),
checkFileExistence: (filePath) => ipcRenderer.invoke('check-file-existence', filePath),
deleteVideoFile: (filePath) => ipcRenderer.invoke('delete-video-file',filePath),
getVideoFrame: (videoPath) => ipcRenderer.invoke('get-video-frame', videoPath),
Expand Down
14 changes: 10 additions & 4 deletions Desktop/src/routes/pythonDownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import sys

def receive_file(ip, port, filename, uid, size, token, mid):
def receive_file(ip, port, filename, uid, size, token, mid, videoDestination):
print("File name: ", filename)

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
Expand All @@ -22,6 +22,7 @@ def receive_file(ip, port, filename, uid, size, token, mid):
filepath = "./" + filename
s.sendall(filename.encode() + b"\0")

# move the file to the videoDestination
with open(filepath, "wb") as f:
print(f"Receiving file {filename}...")
while True:
Expand All @@ -30,10 +31,13 @@ def receive_file(ip, port, filename, uid, size, token, mid):
break;
f.write(data)
print(f"File {filename} received and saved to {filepath}")

# move the file to the videoDestination
os.rename(filepath, videoDestination)


if __name__ == "__main__":
if len(sys.argv) != 8:
if len(sys.argv) != 9:
print("Usage: python script.py <ip> <port> <filepath> <uid> <size> <token> <mid>")
sys.exit(1)

Expand All @@ -44,7 +48,9 @@ def receive_file(ip, port, filename, uid, size, token, mid):
size = sys.argv[5]
token = sys.argv[6]
mid = sys.argv[7]
videoDestination = sys.argv[8]

print(f"{ip} {port} {filepath} {uid} {size} {token} {mid}")
print(f"{ip} {port} {filepath} {uid} {size} {token} {mid} {videoDestination}")

receive_file(ip, port, filepath, uid, size, token, mid)
receive_file(ip, port, filepath, uid, size, token, mid, videoDestination)

Binary file added Process/pipe4/laneTest.pt
Binary file not shown.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ pem==23.1.0
pydantic-extra-types==2.8.0
pydantic-settings==2.3.1
pyotp==2.9.0
pytest-cov==5.0.0
pytest-cov==5.0.0
netifaces==0.11.0
Loading
Loading