442 lines
17 KiB
PHP
442 lines
17 KiB
PHP
<?php
|
|
|
|
class Default_IndexController extends Zend_Controller_Action
|
|
{
|
|
|
|
/* Proprietà Controller */
|
|
protected $_urlHelper;
|
|
protected $_genericModel;
|
|
protected $_restModel;
|
|
protected $_authService;
|
|
protected $_configs;
|
|
protected $_translate;
|
|
protected $_ipManager;
|
|
protected $_VariabiliSito;
|
|
protected $_rsaCryptor;
|
|
|
|
protected App_Service_JsonConfiguration $_datiAziendali;
|
|
protected App_Service_JsonConfiguration $_parametriSito;
|
|
|
|
/* Dati metatag del sito */
|
|
private $_KEYWORDS;
|
|
private $_TITLE;
|
|
private $_DESCRIPTION;
|
|
|
|
/* Dati per le sezioni dinamiche del sito */
|
|
private $_MENUITEM;
|
|
private $_PAGENAME;
|
|
private $_SUBTITLE;
|
|
|
|
private $_COOKIE_EXPIRE_TIME;
|
|
private $_COOKIE_SITE_CREDENTIALS;
|
|
|
|
public function init()
|
|
{
|
|
|
|
$this->_helper->layout->setLayout('layout');
|
|
$this->_urlHelper = $this->_helper->getHelper('url');
|
|
$this->_authService = new App_Service_Auth();
|
|
$this->_genericModel = new Application_Model_Generic();
|
|
$this->_restModel = new Application_Model_Rest();
|
|
$this->_configs = new App_Service_ConfigManager();
|
|
$this->_translate = Zend_Form::getDefaultTranslator();
|
|
$this->_ipManager = new App_Service_IpManager();
|
|
$this->_rsaCryptor = new App_Service_RsaCryptor();
|
|
|
|
$this->_VariabiliSito = new App_Service_VariabiliSito();
|
|
$this->_datiAziendali = new App_Service_JsonConfiguration('dati_aziendali');
|
|
$this->_parametriSito = new App_Service_JsonConfiguration("parametri_sito");
|
|
|
|
$this->_TITLE = "home";
|
|
$this->_DESCRIPTION = "";
|
|
$this->_KEYWORDS = "";
|
|
|
|
$this->_TITLE = $this->_parametriSito->get('base_title');
|
|
$this->_DESCRIPTION = "";
|
|
$this->_KEYWORDS = $this->_parametriSito->get('base_keywords');
|
|
|
|
$BASE_COOKIE_STRING = strtolower(Zend_Registry::get('ENVIROMENTS')->get('site_short_id')) . '_';
|
|
|
|
$this->_COOKIE_EXPIRE_TIME = time() + (86400 * 30);
|
|
$this->_COOKIE_SITE_CREDENTIALS = $BASE_COOKIE_STRING . "CREDENTIALS";
|
|
}
|
|
|
|
public function preDispatch()
|
|
{
|
|
|
|
$action = $this->getRequest()->getActionName();
|
|
if ($this->_configs->get('interrutore_sito') == 'off' && $action != 'login' && $action != 'authenticate' && $action != 'offline' && !$this->_ipManager->allowedIp()) {
|
|
$this->_helper->redirector('offline', 'index', 'default');
|
|
}
|
|
|
|
if (Zend_Registry::get('Zend_Locale') == 'it') {
|
|
$this->view->lang = 'it';
|
|
} else {
|
|
$this->view->lang = 'en';
|
|
}
|
|
|
|
$this->view->action = $action;
|
|
$this->view->controller = $this->getRequest()->getControllerName();
|
|
|
|
$this->view->enableTestSdk = $this->_ipManager->controllaAbilitazioneTestSdk();
|
|
}
|
|
|
|
public function postDispatch()
|
|
{
|
|
$this->view->title = $this->_TITLE;
|
|
$this->view->keywords = $this->_KEYWORDS;
|
|
$this->view->description = $this->_DESCRIPTION;
|
|
|
|
$this->view->menuitem = $this->_MENUITEM;
|
|
$this->view->pagename = $this->_PAGENAME;
|
|
$this->view->subtitle = $this->_SUBTITLE;
|
|
|
|
$this->view->parametriSito = $this->_parametriSito->getAllParams();
|
|
$this->view->datiAziendali = $this->_datiAziendali->getAllParams();
|
|
}
|
|
|
|
public function offlineAction()
|
|
{
|
|
$this->_DESCRIPTION .= "Il Sito è in manutenzuione";
|
|
if ($this->_configs->get('interrutore_sito') == 'off') {
|
|
$this->_helper->getHelper('layout')->disableLayout();
|
|
} else {
|
|
$this->_helper->redirector('index', 'index');
|
|
}
|
|
}
|
|
|
|
public function loginAction()
|
|
{
|
|
$this->_helper->layout->setLayout('admin');
|
|
|
|
$this->view->moduleName = 'default';
|
|
$this->view->eventLoader = 'login';
|
|
$this->view->formData = $this->recuperaCredenziali();
|
|
|
|
if (isset($this->_authService->getAuth()->getIdentity()->username))
|
|
$this->_helper->redirector('index', $this->_authService->getAuth()->getIdentity()->role);
|
|
}
|
|
|
|
public function authenticateAction()
|
|
{
|
|
$this->_helper->layout->setLayout('admin');
|
|
|
|
$this->view->moduleName = 'default';
|
|
$this->view->eventLoader = 'login';
|
|
$this->view->formData = $this->recuperaCredenziali();
|
|
|
|
if (!$this->getRequest()->isPost()) {
|
|
return $this->_helper->redirector('index');
|
|
}
|
|
|
|
$form = new Application_Form_Default_Index_Auth_Login();
|
|
if (!$form->isValid($this->getRequest()->getPost())) {
|
|
$this->view->error = 'I campi sono richiesti';
|
|
|
|
$this->render('login');
|
|
return false;
|
|
}
|
|
|
|
if (false === $this->_authService->authenticate($form->getValues())) {
|
|
$this->view->error = 'Le credenziali non sono valide!';
|
|
$this->render('login');
|
|
return false;
|
|
}
|
|
|
|
//memorizzo le credenziali se necessario
|
|
$data = $form->getValues();
|
|
if ($data['ricorda_password'] == 'on') {
|
|
try {
|
|
$data['password'] = $this->_rsaCryptor->cripta($data['password']);
|
|
setcookie($this->_COOKIE_SITE_CREDENTIALS, Zend_Json::encode($data), $this->_COOKIE_EXPIRE_TIME, "/");
|
|
} catch (Exception $e) {
|
|
}
|
|
} else {
|
|
setcookie($this->_COOKIE_SITE_CREDENTIALS, "", $this->_COOKIE_EXPIRE_TIME, "/");
|
|
}
|
|
|
|
//Accesso andato a buon fine
|
|
|
|
//Generazione del Token temporaneo per l'accesso
|
|
$user = $this->_authService->getIdentity();
|
|
|
|
if ($user->role !== 'admin') {
|
|
if ($user->token != null) {
|
|
$token = $user->token; //Esistente uso quello già presente
|
|
} else {
|
|
do { //se non esiste ne genero uno nuovo e controllo che sia univoco
|
|
$token = hash('sha1', $user->username . date('YmdHis') . mt_rand(5, 10));
|
|
if ($this->_genericModel->getByColumnName('Users', 'token', $token)) {
|
|
$exist = true;
|
|
} else {
|
|
$exist = false;
|
|
}
|
|
$user->token = $token;
|
|
} while ($exist);
|
|
}
|
|
|
|
$this->_genericModel->update('Users', $user->id, array('UltimoLogin' => date('Y-m-d H:i:s'), 'token' => $token));
|
|
} else {
|
|
$this->_genericModel->update('Users', $user->id, array('UltimoLogin' => date('Y-m-d H:i:s')));
|
|
}
|
|
|
|
$this->_genericModel->insert('Accesslog', array('ip' => $_SERVER['REMOTE_ADDR'], 'tipo' => $this->_authService->getIdentity()->role));
|
|
|
|
return $this->_helper->redirector('index', 'index', $this->_authService->getIdentity()->role);
|
|
}
|
|
|
|
public function indexAction()
|
|
{
|
|
// $this->_helper->getHelper('layout')->disableLayout();
|
|
|
|
/*if (isset($this->_authService->getAuth()->getIdentity()->username))
|
|
$this->_helper->redirector('index', $this->_authService->getAuth()->getIdentity()->role);
|
|
else
|
|
$this->_helper->redirector('login', 'index', 'default');*/
|
|
}
|
|
|
|
/**
|
|
* =====================================================================================================================
|
|
* ========= ELENCO PAGINE STATIC ACTION ===============================================
|
|
* =====================================================================================================================
|
|
*/
|
|
|
|
public function assistenzaAction()
|
|
{
|
|
|
|
}
|
|
|
|
/*public function caratteristicheAction()
|
|
{
|
|
|
|
}*/
|
|
|
|
public function acquistaAction()
|
|
{
|
|
|
|
}
|
|
|
|
public function shopAction()
|
|
{
|
|
|
|
}
|
|
|
|
public function downloadsoftwareAction()
|
|
{
|
|
|
|
}
|
|
|
|
public function copyrightAction()
|
|
{
|
|
|
|
}
|
|
|
|
public function privacyAction()
|
|
{
|
|
$this->redirect("https://www.iubenda.com/privacy-policy/70038880");
|
|
}
|
|
|
|
public function cookiepolicyAction()
|
|
{
|
|
$this->redirect("https://www.iubenda.com/privacy-policy/70038880/cookie-policy");
|
|
}
|
|
|
|
/**
|
|
* =====================================================================================================================
|
|
* ========= ACTION SPECIALI ===========================================================
|
|
* =====================================================================================================================
|
|
*/
|
|
|
|
public function resetpasswordAction()
|
|
{
|
|
$this->_helper->layout->setLayout('admin');
|
|
|
|
$this->view->moduleName = 'default';
|
|
$rcode = $this->getParam('rcode', null);
|
|
$this->view->hideForm = false;
|
|
$this->view->rcode = $rcode;
|
|
|
|
if (!$rcode && $this->getRequest()->isPost()) {
|
|
|
|
$email = $this->_getParam('Email', null);
|
|
if (!$email) {
|
|
$this->view->errorMessage = "Inserire un email corretta!";
|
|
return;
|
|
}
|
|
|
|
$users = $this->_genericModel->getByColumnName('Users', 'Email', $email);
|
|
if (!$users || !$users['stato'] || $users['role'] === 'admin') {
|
|
$this->view->warningMessage = "Nessuna corrispondenza per l'email inserita.";
|
|
$this->view->hideForm = true;
|
|
return;
|
|
}
|
|
|
|
if ($users['NumeroResetPw'] > 5) {
|
|
$this->view->warningMessage = "Hai effettuato troppe richieste per il reseet password, attendi 48 ore o contatta l'amministrazione su xxxx";
|
|
$this->view->hideForm = true;
|
|
return;
|
|
}
|
|
|
|
//Genero rcode e incremento il numero di richieste già effettuate per il limite max
|
|
$numeroReset = ($users['NumeroResetPw']) ? $users['NumeroResetPw'] : 0;
|
|
$numeroReset += 1;
|
|
$rcode = md5($users['PartitaIva'] . date('YmdHis'));
|
|
$this->_genericModel->update('Users', $users['id'], array('DataRichiestaResetPw' => date('Y-m-d H:i:s'), 'rcode' => $rcode, 'NumeroResetPw' => $numeroReset));
|
|
$users['rcode'] = $rcode;
|
|
|
|
//Invio email di recupero
|
|
$this->inviaEmailDiRecuperoPassword($users);
|
|
|
|
$this->view->successMessage = "Ti è stata inviata una email per effettuare il reset della password, consulta la tua casella di posta e segui le istruzioni.";
|
|
$this->view->hideForm = true;
|
|
return;
|
|
}
|
|
|
|
// FINE RICHIESTA
|
|
|
|
// INIZIO RESET PASSWORD
|
|
|
|
if ($rcode) {
|
|
|
|
//Controllo del codice rcode
|
|
$utente = $this->_genericModel->getByColumnName('Users', 'rcode', $rcode);
|
|
if (!$utente) {
|
|
$this->view->warningMessage = "La richiesta è scaduta, effettuare una nuova richiesta!";
|
|
$this->view->rcode = false;
|
|
return;
|
|
}
|
|
|
|
|
|
if ($this->getRequest()->isPost()) {
|
|
$form = new Application_Form_Default_Index_Auth_ResetPw();
|
|
if (!$form->isValid($this->getAllParams())) {
|
|
$this->view->errorMessage = "Ci sono errori di compilazione, controllare i campi!";
|
|
$this->view->errorForm = $form->getMessages();
|
|
$this->view->formData = $form->getValues();
|
|
return;
|
|
}
|
|
|
|
$data = $form->getValues();
|
|
$nuovaPassword = md5(Zend_Registry::get('ENVIROMENTS')->get('password_salt') . $data['password']);
|
|
|
|
//Inserimento nuova password nel db
|
|
$this->_genericModel->update('Users', $utente['id'], array('password' => $nuovaPassword, 'rcode' => null, 'NumeroResetPw' => 0));
|
|
$this->view->successMessage = 'La password è stata reimpostata correttamente, effettua un nuovo login <a href="' .
|
|
$this->_urlHelper->url(array('action' => 'login', 'controller' => 'index'), 'default', true) . '">cliccando qui.</a>';
|
|
$this->view->hideForm = true;
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function sendcontactAction()
|
|
{
|
|
$this->_helper->getHelper('layout')->disableLayout();
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
if ($this->getRequest()->isXmlHttpRequest()) {
|
|
|
|
$form = new Application_Form_Index_Contact_Add();
|
|
if (!$form->isValid($this->getAllParams())) {
|
|
return $this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody(Zend_Json::encode(array(
|
|
'success' => false,
|
|
'message' => $form->getMessages(),
|
|
)));
|
|
}
|
|
|
|
try {
|
|
$emailTemplate = $this->_genericModel->getByColumnName('EmailTemplate', 'Codice', $this->_configs->get('email_contatto_template'));
|
|
if (!$emailTemplate) {
|
|
return $this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody(Zend_Json::encode(array(
|
|
'success' => false,
|
|
'message' => "Email template non trovato o non assegnato",
|
|
)));
|
|
}
|
|
|
|
$this->_helper->Email->sendEmailByTemplate($this->_configs->get('email_primo_contatto'), $emailTemplate, $form->getValues());
|
|
|
|
//Incremento il contatore contatti email
|
|
$numContatti = $this->_VariabiliSito->get('I_Numero_Contatti_Email');
|
|
$this->_VariabiliSito->set('I_Numero_Contatti_Email', ++$numContatti);
|
|
|
|
$response['success'] = true;
|
|
} catch (Zend_Exception $e) {
|
|
return $this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody(Zend_Json::encode(array(
|
|
'success' => false,
|
|
'message' => "si è verificato un errore durante l'invio del messaggio",
|
|
)));
|
|
}
|
|
|
|
$this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody(Zend_Json::encode($response));
|
|
} else {
|
|
$this->getResponse()->setHeader('Content-type', 'application/json;charset=UTF-8')->setBody(Zend_Json::encode(array('success' => false, 'errore' => 'Operazione non consentita')));
|
|
}
|
|
}
|
|
|
|
public function sitemapAction()
|
|
{
|
|
|
|
$this->_helper->getHelper('layout')->disableLayout();
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
header('Content-type: text/xml');
|
|
header('Pragma: public');
|
|
header('Cache-control: private');
|
|
header('Expires: -1');
|
|
echo '<?xml version="1.0" encoding="UTF-8"?>';
|
|
echo '<urlset
|
|
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
|
|
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
|
|
|
|
/*echo '<url>';
|
|
echo '<loc>https://sfdasdas.com/</loc>';
|
|
echo '<changefreq>monthly</changefreq>';
|
|
echo '</url>';*/
|
|
|
|
echo '</urlset>';
|
|
}
|
|
|
|
/**
|
|
* =====================================================================================================================
|
|
* ========= FUNZIONI PRIVATE DEL CONTROLLER ===========================================
|
|
* =====================================================================================================================
|
|
*/
|
|
|
|
private function recuperaCredenziali()
|
|
{
|
|
//Recupero eventuali credenziali memorizzate
|
|
if (isset($_COOKIE[$this->_COOKIE_SITE_CREDENTIALS])) {
|
|
$credentials = Zend_Json::decode($_COOKIE[$this->_COOKIE_SITE_CREDENTIALS]);
|
|
if ($credentials['ricorda_password'] == 'on') {
|
|
try {
|
|
$credentials['password'] = $this->_rsaCryptor->decripta($credentials['password']);
|
|
} catch (Exception $e) {
|
|
$credentials = array('ricorda_password' => 'off');
|
|
}
|
|
return $credentials;
|
|
}
|
|
}
|
|
|
|
return array('ricorda_password' => 'on');
|
|
}
|
|
|
|
private function inviaEmailDiRecuperoPassword($user)
|
|
{
|
|
|
|
//Invio email per conferma
|
|
$emailTemplate = $this->_genericModel->getByColumnName('EmailTemplate', 'Codice', 'EMAIL_RECUPERO_PASSWORD');
|
|
if (!$emailTemplate) {
|
|
throw new Exception("Errore invio email richiesta recupero password");
|
|
}
|
|
|
|
$params = $user;
|
|
$params['link'] = $this->getRequest()->getScheme() . '://' . $this->getRequest()->getHttpHost()
|
|
. $this->_urlHelper->url(array('rcode' => $params['rcode']), 'resetpassword', true);
|
|
$this->_helper->Email->sendEmailByTemplate($params['Email'], $emailTemplate, $params);
|
|
}
|
|
|
|
}
|
|
|