summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile19
-rwxr-xr-xfooconf6
-rwxr-xr-xfooconf-apache39
-rwxr-xr-xfooconf-cron22
-rwxr-xr-xfooconf-postfix-alias-map22
-rw-r--r--fooconf-postfix-mailbox-domains21
-rwxr-xr-xfooconf-postfix-mailbox-map25
-rwxr-xr-xfooconf-unix-group19
-rwxr-xr-xfooconf-unix-passwd31
-rw-r--r--fooconf.sql20
-rw-r--r--fooconf.sqlitebin0 -> 16384 bytes
-rw-r--r--fooconflib.py42
12 files changed, 266 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..ce98252
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,19 @@
+all:
+ mkdir -p output
+ ./fooconf-unix-passwd > output/passwd
+ ./fooconf-unix-group > output/group
+ ./fooconf-postfix-mailbox-domains > output/postfix-mailbox-domains
+ ./fooconf-postfix-mailbox-map > output/postfix-mailbox-map
+ ./fooconf-postfix-alias-map > output/postfix-alias-map
+ ./fooconf-apache > output/apache.conf
+ ./fooconf-cron > output/cron.allow
+
+reset:
+ rm -f fooconf.sqlite
+ sqlite fooconf.sqlite < fooconf.sql
+
+clean:
+ rm -rf output
+ rm -f *.pyc
+
+.PHONY: reset all
diff --git a/fooconf b/fooconf
new file mode 100755
index 0000000..c4e79db
--- /dev/null
+++ b/fooconf
@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+
+
+from fooconflib import *;
+
+c = FooConfContext();
diff --git a/fooconf-apache b/fooconf-apache
new file mode 100755
index 0000000..92aafbb
--- /dev/null
+++ b/fooconf-apache
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# Hey Emacs, this is -*-python-*- code!
+
+from fooconflib import *
+from sys import stdout
+
+def generateApacheFragment(ctx = FooConfContext()):
+ cursor = ctx.db.cursor()
+ cursor.execute("SELECT domain.name AS name, origin_email, account.email AS email, account.id AS id, account.name AS owner "+
+ "FROM domain, domain_vhost, account "+
+ "WHERE domain.owner = account.id "+
+ "AND domain.name = domain_vhost.name "+
+ "AND domain_vhost.enabled = \"t\" "+
+ "AND account.enabled = \"t\"")
+
+ subcursor = ctx.db.cursor();
+
+ while 1:
+ row = cursor.fetchone()
+ if row is None: break
+
+
+# subcursor.execute("SELECT domain_alias.name AS NAME"+
+# "FROM domain, domain_alias, account "+
+# "WHERE domain.owner = account.id "+
+# "AND domain.name = domain_alias.name "+
+# "AND vhost=\"%s\" "+
+# "AND account.enabled = \"t\"")
+ alias = ""
+
+ stdout.write(("<VirtualHost *:80>\n"+
+ "\tServerName %s\n"+
+ "\tServerAlias %s\n"+
+ "\tServerAdmin %s\n"+
+ "\tDocumentRoot %s\n"+
+ "</VirtualHost>\n") % (row["name"], alias, row["email"], ctx.makeHomeDir(row["owner"])+"/www/"+row["name"]))
+
+if __name__ == "__main__":
+ generateApacheFragment()
diff --git a/fooconf-cron b/fooconf-cron
new file mode 100755
index 0000000..04726b2
--- /dev/null
+++ b/fooconf-cron
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+# Hey Emacs, this is -*-python-*- code!
+
+from fooconflib import *
+
+def generateCronFragment(ctx = FooConfContext()) :
+ cursor = ctx.db.cursor()
+
+ cursor.execute("SELECT name "+
+ "FROM account, permission "+
+ "WHERE enabled=\"t\" "+
+ "AND permission.id=account.id "+
+ "AND action=\"cron\"")
+
+ while 1:
+ row = cursor.fetchone()
+ if row is None: break
+
+ print ctx.makeSysUserName(row["name"])
+
+if __name__ == "__main__":
+ generateCronFragment()
diff --git a/fooconf-postfix-alias-map b/fooconf-postfix-alias-map
new file mode 100755
index 0000000..53fc10f
--- /dev/null
+++ b/fooconf-postfix-alias-map
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+# Hey Emacs, this is -*-python-*- code!
+
+from fooconflib import *
+
+def generatePostfixAliasMapFragment(ctx = FooConfContext()):
+ cursor = ctx.db.cursor()
+ cursor.execute("SELECT DISTINCT local, domain, recipient " +
+ "FROM mail_alias, domain, account " +
+ "WHERE mail_alias.domain = domain.name " +
+ "AND domain.owner = account.id " +
+ "AND account.enabled = \"t\" " +
+ "AND type=\"forward\"")
+
+ while 1:
+ row = cursor.fetchone()
+ if row is None: break
+
+ print "%s@%s %s" % (row["local"], row["domain"], row["recipient"])
+
+if __name__ == "__main__":
+ generatePostfixAliasMapFragment()
diff --git a/fooconf-postfix-mailbox-domains b/fooconf-postfix-mailbox-domains
new file mode 100644
index 0000000..35cc6d6
--- /dev/null
+++ b/fooconf-postfix-mailbox-domains
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# Hey Emacs, this is -*-python-*- code!
+
+from fooconflib import *
+
+def generatePostfixMailboxDomainsFragment(ctx = FooConfContext()):
+ cursor = ctx.db.cursor()
+
+ cursor.execute("SELECT domain.name AS name "+
+ "FROM domain, account "+
+ "WHERE domain.owner = account.id "+
+ "AND account.enabled = \"t\"")
+
+ while 1:
+ row = cursor.fetchone()
+ if row is None: break
+
+ print "%s any" % row["name"]
+
+if __name__ == "__main__":
+ generatePostfixMailboxDomainsFragment()
diff --git a/fooconf-postfix-mailbox-map b/fooconf-postfix-mailbox-map
new file mode 100755
index 0000000..03a8628
--- /dev/null
+++ b/fooconf-postfix-mailbox-map
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+# Hey Emacs, this is -*-python-*- code!
+
+from fooconflib import *
+
+def generatePostfixMailboxMapFragment(ctx = FooConfContext()):
+ cursor = ctx.db.cursor()
+ cursor.execute("SELECT DISTINCT local, domain, recipient, account.name AS name " +
+ "FROM mail_alias, domain, account, mailbox " +
+ "WHERE mail_alias.domain = domain.name " +
+ "AND domain.owner = account.id " +
+ "AND mailbox.owner = account.id " +
+ "AND mailbox.enabled = \"t\" " +
+ "AND account.enabled = \"t\" " +
+ "AND type=\"mailbox\"")
+
+ while 1:
+ row = cursor.fetchone()
+ if row is None: break
+
+ print "%s@%s %s" % (row["local"], row["domain"], ctx.makeHomeDir(row["name"])+"/mail/"+row["recipient"])
+
+if __name__ == "__main__":
+ generatePostfixMailboxMapFragment()
+
diff --git a/fooconf-unix-group b/fooconf-unix-group
new file mode 100755
index 0000000..7a30512
--- /dev/null
+++ b/fooconf-unix-group
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+# Hey Emacs, this is -*-python-*- code!
+
+from fooconflib import *
+
+def generateUnixGroupFragment(ctx = FooConfContext()) :
+ cursor = ctx.db.cursor()
+ cursor.execute("SELECT name, id "+
+ "FROM account")
+
+ while 1:
+ row = cursor.fetchone()
+ if row is None: break
+
+ print "%s:x:%u:" % (ctx.makeSysUserName(row["name"]),
+ ctx.makeSysGID(row["id"]))
+
+if __name__ == "__main__":
+ generateUnixGroupFragment()
diff --git a/fooconf-unix-passwd b/fooconf-unix-passwd
new file mode 100755
index 0000000..a39fa9b
--- /dev/null
+++ b/fooconf-unix-passwd
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+# Hey Emacs, this is -*-python-*- code!
+
+from fooconflib import *
+
+def generateUnixPasswdFragment(ctx = FooConfContext()) :
+ cursor = ctx.db.cursor()
+ cursor.execute("SELECT name, id, enabled"+
+ " FROM account")
+
+ while 1:
+ row = cursor.fetchone()
+ if row is None: break
+
+ if row["enabled"] :
+ pw = "xxx"
+ shell = "/bin/sh"
+ else:
+ pw = ""
+ shell = "/bin/false"
+
+ print "%s:%s:%u:%u:%s,Fooconf User:%s:%s" % (ctx.makeSysUserName(row["name"]),
+ pw,
+ ctx.makeSysUID(row["id"]),
+ ctx.makeSysGID(row["id"]),
+ row["name"],
+ ctx.makeHomeDir(row["name"]),
+ shell)
+
+if __name__ == "__main__":
+ generateUnixPasswdFragment()
diff --git a/fooconf.sql b/fooconf.sql
new file mode 100644
index 0000000..a4861b4
--- /dev/null
+++ b/fooconf.sql
@@ -0,0 +1,20 @@
+
+
+CREATE TABLE account (id INTEGER PRIMARY KEY, name VARCHAR, email VARCHAR, enabled BOOLEAN, password VARCHAR);
+
+-- ACTION: e.g. cron, php, cgi, wedav...
+CREATE TABLE permission (id INTEGER, action VARCHAR);
+
+CREATE TABLE mailbox (name VARCHAR, password VARCHAR, owner INTEGER, enabled BOOLEAN);
+
+-- TYPE: e.g. forward, mailbox
+CREATE TABLE mail_alias (local VARCHAR, domain VARCHAR, type CHAR, recipient VARCHAR);
+
+CREATE TABLE domain (name VARCHAR PRIMARY KEY, owner INTEGER);
+
+CREATE TABLE domain_vhost (name VARCHAR PRIMARY KEY, enabled BOOLEAN, origin_email VARCHAR);
+CREATE TABLE domain_alias (name VARCHAR PRIMARY KEY, vhost VARCHAR);
+
+-- TYPE: proxy, redirect
+CREATE TABLE domain_redirect (name VARCHAR PRIMARY KEY, destination VARCHAR, type VARCHAR);
+
diff --git a/fooconf.sqlite b/fooconf.sqlite
new file mode 100644
index 0000000..8daf247
--- /dev/null
+++ b/fooconf.sqlite
Binary files differ
diff --git a/fooconflib.py b/fooconflib.py
new file mode 100644
index 0000000..d8da830
--- /dev/null
+++ b/fooconflib.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+
+import sqlite
+
+class FooConfContext:
+
+ db = None
+
+ params = {}
+
+ def __init__(self, fname = "fooconf.sqlite"):
+ self.db = sqlite.connect(fname, encoding = "utf-8")
+
+ self.params["base-uid"] = 10000
+ self.params["base-gid"] = 10000
+ self.params["base-home-dir"] = "/home/fooconf"
+ self.params["sys-user-name-prefix"] = "fc"
+ self.params["sys-group-name-prefix"] = "fc"
+
+ def __del__(self):
+ self.db.close()
+
+
+ def getParameter(self, name):
+ return self.params[name]
+
+ def makeSysUserName(self, name):
+ return self.getParameter("sys-user-name-prefix") + name
+
+ def makeSysGroupName(self, name):
+ return self.getParameter("sys-group-name-prefix") + name
+
+ def makeSysUID(self, id):
+ return self.getParameter("base-uid") + id
+
+ def makeSysGID(self, id):
+ return self.getParameter("base-gid") + id
+
+ def makeHomeDir(self, name):
+ return self.getParameter("base-home-dir") + "/" + name
+
+