Skip to content

Commit 4a71ecb

Browse files
committed
Refactor webroot to follow KernelSU WebUI guide
- Move CGI scripts to webroot/cgi-bin/ directory - Update httpd.conf for proper CGI configuration - Simplify service.sh for KernelSU compatibility - Update JavaScript to use new CGI paths (/cgi-bin/api_*.sh) - Update README with new directory structure - Add proper MIME types and security headers - Fix permissions for cgi-bin scripts
1 parent 6357713 commit 4a71ecb

9 files changed

Lines changed: 53 additions & 56 deletions

File tree

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ ps | grep httpd
144144
cat /data/adb/IntegrityHelper/service.log
145145

146146
# Test API endpoints
147-
curl http://127.0.0.1:8585/api_test.sh
147+
curl http://127.0.0.1:8585/cgi-bin/api_test.sh
148148

149149
# Check module status
150150
ls -la /data/adb/modules/IntegrityHelper/
@@ -163,12 +163,14 @@ IntegrityHelper/
163163
│ ├── script.js # Frontend logic
164164
│ ├── manifest.json # Module list
165165
│ ├── httpd.conf # Server config
166-
│ └── api_*.sh # CGI endpoints
166+
│ └── cgi-bin/ # CGI scripts
167+
│ ├── api_download.sh # Download endpoint
168+
│ ├── api_install.sh # Install endpoint
169+
│ ├── api_install_all.sh # Batch install endpoint
170+
│ ├── api_state.sh # State endpoint
171+
│ └── api_test.sh # Test endpoint
167172
└── scripts/ # Backend scripts
168-
├── api_server.sh
169-
├── download.sh
170-
├── get_state.sh
171-
└── handle_request.sh
173+
└── httpd.conf # Alternative config
172174
```
173175

174176
## 📋 Changelog

service.sh

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,41 @@
11
#!/system/bin/sh
2-
# service.sh - Runs persistent servers to keep the web UI servers running
3-
4-
# Detect root solution and set paths
5-
if [ -d "/data/adb/ksu" ]; then
6-
ROOT_TYPE="kernelsu"
7-
MODULES_DIR="/data/adb/ksu/modules"
8-
elif [ -d "/data/adb/apatch" ] || [ -d "/data/adb/ap" ]; then
9-
ROOT_TYPE="apatch"
10-
MODULES_DIR="/data/adb/modules"
11-
else
12-
ROOT_TYPE="magisk"
13-
MODULES_DIR="/data/adb/modules"
14-
fi
2+
# service.sh - KernelSU WebUI Module Service
153

16-
MODDIR="$MODULES_DIR/IntegrityHelper"
17-
UI_DIR="$MODDIR/webroot"
18-
SCRIPTS_DIR="$MODDIR/scripts"
4+
MODDIR=${0%/*}
5+
WEBROOT="$MODDIR/webroot"
196

20-
# Ensure directories exist
7+
# Create necessary directories
218
mkdir -p /data/adb/IntegrityHelper
229
mkdir -p /data/local/tmp/modules
2310

24-
# Make CGI scripts executable
25-
chmod +x "$UI_DIR/api_*.sh"
26-
27-
# Copy httpd.conf to webroot
28-
cp "$SCRIPTS_DIR/httpd.conf" "$UI_DIR/"
11+
# Set permissions for CGI scripts
12+
chmod +x "$WEBROOT"/*.sh
13+
chmod +x "$WEBROOT/cgi-bin"/*.sh
2914

30-
# Kill any existing servers
15+
# Kill any existing httpd processes on our port
3116
pkill -f "httpd.*127.0.0.1:8585" 2>/dev/null || true
3217

33-
# Wait a moment
18+
# Wait for cleanup
3419
sleep 1
3520

36-
# Start busybox httpd for static web UI (port 8585)
37-
httpd -p 127.0.0.1:8585 -c "$MODDIR/webroot/httpd.conf" -h "$MODDIR/webroot" -f
21+
# Start busybox httpd
22+
httpd -p 127.0.0.1:8585 -c "$WEBROOT/httpd.conf" -h "$WEBROOT" -f &
3823

39-
# Wait for servers to start
40-
sleep 3
24+
# Wait for server to start
25+
sleep 2
4126

42-
# Verify servers are running
27+
# Verify server is running
4328
if pgrep -f "httpd.*127.0.0.1:8585" > /dev/null; then
44-
echo "$(date): HTTPD server started successfully on port 8585" >> /data/adb/IntegrityHelper/service.log
29+
echo "$(date): IntegrityHelper WebUI started on port 8585" >> /data/adb/IntegrityHelper/service.log
30+
31+
# Show notification if Android UI is available
32+
if command -v am > /dev/null; then
33+
am broadcast -a android.intent.action.MAIN \
34+
-e message "Integrity Helper WebUI running on http://127.0.0.1:8585" \
35+
-e title "Integrity Helper" \
36+
--ez ongoing true \
37+
--ei notification_id 12345 > /dev/null 2>&1 &
38+
fi
4539
else
46-
echo "$(date): ERROR: HTTPD server failed to start" >> /data/adb/IntegrityHelper/service.log
47-
fi
48-
49-
# Show notification that UI is ready
50-
if command -v am > /dev/null && pgrep -f "httpd.*127.0.0.1:8585" > /dev/null; then
51-
# Show notification
52-
am broadcast -a android.intent.action.MAIN -e message "Integrity Helper UI is running on http://127.0.0.1:8585" -e title "Integrity Helper" --ez ongoing true --ei notification_id 12345 > /dev/null 2>&1 &
53-
fi
54-
55-
# Log that service started
56-
echo "$(date): IntegrityHelper service started on $ROOT_TYPE" >> /data/adb/IntegrityHelper/service.log
40+
echo "$(date): ERROR: Failed to start IntegrityHelper WebUI" >> /data/adb/IntegrityHelper/service.log
41+
fi

webroot/httpd.conf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
# httpd.conf for busybox httpd
2-
# CGI scripts in webroot and cgi-bin/ directory
1+
# httpd.conf for busybox httpd - KernelSU WebUI Module
2+
# CGI configuration for cgi-bin directory
33
*.sh:/system/bin/sh
44
/cgi-bin/*.sh:/system/bin/sh
5-
/api_*.sh:/system/bin/sh
5+
6+
# Security headers
7+
Access-Control-Allow-Origin: *
8+
Access-Control-Allow-Headers: *
9+
Access-Control-Allow-Methods: GET, POST, OPTIONS
10+
11+
# MIME types
12+
*.css:text/css
13+
*.js:application/javascript
14+
*.json:application/json
15+
*.html:text/html

webroot/script.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function checkAPIServer() {
1919
container.insertBefore(statusIndicator, container.firstChild);
2020

2121
try {
22-
const response = await fetch('http://127.0.0.1:8585/api_test.sh', {
22+
const response = await fetch('http://127.0.0.1:8585/cgi-bin/api_test.sh', {
2323
method: 'GET',
2424
signal: AbortSignal.timeout(5000)
2525
});
@@ -46,7 +46,7 @@ async function loadModules() {
4646
// Load state
4747
let state = {};
4848
try {
49-
const stateResponse = await fetch('http://127.0.0.1:8585/api_state.sh');
49+
const stateResponse = await fetch('http://127.0.0.1:8585/cgi-bin/api_state.sh');
5050
state = await stateResponse.json();
5151
} catch (e) {
5252
console.log('No state file yet');
@@ -130,7 +130,7 @@ async function downloadModule(name, repo, event) {
130130
formData.append('name', name);
131131
formData.append('repo', repo);
132132

133-
const response = await fetch('http://127.0.0.1:8585/api_download.sh', {
133+
const response = await fetch('http://127.0.0.1:8585/cgi-bin/api_download.sh', {
134134
method: 'POST',
135135
headers: {
136136
'Content-Type': 'application/x-www-form-urlencoded'
@@ -168,7 +168,7 @@ async function installModule(name, event) {
168168
const formData = new URLSearchParams();
169169
formData.append('name', name);
170170

171-
const response = await fetch('http://127.0.0.1:8585/api_install.sh', {
171+
const response = await fetch('http://127.0.0.1:8585/cgi-bin/api_install.sh', {
172172
method: 'POST',
173173
headers: {
174174
'Content-Type': 'application/x-www-form-urlencoded'
@@ -203,7 +203,7 @@ async function installAllModules() {
203203
statusText.textContent = 'Installing all modules...';
204204

205205
try {
206-
const response = await fetch('http://127.0.0.1:8585/api_install_all.sh', {
206+
const response = await fetch('http://127.0.0.1:8585/cgi-bin/api_install_all.sh', {
207207
method: 'POST'
208208
});
209209

@@ -234,7 +234,7 @@ async function testCGI() {
234234
statusText.textContent = 'Testing API server...';
235235

236236
try {
237-
const response = await fetch('http://127.0.0.1:8585/api_test.sh', {
237+
const response = await fetch('http://127.0.0.1:8585/cgi-bin/api_test.sh', {
238238
method: 'GET'
239239
});
240240

0 commit comments

Comments
 (0)