Example #1
0
 /**
  * 获取用户权限
  *
  */
 public function getAccess()
 {
     if (null === $this->_access) {
         $key = self::CACHE_KEY_ACCESS . strtolower($this->_attrs['username']);
         $access = self::$_memcache->get($key);
         if (!$access) {
             /* @var $daoAccess Dao_Md_Access_Access */
             $daoAccess = Tudu_Dao_Manager::getDao('Dao_Md_Access_Access', Tudu_Dao_Manager::DB_MD);
             $access = $daoAccess->getUserAccess($this->orgId, $this->userId);
             self::$_memcache->set($key, $access, null, 86400);
         }
         $this->_access = new Tudu_Access($access);
     }
     return $this->_access;
 }
Example #2
0
 /**
  * (non-PHPdoc)
  * @see OpenApi_OAuth_Storage_Interface::getRefreshToken()
  */
 public function getRefreshToken($refreshToken)
 {
     return $this->_memcache->get($this->_makeRefreshTokenKey($refreshToken));
 }
Example #3
0
 /**
  * Retrieve item from the storage
  * 
  * @param string $key
  */
 public function get($key)
 {
     return $this->_storage->get($key);
 }
Example #4
0
 /**
  * 连接资源监控
  */
 public function checkConfigAction()
 {
     //
     $message = array();
     $ts = time();
     $count = array('warning' => 0, 'error' => 0);
     $queueName = 'check';
     $memcacheKey = 'TUDU-CHECK-MARK';
     if (defined('WWW_ROOT')) {
         $sites = array('www.tudu.com', 'api.tudu.com', 'admin.tudu.com', 'web.tudu.com');
         // 先写入数据,遍历各站点时读取
         // memcache
         $ret = $this->cache->set($memcacheKey, $ts, null);
         if (!$ret) {
             $message[] = "[ERROR] Memcache prepare failure";
             $count['error']++;
         } else {
             $message[] = "[SUCCESS] Memcache prepare success";
         }
         $this->cache->close();
         // httpsqs
         $cfg = $this->options['httpsqs'];
         $httpsqs = new Oray_Httpsqs($cfg['host'], $cfg['port'], $cfg['chartset'], $queueName);
         $ret = $httpsqs->put($ts, $queueName);
         if (!$ret) {
             $count['error']++;
             $message[] = "[ERROR] Httpsqs prepare failure";
         } else {
             $message[] = "[SUCCESS] Httpsqs prepare success";
         }
         $queueStatus = $httpsqs->status($queueName);
         if ($count['error'] <= 0) {
             foreach ($sites as $site) {
                 $configFile = WWW_ROOT . '/htdocs/' . $site . '/application/configs/application.ini';
                 $message[] = '-=' . $site . '=-';
                 try {
                     $config = new Zend_Config_Ini($configFile, 'production');
                 } catch (Zend_Config_Exception $e) {
                     $message[] = '[ERROR] Config read failure';
                     continue;
                 }
                 $config = $config->toArray();
                 if (!empty($config['resources']['multidb'])) {
                     // 遍历数据库配置
                     foreach ($config['resources']['multidb'] as $k => $opt) {
                         $dbParams = array();
                         $adapterName = '';
                         foreach ($opt as $n => $v) {
                             if ($n == 'adapter') {
                                 $adapterName = $v;
                             } else {
                                 $dbParams[$n] = $v;
                             }
                         }
                         try {
                             $db = Zend_Db::factory($adapterName, $dbParams);
                             if (false !== strpos($adapterName, 'oci')) {
                                 $db->query("SELECT 1 FROM TUDU_LOG");
                             } else {
                                 $db->query("SELECT 1");
                             }
                             $message[] = "[SUCCESS] Database \"{$k}\" success";
                         } catch (Zend_Db_Exception $e) {
                             $message[] = "[ERROR] Database \"{$k}\" failure: " . $e->getMessage();
                             $count['error']++;
                         }
                     }
                 }
                 // 匹配memcache,获取指定key,匹配当前检测插入的值
                 if (!empty($config['resources']['memcache'])) {
                     $memcache = new Oray_Memcache($config['resources']['memcache']);
                     $mv = $memcache->get($memcacheKey);
                     if ($mv != $ts) {
                         $message[] = "[WARNING] memcache get failure or value not match:{$mv}";
                         $count['warning']++;
                     } else {
                         $message[] = "[SUCCESS] memcache match success";
                     }
                     $memcache->close();
                 }
                 // 匹配httpsqs
                 if (!empty($config['httpsqs'])) {
                     $cfg = $config['httpsqs'];
                     $charset = isset($cfg['chartset']) ? $cfg['chartset'] : $cfg['charset'];
                     $httpsqs = new Oray_Httpsqs($cfg['host'], $cfg['port'], $charset, $queueName);
                     $status = $httpsqs->status($queueName);
                     if (!$status || $status['put'] != $queueStatus['put'] || $status['get'] != $queueStatus['get'] || $status['unread'] != $queueStatus['unread']) {
                         $message[] = "[WARNING] httpsqs status not match";
                         $count['warning']++;
                     } else {
                         $message[] = "[SUCCESS] httpsqs status match success";
                     }
                 }
             }
             // 检测脚本配置
             $scriptConfig = WWW_ROOT . '/scripts/task/configs/config.ini';
             $message[] = "-=task=-";
             $config = null;
             try {
                 $config = new Zend_Config_Ini($scriptConfig, 'production');
             } catch (Zend_Config_Exception $e) {
                 $message[] = '[ERROR] Config read failure';
             }
             if ($config) {
                 $config = $config->toArray();
                 if (!empty($config['multidb'])) {
                     foreach ($config['multidb'] as $k => $opt) {
                         try {
                             $db = Zend_Db::factory($opt['adapter'], $opt['params']);
                             if (false !== strpos($opt['adapter'], 'oci')) {
                                 $db->query("SELECT 1 FROM TUDU_LOG");
                             } else {
                                 $db->query("SELECT 1");
                             }
                             $message[] = "[SUCCESS] Database \"{$k}\" success";
                         } catch (Zend_Db_Exception $e) {
                             $message[] = "[WARNING] Database \"{$k}\" failure: " . $e->getMessage();
                             $count['warning']++;
                         }
                     }
                 }
                 if (!empty($config['memcache'])) {
                     $cfg = $config['memcache'];
                     $cfg['servers'] = array('host' => $cfg['host'], 'port' => $cfg['port'], 'timeout' => $cfg['timeout']);
                     $memcache = new Oray_Memcache($cfg);
                     $mv = $memcache->get($memcacheKey);
                     if ($mv != $ts) {
                         $message[] = "[WARNING] memcache get failure or value not match: {$mv}";
                         $count['warning']++;
                     } else {
                         $message[] = "[SUCCESS] memcache match success";
                     }
                 }
                 // 匹配httpsqs
                 if (!empty($config['httpsqs'])) {
                     $cfg = $config['httpsqs'];
                     $charset = isset($cfg['chartset']) ? $cfg['chartset'] : $cfg['charset'];
                     $httpsqs = new Oray_Httpsqs($cfg['host'], $cfg['port'], $charset, $queueName);
                     $status = $httpsqs->status($queueName);
                     if (!$status || $status['put'] != $queueStatus['put'] || $status['get'] != $queueStatus['get'] || $status['unread'] != $queueStatus['unread']) {
                         $message[] = "[WARNING] httpsqs status not match";
                         $count['warning']++;
                     } else {
                         $message[] = "[SUCCESS] httpsqs status match success";
                     }
                     $memcache->close();
                 }
             }
         } else {
             $message[] = "[ERROR] Undefined \"WWW_ROOT\"";
             $count['error']++;
         }
     }
     $message[] = '';
     $message[] = "Check complete, {$count['warning']} warnings, {$count['error']} errors";
     $message = implode("\n", $message);
     header('Accept-Ranges: bytes');
     header('Content-Type', 'text/plain; charset=utf-8');
     //header('Content-Length', strlen($message));
     echo $message;
     exit;
 }
Example #5
0
 /**
  * 获取系统提示数据
  */
 public function getTips()
 {
     if ($this->_tips) {
         return $this->_tips;
     }
     $lang = !empty($this->_user->option['language']) ? $this->_user->option['language'] : 'zh_CN';
     $this->_tips = $this->cache->get('TUDU-TIPS-' . $lang);
     if (!$this->_tips) {
         $dataFile = $this->options['data']['path'] . '/' . 'tudu_tips-' . $lang . '.xml';
         if (!file_exists($dataFile) || !is_readable($dataFile)) {
             return null;
         }
         $xml = @simplexml_load_file($dataFile);
         if (!$xml) {
             return null;
         }
         foreach ($xml as $tip) {
             if (!isset($tip->id)) {
                 continue;
             }
             if (isset($tip->expiretime) && strtotime($tip->expiretime) < time()) {
                 continue;
             }
             $item = array();
             foreach ($tip as $k => $val) {
                 $item[$k] = (string) $val;
             }
             $this->_tips[$item['id']] = $item;
         }
         $this->cache->set('TUDU-TIPS-' . $lang, $this->_tips, null, 86400);
     }
     return $this->_tips;
 }