hostnames registration application for I2P
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# django setup
|
|
|
|
DJANGO_SETTINGS_MODULE = 'settings'
|
|
|
|
DJANGO_PROJECT_PATH = 'web'
|
|
|
|
sys.path.insert(1, DJANGO_PROJECT_PATH)
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = DJANGO_SETTINGS_MODULE
|
|
|
|
from web.postkey.models import i2phost
|
|
|
|
|
|
|
|
# hosts.txt we want to parse
|
|
|
|
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.
|
|
|
|
# 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()
|
|
|
|
f.close()
|