logging到MySQL没有空行/跳过的logging?

我想弄清楚如何使MySQL的Squid代理日志。 我知道ACL顺序是非常重要的,但是我不确定我是否确切地理解ACL是什么或者做什么,这很难解释,但是希望在阅读时能看到我要去的地方!

我已经创build了一些线程来使squid与squid.conf中的助手交互,如下所示:

external_acl_type mysql_log %LOGIN %SRC %PROTO %URI php /etc/squid3/custom/mysql_lg.php acl ex_log external mysql_log http_access allow ex_log 

外部ACL助手(mysql_lg.php)是一个PHP脚本,如下所示:

 error_reporting(0); if (! defined(STDIN)) { define("STDIN", fopen("php://stdin", "r")); } $res = mysql_connect('localhost', 'squid', 'testsquidpw'); $dbres = mysql_select_db('squid', $res); while (!feof(STDIN)) { $line = trim(fgets(STDIN)); $fields = explode(' ', $line); $user = rawurldecode($fields[0]); $cli_ip = rawurldecode($fields[1]); $protocol = rawurldecode($fields[2]); $uri = rawurldecode($fields[3]); $q = "INSERT INTO logs (id, user, cli_ip, protocol, url) VALUES ('', '".$user."', '".$cli_ip."', '".$protocol."', '".$uri."');"; mysql_query($q) or die (mysql_error()); if ($fault) { fwrite(STDOUT, "ERR\n"); }; fwrite(STDOUT, "OK\n"); } 

我现在的configuration看起来像这样:

 ## Authentication Handler auth_param ntlm program /usr/bin/ntlm_auth --helper-protocol=squid-2.5-ntlmssp auth_param ntlm children 30 auth_param negotiate program /usr/bin/ntlm_auth --helper-protocol=squid-2.5-basic auth_param negotiate children 5 # Allow squid to update log external_acl_type mysql_log %LOGIN %SRC %PROTO %URI php /etc/squid3/custom/mysql_lg.php acl ex_log external mysql_log http_access allow ex_log acl localnet src 172.16.45.0/24 acl AuthorizedUsers proxy_auth REQUIRED acl SSL_ports port 443 acl Safe_ports port 80 # http acl Safe_ports port 21 # ftp acl Safe_ports port 443 # https acl CONNECT method CONNECT acl blockeddomain url_regex "/etc/squid3/bl.acl" http_access deny blockeddomain deny_info ERR_BAD_GENERAL blockeddomain # Deny requests to certain unsafe ports http_access deny !Safe_ports # Deny CONNECT to other than secure SSL ports http_access deny CONNECT !SSL_ports # Allow the internal network access to this proxy http_access allow localnet # Allow authorized users access to this proxy http_access allow AuthorizedUsers # FINAL RULE - Deny all other access to this proxy http_access deny all 

从testing来看,越接近底部,我就把日志logging线越less。 它甚至将空行放入MySQL表中。 /var/log/squid3/access.log中的基于文件的日志是正确的,但访问日志中的许多行在MySQL日志中是缺less的。 我忍不住想,这是顺序,我把行,因为我想logging一切到MySQL,未经身份validation的请求,阻止请求,哪个类别阻止了一个特定的请求。

我想在MySQL中这样做的原因是因为我试图通过一个自定义的基于Web的前端来pipe理一切,并希望避免使用任何shell命令和访问系统日志文件,如果我可以帮助它。 最终的结果是尽可能简单地维护,而不需要等待电话,而我添加一个新的规则并重新加载服务器!

希望有人能帮助我,因为这对我来说是一个非常有学问的经历,我很难过。

非常感谢您的帮助!

正确的PHP代码是:

 #!/usr/bin/php <?php error_reporting(0); if (! defined(STDIN)) { define("STDIN", fopen("php://stdin", "r")); } $res = mysql_connect('127.0.0.1', 'root', 'kbpbdxgh9j'); $dbres = mysql_select_db('intranet', $res); while (!feof(STDIN)) { $line = trim(fgets(STDIN)); $fields = explode(' ', $line); $user = rawurldecode($fields[0]); $cli_ip = rawurldecode($fields[1]); $protocol = rawurldecode($fields[2]); $uri = rawurldecode($fields[3]); if ($user!="") { $q = "INSERT INTO log (usuario, ip, protocolo, url) VALUES ('".$user."', '".$cli_ip."', '".$protocol."', '".$uri."');"; mysql_query($q) or die (mysql_error()); if ($fault) { fwrite(STDOUT, "ERR\n"); }; } fwrite(STDOUT, "OK\n"); } 

我会build议按照这些说明如何启用logging的所有ACL请求/允许/拒绝。 从这些你应该能够找出正确/错误地应用哪些ACL规则。