存档
本文为catseven落伍缩写,已发到落伍者,供catseven落伍。如有引用,请注明出处。
因为工作,经常要操作数据库,考虑到安全问题,在防火墙中没有开mssql端口。每次遇到必须使用查询分析器的时候,就麻烦了。为了方便工作,写了这个工具。
可以操作所有ADODB连接的数据库,当然包括MSSQL,MySQL,Access….
本工具分为两个部分。控制代码和输入代码。
控制代码就是VBScript部分,可以实现所有逻辑操作,和asp操作一样。
输入部分就是Link、SQL分别用于输入连接字符串,SQL语句。如果控制代码不调用这些语句,则这部分无实际意义。
默认,控制代码已经写好一个模板。点击执行,可以执行SQL语句,点击下载,将执行结果保存到Excel中。
因为能直接操作VbScript,如果要使用,请设置好权限。新建mssql用户,在iis中设置mssql.asp以mssql的身份执行。mssql.asp的访问权限只有mssq用户。mssql对所有文件无任何权限,对mssql.asp只有可读权限。
代码如下:
<%
Server.ScriptTimeout = 9999
starttime = timer()
cmd = request("cmd")
if request("out")="xls" and trim(cmd)<>"" then
response.ContentType = "application/octet-stream"
response.AddHeader "Content-Disposition", "attachment;filename=执行结果.xls"
execute(cmd)
response.end
end if
%>
<style type="text/css">
form{text-align:center}
textarea{width:100%;height:200px;border:solid 1px #CCC;}
input{height:20px;vertical-align:middle}
input.input{border:solid 1px #CCC;width:40%;line-height:18px;color:#090}
a{font-size:12px;color:#C00;text-decoration:none;}
</style>
<form action="mssql.asp" method="post">
<textarea name="cmd">
<%
if trim(cmd)="" then
%>set Conn = Server.CreateObject("ADODB.Connection")
Conn.open Request("link")
Set Rs=Conn.Execute(Request("sql"))
for i = 0 to Rs.Fields.Count-1
[...]
< %
set FSO = Server.CreateObject("Scripting.FileSystemObject")
Function CheckFile(byval Path)
pathArr = Split(Path,"/")
Path = replace(Path,"/" & pathArr(ubound(pathArr)),"")
if Path = "" then Exit Function
if not FSO.FolderExists(Server.Mappath(Path)) then
Call CheckFile(Path)
FSO.CreateFolder(Server.Mappath(Path))
end if
End Function
Function newFile(byval Path)
if Right(Path,1)="/" then
Path = Path & "index.html"
end if
Call CheckFile(Path)
Set newFile = FSO.CreateTextFile(Server.Mappath(Path))
End Function
set n = newFile("/index/cat2/path/demo/111/222/333/444/555/666/777/888/")
n.write "12345"
n.close
set n = nothing
set n = newFile("../../../../test.css")
n.write "body{}"
n.close
set n = nothing
%>
ASP模板技术探讨之关联变量。
先看可实现的效果:
访问变量,需要与ASP结合
关联变量:支持关联的变量
{$#关联名#}
Assgin #关联名#,#变量#
{$#关联名#}
{$#关联名#.#索引#}
Assgin #关联名#,Array(“123″)
{$#关联名#.0}
{$#关联名#.#索引#.#索引#}
Assgin #关联名#,Array(Array(“123″))
{$#关联名#.0.0}
{$#关联名#.#索引#…..#索引#}
Assgin #关联名#,Array(Arr..ay(“123″)))
{$#关联名#.0…0}
{$#关联名#.#Directionary.Key#}
Assgin #关联名#,#DirectionaryName#
{$#关联名#.#Directionary.Key#}
<%
Dim outHtml
outHtml = "xxx" ‘加载模板
function Assign(t,n)
if isArray(n) then
for x=0 to ubound(n)
Assign t&"."&x,n(x)
next
elseif isobject(n) then
for each x in n
Assign t&"."&x,n.item(x)
next
else
if isnull(n) then
outHtml=replace(outHtml,"{$"&t&"}","")
else
outHtml=replace(outHtml,"{$"&t&"}",n)
end if
end if
end function
%>
又好久没有更新日志了,上次谈到将工作用的脚本换成php,现在发现这是一个非常非常明智的选择。
在Linux也可以直接用php当作脚本,处理工作的事情。也算是“跨平台脚本”咯~~~
今天说一下JS压缩,呵呵,这种工具我可写不出来,但是网上牛人已经帮我们写出了相应的类:JavaScriptPacker(http://creativecommons.org/licenses/LGPL/2.1/)
我们直接调用就可以咯,比如将test_resource.js压缩成test.js。
<?php
#demo.php
require_once ‘class.JavaScriptPacker.php’;
$packer = new JavaScriptPacker(file_get_contents("./test_resource.js"), ‘Normal’, true, false);
file_put_contents("./test.js",$packer->pack());
?>
直接 php demo.php
想下一个CentOS玩玩,在线太慢,想到局域网内有个公共文件共享的服务器,开了ftp。
所处于一个超级内部局域网。我的机器ip为10.1.0.175,公共数据存储在10.0.0.254。用FlashFxp拉下来,速度很快,竟然能达到8MB。但是到数据2G的时候,就停止了。难道FlashFxp传输超过2g文件不可以吗?
在网上找到很久,也没有找到解决办法,忽然想到了Windows自带了一个ftp。连上去,一会就下载完了。还是Windows自带的好哦。
当PHP.ini设置register_globals = On是,通过GET提交的数据可以直接使用表单名调用GET提交的数据。asp就不可以,我想到了asp的execute,也谢了一个脚本,还能过滤SQL注入字符串
<%
Dim myRegExp
set myRegExp=New RegExp
myRegExp.Pattern = "[^a-z0-9_]"
myRegExp.Global=True
for each Req in Request.Querystring
ReqV=Request.Querystring(Req)
if trim(ReqV)<>"" then
ReqV=replace(ReqV,"""","""""")
Req=myRegExp.Replace(Req,"")
Execute(Req&"="""&ReqV&"""")
end if
next
response.write a
%>
调用很简单。比如GET提交/get_Test.asp?a=111&b=222
则直接可以使用Response.write a,输出结果为111。简单吧~
再次感谢小秦(Q48080163)提出的bug