帮老婆的弟媳做一个网站,下载了一份现成的PHP代码,不过都是加了密的.有些改动需要对PHP文件进行,可是发现这份东西是用了ZEND加密的,网上现成的DEZENDER的软件不少,绝大多数是基于黑刀改装的,效果不错,可是都不能对目录结构进行原样复制.找到一份梅花三弄版 DEZENDER据说可以保持原目录结构,可是不知是什么原因,居然在我的计算机上运行不起来.于是我就想自己写一个程序来做这事,顺便学习一下C#.
Form上的几个基本控件:
- txtFolder: PHP文件所在的根目录, 新目录将自动取名为目录名_new
- button1: txtFolder的browse按钮
- CheckBox1: With Subfolders 标记, 即操作是否包括各级子目录
- CheckBox2: Process PHP files only 标记, 即操作是否只针对PHP文件,如果要针对所有文件,则非PHP文件将被复制到指定目录
- txtLog: 日志框, 输出所有信息
- stsInfo: StatusBar, 显示一些提示信息
- btnList: 显示所有文件到txtLog
- btnbProcess: 对文件进行操作
几个private变量:
- private bool WithSub = true; //对应checkbox1
- private bool PhpOnly = false; //对应checkbox2
- private string RootDir; //对应txtFolder
检查运行环境, PHP.EXE是黑刀的执行文件, 必须在当前目录下存在.
- private void Form1_Load(object sender, EventArgs e)
- {
- if (!File.Exists(".php.exe"))
- {
- MessageBox.Show("No php.exe found, the program may not run properly!");
- Application.Exit();
- }
- dlgOpenFld.SelectedPath = "D:temp";
- }
另外, 在PHP.INI文件中, 要确认以下文件的路径名正确, 个人感觉用相对路径会好一些
- [Zend]
- zend_extension_manager.optimizer_ts="libOptimizer-3.3.0"
- zend_extension_ts="libZendExtensionManager.dll"
下面, BROWSE文件夹操作.
- private void button1_Click(object sender, EventArgs e)
- {
- if ( dlgOpenFld.ShowDialog() == DialogResult.OK )
- {
- txtFolder.Text = dlgOpenFld.SelectedPath;
- }
- }
最重要的操作之一, 用递归取得文件列表, 在这一步里,用到了List<>这样的数据类型, 这是用于未知长度数组的, 可以看到, C#对于文件,目录的操作都与DELPHI有了非常大的不同, 这就是FRAMEWORK:
- private List<FileInfo> getFiles(string tDir, bool SubFolder)
- {
- List<FileInfo> FileList = new List<FileInfo>();
- DirectoryInfo fDir = new DirectoryInfo(tDir);
- DirectoryInfo[] subDir = fDir.GetDirectories();
- FileInfo[] sFile = fDir.GetFiles();
- if (SubFolder)
- {
- foreach (DirectoryInfo d in subDir)
- {
- FileList.AddRange(getFiles(tDir + "" + d.Name, SubFolder));
- }
- }
- foreach (FileInfo f in sFile)
- {
- FileList.Add(f);
- }
- return FileList;
- }
下一步, 就是对取得的文件列表进行操作了,新文件夹自动取名为XXX_NEW, 并且对文件列表按规则进行操作, 即是只解密PHP文件, 还是要同时复制其他非PHP文件:
- private void button1_Click_1(object sender, EventArgs e)
- {
- if (!Directory.Exists(txtFolder.Text)||(txtFolder.Text.IndexOf(" ")>0))
- {
- MessageBox.Show("Directory "" + txtFolder.Text + "" is invalid! (No space allowed)", "Invalid folder selection", MessageBoxButtons.OK,MessageBoxIcon.Error);
- return;
- }
- RootDir = txtFolder.Text;
- string newDir=RootDir + "_new";
- List<FileInfo> FileList = new List<FileInfo>();
- FileList = getFiles(txtFolder.Text, WithSub);
- for (int i = 0; i < FileList.Count; i++)
- {
- string tNewDir = FileList[i].DirectoryName.Replace(RootDir, newDir);
- if (!Directory.Exists(tNewDir))
- {
- Directory.CreateDirectory(tNewDir);
- }
- if (FileList[i].Extension != ".php")//&&(FileList[i].
- {
- File.Copy(FileList[i].DirectoryName + "" + FileList[i].Name, tNewDir + "" + FileList[i].Name);
- txtLog.AppendText("COPIED! " + i.ToString() + " - " + FileList[i].DirectoryName + "" + FileList[i].Name + "nn");
- }
- else
- {
- if (runphp(FileList[i].DirectoryName + "" + FileList[i].Name, tNewDir))
- {
- txtLog.AppendText("DECRYPTED! " + i.ToString() + " - " + FileList[i].DirectoryName + "" + FileList[i].Name + "nn");
- }
- else
- {
- txtLog.AppendText("FAILED TO DECRYPT! " + i.ToString() + " - " + FileList[i].DirectoryName + "" + FileList[i].Name + "nn");
- }
- }
- }
- }
这是解码PHP文件, 通过建立新进程来调用外部EXE文件:
- private bool runphp(string filename, string NewFolder)
- {
- try
- {
- string EXE_PATH = @".";
- System.Diagnostics.Process process = new System.Diagnostics.Process();
- process.StartInfo.FileName = "php.exe";
- process.StartInfo.WorkingDirectory = EXE_PATH;
- process.StartInfo.CreateNoWindow = true;
- process.StartInfo.Arguments = filename + " /tab /indent:1 /path:" + NewFolder + " /ext:* /noexpire";
- process.Start();
- if (process.HasExited)
- {
- //txtLog.AppendText("finished!nn");
- //return true;
- }
- return true;
- }
- catch (Exception e)
- {
- throw e;
- //return false;
- }
- }
其他的代码就不一一罗列了. 只是临时使用的代码, 功能还非常简单.
一直想要搞一个自己的BLOG系统,以便能够象个笔记本一样记录一点东西.曾经申请了GOOGLE的BLOGSPOT和MSN空间,都有非常不尽如人意的地方,比如说,BLOGSPOT的功能非常欠缺,简直就是一个NOTEPAD.而MSN的倒是很花哨,可都是些我并不需要的功能,上传图片,插入代码都不能很好地实现,所以就想自己装一个BLOG系统在家里的服务器上.虽然家用网络上传速度只有512K,但是只我一个人用,没关系.用得好了找个空间上传也不错啊,呵呵
试过了几个系统,比如说BO-BLOG,CTB-BLOG,SA-BLOG,TYPECHO,个人觉得还是这个BO-BLOG系统最合适,因为它至少有我所需要的这些功能:
1. 简洁的外观
2. 首页直接登录和发帖链接, 如果一定要登录确认再发帖真是非常麻烦的事
3. 一个优秀的编辑器, BO-BLOG默认的编辑器很普通,但是可以下载并安装FCKeditor可视化编辑器,这个编辑器不是一般的强,本地上传插入图片,加入代码,文本编辑等内容应有尽有.可说是最强的编辑器了
4. 有良好的扩展性.虽然我并不一定会使用那些音乐皮肤等内容,但是备着这功能总是能让人更满意.
差不多就这些了吧,对了,刚开始时我是把BO-BLOG安装到免费空间的, 后来才复制到自家机器上. 改变网站的URL以后,记得要修改BLOG\DATA\CONFIG.PHP文件,把$config['blogurl']变量改为新的网址.
今天收到一封信,是从ATOS数据库服务器代理那儿发来的,说发现服务器运行有错误:
The job failed. Unable to determine if the owner (域\用户) of job Replication agents checkup has server access (reason: Could not obtain information about Windows NT group/user '域\用户', error code 0x5. [SQLSTATE 42000] (Error 15404)).
I did not find any login by the name 域\用户 on the server, but there was user on database PVTxxxx05 by the same name and it mapped on to login mySQLLOGINNAME which had dbo rights on the database.
The error [SQLSTATE 42000] (Error 15404) most likely means the machine account doesn't have permission to query the Active directory, cause generally the local service does not have any rights to query / check the identity of the connecting user.
Changing the job owner to sa might solve the issue.
Kindly look into it and suggest on it.




