forked from vergnet/site-accueil-insa
Added admin updates page
This commit is contained in:
parent
08365a307e
commit
b0ae62f5db
6 changed files with 146 additions and 4 deletions
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
# Default ignored files
|
||||
/workspace.xml
|
|
@ -47,6 +47,8 @@ $relativePath = "../";
|
|||
Action des webmasters
|
||||
</h4>
|
||||
<a href="map.php">Editer le texte de la carte</a>
|
||||
<br/>
|
||||
<a href="update.php">Mises à jour</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
61
admin/update.php
Normal file
61
admin/update.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
ob_start(); // Start reading html
|
||||
$relativePath = "../";
|
||||
require_once $relativePath . 'classes/dao.php';
|
||||
|
||||
$statut = shell_exec("git status");
|
||||
$canUpdate = strpos($statut, 'Your branch is up to date') === false;
|
||||
?>
|
||||
<div class="inner">
|
||||
<h1>ADMIN</h1>
|
||||
<h2>Mise a jour du site</h2>
|
||||
|
||||
<?php if ($canUpdate): ?>
|
||||
<p id="UpdateNeeded">Une mise à jour est disponible</p>
|
||||
<!-- <label for="usernameInput">Login</label>-->
|
||||
<!-- <input type="text" id="usernameInput">-->
|
||||
<!---->
|
||||
<!-- <label for="passwordInput">Password</label>-->
|
||||
<!-- <input type="password" id="passwordInput">-->
|
||||
<!---->
|
||||
<!-- <div class="save">-->
|
||||
<!-- <i class="fas fa-save"></i> Mettre à Jour-->
|
||||
<!-- </div>-->
|
||||
<?php else: ?>
|
||||
<p id="noUpdateNeeded">Aucune mise à jour disponible</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<div id="gitButton">
|
||||
<a href="https://git.srv-falcon.etud.insa-toulouse.fr/vergnet/site-accueil-insa" target="_blank">
|
||||
Voir sur Gitea
|
||||
</a>
|
||||
</div>
|
||||
<h3>Statut</h3>
|
||||
<p>
|
||||
<?php
|
||||
echo nl2br($statut)
|
||||
?>
|
||||
</p>
|
||||
|
||||
<div class="buttons-container">
|
||||
<a href="index.php" class="admin-back-button">
|
||||
Retour sur la page admin
|
||||
</a>
|
||||
<a href="<?= $relativePath ?>index.php" class="website-back-button">
|
||||
Retour sur le site
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<link rel="stylesheet" type="text/css" media="screen" href="<?= $relativePath ?>assets/css/adminEdit.css"/>
|
||||
|
||||
<?php
|
||||
$pageContent = ob_get_clean(); // Store html content in variable
|
||||
$pageTitle = "Mise à jour";
|
||||
|
||||
$pageScripts = "<script type=\"text/javascript\" src=\"../assets/js/updateManager.js\"></script>";
|
||||
|
||||
include($relativePath . "includes/template.php"); // Display template with variable content
|
||||
|
||||
?>
|
|
@ -1,10 +1,15 @@
|
|||
<?php
|
||||
require_once '../../classes/dao.php';
|
||||
|
||||
$rest_json = file_get_contents("php://input");
|
||||
$_POST = json_decode($rest_json, true);
|
||||
//var_dump($_POST);
|
||||
|
||||
if (isset($_GET['function'])) {
|
||||
if (isset($_GET['function']) || isset($_POST['function'])) {
|
||||
if ($_GET['function'] == "save_map_info")
|
||||
save_map_info();
|
||||
elseif ($_POST['function'] == "update_website")
|
||||
update_website();
|
||||
} else
|
||||
show_error();
|
||||
|
||||
|
@ -18,7 +23,25 @@ function save_map_info() {
|
|||
}
|
||||
}
|
||||
|
||||
function show_error() {
|
||||
echo "Échec : ";
|
||||
var_dump($_GET);
|
||||
function update_website() {
|
||||
// if (isset($_POST['login']) && isset($_POST['password'])) {
|
||||
// $login = $_POST['login'];
|
||||
// $password = $_POST['password'];
|
||||
// echo $login . ":" . $password."\n";
|
||||
// // Cannot write because php cannot write as user www-data
|
||||
// // be sure to escape characters
|
||||
// // Do not remove the space before the command (prevent command from being saved in history)
|
||||
//// system(" git pull https://".$login.":".$password."@git.srv-falcon.etud.insa-toulouse.fr/vergnet/site-accueil-insa.git");
|
||||
// } else {
|
||||
// show_error();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
function show_error() {
|
||||
echo "Échec :\n";
|
||||
echo "GET\n";
|
||||
var_dump($_GET);
|
||||
echo "POST\n";
|
||||
var_dump($_POST);
|
||||
}
|
||||
|
|
|
@ -191,3 +191,30 @@ input, textarea {
|
|||
.planning-trash {
|
||||
width: 10%;
|
||||
}
|
||||
|
||||
#noUpdateNeeded {
|
||||
font-size: 2rem;
|
||||
color: #2ce20b;
|
||||
}
|
||||
|
||||
#UpdateNeeded {
|
||||
font-size: 2rem;
|
||||
color: #c53422;
|
||||
}
|
||||
|
||||
#gitButton {
|
||||
font-size: 1.5rem;
|
||||
display: flex;
|
||||
margin: 20px;
|
||||
}
|
||||
|
||||
|
||||
#gitButton a {
|
||||
padding: 10px;
|
||||
background-color: white;
|
||||
color: #052700;
|
||||
margin: auto;
|
||||
width: 200px;
|
||||
cursor: pointer;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
|
26
assets/js/updateManager.js
Normal file
26
assets/js/updateManager.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
$(document).ready(function () {
|
||||
$(".save").click(function () {
|
||||
sendLogin($('#usernameInput').val(), $('#passwordInput').val());
|
||||
});
|
||||
});
|
||||
|
||||
function sendLogin(login, password) {
|
||||
let object = {
|
||||
"function": 'update_website',
|
||||
"login": login,
|
||||
"password": password,
|
||||
};
|
||||
console.log(JSON.stringify(object));
|
||||
// Do not put .php in the url, otherwise the POST request will transformed in GET when server rewrites the url
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../ajax/write/master",
|
||||
data: JSON.stringify(object),
|
||||
dataType: "json",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
complete: function (data) {
|
||||
alert(data.responseText);
|
||||
console.log(data);
|
||||
},
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue