~ubuntu-branches/ubuntu/saucy/nginx/saucy-updates

« back to all changes in this revision

Viewing changes to debian/modules/naxsi/contrib/naxsi-ui/nx_parser.py

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry, Cyril Lavier, Michael Lustfield, Kartik Mistry
  • Date: 2012-05-14 11:15:00 UTC
  • mfrom: (4.2.49 sid)
  • Revision ID: package-import@ubuntu.com-20120514111500-1y9ij7zulu9xnmry
Tags: 1.2.0-1
[Cyril Lavier]
* New upstream release. (Closes: #670306)
  + 1.2.x is stable release now.
* debian/modules/chunkin-nginx-module:
  + Updated chunkin-nginx-module to v0.23rc2-3-g85eca98.
* debian/modules/headers-more-module:
  + Updated headers-more-module to v0.17rc1-4-g33a82ed.
* debian/modules/nginx-development-kit:
  + Updated nginx-development-kit to v0.2.17-7-g24202b4.
* debian/modules/nginx-echo:
  + Updated nginx-echo to v0.38rc2-7-g080c0a1.
* debian/modules/nginx-lua:
  + Updated nginx-lua to v0.5.0rc25-5-g8d28785.
* debian/modules/nginx-upstream-fair:
  + Updated nginx-upstream-fair to a18b409.
* debian/modules/nginx-upload-progress:
  + Updated nginx-upload-progress to v0.9.0-0-ga788dea.
* debian/modules/naxsi:
  + Updated naxsi to 0.46
* debian/modules/README.Modules-versions:
  + Updated versions and URLs for modules.
* debian/naxsi-ui-extract, debian/naxsi-ui-intercept,
  debian/nginx-naxsi-ui.*, debian/naxsi-ui-extract.1,
  debian/naxsi-ui-intercept.1, debian/rules:
  + Added nginx-naxsi-ui package containing the learning daemon
    and the WebUI.
* debian/nginx-common.nginx.default, debian/nginx-common.nginx.init:
  + Renamed files to be compliant with the nginx-naxsi-ui package.
* debian/po:
  + Added needed files for using po-debconf.
  + Added French translation.
* debian/control:
  + Applied the modifications given after the review by Justin Rye.

[Michael Lustfield]
* debian/conf/uwsgi_params:
  + Added UWSGI_SCHEME to uwsgi_params. (Closes: #664878)
* debian/conf/sites-available/default:
  + Added allow directive for ipv6 localhost. (Closes: #664271)

[Kartik Mistry]
* debian/control:
  + wrap-and-sort.
* debian/copyright:
  + Added missing copyrights, minor formatting fixes.
* debian/nginx-common.nginx.init:
  + Added ulimit for restarts, Thanks to Daniel Roschka
    <danielroschka@phoenitydawn.de> for patch. (Closes: #673580)
* debian/conf/sites-available/default:
  + Added patch to fix deprecated "listen" directive, Thanks to
    Guillaume Plessis <gui@dotdeb.org> for patch. (Closes: #672632)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from datetime import datetime
 
2
 
1
3
import urlparse
2
4
import pprint
3
5
import MySQLdb
21
23
                            "auto_increment primary key "
22
24
                            ", action TEXT, msg TEXT, rx TEXT, "
23
25
                            "rx_type INT, url TEXT, "
24
 
                            "zone TEXT, arg_name TEXT);")
 
26
                            "zone TEXT, arg_name TEXT, INDEX id (rule_id));")
25
27
        
26
28
        self.cursor.execute("DROP TABLES IF EXISTS connections")
27
29
        self.cursor.execute("CREATE TABLE connections (connection_id INTEGER "
28
30
                            "auto_increment primary key, "
29
31
                            "src_peer_id INT, dst_peer_id INT, exception_id "
30
32
                            "INT, capture_id INT, date TIMESTAMP default "
31
 
                            "CURRENT_TIMESTAMP);")
 
33
                            "CURRENT_TIMESTAMP, match_id INT, INDEX id (connection_id, exception_id));")
32
34
        
33
35
        self.cursor.execute("DROP TABLES IF EXISTS peer")
34
36
        self.cursor.execute("CREATE TABLE peer (peer_id INTEGER "
35
37
                            "auto_increment primary key, "
36
 
                            "peer_ip TEXT, peer_host TEXT, peer_tags TEXT);")
 
38
                            "peer_ip TEXT, peer_host TEXT, peer_tags TEXT, INDEX id (peer_id));")
37
39
                
38
40
        self.cursor.execute("DROP TABLES IF EXISTS exception")
39
41
        self.cursor.execute("CREATE TABLE exception (exception_id integer "
40
42
                            "auto_increment primary key "
41
 
                            ",url TEXT, md5 TEXT, count INT default 1);")
 
43
                            ",url TEXT, md5 TEXT, count INT default 1, INDEX id (exception_id));")
42
44
        
43
45
        self.cursor.execute("DROP TABLES IF EXISTS match_zone")
44
46
        self.cursor.execute("CREATE TABLE match_zone (match_id INTEGER "
45
47
                            "auto_increment primary key, exception_id INTEGER, "
46
 
                            "zone TEXT, arg_name TEXT, rule_id INTEGER);")
 
48
                            "zone TEXT, arg_name TEXT, rule_id INTEGER, INDEX id (match_id, exception_id, rule_id));")
47
49
 
48
50
        self.cursor.execute("DROP TABLES IF EXISTS capture")
49
51
        self.cursor.execute("CREATE TABLE capture (capture_id INTEGER "
101
103
        capture_id = self.last_id()
102
104
        return capture_id
103
105
 
104
 
    def sig_to_db(self, raw_request, sig, add_capture=False):
 
106
    def sig_to_db(self, raw_request, sig, add_capture=False, date = None):
105
107
        """
106
108
        Insert signature into database. returns 
107
109
        associated connection_id.
116
118
                            "VALUES (%s)", (d.get("server", "")))
117
119
        host_id = self.last_id()
118
120
        self.cursor.execute('SELECT 1 FROM exception where md5=%s', (sig_hash))
119
 
        if self.cursor.fetchall():            
 
121
        if self.cursor.fetchall():
120
122
            self.cursor.execute("UPDATE exception SET url=%s,md5=%s,count = count + 1 "
121
123
                                "where md5=%s", (d.get("uri", ""), sig_hash, sig_hash))
122
124
            self.cursor.execute("select exception_id from exception where url=%s and md5=%s", (d.get('uri', ''), sig_hash))
128
130
        if self.cursor.fetchall():    
129
131
            add_capture = True
130
132
        capture_id = self.add_capture(exception_id, raw_request, add_capture)
 
133
 
 
134
        connection_id = self.last_id()
 
135
        self.add_matchzones(exception_id, d)
 
136
        match_id = self.last_id()
131
137
        self.cursor.execute("INSERT INTO connections (src_peer_id, "
132
 
                            "dst_peer_id, exception_id, capture_id)"
133
 
                            "VALUES (%s, %s, %s, %s)", (str(ip_id), 
 
138
                            "dst_peer_id, exception_id, capture_id, date, match_id)"
 
139
                            "VALUES (%s, %s, %s, %s, %s, %s)", (str(ip_id),
134
140
                                                        str(host_id), 
135
141
                                                        str(exception_id), 
136
 
                                                        str(capture_id)))
137
 
        connection_id = self.last_id()
138
 
        self.add_matchzones(exception_id, d)
 
142
                                                        str(capture_id), datetime.now() if date is None else date, str(match_id)))
139
143
#        self.cursor.execute("UPDATE exception SET md5=%s where "
140
144
#                            "exception_id=%s", (sig_hash, str(exception_id)))
141
145
        return (connection_id)
258
262
        return data
259
263
 
260
264
if __name__ == '__main__':
261
 
    db = MySQLConnector.MySQLConnector().connect()
262
 
    cursor = db.cursor(MySQLdb.cursors.DictCursor)
263
 
    bla = signature_extractor(cursor)
264
 
#    bla.extract_exceptions()
265
 
#    bla.extract_whitelists()
 
265
    print 'nope :)'