flux/buidIncron.php

132 lines
4.0 KiB
PHP
Raw Permalink Normal View History

<?php
2015-10-13 11:41:19 +02:00
// --- Define path to application directory
defined('APPLICATION_PATH')
2015-10-13 11:41:19 +02:00
|| define('APPLICATION_PATH', realpath(__DIR__ . '/../../application'));
2015-10-13 11:41:19 +02:00
// --- Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
2015-10-13 11:41:19 +02:00
// --- Composer autoload
2017-03-02 14:17:33 +01:00
require_once realpath(__DIR__ . '/vendor/autoload.php');
2015-10-13 11:41:19 +02:00
// --- Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$application->bootstrap()->run();
2017-03-02 14:17:33 +01:00
// --- Options
$displayUsage = false;
try {
2017-03-02 14:17:33 +01:00
$opts = new Zend_Console_Getopt(array(
'help|?' => "Display usage information.",
'list' => "List client and prestations.",
'generate' => "Generate",
'send=s' => "Generate send incron file [client]/[name]",
'read=s' => "Generate read incron file [client]/[name]",
));
$opts->parse();
2017-03-02 14:17:33 +01:00
$optsNb = $opts->getOptions();
} catch (Zend_Console_Getopt_Exception $e) {
2017-03-02 14:17:33 +01:00
$displayUsage = true;
}
2017-03-02 14:17:33 +01:00
// --- Aide / Options
if ($optsNb == 0 || isset($opts->help)) {
$displayUsage = true;
}
// --- Usage
if ($displayUsage) {
echo $opts->getUsageMessage();
exit;
}
2017-03-02 14:37:05 +01:00
$logPath = realpath(__DIR__ . '/../shared');
2016-06-17 11:08:25 +02:00
$prestations = include APPLICATION_PATH . '/../config.php';
if ($opts->list)
{
if (count($prestations)>0)
{
foreach ($prestations as $client => $params)
{
echo "Client : ".$client."\n";
foreach ($params['prestations'] as $i => $item)
{
echo " ";
echo $item['name'] . " : ".$item['type'];
if (array_key_exists('directory', $item)) {
echo " - " .$item['directory'];
}
echo "\n";
}
echo "\n";
}
}
}
if ($opts->generate)
{
echo "Generate.\n";
2015-03-31 08:47:55 +02:00
if ($opts->send) {
2015-10-13 11:41:19 +02:00
2015-03-31 08:47:55 +02:00
$input = explode('/', $opts->send);
$client = $input[0];
$name = $input[1];
if (array_key_exists($client, $prestations))
{
2015-03-31 08:47:55 +02:00
foreach ($prestations[$client]['prestations'] as $item)
{
2015-03-31 08:47:55 +02:00
if ($item['name'] == $name)
{
2015-03-31 08:47:55 +02:00
$directory = 'send';
if (array_key_exists('directory', $item))
{
$directory = $item['directory'];
}
$fluxBasePath = '/home/data/' . strtolower($item['type']) . '/' . $client . '/' . $directory;
$file = __DIR__ . '/incron.d/' . strtolower($item['type']) . '_' . $client;
2017-03-02 14:37:05 +01:00
file_put_contents($file, "$fluxBasePath IN_CLOSE_WRITE php /home/flux/current/send.php --file $@/$# >> $logPath/send.log 2>&1");
2015-03-31 08:47:55 +02:00
echo "File created $file\n";
}
}
}
2015-03-31 08:47:55 +02:00
}
2015-10-13 11:41:19 +02:00
2015-03-31 08:47:55 +02:00
if ($opts->read) {
2015-10-13 11:41:19 +02:00
2015-03-31 08:47:55 +02:00
$input = explode('/', $opts->read);
$client = $input[0];
$name = $input[1];
if (array_key_exists($client, $prestations))
{
foreach ($prestations[$client]['prestations'] as $item)
{
if ($item['name'] == $name)
{
$directory = 'recv';
if (array_key_exists('directory', $item))
{
$directory = $item['directory'];
}
$fluxBasePath = '/home/data/' . strtolower($item['type']) . '/' . $client. '/' . $directory;
$file = __DIR__ . '/incron.d/' . strtolower($item['type']) . '_' . $client . '_recv';
2017-03-02 14:37:05 +01:00
file_put_contents($file, "$fluxBasePath IN_ACCESS php /home/flux/current/read.php --file $@/$# >> $logPath/read.log 2>&1");
2015-03-31 08:47:55 +02:00
echo "File created $file\n";
}
}
}
2015-10-13 11:41:19 +02:00
2015-03-31 08:47:55 +02:00
}
2015-10-13 11:41:19 +02:00
echo "Put the file to /etc/incron.d and restart incron.\n";
echo "Generate Ended.\n";
2015-10-13 11:41:19 +02:00
}