Compare commits
29 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
91da2b3658 | ||
|
1b851647c3 | ||
|
01ed73488c | ||
|
7fd3c5df51 | ||
|
6e646e364e | ||
|
01c88b1963 | ||
|
769778cfc3 | ||
|
3d20d60687 | ||
|
7d3f435f2a | ||
|
7751aa504a | ||
|
77fcfa4a9d | ||
|
0271f2e27c | ||
|
1d4a18065b | ||
|
da3836d96e | ||
|
2d1c282af5 | ||
|
9cc6a9af4f | ||
|
3aa3c01931 | ||
|
409758e4f5 | ||
|
7ea58800b4 | ||
|
756c1b68af | ||
|
81f19f3ad3 | ||
|
c41bb05a8b | ||
|
c47069460b | ||
|
bd96303de4 | ||
|
b525a49f5b | ||
|
86cf862fc2 | ||
|
6a4e805282 | ||
|
19b6bf6fd9 | ||
|
85fcc8eaa5 |
134
README
Normal file
134
README
Normal file
@ -0,0 +1,134 @@
|
||||
Mise à disposition fichier de télétransmission
|
||||
----------------------------------------------
|
||||
|
||||
Utilisation des événements INOTIFY pour la surveillance des dossiers
|
||||
|
||||
The command may contain these wildcards:
|
||||
|
||||
$$ - a dollar sign
|
||||
$@ - the watched filesystem path (see above)
|
||||
$# - the event-related file name
|
||||
$% - the event flags (textually)
|
||||
$& - the event flags (numerically)
|
||||
|
||||
Events
|
||||
|
||||
IN_ACCESS
|
||||
File was accessed (read) (*).
|
||||
|
||||
IN_ATTRIB
|
||||
Metadata changed, e.g., permissions, timestamps, extended attributes, link count (since Linux 2.6.25), UID, GID, etc. (*).
|
||||
|
||||
IN_CLOSE_WRITE
|
||||
File opened for writing was closed (*).
|
||||
|
||||
IN_CLOSE_NOWRITE
|
||||
File not opened for writing was closed (*).
|
||||
|
||||
IN_CREATE
|
||||
File/directory created in watched directory (*).
|
||||
|
||||
IN_DELETE
|
||||
File/directory deleted from watched directory (*).
|
||||
|
||||
IN_DELETE_SELF
|
||||
Watched file/directory was itself deleted.
|
||||
|
||||
IN_MODIFY
|
||||
File was modified (*).
|
||||
|
||||
IN_MOVE_SELF
|
||||
Watched file/directory was itself moved.
|
||||
|
||||
IN_MOVED_FROM
|
||||
File moved out of watched directory (*).
|
||||
|
||||
IN_MOVED_TO
|
||||
File moved into watched directory (*).
|
||||
|
||||
IN_OPEN
|
||||
File was opened (*).
|
||||
When monitoring a directory, the events marked with an asterisk (*) above can occur for files in the directory,
|
||||
in which case the name field in the returned inotify_event structure identifies the name of the file within the
|
||||
directory.
|
||||
|
||||
The IN_ALL_EVENTS macro is defined as a bit mask of all of the above events. This macro can be used as the mask
|
||||
argument when calling inotify_add_watch(2).
|
||||
|
||||
Two additional convenience macros are IN_MOVE, which equates to IN_MOVED_FROM|IN_MOVED_TO, and IN_CLOSE, which
|
||||
equates to IN_CLOSE_WRITE|IN_CLOSE_NOWRITE.
|
||||
|
||||
The following further bits can be specified in mask when calling inotify_add_watch(2):
|
||||
IN_DONT_FOLLOW (since Linux 2.6.15)
|
||||
Don't dereference pathname if it is a symbolic link.
|
||||
|
||||
IN_EXCL_UNLINK (since Linux 2.6.36)
|
||||
By default, when watching events on the children of a directory, events are generated for children even after they have been unlinked from the directory. This can result in large numbers of uninteresting events for some applications (e.g., if watching /tmp, in which many applications create temporary files whose names are immediately unlinked). Specifying IN_EXCL_UNLINK changes the default behavior, so that events are not generated for children after they have been unlinked from the watched directory.
|
||||
|
||||
IN_MASK_ADD
|
||||
Add (OR) events to watch mask for this pathname if it already exists (instead of replacing mask).
|
||||
|
||||
IN_ONESHOT
|
||||
Monitor pathname for one event, then remove from watch list.
|
||||
IN_ONLYDIR (since Linux 2.6.15)
|
||||
|
||||
Only watch pathname if it is a directory.
|
||||
|
||||
The following bits may be set in the mask field returned by read(2):
|
||||
IN_IGNORED
|
||||
Watch was removed explicitly (inotify_rm_watch(2)) or automatically (file was deleted, or file system was unmounted).
|
||||
|
||||
IN_ISDIR
|
||||
Subject of this event is a directory.
|
||||
|
||||
IN_Q_OVERFLOW
|
||||
Event queue overflowed (wd is -1 for this event).
|
||||
|
||||
IN_UNMOUNT
|
||||
File system containing watched object was unmounted.
|
||||
|
||||
|
||||
|
||||
Configuration pour les fichiers en entrées
|
||||
------------------------------------------
|
||||
|
||||
'client' => array(
|
||||
'prestations' => array(
|
||||
array(
|
||||
'name' => Nom de la prestation pour référence (UPPERCASE)
|
||||
'type' => Type du dépot SFTP|FTP
|
||||
'directory' => Répertoire de dépot (par defaut "send")
|
||||
'filemask' => Masque du fichier à récupérer ! not working
|
||||
'in' => array(
|
||||
--See the list of options--
|
||||
),
|
||||
'out' => array(
|
||||
--See the list of options--
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Send Options list (in)
|
||||
----------------------
|
||||
- CopyAddDate - Copy file and add a timestamp to the end of the filename
|
||||
- CopyDeleteAfter - After copying the file delete it in repository
|
||||
- RunWithEndFile - Only execute action when we receive file with extension .fin or .end
|
||||
- Log - Log transfert
|
||||
- Route - For each Route options (cp, ftp, sftp, mail)
|
||||
cp => realpath of dir
|
||||
ftp
|
||||
sftp
|
||||
mail
|
||||
- FilterName - Filtre par nom de prestation (true) ou par nom défini
|
||||
|
||||
Recv Options list (out)
|
||||
-----------------------
|
||||
- Log - Log read disable by default
|
||||
|
||||
|
||||
TODO
|
||||
----
|
||||
|
||||
Créer fileMail => Recupération element par mail, enregistrement
|
||||
Filtre sur email et/ou sujet
|
97
fileClean.php
Normal file
97
fileClean.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
// Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
|
||||
|
||||
// Define application environment
|
||||
defined('APPLICATION_ENV')
|
||||
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
/** Zend_Application */
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "Displays usage information.",
|
||||
'cron' => "Mandatory option with cron",
|
||||
'verbose|v' => "Affichage de ce qui est fait."
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
echo $e->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
//Usage
|
||||
if( isset($opts->help) || count($opts->getOptions())==0 )
|
||||
{
|
||||
echo "Clean directories.\n";
|
||||
echo $opts->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
$c = new Zend_Config($application->getOptions());
|
||||
$db = Zend_Db::factory($c->profil->db->metier);
|
||||
Zend_Db_Table::setDefaultAdapter($db);
|
||||
|
||||
// --- Parcours des éléments lu dans la table flux_fileout pour suppression des fichiers de plus de 5 jours
|
||||
$dateEnd = new Zend_Date();
|
||||
$dateEnd->subDay(5);
|
||||
|
||||
$fluxM = new Application_Model_Sdv1FluxFileOut();
|
||||
$deleteSql = $fluxM->select()
|
||||
->where('depotDate BETWEEN "'.date('Ym').'01000000" AND "'.date('Ym').'31235959"')
|
||||
->where('depotDateRead!=0')
|
||||
->where('depotDateRead < ?', $dateEnd->toString('YMdHms'));
|
||||
$deleteResult = $fluxM->fetchAll($deleteSql);
|
||||
if (count($deleteResult) > 0) {
|
||||
foreach ($deleteResult as $item) {
|
||||
$path = '';
|
||||
switch($item->depotType) {
|
||||
case 'FTP':
|
||||
$path = $c->profil->path->ftp;
|
||||
break;
|
||||
case 'SFTP':
|
||||
$path = $c->profil->path->sftp;
|
||||
break;
|
||||
}
|
||||
$path.= '/' . $item->client;
|
||||
if ($item->depotDir == '') {
|
||||
$path.= '/recv';
|
||||
} else {
|
||||
$path.= '/' . $item->depotDir;
|
||||
}
|
||||
$filename = $path . '/' . $item->fileOut;
|
||||
if (file_exists($filename) && is_file($filename)) {
|
||||
unlink($filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Parcours des fichiers pour suppression des fichiers de plus de 30 jours
|
||||
$path = array(
|
||||
$c->profil->path->sftp,
|
||||
$c->profil->path->ftp,
|
||||
);
|
||||
|
||||
// find $p/ -mindepth 2 -maxdepth 4 -type f ! -regex '.*/\..*' -ctime +30 -exec echo {} \;
|
||||
foreach ($path as $p) {
|
||||
passthru("find $p/ -mindepth 2 -maxdepth 4 -type f ! -regex '.*/\..*' -ctime +30 -exec rm -f {} \;");
|
||||
}
|
||||
|
||||
|
115
fileConfig.php
Normal file
115
fileConfig.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
return array(
|
||||
'sfrbtr' => array(
|
||||
'prestations' => array(
|
||||
array(
|
||||
'name' => 'FICH_RCE',
|
||||
'type' => 'SFTP',
|
||||
'in' => array(
|
||||
'CopyDeleteAfter' => true,
|
||||
),
|
||||
'out' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'gefacto' => array(
|
||||
'prestations' => array(
|
||||
array(
|
||||
'name' => 'GEFACTO',
|
||||
'type' => 'SFTP',
|
||||
'in' => array(
|
||||
'RunWithEndFile' => true,
|
||||
'CopyAddDate' => true,
|
||||
'CopyDeleteAfter' => true,
|
||||
),
|
||||
'out' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'fransbonhomme' => array(
|
||||
'prestations' => array(
|
||||
array(
|
||||
'name' => 'RAPPORT',
|
||||
'type' => 'FTP',
|
||||
'in' => array(
|
||||
'CopyDeleteAfter' => true,
|
||||
),
|
||||
'out' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'bilansext' => array(
|
||||
'prestations' => array(
|
||||
array(
|
||||
'name' => 'EXTRANET',
|
||||
'type' => 'FTP',
|
||||
'in' => array(
|
||||
'CopyDeleteAfter' => true,
|
||||
),
|
||||
'out' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'rrg' => array(
|
||||
'prestations' => array(
|
||||
array(
|
||||
'name' => 'HEXAVIA',
|
||||
'type' => 'FTP',
|
||||
'in' => array(),
|
||||
'out' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'jalpdfsed' => array(
|
||||
'prestations' => array(
|
||||
array(
|
||||
'name' => 'PDF',
|
||||
'type' => 'FTP',
|
||||
'in' => array(
|
||||
'CopyDeleteAfter' => true,
|
||||
),
|
||||
'out' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'orone' => array(
|
||||
'prestations' => array(
|
||||
array(
|
||||
'name' => 'XML',
|
||||
'type' => 'FTP',
|
||||
'in' => array(),
|
||||
'out' => array(),
|
||||
),
|
||||
array(
|
||||
'name' => 'PDF',
|
||||
'type' => 'FTP',
|
||||
'in' => array(),
|
||||
'out' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'vwbank' => array(
|
||||
'prestations' => array(
|
||||
array(
|
||||
'name' => 'SURBODPRDCFTVWBANK19300',
|
||||
'type' => 'FTP',
|
||||
'in' => array(
|
||||
'FilterName' => true,
|
||||
'Route' => array( 'cp' => '/home/data/clients-ftp/vwbank/send' ),
|
||||
'CopyDeleteAfter' => true,
|
||||
),
|
||||
'out' => array(),
|
||||
),
|
||||
array(
|
||||
'name' => 'SURBODPRDCFTVWBENG',
|
||||
'type' => 'FTP',
|
||||
'in' => array(
|
||||
'FilterName' => true,
|
||||
'Route' => array( 'cp' => '/home/data/clients-ftp/vwbank/send' ),
|
||||
'CopyDeleteAfter' => true,
|
||||
),
|
||||
'out' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
186
fileRead.php
Normal file
186
fileRead.php
Normal file
@ -0,0 +1,186 @@
|
||||
<?php
|
||||
/**
|
||||
* Indicateur de récupération par le client
|
||||
* Attention le script doit s'executer avec l'utilisateur root
|
||||
*/
|
||||
|
||||
// Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
|
||||
|
||||
// Define application environment
|
||||
defined('APPLICATION_ENV')
|
||||
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
/** Zend_Application */
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "Displays usage information.",
|
||||
'file|f=s' => "Give the full file path to integrate",
|
||||
'debug' => "Send a mail for debug",
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
echo $e->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
//Usage
|
||||
if( isset($opts->help) || count($opts->getOptions())==0 )
|
||||
{
|
||||
echo "Execute basic action when a customer send a file.\n";
|
||||
echo $opts->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
//Get the file
|
||||
if ( isset($opts->file) )
|
||||
{
|
||||
$optionsNoLog = false;
|
||||
$repositoryDir = 'recv';
|
||||
|
||||
$c = new Zend_Config($application->getOptions());
|
||||
|
||||
//Get the main directory name in FTP and SFTP
|
||||
$pathParts = pathinfo($opts->file);
|
||||
$filenameIn = $pathParts['basename'];
|
||||
$extension = '';
|
||||
if (array_key_exists('extension', $pathParts))
|
||||
{
|
||||
$extension = $pathParts['extension'];
|
||||
}
|
||||
$client = basename(dirname($pathParts['dirname']));
|
||||
|
||||
// Base path, type and repository
|
||||
$startpos = strlen( $c->profil->path->data . DIRECTORY_SEPARATOR );
|
||||
if ('sftp' == substr($opts->file, $startpos, 4))
|
||||
{
|
||||
$type = 'SFTP';
|
||||
$fluxBasePath = $c->profil->path->sftp . '/' . $client;
|
||||
}
|
||||
elseif ('ftp' == substr($opts->file, $startpos, 3))
|
||||
{
|
||||
$type = 'FTP';
|
||||
$fluxBasePath = $c->profil->path->ftp . '/' . $client;
|
||||
}
|
||||
$fluxRepository = str_replace(array($fluxBasePath.'/', '/'.$filenameIn), array('', ''), $opts->file);
|
||||
|
||||
// Match prestation
|
||||
$prestations = include __DIR__ . '/fileConfig.php';
|
||||
$prestation = null;
|
||||
if (array_key_exists($client, $prestations))
|
||||
{
|
||||
$clientPrestations = $prestations[$client]['prestations'];
|
||||
foreach ($clientPrestations as $i => $p)
|
||||
{
|
||||
// Not default repository dir
|
||||
if (array_key_exists('directory', $p) && !empty($p['directory']))
|
||||
{
|
||||
$repositoryDir = $p['directory'];
|
||||
}
|
||||
|
||||
if ($type == $p['type'] && $fluxRepository == $repositoryDir)
|
||||
{
|
||||
$prestation = $p['name'];
|
||||
|
||||
// Set option
|
||||
if (array_key_exists('in', $p) && count($p['in']) > 0)
|
||||
{
|
||||
foreach ($p['in'] as $option => $value)
|
||||
{
|
||||
${'options'.$option} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($prestation === null)
|
||||
{
|
||||
echo date('Y-m-d H:i:s')." - Prestation not found !\n";
|
||||
}
|
||||
|
||||
$fluxBasePath .= '/'.$repositoryDir;
|
||||
|
||||
//Prepare mail
|
||||
if ($opts->mail || $opts->debug)
|
||||
{
|
||||
$subject = "[Flux] - Lecture fichier $client";
|
||||
$txt = "Lecture d'un fichier\n";
|
||||
$txt.= "Client : $client\n";
|
||||
$txt.= "Mode de transmission : $type\n";
|
||||
$txt.= "Fichier : ".$filenameIn."\n";
|
||||
$txt.= "Nombre de Lignes : $nbLines\n";
|
||||
$txt.= "Taille du fichier : $size\n";
|
||||
|
||||
$mail = new Zend_Mail('UTF-8');
|
||||
// --- Configuration du transport SMTP
|
||||
if ( $c->profil->mail->method == 'smtp' ) {
|
||||
$config = array();
|
||||
if ( isset($this->config->auth) ) {
|
||||
$config['auth'] = $this->config->auth;
|
||||
if ( isset($this->config->username) ) {
|
||||
$config['username'] = $c->profil->mail->username;
|
||||
}
|
||||
if ( isset($this->config->password) ) {
|
||||
$config['password'] = $c->profil->mail->password;
|
||||
}
|
||||
}
|
||||
if ( isset($this->config->port) ) {
|
||||
$config['port'] = $c->profil->mail->port;
|
||||
}
|
||||
$tr = new Zend_Mail_Transport_Smtp($c->profil->mail->host, $config);
|
||||
}
|
||||
// --- Configuration transport Sendmail
|
||||
if ( $this->config->mail->method == 'sendmail' ) {
|
||||
$tr = new Zend_Mail_Transport_Sendmail();
|
||||
}
|
||||
$mail->setDefaultTransport($tr);
|
||||
$mail->setBodyText($txt);
|
||||
$mail->setFrom('supportdev@scores-decisions.com', 'Machine Flux');
|
||||
$mail->addTo('suivi@scores-decisions.com', 'Suivi');
|
||||
$mail->setSubject($subject);
|
||||
$mail->send();
|
||||
|
||||
//Stop
|
||||
if ($opts->mail)
|
||||
{
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Execute
|
||||
if ($optionsNoLog === false)
|
||||
{
|
||||
$db = Zend_Db::factory($c->profil->db->metier);
|
||||
Zend_Db_Table::setDefaultAdapter($db);
|
||||
try {
|
||||
$fluxM = new Application_Model_Sdv1FluxFileOut();
|
||||
$fluxM->update(array('depotDateRead' => date('YmdHis')), "fileOut='".$filenameIn."'");
|
||||
echo date('Y-m-d H:i:s')." - Enregistrement client:$client fichier:$filenameIn\n";
|
||||
}
|
||||
catch (Zend_Db_Exception $e)
|
||||
{
|
||||
echo date('Y-m-d H:i:s')." - ERREUR Enregistrement client:$client fichier:$filenameIn\n";
|
||||
}
|
||||
}
|
||||
}
|
127
fileRecv.php
127
fileRecv.php
@ -7,16 +7,16 @@
|
||||
|
||||
// Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
|
||||
|
||||
// Define application environment
|
||||
defined('APPLICATION_ENV')
|
||||
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
/** Zend_Application */
|
||||
@ -79,53 +79,130 @@ if ( $result->count() > 0 ) {
|
||||
'/' . 'recv' .
|
||||
'/' . $item->fileOut;
|
||||
|
||||
$depotDir = 'recv';
|
||||
$fluxRepository = 'recv';
|
||||
if ($item->depotDir != '') {
|
||||
$depotDir = $item->depotDir;
|
||||
$fluxRepository = $item->depotDir;
|
||||
}
|
||||
|
||||
switch ($item->depotType) {
|
||||
case 'FTP':
|
||||
$dest = $c->profil->path->ftp .
|
||||
'/' . $item->client .
|
||||
'/' . $depotDir .
|
||||
'/' . $fluxRepository .
|
||||
'/' . $item->fileOut;
|
||||
break;
|
||||
case 'SFTP':
|
||||
$dest = $c->profil->path->sftp .
|
||||
'/' . $item->client .
|
||||
'/' . $depotDir .
|
||||
'/' . $fluxRepository .
|
||||
'/' . $item->fileOut;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// --- Options
|
||||
$optionsCopyAddDate = false;
|
||||
$optionsCopyDeleteAfter = false;
|
||||
$optionsRunWithEndFile = false;
|
||||
$optionsLog = false;
|
||||
|
||||
// Match prestation
|
||||
$prestations = include __DIR__ . '/fileConfig.php';
|
||||
$prestation = null;
|
||||
if (array_key_exists($item->client, $prestations))
|
||||
{
|
||||
$clientPrestations = $prestations[$item->client]['prestations'];
|
||||
foreach ($clientPrestations as $i => $p)
|
||||
{
|
||||
// Not default repository dir
|
||||
$repositoryDir = 'recv';
|
||||
if (array_key_exists('directory', $p) && !empty($p['directory']))
|
||||
{
|
||||
$repositoryDir = $p['directory'];
|
||||
}
|
||||
|
||||
if ($item->depotType == $p['type'] && $fluxRepository == $repositoryDir)
|
||||
{
|
||||
$prestation = $p['name'];
|
||||
|
||||
// Set option
|
||||
if (array_key_exists('out', $p) && count($p['out']) > 0)
|
||||
{
|
||||
foreach ($p['out'] as $option => $value)
|
||||
{
|
||||
${'options'.$option} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Copy du fichier
|
||||
if ( copy($source, $dest) ) {
|
||||
|
||||
$lines = file($source);
|
||||
$nbLines = count($lines);
|
||||
// --- Detail du fichier
|
||||
$nbLines = 0;
|
||||
if ( strtolower(substr(basename($source), -3)) == 'csv' ) {
|
||||
$lines = file($source);
|
||||
$nbLines = count($lines);
|
||||
}
|
||||
$size = filesize($source);
|
||||
|
||||
chown($dest, $item->client);
|
||||
// --- Permission du depot
|
||||
if ($item->depotType == 'FTP') {
|
||||
chown($dest, 'ftpuser');
|
||||
chgrp($dest, 'ftpgroup');
|
||||
}
|
||||
elseif($item->depotType == 'SFTP') {
|
||||
chown($dest, $item->client);
|
||||
}
|
||||
|
||||
// --- Mise à jour information de remise
|
||||
$fluxM->update(array(
|
||||
'depotFileSize' => $size,
|
||||
'depotDate' => date('YmdHis'),
|
||||
), 'id='.$item->id);
|
||||
|
||||
$subject = "[Flux] - Envoi d'un fichier " . $item->client;
|
||||
$txt = "Envoi d'un fichier après traitement\n";
|
||||
$txt.= "Client : ".$item->client."\n";
|
||||
$txt.= "Mode de transmission : ".$item->depotType."\n";
|
||||
$txt.= "Fichier : ".$item->fileOut."\n";
|
||||
$txt.= "Nombre de Lignes : $nbLines\n";
|
||||
// --- Envoi email
|
||||
if ($optionsLog === true) {
|
||||
$subject = "[Flux] - Envoi d'un fichier " . $item->client;
|
||||
$txt = "Envoi d'un fichier après traitement\n";
|
||||
$txt.= "Client : ".$item->client."\n";
|
||||
$txt.= "Mode de transmission : ".$item->depotType."\n";
|
||||
$txt.= "Fichier : ".$item->fileOut."\n";
|
||||
$txt.= "Nombre de Lignes : $nbLines\n";
|
||||
|
||||
$mail = new Zend_Mail('UTF-8');
|
||||
$tr = new Zend_Mail_Transport_Sendmail();
|
||||
$mail->setDefaultTransport($tr);
|
||||
$mail->setBodyText($txt);
|
||||
$mail->setFrom('supportdev@scores-decisions.com', 'Machine');
|
||||
$mail->addTo('suivi@scores-decisions.com', 'Suivi');
|
||||
$mail->setSubject($subject);
|
||||
$mail->send();
|
||||
$mail = new Zend_Mail('UTF-8');
|
||||
// --- Configuration du transport SMTP
|
||||
if ( $c->profil->mail->method == 'smtp' ) {
|
||||
$config = array();
|
||||
if ( isset($this->config->auth) ) {
|
||||
$config['auth'] = $this->config->auth;
|
||||
if ( isset($this->config->username) ) {
|
||||
$config['username'] = $c->profil->mail->username;
|
||||
}
|
||||
if ( isset($this->config->password) ) {
|
||||
$config['password'] = $c->profil->mail->password;
|
||||
}
|
||||
}
|
||||
if ( isset($this->config->port) ) {
|
||||
$config['port'] = $c->profil->mail->port;
|
||||
}
|
||||
$tr = new Zend_Mail_Transport_Smtp($c->profil->mail->host, $config);
|
||||
}
|
||||
// --- Configuration transport Sendmail
|
||||
if ( $this->config->mail->method == 'sendmail' ) {
|
||||
$tr = new Zend_Mail_Transport_Sendmail();
|
||||
}
|
||||
$mail->setDefaultTransport($tr);
|
||||
$mail->setBodyText($txt);
|
||||
$mail->setFrom('supportdev@scores-decisions.com', 'Machine Flux');
|
||||
$mail->addTo('suivi@scores-decisions.com', 'Suivi');
|
||||
$mail->setSubject($subject);
|
||||
$mail->send();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
300
fileSend.php
300
fileSend.php
@ -4,37 +4,37 @@
|
||||
* Attention le script doit s'executer avec l'utilisateur root
|
||||
*/
|
||||
|
||||
// Define path to application directory
|
||||
// --- Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
|
||||
|
||||
// Define application environment
|
||||
// --- Define application environment
|
||||
defined('APPLICATION_ENV')
|
||||
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
// --- Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
/** Zend_Application */
|
||||
// --- Zend_Application
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
// --- Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
// --- Options
|
||||
array(
|
||||
'help|?' => "Displays usage information.",
|
||||
'file|f=s' => "Give the full file path to integrate",
|
||||
'mail' => "Only send a mail when a file is write",
|
||||
'debug' => "Send a mail for debug",
|
||||
'help|?' => "Displays usage information.",
|
||||
'file|f=s' => "Give the full file path to integrate",
|
||||
'mail' => "Only send a mail when a file is write",
|
||||
'debug' => "Send a mail for debug",
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
@ -43,7 +43,7 @@ try {
|
||||
exit;
|
||||
}
|
||||
|
||||
//Usage
|
||||
// --- Usage
|
||||
if( isset($opts->help) || count($opts->getOptions())==0 )
|
||||
{
|
||||
echo "Execute basic action when a customer send a file.\n";
|
||||
@ -51,172 +51,282 @@ if( isset($opts->help) || count($opts->getOptions())==0 )
|
||||
exit;
|
||||
}
|
||||
|
||||
//Get the file
|
||||
// --- Get the file
|
||||
if ( isset($opts->file) )
|
||||
{
|
||||
$optionsCopyAddDate = false;
|
||||
$optionsCopyDeleteAfter = false;
|
||||
$optionsRunWithEndFile = false;
|
||||
$optionsLog = true;
|
||||
$optionsRoute = array();
|
||||
$optionsFilterName = false;
|
||||
$repositoryDir = 'send';
|
||||
|
||||
$c = new Zend_Config($application->getOptions());
|
||||
|
||||
$dateFile = date('YmdHis', filectime($opts->file));
|
||||
|
||||
//Get the main directory name in FTP and SFTP
|
||||
// --- Get the main directory name in FTP and SFTP
|
||||
$pathParts = pathinfo($opts->file);
|
||||
$filenameIn = $pathParts['basename'];
|
||||
$extension = '';
|
||||
if (array_key_exists('extension', $pathParts) ){
|
||||
if (array_key_exists('extension', $pathParts))
|
||||
{
|
||||
$extension = $pathParts['extension'];
|
||||
}
|
||||
$client = basename(dirname($pathParts['dirname']));
|
||||
|
||||
$startpos = strlen( $c->profil->path->data . DIRECTORY_SEPARATOR );
|
||||
if ( 'sftp' == substr($opts->file, $startpos, 4) ) {
|
||||
// --- Base path, type and repository
|
||||
$startpos = strlen( $c->profil->path->data . '/' );
|
||||
if ('sftp' == substr($opts->file, $startpos, 4))
|
||||
{
|
||||
$type = 'SFTP';
|
||||
$fluxBasePath = $c->profil->path->sftp . '/' . $client;
|
||||
} elseif ( 'ftp' == substr($opts->file, $startpos, 3) ) {
|
||||
}
|
||||
elseif ('ftp' == substr($opts->file, $startpos, 3))
|
||||
{
|
||||
$type = 'FTP';
|
||||
$fluxBasePath = $c->profil->path->ftp . '/' . $client;
|
||||
}
|
||||
$fluxRepository = str_replace(array($fluxBasePath.'/', '/'.$filenameIn), array('', ''), $opts->file);
|
||||
|
||||
$fluxBasePath .= '/send';
|
||||
// --- Match prestation
|
||||
$prestations = include __DIR__ . '/fileConfig.php';
|
||||
$prestation = null;
|
||||
if (array_key_exists($client, $prestations))
|
||||
{
|
||||
$clientPrestations = $prestations[$client]['prestations'];
|
||||
foreach ($clientPrestations as $i => $p)
|
||||
{
|
||||
// --- Not default repository dir
|
||||
if (array_key_exists('directory', $p) && !empty($p['directory']))
|
||||
{
|
||||
$repositoryDir = $p['directory'];
|
||||
}
|
||||
|
||||
$OptionsCopyAddDate = false;
|
||||
$OptionsCopyDeleteAfter = false;
|
||||
$OptionsRunWithEndFile = false;
|
||||
// --- Match prestation
|
||||
if ($type == $p['type'] && $fluxRepository == $repositoryDir)
|
||||
{
|
||||
$prestation = $p['name'];
|
||||
|
||||
/**
|
||||
* @todo : links to prestation table and file rules
|
||||
* Prestation => Repertoire reception, etc
|
||||
*/
|
||||
switch ($client) {
|
||||
case 'sfrbtr' :
|
||||
$prestation = 'FICH_RCE';
|
||||
$filemask = array(
|
||||
'FICH_RCE_SCORE_.*.csv',
|
||||
);
|
||||
break;
|
||||
case 'gefacto':
|
||||
$prestation = 'GEFACTO';
|
||||
$OptionsCopyAddDate = true;
|
||||
$OptionsRunWithEndFile = true;
|
||||
break;
|
||||
}
|
||||
// --- Set options
|
||||
if (array_key_exists('in', $p) && count($p['in']) > 0)
|
||||
{
|
||||
foreach ($p['in'] as $option => $value)
|
||||
{
|
||||
${'options'.$option} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
//Use ".fin" or ".end" files to do something
|
||||
// --- Filters
|
||||
if ($optionsFilterName === true) {
|
||||
if ( strpos($filenameIn, $prestation) === false ) {
|
||||
$prestation = null; continue;
|
||||
}
|
||||
}
|
||||
if (is_string($optionsFilterName) && strlen($optionsFilterName) > 0) {
|
||||
if (strpos($filenameIn, $optionsFilterName) === false) {
|
||||
$prestation = null; continue;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($prestation === null)
|
||||
{
|
||||
echo date('Y-m-d H:i:s')." - Prestation not found !\n";
|
||||
}
|
||||
|
||||
$fluxBasePath .= '/'.$repositoryDir;
|
||||
|
||||
// --- Use ".fin" or ".end" files to do something
|
||||
$runExtensions = array('fin', 'end');
|
||||
if ( in_array( $extension, $runExtensions) ) {
|
||||
if ( $OptionsRunWithEndFile ) {
|
||||
$extToDelete = $extension;
|
||||
if (file_exists($fluxBasePath . '/' . $filenameIn)) {
|
||||
if (in_array( $extension, $runExtensions))
|
||||
{
|
||||
if ( $optionsRunWithEndFile )
|
||||
{
|
||||
$extToDelete = $extension;
|
||||
if (file_exists($fluxBasePath . '/' . $filenameIn))
|
||||
{
|
||||
$pathParts = pathinfo($fluxBasePath . '/' . $filenameIn);
|
||||
$filenameIn = $pathParts['basename'];
|
||||
$extension = '';
|
||||
if (array_key_exists('extension', $pathParts) ){
|
||||
if (array_key_exists('extension', $pathParts))
|
||||
{
|
||||
$extension = $pathParts['extension'];
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Fichier inexistant $filenameIn\n";
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
//Get the realname of file IN or exit
|
||||
if ( $OptionsRunWithEndFile ) {
|
||||
if ( in_array( $extension, $runExtensions) ) {
|
||||
// --- Get the realname of file IN or exit
|
||||
if ($optionsRunWithEndFile)
|
||||
{
|
||||
if (in_array( $extension, $runExtensions))
|
||||
{
|
||||
$extensionLength = strlen($extension)+1;
|
||||
$filenameIn = substr($filenameIn, 0, strlen($filenameIn) - $extensionLength);
|
||||
$extension = '';
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$lines = file($fluxBasePath . '/' . $filenameIn);
|
||||
$nbLines = count($lines);
|
||||
// ---
|
||||
|
||||
//Define default out filename
|
||||
// --- Detail du fichier
|
||||
$nbLines = 0;
|
||||
if ( strtolower(substr($filenameIn, -3)) == 'csv' ) {
|
||||
$lines = file($fluxBasePath . '/' . $filenameIn);
|
||||
$nbLines = count($lines);
|
||||
}
|
||||
$size = filesize($fluxBasePath . '/' . $filenameIn);
|
||||
|
||||
// --- Define default out filename
|
||||
$filenameOut = $filenameIn;
|
||||
|
||||
//Add date to filename
|
||||
if ( $OptionsCopyAddDate ) {
|
||||
// --- Add date to filename
|
||||
if ($optionsCopyAddDate)
|
||||
{
|
||||
$extensionLength = 0;
|
||||
if ( $extension != '' ) {
|
||||
if ($extension != '')
|
||||
{
|
||||
$extensionLength = strlen($extension)+1;
|
||||
$filenameOut = substr($filenameIn, 0, strlen($filenameIn) - $extensionLength);
|
||||
$filenameOut = $filenameOut . '_' . date('YmdHis') . '.' . $extension;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$filenameOut = $filenameIn . '_' . date('YmdHis');
|
||||
}
|
||||
}
|
||||
|
||||
//Prepare mail
|
||||
if ($opts->mail || $opts->debug) {
|
||||
|
||||
// --- Prepare mail
|
||||
if ($opts->mail || $opts->debug)
|
||||
{
|
||||
$subject = "[Flux] - Réception fichier $client";
|
||||
$txt = "Réception d'un fichier pour traitement\n";
|
||||
$txt.= "Client : $client\n";
|
||||
$txt.= "Mode de transmission : $type\n";
|
||||
$txt.= "Fichier : ".$filenameIn."\n";
|
||||
$txt.= "Nombre de Lignes : $nbLines\n";
|
||||
$txt.= "Taille du fichier : $size\n";
|
||||
|
||||
$mail = new Zend_Mail('UTF-8');
|
||||
$tr = new Zend_Mail_Transport_Smtp('smtp.celeste.fr');
|
||||
// --- Configuration du transport SMTP
|
||||
if ( $c->profil->mail->method == 'smtp' ) {
|
||||
$config = array();
|
||||
if ( isset($this->config->auth) ) {
|
||||
$config['auth'] = $this->config->auth;
|
||||
if ( isset($this->config->username) ) {
|
||||
$config['username'] = $c->profil->mail->username;
|
||||
}
|
||||
if ( isset($this->config->password) ) {
|
||||
$config['password'] = $c->profil->mail->password;
|
||||
}
|
||||
}
|
||||
if ( isset($this->config->port) ) {
|
||||
$config['port'] = $c->profil->mail->port;
|
||||
}
|
||||
$tr = new Zend_Mail_Transport_Smtp($c->profil->mail->host, $config);
|
||||
}
|
||||
// --- Configuration transport Sendmail
|
||||
if ( $this->config->mail->method == 'sendmail' ) {
|
||||
$tr = new Zend_Mail_Transport_Sendmail();
|
||||
}
|
||||
$mail->setDefaultTransport($tr);
|
||||
$mail->setBodyText($txt);
|
||||
$mail->setFrom('supportdev@scores-decisions.com', 'Machine');
|
||||
$mail->setFrom('supportdev@scores-decisions.com', 'Machine Flux');
|
||||
$mail->addTo('suivi@scores-decisions.com', 'Suivi');
|
||||
$mail->setSubject($subject);
|
||||
$mail->send();
|
||||
|
||||
//Stop
|
||||
if ($opts->mail) {
|
||||
// --- Stop
|
||||
if ($opts->mail)
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Copie du fichier
|
||||
// --- Before store the file send to another repository
|
||||
if (count($optionsRoute) > 0) {
|
||||
foreach ($optionsRoute as $tr => $value) {
|
||||
switch($tr) {
|
||||
case 'cp':
|
||||
if (copy($fluxBasePath . '/' . $filenameIn, $value . '/' . $filenameOut)) {
|
||||
echo date('Y-m-d H:i:s')." - Copie du fichier $filenameIn dans $value\n";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Copy file
|
||||
$destDir = $c->profil->path->storage . '/' . $client . '/' . 'send';
|
||||
|
||||
if ( !is_dir($destDir) ) {
|
||||
if (!is_dir($destDir))
|
||||
{
|
||||
mkdir($destDir, 0755, true);
|
||||
}
|
||||
|
||||
if ( copy($fluxBasePath . '/' . $filenameIn, $destDir. '/' . $filenameOut) ) {
|
||||
if (copy($fluxBasePath . '/' . $filenameIn, $destDir. '/' . $filenameOut))
|
||||
{
|
||||
echo date('Y-m-d H:i:s')." - Copie du fichier $filenameIn dans $destDir\n";
|
||||
|
||||
//Execute
|
||||
$db = Zend_Db::factory($c->profil->db->metier);
|
||||
Zend_Db_Table::setDefaultAdapter($db);
|
||||
try {
|
||||
$fluxM = new Application_Model_Sdv1FluxFileIn();
|
||||
$fluxM->insert(array(
|
||||
'client' => $client,
|
||||
'name' => $prestation,
|
||||
'depotType' => $type,
|
||||
'depotDate' => $dateFile,
|
||||
'depotFile' => $filenameOut,
|
||||
'nbLines' => $nbLines,
|
||||
'dateInsert' => date('YmdHis'),
|
||||
'dateExecute' => '0000-00-00 00:00:00',
|
||||
));
|
||||
echo date('Y-m-d H:i:s')." - Enregistrement client:$client fichier:$filenameOut\n";
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
echo date('Y-m-d H:i:s')." - ERREUR Enregistrement client:$client fichier:$filenameOut\n";
|
||||
// --- Execute
|
||||
if ($optionsLog === true)
|
||||
{
|
||||
$db = Zend_Db::factory($c->profil->db->metier);
|
||||
Zend_Db_Table::setDefaultAdapter($db);
|
||||
try {
|
||||
$fluxM = new Application_Model_Sdv1FluxFileIn();
|
||||
$fluxM->insert(array(
|
||||
'client' => $client,
|
||||
'name' => $prestation,
|
||||
'depotType' => $type,
|
||||
'depotDate' => $dateFile,
|
||||
'depotFile' => $filenameOut,
|
||||
'nbLines' => $nbLines,
|
||||
'depotFileSize' => $size,
|
||||
'dateInsert' => date('YmdHis'),
|
||||
'dateExecute' => '0000-00-00 00:00:00', // @todo : dateExecute
|
||||
));
|
||||
echo date('Y-m-d H:i:s')." - Enregistrement client:$client fichier:$filenameOut\n";
|
||||
}
|
||||
catch (Zend_Db_Exception $e)
|
||||
{
|
||||
echo date('Y-m-d H:i:s')." - ERREUR Enregistrement client:$client fichier:$filenameOut\n";
|
||||
}
|
||||
}
|
||||
|
||||
//Suppression des fichiers
|
||||
if ( $OptionsCopyDeleteAfter ) {
|
||||
// --- Suppression des fichiers
|
||||
if ($optionsCopyDeleteAfter)
|
||||
{
|
||||
unlink( $fluxBasePath . '/' . $filenameIn );
|
||||
|
||||
if ( $OptionsRunWithEndFile ) {
|
||||
if ($optionsRunWithEndFile)
|
||||
{
|
||||
unlink( $fluxBasePath . '/' . $filenameIn . '.' . $extToDelete );
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
echo date('Y-m-d H:i:s')." - ERREUR Copie du fichier $filenameIn dans $destDir\n";
|
||||
}
|
||||
|
||||
}
|
@ -13,36 +13,25 @@ set_include_path(implode(PATH_SEPARATOR, array(
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
//Copy configuration
|
||||
$configDir = realpath(dirname(__FILE__)).'/config';
|
||||
$appconfigDir = APPLICATION_PATH.'/configs';
|
||||
|
||||
if (stristr(PHP_OS, 'WIN')) {
|
||||
$hostname = 'development';
|
||||
} else {
|
||||
$hostname = exec('echo $(hostname)');
|
||||
}
|
||||
|
||||
if ( !copy($configDir.'/'.$hostname.'/application.ini', $appconfigDir.'/application.ini') ) {
|
||||
echo "application.ini could not be copied !\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
/** Zend_Application */
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
//Use classmap autoloader - useful with opcode and realpath cache
|
||||
require_once 'Zend/Loader/AutoloaderFactory.php';
|
||||
require_once 'Zend/Loader/ClassMapAutoloader.php';
|
||||
Zend_Loader_AutoloaderFactory::factory(array(
|
||||
'Zend_Loader_StandardAutoloader' => array(
|
||||
'prefixes' => array(
|
||||
'Zend' => __DIR__ . '/../../library/Zend',
|
||||
'Application' => __DIR__ . '/../../library/Application',
|
||||
),
|
||||
'fallback_autoloader' => true
|
||||
),
|
||||
));
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "Display usage information.",
|
||||
'install' => "Make install operation.",
|
||||
'install=s' => "Make install operation.",
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
@ -52,17 +41,34 @@ try {
|
||||
}
|
||||
|
||||
//Usage
|
||||
if(isset($opts->help))
|
||||
if (isset($opts->help))
|
||||
{
|
||||
echo $opts->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
if(isset($opts->install))
|
||||
|
||||
if ( ! empty($opts->install) )
|
||||
{
|
||||
if (stristr(PHP_OS, 'WIN')) {
|
||||
echo date('Y-m-d H:i:s')." - Démarrage de la configuration.\n";
|
||||
|
||||
//Copy configuration
|
||||
$configDir = realpath(dirname(__FILE__)).'/profil';
|
||||
$appconfigDir = APPLICATION_PATH.'/configs';
|
||||
$profil = $opts->install;
|
||||
|
||||
if ( !file_exists( $appconfigDir.'/application.ini') ) {
|
||||
$result = copy($configDir.'/'.$profil.'/application.ini', $appconfigDir.'/application.ini');
|
||||
if ($result !== true) {
|
||||
echo date('Y-m-d H:i:s')." - Impossible de copier la configuration.\n";
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
|
||||
echo date('Y-m-d H:i:s')." - Le profil de configuration existe déja.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
echo date('Y-m-d H:i:s')." - Fin de la configuration.\n";
|
||||
} else {
|
||||
echo date('Y-m-d H:i:s')." - Je n'ai rien fait !\n";
|
||||
}
|
||||
|
6
scripts/build/etc/cron.d/batchflux
Normal file
6
scripts/build/etc/cron.d/batchflux
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
# Gestion des flux a envoyer au client
|
||||
*/15 4-18 * * * root php /home/batchFlux/fileRecv.php --cron >> /home/log/recv.log 2>&1
|
||||
|
||||
# Nettoyage
|
||||
01 18 * * * root php /home/batchFlux/fileClean.php --cron >> /home/log/clean.log 2>&1
|
134
scripts/build/incron.php
Normal file
134
scripts/build/incron.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
// Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
|
||||
|
||||
// Define application environment
|
||||
defined('APPLICATION_ENV')
|
||||
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
/** Zend_Application */
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
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();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
echo $e->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
//Usage
|
||||
if(isset($opts->help))
|
||||
{
|
||||
echo $opts->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
$prestations = include APPLICATION_PATH . '/../fileConfig.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";
|
||||
|
||||
if ($opts->send) {
|
||||
|
||||
$input = explode('/', $opts->send);
|
||||
$client = $input[0];
|
||||
$name = $input[1];
|
||||
if (array_key_exists($client, $prestations))
|
||||
{
|
||||
foreach ($prestations[$client]['prestations'] as $item)
|
||||
{
|
||||
if ($item['name'] == $name)
|
||||
{
|
||||
$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;
|
||||
file_put_contents($file, "$fluxBasePath IN_CLOSE_WRITE php /home/batchFlux/fileSend.php --file $@/$# >> /home/log/send.log 2>&1");
|
||||
echo "File created $file\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($opts->read) {
|
||||
|
||||
$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';
|
||||
file_put_contents($file, "$fluxBasePath IN_ACCESS php /home/batchFlux/fileRead.php --file $@/$# >> /home/log/read.log 2>&1");
|
||||
echo "File created $file\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo "Put the file to /etc/incron.d and restart incron.\n";
|
||||
echo "Generate Ended.\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
/home/data/sftp/gefacto/send IN_CLOSE_WRITE php /home/batchFlux/fileSend.php --debug --file $@/$#
|
@ -1 +0,0 @@
|
||||
/home/data/sftp/sfrbtr/send IN_CLOSE_WRITE php /home/batchFlux/fileSend.php --debug --file $@/$#
|
@ -27,6 +27,9 @@ profil.db.metier.params.password=2XQTpKatBVRezXE9
|
||||
profil.db.metier.params.dbname=sdv1
|
||||
profil.db.metier.params.driver_options.MYSQLI_INIT_COMMAND = "SET NAMES utf8"
|
||||
|
||||
; Mail configuration
|
||||
profil.db.method = sendmail
|
||||
|
||||
[staging : production]
|
||||
resources.frontController.params.displayExceptions = 1
|
||||
|
Loading…
Reference in New Issue
Block a user