This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.ps1
220 lines (171 loc) · 5.92 KB
/
run.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
$global:flask = $null
$global:evilginx = $null
$global:chrome = $null
$global:frontend = $null
function Install-VirtualEnv {
$createdNew = $false
if (Test-Path "venv") {
Write-Host "Virtual environment found."
$activateScript = "venv\Scripts\Activate.ps1"
}
elseif (Test-Path ".venv") {
Write-Host "Virtual environment found."
$activateScript = ".venv\Scripts\Activate.ps1"
}
else {
Write-Host "No virtual environment found."
Write-Host "Creating venv..."
python -m venv "venv"
$activateScript = "venv\Scripts\Activate.ps1"
$createdNew = $true
}
& "$activateScript"
Write-Host "Virtual environment activated."
return $createdNew
}
function Install-Backend {
Set-Location "backend"
$virtualEnvCreated = Install-VirtualEnv
if ($virtualEnvCreated) {
Write-Output "New virtual environment created. Installing requirements..."
pip install -r requirements.txt
}
else {
Write-Output "Using existing virtual environment. Skipping requirement installation."
}
deactivate
Set-Location ".."
}
function Install-Evilginx {
Set-Location "evilginx"
if (-not (Test-Path "evilginx.exe")) {
Write-Output "Downloading Evilginx..."
Invoke-WebRequest -Uri "https://github.com/kgretzky/evilginx2/releases/download/v3.3.0/evilginx-v3.3.0-windows-64bit.zip" -OutFile "evilginx.zip"
Write-Output "Extracting Evilginx..."
Expand-Archive -Path "evilginx.zip" -DestinationPath "." -Force
Remove-Item "evilginx.zip"
}
else {
Write-Output "Evilginx is already installed."
}
Set-Location ".."
}
function Install-Extension {
Set-Location "extension"
if (-not (Test-Path "node_modules")) {
Write-Output "Installing dependencies for extension..."
npm install
}
else {
Write-Output "Extension dependencies already installed."
}
Write-Output "Building extension..."
npm run build
Set-Location ".."
}
function Install-Frontend {
Set-Location "frontend"
if (-not (Test-Path "node_modules")) {
Write-Output "Installing dependencies for frontend..."
npm install
}
else {
Write-Output "Frontend dependencies already installed."
}
Set-Location ".."
}
function Download-And-Extract-ChromeData {
$url = "https://firebasestorage.googleapis.com/v0/b/itsyourap-misc.appspot.com/o/hack4bengal%2Fchrome-data.zip?alt=media&token=958db72d-36d5-422b-901e-f2427fefefc8"
$zipFile = "chrome-data.zip"
$destination = "chrome-data"
if (-not (Test-Path $zipFile) -and -not (Test-Path $destination)) {
try {
# Download the file
Write-Output "Downloading Chrome data..."
Invoke-WebRequest -Uri $url -OutFile $zipFile -UseBasicParsing
# Extract the archive
Write-Output "Extracting Chrome data..."
Expand-Archive -Path $zipFile -DestinationPath . -Force
Write-Output "Chrome data extraction completed."
}
catch {
Write-Error "Failed to download or extract Chrome data: $_"
}
finally {
if (Test-Path $zipFile) {
Remove-Item $zipFile
}
}
}
else {
if (Test-Path $destination){
Write-Output "Chrome data or its extracted folder already exists. Skipping download and extraction."
} else {
try {
Write-Output "Extracting Chrome data..."
Expand-Archive -Path $zipFile -DestinationPath . -Force
Write-Output "Chrome data extraction completed."
} catch {
Write-Error "Failed to download or extract Chrome data: $_"
}
}
}
}
function Start-Backend {
Set-Location "backend"
Install-VirtualEnv
Write-Output "Starting Flask app..."
$env:FLASK_APP = "main"
$env:FLASK_ENV = "development"
$env:FLASK_DEBUG = "0"
$global:flask = Start-Process python -ArgumentList "-m flask run --host=0.0.0.0" -PassThru -WindowStyle Normal
deactivate
Set-Location ".."
return $global:flask
}
function Start-Evilginx {
Set-Location "evilginx"
Write-Output "Starting Evilginx..."
$global:evilginx = Start-Process "evilginx.exe" -ArgumentList "-developer -c ." -PassThru -WindowStyle Normal
Set-Location ".."
return $global:evilginx
}
function Start-Extension {
Set-Location "extension"
$extensionPath = (Get-Item -Path ".\build").FullName
$dataPath = (Get-Item -Path ".\..\chrome-data").FullName
Write-Output "$dataPath"
Write-Output "Launching Chrome with extension..."
$global:chrome = Start-Process "C:\Program Files\Google\Chrome\Application\chrome.exe" -ArgumentList "-new-window --user-data-dir=$dataPath --ignore-certificate-errors --host-resolver-rules=`"MAP *.localhost 127.0.0.1`" --load-extension=$extensionPath" -PassThru -WindowStyle Normal
Set-Location ".."
return $global:chrome
}
function Start-Frontend {
Set-Location "frontend"
Write-Output "Starting frontend..."
$logPathOut = "frontend_output.log"
$logPathErr = "frontend_error.log"
$global:frontend = Start-Process npm -ArgumentList "run dev" -RedirectStandardOutput $logPathOut -RedirectStandardError $logPathErr -PassThru -NoNewWindow
Set-Location ".."
return $global:frontend
}
Install-Backend
Install-Frontend
Install-Evilginx
Install-Extension
Download-And-Extract-ChromeData
Start-Backend
Start-Frontend
Start-Evilginx
Start-Extension
Write-Output "Frontend Server started at http://localhost:5173/"
try {
Write-Output "Press CTRL+C to exit..."
Wait-Event -Timeout 86400
}
finally {
if ($null -ne $global:flask) { Stop-Process -Id $global:flask.Id -Force }
if ($null -ne $global:frontend) { Stop-Process -Id $global:frontend.Id -Force }
if ($null -ne $global:evilginx) { Stop-Process -Id $global:evilginx.Id -Force }
if ($null -ne $global:chrome) { Stop-Process -Id $global:chrome.Id -Force }
}