diff --git a/clean.php b/clean.php deleted file mode 100644 index 1313353..0000000 --- a/clean.php +++ /dev/null @@ -1,88 +0,0 @@ - "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 {} \;"); -} - - diff --git a/config.php b/config.php deleted file mode 100644 index 930adbc..0000000 --- a/config.php +++ /dev/null @@ -1,164 +0,0 @@ - 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(), - ), - ), - ), - 'futur' => array( - 'prestations' => array( - array( - 'name' => 'SURBODPRDFTPSFRFUTUR', - 'type' => 'FTP', - 'in' => array( - 'Route' => array( 'cp' => '/home/data/clients-ftp/futur/send' ), - 'CopyDeleteAfter' => true, - ), - 'out' => array(), - ), - ), - ), - 'fboissons' => array( - 'prestations' => array( - array( - 'name' => 'SCOREETDECISION', - 'type' => 'FTP', - 'in' => array( - 'Route' => array( 'cp' => '/home/data/clients-ftp/fboissons/send' ), - 'CopyDeleteAfter' => true, - ), - 'out' => array(), - ), - ), - ), - 'effico' => array( - 'prestations' => array( - array( - 'name' => 'DIFBODPRDSFTPEFFICO', - 'type' => 'SFTP', - 'in' => array(), - 'out' => array(), - ), - ), - ), - 'sofid' => array( - 'prestations' => array( - array( - 'name' => 'SURBODPRDFTSSOFID', - 'type' => 'FTP', - 'in' => array( - 'Route' => array( 'cp' => '/home/data/clients-ftp/sofid/send' ), - 'CopyDeleteAfter' => true, - ), - 'out' => array(), - ), - ), - ), -); diff --git a/config/autoload/presta.global.php b/config/autoload/presta.global.php deleted file mode 100644 index 7c1424c..0000000 --- a/config/autoload/presta.global.php +++ /dev/null @@ -1,166 +0,0 @@ - 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(), - ), - ), - ), - 'futur' => array( - 'prestations' => array( - array( - 'name' => 'SURBODPRDFTPSFRFUTUR', - 'type' => 'FTP', - 'in' => array( - 'Route' => array( 'cp' => '/home/data/clients-ftp/futur/send' ), - 'CopyDeleteAfter' => true, - ), - 'out' => array(), - ), - ), - ), - 'fboissons' => array( - 'prestations' => array( - array( - 'name' => 'SCOREETDECISION', - 'type' => 'FTP', - 'in' => array( - 'Route' => array( 'cp' => '/home/data/clients-ftp/fboissons/send' ), - 'CopyDeleteAfter' => true, - ), - 'out' => array(), - ), - ), - ), - 'effico' => array( - 'prestations' => array( - array( - 'name' => 'DIFBODPRDSFTPEFFICO', - 'type' => 'SFTP', - 'in' => array(), - 'out' => array(), - ), - ), - ), - 'sofid' => array( - 'prestations' => array( - array( - 'name' => 'SURBODPRDFTSSOFID', - 'type' => 'FTP', - 'in' => array( - 'Route' => array( 'cp' => '/home/data/clients-ftp/sofid/send' ), - 'CopyDeleteAfter' => true, - ), - 'out' => array(), - ), - ), - ), - ), -); diff --git a/fallback.php b/fallback.php deleted file mode 100644 index b7ba567..0000000 --- a/fallback.php +++ /dev/null @@ -1,227 +0,0 @@ - "Displays usage information.", - 'cron' => "Mandatory option with cron", - 'verbose|v' => "Affichage de ce qui est fait." - )); - $opts->parse(); -} catch (Zend_Console_Getopt_Exception $e) { - $displayUsage = true; -} - -// --- Aide / Options -if (count($opts->getOptions())==0 || isset($opts->help)) { - $displayUsage = true; -} - -// --- Usage -if ($displayUsage) { - echo "Fallback pour distribuer les fichiers si la gestion par event n'as pas fonctionné.\n"; - echo $opts->getUsageMessage(); - exit; -} - -$c = new Zend_Config($application->getOptions()); -$db = Zend_Db::factory($c->profil->db->metier); -Zend_Db_Table::setDefaultAdapter($db); - -$fileConfig = include __DIR__ . '/fileConfig.php'; - -if (count($fileConfig) > 0) { - foreach ($fileConfig as $client => $prestations) { - if (count($prestations) > 0) { - foreach($prestations as $p) { - - $prestation = $p['name']; - $type = $p['type']; - - $optionsCopyAddDate = false; - $optionsCopyDeleteAfter = false; - $optionsRunWithEndFile = false; - $optionsLog = true; - $optionsRoute = array(); - $optionsFilterName = false; - - // --- Set options - if (array_key_exists('in', $p) && count($p['in']) > 0) { - foreach ($p['in'] as $option => $value) { - ${'options'.$option} = $value; - } - } - - $repositoryDir = 'send'; - - // --- Base path, type and repository - $startpos = strlen( $c->profil->path->data . '/' ); - if ($type == 'SFTP') { - $fluxBasePath = $c->profil->path->sftp . '/' . $client; - } - elseif ($type == 'FTP') { - $fluxBasePath = $c->profil->path->ftp . '/' . $client; - } - - // --- Repository dir - if (array_key_exists('directory', $p) && !empty($p['directory'])) { - $repositoryDir = $p['directory']; - } - $fluxBasePath = $fluxBasePath . '/' . $repositoryDir; - - // --- Get files - $it = new FilesystemIterator($fluxBasePath); - foreach ($it as $fileinfo) { - $filenameIn = $fileinfo->getFilename(); - $extension = $fileinfo->getExtension(); - - // --- Don't play with *.tck files - if ($extension == 'tck') { - continue; - } - - // --- 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; - } - } - - // --- 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)) { - $pathParts = pathinfo($fluxBasePath . '/' . $filenameIn); - $filenameIn = $pathParts['basename']; - } - else { - echo "Fichier fin inexistant $filenameIn\n"; - continue; - } - } - else { - continue; - } - } - - // --- 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 { - continue; - } - } - - // --- Detail du fichier - $nbLines = 0; - if ( strtolower(substr($filenameIn, -3)) == 'csv' ) { - $lines = file($fluxBasePath . '/' . $filenameIn); - $nbLines = count($lines); - } - $size = filesize($fluxBasePath . '/' . $filenameIn); - $dateFile = date('YmdHis', filectime($fluxBasePath . '/' . $filenameIn)); - - // --- Define default out filename - $filenameOut = $filenameIn; - - // --- Add date to filename - if ($optionsCopyAddDate) { - $extensionLength = 0; - if ($extension != '') { - $extensionLength = strlen($extension)+1; - $filenameOut = substr($filenameIn, 0, strlen($filenameIn) - $extensionLength); - $filenameOut = $filenameOut . '_' . date('YmdHis') . '.' . $extension; - } - else { - $filenameOut = $filenameIn . '_' . date('YmdHis'); - } - } - - // --- 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)) { - mkdir($destDir, 0755, true); - } - - if (copy($fluxBasePath . '/' . $filenameIn, $destDir. '/' . $filenameOut)) { - echo date('Y-m-d H:i:s')." - Copie du fichier $filenameIn dans $destDir\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) { - unlink( $fluxBasePath . '/' . $filenameIn ); - if ($optionsRunWithEndFile) { - unlink( $fluxBasePath . '/' . $filenameIn . '.' . $extToDelete ); - } - } - } - else { - echo date('Y-m-d H:i:s')." - ERREUR Copie du fichier $filenameIn dans $destDir\n"; - } - - } - } - } - } -} diff --git a/read.php b/read.php deleted file mode 100644 index 638827e..0000000 --- a/read.php +++ /dev/null @@ -1,182 +0,0 @@ - "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 read 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__ . '/config.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 or Debug mode - 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); - $fluxM = new Application_Model_Sdv1FluxFileOut(); - - // --- Vérifier si l'indicateur de lecture n'a pas déjà été ecrit - $readSql = $fluxM->select()->where("fileOut='".$filenameIn."'"); - $readResult = $fluxM->fetchRow($readSql); - if ($readResult !== null) { - if ($readResult->depotDateRead == 0) { - // --- Ecrire l'indicateur de lecture - try { - $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"; - } - } - } - } -} \ No newline at end of file diff --git a/recv.php b/recv.php deleted file mode 100644 index d5742fd..0000000 --- a/recv.php +++ /dev/null @@ -1,201 +0,0 @@ - Client - * Attention le script doit s'executer avec l'utilisateur root, afin de lire le fichier même - * s'il n'a pas les droits - */ - -// --- Define path to application directory -defined('APPLICATION_PATH') - || define('APPLICATION_PATH', realpath(__DIR__ . '/application')); - -// --- Define application environment -defined('APPLICATION_ENV') - || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); - -// --- Composer autoload -require_once realpath(__DIR__ . '/vendor/autoload.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 in crontab", - 'file=s' => "Manually define the file to process", - 'client=s' => "Define the client name for getting the file manually", - '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 "Place files in right directory for sending to the customer.\n"; - echo $opts->getUsageMessage(); - exit; -} - -$c = new Zend_Config($application->getOptions()); -$db = Zend_Db::factory($c->profil->db->metier); -Zend_Db_Table::setDefaultAdapter($db); - -$fluxM = new Application_Model_Sdv1FluxFileOut(); -$sql = $fluxM->select()->where('dateEnd!=?','0000-00-00 00:00:00'); - -//Get specific file -if ( isset($opts->file) && isset($opts->client) ) { - $sql->where('client=?', $opts->client) - ->where('fileOut=?', $opts->file); -} else { - $sql->where('dateEnd!=?', '0000-00-00 00:00:00'); - $sql->where('depotDate=?', '0000-00-00 00:00:00'); -} - -$result = $fluxM->fetchAll($sql); - -if ( $result->count() > 0 ) { - foreach ( $result as $item ) { - - $source = $c->profil->path->storage . - '/' . $item->client . - '/' . 'recv' . - '/' . $item->fileOut; - - $fluxRepository = 'recv'; - if ($item->depotDir != '') { - $fluxRepository = $item->depotDir; - } - - switch ($item->depotType) { - case 'FTP': - $dest = $c->profil->path->ftp . - '/' . $item->client . - '/' . $fluxRepository . - '/' . $item->fileOut; - break; - case 'SFTP': - $dest = $c->profil->path->sftp . - '/' . $item->client . - '/' . $fluxRepository . - '/' . $item->fileOut; - - break; - } - - // --- Options - $optionsCopyAddDate = false; - $optionsCopyDeleteAfter = false; - $optionsRunWithEndFile = false; - $optionsLog = false; - - // Match prestation - $prestations = include __DIR__ . '/config.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) ) { - - // --- Detail du fichier - $nbLines = 0; - if ( strtolower(substr(basename($source), -3)) == 'csv' ) { - $lines = file($source); - $nbLines = count($lines); - } - $size = filesize($source); - - // --- 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); - - // --- 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'); - // --- 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(); - } - - } - - } -} diff --git a/send.php b/send.php deleted file mode 100644 index 8b7b84b..0000000 --- a/send.php +++ /dev/null @@ -1,290 +0,0 @@ - SD - * Attention le script doit s'executer avec l'utilisateur root - */ - -// --- Define path to application directory -defined('APPLICATION_PATH') - || define('APPLICATION_PATH', realpath(__DIR__ . '/application')); - -// --- Define application environment -defined('APPLICATION_ENV') - || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); - -// --- Composer autoload -require_once realpath(__DIR__ . '/vendor/autoload.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", - 'mail' => "Only send a mail when a file is write", - '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) ) -{ - $optionsCopyAddDate = false; - $optionsCopyDeleteAfter = false; - $optionsRunWithEndFile = false; - $optionsLog = true; - $optionsRoute = array(); - $optionsFilterName = false; - $repositoryDir = 'send'; - - $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']; - } - // --- Don't play with *.tck files - if ($extension == 'tck') { - passthru(__DIR__ . '/tck.php --file '.$opts->file.' >> /home/log/tck.log 2>&1'); - exit; - } - $client = basename(dirname($pathParts['dirname'])); - - // --- 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)) { - $type = 'FTP'; - $fluxBasePath = $c->profil->path->ftp . '/' . $client; - } - $fluxRepository = str_replace(array($fluxBasePath.'/', '/'.$filenameIn), array('', ''), $opts->file); - - // --- Match prestation - $prestations = include __DIR__ . '/config.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']; - } - - // --- Match prestation - if ($type == $p['type'] && $fluxRepository == $repositoryDir) { - $prestation = $p['name']; - - // --- Set options - if (array_key_exists('in', $p) && count($p['in']) > 0) { - foreach ($p['in'] as $option => $value) { - ${'options'.$option} = $value; - } - } - - // --- 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)) { - $pathParts = pathinfo($fluxBasePath . '/' . $filenameIn); - $filenameIn = $pathParts['basename']; - } - else { - echo "Fichier fin inexistant $filenameIn\n"; - exit; - } - } - else { - exit; - } - } - - // --- 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 { - exit; - } - } - - // --- - - // --- Detail du fichier - $nbLines = 0; - if ( strtolower(substr($filenameIn, -3)) == 'csv' ) { - $lines = file($fluxBasePath . '/' . $filenameIn); - $nbLines = count($lines); - } - $size = filesize($fluxBasePath . '/' . $filenameIn); - $dateFile = date('YmdHis', filectime($fluxBasePath . '/' . $filenameIn)); - - // --- Define default out filename - $filenameOut = $filenameIn; - - // --- Add date to filename - if ($optionsCopyAddDate) { - $extensionLength = 0; - if ($extension != '') { - $extensionLength = strlen($extension)+1; - $filenameOut = substr($filenameIn, 0, strlen($filenameIn) - $extensionLength); - $filenameOut = $filenameOut . '_' . date('YmdHis') . '.' . $extension; - } - else { - $filenameOut = $filenameIn . '_' . date('YmdHis'); - } - } - - // --- 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'); - // --- 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; - } - } - - // --- 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)) { - mkdir($destDir, 0755, true); - } - - if (copy($fluxBasePath . '/' . $filenameIn, $destDir. '/' . $filenameOut)) { - echo date('Y-m-d H:i:s')." - Copie du fichier $filenameIn dans $destDir\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) { - unlink( $fluxBasePath . '/' . $filenameIn ); - if ($optionsRunWithEndFile) { - unlink( $fluxBasePath . '/' . $filenameIn . '.' . $extToDelete ); - } - } - - } - else { - echo date('Y-m-d H:i:s')." - ERREUR Copie du fichier $filenameIn dans $destDir\n"; - } -} \ No newline at end of file diff --git a/tck.php b/tck.php deleted file mode 100644 index a904442..0000000 --- a/tck.php +++ /dev/null @@ -1,176 +0,0 @@ - "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 "Mark as transfert.\n"; - echo $opts->getUsageMessage(); - exit; -} - -// --- Get the file -if ( isset($opts->file) ) -{ - $optionsNoLog = false; - $repositoryDir = 'send'; - - $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']; - } - - // --- Only file with .tck - if ($extension != 'tck') { - exit; - } - - $client = basename(dirname($pathParts['dirname'])); - $filenameSearch = str_replace('.tck', '', $filenameIn); - - // --- 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__ . '/config.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; - } - } - } - - $fluxBasePath .= '/'.$repositoryDir; - - // --- Prepare mail or Debug mode - if ($opts->mail || $opts->debug) - { - $subject = "[Flux] - Transfert fichier $client"; - $txt = "Transfert d'un fichier\n"; - $txt.= "Client : $client\n"; - $txt.= "Fichier : ".$filenameIn."\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('transfertDate' => date('YmdHis')), "fileOut='".$filenameSearch."'"); - echo date('Y-m-d H:i:s')." - Enregistrement client:$client fichier:$filenameSearch\n"; - unlink($fluxBasePath.'/'.$filenameIn); - } - catch (Zend_Db_Exception $e) - { - echo date('Y-m-d H:i:s')." - ERREUR Enregistrement client:$client fichier:$filenameSearch\n"; - } - } -} \ No newline at end of file diff --git a/trigger.php b/trigger.php deleted file mode 100644 index 6f00e4d..0000000 --- a/trigger.php +++ /dev/null @@ -1,62 +0,0 @@ - "Displays usage information.", - 'file|f=s' => "Full file path to integrate", - 'event=s' => "Event", - )); - $opts->parse(); -} catch (Zend_Console_Getopt_Exception $e) { - echo $e->getUsageMessage(); - exit; -} - -// --- Usage -if( isset($opts->help) || count($opts->getOptions())==0 ) -{ - echo "Proxy Event Trigger.\n"; - echo $opts->getUsageMessage(); - exit; -} - -// --- Basic file information -if (empty($opts->file)) { - exit; -} - -$pathParts = pathinfo($opts->file); -$filename = $pathParts['basename']; -$extension = $pathParts['extension']; - -switch($opts->event) -{ - case 'IN_CLOSE_WRITE': - if ($extension == 'tck') { - passthru(__DIR__ . '/tck.php --file '.$opts->file.' >> /home/log/tck.log 2>&1'); - } else { - passthru(__DIR__ . '/send.php --file '.$opts->file.' >> /home/log/send.log 2>&1'); - } - break; - case 'IN_ACCESS': - case 'IN_CLOSE_NOWRITE': - passthru(__DIR__ . '/read.php --file '.$opts->file.' >> /home/log/read.log 2>&1'); - break; - case 'IN_DELETE': - passthru(__DIR__ . '/read.php --file '.$opts->file.' >> /home/log/read.log 2>&1'); - break; -}