Hello guys, how are you?
I had have a server running debian 7 and had to make a new one with debian 12.
The python on the old server, was python 2.7.2+ and the new one is. 3.11.2.
I’m using a cgi to show a block page for the SquidGuard, but the problem is, It’ll bring the error page without the info about ip adress, user, page accessed and so on. It’ll only show the html code, the rest it won’t.
I tried and read on the net and nothing made it work, so here I’m. Hope you can help me
The string it’ll get from the access is
“GET /cgi-bin/squidGuard.cgi?clientaddr=192.168.0.11&clientname=192.168.0.11&clientuser=&clientident=admin&srcclass=netherworld&url=http://www.google.com/&targetclass=google HTTP/1.1” 200 695 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36”
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Script to show a error page for SquidGuard
import cgi
import sys
formData = cgi.FieldStorage()
from time import strftime
t = strftime("%d-%b-%y %H:%M:%S")
print ("Content-type: text/html\n")
print ("""<html>
<head>
<title>Access Denied</title>
<STYLE type="text/css"><!--BODY{background-color:red;font-family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE>
<H1>ERRO</H1>
<H2>The requested URL couldn't be retrieved</H2>
<HR noshade size="1px">
<P>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="Helder Guerreiro">
<meta name="language" content="pt">
<meta http-equiv="cache-control" content="no-cache">
</head>
<body>
<br>
<STRONG><font color="yellow" size=4>
Forbidden Access. Your access has been recorded!
</STRONG><br><br><br></font>
""")
#formData = cgi.FieldStorage()
#if not ((form.in("clientaddr")) or \
#(form.in("clientname")) or \
# (form.in("clientuser")) or \
# (form.in("clientident")) or \
# (form.in("srcclass")) or \
# (form.in("targetclass")) or \
# (form.in("url")) ):
## print "<h2>Erro</h2>"
if "clientaddr" not in formData or "clientname" not in formData or "clientuser" not in formData or "clientident" not in formData or "srcclass" not in formData or "targetclass" not in formData or "url" not in formData:
print ("<p>Thie script is not to be accessed!")
sys.exit(0)
#return
#print "<h1>Your access has been blocked!</h1>"
print ("""<p>This system has a Webfilter.
All websites that are not allowed is blocked.
<br>If you think this is a mistake,
get in touch with the admin on admin@admin.com.<br><br>
<ul>""")
try:
clientaddr = formData["clientaddr"].value
except:
clientaddr = ""
try:
clientname = formData["clientname"].value
except:
clientname = ""
try:
clientuser = formData["clientuser"].value
except:
clientuser = ""
try:
clientident = formData["clientident"].value
except:
clientident = ""
try:
srcclass = formData["srcclass"].value
except:
srcclass = ""
try:
targetclass = formData["targetclass"].value
except:
targetgroup = ""
try:
url = formData["url"].value
except:
url = ""
print ("<STRONG><li>IP:"), clientaddr
#print "</STRONG><li>Domain:", clientname
#print "</STRONG><li>Teste:", clientuser
print ("<li>User:"), clientident
print ("</STRONG><li>Date and hour:"), t
print ("<li>ACL SquidGuard:"), srcclass
print ("<li>Kind:"), targetclass>
> print ("<li>Blocked URL:<STRONG>"), url
> print ("""</STRONG></ul>
>
>
> </body>
> </html>
> """)
```'''