Files
2021-09-17 12:41:45 +02:00

74 lines
1.9 KiB
PHP

<?php
class App_Service_IpManager
{
protected $_configs;
protected $_enviroments;
protected $_allowedHostList;
public function __construct()
{
$this->_configs = Zend_Registry::get('config');
$this->_enviroments = Zend_Registry::get('ENVIROMENTS');
$this->_allowedHostList = array();
}
/**
* Aggiorna l'oggetto config ricaricando tutte le impostazioni memorizzate
* nel file config.ini
*/
public function allowedIp()
{
$ip_consentiti = explode(',',$this->_configs->get('ip_alternativo'));
$ip_master = trim($this->_configs->get('ip_master'));
$ip_server = trim($this->_configs->get('ip_server'));
if(in_array($_SERVER['REMOTE_ADDR'], array_merge([$ip_master], [$ip_server], $ip_consentiti))){
return true;
}
return false;
}
public function allowedHost(Zend_Controller_Request_Http $request){
$host = $request->getServer();
$host = $host['SERVER_NAME'];
if(preg_match('/'.implode('|', $this->_allowedHostList).'/',$host)){
return true;
}
return false;
}
public function allowedDevMode(){
return (APPLICATION_ENV === 'development');
}
public function allowedDevAndStagingMode(){
return (APPLICATION_ENV === 'development' || APPLICATION_ENV === 'staging');
}
public function controllaAbilitazioneTestSdk(){
return $this->allowedDevMode();
}
public function getMongoAdminDbName(){
return $this->_enviroments->get('mongodb')->get('params')->get('dbname');
}
public function getMongoDbName($nomeDb){
switch (APPLICATION_ENV){
case 'development':
return $nomeDb.'_dev';
case 'staging':
return $nomeDb.'_test';
default:
case 'production':
return $nomeDb;
}
}
}