分类 经典代码 下的文章

功能: 批量读取指定目录下的子目录中的相同文件名的文件,然后替换某些内容.

使用时遭遇了一个错误,如下.

sed:-e 表达式 #1,字符 13:“s”的未知选项

经研究发现,原来替换的内容正好有一个/,而sed正好也用了/作为分隔符.所以,把sed中的/替换为别的符号就可以了,如下换成了@

#!/bin/sh
# *表示匹配任意目录
site_dir="site/*"
filename="header.html"
replace_content="xxx"
src_content=""
TFILE="/tmp/out.tmp.$$"
# 列出所有目录
dirs=$(ls -d $site_dir)
for dir in $dirs
do
header_file="$dir/$filename"
if [ -w $header_file ]; then
sed "s@$src_content@$replace_content@g" "$header_file" > $TFILE && mv $TFILE "$header_file"
else
echo "cannot write: $header_file"
fi
done

不像PHP,安装好就不用管什么了,Python的环境部署还真是麻烦,还要弄各种路径…

在Google找了找,知道了一个uWSG的东西,别人评测说速度很快,效率高.就决定使用了..能力现在有限,没法测试是否真的快呢.

用Python的pip install uwsgi命令安装uWSGI时,不是502 gate away,就是 uWSGI error

经过几百次安装研究搜索,终于弄uWSGI部署好Python网站环境了..

折腾的东西说不完,实在太多了,搞了三天 -_-!! 还把yum命令给搞坏了..记录下正确的操作好了…使用的是CentOS6.2 64bit

先去官网下面个uWSGI的最新版

[deloz@deloz.net ~]# wget -c http://projects.unbit.it/downloads/uwsgi-1.1.2.tar.gz
[deloz@deloz.net ~]# tar -zxvf uwsgi-1.1.2.tar.gz
[deloz@deloz.net ~]# cd uwsgi-1.1.2 && make

编译结束用下面的命令把uwsgi这个程序文件复制到/usr/bin,如下. 这样就可以直接使用uwsgi命令了.

[deloz@deloz.net uwsgi-1.1.2]# cp uwsgi /usr/bin/

启动uWSGI,如下.

uwsgi -s /tmp/uwsgi.sock -C 666 -M -p 4 -t 60 --limit-as 128 -R 10000 --vhost -d /logs/uwsgi.log --pidfile /tmp/uwsgi.pid --pythonpath /python_sites

uWSGI的参数说明:

-s 以unix socket的方式执行uWSGI,后面跟路径.
-C 修改/tmp/uwsgi.sock的权限为666
-M 启动管理进程
-p 生成worker子进程数,-p 4 表示生成4个
-t cgi程序超时时间,-t 60 表示超时60秒就丢掉
–limit-as 脚本占用最大内存,–limit-as 128表示最大为128M
-R 每个worker处理的最大请求数,-R 10000表示处理的请求最多10000个
–vhost 表示启用虚拟服务器,这样就可以一个uWSGI主进程,管理多个Python站点了
-d 守护进程方式启动,-d /logs/uwsgi.log 表示指定日志文件
–pythonpath 指定Python站点的目录, –pythonpath /python_sites 表示里边放Python的站点,例如/python_sites/web_one/, /python_sites/web_two/

本来想加进开机启动的,把命令给写错了.正确的应该是>>而不是> ,导致覆盖了/etc/rc.local之前的配置…

[deloz@deloz.net uwsgi-1.1.2]# echo /usr/bin/uwsgi -s /tmp/uwsgi.sock -C 666 -M -p 4 -t 60 --limit-as 128 -R 10000 --vhost -d /data/logs/uwsgi.log --pidfile /tmp/uwsgi.pid --pythonpath /python_sites >> /etc/rc.local

在Google把/etc/rc.local的初始配置给找回来了,添加uWSGI后,变成

#!/bin/sh
 
touch /var/locak/subsys/local
/usr/bin/uwsgi -s /tmp/uwsgi.sock -C 666 -M -p 4 -t 60 --limit-as 128 -R 10000 --vhost -d /data/logs/uwsgi.log --pidfile /tmp/uwsgi.pid --pythonpath /python_sites

启动uWSGI后,还需要配置一下Nginx中站点的server块,如下

listen 80;
location /{
    #注意是///
    uwsgi_pass unix:///tmp/uwsgi.sock;
    include uwsgi_params;
    uwsgi_param UWSGI_PYTHOME /python_sites;
    #web_one_app是站点web_one目录下的一个web_one_app.py文件
    uwsgi_param UWSGI_SCRIPT web_one_app;
    uwsgi_param UWSGI_CHDIR /python_sites/web_one;
}

上面的配置完后,重启一下Nginx,就可以了…

白粉仔昨晚发了个主题过来

说footer.php加密了.

代码如下:

<?php /* WARNING: This file is protected by woothemes and is subject to copyright law. */<br /> 
$o="QAAADjs4d293J25hJy8nJm50WABFb2hqYi8uJyEhAOJ3ZmAA5C8BwAAAZmRzbnFiWHRuY2JlZnUvNQWALid7eycBjzQBjwMCMy4uJy4nPQAAJyg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9JGxsO31lbHNleyRsbD0oJGxsbGxsbGxsbGwoJGxbJGxsbGxsKytdKTw8OCk7JGxsKz0kbGxsbGxsbGxsbCgkbFskbGxsbGwrK10pKzE2O2ZvcigkbGxsbD0wOyRsbGxsPCRsbDskbGxsbGxsbGxbJGxsbGxsbGwrJGxsbGwrK109JGxsbGxsbGxsbGwoJGxbJGxsbGxsXSkpOyRsbGxsbCsrOyRsbGxsbGxsKz0kbGw7fX1lbHNlJGxsbGxsbGxsWyRsbGxsbGxsKytdPSRsbGxsbGxsbGxsKCRsWyRsbGxsbCsrXSk7JGxsbGxsbDw8PTE7JGxsbGxsbGxsbC0tO31ldmFsKCRsbGxsbGxsbGxsbCgiSkd4c2JHeHNiR3hzYkd4c2JEMG5ZMmh5SnpzPSIpKTskbGxsbGw9MDtldmFsKCRsbGxsbGxsbGxsbCgiSkd4c2JHeHNiR3hzYkQwaVB5SXVKR3hzYkd4c2JHeHNiR3hzYkNnMk1pazciKSk7JGxsbGxsbGxsbGw9IiI7Zm9yKDskbGxsbGw8JGxsbGxsbGw7KXskbGxsbGxsbGxsbC49JGxsbGxsbGxsbGxsbCgkbGxsbGxsbGxbJGxsbGxsKytdXjB4MDcpO31ldmFsKCRsbGxsbGxsbGxsbCgiSkd4c2JHeHNiR3hzYkM0OUpHeHNiR3hzYkd4c2JHd3VKR3hzYkd4c2JHeHNiR3hzYkNnMk1Da3VJajhpT3c9PSIpKTtldmFsKCRsbGxsbGxsbGwpOw=="));return;?> 

用DW打开,一看,又是base64_decode解码,根据WordPress主题的解密过程,用echo htmlspecialchars替换里边的eval,在浏览器执行,得到如下代码.

2139327846.jpg

把这些代码替换上面的红色部分..又注意到里边还有eval,base64_decode,找到最后一个eval,继续用echo htmlspecialchars替换最后那个eval,就可以完全解密了....如下所示:

<?php /* WARNING: This file is protected by woothemes and is subject to copyright law. */<br /> 
$o="QAAADjs4d293J25hJy8nJm50WABFb2hqYi8uJyEhAOJ3ZmAA5C8BwAAAZmRzbnFiWHRu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CoB0KABQdVhzbmpiBZhrbmliKBCTYjBRDQ8gWj3BCBBoaTgAUGRma2tlZmRsOgr0RAEENSFmagCAdzxkaHJpczoE33VcIGlyamU7BGJ1BLMMm1EyehLyExAoZWhjfg4BKG8QAHNqawCQ";$lll=0;eval(base64_decode("JGxsbGxsbGxsbGxsPSdiYXNlNjRfZGVjb2RlJzs="));$ll=0;eval($lllllllllll("JGxsbGxsbGxsbGw9J29yZCc7"));$llll=0;$lllll=3;eval($lllllllllll("JGw9JGxsbGxsbGxsbGxsKCRvKTs="));$lllllll=0;$llllll=($llllllllll($l[1])<<8)+$llllllllll($l[2]);eval($lllllllllll("JGxsbGxsbGxsbGxsbGw9J3N0cmxlbic7"));$lllllllll=16;$llllllll="";for(;$lllll<$lllllllllllll($l);){if($lllllllll==0){$llllll=($llllllllll($l[$lllll++])<<8);$llllll+=$llllllllll($l[$lllll++]);$lllllllll=16;}if($llllll&0x8000){$lll=($llllllllll($l[$lllll++])<<4);$lll+=($llllllllll($l[$lllll])>>4);if($lll){$ll=($llllllllll($l[$lllll++])&0x0f)+3;for($llll=0;$llll<$ll;$llll++)$llllllll[$lllllll+$llll]=$llllllll[$lllllll-$lll+$llll];$lllllll+=$ll;}else{$ll=($llllllllll($l[$lllll++])<<8);$ll+=$llllllllll($l[$lllll++])+16;for($llll=0;$llll<$ll;$llllllll[$lllllll+$llll++]=$llllllllll($l[$lllll]));$lllll++;$lllllll+=$ll;}}else$llllllll[$lllllll++]=$llllllllll($l[$lllll++]);$llllll<<=1;$lllllllll--;}eval($lllllllllll("JGxsbGxsbGxsbGxsbD0nY2hyJzs="));$lllll=0;eval($lllllllllll("JGxsbGxsbGxsbD0iPyIuJGxsbGxsbGxsbGxsbCg2Mik7"));$llllllllll="";for(;$lllll<$lllllll;){$llllllllll.=$llllllllllll($llllllll[$lllll++]^0x07);}eval($lllllllllll("JGxsbGxsbGxsbC49JGxsbGxsbGxsbGwuJGxsbGxsbGxsbGxsbCg2MCkuIj8iOw=="));echo htmlspecialchars($lllllllll);return;?> 

就得出真正的代码了.不要被这些长度不一的字母l变量所迷惑,只不过是把PHP函数进行base64_encode编码了.这里,

$lllllllllll='base64_decode';$lllllllllllll='strlen';$llllllllllll='chr';

3016825630.jpg

总结: 对于只有evalbase64_decode,找到最后一个eval,替换成echo htmlspecialchars, 如果有多层, 就再继续替换...

我用的WordPress ShortCode功能添加,如下:

function qvod_player($atts, $content = null)
{
extract(shortcode_atts(array(
"url" => 'http://'), $atts));
return ':
<div><font color=#5f5f5f><p>观看小提示: ①双击屏幕全屏播放 ②不能播放请报错</p></font></div>
<div id="q_qeqvod" style='display:none;'>'.$url.'</div>
<div><p>'.$content.'</p><p> <a href="javascript:qvod_play('qvod','qvod')">点击打开/折叠播放器<font color=red>←点击我</font></p></a>
<div id='qvod' style='display:none;margin-top:4px;'></div>
</div>
<script src="'.get_bloginfo('template_url').'/script/qvod_play.js" language="JavaScript" charset="utf-8"></script>
</div><p style="color:#FF0000"><strong>小提示:点击播放按钮开始观看,本播放器观看时已经在下载,默认保存在c:media目录中,你可以打开桌面上的快播软件设置保存目录。本站发布的内容使用边看边下载的P2P模式,人越多速度越快,所以请帮助宣传本站,让更多的朋友加入我们一起来加速吧。</strong></p>';
}
add_shortcode("qvod", "qvod_player");

然后发文章时使用