Skip to content

Commit 4b68920

Browse files
bump to support python 3
1 parent e4a0a98 commit 4b68920

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ An ICAP Server with yara scanner for URL and content.
44

55
## Requirement
66
* Squid Proxy 3.5
7-
* Python 2.7
8-
* [Yara-Python](https://github.com/VirusTotal/yara-python)
9-
* [ConfigParser](https://docs.python.org/2/library/configparser.html)
7+
* Python 3
108

119
## Squid Configuration
1210
```
@@ -21,6 +19,7 @@ adaptation_access service_resp allow all
2119
## Running
2220
```
2321
$ git clone https://github.com/RamadhanAmizudin/python-icap-yara
22+
$ pip install -r requirements.txt
2423
$ python server.py
2524
```
2625

@@ -75,7 +74,7 @@ License
7574
=======
7675
The MIT License (MIT)
7776

78-
Copyright (c) 2017 Ahmad Ramadhan Amizudin
77+
Copyright (c) 2021 Ahmad Ramadhan Amizudin
7978

8079
Permission is hereby granted, free of charge, to any person obtaining a copy
8180
of this software and associated documentation files (the "Software"), to deal

icapserver.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import socket
1919
import string
2020
import logging
21-
import urlparse
22-
import SocketServer
21+
import urllib.parse
22+
import socketserver
2323

2424
__version__ = "1.2"
2525

@@ -46,14 +46,14 @@ def __init__(self, code=500, message=None):
4646
msg = 'Code: %d Message: %s' % (code, message)
4747
LOG.error(msg)
4848

49-
class ICAPServer(SocketServer.TCPServer):
49+
class ICAPServer(socketserver.TCPServer):
5050
"""
5151
ICAP Server
5252
This is a simple TCPServer, that allows address reuse.
5353
"""
5454
allow_reuse_address = 1
5555

56-
class BaseICAPRequestHandler(SocketServer.StreamRequestHandler):
56+
class BaseICAPRequestHandler(socketserver.StreamRequestHandler):
5757
"""
5858
ICAP request handler base class.
5959
You have to subclass it and provide methods for each service
@@ -756,7 +756,7 @@ def example_RESPMOD(self):
756756
icap_server = ServerClass(server_address, HandlerClass)
757757

758758
sa = icap_server.socket.getsockname()
759-
print "Serving ICAP on", sa[0], "port", sa[1]
759+
print("Serving ICAP on", sa[0], "port", sa[1])
760760
icap_server.serve_forever()
761761

762762

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yara==1.7.7

server.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
import os, datetime, string, sys
44
import time, threading
55
import logging, logging.handlers
6-
import socket, SocketServer
6+
import socket, socketserver
77
from yarascanner import *
88
from icapserver import *
99

1010
def dump(obj):
1111
for attr in dir(obj):
12-
print "obj.%s = %s" % (attr, getattr(obj, attr))
12+
print("obj.%s = %s") % (attr, getattr(obj, attr))
1313

1414
yara = YaraScanner()
1515

16-
class ThreadingSimpleServer(SocketServer.ThreadingMixIn, ICAPServer):
16+
class ThreadingSimpleServer(socketserver.ThreadingMixIn, ICAPServer):
1717
pass
1818

1919
class YaraICAPHandler(BaseICAPRequestHandler):
@@ -52,10 +52,10 @@ def yara_RESPMOD(self):
5252
yara.Scan(content, self.enc_req, self.enc_req_headers, self.enc_res_headers, self.headers['x-client-ip'])
5353

5454
try:
55-
print 'Use Control-C to exit'
55+
print('Use Control-C to exit')
5656
server = ThreadingSimpleServer(('127.0.0.1', 1344), YaraICAPHandler)
5757
server.serve_forever()
5858
except KeyboardInterrupt:
5959
server.shutdown()
6060
server.server_close()
61-
print "Finished"
61+
print("Finished")

0 commit comments

Comments
 (0)