mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-02 02:53:19 +00:00
commit
95d10b3a26
2 changed files with 13 additions and 27 deletions
|
@ -62,7 +62,6 @@ r_re = re.compile(r'(.*) dnsmasq\[\d+\]: (reply|cached) (.*) is (.*)')
|
||||||
def create_tables():
|
def create_tables():
|
||||||
qt = '''
|
qt = '''
|
||||||
CREATE TABLE IF NOT EXISTS queries (
|
CREATE TABLE IF NOT EXISTS queries (
|
||||||
id integer primary key autoincrement,
|
|
||||||
source text,
|
source text,
|
||||||
query_type text,
|
query_type text,
|
||||||
name text,
|
name text,
|
||||||
|
@ -74,7 +73,6 @@ def create_tables():
|
||||||
|
|
||||||
ft = '''
|
ft = '''
|
||||||
CREATE TABLE IF NOT EXISTS forwards (
|
CREATE TABLE IF NOT EXISTS forwards (
|
||||||
id integer primary key autoincrement,
|
|
||||||
resolver text,
|
resolver text,
|
||||||
name text,
|
name text,
|
||||||
ts datetime
|
ts datetime
|
||||||
|
@ -85,7 +83,6 @@ def create_tables():
|
||||||
|
|
||||||
rt = '''
|
rt = '''
|
||||||
CREATE TABLE IF NOT EXISTS replies (
|
CREATE TABLE IF NOT EXISTS replies (
|
||||||
id integer primary key autoincrement,
|
|
||||||
ip text,
|
ip text,
|
||||||
reply_type text,
|
reply_type text,
|
||||||
name text,
|
name text,
|
||||||
|
@ -106,21 +103,18 @@ def convert_date(ds):
|
||||||
def parse_query(query):
|
def parse_query(query):
|
||||||
m = q_re.match(query)
|
m = q_re.match(query)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
counts['qc'] += 1
|
|
||||||
add_query(m.group(4), m.group(2), m.group(3), m.group(1))
|
add_query(m.group(4), m.group(2), m.group(3), m.group(1))
|
||||||
|
|
||||||
|
|
||||||
def parse_forward(query):
|
def parse_forward(query):
|
||||||
m = f_re.match(query)
|
m = f_re.match(query)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
counts['fc'] += 1
|
|
||||||
add_forward(m.group(3), m.group(2), m.group(1))
|
add_forward(m.group(3), m.group(2), m.group(1))
|
||||||
|
|
||||||
|
|
||||||
def parse_reply(query):
|
def parse_reply(query):
|
||||||
m = r_re.match(query)
|
m = r_re.match(query)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
counts['rc'] += 1
|
|
||||||
add_reply(m.group(4), m.group(2), m.group(3), m.group(1))
|
add_reply(m.group(4), m.group(2), m.group(3), m.group(1))
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,21 +142,18 @@ if len(sys.argv) != 2:
|
||||||
|
|
||||||
logfile = sys.argv[1]
|
logfile = sys.argv[1]
|
||||||
|
|
||||||
counts = {'lc': 0, 'qc': 0, 'fc': 0, 'rc': 0, 'bc':0}
|
|
||||||
|
|
||||||
# Create the SQLite connection
|
# Create the SQLite connection
|
||||||
conn = sqlite3.connect('/etc/pihole/pihole.db')
|
conn = sqlite3.connect('/etc/pihole/pihole.db')
|
||||||
|
|
||||||
|
with conn:
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
create_tables()
|
create_tables()
|
||||||
|
|
||||||
# Parse the log file.
|
# Parse the log file.
|
||||||
for line in open(logfile):
|
with open(logfile) as f:
|
||||||
|
for line in f:
|
||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
counts['lc'] += 1
|
|
||||||
|
|
||||||
if (counts['lc'] % 10000) == 0:
|
|
||||||
conn.commit()
|
|
||||||
|
|
||||||
if ': query[' in line:
|
if ': query[' in line:
|
||||||
parse_query(line)
|
parse_query(line)
|
||||||
|
@ -173,7 +164,3 @@ for line in open(logfile):
|
||||||
elif (': reply ' in line) or (': cached ' in line):
|
elif (': reply ' in line) or (': cached ' in line):
|
||||||
parse_reply(line)
|
parse_reply(line)
|
||||||
|
|
||||||
else:
|
|
||||||
counts['bc'] += 1
|
|
||||||
|
|
||||||
conn.commit()
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ with conn:
|
||||||
# Ready new table for list of domains
|
# Ready new table for list of domains
|
||||||
gt = '''
|
gt = '''
|
||||||
CREATE TABLE IF NOT EXISTS gravity (
|
CREATE TABLE IF NOT EXISTS gravity (
|
||||||
idx INTEGER PRIMARY KEY ASC,
|
|
||||||
domain text
|
domain text
|
||||||
)
|
)
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in a new issue