diff --git a/application/configs/menu.config.php b/application/configs/menu.config.php index 634c0e7..37246ab 100644 --- a/application/configs/menu.config.php +++ b/application/configs/menu.config.php @@ -1,4 +1,29 @@ "Prestations", + 'title' => "", + 'controller' => 'index', + 'action' => 'index', + 'pages' => array( + array( + 'label' => "Résumé", + 'title' => 'Listes de vos prestations', + 'controller' => 'presta', + 'action' => 'index', + ), + array( + 'label' => "Fichiers", + 'title' => 'Listes de vos fichiers', + 'controller' => 'presta', + 'action' => 'files', + ), + ), + ), + array( + 'label'=> "Contact", + 'title' => "Contact", + 'controller' => 'contact', + 'action' => 'index', + ), ); \ No newline at end of file diff --git a/application/controllers/FileController.php b/application/controllers/FileController.php new file mode 100644 index 0000000..c80bd49 --- /dev/null +++ b/application/controllers/FileController.php @@ -0,0 +1,8 @@ + - Backoffice + WebFiler \ No newline at end of file diff --git a/application/views/user/login.phtml b/application/views/scripts/user/login.phtml similarity index 93% rename from application/views/user/login.phtml rename to application/views/scripts/user/login.phtml index 5ac7035..a265214 100644 --- a/application/views/user/login.phtml +++ b/application/views/scripts/user/login.phtml @@ -13,7 +13,7 @@
- + diff --git a/application/views/user/logout.phtml b/application/views/scripts/user/logout.phtml similarity index 100% rename from application/views/user/logout.phtml rename to application/views/scripts/user/logout.phtml diff --git a/composer.json b/composer.json index af0c974..8469415 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "classmap": [ "application/", "library/Application/", - "library/Scores/", + "library/Scores/" ] }, "authors": [ diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..8b100af --- /dev/null +++ b/composer.lock @@ -0,0 +1,66 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "21cd92d8299580fb00abd42b96cd39d8", + "content-hash": "29c45f207db6f7e602df7361e5d3b32e", + "packages": [ + { + "name": "zendframework/zendframework1", + "version": "1.12.16", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zf1.git", + "reference": "8a3c471ef0a337d303cd5ae578e64c2ba1d2c025" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zf1/zipball/8a3c471ef0a337d303cd5ae578e64c2ba1d2c025", + "reference": "8a3c471ef0a337d303cd5ae578e64c2ba1d2c025", + "shasum": "" + }, + "require": { + "php": ">=5.2.11" + }, + "require-dev": { + "phpunit/dbunit": "1.3.*", + "phpunit/phpunit": "3.7.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.12.x-dev" + } + }, + "autoload": { + "psr-0": { + "Zend_": "library/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "library/" + ], + "license": [ + "BSD-3-Clause" + ], + "description": "Zend Framework 1", + "homepage": "http://framework.zend.com/", + "keywords": [ + "ZF1", + "framework" + ], + "time": "2015-09-15 15:49:51" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/library/Application/Controller/Plugin/Auth.php b/library/Application/Controller/Plugin/Auth.php index 6ba627e..a2e4483 100644 --- a/library/Application/Controller/Plugin/Auth.php +++ b/library/Application/Controller/Plugin/Auth.php @@ -18,81 +18,28 @@ class Application_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract $checkAuth = false; } - // --- Pas d'authentification sur ces services - if ( in_array($controller, array('service', 'import')) - || ( $controller == 'fichier' && $action == 'logs' ) - || ( $controller == 'fichier' && $action == 'kbis' ) - || ( $controller == 'fichier' && $action == 'csv' ) - || ( $controller == 'fichier' && $action == 'associations' ) - || ( $controller == 'fichier' && $action == 'greffes' ) - || ( $controller == 'fichier' && $action == 'crm' )) { - $checkAuth = false; - } - - $checkWs = true; - if ( $controller == 'fichier' ) { - $checkWs = false; - } - if ($checkAuth) { - $login = $request->getParam('login'); - $pass = $request->getParam('pass', ''); - - $hach = $request->getParam('hach'); - if (!empty($hach)) { - $pass = $hach; - } - $auth = Zend_Auth::getInstance(); - // --- On vérifie le tout lors d'une connexion par url - if ( !empty($login) && !empty($pass) ) { + // --- Pas authentifié + if ( !$auth->hasIdentity() || time() > $auth->getIdentity()->time ) { - $authAdapter = new Scores_Auth_Adapter_Db($login, $pass, $checkWs); - $result = $auth->authenticate($authAdapter); + $layout = Zend_Layout::getMVCInstance(); + if (!$layout->isEnabled()){ + echo "Identification incorrect ou périmé."; + } else { + $this->_response->setRedirect('/user/login')->sendResponse(); + } - if ($result->isValid()) { - - $storage = new Zend_Auth_Storage_Session(); - $session = new Zend_Session_Namespace($storage->getNamespace()); - //$session->setExpirationSeconds(86400); - $auth->setStorage($storage); - - } else { - - $layout = Zend_Layout::getMVCInstance(); - if ( !$layout->isEnabled() ){ - echo "Identification incorrect ou périmé."; - } else { - $request->setModuleName('default') - ->setControllerName('user') - ->setActionName('logout'); - } - - } - - //Sinon on reste sur le standard + // --- Authentifié => on met à jour la session } else { - //Pas authentifié - if ( !$auth->hasIdentity() || time() > $auth->getIdentity()->time ) { + $identity = $auth->getIdentity(); + $identity->time = time() + $identity->timeout; + $auth->getStorage()->write($identity); - $layout = Zend_Layout::getMVCInstance(); - if (!$layout->isEnabled()){ - echo "Identification incorrect ou périmé."; - } else { - $this->_response->setRedirect('/user/login')->sendResponse(); - } - - //Authentifié => on met à jour la session - } else { - - $identity = $auth->getIdentity(); - $identity->time = time() + $identity->timeout; - $auth->getStorage()->write($identity); - - } } + } } } \ No newline at end of file diff --git a/library/Application/Controller/Plugin/Menu.php b/library/Application/Controller/Plugin/Menu.php new file mode 100644 index 0000000..7130a9d --- /dev/null +++ b/library/Application/Controller/Plugin/Menu.php @@ -0,0 +1,24 @@ +getControllerName(); + $action = $request->getActionName(); + + if ( $layout->isEnabled() && $controller!='user' ) + { + $view = $layout->getView(); + $config = include APPLICATION_PATH . '/configs/menu.config.php'; + $container = new Zend_Navigation($config); + $view->navigation($container); + } + + } +} \ No newline at end of file diff --git a/library/Application/Model/Sdv1ClientsPresta.php b/library/Application/Model/Sdv1ClientsPresta.php new file mode 100644 index 0000000..150a762 --- /dev/null +++ b/library/Application/Model/Sdv1ClientsPresta.php @@ -0,0 +1,6 @@ + array( + 'columns' => 'idClient', + 'refTableClass' => 'Sdv1Clients', + 'refColumns' => 'id' + ), + ); +} \ No newline at end of file diff --git a/library/Application/Model/WebfilerPrestaDetail.php b/library/Application/Model/WebfilerPrestaDetail.php index b3d9bbc..5595ac9 100644 --- a/library/Application/Model/WebfilerPrestaDetail.php +++ b/library/Application/Model/WebfilerPrestaDetail.php @@ -1 +1,5 @@ _username = $username; + $this->_password = $password; + } + + /** + * Override the timeout + * @param integer $seconds + */ + public function setTimeout($seconds = null) + { + if ($seconds===null) + return; + + $this->_timeout = $seconds; + } + + /** + * (non-PHPdoc) + * @see Zend_Auth_Adapter_Interface::authenticate() + */ + public function authenticate() + { + $userM = new Application_Model_Sdv1Utilisateurs(); + + $sql = $userM->select() + ->setIntegrityCheck(false) + ->from(array('u'=>'user'), array('u.clientId', 'u.id', 'u.login', 'u.password'), 'webfiler') + ->join(array('c'=>'clients'), 'u.clientId = c.id', array(), 'sdv1') + ->where('u.login=?', $this->_username) + ->where('u.deleted=?', 0) + ->where('c.actif=?','Oui'); + + $result = $userM->fetchRow($sql); + + $identity = new stdClass(); + $identity->username = $this->_username; + + if ( null === $result ) { + return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, $identity); + } else { + if ( password_verify($this->_password, $result->password) ) { + $identity->hash = $result->password; + $identity->id = $result->id; + $identity->clientId = $result->clientId; + $timeout = (!empty($result->timeout)) ? $result->timeout : $this->_timeout; + $identity->timeout = $timeout; + $identity->time = time() + $timeout; + return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity); + } else { + return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, $identity); + } + } + } +} \ No newline at end of file diff --git a/public/index.php b/public/index.php index b9e1f0f..1d97b85 100644 --- a/public/index.php +++ b/public/index.php @@ -1,31 +1,15 @@ bootstrap() - ->run(); \ No newline at end of file +// --- Create application, bootstrap, and run +$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); +$application->bootstrap()->run(); \ No newline at end of file diff --git a/public/themes/default/css/main.css b/public/themes/default/css/main.css new file mode 100644 index 0000000..43dfa86 --- /dev/null +++ b/public/themes/default/css/main.css @@ -0,0 +1,56 @@ +/* Sticky footer styles +-------------------------------------------------- */ + +html, +body { + height: 100%; + /* The html and body elements cannot have any padding or margin. */ +} + +/* Wrapper for page content to push down footer */ +#wrap { + min-height: 100%; + height: auto !important; + height: 100%; + /* Negative indent footer by its height */ + margin: 0 auto -60px; + /* Pad bottom by footer height */ + padding: 0 0 60px; +} + +/* Set the fixed height of the footer here */ +#footer { + height: 60px; + background-color: #f5f5f5; +} + + +/* Custom page CSS +-------------------------------------------------- */ +/* Not required for template or sticky footer method. */ +body { font-size:12px; } + +.container .credit { + margin: 20px 0; +} + +#footer > .container { + padding-left: 15px; + padding-right: 15px; +} + +code { + font-size: 80%; +} + +p.bg-classes { + padding:15px; +} + +#wrap .h1, #wrap .h2, #wrap .h3, #wrap h1, #wrap h2, #wrap h3 { + margin-top: 10px; +} + +#wrap .breadcrumb { + margin-bottom: 0px; +} \ No newline at end of file diff --git a/public/themes/default/css/signin.css b/public/themes/default/css/signin.css new file mode 100644 index 0000000..271f9e9 --- /dev/null +++ b/public/themes/default/css/signin.css @@ -0,0 +1,73 @@ +body { + background-color: #eee; +} + +html, +body { + height: 100%; + /* The html and body elements cannot have any padding or margin. */ +} + +/* Wrapper for page content to push down footer */ +#wrap { + min-height: 100%; + height: auto !important; + height: 100%; + /* Negative indent footer by its height */ + margin: 0 auto -60px; + /* Pad bottom by footer height */ + padding: 0 0 60px; +} + +#wrap > .container { + padding: 60px 15px 0; +} +.container .credit { + margin: 20px 0; +} + +/* Set the fixed height of the footer here */ +#footer { + height: 60px; + background-color: #f5f5f5; +} + +#footer > .container { + padding-left: 15px; + padding-right: 15px; +} + +.form-signin { + max-width: 330px; + padding: 15px; + margin: 0 auto; +} +.form-signin .form-signin-heading, +.form-signin .checkbox { + margin-bottom: 10px; +} +.form-signin .checkbox { + font-weight: normal; +} +.form-signin .form-control { + position: relative; + font-size: 16px; + height: auto; + padding: 10px; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +.form-signin .form-control:focus { + z-index: 2; +} +.form-signin input[type="text"] { + margin-bottom: -1px; + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; +} +.form-signin input[type="password"] { + margin-bottom: 10px; + border-top-left-radius: 0; + border-top-right-radius: 0; +} \ No newline at end of file diff --git a/scripts/jobs/file.php b/scripts/jobs/file.php deleted file mode 100644 index b3d9bbc..0000000 --- a/scripts/jobs/file.php +++ /dev/null @@ -1 +0,0 @@ - "Affiche l'aide.", + 'cron' => "Use in crontab", + 'user=s' => "Regen for user et toutes ses prestations", + 'presta=s' => "Regen for a prestation", + ) + ); + $opts->parse(); +} catch (Zend_Console_Getopt_Exception $e) { + echo $e->getUsageMessage(); + exit; +} + +//Usage +if(count($opts->getOptions())==0 || isset($opts->help)) +{ + echo "Integrate file in webfiler."; + echo "\n\n"; + echo $opts->getUsageMessage(); + echo "\n"; + exit; +} + +$c = new Zend_Config($application->getOptions()); +$db = Zend_Db::factory($c->resources->db); + +$prestaSql = $db->select() + ->from(array('p'=>'clients_presta'), array(), 'sdv1') + ->join(array('c'=>'clients'), 'c.id = p.clientId ', 'sdv1') + ->where('p.actif = ?', 1) + ->where('c.actif = ?', 'Oui'); + +$prestaList = $db->fetchAll($prestaSql, Zend_Db::FETCH_OBJ); + +foreach ($prestaList as $p) { + echo date('Y-m-d H:i:s')." - Recherche des paramètres pour la prestation ".$p->code."\n"; + + $params = array(); + $paramSql = $db->select()->from('prestadetail', array(), 'webfiler')->where('prestaCode = ?', $p->code); + $paramResult = $db->fetchAll($paramSql, Zend_Db::FETCH_OBJ); + if (count($paramsResult) > 0) { + foreach ($params as $item) { + $params[$item->name] = $item->value; + } + } else { + echo date('Y-m-d H:i:s')." - Aucun paramètre.\n"; + continue; + } + + // --- Traitement + if (count($params) > 0) { + switch ($params['type']) { + case 'db': + // --- Lecture de la base de données pour obtenir la liste des fichiers + $stmt = $db->query($sql); + $rows = $stmt->fetchAll(Zend_Db::FETCH_OBJ); + if (count($rows) > 0) { + foreach ($rows as $f) { + $directory = $f->directory; + if (substr($f->directory, -1) == '/') { + $directory = substr($f->directory, 0, strlen($f->directory)-1); + } + if (substr($directory, 0, 1) == '/') { + $filename = $directory.'/'.$f->file; + } else { + $filename = $c->profil->path->secure.'/'.$directory.'/'.$f->file; + } + + if (file_exists($filename)) { + + $fileDate = filectime($filename); + $fileSize = filesize($filename); + $fileMd5 = md5_file($filename); + $fileSha1 = sha1_file($filename); + + // --- Enregistrer dans la base + + } + } + } + break; + case 'file': + // --- Lecture du repertoire pour obtenir la liste des fichiers + $directory = $params['directory']; + if (substr($params['directory'], -1) == '/') { + $directory = substr($params['directory'], 0, strlen($params['directory'])-1); + } + if (substr($directory, 0, 1) != '/') { + $directory = $c->profil->path->secure.'/'.$directory; + } + if ($handle = opendir($directory)) { + while (false !== ($file = readdir($handle))) { + if ($file != "." && $file != "..") { + + // --- Masque de fichier + if (array_key_exists('filemask', $params)) { + $pattern = '/'.$params['filemask'].'/'; + if (!preg_match($pattern, $file)) { + continue; + } + } + + $filename = $directory.'/'.$file; + $fileDate = filectime($filename); + + // --- Calcul du nombre de jours + $dateNow = new Zend_Date(); + $dateFile = new Zend_Date($fileDate, Zend_Date::TIMESTAMP); + $difference = $dateNow->sub($dateFile); + $measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::DAY); + $measure->convertTo(Zend_Measure_Time::DAY); + $nbJour = $measure->getValue(0); + if ($nbJour > $params['maxkeepday']) { + continue; + } + $fileSize = filesize($filename); + $fileMd5 = md5_file($filename); + $fileSha1 = sha1_file($filename); + + // --- Enregistrer dans la base + + } + } + closedir($handle); + } + break; + default: + echo date('Y-m-d H:i:s')." - Type inconnu.\n"; + break; + } + } +} \ No newline at end of file