Skip to content
Snippets Groups Projects
Commit 8e16a4c5 authored by Bob Mottram's avatar Bob Mottram
Browse files

App removal from web admin

parent b2fdf6c8
No related branches found
No related tags found
No related merge requests found
......@@ -260,6 +260,7 @@ function web_admin_create_installed_apps {
app_template_filename="/var/www/${local_hostname}/htdocs/admin/app_template.html"
appslist_filename="/var/www/${local_hostname}/htdocs/admin/apps.html"
icons_dir="/var/www/${local_hostname}/htdocs/admin/icons"
pending_removes="/var/www/${local_hostname}/htdocs/admin/pending_removes.txt"
if [ ! -d "$icons_dir" ]; then
mkdir -p "$icons_dir"
......@@ -281,76 +282,88 @@ function web_admin_create_installed_apps {
if [ "$app_name" ]; then
app_filename="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"
if [ -f "$app_filename" ]; then
# get the icon for the app
icon_filename="/usr/share/${PROJECT_NAME}/android-app/${app_name}.png"
if [ -f "$icon_filename" ]; then
cp "$icon_filename" "/var/www/${local_hostname}/htdocs/admin/icons/${app_name}.png"
else
icon_filename=
# check if the app is being removed
app_being_removed=
if [ -f "$pending_removes" ]; then
if grep -q "remove_${app_name}" "$pending_removes"; then
app_being_removed=1
fi
fi
app_name_upper=$(echo "$app_name" | awk '{print toupper($0)}')
SHORT_DESCRIPTION=
DESCRIPTION=
if [ ! $app_being_removed ]; then
# get the icon for the app
icon_filename="/usr/share/${PROJECT_NAME}/android-app/${app_name}.png"
if [ -f "$icon_filename" ]; then
cp "$icon_filename" "/var/www/${local_hostname}/htdocs/admin/icons/${app_name}.png"
else
icon_filename=
fi
if ! grep -q "${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename"; then
app_index=$((app_index+1))
continue
fi
if grep -q "#${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename"; then
app_index=$((app_index+1))
continue
fi
SHORT_DESCRIPTION="$(grep "${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename" | head -n 1 | sed 's|\$||g' | sed "s|'||g" | sed 's|\"||g' | awk -F '=' '{print $2}')"
app_name_upper=$(echo "$app_name" | awk '{print toupper($0)}')
SHORT_DESCRIPTION=
DESCRIPTION=
if grep -q "${app_name_upper}_DESCRIPTION=" "$app_filename"; then
DESCRIPTION="$(grep "${app_name_upper}_DESCRIPTION=" "$app_filename" | head -n 1 | sed 's|\$||g' | sed "s|'||g" | sed 's|\"||g' | awk -F '=' '{print $2}')"
fi
if ! grep -q "${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename"; then
app_index=$((app_index+1))
continue
fi
if grep -q "#${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename"; then
app_index=$((app_index+1))
continue
fi
SHORT_DESCRIPTION="$(grep "${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename" | head -n 1 | sed 's|\$||g' | sed "s|'||g" | sed 's|\"||g' | awk -F '=' '{print $2}')"
read_config_param "${app_name_upper}_DOMAIN_NAME"
test_domain_name="${app_name_upper}_DOMAIN_NAME"
domain_name=${!test_domain_name}
if [ "$domain_name" ]; then
if [[ "$domain_name" != *'.onion' ]]; then
domain_name="https://${!test_domain_name}"
else
domain_name="http://${!test_domain_name}"
if grep -q "${app_name_upper}_DESCRIPTION=" "$app_filename"; then
DESCRIPTION="$(grep "${app_name_upper}_DESCRIPTION=" "$app_filename" | head -n 1 | sed 's|\$||g' | sed "s|'||g" | sed 's|\"||g' | awk -F '=' '{print $2}')"
fi
fi
if [ $installed_apps_ctr -eq 0 ]; then
echo ' <div class="row">' >> "$appslist_filename"
fi
read_config_param "${app_name_upper}_DOMAIN_NAME"
test_domain_name="${app_name_upper}_DOMAIN_NAME"
domain_name=${!test_domain_name}
if [ "$domain_name" ]; then
if [[ "$domain_name" != *'.onion' ]]; then
domain_name="https://${!test_domain_name}"
else
domain_name="http://${!test_domain_name}"
fi
fi
filename="/var/www/${local_hostname}/htdocs/admin/app_add_${app_name}.html"
if [ -f "$filename" ]; then
rm "$filename"
fi
if [ $installed_apps_ctr -eq 0 ]; then
echo ' <div class="row">' >> "$appslist_filename"
fi
filename="/var/www/${local_hostname}/htdocs/admin/app_${app_name}.html"
filename="/var/www/${local_hostname}/htdocs/admin/app_add_${app_name}.html"
if [ -f "$filename" ]; then
rm "$filename"
fi
{ echo ' <div class="column">';
echo ' <div>';
echo " <a href=\"app_${app_name}.html\">";
echo " <img src=\"icons/${app_name}.png\" style=\"width:100%\">";
echo " <center>${app_name}</center>";
echo ' </a>';
echo ' </div>';
echo ' </div>'; } >> "$appslist_filename"
filename="/var/www/${local_hostname}/htdocs/admin/app_${app_name}.html"
cp "$app_template_filename" "$filename"
{ echo ' <div class="column">';
echo ' <div>';
echo " <a href=\"app_${app_name}.html\">";
echo " <img src=\"icons/${app_name}.png\" style=\"width:100%\">";
echo " <center>${app_name}</center>";
echo ' </a>';
echo ' </div>';
echo ' </div>'; } >> "$appslist_filename"
# Replace app variables
sed -i "s|APPNAME|${app_name}|g" "$filename"
sed -i "s|APPURL|${domain_name}|g" "$filename"
sed -i "s|APPDESCRIPTION|${DESCRIPTION}|g" "$filename"
cp "$app_template_filename" "$filename"
installed_apps_ctr=$((installed_apps_ctr+1))
# Replace app variables
sed -i "s|HOSTNAME|$(hostname)|g" "$filename"
sed -i "s|APPNAME|${app_name}|g" "$filename"
sed -i "s|APPURL|${domain_name}|g" "$filename"
sed -i "s|APPDESCRIPTION|${DESCRIPTION}|g" "$filename"
# four columns per row
if [ $installed_apps_ctr -eq 4 ]; then
echo ' </div>' >> "$appslist_filename"
installed_apps_ctr=0
installed_apps_ctr=$((installed_apps_ctr+1))
# four columns per row
if [ $installed_apps_ctr -eq 4 ]; then
echo ' </div>' >> "$appslist_filename"
installed_apps_ctr=0
fi
fi
fi
fi
......
<!DOCTYPE html>
<html>
<head>
<style>
#headerpic {
width: 60%;
height: auto;
margin-right : auto;
margin-left : auto;
min-width : 220px;
}
.header {
text-align: center;
padding: 32px;
}
#iconpic {
width: 20%;
height: auto;
margin-right : auto;
margin-left : auto;
min-width : 120px;
}
.appurl {
color: grey;
font-size: 100%;
}
.appdesc {
color: black;
font-size: 65%;
}
button {
border: none;
outline: 0;
display: inline-block;
padding: 8px;
color: white;
background-color: #000;
text-align: center;
cursor: pointer;
width: 100%;
font-size: 18px;
}
a {
text-decoration: none;
color: black;
}
button:hover, a:hover {
opacity: 0.7;
}
</style>
</head>
<body>
<div class="header">
<a href="apps.html"><img id="headerpic" class="img-responsive" src="logo.png"></a>
<h2>Beginning removal of app</h2>
<form action="apps.html">
<input type="submit" value="Go Back" />
</form>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
#headerpic {
width: 60%;
height: auto;
margin-right : auto;
margin-left : auto;
min-width : 220px;
}
.header {
text-align: center;
padding: 32px;
}
#iconpic {
width: 20%;
height: auto;
margin-right : auto;
margin-left : auto;
min-width : 120px;
}
.appurl {
color: grey;
font-size: 100%;
}
.appdesc {
color: black;
font-size: 65%;
}
button {
border: none;
outline: 0;
display: inline-block;
padding: 8px;
color: white;
background-color: #000;
text-align: center;
cursor: pointer;
width: 100%;
font-size: 18px;
}
a {
text-decoration: none;
color: black;
}
button:hover, a:hover {
opacity: 0.7;
}
</style>
</head>
<body>
<div class="header">
<a href="apps.html"><img id="headerpic" class="img-responsive" src="logo.png"></a>
<h2>App is being removed</h2>
<form action="apps.html">
<input type="submit" value="Go Back" />
</form>
</div>
</body>
</html>
......@@ -20,6 +20,13 @@
margin: auto;
text-align: center;
font-family: arial;
clear: both;
}
.card input[type=text] {
width: 90%;
clear: both;
text-align: center;
}
.appurl {
......@@ -53,24 +60,6 @@
button:hover, a:hover {
opacity: 0.7;
}
.chip {
display: inline-block;
padding: 0 25px;
height: 50px;
font-size: 70%;
line-height: 50px;
border-radius: 25px;
background-color: #f1f1f1;
}
.chip img {
float: left;
margin: 0 10px 0 -25px;
height: 50px;
width: 50px;
border-radius: 50%;
}
</style>
</head>
<body>
......@@ -83,9 +72,11 @@
<h1>APPNAME</h1>
<p class="appurl"><a href="APPURL">APPURL</a></p>
<p class="appdesc">APPDESCRIPTION</p>
<div class="chip">
Uninstall
</div>
<form action="removeapp.php" method="post">
<input type="hidden" name="app_name" value="APPNAME">
<input type="submit" name="uninstall" value="Uninstall">
</form>
</div>
</body>
......
......@@ -6,20 +6,37 @@ if (isset($_POST['install'])) {
$app_name = htmlspecialchars($_POST['app_name']);
$install_domain = $_POST['install_domain'];
if(! file_exists("pending_installs.txt")) {
$pending_installs = fopen("pending_installs.txt", "w") or die("Unable to create installs file");
fclose($pending_installs);
$continue_install=true;
if(file_exists("pending_removes.txt")) {
// Is this app in the pending_removes list?
if(exec('grep '.escapeshellarg("remove_".$app_name).' ./pending_removes.txt')) {
if(! exec('grep '.escapeshellarg("remove_".$app_name).'_running ./pending_removes.txt')) {
// Not Removing yet so remove from schedule
exec('sed -i "/'.escapeshellarg("remove_".$app_name).'/d');
}
else {
// Removing so don't continue
$continue_install=false;
}
}
}
if(! exec('grep '.escapeshellarg("install_".$app_name).' ./pending_installs.txt')) {
$pending_installs = fopen("pending_installs.txt", "a") or die("Unable to append to installs file");
fwrite($pending_installs, "install_".$app_name."\n");
fclose($pending_installs);
$output_filename = "app_installing.html";
}
else {
// The app is already scheduled for installation
$output_filename = "app_scheduled.html";
if($continue_install) {
if(! file_exists("pending_installs.txt")) {
$pending_installs = fopen("pending_installs.txt", "w") or die("Unable to create installs file");
fclose($pending_installs);
}
if(! exec('grep '.escapeshellarg("install_".$app_name).' ./pending_installs.txt')) {
$pending_installs = fopen("pending_installs.txt", "a") or die("Unable to append to installs file");
fwrite($pending_installs, "install_".$app_name."\n");
fclose($pending_installs);
$output_filename = "app_installing.html";
}
else {
// The app is already scheduled for installation
$output_filename = "app_scheduled.html";
}
}
}
......
<?php
$output_filename = "apps.html";
if (isset($_POST['uninstall'])) {
$app_name = htmlspecialchars($_POST['app_name']);
$continue_remove=true;
if(file_exists("pending_installs.txt")) {
// Is this app in the pending_installs list?
if(exec('grep '.escapeshellarg("install_".$app_name).' ./pending_installs.txt')) {
if(! exec('grep '.escapeshellarg("install_".$app_name).'_running ./pending_installs.txt')) {
// Not installing yet so remove from schedule
exec('sed -i "/'.escapeshellarg("install_".$app_name).'/d');
}
else {
// Installing so don't continue
$continue_remove=false;
}
}
}
if($continue_remove) {
if(! file_exists("pending_removes.txt")) {
$pending_removes = fopen("pending_removes.txt", "w") or die("Unable to create removes file");
fclose($pending_removes);
}
if(! exec('grep '.escapeshellarg("remove_".$app_name).' ./pending_removes.txt')) {
$pending_removes = fopen("pending_removes.txt", "a") or die("Unable to append to removes file");
fwrite($pending_removes, "remove_".$app_name."\n");
fclose($pending_removes);
$output_filename = "app_remove.html";
}
else {
// The app is already scheduled for removal
$output_filename = "app_remove_scheduled.html";
}
}
}
$htmlfile = fopen("$output_filename", "r") or die("Unable to open $output_filename");
echo fread($htmlfile,filesize("$output_filename"));
fclose($htmlfile);
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment