Chinaunix首页 | 论坛 | 博客
  • 博客访问: 503801
  • 博文数量: 81
  • 博客积分: 7010
  • 博客等级: 少将
  • 技术积分: 1500
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-15 10:51
文章分类

全部博文(81)

文章存档

2011年(1)

2009年(22)

2008年(58)

我的朋友

分类: LINUX

2008-06-20 01:00:27

工具包
httpd-2.2.4
下载地址
][/url]
apr-1.2.8
apr-util-1.2.8
下载地址
][/url]
openssl
openssl-0.9.7d.tar.gz
下载地址

证书软件
ssl.ca-0.1.tar.gz
下载地址

SVN
下载地址
][/url]
//////////////////////////////////////////////////////////////////////
开始安装
安装apr,apr-util
tar zxvf apr-1.2.8.tar.gz
cd apr-1.2.8
./configure --prefix=/usr/local/apr
make
make install
tar zxvf apr-util-1.2.8.tar.gz
cd apr-util-1.2.8
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make
make install
# tar zxvf openssl-0.9.8d.tar.gz
# cd openssl-0.9.8d
# ./config --prefix=/usr/local/openssl
# make
# make install
安装apache
tar zxvf httpd-2.2.3.tar.gz
cd httpd-2.2.3
./configure --prefix=/usr/local/apache2 --enable-so
--enable-rewrite=share --enable-proxy=share --enable-proxy-ajp=share
--enable-dav=share --enable-dav-fs --with-apr=/usr/local/apr/
--with-apr-util=/usr/local/apr-util/ --enable-ssl=static
--with-ssl=/usr/local/ssl --enable-mods-shared=all
//此语句意思是把所有模块都添加上,在这里可以不写
make
make install
其中/usr/local/ssl目录自己建
安装SVN
tar zxvf subversion-1.4.2.tar.gz
cd subversion-1.4.2
./configure --with-apxs=/usr/local/apache2/bin/apxs
--prefix=/usr/local/subversion --with-apr=/usr/local/apr
--with-apr-util=/usr/local/apr-util --with-ssl --with-zlib
--enable-maintainer-mode
make
make install
///////////////////////////////////////////////////////////
配置
1.//创建库文件
# mkdir /home/svnroot/repository //进入subversion的bin目录
# cd /usr/local/subversion/bin
# ./svnadmin create /home/svnroot/repository/test //创建仓库"test"
# ls –l /home/svnroot/repository/test //看看是不是多了些文件,如果是则说明Subversion安装成功了
# cd /usr/local/subverion/bin
# ./svn import /home/user/import file:///home/svnroot/repository/test
–m "init" //这条语句将把路径/home/user/import下找到的文件导入到你创建的Subversion
仓库中去,其中/user/import/下有自己的项目.提交后的修订版为1。
apache进程的权限:因为所有跟仓库传输的操作都是通过apache进程进行的,所以即使你给svn用户设置了很大的权限,但是apache进程没有
访问仓库或者相关文件的权限也没有用,apache进程的权限设置在 /usr/local/apache2/conf/httpd.conf
文件中配置,找到文件中的这两行:
User daemon # 将daemon改为svnroot,
Group daemon
2.修改Apache配置文件
# cd /usr/local/apache2/bin
# ./apachect1 start //启动Apache
# vi /opt/apache2/conf/httpd.conf //在最下面添加
#LoadModule dav_svn_module modules/mod_dav_svn.so
#LoadModule authz_svn_module modules/mod_authz_svn.so //如果有可不写

DAV svn
SVNParentPath /home/svnroot/repository/ //svn父目录
AuthzSVNAccessFile /home/svnroot/repository/authz.conf //权限配置文件
AuthType Basic //连接类型设置
AuthName "Subversion.zoneyump" //连接框提示
AuthUserFile /home/svnroot/repository/authfile //用户配置文件
Require valid-user //采用何种认证

#"Require valid-user"告诉apache在authfile中所有的用户都可以访问。如果没有它,则只能第一个用户可以访问新建库
3.创建用户配置文件
#cd /usr/local/apache2/bin
#htpasswd -c /home/svnroot/repository/authfile wooin //其中authfile是通过来创建的
4.配置用户访问权限:
vi /home/svnroot/repository/authz.conf //示例
[groups]
admin = mangosoft
[/]
@admin = rw
[test:/]
@admin = rw
wooin = rw
为了简化配置,3个版本库共用1个权限配置文件/home/svnroot/repository/pwd.conf。如有必要,也可以分开。文件中定义用户组和版本库目录权限。
注意:
* 权限配置文件中出现的用户名必须已在用户配置文件中定义。
* 对权限配置文件的修改立即生效,不必重启svn。
用户组格式:
[groups]
<用户组名> = <用户1>,<用户2>
其中,1个用户组可以包含1个或多个用户,用户间以逗号分隔。
版本库目录格式:
[<版本库>:/项目/目录]
@<用户组名> = <权限>
<用户名> = <权限>
其中,方框号内部分可以有多种写法:
/,表示根目录及以下。根目录是svnserve启动时指定的,我们指定为/home/svnroot/repository。这样,/就是表示对全部版本库设置权限。
test:/,表示对版本库test设置权限
权限主体可以是用户组、用户或*,用户组在前面加@,*表示全部用户。权限可以是w、r、wr和空,空表示没有任何权限。
5. 不让其他人有该目录的权限
# chown -R svnroot:daemon /home/svnroot/repository //,这里的用户名可以自己定
6.检验是否成功
重启apache
cd /usr/local/apache2/bin/
./apachectl restart
//打开浏览器访问]
//如果有东西显示就说明成功。
注意:如果没成功在/usr/local/apache2/htdocs/下建一个favicon.ico文件.
////////////////////////////////////////////////////////
基本应用
1. 权限管理
1)增加用户
# htpasswd [-c] /home/svnroot/repository/authfile wooin //第一次设置用户时使用-c表示新建一个用户文件。回车后输入用户密码,
# htpasswd authfile 用户名(加入新的用户) //完成对用户 的增加
2)权限分配
# vi /home/svnroot/repository/authz.conf
[test:/] //这表示,仓库test的根目录下的访问权限
wooin = rw //test仓库wooin用户具有读和写权限
bao = r //test仓库bao用户具有读权限
[test2:/] //test2仓库根目录下的访问权限
wooin = r //wooin用户在test2仓库根目录下只有读权限
bao = //bao用户在 test2仓库根目录下无任何权限
[/] //这个表示在所有仓库的根目录下
* = r //这个表示对所有的用户都具有读权限
#[groups] //这个表示群组设置
#svn1-developers = wooin, bao //这个表示某群 组里的成员
#svn2-developers = wooin
#[svn1:/]
#@svn1-developers = rw //如果在前面加上@符号,则表 示这是个群组权限设置
将这个设置完成后。重启Apache,就可以通过

这个URL来访问仓库了,当然,受权限的限制,必须是合法用户才能访问且具有相应的权限
2. 在/etc/profile的结尾设置一些svn启动时要做的工作
# start apache server for svn
/usr/sbin/apachectl start
export SVN_EDITOR=vi
3.
如果linux的登录用户名密码都和svn的其中一个用户名密码相同时,在checkout的时候不会要求输入用户名密码直接就可以checkout出
来。比如:linux有个用户wooin,svn也有一个用户wooin,并且密码都是一样的,当用wooin登录linux后,执行checkout,
可以直接提取出源码文件,不用输入认证信息。
4. 在svn使用过程中牵扯到几种权限:文件系统的权限,linux系统权限,svn用户的权限,apache进程的权限。
文件系统的权限,linux系统权限:这里相同的意思,就是平时大家使用linux时文件夹和文件的访问权限。在
svn建立仓库,文件夹,配置文件的时候用svnroot用户,并将仓库权限设置为700,不允许其他用户直接通过文件系统查看,只能由svnroot进
行管理。
apache进程的权限:因为所有跟仓库传输的操作都是通过apache进程进行的,所以即使你给svn用户设置了很大的权限,但是apache进程没有
访问仓库或者相关文件的权限也没有用,apache进程的权限设置在 /usr/local/apache2/conf/httpd.conf
文件中配置,找到文件中的这两行:
User daemon # 将daemon改为svnroot,让apache进程以svnroot的身份运行
Group daemon
svn用户的权限:就是在authz.conf文件中设置的权限信息,是svn用来管理仓库访问权限的。
5. 重新部署SVN仓库
需要将目前的某个仓库导出,并导入到另一个仓库(可以导入到该仓库的指定目录下),
要用到以下的命令:
# svnadmin dump /home/svnroot/sonatina/ > stn.dump // 导出所有版本到stn.dump文件中
# svnadmin dump /home/svnroot/sonatina/ --revision 10 > stn.r10.dump // 或者也可以只导出其中一个版本
# svnadmin dump /home/svnroot/sonatina/ --revision 0:10 > stn.r0-10.dump // 或者也可以导出多个版本,比如0-10版本
# svnadmin load /home/svnroot/sonatinab/ --parent-dir trunk <
stn.r0-10.dump //
导入到sonatinab/trunk目录下,如果不指定--parent-dir,则会导入到根目录sonatinab/下
//////////////////////////////////////////////////////////
使用ssh方式验证:
cd /home/usr/local/subversion/bin
./svn list svn+ssh://ip地址/home/svnroot/repository/test
如果出现这个问题:
subversion/libsvn_repos/repos.c:1004: (apr_err=165005)
svn: Expected version '3' of repository; found version '5'
把home/svnroot/repository/test/format文件中的5改成3就可以了.
///////////////////////////////////////////////////////
使用https方式验证
vi /usr/local/apache/conf/http.conf
# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf //把此处的#去掉
#
# Note: The following must must be present to support
# starting without SSL on platforms with no /dev/random equivalent
# but a statically compiled-in mod_ssl.
#
# cd /usr/local/apache2
# ./bin/apachectl start
Syntax error on line 108 of /usr/local/apache2/conf/ssl.conf:
SSLCertificateFile: file '/usr/local/apache2/conf/server.key' does not exist or is empty
这又是什么原因呢?因为我们没有配置ssl,需要生成ssl需要的证书。
以前使用apache1+mod_ssl的时候,make之后有一个这样的步骤
$ make certificate
可以用来生成ssl所用到的证书。
现在没有这个工具了,只能自己动手生成了,对证书不熟悉的人,有一个工具可以使用:
# cd /usr/local/apache2/conf
# tar zxvf ssl.ca-0.1.tar.gz
# cd ssl.ca-0.1
# ./new-root-ca.sh (生成根证书)
No Root CA key round. Generating one
Generating RSA private key, 1024 bit long modulus
...........................++++++
....++++++
e is 65537 (0x10001)
Enter pass phrase for ca.key: (输入一个密码)
Verifying - Enter pass phrase for ca.key: (再输入一次密码)
......
Self-sign the root CA... (签署根证书)
Enter pass phrase for ca.key: (输入刚刚设置的密码)
........
........ (下面开始签署)
Country Name (2 letter code) [MY]: CN
State or Province Name (full name) [Perak]: liaoning
Locality Name (eg, city) [Sitiawan]: dalian
Organization Name (eg, company) [My Directory Sdn Bhd]: jishikeyan
Organizational Unit Name (eg, section) [Certification Services Division]: ACSTAR
Common Name (eg, MD Root CA) []: yong
Email Address []: yong@yong.com.cn
这样就生成了ca.key和ca.crt两个文件,下面还要为我们的服务器生成一个证书:
# ./new-server-cert.sh server (这个证书的名字是server)
......
......
Country Name (2 letter code) [MY]: CN
State or Province Name (full name) [Perak]: liaoning
Locality Name (eg, city) [Sitiawan]: dalian
Organization Name (eg, company) [My Directory Sdn Bhd]: jishikeyan
Organizational Unit Name (eg, section) [Secure Web Server]: ACSTAR
Common Name (eg, ) []: localhost
Email Address []: yong@yong.com.cn
这样就生成了server.csr和server.key这两个文件。
还需要签署一下才能使用的:
# ./sign-server-cert.sh server
CA signing: server.csr -> server.crt:
Using configuration from ca.config
Enter pass phrase for ./ca.key: (输入上面设置的根证书密码)
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'liaoning'
localityName :PRINTABLE:'liaoning'
organizationName :PRINTABLE:'jishikeyan'
organizationalUnitName:PRINTABLE:'ACSTAR'
commonName :PRINTABLE:'localhost'
emailAddress :IA5STRING:'yongl@yong.com.cn'
Certificate is to be certified until Jul 16 12:55:34 2005 GMT (365 days)
Sign the certificate? [y/n]: y
1 out of 1 certificate requests certified, commit? [y/n] y
Write out database with 1 new entries
Data Base Updated
CA verifying: server.crt <-> CA cert
server.crt: OK
下面要按照ssl.conf里面的设置,将证书放在适当的位置。
# chmod 400 server.key
# cd ..
# mv ssl.ca-0.1/server.key server.key
# mv ssl.ca-0.1/server.crt server.crt
然后就可以启动啦!
# cd /usr/local/apache2
# ./bin/apachectl start
在浏览器中就可以进行https用户验证啦!
subversion验证
./svn list
验证“”的服务器凭证时发生错误:
- 本凭证并不是由受信任的权威机权所核发。请手动利用指纹以验证
凭证的有效性!
- 本凭证的主机名称不符。
凭证信息:
- 主机名称:
- 有效期间:自 Jan 25 07:55:48 2007 GMT 至 Jan 25 07:55:48 2008 GMT - 发行者:yong, jishi, dalian, liaoning, CN
- 指纹:49:c4:12:38:5e:03:df:52:64:eb:f4:02:b8:a4:f3:b0:2c:f7:8d:2a(R)拒绝,(t)暂时接受 或 (p)永远接受?t
填写证书密码
用户名
密码
登录成功!!!!!
//////////////////////////////////////////////////////
subversion基本操作
1.从服务器中拷贝库文件
#cd /usr/local/subversion/bin
#./svn checkout 地址/svn/test
[root@localhost bin]# ./svn checkout
认证领域:<> Subversion.zoneyump
“root”的密码:
认证领域:<> Subversion.zoneyump
用户登录名:gy
“gy”的密码:
A test/index.html
A test/dianhuaben
A test/dianhuaben/chaxun.jsp
A test/dianhuaben/modify.jsp
A test/dianhuaben/work
A test/dianhuaben/work/tldCache.ser
A test/dianhuaben/work/org
A test/dianhuaben/work/org/apache
A test/dianhuaben/work/org/apache/jsp
A test/dianhuaben/work/org/apache/jsp/addtel_jsp.java
A test/dianhuaben/work/org/apache/jsp/selectAllTel_jsp.java
A test/dianhuaben/work/org/apache/jsp/addtel_jsp.class
A test/dianhuaben/work/org/apache/jsp/selectAllTel_jsp.class
A test/dianhuaben/work/SESSIONS.ser
A test/dianhuaben/.tomcatplugin
A test/dianhuaben/.project
A test/dianhuaben/modifytel.jsp
A test/dianhuaben/WEB-INF
A test/dianhuaben/WEB-INF/_desktop.ini
A test/dianhuaben/WEB-INF/lib
A test/dianhuaben/WEB-INF/src
A test/dianhuaben/WEB-INF/web.xml
A test/dianhuaben/WEB-INF/.cvsignore
A test/dianhuaben/WEB-INF/classes
A test/dianhuaben/WEB-INF/classes/com
A test/dianhuaben/WEB-INF/classes/com/Telbook.java
A test/dianhuaben/WEB-INF/classes/com/Telbook.class
A test/dianhuaben/WEB-INF/classes/com/DataBaseConnection.java
A test/dianhuaben/WEB-INF/classes/com/DataBaseConnection.class
A test/dianhuaben/WEB-INF/classes/com/TelBean.java
A test/dianhuaben/WEB-INF/classes/com/TelBean.class
A test/dianhuaben/modifydel1.jsp
A test/dianhuaben/addtel.jsp
A test/dianhuaben/modify.html
A test/dianhuaben/chanxun.jsp
A test/dianhuaben/addtel.html
A test/dianhuaben/.classpath
A test/dianhuaben/deletetel.jsp
A test/dianhuaben/deltel.jsp
A test/dianhuaben/selectAllTel.jsp
A test/dianhuaben/index.html
A test/dianhuaben/.cvsignore
取出修订版 1。
2. 发布你的修改给别人,你可以使用Subversion的提交(commit)命令
#./svn commit 项目名或文件名
[root@localhost bin]# ./svn commit test/index.html
日志信息未改变,或是未指定
a)中断,c)继续,e)编辑
c
正在发送 test/index.html
传输文件数据.
提交后的修订版为 3。
3.状态查询(status)
#./svn status 路径/项目名
L some_dir # svn已经在.svn目录锁定了some_dir
M bar.c # bar.c的内容已经在本地修改过了
M baz.c # baz.c属性有修改,但没有内容修改
X 3rd_party # 这个目录是外部定义的一部分
? foo.o # svn并没有管理foo.o
! some_dir # svn管理这个,但它可能丢失或者不完
~ qux # 作为file/dir/link进行了版本控制,但类型已经改变
I .screenrc # svn不管理这个,配置确定要忽略它
A + moved_dir # 包含历史的添加,历史记录了它的来历
M + moved_dir/README # 包含历史的添加,并有了本地修改
D stuff/fish.c # 这个文件预定要删除
A stuff/loot/bloo.h # 这个文件预定要添加
C stuff/loot/lump.c # 这个文件在更新时发生冲突
C stuff/loot/glub.c # 文件在更新时发生属性冲突
R xyz.c # 这个文件预定要被替换
S stuff/squawk # 这个文件已经跳转到了分支
K dog.jpg # 文件在本地锁定;有锁定令牌
O cat.jpg # 文件在版本库被其他用户锁定
B bird.jpg # 文件本地锁定,但锁定发生错误
T fish.jpg # 文件本地锁定,但锁定丢失
4.检查修改的方式是svn diff命令,你可以通过不带参数的svn diff精确的找出你所做的修改
#./svn diff 项目名
root@localhost bin]# ./svn diff test
Index: test/index.html
===================================================================
--- test/index.html (修订版 2)
+++ test/index.html (工作拷贝)
@@ -1,6 +1,6 @@


- 人才库</html> <BR>+ <title>人才库资料</html> <BR><meta context="text/html;charset=UTF-8"> <BR></head> <BR><body> <BR>输出的格式为统一区别格式(unified diff format),删除的行前面加一个-,添加的行前面有一个+ <BR>svn diff命令也打印文件名和打补丁需要的信息,所以你可以通过重定向一个区别文件来生成“补丁” <BR>#./svn diff 项目名 > 文件名 <BR>[root@localhost bin]# ./svn diff test > haha <BR>[root@localhost bin]# ls <BR>haha svn svndumpfilter svnserve svnversion <BR>stn.dump svnadmin svnlook svnsync test <BR>生成一个haha文件 <BR>5.添加文件或目录(add) <BR>#./svn add 项目名/新建文件或目录 <BR>6.删除文件或目录(delete) <BR>#./svn delete 项目名/删除的文件或目录 <BR>svn delete 地址/svn_dir/repository/project_dir 这条命令刚好可以用来删除 <BR>7.列出仓库中的项目(list) <BR>svn list --verbose <BR>#./svn list --verbose file:///home/svnroot/repository/test/ <BR>[root@localhost bin]# ./svn list --verbose file:///home/svnroot/repository/test/ <BR>1 root 529 1月 25 14:16 .classpath <BR>1 root 4 1月 25 14:16 .cvsignore <BR>1 root 12288 1月 25 14:16 .genggai1.jsp.swp <BR>1 root 425 1月 25 14:16 .project <BR>1 root 358 1月 25 14:16 .tomcatplugin <BR>1 root 1月 25 14:16 WEB-INF/ <BR>1 root 10 1月 25 14:16 _desktop.ini <BR>1 root 29269 1月 25 14:16 a.gif <BR>1 root 1172 1月 25 14:16 chaxun.jsp <BR>1 root 1245 1月 25 14:16 genggai.jsp <BR>1 root 1787 1月 25 14:16 genggai1.jsp <BR>1 root 707 1月 25 14:16 genggai2.jsp <BR>6 wooin 1月 26 12:10 hehe/ <BR>4 wooin 1047 1月 26 11:48 index.html <BR>1 root 3719546 1月 25 14:16 love.mp3 <BR>1 root 3073 1月 25 14:16 rencaiku.txt <BR>1 root 1243 1月 25 14:16 shanchu.jsp <BR>1 root 409 1月 25 14:16 shanchu1.jsp <BR>1 root 1073 1月 25 14:16 tianjia.html <BR>1 root 813 1月 25 14:16 tianjia.jsp <BR>1 root 1月 25 14:16 work/ <BR>//////////////////////////////////////////////////////////////////////// <BR>subversion的分支与合并 <BR>1.建立分支 <BR>#cd /usr/local/subversion/bin <BR>#./svn copy -m "copy a branch" <BR>2.在分支上工作(导出分支到本地) <BR>#./svn checkout mycopy1 <BR>3.合并 <BR>#./svn merge -r 15:16 test</DIV> </div> <!-- <div class="Blog_con3_1">管理员在2009年8月13日编辑了该文章文章。</div> --> <div class="Blog_con2_1 Blog_con3_2"> <div> <!--<img src="/image/default/tu_8.png">--> <!-- JiaThis Button BEGIN --> <div class="bdsharebuttonbox"><A class=bds_more href="#" data-cmd="more"></A><A class=bds_qzone title=分享到QQ空间 href="#" data-cmd="qzone"></A><A class=bds_tsina title=分享到新浪微博 href="#" data-cmd="tsina"></A><A class=bds_tqq title=分享到腾讯微博 href="#" data-cmd="tqq"></A><A class=bds_renren title=分享到人人网 href="#" data-cmd="renren"></A><A class=bds_weixin title=分享到微信 href="#" data-cmd="weixin"></A></div> <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> <!-- JiaThis Button END --> </div> 阅读(2923) | 评论(0) | 转发(0) | <div class="HT_line3"></div> </div> <div class="Blog_con3_3"> <div><span id='digg_num'>0</span><a href="javascript:void(0)" id='digg' bid='1732269' url='/blog/digg.html' ></a></div> <p>上一篇:<a href="/uid-20164947-id-1732266.html">rsync</a></p> <p>下一篇:<a href="/uid-20164947-id-1732270.html">centos 中yum的使用</a></p> </div> </div> <!-- <div class="Blog_con3_4 Blog_con3_5"> <div class="Blog_tit2 Blog_tit7">热门推荐</div> <ul> <li><a href="" title="" target='blank' ></a></li> </ul> </div> --> </div> </div> <div class="Blog_right1_7" id='replyList'> <div class="Blog_tit3">给主人留下些什么吧!~~</div> <!--暂无内容--> <!-- 评论分页--> <div class="Blog_right1_6 Blog_right1_12"> </div> <!-- 评论分页--> <div class="Blog_right1_10" style="display:none"> <div class="Blog_tit3">评论热议</div> <!--未登录 --> <div class="Blog_right1_8"> <div class="nologin_con1"> 请登录后评论。 <p><a href="http://account.chinaunix.net/login" onclick="link(this)">登录</a> <a href="http://account.chinaunix.net/register?url=http%3a%2f%2fblog.chinaunix.net">注册</a></p> </div> </div> </div> <div style="text-align:center;margin-top:10px;"> <script type="text/javascript" smua="d=p&s=b&u=u3118759&w=960&h=90" src="//www.nkscdn.com/smu0/o.js"></script> </div> </div> </div> </div> <input type='hidden' id='report_url' value='/blog/ViewReport.html' /> <script type="text/javascript"> //测试字符串的长度 一个汉字算2个字节 function mb_strlen(str) { var len=str.length; var totalCount=0; for(var i=0;i<len;i++) { var c = str.charCodeAt(i); if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) { totalCount++; }else{ totalCount+=2; } } return totalCount; } /* var Util = {}; Util.calWbText = function (text, max){ if(max === undefined) max = 500; var cLen=0; var matcher = text.match(/[^\x00-\xff]/g), wlen = (matcher && matcher.length) || 0; //匹配url链接正则 http://*** var pattern = /http:\/\/([\w-]+\.)+[\w-]+(\/*[\w-\.\/\?%&=][^\s^\u4e00-\u9fa5]*)?/gi; //匹配的数据存入数组 var arrPt = new Array(); var i = 0; while((result = pattern.exec(text)) != null){ arrPt[i] = result[0]; i++; } //替换掉原文本中的链接 for(var j = 0;j<arrPt.length;j++){ text = text.replace(arrPt[j],""); } //减掉链接所占的长度 return Math.floor((max*2 - text.length - wlen)/2 - 12*i); }; */ var allowComment = '0'; //举报弹出层 function showJuBao(url, cid){ $.cover(false); asyncbox.open({ id : 'report_thickbox', url : url, title : '举报违规', width : 378, height : 240, scroll : 'no', data : { 'cid' : cid, 'idtype' : 2 , 'blogurl' : window.location.href }, callback : function(action){ if(action == 'close'){ $.cover(false); } } }); } $(function(){ //创建管理员删除的弹出层 $('#admin_article_del').click(function(){ $.cover(false); asyncbox.open({ id : 'class_thickbox', html : '<div class="HT_layer3_1"><ul><li class="HT_li1">操作原因:<select class="HT_sel7" id="del_type" name="del_type"><option value="广告文章">广告文章</option><option value="违规内容">违规内容</option><option value="标题不明">标题不明</option><option value="文不对题">文不对题</option></select></li><li class="HT_li1" ><input class="HT_btn4" id="admin_delete" type="button" /></li></ul></div>', title : '选择类型', width : 300, height : 150, scroll : 'no', callback : function(action){ if(action == 'close'){ $.cover(false); } } }); }); $('#admin_delete').live('click' , function(){ ///blog/logicdel/id/3480184/url/%252Fblog%252Findex.html.html var type = $('#del_type').val(); var url = '/blog/logicdel/id/1732269/url/%252Fuid%252F20164947.html.html'; window.location.href= url + '?type=' + type; }); //顶 js中暂未添加&过滤 $('#digg').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $('#digg').attr('bid'); var url = $('#digg').attr('url'); var digg_str = $.cookie('digg_id'); if(digg_str != null) { var arr= new Array(); //定义一数组 arr = digg_str.split(","); //字符分割 for( i=0 ; i < arr.length ; i++ ) { if(bid == arr[i]) { showErrorMsg('已经赞过该文章', '消息提示'); return false; } } } $.ajax({ type:"POST", url:url, data: { 'bid' : bid }, dataType: 'json', success:function(msg){ if(msg.error == 0) { var num = parseInt($('#digg_num').html(),10); num += 1; $('#digg_num').html(num); $('#digg').die(); if(digg_str == null) { $.cookie('digg_id', bid, {expires: 30 , path: '/'}); } else { $.cookie('digg_id', digg_str + ',' + bid, {expires: 30 , path: '/'}); } showSucceedMsg('谢谢' , '消息提示'); } else if(msg.error == 1) { //showErrorMsg(msg.error_content , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); } else if(msg.error == 2) { showErrorMsg(msg.error_content , '消息提示'); } } }); }); //举报弹出层 /*$('.box_report').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var url = $('#report_url').val(); var cid = $(this).attr('cid'); $.cover(false); asyncbox.open({ id : 'report_thickbox', url : url, title : '举报违规', width : 378, height : 240, scroll : 'no', data : { 'cid' : cid, 'idtype' : 2 }, callback : function(action){ if(action == 'close'){ $.cover(false); } } }); });*/ //评论相关代码 //点击回复显示评论框 $('.Blog_a10').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } if(allowComment == 1) { showErrorMsg('该博文不允许评论' , '消息提示'); return false; } var tid = $(this).attr('toid');//留言作者id var bid = $(this).attr('bid');//blogid var cid = $(this).attr('cid');//留言id var tname = $(this).attr('tname'); var tpl = '<div class="Blog_right1_9">'; tpl += '<div class="div2">'; tpl += '<textarea name="" cols="" rows="" class="Blog_ar1_1" id="rmsg">文明上网,理性发言...</textarea>'; tpl += '</div>'; tpl += '<div class="div3">'; tpl += '<div class="div3_2"><a href="javascript:void(0);" class="Blog_a11" id="quota_sbumit" url="/Comment/PostComment.html" tid="'+tid+'" bid="'+bid+'" cid="'+cid+'" tname="'+tname+'" ></a><a href="javascript:void(0)" id="qx_comment" class="Blog_a12"></a></div>'; tpl += '<div class="div3_1"><a href="javascript:void(0);" id="mface"><span></span>表情</a></div>'; tpl += '<div class="clear"></div>'; tpl += '</div>'; tpl += '</div>'; $('.z_move_comment').html(''); $(this).parents('.Blog_right1_8').find('.z_move_comment').html(tpl).show(); }); //引用的评论提交 $('#quota_sbumit').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $(this).attr('bid'); var tid = $(this).attr('tid');//被引用人的id var qid = $(this).attr('cid');//引用的id var url = $(this).attr('url'); var text = $('#rmsg').val(); var tname = $(this).attr('tname'); if(text == '' || text=='文明上网,理性发言...') { showErrorMsg('评论内容不能为空!' , '消息提示'); return false; } else { if(mb_strlen(text) > 1000){ showErrorMsg('评论内容不能超过500个汉字' , '消息提示'); return false; } } $.ajax({ type: "post", url: url , data: {'bid': bid , 'to' : tid , 'qid' : qid , 'text': text , 'tname' : tname }, dataType: 'json', success: function(data){ if(data.code == 1){ var tpl = '<div class="Blog_right1_8">'; tpl+= '<div class="Blog_right_img1"><a href="' +data.info.url+ '" >' + data.info.header + '</a></div>'; tpl+= '<div class="Blog_right_font1">'; tpl+= '<p class="Blog_p5"><span><a href="' +data.info.url+ '" >' + data.info.username + '</a></span>' + data.info.dateline + '</p>'; tpl+= '<p class="Blog_p7"><a href="' + data.info.quota.url + '">' + data.info.quota.username + '</a>:'+ data.info.quota.content + '</p>'; tpl+= '<p class="Blog_p8">' + data.info.content + '</p><span class="span_text1"><a href="javascript:void(0);" class="Blog_a10" toid=' + data.info.fuid + ' bid=' + data.info.bid + ' cid=' + data.info.cid + ' tname = ' + data.info.username + ' >回复</a> |  <a class="comment_del_mark" style="cursor:pointer" url="' + data.info.delurl + '" >删除</a> |  <a href="javascript:showJuBao(\'/blog/ViewReport.html\','+data.info.cid+')" class="box_report" cid="' + data.info.cid + '" >举报</a></span></div>'; tpl+= '<div class="z_move_comment" style="display:none"></div>'; tpl+= '<div class="Blog_line1"></div></div>'; $('#replyList .Blog_right1_8:first').before(tpl); $('.z_move_comment').html('').hide(); } else if(data.code == -1){ //showErrorMsg(data.info , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); } }, error: function(){//请求出错处理 } }); }); //底部发表评论 $('#submitmsg').click(function(){ if(allowComment == 1) { showErrorMsg('该博文不允许评论' , '消息提示'); return false; } var bid = $(this).attr('bid'); var toid = $(this).attr('toid'); var text = $('#reply').val(); var url = $(this).attr('url'); if(text == '' || text=='文明上网,理性发言...') { showErrorMsg('评论内容不能为空!' , '消息提示'); return false; } else { if(mb_strlen(text) > 1000){ showErrorMsg('评论内容不能超过500个汉字' , '消息提示'); return false; } } $.ajax({ type: "post", url: url , data: {'bid': bid , 'to' : toid ,'text': text}, dataType: 'json', success: function(data){ if(data.code == 1) { var tpl = '<div class="Blog_right1_8">'; tpl += '<div class="Blog_right_img1"><a href="' +data.info.url+ '" >' + data.info.header + '</a></div>'; tpl += '<div class="Blog_right_font1">'; tpl += '<p class="Blog_p5"><span><a href="' +data.info.url+ '" >' + data.info.username + '</a></span>' + data.info.dateline + '</p>'; tpl += '<p class="Blog_p6">' + data.info.content + '</p>'; tpl += '<div class="div1"><a href="javascript:void(0);" class="Blog_a10" toid=' + data.info.fuid + ' bid=' + data.info.bid + ' cid=' + data.info.cid + '>回复</a> |  <a class="comment_del_mark" style="cursor:pointer" url="' + data.info.delurl + '">删除</a> |  <a href="javascript:showJuBao(\'/blog/ViewReport.html\','+data.info.cid+')" class="box_report" cid="' + data.info.cid + '">举报</a></div>'; tpl += '<div class="z_move_comment" style="display:none"></div>'; tpl += '</div><div class="Blog_line1"></div></div>'; $('.Blog_tit3:first').after(tpl); $('#reply').val('文明上网,理性发言...'); } else if(data.code == -1) { showErrorMsg(data.info , '消息提示'); } }, error: function(){//请求出错处理 } }); }); //底部评论重置 $('#reset_comment').click(function(){ $('#reply').val('文明上网,理性发言...'); }); //取消回复 $('#qx_comment').live('click' , function(){ $('.z_move_comment').html('').hide(); }); $('#rmsg, #reply').live({ focus:function(){ if($(this).val() == '文明上网,理性发言...'){ $(this).val(''); } }, blur:function(){ if($(this).val() == ''){ $(this).val('文明上网,理性发言...'); } } }); //删除留言确认 $('.comment_del_mark').live('click' , function(){ var url = $(this).attr('url'); asyncbox.confirm('删除留言','确认', function(action){ if(action == 'ok') { location.href = url; } }); }); //删除时间确认 $('.del_article_id').click(function(){ var delurl = $(this).attr('delurl'); asyncbox.confirm('删除文章','确认', function(action){ if(action == 'ok') { location.href = delurl; } }); }); /* //字数限制 $('#rmsg, #reply').live('keyup', function(){ var id = $(this).attr('id'); var left = Util.calWbText($(this).val(), 500); var eid = '#errmsg'; if(id == 'reply') eid = '#rerrmsg'; if (left >= 0) $(eid).html('您还可以输入<span>' + left + '</span>字'); else $(eid).html('<font color="red">您已超出<span>' + Math.abs(left) + '</span>字 </font>'); }); */ //加载表情 $('#face').qqFace({id : 'facebox1', assign : 'reply', path : '/image/qqface/'}); $('#mface').qqFace({id : 'facebox', assign : 'rmsg', path:'/image/qqface/'}); /* $('#class_one_id').change(function(){ alert(123213); var id = parseInt($(this).val() , 10); if(id == 0) return false; $('.hidden_son_class span').each(function( index , dom ){ if( dom.attr('cid') == id ) { } }); }); */ //转载文章 var turn_url = "/blog/viewClassPart.html"; $('#repost_bar').click(function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var id = $(this).attr('bid'); asyncbox.open({ id : 'turn_class_thickbox', url : turn_url, title : '转载文章', width : 330, height : 131, scroll : 'no', data : { 'id' : id }, callback : function(action){ if(action == 'close'){ $.cover(false); } } }); }); /* //转发文章 $('#repost_bar').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $(this).attr('bid'); var url = $(this).attr('url'); asyncbox.confirm('转载文章','确认', function(action){ if(action == 'ok'){ $.ajax({ type:"POST", url:url, data: { 'bid' : bid }, dataType: 'json', success:function(msg){ if(msg.error == 0){ showSucceedMsg('转发成功!', '消息提示'); }else if(msg.error == 1){ //location.href = '/index.php?r=site/login'; showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); }else{ showErrorMsg(msg.error_content, '消息提示'); } } }); } }); }); */ }); </script> <!--该部分应该放在输出代码块的后面才起作用 --> <script type="text/javascript"> SyntaxHighlighter.autoloader( 'applescript /highlight/scripts/shBrushAppleScript.js', 'actionscript3 as3 /highlight/scripts/shBrushAS3.js', 'bash shell /highlight/scripts/shBrushBash.js', 'coldfusion cf /highlight/scripts/shBrushColdFusion.js', 'cpp c /highlight/scripts/shBrushCpp.js', 'c# c-sharp csharp /highlight/scripts/shBrushCSharp.js', 'css /highlight/scripts/shBrushCss.js', 'delphi pascal /highlight/scripts/shBrushDelphi.js', 'diff patch pas /highlight/scripts/shBrushDiff.js', 'erl erlang /highlight/scripts/shBrushErlang.js', 'groovy /highlight/scripts/shBrushGroovy.js', 'java /highlight/scripts/shBrushJava.js', 'jfx javafx /highlight/scripts/shBrushJavaFX.js', 'js jscript javascript /highlight/scripts/shBrushJScript.js', 'perl pl /highlight/scripts/shBrushPerl.js', 'php /highlight/scripts/shBrushPhp.js', 'text plain /highlight/scripts/shBrushPlain.js', 'py python /highlight/scripts/shBrushPython.js', 'ruby rails ror rb /highlight/scripts/shBrushRuby.js', 'scala /highlight/scripts/shBrushScala.js', 'sql /highlight/scripts/shBrushSql.js', 'vb vbnet /highlight/scripts/shBrushVb.js', 'xml xhtml xslt html /highlight/scripts/shBrushXml.js' ); SyntaxHighlighter.all(); function code_hide(id){ var code = document.getElementById(id).style.display; if(code == 'none'){ document.getElementById(id).style.display = 'block'; }else{ document.getElementById(id).style.display = 'none'; } } </script> <!--回顶部js2011.12.30--> <script language="javascript"> lastScrollY=0; function heartBeat(){ var diffY; if (document.documentElement && document.documentElement.scrollTop) diffY = document.documentElement.scrollTop; else if (document.body) diffY = document.body.scrollTop else {/*Netscape stuff*/} percent=.1*(diffY-lastScrollY); if(percent>0)percent=Math.ceil(percent); else percent=Math.floor(percent); document.getElementById("full").style.top=parseInt(document.getElementById("full").style.top)+percent+"px"; lastScrollY=lastScrollY+percent; if(lastScrollY<200) { document.getElementById("full").style.display="none"; } else { document.getElementById("full").style.display="block"; } } var gkuan=document.body.clientWidth; var ks=(gkuan-960)/2-30; suspendcode="<div id=\"full\" style='right:-30px;POSITION:absolute;TOP:500px;z-index:100;width:26px; height:86px;cursor:pointer;'><a href=\"javascript:void(0)\" onclick=\"window.scrollTo(0,0);\"><img src=\"\/image\/top.png\" /></a></div>" document.write(suspendcode); window.setInterval("heartBeat()",1); </script> <!-- footer --> <div class="Blog_footer" style='clear:both'> <div><a href="http://www.chinaunix.net/about/index.shtml" target="_blank" rel="nofollow">关于我们</a> | <a href="http://www.it168.com/bottomfile/it168.shtml" target="_blank" rel="nofollow">关于IT168</a> | <a href="http://www.chinaunix.net/about/connect.html" target="_blank" rel="nofollow">联系方式</a> | <a href="http://www.chinaunix.net/about/service.html" target="_blank" rel="nofollow">广告合作</a> | <a href="http://www.it168.com//bottomfile/flgw/fl.htm" target="_blank" rel="nofollow">法律声明</a> | <a href="http://account.chinaunix.net/register?url=http%3a%2f%2fblog.chinaunix.net" target="_blank" rel="nofollow">免费注册</a> <p>Copyright 2001-2010 ChinaUnix.net All Rights Reserved 北京皓辰网域网络信息技术有限公司. 版权所有 </p> <div>感谢所有关心和支持过ChinaUnix的朋友们 <p><a href="http://beian.miit.gov.cn/">16024965号-6 </a></p> </div> </div> </div> </div> <script language="javascript"> //全局错误提示弹出框 function showErrorMsg(content, title, url){ var url = url || ''; var title = title || '消息提示'; var html = ''; html += '<div class="HT_layer3_1 HT_layer3_2"><ul><li><p><span class="login_span1"></span>' + content + '</p></li>'; if(url == '' || url.length == 0){ html += '<li class="HT_li1"><input type="button" class="HT_btn2" onclick=\'close_windows("error_msg")\'></li>'; } else { html += '<li class="HT_li1"><input type="button" class="login_btn1" onclick="location.href=\'' + url + '\'"></li>'; } html += '</ul></div>'; $.cover(true); asyncbox.open({ id: 'error_msg', title : title, html : html, 'callback' : function(action){ if(action == 'close'){ $.cover(false); } } }); } //全局正确提示 function showSucceedMsg(content, title , url ){ var url = url || ''; var title = title || '消息提示'; var html = ''; html += '<div class="HT_layer3_1 HT_layer3_2"><ul><li><p><span class="login_span2"></span>' + content + '</p></li>'; if(url == '' || url.length == 0){ html += '<li class="HT_li1"><input type="button" class="HT_btn2" onclick=\'close_windows("error_msg")\'></li>'; } else { html += '<li class="HT_li1"><input type="button" class="HT_btn2" onclick="location.href=\'' + url + '\'"></li>'; } html += '</ul></div>'; $.cover(true); asyncbox.open({ id: 'error_msg', title : title, html : html, 'callback' : function(action){ if(action == 'close'){ $.cover(false); } } }); } //关闭指定id的窗口 function close_windows(id){ $.cover(false); $.close(id); } //公告 var tID; var tn; // 高度 var nStopTime = 5000; // 不同行间滚动时间隔的时间,值越小,移动越快 var nSpeed = 50; // 滚动时,向上移动一像素间隔的时间,值越小,移动越快 var isMove = true; var nHeight = 25; var nS = 0; var nNewsCount = 3; /** * n 用于表示是否为第一次运行 **/ function moveT(n) { clearTimeout(tID) var noticev2 = document.getElementById("noticev2") nS = nSpeed; // 只在第一次调用时运行,初始化环境(有没有参数) if (n) { // 设置行高 noticev2.style.lineHeight = nHeight + "px"; // 初始化显示位置 tn = 0; // 刚进入时在第一行停止时间 nS = nStopTime; } // 判断鼠标是否指向层 if (isMove) { // 向上移动一像素 tn--; // 如果移动到最下面一行了,则移到顶行 if (Math.abs(tn) == nNewsCount * nHeight) { tn = 0; } // 设置位置 noticev2.style.marginTop = tn + "px"; // 完整显示一行时,停止一段时间 if (tn % nHeight == 0) { nS = nStopTime; } } tID = setTimeout("moveT()", nS); } moveT(1); // 此处可以传入任何参数 </script> <script type="text/javascript"> // var _gaq = _gaq || []; // _gaq.push(['_setAccount', 'UA-20237423-2']); // _gaq.push(['_setDomainName', '.chinaunix.net']); // _gaq.push(['_trackPageview']); // // (function() { // var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; // ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; // var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); // })(); </script> <script type="text/javascript"> var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://"); document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F0ee5e8cdc4d43389b3d1bfd76e83216b' type='text/javascript'%3E%3C/script%3E")); function link(t){ var href= $(t).attr('href'); href+="?url="+encodeURIComponent(location.href); $(t).attr('href',href); //setCookie("returnOutUrl", location.href, 60, "/"); } </script> <script type="text/javascript" src="/js/jquery.qqFace.js"></script> </body> </html>