以下是我在应用到过的一些Yii中的解决方案,计划不断更新。
如何在Yii中使用PHPExcel 扩展
How to use PHPExcel external library with Yii
启用Gzip
Enabling Gzip
如何用ActiveRecords记录数据变更日志
How to log changes of ActiveRecords
以下是我在应用到过的一些Yii中的解决方案,计划不断更新。
如何在Yii中使用PHPExcel 扩展
How to use PHPExcel external library with Yii
启用Gzip
Enabling Gzip
如何用ActiveRecords记录数据变更日志
How to log changes of ActiveRecords
借助第三方类库adLDAP,将adLDAP.php复制到项目的vendors目录中。修改UserIdentity.php
<?php /** * UserIdentity represents the data needed to identity a user. * It contains the authentication method that checks if the provided * data can identity the user. */ class UserIdentity extends CUserIdentity { public function authenticate() { $ldapConfig = Yii::app()->params['ldap']; Yii::import('application.vendors.*'); require_once('adLDAP.php'); try { $adldap = new adLDAP($ldapConfig); } catch (adLDAPException $e) { echo $e; exit(); } if(!$adldap->authenticate($this->username, $this->password)) $this->errorCode=self::ERROR_PASSWORD_INVALID; else { $adInfo = $adldap->user_info($this->username); $this->setState('ad_info',$adInfo); $this->setState('login_time',time()); $this->errorCode=self::ERROR_NONE; } return !$this->errorCode; } }
![TomcatStats_0.1_PHP – Apache/Tomcat Monitor [Cacti Script and Template]](http://nerrsoft.com/wp-content/plugins/ttftitles/cache/5e5de75c46fce5cd3438bc9d3347c01d.png)
基于 Timothy Denike 的 TomcatStats v0.1 修改,去掉了perl的采集脚本,改为PHP实现(SimpleXML)。
Step 1.
配置Tomcat Manager
Step 2.
将采集脚本tomcatstats.php得到到 <cacti_root>/scripts/ 目录下。导入模板cacti_host_template_tomcat_server.xml
Step 3.
调试,在命令行下输入,测试是否可以获取数据。
php tomcatstats.php app1:8444 admin passwords
Step 4.
根据实现设定的账号密码设定Cacti Data Input Methods 中Tomcat Status Input String项
Step 5.
创建图像。
详见附件 »Read More
(主机=Host=Device)
背景:默认情况下Cacti的Down机邮件报警功能只能设置一个统一的接受地址,不够人性化。特是对于集团性质的企业,通常不同的主机是由不同的人员来负责的,因此,为每主机定义不同的邮件接收地址就很有必要。
环境:Cacti 0.8.7g Monitor1.2.1 Thold 0.4.1
Setp1: 给cacti.host表增加一个字段`alertMail`
ALTER TABLE host ADD laertmail varchar(200) default ” not null AFTER monitor_text;
Setp2: 修改脚本
$fields_host_edit3['alertMail'] = array( "method" => "textbox", "friendly_name" => "Alert Email", "description" => "This is the email address that will be sent when this host is reported as down.", "value" => "|arg1:alertMail|", "max_length" => "250", );
找到monitor_api_device_save()方法,在return $save;一行的上面,增加如下代码
if (isset($_POST['alertMail'])) $save['alertMail'] = form_input_validate($_POST['alertMail'], 'alertMail', '', true, 3); else $save['alertMail'] = form_input_validate('', 'alertMail', '', true, 3);
公司换了Lotus邮件服务器,更换后不能任意设置“From Email Address”,导致Cacti Thold不能正常发送报警邮件,提示“554 Sender address not allowed for this authenticated session”。
修改
查找
if ($from == '') { if (isset($_SERVER['HOSTNAME'])) { $from = 'Cacti@' . $_SERVER['HOSTNAME']; } else { $from = 'Cacti@cactiusers.org'; } }
修改为,即指定Settings->Mail/DNS->Emailing Options->From Email Address中填写的邮件地址
if ($from == '') { $from = read_config_option('settings_from_email'); }
加入了64位与32位环境的判断(ip2long),更新了计算方法。
<?php /* * Leon * http://nerrsoft.com * leon@nerrsoft.com * 2011-04-11 */ class ipInfo{ var $address; var $netbits; public function getIpInfo($ipStr){ list($this->address, $this->netbits) = explode('/', $ipStr); $info['long']['mask'] = $this->netmask(); $info['ip']['mask'] = long2ip($info['long']['mask']); $info['long']['net'] = $this->network(); $info['ip']['net'] = long2ip($info['long']['net']); $info['long']['begin'] = $info['long']['net'] + 1; $info['ip']['begin'] = long2ip($info['long']['begin']); $info['long']['end'] = abs($info['long']['mask']) + $info['long']['begin'] - 3; $info['ip']['end'] = long2ip($info['long']['end']); $info['long']['broacast'] = $this->broadcast(); $info['ip']['broacast'] = long2ip($info['long']['broacast']); $info['count'] = $info['long']['broacast'] - $info['long']['net'] - 1; return $info; } // Return the netmask function netmask(){ $mask = $this->check6432('255.255.255.255'); return $mask << (32 - $this->netbits); } // Return the network that the address sits in function network(){ $ip = $this->check6432($this->address); return ($ip & $this->netmask()); } // Return the broadcast that the address sits in function broadcast(){ return ($this->network() | (~$this->netmask())); } // Return the inverse mask of the netmask function inverse(){ $mask = $this->check6432('255.255.255.255'); return (long2ip(~($mask << (32 - $this->netbits)))); } // function check6432($ip){ if(PHP_INT_MAX==2147483647){ $mask = ip2long($ip); }else{ list(, $mask) = unpack('l', pack('l', ip2long($ip))); } return $mask; } } ?>
Comments