文章列表
 
2009-07-16 18:13

在国内做互联网,总免不了要封这个,杀那个的。这不,刚收到要封禁N个IP段的需求,而且要求的还贼急。

有如下几个方法:
1) 改业务代码,封禁逻辑放在这里 -- 放弃了,业务不得慢死!
2) 改接入机IPTABLES -- 没敢做,怕把自己给ban了,要打电话到机房重启就惨了
3) 修改接入机上的haproxy -- 幸亏peterwang提醒了一下啊

这里就讲一下如何用haproxy满足这类封禁需求。

haproxy的简要介绍如下:
HAProxy提供高可用性、负载均衡 以及基于TCP和HTTP应用的代理,它是免费、快速并且可靠的一种解决方案。HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会氨3只蚱卟愦 怼?HAProxy运行在当前的硬件上,完全可以支持数以万计的并发连接。并且它的运行模式使得它可以很简单安全的整合进您当前的架构中, 同时可以保护你的web服务器不被暴露到网络上。
更详细的信息请看:http://cn.haproxy.org/

我们需要用到的是haproxy的 acl功能,例子如下:

acl invalid_src src 0.0.0.0/7 224.0.0.0/3
acl invalid_src src_port 0:1023
acl local_dst hdr(host) -i localhost
block if invalid_src || local_dst

用acl定义一些规则,而用(block|use_backend)指定满足这些规则怎么做,我们当然选择block!

上述这段配置可以位于如下section

keyword                 defaults   frontend   listen    backend
----------------------+----------+----------+---------+---------
acl                         -          X         X         X

----------------------------------------------------------------
有点:
快速、高效;只需要改动一下配置文件即可,特别是应对突发事件。

缺点:
用户会得到一个403页面。不是很友好。
最好是业务端有封禁server,可以给出更友好的提示。

 
2009-02-14 15:23
在ie下面,iframe背景默认为白色,如果要改变,最好的方法是在iframe的body中添加

<body style="backgroud-color:transparent;">

如果不能改动iframe的源码,但是iframe和主页面在同一主域下,可以在iframe的onload事件中去改变被引用的iframe的背景色。

function bgtransparent()
{
if (document.all)
{
    var frm = document.getElementById("loginstatus");
    var node = frm.Document.createElement('style');
    var cssText = 'body{background-color:transparent}';
    node.setAttribute('type', 'text/css');
    frm.Document.getElementsByTagName('head')[0].appendChild(node);
    if (node.styleSheet) node.styleSheet.cssText = cssText;
    else if (frm.Document.createTextNode) node.appendChild(frm.Document.createTextNode(cssText));
    if (frm.allowTransparency) frm.allowTransparency = true;
}
}

<iframe src="a.html" onload="bgtransparent();"></iframe>
 
2009-02-01 10:52
为了跨平台的兼容,有时候需要知道当前运行平台,PHP提供了三种方式来获取当前平台信息:
1. PHP_OS
2. getenv('OS')
3. php_uname()

以我的winxp为例,在上面运行代码:
echo PHP_OS . "\n";
echo getenv('OS') . "\n";
echo php_uname() . "\n";

得到的输出是:
WINNT
Windows_NT
Windows NT colinli-nw 5.1 build 2600

这里面当然php_uname()功能最为强大,具体情况可以参见手册。
如果要判断是否是windows平台,这个是由只需要使用上述任何一个方法,然后判断是否以‘win’打头就是了。
 
2009-01-22 22:31
// ==UserScript==
// @name          jQuery
// @namespace     http://www.joanpiedra.com/jquery/greasemonkey
// @description    Play nicely with jQuery and Greasemonkey
// @author        Joan Piedra
// @homepage      http://www.joanpiedra.com/jquery/greasemonkey
// @include       http://myxingchenbian.cn/*
// ==/UserScript==


// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://cache.soso.com/post/js/jquery.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);

// Check if jQuery's loaded
function GM_wait() {
    if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
    else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();

// All your GM code must be inside this function
function letsJQuery() {
try{
    if (window.location.href.match(/myxingchenbian.cn/))
    {
        $("div.cBody").eq(0).hide();
        $("div.tonglan").hide();
        $("div.right").hide();
        $("div.newsView").children().not($("#content")).each(function(){$(this).hide();});
        $("div.footer").hide();
        $("div.content_up").hide();
        $("div.content_end").hide();
        $("div.cupage").hide();
    }
}catch(e){alert (e);}
}


使用require特性,将js文件下载到本地,以后不必再下载

// ==UserScript==
// @name           hello jquery
// @namespace      http://jquery.com
// @description    using jquery to remove ads
// @include        http://www.myxingchenbian.cn/*
// @require           http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js
// @require           http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js
// ==/UserScript==

try{
    if (window.location.href.match(/myxingchenbian.cn/))
    {
        $(".tonglan, .footer, span:hidden, .right, .ad_style, .info_a3, .cBody:first, body script").remove(); //去掉广告内容
        $("#content").children().each(function(i){if (i>0 && i<5) $(this).remove();});
        $(".thisPlace:first").prependTo("body").after($("#content")); //挪动需要的内容到body中
        if (window.location.href.match(/\d+/)) $(".main").remove(); //只有具体的页才把main去掉
        $("p:contains('myxingchenbian.cn'), p:contains(',,')").remove(); //去除夹杂的广告
        $("p").each(function(){if ($(this).text().length < 2) $(this).remove();}); //去除空的段落
        $("body").attr('style', 'font-size:16px'); //重置字体大小
    }
    else if (window.location.href.match(/lqqm.net/))
    {
        $("table[width='100%']:first td[valign='top']").remove();
    }
}catch(e){alert (e);}


安装

将上述文件保存为以".user.js"结尾命名的js文件,然后使用firefox打开,这个时候greasemonkey就会提示你进行安装,在安装的过程中,就会下载对应的js文件并保存到本地。
 
2008-12-17 22:06

#### 统计单词数、行数等 *count-items*

:%s/./&/gn 字符数

:%s/\i\+/&/gn 单词数

:%s/^//n 行数

:%s/the/&/gn 任何地方出现的 "the"

 
2008-12-14 13:57
转自 http://www.adobe.com/cn/devnet/dreamweaver/articles/css_starter_pages.html

有五种基本布局定位类型可供选择:

  • 弹性布局 - 总体宽度及其中所有栏的值都以 em 单位编写。 这应使布局能够使用浏览器的指定基本字体大小缩放。 对于视力不好的用户, 这可能更有吸引力、更易于访问, 因为栏宽度将变得更宽, 能以任何大小显示更舒适、更可读的行长度。 由于总体宽度将缩放, 您的设计必须允许可这宽度。
  • 固定布局 - 总体宽度及其中所有栏的值都以像素单位编写。 布局位于用户浏览器的中心。
  • 流体布局 - 总体宽度及其中所有栏的值都以百分比编写。 百分比通过用户浏览器窗口的大小计算。
  • 混合布局 - 混合布局组合两种其他类型的布局 - 弹性和流体。 页面的总宽度为 100%, 但侧栏值设置为 em 单位。
  • 绝对定位布局 - 所有前述布局的外栏使用浮动内容。 而绝对定位布局完全如其名所示 - 有绝对定位的外栏。 必须记住, 当使用这些布局时, 侧栏会“提出文档流程”, 因而可能有一些不合适的结果 (例如, 页脚可能“看不见”在侧栏在何处结束并在主要内容区域包含的内容少于侧栏的页面与页脚重叠)。
 
2008-11-14 19:49
1. 使用mysql命令或者mysqldump把数据dump到一个文本文件中
使用mysql命令:
mysql -N -e -utest -ptestpw test -e "select * from show" >show.txt
将test吧中show表的数据dump出来,这里的好处是可以使用select的where,子查询等功能,可以有选择地导出部分数据。

2. 使用mysqlimport导入到另外一个机器上
mysqlimport -i --local test show.txt
-i 表示遇到重复的忽略
--local表示从本地文件导入数据
这样会把show.txt中的数据导入到test吧的show表中
 
2008-11-14 11:50

import memcache
mc = memcache.Client([pinyin_ywhost])
try:
   mc.get('xxx yy zz'.replace(' ', ''))
except Exception, errmsg:
    logging.error(errmsg)

默认memcache,模块使用3秒的超时控制,没有提供接口设置超时

 
2008-11-14 10:36
# Import required module
import MySQLdb

# Connect
conn = MySQLdb.connect(host="localhost", port=3306, user="root", passwd="root123", db="mysql")
cursor = conn.cursor( )

# Execute statement
stmt = "SELECT * FROM user"
cursor.execute(stmt)

# Fetch and output the result
result = cursor.fetchall( )
print result

# Close connection
conn.close( )

连接超时控制 connect_timeout 以秒计算
conn = MySQLdb.connect(host="localhost", port=3306, user="root", passwd="root123", db="mysql", connect_timeout=3)

对于execute()或者query()的超时控制,始终没有找到方法

 
2008-11-10 11:27
#!/usr/bin/expect -f
exp_version -exit 5.0
if {$argc!=2} {
    send_user "usage: remote-exec command password\n"
    send_user "Eg. remote-exec \"ssh user@host ls\\; echo done\" password\n"
    send_user "or: remote-exec \"scp /local-file user@host:/remote-file\" password\n"
    send_user "or: remote-exec \"scp user@host:/remote-file local-file\" password\n"
    send_user "or: remote-exec \"rsync --rsh=ssh /local-file user@host:/remote-file\" password\n"
    send_user "Caution: command should be quoted.\n"
    exit
}
set cmd [lindex $argv 0]
set password [lindex $argv 1]
eval spawn $cmd
set timeout 30
while {1} {
    expect -re "Are you sure you want to continue connecting (yes/no)?" {
            # First connect, no public key in ~/.ssh/known_hosts
            send "yes\r"
        } -re "assword:" {
            # Already has public key in ~/.ssh/known_hosts
            send "$password\r"
        } -re "Permission denied, please try again." {
            # Password not correct
            exit
        } -re "kB/s|MB/s" {
            # User equivalence already established, no password is necessary
            set timeout -1
        } -re "file list ..." {
            # rsync started
            set timeout -1
        } -re "bind: Address already in use" {
            # For local or remote port forwarding
            set timeout -1
        } -re "Is a directory|No such file or directory" {
            exit
        } -re "Connection refused" {
            exit
        } timeout {
            exit
        } eof {
            exit
        }
}
 
   
 
 
文章分类
 
   
 
文章存档
 
     
 
最新文章评论
  

tags.sh: line 22: cscope: command not found 这个是什么情况?
 

回复chy:我记得reverse.put.as 的作者写了个.gdbinit的脚本 很强大 你可以参考一
 

谢谢!写的不错,很受益。
 

大哥,应该加工已下呀,你这东西连主函数也没有,怎么看呀
 

是给新人看的吗?
   
帮助中心 | 空间客服 | 投诉中心 | 空间协议
©2012 Baidu