Commit 49c5fcb5 authored by VINOT Gaël's avatar VINOT Gaël

script de paramétrage automatisé du portail bokeh

parent c5eac386
......@@ -18,7 +18,12 @@
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
//vérification du paramétrage Bokeh
if (!file_exists('local.php') || !file_exists('config.ini') || !file_exists('cosmogramme/config.php')) {
if (file_exists('scripts/install-bokeh.php')) {
include('scripts/install-bokeh.php');
}
}
require('includes.php');
try {
......
<?php
function clean($in,$wa=0) {
//return preg_replace('@[^a-zA-Z0-9_\-\.]@','',$in);
$accents = 'éèêëÊËàâäÂÄîïÎÏûùüÛÜôöÔÖ';
return preg_replace('#[^a-zA-Z0-9_\-\.\ @'.(($wa==1)?$accents:'').']#','',$in);
}
function extractSqlInstructions($data) {
$instructions = [];
$instruction = '';
foreach($data as $ligne) {
$ligne = trim($ligne);
if (!$ligne or substr($ligne,0,2) == '--')
continue;
$instruction .= $ligne . ' ';
if(substr($ligne,-1) != ';')
continue;
$instructions[] = $instruction;
$instruction = '';
}
return $instructions;
}
//install bokeh php - variables defaut
$vars = array('user' => 'Nom Utilisateur', 'pass' => 'Mot de passe', 'name' => 'Base de donnée', 'host' => 'Adresse');
$db['user'] = 'root';
$db['pass'] = '';
$db['name'] = 'opacce';
$db['host'] = 'localhost';
//$path = './';
$path = "";
$db['init'] = $path.'scripts/opac2.sql';
$db['MAJ_Url'] = '/database-migration/migrate';
$db['install-bokeh'] = false;
$form_data = "Bokeh n'est pas configuré sur votre environnement<br/>\n";
$form_data .= "Veuillez modifier les paramètres suivant selon vos besoin et Valider pour lancer le paramétrage<br/>\n";
$form_data .= '<br/>';
foreach ($vars as $k => $v) {
if ($k == 'pass') {
$db[$k] = (!empty($_POST[$k]))?clean($_POST[$k],1):$db[$k];
}
else {
$db[$k] = (!empty($_POST[$k]))?clean($_POST[$k]):$db[$k];
}
$form_data .= "<label for='".$k."'>".$v."</label><input id='".$k."' name='".$k."' value='".$db[$k]."'><br/>\n";
}
$k = 'install-bokeh';
$form_data .= '<br/>';
$form_data .= "<input id='".$k."' name='".$k."' value='".$k."' type='checkbox'> <label for='".$k."'>Je souhaite Paramétrer Bokeh</label><br/>";
$form_data .= '<br/>';
$form_data .= "<input type='submit' value='Valider'>";
$db[$k] = (!empty($_POST[$k]))?clean($_POST[$k]):$db[$k];
$db[$k] = ($db[$k] == $k);
//préparation des fichiers de configuration
$config_files = array(
$path.'local.php' => '',
$path.'config.ini' => '[global]
timeZone = Europe/Paris
; SMTP
; mail.transport.smtp.host =
; Used by global http client
proxy.host =
proxy.port =
proxy.user =
proxy.pass =
; SGBD
sgbd.adapter = mysqli
sgbd.config.host = '.$db['host'].'
sgbd.config.port = 3306
sgbd.config.username = '.$db['user'].'
sgbd.config.password = '.$db['pass'].'
sgbd.config.dbname = '.$db['name'].'
; Advanced
amber.deploy = 0
experimental_dev = true
[local : global]
[production : global]
',
$path.'cosmogramme/config.php' => '<?php
print("<center>");
print("<br><br><br><br><br>");
print("<div style=\"font-family:Verdana;font-size:20pt;color:red;font-weight:bold;\">Accès interdit</div>");
exit;
?>
// BASE INTEGRATION
integration_server='.$db['host'].'
integration_user='.$db['user'].'
integration_pwd=
integration_base='.$db['name'].'
pwd_master=opacce
// BASE OPAC3
');
$logs = '';
$compl_data = '';
if ($db['install-bokeh'] == true) {
//on commence par tester la connexion à la base de données
//si la connexion est impossible on s'arrête la
$opac = mysqli_init();
$opac->real_connect($db['host'], $db['user'] , $db['pass']);
if ($opac->connect_errno) {
$logs = "Problème de connexion au serveur base de donnée : Erreur MySQL : ".$opac->connect_errno." )<br />".$opac->connect_error;
}
else {
$opac->query('SET NAMES utf8');
$opac->query("SET CHARACTER SET 'utf8'");
//création des fichiers de configuration
foreach ($config_files as $fichier => $donnees) {
if (!file_exists($fichier)) {
file_put_contents($fichier,$donnees);
$logs .= 'Installation de '.$fichier."\n";
}
else $logs .= ''.$fichier." existe déjà\n";
}
//création de la base de donnée BOKEH
$sql = 'CREATE DATABASE IF NOT EXISTS `'.$db['name'].'` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;';
$opac->query($sql);
$sql = 'USE `'.$db['name'].'`;';
$opac->query($sql);
//vérification d'état du paramétrage de la base
$tabletest = 'variables';
$sql = 'select * from '.$tabletest;
$opac->query($sql);
$check = $opac->error;
if ($check == "Table '".$db['name'].".".$tabletest."' doesn't exist") {
$logs .= 'Paramétrage de la base de donnée'."\n";
//on lance l'initialisation de la base
$data = file($db['init']);
//merci Class_Migration_Patchs
$instructions = extractSqlInstructions($data);
foreach($instructions as $sql) {
$opac->query($sql);
if (!empty($opac->error)) $logs .= "Erreur MySQL : ".$opac->error." <br />";
}
}
else $logs .= 'base de donnée déjà paramétrée';
//on renvoi le lien permettant la mise a jour de la base
//$form_data = "Bokeh est désormais paramétré<br/>\n";
$form_data = "";
$logs .= "<div id='majdb'><img src='/public/opac/images/patience.gif'/>Mise à jour de la base en cours - veuillez patienter\n</div>";
$logs .= "<div id='majdbdone' class='masquee'>Mise à jour de la base terminée\n<a href='/admin/'>Accèder a l'administration</a>\n<a href='/cosmogramme/'>Accèder au cosmogramme</a>\nidentification : admin / achanger</div>";
$logs .="<iframe class='masquee' src='".$db['MAJ_Url']."' onload=\"$('#majdb')[0].setAttribute('class','masquee');$('#majdbdone')[0].setAttribute('class','');\"></iframe>";
}
$compl_data = '<pre>'.$logs.'</pre>';
}
?><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title></title>
<style type="text/css">
body {
font-family: arial; font-size: 12;
}
table {
border:2px solid;
-moz-border-radius:5px;
-khtml-border-radius:5px;
border-radius:5px;
/* border-collapse:collapse; */
border-spacing: 0;
}
th { border-bottom:solid 2px; }
th { padding: 2 5 2 5; text-align:center; border-top:solid 1px; border-left:solid 1px; border-bottom:solid 1px; border-right:solid 1px; vertical-align:middle;}
.bbottom {}
th { padding: 2 5 2 5; text-align:center; border:solid 2px; vertical-align:middle; }
td { padding: 2 5 2 5; text-align:center; border-top:solid 1px; border-left:solid 1px; border-bottom:solid 1px; border-right:solid 1px; vertical-align:top;}
td { padding: 2 5 2 5; border-top:solid 1px; border-left:solid 1px; border-bottom:solid 1px; border-right:solid 1px; vertical-align:top;}
.left { text-align:left; }
label { min-width: 100px; display: inline-block; margin-right: 5px; }
.masquee { display:none;}
</style>
<script src="/public/admin/js/jquery-1.8.3.js" type="text/javascript"></script>
<script src="/public/admin/js/jquery_ui/jquery-ui-1.10.3.full.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
//-->
</script>
</head>
<body>
<form id=form method=POST><?php echo $form_data; ?></form>
<?php echo $compl_data; ?>
</body>
</html><?php exit; ?>
\ 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