public function write($buf, $length = 0) { $length = intval($length) > 0 ? intval($length) : strlen($buf); $rev = socket_write($this->sock, $buf, $length); if (false === $rev) { $err = socket_strerror(socket_last_error($this->sock)); Watt_Log::addLog('write socket error.[' . $err . ']'); throw new Exception("socket_write() failed: " . $err); } }
/** * @param string $tipType * @return Watt_Util_SearchTip */ public static function factory($tipType) { Watt_Log::addLog($tipType); return new $tipType(); /* switch ( $tipType ){ case "xiangmubianhao": return new Tpm_Util_SearchTip_XmBianhao(); break; case "ddbianhao": return new Tpm_Util_SearchTip_DdBianhao(); break; default: return new Watt_Util_SearchTip_DdBianhao(); break; } */ }
public function notice($alertType, $msg) { $msg .= ' ' . date('Y-m-d H:i:s'); $recerverlist = $this->getReceiverList($alertType); if (is_array($recerverlist)) { foreach ($recerverlist as $type => $recerver) { switch ($type) { case self::NOTICE_TYPE_MAIL: $rev = Watt_Util_Msg_Mail::sendMail($recerver, Watt_I18n::trans("JT_OTHER_TONGBUJIANKONGFAXIAOXI"), $msg); Watt_Log::addLog("Notice [{$msg}] to [{$recerver}] and rev [{$rev}]"); break; case self::MOTICE_TYPE_SMS: $rev = Watt_Util_Msg_Sms::sendSms($recerver, $msg); Watt_Log::addLog("Notice [{$msg}] to [{$recerver}] and rev [{$rev}]"); break; } } } else { Watt_Log::addLog("Notice [{$msg}] to Nobody!"); } }
/** * 获得系统日志程序 * * @return Watt_Log */ public static final function getSystemLogger() { if (!is_object(self::$_systemLoger)) { self::$_systemLoger = new Watt_Log_Db(); } return self::$_systemLoger; }
private function _sendMsgToEpoll($cmd, $data) { $rev = 0; if ($this->_epollClient) { try { /** * 因为存在EpollServer能够连接上,但是无法发送信息的情况,所以设置了超时时间 * @author terry * @version 0.1.0 * Sun Feb 01 11:38:08 CST 2009 */ set_time_limit(10); $header = pack('nn', strlen($data), $cmd); $total = $header . $data; $this->_epollClient->write($total, strlen($total)); //$rev = $this->_getMsgToEpoll(); $rev = 1; } catch (Exception $e) { Watt_Log::addLog('Send epoll msg error, msg[' . $e->getMessage() . ']', Watt_Log::LEVEL_ERROR); $rev = 0; } } return $rev; }
public static function setLang($lang_code) { if ($lang_code) { if (is_dir(Watt_Config::getLangPath() . $lang_code)) { self::$lang = $lang_code; } else { if (class_exists('Watt_Log')) { Watt_Log::addLog('No language file for [' . $lang_code . ']'); } } } }
/** * dispatch mobile * 如果分发成功,则返回 true * 否则返回 false * @param string $source 去掉特服号的source * @param string $_old_source 最原始的source * @return boolean */ public static function dispatchMobile($mobile, $msg, $source, $_old_source) { self::_init(); $arrSiteList = array(10 => 'testtpm.transn.net', 20 => 'demotpm.transn.net', 40 => 'tpm.transn.net', 50 => 'uetpm.transn.net', 60 => 'vtpm.transn.net', 70 => 'devtpm.transn.net'); $smsInterface = '/message/sms/get.php'; $siteCode = substr($source, 1, 2); if ($siteCode == self::$_site_code) { //如果刚好是本站地址 return false; //则不分发,return false } if (key_exists($siteCode, $arrSiteList)) { //如果存在于站点列表中 Watt_Log::addLog("Recieve sms: mobile[{$mobile}],msg[{$msg}],source[{$source}]. And dispatch to [{$arrSiteList[$siteCode]}]( sitecode[{$siteCode}] ).", Watt_Log::LEVEL_INFO, 'MSG_SMS'); $url = "http://" . $arrSiteList[$siteCode] . $smsInterface . "?mobile={$mobile}&msg={$msg}&source={$_old_source}"; file_get_contents($url); //print"<pre>Terry :";var_dump( file_get_contents($url) );print"</pre>"; //exit(); return true; //分发成功,不管结果 } else { return false; //否则依然在本站内处理 } }
public function __construct($pathFilename) { //目录不存在则创建 if (!is_dir(dirname($pathFilename))) { BaseOption::create_dir($pathFilename); } $this->setFilename($pathFilename); $this->_tmpFilename = $pathFilename . ".tmp"; $this->_fPoint = @fopen($this->_tmpFilename, 'a'); if (!$this->_fPoint) { Watt_Log::addLog('Cannot create file [' . $this->_tmpFilename . ']'); } }
/** * 查询并返回结果集连接 * @param String $sql * @return resource */ private function _query($sql, $logSql = true) { if ($this->_debug) { Watt_Debug::addInfoToDefault('', "Pre execute sql"); } //self::autoSelectDbBySql( $sql ); //return mysql_query( $sql, $this->_conn ); //如果return $rs 会慢 数十毫秒 @todo 再次验证 if ($this->_mutile_read_db) { //if ( is_object($this->_connection) && $this->_connection->getAutoCommit() ){ if ('Watt_Dbx' == get_class($this)) { self::superUpdateConnectionX(); } else { self::superUpdateConnection(); // 强制更新数据库连接,使只需只读的操作连接到“只读数据库服务器” } //} } $rev = mysql_query($sql, $this->_conn); self::addQueryTimes(); $queryTimes = self::getQueryTimes(); if ($this->_debug) { Watt_Debug::addInfoToDefault(__FILE__, "[{$queryTimes}] Executed sql [<p> {$sql} </p>]"); } if (mysql_errno()) { //如果使用System级别会重复记录db日志,可能死循环。 if ($this->_log) { Watt_Log::addLog('Execute sql [' . $sql . '] fail, error [' . mysql_errno() . ':' . mysql_error() . ']', Watt_Log::LEVEL_DEBUG); } throw new Watt_Db_Exception(mysql_errno() . ": " . mysql_error() . "\n"); } if ($logSql) { if ($this->_log) { Watt_Log::logDbOprate($sql); } } return $rev; }
/** * 回到之前所在组 * 如果组列表只有一个元素,则保持在该组 * @param int $backStep 回退步数,如果为0,退到初始状态 */ public function backToPrevGroup($backStep = 1) { if ($backStep > 0) { for (; $backStep > 0; $backStep--) { $prevGroupId = array_pop($this->_groupIdStack); if ($prevGroupId) { $this->_groupId = $prevGroupId; Watt_Log::addLog('Back to group [' . $prevGroupId . ']'); } } } else { //如果 步数 <= 0 回退到最起点 $prevGroupId = array_pop($this->_groupIdStack); while ($prevGroupId) { if ($prevGroupId) { $this->_groupId = $prevGroupId; } $prevGroupId = array_pop($this->_groupIdStack); } } }
/** * 过滤字符串 * * @param string $str 欲过滤的字符串 * @param array|string $maskList 数组或者,分隔的字符串 * @param string $mask 过滤后的替换字符 * @return string */ public static function filterString($str, $maskList, $mask = '--') { if (!is_array($maskList)) { $maskList = explode(',', $maskList); } foreach ($maskList as $val) { $count = 0; $str = str_replace($val, $mask, $str, $count); if ($count > 0) { if (class_exists('Watt_Log')) { Watt_Log::addLog("filter string:[{$val}]", Watt_Log::LEVEL_INFO); } } } return $str; }
/** * 循环进行 do 的处理 * */ function dispatch() { /** * 因为Tq是用Post传递参数过来的,所以不能用$_GET */ $do = empty($_REQUEST["do"]) ? "index" : trim($_REQUEST["do"]); /** * 这是为了兼容 do=xxx&action=yyy 的形式 */ $a = empty($_REQUEST["action"]) ? "" : trim($_REQUEST["action"]); if ($a) { $do .= "_" . $a; } /** * 获取view的type */ $v = empty($_REQUEST["v"]) ? "Html" : trim($_REQUEST["v"]); //TQ任务LINK //http://testtpm.transn.net/index.php?do=if_renwu_detail&sj_id=35c55571-80bb-c18b-6078-465a87c329bd&Username=dGVzdC1wcjE=&Password=MjAyY2I5NjJhYzU5MDc1Yjk2NGIwNzE1MmQyMzRiNzA=&pwdway=md5 /** * 获取用户名和密码进行快速登录 */ $accounts = ''; $pwd = ''; if (r('pwdway')) { if (!Watt_Session::getSession()->getUserId()) { //这个判断是为了不让TQ登录后,访问此链接时,冲掉session中[是否TQ]那个设置 $accounts = iconv('GB2312', 'UTF-8', base64_decode(str_replace(' ', '+', r("Username")))); $pwd = iconv('GB2312', 'UTF-8', base64_decode(str_replace(' ', '+', r("Password")))); } } else { //if( r( 'login' ) == 'ok' ){ if (r('login')) { /** * 这是为了兼容TQ的那个点击“查收我的订单”,导致Web重登录的问题。 * @author terry * @version 0.1.0 * Thu Sep 06 16:44:53 CST 2007 */ $accounts = ''; $pwd = ''; } else { // if(r('yh_xiaoshou_id')){ // $wkh_id = r( "yh_waibukehu_id" ); // $yh_xiaoshou_id = r( "yh_xiaoshou_id" ); // $yh_xiaoshou_name = TpmYonghuPeer::getYhZhanghuByYhId($yh_xiaoshou_id); // $nkh_id = TpmKehufromkehuPeer::getNkIdByWkId($wkh_id,$yh_xiaoshou_name); // $accounts = TpmYonghuPeer::getYhZhanghuByYhId($nkh_id) ; // $pwd = r( "user_pw" ); // if($pwd==''){ // $pwd = r('yh_xiaoshou_id'); // } // }else{ $accounts = r("user_name"); $pwd = r("user_pw"); //} } } //var_dump(); //exit; if ($accounts && $pwd) { $login_rev = 0; $user = TpmYonghuPeer::checkUserLogin($accounts, $pwd, $login_rev); if ($login_rev == TpmYonghuPeer::USER_LOGIN_OK) { // 用户登陆成功后如果密码安全强度不够,跳转到修改密码页提示用户设置安全的密码 $pswdChecker = new Tpm_Passwordchecker($pwd); $cfgLevel = Watt_Config::getCfg('PSWD_CHECK_LEVEL'); if ($cfgLevel == '') { $cfgLevel = '0'; } if ($pswdChecker->getSecurityLevel() < $cfgLevel) { $_SESSION['LOW_PASSWORD'] = true; // header('Location:?do=ps_yonghu_changepwd&nosecurity=true'); // exit; } Watt_Log::addLog('Login ok, accounts[' . $accounts . '],[' . session_name() . '=' . session_id() . ']', Watt_Log::LEVEL_INFO, 'LOGIN_WEB_DIRECT_LOGIN'); } else { if ($login_rev == TpmYonghuPeer::USER_LOGIN_SHOUQUANOK) { //授权密码登录 jute 20071220 Watt_Log::addLog('Authorizepwd Login ok, accounts[' . $accounts . ']', Watt_Log::LEVEL_INFO, 'LOGIN_WEB_DIRECT_LOGIN'); } } } //如密码强度不够, 强制修改密码 $superDoList = array('ps_yonghu_changepwd', 'login_logout', ''); // 数组中的Action不在强制之列 if (@$_SESSION['LOW_PASSWORD'] && !in_array($do, $superDoList)) { header('Location:?do=ps_yonghu_changepwd&nosecurity=true'); exit; } /** * 除了译员和客户,只能从内部登录 * @author terry * @version 0.1.0 * Mon Mar 31 23:24:00 CST 2008 */ if (Watt_Session::getSession()->getUserName()) { if (!Watt_Util_Net::isLANIp($_SERVER['REMOTE_ADDR']) && r('do') != 'main_home') { if (!(Watt_Session::getSession()->getYhShifouWaibuDenglu() || Watt_Session::getSession()->getJsShifouWaibuDenglu())) { echo '您没有外部访问权限,请联系企业管理员开通'; Watt_Session::getSession()->clearUserSessionInfo(); exit; } } } $i = $this->_maxToDo; while ($do != "" && $i-- > 0) { $do = $this->processDo($do, $v); } //如果是渠道代理商客户,传神客户,客户则记录日志 2007-7-9 john if (Watt_Session::getSession()->getRoleShortname() == "QDKH" || Watt_Session::getSession()->getRoleShortname() == "CSKH" || Watt_Session::getSession()->getRoleShortname() == "CR") { $accessLoger = new Watt_Log_Db('tpm_rizhi_fangwen'); $accessLoger->log("", 0, $_REQUEST["do"]); } }