2011-11-08 15:08:29 +01:00
|
|
|
<?php
|
|
|
|
Class configure
|
|
|
|
{
|
|
|
|
protected $dirname;
|
|
|
|
protected $sphinx;
|
|
|
|
protected $hostname;
|
|
|
|
|
|
|
|
protected $sql;
|
|
|
|
protected $indexes;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->hostname = exec('echo $(hostname)');
|
|
|
|
$this->sphinx = 'sphinx.conf';
|
|
|
|
$this->dirname = 'config/'.$this->hostname.'/';
|
|
|
|
(file_exists($this->sphinx))?unlink($this->sphinx):'';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function printIndexes($nbServer)
|
|
|
|
{
|
|
|
|
$dir = opendir($this->dirname.$this->sql[$nbServer].'/');
|
|
|
|
$i = 1;
|
|
|
|
|
|
|
|
while($file = readdir($dir)) {
|
2011-11-16 14:47:57 +01:00
|
|
|
$extension = explode('.', $file);
|
|
|
|
if($file != '.' and $file != '..' and $extension[1] == 'conf') {
|
2011-11-08 15:08:29 +01:00
|
|
|
echo "\t\t".'['.$i.'] '. $file."\n";
|
|
|
|
$this->indexes[$i] = $file;$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(count($this->indexes) == 0) {
|
|
|
|
echo "\tAucun indexes dans le repertoire : '".$this->dirname.$this->sql[$nbServer]."' \n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function printMysqlServer()
|
|
|
|
{
|
2011-11-16 14:47:57 +01:00
|
|
|
$dir = opendir($this->dirname);
|
2011-11-08 15:08:29 +01:00
|
|
|
$i = 1;
|
|
|
|
|
|
|
|
while($rep = readdir($dir)) {
|
|
|
|
if($rep != '.' and $rep != '..' and is_dir($this->dirname.$rep)) {
|
|
|
|
echo "\t".'['.$i.'] '.$rep."\n";
|
|
|
|
$this->sql[$i] = $rep;
|
|
|
|
$this->printIndexes($i);
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(count($this->sql) == 0) {
|
|
|
|
echo "\tAucun serveurs dans le repertoire : '".$this->dirname."' \n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createConfig($mySqlServer, $index)
|
|
|
|
{
|
|
|
|
$dirname = $this->dirname.$mySqlServer.'/';
|
|
|
|
$dir = opendir($dirname);
|
|
|
|
|
|
|
|
if(file_exists($dirname.$index)) {
|
|
|
|
file_put_contents($this->sphinx, file_get_contents($dirname.$index), FILE_APPEND);
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function inviteDeCommande()
|
|
|
|
{
|
|
|
|
$handle = fopen('.', 'r');
|
|
|
|
$server = '';
|
|
|
|
|
|
|
|
fwrite(STDOUT, "\n - Serveurs SQL disponnible :\n");
|
|
|
|
$this->printMysqlServer();
|
|
|
|
while($server != "exit\n") {
|
|
|
|
echo "Selectionnez Server et Indexe : ";
|
|
|
|
$server = fgets(STDIN);
|
|
|
|
$indexes = explode(' ', $server);
|
|
|
|
if(isset($this->sql[intval($indexes[0])]) and isset($this->indexes[intval($indexes[1])])) {
|
|
|
|
$this->createConfig($this->sql[intval($indexes[0])], $this->indexes[intval($indexes[1])]);
|
|
|
|
echo 'Indexe ajouté !'."\n";
|
|
|
|
} else
|
|
|
|
echo 'Cet indexe n\'existe pas !'."\n";
|
|
|
|
}
|
|
|
|
file_put_contents($this->sphinx, file_get_contents($this->dirname.$this->sphinx), FILE_APPEND);
|
|
|
|
exec('sudo mv '.$this->sphinx.' /usr/local/sphinx/etc/'.$this->sphinx);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = new configure();
|
|
|
|
$a->inviteDeCommande();
|