Example #1
0
File: Login.php Project: dafik/dfi
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     Zend_Auth::getInstance()->setStorage(new Dfi_Auth_Storage_Cookie('user'));
     /** @var Zend_Controller_Request_Http $request */
     $request = $this->getRequest();
     $bypass = $this->isBypassRequest($request->getModuleName(), $request->getControllerName(), $request->getActionName());
     if (!Zend_Auth::getInstance()->hasIdentity() && !$bypass) {
         if ($request->isXmlHttpRequest()) {
             $response = $this->getResponse();
             $data = array('auth' => true);
             $output = json_encode($data);
             $response->setHeader('Content-Type', 'application/json', true);
             $this->getResponse()->setBody($output);
             $this->getResponse()->sendResponse();
             exit;
         } else {
             if ($request->getControllerName() == 'index' && $request->getActionName() == 'index') {
                 if (!Zend_Layout::getMvcInstance()) {
                     $layoutPath = Dfi_App_Config::get('layout.layoutPath');
                     Zend_Layout::startMvc($layoutPath);
                 }
             }
             $request->setControllerName('login');
             $request->setActionName('index');
             $request->setModuleName('default');
         }
     }
 }
Example #2
0
 public function hash($password)
 {
     $salt = Dfi_App_Config::get('main.auth.salt');
     $hash = Dfi_App_Config::get('main.auth.hash');
     $enc = hash($hash, $salt . $password . $salt, true);
     $x = strlen($enc);
     return $enc;
 }
Example #3
0
 public function __construct($username, $password)
 {
     $this->username = $username;
     $this->password = $password;
     if (Dfi_App_Config::get('main.useFakeLogin')) {
         $this->useFakeLogin = true;
     }
 }
Example #4
0
 private function setup()
 {
     $this->cwd = getcwd();
     $this->_initPaths($this->cwd . '/application');
     $this->_readAppConfig();
     $includeConfig = Dfi_App_Config::get('phpSettings.include_path', '');
     $this->_initIncludePaths($includeConfig);
     Zend_Loader_Autoloader::getInstance()->registerNamespace('Dfi_')->suppressNotFoundWarnings(true);
 }
Example #5
0
File: Ami.php Project: dafik/dfi
 /**
  * return AMI client and create if not exist
  * @return Dfi_Asterisk_Client
  */
 private static function getAmiClient()
 {
     if (!Dfi_Asterisk_Ami::$amiClient instanceof ClientImpl) {
         $config = self::getConfig();
         $c = new Zend_Config_Ini(APPLICATION_PATH . '/configs/sys/log4php-pami.conf.php');
         $config["log4php.properties"] = $c->toArray();
         $config["log4php.properties"]['appenders']['appender']['default']['file'] = Dfi_App_Config::get('paths.log') . 'ami.log';
         $client = new Dfi_Asterisk_Client($config);
         if (!Dfi_App_Config::getString('asterisk.fake', true)) {
             $client->open();
         }
         Dfi_Asterisk_Ami::$amiClient = $client;
     }
     return Dfi_Asterisk_Ami::$amiClient;
 }
Example #6
0
 protected function _initDatabase()
 {
     if (Zend_Loader::isReadable(Dfi_App_Config::get('db.config'))) {
         try {
             $logger = Zend_Registry::get('propelLogger');
             $adapter = new Dfi_Log_Adapter_Propel2Zend($logger);
             require_once 'Propel.php';
             Propel::setLogger($adapter);
             Propel::init(Dfi_App_Config::get('db.config'));
         } catch (Exception $e) {
             throw new Exception('Can\'t setup database: ' . $e->getMessage());
         }
     } else {
         throw new Exception('database config read failed');
     }
 }
Example #7
0
 public static function shutdown()
 {
     $isError = false;
     if ($error = error_get_last()) {
         switch ($error['type']) {
             case E_ERROR:
                 // 1
             // 1
             case E_CORE_ERROR:
                 // 16
             // 16
             case E_COMPILE_ERROR:
                 // 64
             // 64
             case E_USER_ERROR:
                 //256
             //256
             case E_PARSE:
                 //4
                 $isError = true;
                 break;
             case E_WARNING:
                 //2
             //2
             case E_NOTICE:
                 //8
             //8
             case E_CORE_WARNING:
                 //32
             //32
             case E_COMPILE_WARNING:
                 //128
             //128
             case E_USER_WARNING:
                 //512
             //512
             case E_USER_NOTICE:
                 //1024
             //1024
             case E_STRICT:
                 //2048
                 break;
         }
     }
     if ($isError) {
         http_response_code(500);
         $guid = false;
         try {
             $e = new ErrorException($error['message'], 0, 1, $error['file'], $error['line']);
             //$guid = Dfi_Error_Report::saveException($e);
         } catch (Exception $e) {
             $guid = false;
         }
         if (!preg_match('/cli/', php_sapi_name())) {
             Zend_Registry::get('shutdownLogger')->log($error['message'] . ' : ' . $error['file'] . ' : (' . $error['line'] . ')', Zend_Log::CRIT);
             if (!Dfi_App_Config::get('main.showDebug')) {
                 $url = "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s://" : "://") . $_SERVER['HTTP_HOST'] . '/';
                 header("Location: " . $url . "error/error" . ($guid ? '/guid/' . $guid : ''));
                 exit;
             } else {
                 ob_clean();
                 echo '<pre>REPORT: ' . ($guid ? $guid : 'brak') . "\n";
                 echo 'REQUEST: ' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') . "\n";
                 echo 'REFERER: ' . (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '') . "\n";
                 echo 'ERROR: ' . $e->getMessage() . ' : ' . $e->getFile() . ' : (' . $e->getLine() . ')' . "\n" . $e->getTraceAsString() . '</pre>';
             }
         }
     }
 }
Example #8
0
File: AD.php Project: dafik/dfi
 public function resetPassword($login)
 {
     $options = array('unicodePwd' => $this->encodeUnicodePassword(Dfi_App_Config::get('ad.defaultPassword')), 'pwdLastSet' => 0);
     $res = $this->updateByLogin($login, $options);
     return $res;
 }
Example #9
0
 private function _mergeRuntime($ormDir, $configs)
 {
     $files = array();
     $default = Dfi_App_Config::get('generator.default');
     foreach ($configs as $config) {
         $runtimeFile = $ormDir . '/' . $config . '/' . $config . '-runtime-conf.xml';
         $files[] = $runtimeFile;
     }
     $defaultIndex = array_search($default, $configs);
     $main = $files[$defaultIndex];
     unset($files[$defaultIndex]);
     $destinationDocument = new DOMDocument();
     $destinationDocument->preserveWhiteSpace = false;
     $destinationDocument->formatOutput = true;
     $res = $destinationDocument->loadXML(file_get_contents($main));
     if (!$res) {
         ZFscaffold_ZfTool_Helpers_Messages::printOut('error loding xml  runtime conf ' . $main, ZFscaffold_ZfTool_Helpers_Messages::MSG_ERROR);
     }
     foreach ($files as $file) {
         $docSource = new DOMDocument();
         $res = $docSource->loadXML(file_get_contents($file));
         if (!$res) {
             ZFscaffold_ZfTool_Helpers_Messages::printOut('error loding xml  runtime conf ' . $file, ZFscaffold_ZfTool_Helpers_Messages::MSG_ERROR);
         }
         $xpath = new DOMXPath($docSource);
         $result = $xpath->query('//datasource');
         foreach ($result as $node) {
             $result = $destinationDocument->importNode($node, true);
             //Copy the node to the other document
             $items = $destinationDocument->getElementsByTagName('datasources')->item(0);
             $items->appendChild($result);
             //Add the copied node to the destination document
         }
     }
     foreach ($configs as $config) {
         $runtimeFile = $ormDir . '/' . $config . '/runtime-conf.xml';
         $res = $destinationDocument->save($runtimeFile);
         if (!$res) {
             ZFscaffold_ZfTool_Helpers_Messages::printOut('error writing runtime conf ' . $runtimeFile, ZFscaffold_ZfTool_Helpers_Messages::MSG_ERROR);
         }
     }
 }
Example #10
0
 private function _setup()
 {
     $this->cwd = getcwd();
     $this->_initPaths($this->cwd . '/application');
     $this->_readAppConfig();
     $includeConfig = Dfi_App_Config::get('phpSettings.include_path', '');
     $this->_initIncludePaths($includeConfig);
     Zend_Loader_Autoloader::getInstance()->registerNamespace('Dfi_')->suppressNotFoundWarnings(true);
     foreach (Dfi_App_Config::getConfig(true, false, array(), 'scaffold') as $key => $value) {
         $method = '_' . $key;
         if (property_exists($this, $method)) {
             $this->{$method} = $value;
         }
     }
     $propelConfig = Dfi_App_Config::get('db.config', null);
     if (null === $propelConfig) {
         $projectProvider = $this->_registry->getProviderRepository()->getProvider('propelorm');
         $projectProvider->generate();
     }
     $this->_initPropel($propelConfig);
     $this->_packageName = $this->_getCamelCase(Propel::getConfiguration()['datasources']['default']);
 }