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

Add confirmation for removal of apps via webadmin

parent 0b14921f
No related branches found
No related tags found
No related merge requests found
......@@ -83,7 +83,7 @@
<p class="appdesc">APPDESCRIPTION</p>
<p class="appurl"><a href="APPURL">APPURL</a></p>
<br>
<form action="removeapp.php" method="post">
<form action="removeappconfirm.php" method="post">
<input type="hidden" name="app_name" value="APPNAME">
<input type="submit" name="uninstall" value="Uninstall">
</form>
......
<!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;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
max-width: 600px;
margin: auto;
text-align: center;
font-family: arial;
clear: both;
}
.card input[type=text] {
width: 90%;
clear: both;
text-align: center;
}
.appurl {
color: grey;
font-size: 100%;
}
.proceedtext {
color: red;
font-size: 120%;
}
button {
border: none;
outline: 0;
display: inline-block;
padding: 8px;
color: white;
background-color: red;
text-align: center;
cursor: pointer;
width: 100%;
font-size: 18px;
}
a {
text-decoration: none;
color: red;
}
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>
<div class="card">
<div class="header">
<img id="headerpic" class="img-responsive" src="images/logo.png"><br>
<br>
<p class="proceedtext"><b>Remove APPNAME now?</b></p>
<br>
<form action="removeappconfirm.php" method="post">
<p>
<input type="radio" name="removeconfirm" value="0" checked>No
<input type="radio" name="removeconfirm" value="1">Yes
<input type="hidden" name="app_name" value="APPNAME">
</p>
<br><br>
<input type="submit" name="removeconfirmsubmit" value="Continue" />
</form>
<br>
</div>
</div>
</body>
</html>
<?php
// This is used to begin removing an app.
//
// It creates the confirm screen, populates the variables
// in it and then opens it.
$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 ./pending_installs.txt');
}
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";
}
// create the confirm screen populated with details for the app
exec('cp remove_app_confirm_template.html remove_app_confirm.html');
if(file_exists("remove_app_confirm.html")) {
exec('sed -i "s|APPNAME|'.$app_name.'|g" remove_app_confirm.html');
$output_filename = "remove_app_confirm.html";
}
}
......
<?php
// This receives the yes/no confirmation when removing
// an app and then begins the removal
//
// Apps are removed by adding them to the pending_removes.txt
// file and the webadmin daemon (freedombone-installer) then
// does the actual removal in the background
$output_filename = "apps.html";
if (isset($_POST['removeconfirmsubmit'])) {
if(isset($_POST['removeconfirm'])) {
$confirm = htmlspecialchars($_POST['removeconfirm']);
if($confirm == "1") {
$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 ./pending_installs.txt');
}
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);
// remove confirm screen
if(file_exists("remove_app_confirm.html")) {
exec('rm remove_app_confirm.html');
}
?>
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