浏览模式: 标准 | 列表
分类:[原创]网站架设

给自己的Blog加上自定义错误页面

闲来无事,研究了一下 Sablog 模板和 .htaccess,顺便给自己的网站加上了自定义错误页面。参见以下链接:

http://www.snailium.net/error-400.html
http://www.snailium.net/error-401.html
http://www.snailium.net/error-403.html
http://www.snailium.net/error-404.html
http://www.snailium.net/error-500.html

阅读全文...

Tags: sablog, error, 错误, 页面, 自定义 | 分类:[原创]网站架设 | 评论:3 | Trackbacks:0 | 阅读:270

HTTP/1.1 状态代码

100 系列(信息)
100 Continue(客户端可以继续发送未发完的请求)
101 Switch Protocals(服务端/客户端所使用的协议不一致)
200 系列(成功)
200 OK(成功)
201 Created(已按请求创建新资源)
202 Accepted(请求已被接受)
203 Non-Authoritative Information(从第三方获取的信息)
204 No Content(服务端没有可返回的数据)
205 Reset Content(客户端需重置请求内容)
206 Partial Content(服务端返回部分数据)
300 系列(重定向)
300 Multiple Choices(多个资源可用)
301 Moved Permanently(资源已被移动)
302 Found(临时在其他地址找到相应资源)
303 See Other(在其他地址找到相应资源)
304 Not Modified
305 Use Proxy
306 (Unused)
307 Temporary Redirect
400 系列(错误)
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Long
415 Unsupported Media Type
416 Requested Range Not Satisfiable
417 Expectation Failed
500 系列(服务器错误)
500 Server Internal Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported

参考资料:http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Tags: http, status code, 状态 | 分类:[原创]网站架设 | 评论:0 | Trackbacks:0 | 阅读:373

Perl CGI 初体验

开始还满怀信心的打算拿 Perl 写一个文件上传管理程序,可是在写完了登陆部分之后就泄气了。原因很简单,服务器不支持 CGI::Session,而我又不想花时间去研究 Perl Cookie。

login.cgi
  1. #!/usr/bin/perl -w
  2. # ***********************************************
  3. # *  Handle User Login                          *
  4. # ***********************************************
  5. use strict;
  6.  
  7. use DBI;
  8. #use CGI::Session;
  9. use CGI;
  10. use Digest::MD5 qw(md5_hex);
  11.  
  12. # Get the CGI form data
  13. my $cgi = new CGI;
  14. # Fetch login username and password
  15. my $user_name = $cgi->param('username');
  16. my $user_pass = $cgi->param('password');
  17. $user_name =~ s/(?:\012\015|\012|\015)//g;
  18. $user_pass =~ s/(?:\012\015|\012|\015)//g;
  19. $user_pass = md5_hex($user_pass);
  20. my $user_login = 0
  21.  
  22. require "config.pm"
  23.  
  24. # Import Database configuration
  25. our $db_host;
  26. our $db_use;
  27. our $db_user;
  28. our $db_pass;
  29. our $db_table;
  30.  
  31. # Connect to database
  32. my $db_conn = DBI->connect("DBI:mysql:database=$db_use;host=$db_host","$db_user","$db_pass", {'RaiseError' => 1});
  33. print "Location: /error-503\n\n" unless $db_conn;
  34.  
  35. # Check if we have such password in database
  36. my $sql = $db_conn->prepare("SELECT username FROM `$db_table` WHERE user_password='$user_pass'");
  37. $sql->execute() or print "Location: /error-503\n\n";
  38.  
  39. # Process query result
  40. while(my @result = $sql->fetchrow_array()) {
  41.   if($user_name eq $result[0]) {
  42.     # Here we go. A user is found with the same username and password.
  43.     $user_login = 1
  44.     last;
  45.   }
  46. }
  47.  
  48. # Disconnect from database
  49. $db_conn->disconnect();
  50.  
  51. # Not pass user check? Kick it out!
  52. print "Location: /error-401\n\n" unless $user_login;
  53.  
  54. # User check successful! Log it in!
  55. print "Content-type: text/plain\n\nYes !";
  56.  
  57. exit(0);

其中登陆部分采用了《突发奇想,小改动解决安全问题》其中的方法。

看来要重操 PHP 旧业了……

Tags: perl, cgi, 登陆 | 分类:[原创]网站架设 | 评论:0 | Trackbacks:0 | 阅读:349

突发奇想,小改动解决安全问题

这几天一直在琢磨用 Perl CGI 架设网站,正好在网上看到了一篇关于 CGI 安全的文章,里面提到了数据库注入和远程执行等等安全问题。也就是说,比较安全的方法是屏蔽一系列特殊字符(比如说,管道“|”、引号“" '”、斜线“/”等等)。今天偶然间突发奇想,如果换一种思路,不需要过滤特殊字符也能做到脚本安全。

具体方法如下。(假设:用户名与密码存在 user 表中,密码用 md5 加密)

Pseudo-code
  1. $username = http_get("username"); // Get username from browser
  2. $password = http_get("password"); // Get password from browser
  3.  
  4. $password = md5($password);       // Make md5 hash for password
  5.  
  6. $mysql->connect();                // Connect to database
  7. // Get all users that have this password
  8. $rows = $mysql->query("SELECT username FROM `user` WHERE password='$password'");
  9.  
  10. // If no one match, must be username/password problem
  11. while($r = $rows->next()) {
  12.   if($r->username == $username) login_success();
  13. }
  14. die("Username/password incorrect!");

由于 md5 hash 不包括任何特殊字符,所以这段脚本对数据库无害。

优点总结:由于传递给数据库的字符串当中不包括任何特殊字符,因此没有任何注入危险。

缺点总结:一般来说,用户数据表都是拿用户名做索引,所以按密码查询效率相对低一些。但是考虑到用户登录的频繁程度,这个缺点就无所谓了。

Tags: 网站, 数据库, 安全, 注入 | 分类:[原创]网站架设 | 评论:2 | Trackbacks:0 | 阅读:347

[Discuz! 5.5]在帖子中加入eMule链接

本文介绍了如何在Discuz! 5.5论坛系统中加入eMule下载功能。具体实例参考VeryCD。

阅读全文...

Tags: discuz, emule | 分类:[原创]网站架设 | 评论:1 | Trackbacks:0 | 阅读:1337

架设UTF-8网站需要注意的BOM

BOM: Byte Order Mark(字节顺序标记)
本来BOM是用来确定UTF-8文件的字序的(Big Endian/Little Endian)。但是,如果BOM设置不当,便会造成网站白屏。

阅读全文...

Tags: utf8, bom | 分类:[原创]网站架设 | 评论:0 | Trackbacks:0 | 阅读:1141