- repository reorganization
git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/trunk@242 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
parent
5c1a97e82d
commit
dea15a6c4f
29 changed files with 1053 additions and 0 deletions
74
testdb/addclient.py
Normal file
74
testdb/addclient.py
Normal file
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2007 Jan Dittberner
|
||||
# $Id$
|
||||
#
|
||||
import getopt, sys
|
||||
from gnuviechadmin.dblayer import *
|
||||
|
||||
def usage():
|
||||
print """Usage information:
|
||||
=====================
|
||||
%(process)s -h|--help
|
||||
- prints this help text
|
||||
|
||||
%(process)s --firstname=<firstname> --lastname=<lastname> \
|
||||
--address1=<address1> --town=<town> --zipcode=<zipcode> \
|
||||
[--address2=<address2>] [--country=<country>] [--state=<state>] \
|
||||
[--active=true|false] [--phone=<phone>] [--mobile=<mobile>]
|
||||
- adds a new client
|
||||
""" % {'process': sys.argv[0]}
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
(options, args) = getopt.getopt(sys.argv[1:], "h",
|
||||
['help',
|
||||
'firstname=', 'lastname=', 'address1=',
|
||||
'town=', 'zipcode=', 'address2=',
|
||||
'country=', 'state=', 'active=',
|
||||
'phone=', 'mobile='])
|
||||
except getopt.GetoptError:
|
||||
usage()
|
||||
sys.exit(1)
|
||||
|
||||
if (not options or
|
||||
dict(options).has_key('-h') or
|
||||
dict(options).has_key('--help') or
|
||||
not dict(options).has_key('--firstname') or
|
||||
not dict(options).has_key('--lastname') or
|
||||
not dict(options).has_key('--address1') or
|
||||
not dict(options).has_key('--town') or
|
||||
not dict(options).has_key('--zipcode') or
|
||||
not dict(options)['--firstname'].strip() or
|
||||
not dict(options)['--lastname'].strip() or
|
||||
not dict(options)['--address1'].strip() or
|
||||
not dict(options)['--town'].strip() or
|
||||
not dict(options)['--zipcode'].strip()):
|
||||
usage()
|
||||
sys.exit(1)
|
||||
|
||||
po = dict(options)
|
||||
for key in po.keys():
|
||||
po[key] = po[key].strip()
|
||||
client = Client()
|
||||
client.firstname = po['--firstname']
|
||||
client.lastname = po['--lastname']
|
||||
client.address1 = po['--address1']
|
||||
client.town = po['--town']
|
||||
client.zipcode = po['--zipcode']
|
||||
if po.has_key('--active'):
|
||||
client.active = (po['--active'] == 'true')
|
||||
else:
|
||||
client.active = True
|
||||
if po.has_key('--address2') and po['--address2']:
|
||||
client.address2 = po['--address2']
|
||||
if po.has_key('--country') and po['--country']:
|
||||
client.country = po['--country']
|
||||
if po.has_key('--state') and po['--state']:
|
||||
client.state = po['--state']
|
||||
if po.has_key('--phone') and po['--phone']:
|
||||
client.phone = po['--phone']
|
||||
if po.has_key('--mobile') and po['--mobile']:
|
||||
client.mobile = po['--mobile']
|
||||
session.save(client)
|
||||
session.flush()
|
59
testdb/adddomain.py
Normal file
59
testdb/adddomain.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2007 Jan Dittberner
|
||||
# $Id$
|
||||
#
|
||||
import getopt, sys
|
||||
from gnuviechadmin.dblayer import *
|
||||
|
||||
def usage():
|
||||
print """Usage information:
|
||||
=====================
|
||||
%(process)s -h|--help
|
||||
- prints this help text
|
||||
|
||||
%(process)s --domain=<domain> --sysuser=<sysuser> --type=MASTER|SLAVE \
|
||||
[[--ns=<nameserver>] [--mx=<mxserver[,prio]>] [--a=<ipaddress>] ...]
|
||||
- adds a new domain
|
||||
""" % {'process': sys.argv[0]}
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
(options, args) = getopt.getopt(sys.argv[1:], "h",
|
||||
['help',
|
||||
'domain=', 'sysuser=',
|
||||
'type=', 'ns=', 'mx=', 'a='])
|
||||
except getopt.GetoptError:
|
||||
usage()
|
||||
sys.exit(1)
|
||||
|
||||
if (not options or
|
||||
dict(options).has_key('-h') or
|
||||
dict(options).has_key('--help') or
|
||||
not dict(options).has_key('--domain') or
|
||||
not dict(options).has_key('--sysuser') or
|
||||
not dict(options)['--sysuser'].strip() or
|
||||
not dict(options)['--domain'].strip()):
|
||||
usage()
|
||||
sys.exit(1)
|
||||
|
||||
po = {}
|
||||
for (key, value) in options:
|
||||
if po.has_key(key):
|
||||
po[key].append(value.strip())
|
||||
else:
|
||||
po[key] = [value.strip()]
|
||||
|
||||
# fetch the sysuser
|
||||
query = session.query(SysUser)
|
||||
sysuser = query.get_by(name = po['--sysuser'][0])
|
||||
if not sysuser:
|
||||
print "Invalid system user"
|
||||
allsysusers = query.get_by(name = '*')
|
||||
if allsysusers:
|
||||
print "Valid system users are:\n%s" % ("\n".join(allsysusers))
|
||||
else:
|
||||
print "No system users defined yet."
|
||||
sys.exit(1)
|
||||
|
||||
print sysuser.domains
|
45
testdb/addpopuser.py
Normal file
45
testdb/addpopuser.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2007 Jan Dittberner
|
||||
# $Id$
|
||||
#
|
||||
import getopt, sys
|
||||
from gnuviechadmin.dblayer import *
|
||||
|
||||
def usage():
|
||||
print """Usage information:
|
||||
=====================
|
||||
%(process)s -h|--help
|
||||
- prints this help text
|
||||
|
||||
%(process)s --domain=<domain> [--password=<password>]
|
||||
- adds a new pop user for the given domain
|
||||
- if the optional password is ommitted a generated one is used
|
||||
- the password is checked using cracklib
|
||||
- if the password is too weak a generated one is used
|
||||
""" % {'process': sys.argv[0]}
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
(options, args) = getopt.getopt(sys.argv[1:], "h", ['help', 'password=', 'domain='])
|
||||
except getopt.GetoptError:
|
||||
usage()
|
||||
sys.exit(1)
|
||||
|
||||
if (not options or
|
||||
dict(options).has_key('-h') or
|
||||
dict(options).has_key('--help') or
|
||||
not dict(options).has_key('--domain') or
|
||||
not dict(options)['--domain'].strip()):
|
||||
usage()
|
||||
sys.exit(1)
|
||||
|
||||
# specify the domain
|
||||
query = session.query(Domain)
|
||||
domain = query.get_by(name = dict(options)['--domain'].strip())
|
||||
if not domain:
|
||||
print "Invalid Domain"
|
||||
print "valid domains are:\n%s" % ("\n".join(query.get()))
|
||||
sys.exit(1)
|
||||
|
||||
print domain.popaccounts
|
53
testdb/addsysuser.py
Normal file
53
testdb/addsysuser.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2007 Jan Dittberner
|
||||
# $Id$
|
||||
#
|
||||
import getopt, sys
|
||||
from gnuviechadmin.dblayer import *
|
||||
|
||||
def usage():
|
||||
print """Usage information:
|
||||
=====================
|
||||
%(process)s -h|--help
|
||||
- prints this help text
|
||||
|
||||
%(process)s --type=admin|reseller|client --clientid=<clientid> \
|
||||
[--name=<name>] [--home=<home>] [--shell=<shell>] [--password] \
|
||||
[--sysuid=<uid>]
|
||||
- adds a new system user
|
||||
""" % {'process': sys.argv[0]}
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
(options, args) = getopt.getopt(sys.argv[1:], "h",
|
||||
['help',
|
||||
'type=', 'clientid=', 'name=', 'home=',
|
||||
'shell=', 'password=', 'sysuid='])
|
||||
except getopt.GetoptError:
|
||||
usage()
|
||||
sys.exit(1)
|
||||
|
||||
if (not options or
|
||||
dict(options).has_key('-h') or
|
||||
dict(options).has_key('--help') or
|
||||
not dict(options).has_key('--type') or
|
||||
not dict(options).has_key('--clientid') or
|
||||
not dict(options)['--type'].strip() or
|
||||
not dict(options)['--clientid'].strip() or
|
||||
not dict(options)['--type'].strip() in ('admin', 'reseller', 'client')):
|
||||
usage()
|
||||
sys.exit(1)
|
||||
|
||||
query = session.query(Client)
|
||||
client = query.get_by(clientid = dict(options)['--clientid'].strip())
|
||||
if not client:
|
||||
print "Invalid client"
|
||||
allclients = query.select()
|
||||
if allclients:
|
||||
print "Valid clients are:\n- %s" % "\n- ".join([str(client) for client in allclients])
|
||||
else:
|
||||
print "No clients defined yet."
|
||||
sys.exit(1)
|
||||
|
||||
print client.sysusers
|
4
testdb/dbschema/gnuviechadmin/README
Normal file
4
testdb/dbschema/gnuviechadmin/README
Normal file
|
@ -0,0 +1,4 @@
|
|||
This is a database migration repository.
|
||||
|
||||
More information at
|
||||
http://trac.erosson.com/migrate
|
0
testdb/dbschema/gnuviechadmin/__init__.py
Normal file
0
testdb/dbschema/gnuviechadmin/__init__.py
Normal file
4
testdb/dbschema/gnuviechadmin/manage.py
Normal file
4
testdb/dbschema/gnuviechadmin/manage.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/python
|
||||
from migrate.versioning.shell import main
|
||||
|
||||
main(repository='gnuviechadmin')
|
20
testdb/dbschema/gnuviechadmin/migrate.cfg
Normal file
20
testdb/dbschema/gnuviechadmin/migrate.cfg
Normal file
|
@ -0,0 +1,20 @@
|
|||
[db_settings]
|
||||
# Used to identify which repository this database is versioned under.
|
||||
# You can use the name of your project.
|
||||
repository_id=GNUViech Admin
|
||||
|
||||
# The name of the database table used to track the schema version.
|
||||
# This name shouldn't already be used by your project.
|
||||
# If this is changed once a database is under version control, you'll need to
|
||||
# change the table name in each database too.
|
||||
version_table=migrate_version
|
||||
|
||||
# When committing a change script, Migrate will attempt to generate the
|
||||
# sql for all supported databases; normally, if one of them fails - probably
|
||||
# because you don't have that database installed - it is ignored and the
|
||||
# commit continues, perhaps ending successfully.
|
||||
# Databases in this list MUST compile successfully during a commit, or the
|
||||
# entire commit will fail. List the databases your application will actually
|
||||
# be using to ensure your updates to that database work properly.
|
||||
# This must be a list; example: ['postgres','sqlite']
|
||||
required_dbs=[]
|
33
testdb/dbschema/gnuviechadmin/versions/1/1.py
Normal file
33
testdb/dbschema/gnuviechadmin/versions/1/1.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
# setup tables for spamassassin
|
||||
from sqlalchemy import *
|
||||
from migrate import *
|
||||
|
||||
meta = BoundMetaData(migrate_engine)
|
||||
domains = Table('domains', meta, autoload = True)
|
||||
mailalias = Table(
|
||||
'mailalias', meta,
|
||||
Column('mailaliasid', Integer, primary_key = True),
|
||||
Column('domainid', Integer, ForeignKey('domains.id'), nullable = False),
|
||||
Column('email', String(255), nullable = False),
|
||||
Column('target', TEXT, nullable = False),
|
||||
UniqueConstraint('email', 'domainid'))
|
||||
|
||||
mailpassword = Table(
|
||||
'mailpassword', meta,
|
||||
Column('id', String(18), primary_key = True),
|
||||
Column('domainid', Integer, ForeignKey('domains.id'), nullable = False),
|
||||
Column('uid', Integer, nullable = False),
|
||||
Column('gid', Integer, nullable = False),
|
||||
Column('home', String(255), nullable = False),
|
||||
Column('cryptpass', String(34), nullable = False),
|
||||
Column('clearpass', String(64), nullable = False),
|
||||
Column('spamcheck', Boolean, default = False),
|
||||
Column('sajunkscore', Integer))
|
||||
|
||||
def upgrade():
|
||||
mailalias.create()
|
||||
mailpassword.create()
|
||||
|
||||
def downgrade():
|
||||
mailpassword.drop()
|
||||
mailalias.drop()
|
40
testdb/dbschema/gnuviechadmin/versions/2/2.py
Normal file
40
testdb/dbschema/gnuviechadmin/versions/2/2.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
from sqlalchemy import *
|
||||
from migrate import *
|
||||
|
||||
meta = BoundMetaData(migrate_engine)
|
||||
client_table = Table(
|
||||
'client', meta,
|
||||
Column('clientid', Integer, primary_key = True),
|
||||
Column('firstname', String(40), nullable = False),
|
||||
Column('lastname', String(40), nullable = False),
|
||||
Column('address1', String(40), nullable = False),
|
||||
Column('address2', String(40)),
|
||||
Column('country', String(40)),
|
||||
Column('town', String(50), nullable = False),
|
||||
Column('zipcode', String(5), nullable = False),
|
||||
Column('state', String(40)),
|
||||
Column('active', Boolean, default = False, nullable = False),
|
||||
Column('phone', String(20)),
|
||||
Column('mobile', String(20)))
|
||||
|
||||
sysuser_table = Table(
|
||||
'sysuser', meta,
|
||||
Column('sysuserid', Integer, primary_key = True),
|
||||
Column('name', String(12), nullable = False),
|
||||
Column('type', Integer, default = 0, nullable = False),
|
||||
Column('home', String(128)),
|
||||
Column('shell', Boolean),
|
||||
Column('password', String(64)),
|
||||
Column('clientid', Integer, ForeignKey('client.clientid'),
|
||||
nullable = False),
|
||||
Column('toupdate', Boolean, default = False, nullable = False),
|
||||
Column('md5pass', String(34)),
|
||||
Column('sysuid', Integer))
|
||||
|
||||
def upgrade():
|
||||
client_table.create()
|
||||
sysuser_table.create()
|
||||
|
||||
def downgrade():
|
||||
sysuser_table.drop()
|
||||
client_table.drop()
|
17
testdb/dbschema/gnuviechadmin/versions/3/3.py
Normal file
17
testdb/dbschema/gnuviechadmin/versions/3/3.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
from sqlalchemy import *
|
||||
from migrate import *
|
||||
import migrate.changeset
|
||||
|
||||
meta = BoundMetaData(migrate_engine)
|
||||
sysuser = Table('sysuser', meta, autoload = True)
|
||||
domains = Table('domains', meta, autoload = True)
|
||||
sysuidrefcol = Column('sysuserid', Integer,
|
||||
ForeignKey('sysuser.sysuserid'),
|
||||
nullable = False)
|
||||
|
||||
def upgrade():
|
||||
sysuidrefcol.create(domains)
|
||||
|
||||
def downgrade():
|
||||
col = domains.c.sysuserid
|
||||
col.drop()
|
0
testdb/dbschema/gnuviechadmin/versions/__init__.py
Normal file
0
testdb/dbschema/gnuviechadmin/versions/__init__.py
Normal file
16
testdb/dbschema/initdb.sh
Executable file
16
testdb/dbschema/initdb.sh
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
dirname=$(pwd)
|
||||
dbname=testdb
|
||||
dbuser=jan
|
||||
dbpassword=heyyou97
|
||||
reponame=gnuviechadmin
|
||||
dburl=postgres://$dbuser:$dbpassword@localhost:5432/$dbname
|
||||
|
||||
sudo su - postgres -c "createdb -O $dbuser -E UTF-8 $dbname"
|
||||
sudo su - postgres -c "psql $dbname < $dirname/initdb.sql"
|
||||
|
||||
#migrate create $reponame "GNUViech Admin"
|
||||
migrate version_control $dburl $reponame
|
||||
migrate manage manage.py --repository=$reponame --url=$dburl
|
||||
python manage.py upgrade
|
188
testdb/dbschema/initdb.sql
Normal file
188
testdb/dbschema/initdb.sql
Normal file
|
@ -0,0 +1,188 @@
|
|||
-- initial schema setup for postgresql
|
||||
|
||||
-- spamassassin bayes storage
|
||||
|
||||
CREATE PROCEDURAL LANGUAGE plpgsql;
|
||||
|
||||
SET search_path = public, pg_catalog;
|
||||
|
||||
CREATE TABLE bayes_expire (
|
||||
id integer NOT NULL default '0',
|
||||
runtime integer NOT NULL default '0'
|
||||
) WITHOUT OIDS;
|
||||
|
||||
CREATE INDEX bayes_expire_idx1 ON bayes_expire (id);
|
||||
|
||||
CREATE TABLE bayes_global_vars (
|
||||
variable varchar(30) NOT NULL default '',
|
||||
value varchar(200) NOT NULL default '',
|
||||
PRIMARY KEY (variable)
|
||||
) WITHOUT OIDS;
|
||||
|
||||
INSERT INTO bayes_global_vars VALUES ('VERSION','3');
|
||||
|
||||
CREATE TABLE bayes_seen (
|
||||
id integer NOT NULL default '0',
|
||||
msgid varchar(200) NOT NULL default '',
|
||||
flag character(1) NOT NULL default '',
|
||||
PRIMARY KEY (id,msgid)
|
||||
) WITHOUT OIDS;
|
||||
|
||||
CREATE TABLE bayes_token (
|
||||
id integer NOT NULL default '0',
|
||||
token bytea NOT NULL default '',
|
||||
spam_count integer NOT NULL default '0',
|
||||
ham_count integer NOT NULL default '0',
|
||||
atime integer NOT NULL default '0',
|
||||
PRIMARY KEY (id,token)
|
||||
) WITHOUT OIDS;
|
||||
|
||||
CREATE INDEX bayes_token_idx1 ON bayes_token (token);
|
||||
|
||||
CREATE TABLE bayes_vars (
|
||||
id serial NOT NULL,
|
||||
username varchar(200) NOT NULL default '',
|
||||
spam_count integer NOT NULL default '0',
|
||||
ham_count integer NOT NULL default '0',
|
||||
token_count integer NOT NULL default '0',
|
||||
last_expire integer NOT NULL default '0',
|
||||
last_atime_delta integer NOT NULL default '0',
|
||||
last_expire_reduce integer NOT NULL default '0',
|
||||
oldest_token_age integer NOT NULL default '2147483647',
|
||||
newest_token_age integer NOT NULL default '0',
|
||||
PRIMARY KEY (id)
|
||||
) WITHOUT OIDS;
|
||||
|
||||
CREATE UNIQUE INDEX bayes_vars_idx1 ON bayes_vars (username);
|
||||
|
||||
CREATE OR REPLACE FUNCTION greatest_int (integer, integer)
|
||||
RETURNS INTEGER
|
||||
IMMUTABLE STRICT
|
||||
AS 'SELECT CASE WHEN $1 < $2 THEN $2 ELSE $1 END;'
|
||||
LANGUAGE SQL;
|
||||
|
||||
CREATE OR REPLACE FUNCTION least_int (integer, integer)
|
||||
RETURNS INTEGER
|
||||
IMMUTABLE STRICT
|
||||
AS 'SELECT CASE WHEN $1 < $2 THEN $1 ELSE $2 END;'
|
||||
LANGUAGE SQL;
|
||||
|
||||
CREATE OR REPLACE FUNCTION put_tokens(inuserid INTEGER,
|
||||
intokenary BYTEA[],
|
||||
inspam_count INTEGER,
|
||||
inham_count INTEGER,
|
||||
inatime INTEGER)
|
||||
RETURNS VOID AS '
|
||||
DECLARE
|
||||
_token BYTEA;
|
||||
new_tokens INTEGER := 0;
|
||||
BEGIN
|
||||
for i in array_lower(intokenary, 1) .. array_upper(intokenary, 1)
|
||||
LOOP
|
||||
_token := intokenary[i];
|
||||
UPDATE bayes_token
|
||||
SET spam_count = greatest_int(spam_count + inspam_count, 0),
|
||||
ham_count = greatest_int(ham_count + inham_count, 0),
|
||||
atime = greatest_int(atime, inatime)
|
||||
WHERE id = inuserid
|
||||
AND token = _token;
|
||||
IF NOT FOUND THEN
|
||||
-- we do not insert negative counts, just return true
|
||||
IF NOT (inspam_count < 0 OR inham_count < 0) THEN
|
||||
INSERT INTO bayes_token (id, token, spam_count, ham_count, atime)
|
||||
VALUES (inuserid, _token, inspam_count, inham_count, inatime);
|
||||
IF FOUND THEN
|
||||
new_tokens := new_tokens + 1;
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
IF new_tokens > 0 AND inatime > 0 THEN
|
||||
UPDATE bayes_vars
|
||||
SET token_count = token_count + new_tokens,
|
||||
newest_token_age = greatest_int(newest_token_age, inatime),
|
||||
oldest_token_age = least_int(oldest_token_age, inatime)
|
||||
WHERE id = inuserid;
|
||||
ELSEIF new_tokens > 0 AND NOT inatime > 0 THEN
|
||||
UPDATE bayes_vars
|
||||
SET token_count = token_count + new_tokens
|
||||
WHERE id = inuserid;
|
||||
ELSEIF NOT new_tokens > 0 AND inatime > 0 THEN
|
||||
UPDATE bayes_vars
|
||||
SET newest_token_age = greatest_int(newest_token_age, inatime),
|
||||
oldest_token_age = least_int(oldest_token_age, inatime)
|
||||
WHERE id = inuserid;
|
||||
END IF;
|
||||
RETURN;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql';
|
||||
|
||||
-- tables for spamassassin auto-whitelists
|
||||
|
||||
CREATE TABLE awl (
|
||||
username varchar(100) NOT NULL default '',
|
||||
email varchar(200) NOT NULL default '',
|
||||
ip varchar(10) NOT NULL default '',
|
||||
count bigint default '0',
|
||||
totscore float default '0'
|
||||
);
|
||||
CREATE UNIQUE INDEX awl_pkey ON awl (username,email,ip);
|
||||
|
||||
-- tables for spamassassin user preferences
|
||||
|
||||
CREATE TABLE userpref (
|
||||
prefid bigserial NOT NULL unique primary key,
|
||||
username varchar(100) NOT NULL,
|
||||
preference varchar(30) NOT NULL,
|
||||
value varchar(100) NOT NULL
|
||||
);
|
||||
CREATE INDEX userpref_username_idx ON userpref(username);
|
||||
|
||||
-- tables for powerdns
|
||||
|
||||
CREATE TABLE domains (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL UNIQUE,
|
||||
master VARCHAR(20) DEFAULT NULL,
|
||||
last_check INT DEFAULT NULL,
|
||||
type VARCHAR(6) NOT NULL,
|
||||
notified_serial INT DEFAULT NULL,
|
||||
account VARCHAR(40) DEFAULT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE records (
|
||||
id SERIAL PRIMARY KEY,
|
||||
domain_id INT DEFAULT NULL,
|
||||
name VARCHAR(255) DEFAULT NULL,
|
||||
type VARCHAR(6) DEFAULT NULL,
|
||||
content VARCHAR(255) DEFAULT NULL,
|
||||
ttl INT DEFAULT NULL,
|
||||
prio INT DEFAULT NULL,
|
||||
change_date INT DEFAULT NULL,
|
||||
CONSTRAINT domain_exists
|
||||
FOREIGN KEY(domain_id) REFERENCES domains(id)
|
||||
ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX rec_name_index ON records(name);
|
||||
CREATE INDEX nametype_index ON records(name, type);
|
||||
CREATE INDEX domain_id ON records(domain_id);
|
||||
|
||||
CREATE TABLE supermasters (
|
||||
ip VARCHAR(25) NOT NULL,
|
||||
nameserver VARCHAR(255) NOT NULL,
|
||||
account VARCHAR(40) DEFAULT NULL
|
||||
);
|
||||
|
||||
GRANT ALL ON supermasters TO jan;
|
||||
GRANT ALL ON domains TO jan;
|
||||
GRANT ALL ON domains_id_seq TO jan;
|
||||
GRANT ALL ON records TO jan;
|
||||
GRANT ALL ON records_id_seq TO jan;
|
||||
|
||||
-- GRANT SELECT ON supermasters TO pdns;
|
||||
-- GRANT ALL ON domains TO pdns;
|
||||
-- GRANT ALL ON domains_id_seq TO pdns;
|
||||
-- GRANT ALL ON records TO pdns;
|
||||
-- GRANT ALL ON records_id_seq TO pdns;
|
4
testdb/dbschema/manage.py
Normal file
4
testdb/dbschema/manage.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/python
|
||||
from migrate.versioning.shell import main
|
||||
|
||||
main(url='postgres://jan:heyyou97@localhost:5432/testdb',repository='gnuviechadmin')
|
0
testdb/gnuviechadmin/__init__.py
Normal file
0
testdb/gnuviechadmin/__init__.py
Normal file
23
testdb/gnuviechadmin/dblayer.py
Normal file
23
testdb/gnuviechadmin/dblayer.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
from sqlalchemy import *
|
||||
from entities import *
|
||||
|
||||
db = create_engine('postgres://jan:heyyou97@localhost:5432/testdb')
|
||||
|
||||
metadata = BoundMetaData(db)
|
||||
|
||||
domains_table = Table('domains', metadata, autoload = True)
|
||||
sysuser_table = Table('sysuser', metadata, autoload = True)
|
||||
mailpassword_table = Table('mailpassword', metadata, autoload = True)
|
||||
client_table = Table('client', metadata, autoload = True)
|
||||
|
||||
popaccountmapper = mapper(PopAccount, mailpassword_table)
|
||||
|
||||
domainmapper = mapper(Domain, domains_table)
|
||||
domainmapper.add_property('popaccounts', relation(PopAccount))
|
||||
|
||||
sysusermapper = mapper(SysUser, sysuser_table)
|
||||
|
||||
clientmapper = mapper(Client, client_table)
|
||||
clientmapper.add_property('sysusers', relation(SysUser))
|
||||
|
||||
session = create_session()
|
46
testdb/gnuviechadmin/entities.py
Normal file
46
testdb/gnuviechadmin/entities.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
class Client(object):
|
||||
def __repr__(self):
|
||||
return "%s(clientid=%s,firstname=%s,lastname=%s)" % \
|
||||
(self.__class__.__name__,
|
||||
self.clientid,
|
||||
self.firstname,
|
||||
self.lastname)
|
||||
|
||||
class PopAccount(object):
|
||||
def __repr__(self):
|
||||
return "%s(%s,%d,%d,%d,%s,%s,%s)" % \
|
||||
(self.__class__.__name__,
|
||||
self.id,
|
||||
self.domainid,
|
||||
self.uid,
|
||||
self.gid,
|
||||
self.home,
|
||||
self.cryptpass,
|
||||
self.clearpass)
|
||||
|
||||
class SysUser(object):
|
||||
def __repr__(self):
|
||||
return "%s(%d,%s,%d,%s,%s,%s,%d,%d,%s,%d)" % \
|
||||
(self.__class__.__name__,
|
||||
self.sysuserid,
|
||||
self.name,
|
||||
self.type,
|
||||
self.home,
|
||||
self.shell,
|
||||
self.password,
|
||||
self.clientid,
|
||||
self.toupdate,
|
||||
self.md5pass,
|
||||
self.sysuid)
|
||||
|
||||
class Domain(object):
|
||||
def __repr__(self):
|
||||
return "%s(%d,%s,%s,%s,%s,%s,%s)" % \
|
||||
(self.__class__.__name__,
|
||||
self.id,
|
||||
self.name,
|
||||
self.master,
|
||||
self.last_check,
|
||||
self.type,
|
||||
self.notified_serial,
|
||||
self.account)
|
Loading…
Add table
Add a link
Reference in a new issue