Commit f5e7c48b authored by Feu's avatar Feu
Browse files

outils d'admin

parent a32473d6
......@@ -124,7 +124,7 @@ class aecms extends site
$this->set_side_boxes("left",array());
$this->set_side_boxes("right",array());
if ( file_exists(CMS_CONFIGFILE) && !isset($GET["aecms_admin_ignoreconf"]) )
if ( file_exists(CMS_CONFIGFILE) && !isset($_GET["aecms_admin_ignoreconf"]) )
include(CMS_CONFIGFILE);
if ($this->is_user_admin())
......
<?php
/* Copyright 2006
/* Copyright 2006,2007
* - Julien Etelain < julien at pmad dot net >
*
* Ce fichier fait partie du site de l'Association des Étudiants de
......
......@@ -32,7 +32,7 @@
officiel */
if( !preg_match('/^\/var\/www\/ae\/www\/(taiste|taiste21|ae2)\//', $_SERVER['SCRIPT_FILENAME'])
&& !ereg("^/var/www/ae/accounts/([a-z]*)/aecms",$_SERVER['SCRIPT_FILENAME']) )
&& !ereg("^/var/www/ae/accounts/([a-z0-9]*)/aecms",$_SERVER['SCRIPT_FILENAME']) )
{
/* On est peut_etre dans le cas d'une utilisation "home" */
if (file_exists($topdir . "include/mysqlae_home.inc.php"))
......
<?php
/* Copyright 2007
* - Julien Etelain < julien at pmad dot net >
*
* Ce fichier fait partie du site de l'Association des Étudiants de
* l'UTBM, http://ae.utbm.fr.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
$topdir="../";
require_once($topdir. "include/site.inc.php");
require_once($topdir."include/cts/sqltable.inc.php");
$site = new site ();
if ( !$site->user->is_in_group("root") )
error_403();
if( !preg_match('/^\/var\/www\/ae\/www\/ae2\//', $_SERVER['SCRIPT_FILENAME']) )
$aecms_home = "/var/www/ae/www/taiste/aecms";
else
$aecms_home = "/var/www/ae/www/ae2/aecms";
define("AECMS_ACCOUNTS","/var/www/ae/accounts/");
function list_aecms ()
{
$list = array();
if ($dh = opendir(AECMS_ACCOUNTS))
{ while (($file = readdir($dh)) !== false)
{
if ( is_dir(AECMS_ACCOUNTS.$file) && file_exists(AECMS_ACCOUNTS.$file."/specific/aecms.conf.php") )
{
$data = file_get_contents(AECMS_ACCOUNTS.$file."/specific/aecms.conf.php");
if ( ereg("define\\(\"CMS_ID_ASSO\",([0-9]+)\\)",$data,$regs) )
{
$list[] = array("unixname"=>$file,"id_asso"=>$regs[1], "aecms"=>readlink(AECMS_ACCOUNTS.$file."/aecms") );
}
}
} closedir($dh); }
return $list;
}
function list_noaecms ()
{
$list = array();
if ($dh = opendir(AECMS_ACCOUNTS))
{ while (($file = readdir($dh)) !== false)
{
if ( is_dir(AECMS_ACCOUNTS.$file) && !file_exists(AECMS_ACCOUNTS.$file."/specific/aecms.conf.php") )
$list[] = $file;
} closedir($dh); }
return $list;
}
function install_aecms ( $unixname, $id_asso )
{
if ( !ereg("^([a-z0-9])$", $unixname) )
return false;
return _install_aecms(AECMS_ACCOUNTS.$unixname."/",$id_asso);
}
function _install_aecms ( $target, $id_asso )
{
global $aecms_home;
if ( !is_dir($target) )
if ( !mkdir($target) )
return false;
if ( substr($target,-1) != "/" )
$target = $target."/";
if ( !is_dir($target."specific") )
if ( !mkdir($target."specific") )
return false;
$aecmsConfPhp='<?php
define("CMS_ID_ASSO",'.$id_asso.');
define("CMS_PREFIX","cms:".CMS_ID_ASSO.":");
?>';
if ( !file_put_contents($target."specific/aecms.conf.php",$aecmsConfPhp) )
return false;
if ( !file_put_contents($target."specific/custom.css","/* a personaliser */") )
return false;
if ( is_link($target."aecms") )
if ( !unlink($target."aecms") )
return false;
if ( !symlink($aecms_home,$target."aecms") )
return false;
$apacheRules='RewriteEngine On
RewriteRule ^([a-z]*)\.php(.*)$ aecms/$1.php$2 [L]
RewriteRule ^$ aecms/index.php [L]
RewriteRule ^images/(.*)$ aecms/images/$1 [L]
RewriteRule ^css/(.*)$ aecms/css/$1 [L]
';
if ( !file_put_contents($target.".htaccess",$apacheRules) )
return false;
return true;
}
function raz_aecms ( $id_asso )
{
$file = $topdir."var/aecms/cms".$id_asso.".conf.php";
return unlink($file);
}
$site->start_page("none","Administration");
$list = list_aecms();
$cts = new contents("AECMS");
$cts->add(new sqltable(
"aecms",
"", $list, "aecms.php",
"type",
array("unixname"=>"Nom","aecms"=>"AECMS installé"),
array(),
array(),
array()
));
$site->add_contents($cts);
//TODO
$site->end_page();
?>
\ No newline at end of file
<?php
/* Copyright 2007
* - Julien Etelain < julien at pmad dot net >
*
* Ce fichier fait partie du site de l'Association des Étudiants de
* l'UTBM, http://ae.utbm.fr.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
$topdir="../";
require_once($topdir. "include/site.inc.php");
$site = new site ();
if ( !$site->user->is_in_group("root") )
error_403();
$site->start_page("none","Administration");
$cts = new contents("Administration");
$cts->add_paragraph("Révision en production : ".get_rev());
$cts->add_title(2,"AECMS");
$lst = new itemlist();
$lst->add("<a href=\"aecms.php\">Liste des AECMS</a>");
$lst->add("<a href=\"aecms.php?page=raz\">RAZ d'un AECMS</a> (remet les paramètres aux valeurs par défaut)");
$lst->add("<a href=\"aecms.php?page=install\">Installation d'un AECMS</a> (ou re-installation)");
$cts->add($lst);
$cts->add_title(2,"Maintenance");
$lst = new itemlist();
$lst->add("<a href=\"pollcoti.php\">Expiration des cotisations</a>");
$lst->add("<a href=\"repairdb.php\">Auto-Reparation de la base de données</a>");
$cts->add($lst);
$site->add_contents($cts);
$site->end_page();
?>
\ No newline at end of file
......@@ -26,18 +26,33 @@ require_once($topdir. "include/site.inc.php");
$site = new site ();
if ( !$site->user->is_in_group("root") )
error_403();
$site->start_page("none","Administration");
$cts = new contents("<a href=\"./\">Administration</a> / Maintenance / Auto-Reparation de la base de données");
$req = new requete($site->dbrw,"UPDATE `ae_carte` SET `etat_vie_carte_ae`='".CETAT_EXPIRE."' " .
"WHERE `date_expiration` <= NOW() AND `etat_vie_carte_ae`<".CETAT_EXPIRE."");
$cts->add_paragraph($req->lines." cartes ont expirées");
$req = new requete($site->dbrw,"UPDATE `utilisateurs` SET `ae_utl`='1' " .
"WHERE `ae_utl`='0' AND EXISTS(SELECT * FROM `ae_cotisations` " .
"WHERE `ae_cotisations`.`id_utilisateur`=`utilisateurs`.`id_utilisateur` " .
"AND `date_fin_cotis` > NOW())");
$cts->add_paragraph($req->lines." utilisateurs de plus sont désormais cotisants");
$req = new requete($site->dbrw,"UPDATE `utilisateurs` SET `ae_utl`='0' " .
"WHERE `ae_utl`='1' AND NOT EXISTS(SELECT * FROM `ae_cotisations` " .
"WHERE `ae_cotisations`.`id_utilisateur`=`utilisateurs`.`id_utilisateur` " .
"AND `date_fin_cotis` > NOW())");
$cts->add_paragraph($req->lines." utilisateurs ne sont plus cotisants");
$site->add_contents($cts);
$site->end_page();
?>
?>
\ No newline at end of file
......@@ -32,54 +32,56 @@ require_once($topdir. "include/entities/asso.inc.php");
$site = new site ();
header("Content-Type: text/html; charset=utf-8");
if ( !$site->user->is_in_group("root") )
error_403();
echo "<h1>AE2: Auto repair</h1>";
$site->start_page("none","Administration");
echo "<ul>";
$cts = new contents("<a href=\"./\">Administration</a> / Maintenance / Auto-Reparation de la base de données");
$lst = new itemlist();
// Supprime les cotisations rattchés à des utilisateurs qui n'existent pas
echo "<li><b>Check cotisations users</b></li>";
$lst->add("<b>Check cotisations users</b>");
$sql = new requete($site->db,"SELECT id_cotisation FROM ae_cotisations LEFT JOIN utilisateurs USING(`id_utilisateur`) WHERE utilisateurs.id_utilisateur IS NULL");
while ( list($id_cotisation) = $sql->get_row() )
{
$rem = new delete($site->dbrw,"ae_cotisations",array("id_cotisation"=>$id_cotisation));
echo "<li>Missing user: Cotisation $id_cotisation removed.</li>";
}
// Supprime les cartes AE rattachés à une cotisation qui n'existe pas
echo "<li><b>Check cards cotisations</b></li>";
$sql = new requete($site->db,"SELECT id_carte_ae FROM ae_carte LEFT JOIN ae_cotisations USING(`id_cotisation`) WHERE ae_cotisations.id_cotisation IS NULL");
while ( list($id_carte_ae) = $sql->get_row() )
{
$rem = new delete($site->dbrw,"ae_carte",array("id_carte_ae"=>$id_carte_ae));
echo "<li>Missing cotisation: Card $id_carte_ae removed.</li>";
$lst->add("Missing user: Cotisation $id_cotisation removed.");
}
// Ajoute les carte AE aux cotisations qui n'ont on pas
echo "<li><b>Check cotisations cards</b></li>";
$lst->add("<b>Check cotisations cards</b>");
$sql = new requete($site->db,"SELECT ae_cotisations.* FROM ae_cotisations LEFT JOIN ae_carte USING(`id_cotisation`) WHERE ae_carte.id_cotisation IS NULL AND date_fin_cotis > NOW()");
$cotiz = new cotisation($site->db,$site->dbrw);
while ( $row = $sql->get_row() )
{
$cotiz->_load($row);
$cotiz->generate_card();
echo "<li>Missing card for valid cotisation ".$cotiz->id." (user ".$cotiz->id_utilisateur.") : A card added.</li>";
$lst->add("Missing card for valid cotisation ".$cotiz->id." (user ".$cotiz->id_utilisateur.") : A card added.");
}
// Supprime les cartes AE rattachés à une cotisation qui n'existe pas
$lst->add("<b>Check cards cotisations</b>");
$sql = new requete($site->db,"SELECT id_carte_ae FROM ae_carte LEFT JOIN ae_cotisations USING(`id_cotisation`) WHERE ae_cotisations.id_cotisation IS NULL");
while ( list($id_carte_ae) = $sql->get_row() )
{
$rem = new delete($site->dbrw,"ae_carte",array("id_carte_ae"=>$id_carte_ae));
$lst->add("Missing cotisation: Card $id_carte_ae removed.");
}
// Supprime les alias utilisés par plusieurs utilisateurs
echo "<li><b>Check aliases unicity</b></li>";
$lst->add("<b>Check aliases unicity</b>");
$sql = new requete($site->db,"SELECT COUNT(*),alias_utl FROM `utilisateurs` WHERE alias_utl IS NOT NULL GROUP BY alias_utl HAVING COUNT(*) > 1");
$aliases=array();
while ( $row = $sql->get_row() )
{
echo "<li>Alias ".$row[1]." used by ".$row[0]." users : Set to NULL.</li>";
$lst->add("Alias ".$row[1]." used by ".$row[0]." users : Set to NULL.");
new requete($site->dbrw,"UPDATE `utilisateurs` SET alias_utl=NULL WHERE alias_utl='".mysql_real_escape_string($row[1])."'");
}
// Génére un alias aux utilisateurs du forum
echo "<li><b>Check forum users aliases</b></li>";
$lst->add("<b>Check forum users aliases</b>");
$sql = new requete($site->db,"SELECT utilisateurs.id_utilisateur,email_utbm,nom_utl,prenom_utl,email_utl ".
"FROM `utilisateurs` ".
"JOIN frm_message ON (frm_message.id_utilisateur=utilisateurs.id_utilisateur) ".
......@@ -138,7 +140,7 @@ while ( $row = $sql->get_row() )
}
}
echo "<li>Alias for ".$row["prenom_utl"]." ".$row["nom_utl"]." (".$row["id_utilisateur"].") : $alias</li>";
$lst->add("Alias for ".$row["prenom_utl"]." ".$row["nom_utl"]." (".$row["id_utilisateur"].") : $alias");
new update($site->dbrw,
"utilisateurs",
......@@ -146,7 +148,7 @@ while ( $row = $sql->get_row() )
array('id_utilisateur' => $row["id_utilisateur"]));
}
echo "<li><b>Check folder names (nulls)</b></li>";
$lst->add("<b>Check folder names (nulls)</b>");
$sql = new requete($site->db,"SELECT * FROM `d_folder` WHERE nom_fichier_folder IS NULL");
......@@ -156,11 +158,11 @@ while ( $row = $sql->get_row() )
{
$folder->_load($row);
$folder->update_folder ( $folder->titre, $folder->description, $folder->id_asso );
echo "<li>Folder #".$folder->id." is now named ".$folder->nom_fichier."</li>";
$lst->add("Folder #".$folder->id." is now named ".$folder->nom_fichier."");
}
echo "<li><b>Check files names (unicity)</b></li>";
$lst->add("<b>Check files names (unicity)</b>");
$file=new dfile($site->db,$site->dbrw);
......@@ -178,9 +180,12 @@ while ( $row = $sql->get_row() )
array("nom_fichier_file"=>$file->nom_fichier),
array("id_file"=>$file->id)
);
echo "<li>File #".$file->id." is now named ".$file->nom_fichier."</li>";
$lst->add("File #".$file->id." is now named ".$file->nom_fichier."");
}
}
echo "</ul>";
$cts->add($lst);
$site->add_contents($cts);
$site->end_page();
?>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment