mirror of
https://github.com/r4sas/py-i2phosts
synced 2025-02-02 01:44:40 +00:00
injector: permit adding hostnames with non-unique b64 hashes
This commit is contained in:
parent
5cb9d1943a
commit
40a708bb60
14
injector
14
injector
@ -16,17 +16,15 @@ hostsfile = os.environ['HOME'] + '/.i2p/hosts.txt'
|
||||
f = open(hostsfile, 'r')
|
||||
for line in f:
|
||||
entry = line.split('=')
|
||||
# check for already existed hosts in database to avoid adding duplicates
|
||||
# 1. do lookup by hostname
|
||||
# 2. do lookup by base64 hash
|
||||
qs1 = i2phost.objects.filter(name=entry[0])
|
||||
qs2 = i2phost.objects.filter(name=entry[1])
|
||||
if not qs1.exists() and not qs2.exists():
|
||||
# Check for already existed hosts in database to avoid adding duplicates.
|
||||
# Do lookup by hostname only.
|
||||
qs = i2phost.objects.filter(name=entry[0])
|
||||
if qs.exists():
|
||||
print 'Host %s already exists' % entry[0]
|
||||
else:
|
||||
print 'Adding %s' % entry[0]
|
||||
host = i2phost(name=entry[0], b64hash=entry[1],
|
||||
description='Auto-added from external hosts.txt',
|
||||
activated=True)
|
||||
host.save()
|
||||
else:
|
||||
print 'Host %s already exists' % entry[0]
|
||||
f.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user