Jump to navigation

You are currently browsing the monthly archives for May 2010

discuz 短消息群发给版主的功能

  • Posted on May 31, 2010 at 9:48 am

discuz 添加短消息群发给版主的功能

版本:discuz 7.2 gbk.

在discuz的短消息功能里面,我们只能群发短消息给好友
对于管理组来说,有必要增加群发给版主/总版主的功能。

修改 pm.php
在 204行

$buddyarray = array();
if($uids) {
	$query = $db->query("SELECT uid, username FROM {$tablepre}members WHERE uid IN (".implodeids($uids).")");
	while($buddy = $db->fetch_array($query)) {
		$buddyarray[] = $buddy;
	}
}

下面增加:

       if (intval($_DSESSION['groupid'])==1 || intval($_DSESSION['groupid'])==2 || intval($_DSESSION['groupid'])==3 )
        {   
                //to banzhu:
                $banzhuarray = array();
                $query = $db->query("SELECT uid,username FROM {$tablepre}members WHERE  groupid=3 ");
                while($banzhu = $db->fetch_array($query))
                {   
                        $banzhuarray[] = $banzhu;
                }   
 
                //to zongbanzhu:
                $zongbanzhuarray = array();
                $query = $db->query("SELECT uid,username FROM {$tablepre}members WHERE  groupid=2 ");
                while($zongbanzhu = $db->fetch_array($query))
                {   
                        $zongbanzhuarray[] = $zongbanzhu;
                }   
 
	}

继续修改pm.php:
找到

} elseif($action == 'send' && submitcheck('pmsubmit')) {
....
                        foreach($buddyarray as $buddy) {
                                $uids[] = $buddy['friendid'];
                        }
                        $msgto = $p = '';

把下面的

                                foreach($msgtos as $uid) {
                                        $msgto .= in_array($uid, $uids) ? $p.$uid : '';
                                        $p = ',';
                                }

替换成:

                        if (intval($_DSESSION['groupid'])==1 || intval($_DSESSION['groupid'])==2 || intval($_DSESSION['groupi
d'])==3 )
                        {
                                foreach($msgtos as $uid) {
                                        $msgto .= $p.$uid;
                                        $p = ',';
                                }
                        }
                        else
                        {
                                foreach($msgtos as $uid) {
                                        $msgto .= in_array($uid, $uids) ? $p.$uid : '';
                                        $p = ',';
                                }
                        }

然后修改模板templates/default/pm_send.htm
在24行:

                                                        <input name="msgto" value="$username" class="txt" tabindex="1" />
                                                        <!--{if $buddyarray}--><a href="javascript:display('buddies');" class="dropmenu">
{lang pm_to_buddy}</a><!--{/if}-->

后面添加:

<!--{if $banzhuarray}--><a href="javascript:display('banzhu');" class="dropmenu">版主群发</a><!--{/if}-->                        
<!--{if $zongbanzhuarray}--><a href="javascript:display('zongbanzhu')
;" class="dropmenu">总版主群发</a><!--{/if}-->

然后在

                                        <!--{if $buddyarray}-->
                                        <tbody id="buddies" style="display: none;">
                                        <tr><td colspan=5 align=center><font color=RED>好友群发</font></td></tr>
                                        <tr>
                                                <td width="60"></td>
                                                <td>
                                                        <ul class="s_clear">
                                                        <!--{loop $buddyarray $buddy}-->
                                                                <li><label for="msgto_$buddy[uid]">
<input id="msgto_$buddy[uid]" name="msgtos[]" type="checkbox" value="$buddy[uid]"> $buddy[username]</label></li>
                                                        <!--{/loop}-->
                                                        </ul>
                                                </td>
                                        </tr>
                                        </tbody>
                                        <!--{/if}-->

后面加添加

                                        <!--{if $banzhuarray}-->
                                        <tbody id="banzhu" style="display: none;" class="modify_buddies">
                                        <tr><td colspan=5 align=center><font color=RED>版主群发</font></td></tr>
                                        <tr>
                                                <td width="60"></td>
                                                <td>
                                                        <ul class="s_clear">
                                                        <!--{loop $banzhuarray $buddy}-->
                                                                <li><label for="msgto_$buddy[uid]">
<input id="msgto_$buddy[uid]" name="msgtos[]" type="checkbox" value="$buddy[uid]"> $buddy[username]</label></li>
                                                        <!--{/loop}-->
                                                        </ul>
                                                </td>
                                        </tr>
                                        </tbody>
                                        <!--{/if}-->
                                        <!--{if $zongbanzhuarray}-->
                                        <tbody id="zongbanzhu" style="display: none;" class="modify_buddies">
                                        <tr><td colspan=5 align=center><font color=RED>总版主群发</font></td></tr>
                                        <tr>
                                                <td width="60"></td>
                                                <td>
                                                        <ul class="s_clear">
                                                        <!--{loop $zongbanzhuarray $buddy}-->
                                                                <li><label for="msgto_$buddy[uid]">
<input id="msgto_$buddy[uid]" name="msgtos[]" type="checkbox" value="$buddy[uid]"> $buddy[username]</label></li>
                                                        <!--{/loop}-->
                                                        </ul>
                                                </td>
                                        </tr>
                                        </tbody>
                                        <!--{/if}-->

没想到uc_client里面又一次检查了收信人是否为发信人的好友。。。
再修改uc_client/control/pm.php
在 function onsendpm() 里面
找到

                        $this->load('friend');

把下面的

if(count($msgto) > 1 && !($is_friend = $_ENV['friend']->is_friend($fromuid, $msgto, 3))) {
                                        return PMMSGTONOTFRIEND;
                                }

替换成:

                        $modify_userinfo = $_ENV['user']->db->fetch_first("SELECT * FROM cdb_members WHERE uid='$fromuid'");
                        if (intval($modify_userinfo['groupid'])==1 || intval($modify_userinfo['groupid'])==2 || intval($modif
y_userinfo['groupid'])==3 )
                        {
                        }
                        else
                        {
                                if(count($msgto) > 1 && !($is_friend = $_ENV['friend']->is_friend($fromuid, $msgto, 3))) {
                                        return PMMSGTONOTFRIEND;
                                }
                        }

中英夹杂

  • Posted on May 30, 2010 at 1:27 pm

最近遇到几次中英夹杂的事情:

1 一群人去爬山。
个MM问我:你偷偷爬过这座山么?
我就晕了:为什么要偷偷地爬?
后来才知道她说的是 total

2 一位台湾老奶奶说:我们那里有很多building.
台湾人说的英语,原来也很难听懂。

3 A问B:你report给谁?
意思就是问你的上司是谁。

是不是我落伍了……

honey honey

  • Posted on May 29, 2010 at 8:25 pm

期待一个好日子
工作不需我操心
能随便想想东西
喔喔
喝一杯茶也可以
写封信也可以
不做什么也可以
忙碌中又想起你
对我的若即若离
生气了也没痕迹
喔喔
忽然很想拥抱你
吻你措手不及
这只能想像而已
honey honey
要对你说声对不起
我总是没时间陪你
honey honey
你是否想亲亲密密
还是喜欢这段距离
虽然留点空间不见面
反而能够拉紧彼此的心
当我需要拥抱的时候
我总希望你在这里
啦……
忙碌中又想起你
对我的若即若离
生气了也没痕迹
喔喔
忽然很想拥抱你
吻你措手不及
这只能想像而已
honey honey
要对你说声对不起
我总是没时间陪你
honey honey
你是否想亲亲密密
还是喜欢这段距离
honey honey
要对你说声对不起
我总是没时间陪你
honey honey
你是否想亲亲密密
还是喜欢这段距离
虽然留点空间不见面
反而能够拉紧彼此的心
当我需要拥抱的时候
我总希望你在这里
继续期待好日子
继续埋首工作里
寄托在下个假期
喔喔
天空总是蓝蓝的
心情总是快乐
知道我在你心里
知道我在你心里
知道我在你心里
知道我在你心里

php使用gd2输出高清晰度的超小字体

  • Posted on May 28, 2010 at 10:56 am

一般来说我们都使用truetype字体,有些字体缺点非常明显:
在字体大于12px的时候,非常PP,很完美。
但是到了8px以下,就惨不忍睹了,字体发虚,有些笔划还有断线的现象。

解决的办法有三种:

第一种方法:
生成三倍大小的图像,然后由浏览器做缩放。

$im = imagecreatetruecolor(300, 300);
$ok=imagettftext($im,$font_size,$angle,$x,$y,$text_color,$font,$text);

然后在网页中调用的时候写

<img src='./xxx.php'  width=100 height=100 />

这样就相当于浏览器帮你做了缩放。
效果还不错,就是生成出来的文件比较大。

第二种方法:
生成三倍大小的图像,然后使用gd的函数(imagecopyresized)来做缩放。

$im = imagecreatetruecolor(300, 300);
$ok=imagettftext($im,$font_size,$angle,$x,$y,$text_color,$font,$text);
$im_small = imagecreatetruecolor(100,100);
imagecopyresized($im_small, $im, 0,0,0,0,100,100,300,300);

效果一般,速度快

第三种方法:
生成三倍大小的图像,然后使用gd的函数(imagecopyresampled)来取样并缩放:

$im = imagecreatetruecolor(300, 300);
$ok=imagettftext($im,$font_size,$angle,$x,$y,$text_color,$font,$text);
$im_small = imagecreatetruecolor(100,100);
imagecopyresampled($im_small, $im, 0,0,0,0,100,100,300,300);

效果好,速度慢
其实也慢不到哪里去啦,1M大小的图,大概也就慢个1秒左右吧(貌似和CPU性能有关?)。

至于为什么要做三倍精度的图,我也没有测试过2倍或者4,5,6,7,8,9,10倍的图的效果。

ie6中png图片透明效果

  • Posted on May 27, 2010 at 1:18 pm

如果你的png图片是透明的,在IE7,FF,chrome下面都不会有什么问题,
但是在IE6里面就郁闷了,图片变得不透明了。

还是直接看代码吧:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
	<img src='http://bbs.enjoykorea.net/images/common/medal/xinyushangjia_1-3.png'>
<script>
function m_addLoadEvent(func) {
 
var oldonload = window.onload;
 
if (typeof window.onload != 'function') {
 
window.onload = func;
 
} else {
 
window.onload = function() {
 
oldonload();
 
func();
 
}
 
}
 
}
 
function correctPNG() 
{  
var arVersion = navigator.appVersion.split("MSIE")  
var version = parseFloat(arVersion[1])  
if ((version >= 5.5) && (document.body.filters))  
{  
for(var i=0; i<document.images.length; i++)  
{  
var img = document.images[i]  
//var imgName = img.src.toUpperCase()  
var imgName = img.src;
if (imgName.substring(imgName.length-21, imgName.length) == "xinyushangjia_1-3.png")  
{  
var imgID = (img.id) ? "id='" + img.id + "' " : ""  
var imgClass = (img.className) ? "class='" + img.className + "' " : ""  
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "  
var imgStyle = "display:inline-block;" + img.style.cssText  
if (img.align == "left") imgStyle = "float:left;" + imgStyle  
if (img.align == "right") imgStyle = "float:right;" + imgStyle  
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle  
var strNewHTML = "<span " + imgID + imgClass + imgTitle  
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"  
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"  
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"  
img.outerHTML = strNewHTML  
i = i-1  
}  
}  
}  
} 
 
m_addLoadEvent(correctPNG);
</script>

在utf8页面上添加百度搜索按钮

  • Posted on May 26, 2010 at 9:28 am

遇到一问题,
要在utf8的页面上加入一个按钮,
点击之后进入百度的搜索

代码如下:

<div id="search">
<form name="searchFrm" method="GET" target="_blank">
<input name="keyword" class="keyword" id="keyword" type="text" value="" />
<input type="button" name="baidu_btn" value="百度一下" class="searchBtn" onClick='window.open("http://www.baidu.com/?wd="+encodeURIComponent(this.form.keyword.value),"_blank");return false;' />
        </form>
</div>

么有想到的是,encode之后的字符串竟然是乱码。

想必是因为本页是utf8的,而baidu是gbk的。
于是开始搜索js把utf8转成gbk的函数。
搜到了二个函数,都不能用。要么有js错误,要么转出来的字符串是空的。

后来只好自己做了一个php页面,在里面用iconv做了转化:
代码如下:

<div id="search">
<form name="searchFrm" method="GET" target="_blank">
<input name="keyword" class="keyword" id="keyword" type="text" value="" />
<input type="button" name="baidu_btn" value="百度一下" class="searchBtn" onClick='window.open("baidu.php?wd="+encodeURIComponent(this.form.keyword.value),"_blank");return false;' />
        </form>
</div>

baidu.php代码如下:

<?PHP
$url = "http://www.baidu.com/s?wd=";
$keyword = iconv("UTF-8","GBK", trim($_GET['wd']));
$keyword = urlencode($keyword);
$url .= $keyword;
Header("Location: ". $url);
die();

域名注册商声称“信息不实将注销域名”

  • Posted on May 25, 2010 at 12:18 pm

IT时报报道,位于厦门的域名注册机构 “商务中国”声称“信息不实将注销域名”。近期不少“商务中国”的客户都收到了邮件,要求他们及时修改更正域名注册资料中不正确的信息,否则域名有可能被注销。有个人站长将此举与国内将全面推行域名管理实名制的风声联系在了一起。
万网市场部方晓静解释说,万网一般每年第4季度都会对用户发邮件提醒,让用户核查自己所持有的域名注册资料是否正确。方晓静向记者透露了万网对域名注册资料的处理流程,“首先注册域名时就有合法性校验,而此后在人工审核发现有问题先邮件通知用户更正。如果限时没有解决,将由审核人员拨打电话联系,最后仍然无法按时更正,将暂停域名,直至删除。”

天涯又挂了,某域名无法解析

  • Posted on May 24, 2010 at 1:46 pm

[huarong@masalife.com ~]$ ping static.tianyaui.com
ping: unknown host static.tianyaui.com

已经过去很长时间了,还没有处理好,可见只是部分区域出现了这种情况。

写给发垃圾评论的人们

  • Posted on May 23, 2010 at 12:22 pm

每天都要删你们发的垃圾评论,
烦得很。
不过我也实在是懒得去加验证码或者装什么反垃圾的插件了。

如果你们再来发,
我就把你们的网址删除。。。然后approve.

nginx文件类型错误解析漏洞

  • Posted on May 22, 2010 at 7:44 am

漏洞介绍:nginx是一款高性能的web服务器,使用非常广泛,其不仅经常被用作反向代理,也可以非常好的支持PHP的运行。80sec发现其中存在一个较为严重的安全问题,默认情况下可能导致服务器错误的将任何类型的文件以PHP的方式进行解析,这将导致严重的安全问题,使得恶意的攻击者可能攻陷支持php的nginx服务器。

漏洞分析:nginx默认以cgi的方式支持php的运行,譬如在配置文件当中可以以

location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}

的方式支持对php的解析,location对请求进行选择的时候会使用URI环境变量进行选择,其中传递到后端Fastcgi的关键变量SCRIPT_FILENAME由nginx生成的$fastcgi_script_name决定,而通过分析可以看到$fastcgi_script_name是直接由URI环境变量控制的,这里就是产生问题的点。而为了较好的支持PATH_INFO的提取,在PHP的配置选项里存在cgi.fix_pathinfo选项,其目的是为了从SCRIPT_FILENAME里取出真正的脚本名。
那么假设存在一个http://www.80sec.com/80sec.jpg,我们以如下的方式去访问

http://www.80sec.com/80sec.jpg/80sec.php

将会得到一个URI

/80sec.jpg/80sec.php

经过location指令,该请求将会交给后端的fastcgi处理,nginx为其设置环境变量SCRIPT_FILENAME,内容为

/scripts/80sec.jpg/80sec.php

而在其他的webserver如lighttpd当中,我们发现其中的SCRIPT_FILENAME被正确的设置为

/scripts/80sec.jpg

所以不存在此问题。
后端的fastcgi在接受到该选项时,会根据fix_pathinfo配置决定是否对SCRIPT_FILENAME进行额外的处理,一般情况下如果不对fix_pathinfo进行设置将影响使用PATH_INFO进行路由选择的应用,所以该选项一般配置开启。Php通过该选项之后将查找其中真正的脚本文件名字,查找的方式也是查看文件是否存在,这个时候将分离出SCRIPT_FILENAME和PATH_INFO分别为

/scripts/80sec.jpg和80sec.php

最后,以/scripts/80sec.jpg作为此次请求需要执行的脚本,攻击者就可以实现让nginx以php来解析任何类型的文件了。

POC: 访问一个nginx来支持php的站点,在一个任何资源的文件如robots.txt后面加上/80sec.php,这个时候你可以看到如下的区别:

访问http://www.80sec.com/robots.txt

HTTP/1.1 200 OK
Server: nginx/0.6.32
Date: Thu, 20 May 2010 10:05:30 GMT
Content-Type: text/plain
Content-Length: 18
Last-Modified: Thu, 20 May 2010 06:26:34 GMT
Connection: keep-alive
Keep-Alive: timeout=20
Accept-Ranges: bytes

访问访问http://www.80sec.com/robots.txt/80sec.php

HTTP/1.1 200 OK
Server: nginx/0.6.32
Date: Thu, 20 May 2010 10:06:49 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/5.2.6

其中的Content-Type的变化说明了后端负责解析的变化,该站点就可能存在漏洞。

漏洞厂商:http://www.nginx.org

解决方案:

我们已经尝试联系官方,但是此前你可以通过以下的方式来减少损失

关闭cgi.fix_pathinfo为0

或者

if ( $fastcgi_script_name ~ \..*\/.*php ) {
return 403;
}

PS: 鸣谢laruence大牛在分析过程中给的帮助

转载自:
nginx文件类型错误解析漏洞:http://www.80sec.com/nginx-securit.html

Top