forked from samtap/fang-hacks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create bootstrap CSS template and update status/scripts
The work in fang_hacks.sh is UNTESTED
- Loading branch information
1 parent
8c49783
commit 2816a9b
Showing
13 changed files
with
284 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<script src="/js/jquery.min.js"></script> | ||
<script src="/js/bootstrap.min.js"></script> | ||
</div> | ||
</body> | ||
</html> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<title>Fang Hacks</title> | ||
<link rel="stylesheet" href="/css/bootstrap.min.css"> | ||
<style> | ||
body { padding-top: 5rem; } | ||
pre { font-size: 70%; } | ||
</style> | ||
</head> | ||
|
||
<body> | ||
|
||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top"> | ||
<a class="navbar-brand" href="status">Fang Hacks</a> | ||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation"> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
|
||
<div class="collapse navbar-collapse" id="navbarsExampleDefault"> | ||
<ul class="navbar-nav mr-auto"> | ||
<li class="nav-item active"> | ||
<a class="nav-link" href="status">Status</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="scripts">Scripts</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="network">Network</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="action?cmd=showlog">Log</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="action?cmd=reboot">Reboot</a> | ||
</li> | ||
</ul> | ||
</div> | ||
</nav> | ||
|
||
<div class="container"> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/bin/sh | ||
|
||
echo "Content-type: text/html" | ||
echo "" | ||
|
||
source func.cgi | ||
|
||
cat header.tpl | ||
|
||
echo '<h1>Boot scripts</h1>' | ||
|
||
SCRIPT_HOME="/media/mmcblk0p2/data/etc/scripts" | ||
source "/media/mmcblk0p2/data/etc/profile" >/dev/null 2>&1 | ||
if [ -n "$F_script" ]; then | ||
script="${F_script##*/}" | ||
if [ -e "$SCRIPT_HOME/$script" ]; then | ||
case "$F_cmd" in | ||
start) | ||
echo "Running script '$script'...<br/>" | ||
echo "<pre>$($SCRIPT_HOME/$script 2>&1)</pre>" | ||
;; | ||
disable) | ||
echo "Disable script '$script'...<br/>" | ||
chmod a-x "$SCRIPT_HOME/$script" 2>&1 | ||
;; | ||
stop) | ||
echo "Stop script '$script'...<br/>" | ||
$SCRIPT_HOME/$script stop 2>&1 && echo "OK" || echo "NOK" | ||
echo "<br/>" | ||
;; | ||
enable) | ||
echo "Enable script '$script'...<br/>" | ||
chmod a+x "$SCRIPT_HOME/$script" 2>&1 | ||
;; | ||
view) | ||
echo "<h3>Contents of script '$script':</h3>" | ||
echo "<pre>$(cat $SCRIPT_HOME/$script 2>&1)</pre>" | ||
;; | ||
*) | ||
echo "Unsupported command '$F_cmd'<br/>" | ||
echo "<div class='alert alert-warning' role='alert'>$F_script is not a valid script!</div>" | ||
;; | ||
esac | ||
echo "<hr/>" | ||
else | ||
echo "<div class='alert alert-danger' role='alert'>$F_script is not a valid script!</div>" | ||
fi | ||
fi | ||
|
||
if [ ! -d "$SCRIPT_HOME" ]; then | ||
echo "No scripts found in $SCRIPT_HOME<br/>" | ||
else | ||
SCRIPTS=$(ls -A "$SCRIPT_HOME") | ||
echo "<table class='table table-bordered table-striped'>" | ||
echo "<tr><th>Service</th><th>Status</th><th/><th/><th/><th/></tr>" | ||
for i in $SCRIPTS; do | ||
echo "<tr>" | ||
echo "<td>$i</td>" | ||
if [ -x "$SCRIPT_HOME/$i" ]; then | ||
if [ $(grep "^status\(\)" "$SCRIPT_HOME/$i") ]; then | ||
status="$($SCRIPT_HOME/$i status)" | ||
if [ $? -eq 0 ]; then | ||
if [ -n "$status" ]; then | ||
bgcolor="table-success"; | ||
else | ||
bgcolor="table-warning"; | ||
fi | ||
else | ||
bgcolor="table-danger" | ||
status="NOK" | ||
fi | ||
echo "<td class='$bgcolor'>$status</td>"; | ||
else | ||
echo "<td/>" | ||
fi | ||
|
||
if [ $(grep "^start\(\)" "$SCRIPT_HOME/$i") ]; then | ||
if [ -z "$status" ]; then | ||
echo "<td><button title='Start script' type='button' class='btn btn-success' onClick=\"window.location.href='scripts?cmd=start&script=$i'\">Start</button</td>" | ||
else | ||
echo "<td><button title='Already running' class='btn disabled' disabled>Start</button>" | ||
fi | ||
else | ||
echo "<td><button title='Run script' type='button' class='btn' onClick=\"window.location.href='scripts?cmd=start&script=$i'\">Run</button></td>" | ||
fi | ||
|
||
if [ $(grep "^stop\(\)" "$SCRIPT_HOME/$i") ]; then | ||
if [ -n "$status" ]; then | ||
echo "<td><button title='Stop script' type='button' class='btn btn-danger' onClick=\"window.location.href='scripts?cmd=stop&script=$i'\">Stop</button></td>" | ||
else | ||
echo "<td><button title='Not running' class='btn disabled' disabled>Stop</button>" | ||
fi | ||
else | ||
echo "<td></td>" | ||
fi | ||
echo "<td><button title='Disable script' type='button' class='btn' onClick=\"window.location.href='scripts?cmd=disable&script=$i'\">Disable</button></td>" | ||
else | ||
echo "<td/>" | ||
echo "<td><button title='Enable script' type='button' class='btn' onClick=\"window.location.href='scripts?cmd=enable&script=$i'\">Enable</button></td>" | ||
echo "<td/><td/>" | ||
fi | ||
echo "<td><button title='View script' type='button' class='btn' onClick=\"window.location.href='scripts?cmd=view&script=$i'\">View</button></td>" | ||
echo "</tr>" | ||
done | ||
echo "</table>" | ||
fi | ||
|
||
cat footer.tpl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/bin/sh | ||
|
||
echo "Content-type: text/html" | ||
echo "" | ||
|
||
cat header.tpl | ||
|
||
echo '<h1>Fang Hacks!</h1>' | ||
|
||
HACKS_HOME="/media/mmcblk0p2/data" | ||
if [ -x "/etc/fang_hacks.sh" ]; then | ||
echo "<div class='alert alert-success' role='alert'>Script is already installed!</div>" | ||
if [ ! $(mount |grep /media/mmcblk0p2) ]; then | ||
echo "<span class='err'>Error: Nothing is mounted on /media/mmcblk0p2!</span>" | ||
echo "<button title='Try to mount the hacks partition manually' type='button' class='btn btn-outline-primary' onClick=\"window.location.href='action?cmd=manual_mount'\">Manual Mount</button>" | ||
echo "<br/>" | ||
elif [ ! -d "$HACKS_HOME" ]; then | ||
echo "<span class='err'>Error: No 'data' directory found in /media/mmcblk0p2!</span>" | ||
echo "<br/>" | ||
else | ||
if [ -e "/etc/.resize_runonce" ]; then | ||
echo "<span class='err'>Reboot required to apply new partition layout!</span>" | ||
echo "<br/>" | ||
elif [ -e "$HACKS_HOME/.resize" ]; then | ||
echo "Expand data partition (/media/mmcblk0p2)?" | ||
echo "<button title='Expand data partition' type='button' class='btn btn-outline-primary' onClick=\"window.location.href='action?cmd=expandfs'\">Yes</button>" | ||
echo "<br/>" | ||
fi | ||
fi | ||
if [ -e /etc/fang_hacks.cfg ]; then | ||
source /etc/fang_hacks.cfg | ||
echo "<form action='/cgi-bin/action?cmd=apply_cfg' method='post'>" | ||
echo "<input type='hidden' name='none'/><!-- never post an empty form -->" | ||
if [ "$HACKS_ENABLED" -eq 1 ]; then checked="checked"; fi | ||
echo "<label class='btn btn-outline-primary active'><input name='hacks_enable' type='checkbox' $checked/>Hacks enabled</label>" | ||
echo "<br/>" | ||
unset checked | ||
|
||
if [ "$DISABLE_CLOUD" -eq 1 ]; then | ||
checked="checked" | ||
else | ||
if [ "$NETWORK_MODE" -eq 0 ]; then | ||
disabled="disabled" | ||
title="Cannot disable when network is set to Cloud Mode!" | ||
fi | ||
fi | ||
echo "<label class='btn btn-outline-primary active'><input name='disable_cloud' type='checkbox' title='$title' $checked $disabled/>Disable cloud applications</label>" | ||
echo "<br/>" | ||
echo "<input type='submit' value='Apply' class='btn button-outline-primary'/>" | ||
echo "</form>" | ||
fi | ||
echo "Apply updates from sd-card?" | ||
echo "<button title='Copy updates from sd-card to device' type='button' class='btn btn-outline-primary' onClick=\"window.location.href='action?cmd=update'\">Update</button>" | ||
else | ||
echo "Do you want to apply Xiao Fang hacks?<br/>" | ||
echo "<button title='Copy the fang_hacks.sh script to the device' type='button' class='btn btn-outline-primary' onClick=\"window.location.href='action?cmd=apply'\">Apply</button>" | ||
fi | ||
|
||
cat << EOF | ||
</p> | ||
<hr/> | ||
<button title='Start default telnetd on port 23' type='button' class='btn btn-outline-primary' onClick="window.location.href='action?cmd=telnetd'">Start rescue telnetd</button> | ||
<button title='Reboot the device' type='button' class='btn btn-outline-primary' onClick="window.location.href='action?cmd=reboot'">Reboot</button> | ||
<button title='Manage scripts' type='button' class='btn btn-outline-primary' onClick="window.location.href='scripts'">Manage scripts</button> | ||
<button title='Network' type='button' class='btn btn-outline-primary' onClick="window.location.href='network'">Network</button> | ||
<button title='View /tmp/hacks.log' type='button' class='btn btn-outline-primary' onClick="window.location.href='action?cmd=showlog'">View log</button> | ||
<hr/> | ||
<table class="table table-bordered table-striped table-responsive"> | ||
<tr> | ||
<th>Date:</th> | ||
<td> | ||
<form style="margin: 0px" action="/cgi-bin/action?cmd=settz" method="post"> | ||
$(date) | ||
<label style="margin-left: 1em" for="tz">TZ:</label> | ||
<input id="tz" name="tz" type="text" size="25" value="$(cat /etc/TZ)"/> | ||
<label for="hostname">Hostname:</label> | ||
<input id="hostname" name="hostname" type="text" size="15" value="$(cat /etc/hostname)"/> | ||
<input type="submit" class='btn btn-outline-primary' value="Set"/> | ||
</form> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th>System uptime:</th> | ||
<td>$(uptime)</td> | ||
</tr> | ||
<tr> | ||
<th>Version:</th> | ||
<td>$(cat /etc/os-release | cut -d'=' -f2)</td> | ||
</tr> | ||
<tr> | ||
<th>Kernel:</th> | ||
<td>$(uname -a)</td> | ||
</tr> | ||
</table> | ||
<h3>Process list</h3> | ||
<pre>$(ps)</pre> | ||
<h3>Mounts</h3> | ||
<pre>$(mount)</pre> | ||
EOF | ||
|
||
cat footer.tpl |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.