-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
Β·255 lines (222 loc) Β· 8.43 KB
/
setup.sh
File metadata and controls
executable file
Β·255 lines (222 loc) Β· 8.43 KB
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/bin/bash
# Exit on any error
set -e
# ========== COMMAND LINE ARGUMENT HANDLING ==========
COMMAND="${1:-install}"
SERVER_DIR="$HOME/Library/Application Support/NodeServerStarter"
# Server management functions (available after installation)
check_server_running() {
if command -v curl >/dev/null 2>&1; then
curl -s "http://127.0.0.1:1337/health" >/dev/null 2>&1
elif command -v wget >/dev/null 2>&1; then
wget -q --timeout=2 "http://127.0.0.1:1337/health" -O /dev/null >/dev/null 2>&1
else
return 1
fi
}
start_server() {
echo "π Starting FrogPost server..."
if [ ! -d "$SERVER_DIR" ]; then
echo "β FrogPost not installed. Please run: bash setup.sh"
exit 1
fi
if check_server_running; then
echo "β
Server already running on port 1337"
return 0
fi
cd "$SERVER_DIR"
nohup node server.js >> frogpost-server.log 2>&1 &
SERVER_PID=$!
echo $SERVER_PID > .frogpost-server.pid
echo "β³ Waiting for server to start..."
for i in {1..10}; do
sleep 1
if check_server_running; then
echo "β
FrogPost server started successfully (PID: $SERVER_PID)"
echo "π Server accessible at: http://127.0.0.1:1337"
return 0
fi
done
echo "β Server failed to start within 10 seconds"
return 1
}
stop_server() {
echo "π Stopping FrogPost server..."
if [ -f "$SERVER_DIR/.frogpost-server.pid" ]; then
PID=$(cat "$SERVER_DIR/.frogpost-server.pid")
if ps -p "$PID" >/dev/null 2>&1; then
kill "$PID" 2>/dev/null
sleep 2
if ps -p "$PID" >/dev/null 2>&1; then
kill -9 "$PID" 2>/dev/null
fi
fi
rm -f "$SERVER_DIR/.frogpost-server.pid"
fi
pkill -f "node.*server" 2>/dev/null || true
echo "β
Server stopped"
}
server_status() {
if check_server_running; then
echo "Server status: β
Running"
return 0
else
echo "Server status: β Stopped"
return 1
fi
}
# Handle server management commands
case "$COMMAND" in
start)
start_server
exit 0
;;
stop)
stop_server
exit 0
;;
status)
server_status
exit $?
;;
restart)
stop_server
sleep 2
start_server
exit 0
;;
install)
# Continue with installation below
;;
*)
echo "Usage: $0 [install|start|stop|status|restart]"
echo " install - Install FrogPost (default)"
echo " start - Start server in background"
echo " stop - Stop background server"
echo " status - Check server status"
echo " restart - Restart server"
exit 1
;;
esac
cat << "EOF"
###############################################################################
# #
# ______ _____ _ #
# | ____| | __ \ | | #
# | |__ _ __ ___ __ _ | |__) |__ ___ | |_ #
# | __| '__/ _ \ / _` | | ___/ _ \/ __|| __| #
# | | | | | (_) | (_| | | | | (_) \__ \| |_ #
# |_| |_| \___/ \__, | |_| \___/|___/ \__| #
# __/ | #
# |___/ #
# #
# πΈ FrogPost - postMessage Security Testing Tool #
# Created by: thisis0xczar #
# #
###############################################################################
EOF
echo "πΈ Starting FrogPost installation on macOS..."
# ========== AUTO CONFIGURATION ==========
FROGPOST_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "π FrogPost repository detected at: $FROGPOST_REPO"
USER_NAME=$(whoami)
echo "π€ Installing for user: $USER_NAME"
echo ""
echo "π Please enter your Chrome extension ID"
echo " (You can find this at chrome://extensions after enabling Developer Mode)"
read -p "Extension ID: " EXTENSION_ID
# Validate extension ID format
while [[ ! $EXTENSION_ID =~ ^[a-z0-9]{32}$ ]]; do
echo "β Invalid extension ID format. It should be 32 lowercase alphanumeric characters."
read -p "Extension ID: " EXTENSION_ID
done
# Directory paths (SERVER_DIR already defined above)
NATIVE_HOST_DIR="$HOME/Library/Application Support/Google/Chrome/NativeMessagingHosts"
# Source file paths (updated for new folder structure)
SERVER_JS_SRC="$FROGPOST_REPO/server/server.js"
START_SH_SRC="$FROGPOST_REPO/server/start_server.sh"
MANIFEST_SRC="$FROGPOST_REPO/server/com.nodeserver.starter.json"
# Target destination paths
SERVER_JS_DST="$SERVER_DIR/server.js"
START_SH_DST="$SERVER_DIR/start_server.sh"
MANIFEST_DST="$NATIVE_HOST_DIR/com.nodeserver.starter.json"
# ========== PRECHECK ==========
if ! command -v node >/dev/null || ! command -v npm >/dev/null; then
echo "β Node.js and npm are required. Please install them first: https://nodejs.org/"
exit 1
fi
# ========== STEP 1: Create Directories ==========
echo "π Creating required directories..."
mkdir -p "$SERVER_DIR"
mkdir -p "$NATIVE_HOST_DIR"
echo "β
Directories ready."
# ========== STEP 2: Copy Files Before Modifying ==========
echo "π¦ Copying files to destination directories..."
cp "$SERVER_JS_SRC" "$SERVER_JS_DST"
cp "$START_SH_SRC" "$START_SH_DST"
cp "$MANIFEST_SRC" "$MANIFEST_DST"
echo "β
Files copied."
# ========== STEP 3: Update Manifest ==========
echo "π§ Updating manifest..."
sed -i '' "s/abcdefghijklmnopabcdefghijklmnop/${EXTENSION_ID}/g" "$MANIFEST_DST"
sed -i '' "s/\[USER_NAME\]/${USER_NAME}/g" "$MANIFEST_DST"
echo "β
Manifest updated at: $MANIFEST_DST"
# ========== STEP 4: Modify copied server.js ==========
echo "π Updating copied server.js..."
FULL_REPO_PATH=$(cd "$FROGPOST_REPO" && pwd)
sed -i '' "s|const rootDir = .*|const rootDir = '${FULL_REPO_PATH}';|" "$SERVER_JS_DST"
echo "β
rootDir set to: $FULL_REPO_PATH"
# ========== STEP 5: Modify copied start_server.sh ==========
echo "π Updating copied start_server.sh..."
ESCAPED_PATH=$(echo "$SERVER_JS_DST" | sed 's/\//\\\//g')
sed -i '' "s|\[USER_NAME\]|${USER_NAME}|g" "$START_SH_DST"
sed -i '' "s|^SERVER_JS=.*|SERVER_JS=\"${SERVER_JS_DST}\" # Set by install script|" "$START_SH_DST"
chmod +x "$START_SH_DST"
echo "β
start_server.sh updated."
# ========== STEP 6: Create log file ==========
LOG_FILE="$SERVER_DIR/node-finder.log"
echo "π Creating log file: $LOG_FILE"
touch "$LOG_FILE"
chmod 666 "$LOG_FILE"
echo "β
Log file ready."
# ========== STEP 7: Install Node.js dependencies ==========
echo "π¦ Installing Node.js dependencies..."
cd "$SERVER_DIR"
cp "$FROGPOST_REPO/package.json" "$SERVER_DIR/package.json"
npm i
echo "β
All dependencies installed from package.json."
# ========== ASK TO START SERVER ==========
echo ""
read -p "π€ Would you like to start the FrogPost server now? (y/n): " START_NOW
if [[ $START_NOW =~ ^[Yy]$ ]]; then
start_server
else
echo "βοΈ Server not started. You can start it later with:"
echo " bash setup.sh start"
echo " OR directly: cd \"$SERVER_DIR\" && node server.js"
fi
# ========== COMPLETE ==========
echo ""
echo "π FrogPost installation complete!"
echo ""
echo "π What was installed:"
echo " β
Native messaging host for Chrome extension"
echo " β
Server with all dependencies"
echo " β
Server management through setup.sh"
echo ""
echo "π Server Management Commands:"
echo " bash setup.sh start # Start server in background"
echo " bash setup.sh status # Check server status"
echo " bash setup.sh stop # Stop server"
echo " bash setup.sh restart # Restart server"
echo ""
echo "π Chrome Extension Setup:"
echo " 1. Go to chrome://extensions/"
echo " 2. Enable 'Developer Mode'"
echo " 3. Click 'Load unpacked' and select: $FROGPOST_REPO"
echo ""
echo "β οΈ Extension ID: $EXTENSION_ID"
echo " (This ID is configured for native messaging)"
echo ""
echo "π― Ready to use! Server management is now integrated into setup.sh"
echo "π‘ Happy Hacking with FrogPost πΈ"