Esempio n. 1
0
	def from_file(self, filename=None):
		if filename is None:
			filename = tutuconfig.get('namedconf', 'dnsbind');
		lines = [];
		with open(filename, 'r') as fh:
			lines.append(fh.read());
		catlines = '\n'.join(lines);
		self._lines = catlines;
		self._load_zones();
		return True
Esempio n. 2
0
def main(global_config, **settings):
	sessfac = SignedCookieSessionFactory(tutuconfig.get('cookie_signing_key'));
	authc = AuthTktAuthenticationPolicy(tutuconfig.get('authentication_secret'), hashalg='sha512');
	authz = TutuAuthorizationPolicy();
	config = Configurator(settings=settings,
											 session_factory=sessfac,
											 authentication_policy=authc,
											 authorization_policy=authz);
	config.include('pyramid_chameleon');
	
	config.add_route('home', '/');
	
	config.add_route('zone_create', '/dns/zone/create');
	config.add_route('zone_delete', '/dns/zone/delete');
	config.add_route('zone_read', '/dns/zone/{zone}');
	config.add_route('zone_list', '/dns/zones');
	
	#config.add_route('record_read', '/dns/record/read');
	config.add_route('record_update', '/dns/record/update');
	config.add_route('record_create', '/dns/record/create');
	config.add_route('record_delete', '/dns/record/delete');
	
	config.add_route('auth_login', '/login');
	config.add_route('auth_logout', '/logout');
	
	config.add_route('users_profile', '/profile');
	config.add_route('users_list', '/settings/users');
	config.add_route('users_create', '/settings/users/create');
	config.add_route('users_update', '/settings/users/update');
	config.add_route('users_read', '/settings/users/{user}');
	
	
	config.scan('.views.viewdashboard');
	config.scan('.views.viewauth');
	config.scan('.views.viewusers');
	config.scan('.dnsbind.views.viewzones');
	config.scan('.dnsbind.views.viewrecords');
	config.add_static_view(name='assets', path='tutu:assets');
	return config.make_wsgi_app();

# vim: set ts=2:
Esempio n. 3
0
	def create(self):
		if self.posted():
			zname = self.request.POST['name'];
			mname = self.request.POST['mname'];
			rname = self.request.POST['rname'];
			refresh = self.request.POST['refresh'];
			retry = self.request.POST['retry'];
			expire = self.request.POST['expire'];
			minimum = self.request.POST['minimum'];
			nstarget = self.request.POST['ns'];
			
			if zname[-1:] == '.':
				zname = zname[:-1];
			
			z = tutuzone.Zone(zname);
			
			soa = tuturecord.Record('SOA');
			soa.serial = 0;
			soa.mname = mname;
			soa.rname = rname;
			soa.refresh = refresh;
			soa.retry = retry;
			soa.expire = expire;
			soa.minimum = minimum;
			
			z.add_record('@', soa);
			
			ns = tuturecord.Record('NS');
			ns.target = nstarget;
			z.add_record('@', ns);
			
			z.save();
			
			namedconf = tutuconfig.get('namedconf', 'dnsbind');
			ncp = NamedConfParser();
			ncp.from_file(namedconf);
			ncp.add_zone(zname, z.get_filename());
			ncp.to_file(namedconf);
			
			return HTTPFound('/dns/zone/{}'.format(zname));
			
		import copy
		helpers = copy.copy(tuturecord.helpers);
		helpers['name'] = {'type': 'text', 'label': 'Zone Name', 'help':'FQDN of the zone'};
		helpers['ns'] = {'type': 'text', 'label': 'First NS record', 'help':'FQDN of the first NameServer of the zone'};
		zone = {
			'name': '', 'mname': '', 'rname': '', 'refresh': 604800,
			'retry': 86400, 'expire': 2419200, 'minimum': 86400, 'ns': ''
		};
		keys = ['name', 'mname', 'rname', 'refresh', 'retry', 'expire', 'minimum', 'ns'];
		
		return {'zone': zone, 'keys': keys, 'helpers': helpers};
Esempio n. 4
0
def _count_records(zonename):
  namedconf = tutuconfig.get('namedconf', 'dnsbind');
  ncp = NamedConfParser();
  ncp.from_file(namedconf);
  zonefile = ncp.find_zone_file(zonename);

  z  = dns.zone.from_file(zonefile);
  recordcount = 0;
  for node in z.nodes:
    for rds in z.nodes[node].rdatasets:
      recordcount += len(rds.items);

  return recordcount;
Esempio n. 5
0
	def delete(self):
		if self.posted():
			zname = self.request.POST['zonename'];

			namedconf = tutuconfig.get('namedconf', 'dnsbind');
			ncp = NamedConfParser();
			ncp.from_file(namedconf);
			zonefile = ncp.find_zone_file(zname);
			os.remove(zonefile);
			ncp.delete_zone(zname);
			ncp.to_file(namedconf);
			return HTTPFound('/dns/zones');
		
# vim: set ts=2:
Esempio n. 6
0
	def delete(self):
			session = self.request.session;
			try:
				rzone = session['rzone'];
			except NameError:
				return HTTPFound('/dns/zones');
			
			try:
				oname = session['rname'];
				rtype = session['rtype'];
				odata = session['rdata'];
				rclass = session['rclass'];
			except NameError:
				return HTTPFound('/dns/zone/{}'.format(rzone));
			
			namedconf = tutuconfig.get('namedconf', 'dnsbind');
			ncp = NamedConfParser();
			ncp.from_file(namedconf);
			zonefile = ncp.find_zone_file(rzone);
			
			z = zone.from_file(zonefile);
			
			dset = z.get_rdataset(oname, rtype);
			newdset = dns.rdataset.Rdataset(rdc.from_text(rclass), rdt.from_text(rtype));
			newdset.ttl = 300;
			if rtype == 'SOA':
				newdset.add(rdata);
			else:
				for rd in dset:
					if odata == rd.to_text():
						pass
					else:
						newdset.add(rd);
			z.replace_rdataset(oname, newdset);
			
			tutuzone.save_zone(z, zonefile);
			
			return HTTPFound('/dns/zone/{}'.format(rzone));
# vim: set ts=2:
Esempio n. 7
0
		results = None;
	return results is not None;

Base = declarative_base();


class User(Base):
	__tablename__ = 'users';

	id = Column(Integer, primary_key = True);
	uname = Column(String);
	pword = Column(String);
	fname = Column(String);
	lname = Column(String);
	email = Column(String);

class AuditLog(Base):
	__tablename__ = 'auditlog';

	id = Column(Integer, primary_key = True);
	uname = Column(String);
	action = Column(String);
	date = Column(DateTime);

_uri = tutuconfig.get('uri', 'database');

_engine = create_engine(_uri);
_DBSession = sessionmaker(bind=_engine);
_init_db();

# vim: set ts=2:
Esempio n. 8
0
	def save(self):
		if self._filename is None:
			zonefilelocation = tutuconfig.get('zonefiles', 'dnsbind');
			self._filename = '{}/{}.zone'.format(zonefilelocation, self._zname);
			#TOTO: this should check whether the file exists...
		self.to_file(self._filename);
Esempio n. 9
0
	def load(self):
		zonefilelocation = tutuconfig.get('zonefiles', 'dnsbind');
		filename = '{}/{}.zone'.format(zonefilelocation, self._zname);
		#TOTO: this should check whether the file exists...
		self.from_file(filename);