Skip to content

Commit

Permalink
CMAL100 (RACHEL-Plus v3) changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Field committed May 1, 2018
1 parent 5e8425c commit d98f84d
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 60 deletions.
Binary file added admin/art/ecs-cap-power-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 32 additions & 2 deletions admin/background.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,38 @@ function setRsyncDaemon($state) {
}

function getBatteryInfo() {
$level = rtrim(file_get_contents("/tmp/batteryLastChargeLevel"));
$status = rtrim(file_get_contents("/tmp/chargeStatus"));

# CAP1 & CAP2 (Gemtek)
$chargefile = "/tmp/batteryLastChargeLevel";
$statusfile = "/tmp/chargeStatus";
if (file_exists($chargefile)) {
$level = rtrim(file_get_contents($chargefile));
$status = rtrim(file_get_contents($statusfile));
# status is an unsigned number that indicates the
# load on the battery -- it varies constantly, but
# we've determined that -20 indicates discharge
# (i.e. not plugged in)
if ($status <= -20) {
$status = "discharging";
} else {
$status = "charging";
}

# CAP3 (ECS CMAL100)
} else if (file_exists("/usr/bin/ubus")) {
exec("ubus call battery info", $out, $rv);
$ubus = json_decode(implode($out), true);
$level = $ubus['capacity'];
$status = rtrim($ubus['status']);
# options are "Charging", "Discharging", and "Unknown"
# which seems to indicate charged (so we call it charging)
if ($status == "Discharging") {
$status = "discharging";
} else {
$status = "charging";
}
}

header("HTTP/1.1 200 OK");
header("Content-Type: application/json");
echo "{ \"level\" : \"$level\", \"status\" : \"$status\" }\n";
Expand Down
3 changes: 3 additions & 0 deletions admin/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ function is_rachelpi() {
function is_rachelplus() {
return is_dir(RACHELPLUS_MODPATH) || file_exists("/tmp/fake-rachelplus");
}
function is_rachelplusv3() {
return is_dir("/.data/RACHEL") || file_exists("/tmp/fake-rachelplusv3");
}

#-------------------------------------------
# gets the absolute module path on any machine
Expand Down
77 changes: 56 additions & 21 deletions admin/hardware.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,26 @@
}

if (isset($_POST['shutdown'])) {
exec("sudo /sbin/poweroff", $exec_out, $exec_err);
# pause so the webserver can respond, the complexity of the the
# command is so that the exec() returns instantly
exec("sudo sh -c 'sleep 3; /sbin/poweroff;' > /dev/null 2>&1 &", $exec_out, $exec_err);
if ($exec_err) {
echo $lang['shutdown_failed'];
} else {
echo $lang['shutdown_ok'];
}
include "foot.php";
exit;
} else if (isset($_POST['reboot'])) {
exec("sudo /sbin/reboot", $exec_out, $exec_err);
# pause so the webserver can respond, the complexity of the the
# command is so that the exec() returns instantly
exec("sudo sh -c 'sleep 3; /sbin/reboot;' > /dev/null 2>&1 &", $exec_out, $exec_err);
if ($exec_err) {
echo $lang['restart_failed'];
} else {
echo $lang['restart_ok'];
}
include "foot.php";
exit;
}

Expand All @@ -55,7 +61,12 @@
";

if (file_exists("/root/rachel-scripts/esp-checker.php")) {
$id = strtoupper(exec("ifconfig | grep eth0 | awk '{ print $5 }' | sed s/://g | grep -o '.\{6\}$'"));
if (is_rachelplusv3()) {
$interface = "enp2s0";
} else {
$interface = "eth0";
}
$id = strtoupper(exec("ifconfig | grep $interface | awk '{ print $5 }' | sed s/://g | grep -o '.\{6\}$'"));
echo "<h3 style='float: right;'>Device ID: $id</h3>";
}

Expand Down Expand Up @@ -85,11 +96,18 @@

$usage_supported = true;

$partitions = array(
"/media/preloaded" => "Admin (preloaded)",
"/media/uploaded" => "Teacher (uploaded)",
"/media/RACHEL" => "RACHEL (RACHEL modules)"
);
# v3 has different layout
if (file_exists("/.data/RACHEL")) {
$partitions = array(
"/.data" => "/media/RACHEL",
);
} else {
$partitions = array(
"/media/preloaded" => "Admin (preloaded)",
"/media/uploaded" => "Teacher (uploaded)",
"/media/RACHEL" => "RACHEL (RACHEL modules)"
);
}

foreach ($output as $line) {
list($fs, $size, $used, $avail, $perc, $name) = preg_split("/\s+/", $line);
Expand Down Expand Up @@ -156,10 +174,9 @@
#-------------------------------------------
# This is the only way to turn wifi on and off on the PLUS
#-------------------------------------------
if (is_rachelplus()) {

if (is_rachelplus() && !is_rachelplusv3()) {
echo "
<h2>$lang[wifi_control]</h3>
<h2>$lang[wifi_control]</h2>
<div style='height: 24px;'>
<div style='float: left; height: 24px; margin-right: 10px;'>$lang[current_status]:</div>
<div id='wifistat' style='height: 24px;'>&nbsp;</div>
Expand All @@ -170,12 +187,11 @@
</div>
<p>$lang[wifi_warning]</p>
";

}

#-------------------------------------------
# We also offer a shutdown option for raspberry pi systems
# (which otherwise might corrupt themselves when unplugged)
# We also offer a shutdown (especially important for raspberry pi systems
# which otherwise might corrupt themselves when unplugged)
#-------------------------------------------
if (is_rachelpi()) {
echo "
Expand All @@ -189,6 +205,20 @@
$lang[shutdown_blurb]
</div>
";
} else if (is_rachelplusv3()) {
echo "
<h2>$lang[system_shutdown]</h3>
<h3>RACHEL-Plus</h3>
<img src='art/ecs-cap-power-button.png' width='178' height='178'>
<p>You can force shut down by pressing and holding the power button for five seconds.
<p><b>To safely shut down or restart, use the buttons below:</b>
<div style='padding: 10px; border: 1px solid red; background: #fee;'>
<form action='hardware.php' method='post'>
<input type='submit' name='shutdown' value='$lang[shutdown]' onclick=\"if (!confirm('$lang[confirm_shutdown]')) { return false; }\">
<input type='submit' name='reboot' value='$lang[restart]' onclick=\"if (!confirm('$lang[confirm_restart]')) { return false; }\">
</form>
</div>
";
} else if (is_rachelplus()) {
echo "
<h2>$lang[system_shutdown]</h3>
Expand All @@ -202,14 +232,19 @@
</form>
</div>
";
} else {
# decided to just not show this for unsupported systems
# echo "
# <h3>$lang[unknown_system]</h3>
# <p>$lang[shutdown_not_supported]</p>
# ";
}

include "foot.php"
if (is_rachelplus()) {
echo "
<h2>Advanced Hardware Control</h2>
To modify advanced hardware settings (WiFi, DHCP, Firewall, etc.) please
<a href='//$_SERVER[HTTP_HOST]:8080' target='_blank'>click here</a>
<p><b>Note:</b> The settings in the advanced hardware control can cause your RACHEL
to stop working.<br>
Do not change unless you know what you are doing.</p>
";
}

include "foot.php";

?>
4 changes: 2 additions & 2 deletions admin/nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function getBatteryInfo() {
else if (results.level < 40) { vert = -36; }
else if (results.level < 60) { vert = -24; }
else if (results.level < 80) { vert = -12; }
var horz = 0; // shows not plugged (40px right to show plugged)
if (results.status > -20 ) { horz = 40 }
var horz = 0; // 0 shows discharging, 40px offset shows charging
if (results.status == "charging" ) { horz = 40 }
$("#battery").css({
background: "url(\'art/battery-level-sprite-dark.png\')",
backgroundPosition: horz+"px "+vert+"px",
Expand Down
72 changes: 42 additions & 30 deletions admin/post-update-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ setVariables() {
isPlusVer1=1
elif [[ `uname -n` = "WAPD-235N-Server" ]]; then
isPlusVer2=1
elif [[ `uname -n | grep CMAL` ]]; then
isPlusVer3=1
fi
elif [[ -d $piWebDir ]]; then
# we're on a RACHEL-Pi
Expand All @@ -71,6 +73,7 @@ checkVariables() {
echo " isPlus: " $isPlus;
echo "isPlusVer1: " $isPlusVer1
echo "isPlusVer2: " $isPlusVer2
echo "isPlusVer3: " $isPlusVer3
echo " webDir: " $webDir;
echo " adminDir: " $adminDir;
echo " modDir: " $modDir;
Expand Down Expand Up @@ -142,37 +145,45 @@ installAWStats() {
# we only install on the plus
awstatsDir=/media/RACHEL/awstats
if [[ $isPlus ]]; then
# and only if it's not there yet -- in the future we'll want
# to check a version number or just always copy the lastest
# version over -- early on there was an installer error
# where we didn't create the data directory, so we check for that
# instead of just the awstats directory
if [[ ! -d $awstatsDir/data ]]; then
# remove any incomplete version
rm -rf $awstatsDir
# copy over our version
cp -r $adminDir/externals/awstats $awstatsDir
# symlink the conf file
ln -sf $awstatsDir/awstats.conf /etc/

# copy over the latest version, but leave data intact
rsync -a --exclude '/data/' $adminDir/externals/awstats/ $awstatsDir/

# create data directory (should be harmless if already there)
mkdir -p $awstatsDir/data

# symlink the conf file (should be harmless if already there)
ln -sf $awstatsDir/awstats.conf /etc/

# the v3 uses nginx instead of lighttpd
if [[ $isPlusVer3 ]]; then
sed -i '/LogFile/ s/httpd\/access_log/nginx\/access.log/' $awstatsDir/awstats.conf
fi
# next we update lighttpd configuration to run awstats on
# its own port, and to use a fixed hostname in the log
# -- be careful not to do it twice (or more!)
lighttpdConf=/usr/local/etc/lighttpd.conf
if [[ -z `grep 'start awstats changes' $lighttpdConf` ]]; then
# append the conf addtions
cat $awstatsDir/lighttpd.awstats.conf >> $lighttpdConf
# restart webserver - note that while it may be smarter
# to do this once at the end, we actually need this to happen
# before we do the log processing below, so do it now
restartWebserver
# after changing the server log config we have to filter the
# existing log for server hostname/ip -- this can take a few
# minutes so we background it -- we also need to clear out
# any collated awstats data after we're done fixing the
# log because that data will be based on the unfixed log
perl -pi -e 's/ \S+ / RACHEL /' /var/log/httpd/access_log && rm -rf $awstatsDir/data/* &

# everything is already taken care of on the v3 plus, but on the v1/v2:
if [[ $isPlus1 || $isPlus2 ]]; then

# next we update lighttpd configuration to run awstats on
# its own port, and to use a fixed hostname in the log
# -- be careful not to do it twice (or more!)
lighttpdConf=/usr/local/etc/lighttpd.conf
if [[ -z `grep 'start awstats changes' $lighttpdConf` ]]; then
# append the conf addtions
cat $awstatsDir/lighttpd.awstats.conf >> $lighttpdConf
# restart webserver - note that while it may be smarter
# to do this once at the end, we actually need this to happen
# before we do the log processing below, so do it now
restartWebserver
# after changing the server log config we have to filter the
# existing log for server hostname/ip -- this can take a few
# minutes so we background it -- we also need to clear out
# any collated awstats data after we're done fixing the
# log because that data will be based on the unfixed log
perl -pi -e 's/ \S+ / RACHEL /' /var/log/httpd/access_log && rm -rf $awstatsDir/data/* &
fi
fi
# that's the end of the plus 1/2 code

# next we need to add a line to crontab to collate the log data
crontabFile=/etc/crontab
if [[ -z `grep 'awstats upkeep' $crontabFile` ]]; then
Expand All @@ -187,12 +198,13 @@ installAWStats() {
sed -i '/awstats.pl > \/dev\/null/ s/null/null\n/' $crontabFile
fi
fi

fi
}

# restarts the webserver if the flag to do so has been set
restartWebserver() {
if [[ $isPlus ]]; then
if [[ $isPlus1 || $isPlus2 ]]; then
killall -INT lighttpd && /usr/bin/lighttpd -f /usr/local/etc/lighttpd.conf
fi
}
Expand Down
9 changes: 6 additions & 3 deletions admin/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,11 @@ function cancelTask(task_id, mybutton) {
$kalite_version = "?";
}

$kiwix_version = exec("cat /var/kiwix/application.ini | grep ^Version | cut -d= -f2");
if (!$kiwix_version || !preg_match("/^[\d\.]+$/", $kiwix_version)) {
$kiwix_version = exec("cat /etc/kiwix/application.ini | grep ^Version | cut -d= -f2");
if (!$kiwix_version) {
$kiwix_version = exec("cat /etc/kiwix-version");
}
if (!$kiwix_version) {
$kiwix_version = "?";
}

Expand All @@ -420,7 +423,7 @@ function cancelTask(task_id, mybutton) {
<tr><td>Kiwix</td><td><?php echo $kiwix_version ?></td></tr>
<tr><td>Content Shell</td><td>

<span id="cur_contentshell">v2.3.5</span>
<span id="cur_contentshell">v2.3.6</span>
<div style="float: right; margin-left: 20px;">
<div style="float: left; width: 24px; height: 24px; margin-top: 2px;">
<img src="../art/spinner.gif" id="spinner" style="display: none;">
Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ function getBatteryInfo() {
else if (results.level < 40) { vert = -36; }
else if (results.level < 60) { vert = -24; }
else if (results.level < 80) { vert = -12; }
var horz = 0; // shows not plugged (40px right to show plugged)
if (results.status > -20 ) { horz = 40 }
var horz = 0; // 0 shows discharging, 40px offset shows charging
if (results.status == "charging" ) { horz = 40 }
$("#battery").css({
background: "url(\'art/battery-level-sprite-light.png\')",
backgroundPosition: horz+"px "+vert+"px",
Expand Down

0 comments on commit d98f84d

Please sign in to comment.