Exemplo n.º 1
0
 def editName(self, fromName, toName):
     data = {}
     if fromName == toName:
         data["error"] = u"Name entry is the same as existing name"
         data["success"] = False
         return data
     db = DBHandler(app.config["DBFILE"])
     c = db.getCursor()
     if db.exists("zones", "name", toName):
         data["error"] = u"Duplicate name entry in db"
         data["success"] = False
         return data
     if not db.exists("zones", "name", fromName):
         data["error"] = u"No old name entry in db"
         data["success"] = False
         return data
     try:
         c.execute(
             """
             UPDATE zones
             SET old_value = name, name = ?,
             updated = 1, update_type = 'MODIFIED NAME'
             WHERE name LIKE ?
             """, [toName, fromName])
         db.commit()
         data["success"] = True
         data["message"] = u"Entry %s updated from %s" % (toName, fromName)
     except Exception, e:
         errormsg = u"Unsuccessful database update transaction:" + str(e)
         log.exception(errormsg, self.__class__.__name__)
         data["success"] = False
         data["error"] = errormsg
Exemplo n.º 2
0
 def editHost(self, name, host):
     data = {}
     db = DBHandler(app.config["DBFILE"])
     c = db.getCursor()
     dbdata = list(
         c.execute(
             """
         SELECT host FROM zones
         WHERE name LIKE ?
         """, [name]))
     if len(dbdata) == 0:
         data["error"] = u"Zone doesn't exist"
         data["success"] = False
         return data
     else:
         zone = dbdata[0]
     if zone[0] == host:
         data["error"] = u"Host entry is the same as existing name"
         data["success"] = False
         return data
     try:
         c.execute(
             """
             UPDATE zones
             SET host = ?, updated = 1, update_type = 'MODIFIED HOST'
             WHERE name LIKE ?
             """, [host, name])
         db.commit()
         data["success"] = True
         data["message"] = u"Entry %s updated from %s" % (host, zone[0])
     except Exception, e:
         errormsg = u"Unsuccessful database update transaction:" + str(e)
         log.exception(errormsg, self.__class__.__name__)
         data["success"] = False
         data["error"] = errormsg
Exemplo n.º 3
0
 def delete(self, name):
     data = {}
     db = DBHandler(app.config["DBFILE"])
     c = db.getCursor()
     zone = list(
         c.execute(
             """
         SELECT name FROM zones
         WHERE name LIKE ?
         """, [name]))
     if len(zone) > 0 and zone[0][0] == name:
         try:
             c.execute(
                 """
                 UPDATE zones
                 SET updated = 1, update_type = 'DELETE'
                 WHERE name LIKE ?
                 """, [name])
             db.commit()
             data["success"] = True
             data["message"] = u"Entry %s deleted" % (name)
         except Exception, e:
             errormsg = u"Unsuccessful database delete transaction:" + str(
                 e)
             log.exception(errormsg, self.__class__.__name__)
             data["success"] = False
             data["error"] = errormsg
Exemplo n.º 4
0
 def editHost(self, name, host):
     data = {}
     db = DBHandler(app.config["DBFILE"])
     c = db.getCursor()
     dbdata = list(c.execute("""
         SELECT host FROM zones
         WHERE name LIKE ?
         """,[name]))
     if len(dbdata) == 0:
         data["error"] = u"Zone doesn't exist"
         data["success"] = False
         return data
     else:
         zone = dbdata[0]
     if zone[0] == host:
         data["error"] = u"Host entry is the same as existing name"
         data["success"] = False
         return data
     try:
         c.execute("""
             UPDATE zones
             SET host = ?, updated = 1, update_type = 'MODIFIED HOST'
             WHERE name LIKE ?
             """,[host,name])
         db.commit()
         data["success"] = True
         data["message"] = u"Entry %s updated from %s"%(host, zone[0])
     except Exception, e:
         errormsg = u"Unsuccessful database update transaction:" + str(e)
         log.exception(errormsg, self.__class__.__name__)
         data["success"] = False
         data["error"] = errormsg
Exemplo n.º 5
0
 def addZone(self, zone):
     added = False
     for i, line in enumerate(self.lines):
         if app.config["ZONES_END_POINT"] in line:
             # Check if ip address or hostname
             try:
                 socket.inet_aton(zone.host)
                 newline = "%s\tIN\tA\t%s\n"%(zone.name,zone.host)
             except:
                 if not zone.host[:-1] == ".":
                     zone.host = zone.host + "."
                 newline = "%s\tIN\tCNAME\t%s\n"%(
                     zone.name,zone.host)
             self.templines.insert(i, newline)
             added = True
         if added:
             self.templines.insert(i+1, line)
         else:
             self.templines.insert(i, line)
     if added:
         try:
             self.c.execute("""
                 UPDATE zones
                 SET updated = 0, update_type = NULL
                 WHERE name LIKE ?
                 """,[zone.name])
             self.db.commit()
         except Exception, e:
             errormsg = u"Unsuccessful database update transaction:" + str(e)
             log.exception(errormsg, self.__class__.__name__)
Exemplo n.º 6
0
 def editName(self, fromName, toName):
     data = {}
     if fromName == toName:
         data["error"] = u"Name entry is the same as existing name"
         data["success"] = False
         return data
     db = DBHandler(app.config["DBFILE"])
     c = db.getCursor()
     if db.exists("zones", "name", toName):
         data["error"] = u"Duplicate name entry in db"
         data["success"] = False
         return data
     if not db.exists("zones", "name", fromName):
         data["error"] = u"No old name entry in db"
         data["success"] = False
         return data
     try:
         c.execute("""
             UPDATE zones
             SET old_value = name, name = ?,
             updated = 1, update_type = 'MODIFIED NAME'
             WHERE name LIKE ?
             """,[toName, fromName])
         db.commit()
         data["success"] = True
         data["message"] = u"Entry %s updated from %s"%(toName, fromName)
     except Exception, e:
         errormsg = u"Unsuccessful database update transaction:" + str(e)
         log.exception(errormsg, self.__class__.__name__)
         data["success"] = False
         data["error"] = errormsg
Exemplo n.º 7
0
 def updateZone(self, zone):
     checkZoneName = False
     updatedName = False
     updatedHost = False
     for line in self.lines:
         if app.config["ZONES_END_POINT"] in line:
             checkZoneName = False
         if app.config["ZONES_START_POINT"] in line:
             checkZoneName = True
         if zone.updateType == "MODIFIED NAME":
             if checkZoneName is True and zone.old_value == line.split()[0]:
                 # This will remove duplicates
                 if not updatedName:
                     # Check if ip address or hostname
                     try:
                         socket.inet_aton(zone.host)
                         newline = "%s\tIN\tA\t%s\n"%(zone.name,zone.host)
                     except:
                         if not zone.host[:-1] == ".":
                             zone.host = zone.host + "."
                         newline = "%s\tIN\tCNAME\t%s\n"%(
                             zone.name,zone.host)
                     self.templines.append(newline)
                     updatedName = True
             else:
                 self.templines.append(line)
         elif zone.updateType == "MODIFIED HOST":
             if checkZoneName is True and zone.name in line.split()[0]:
                 # This will remove duplicates
                 if not updatedHost:
                     # Check if ip address or hostname
                     try:
                         socket.inet_aton(zone.host)
                         newline = "%s\tIN\tA\t%s\n"%(zone.name,zone.host)
                     except:
                         if not zone.host[:-1] == ".":
                             zone.host = zone.host + "."
                         newline = "%s\tIN\tCNAME\t%s\n"%(
                             zone.name,zone.host)
                     self.templines.append(newline)
                     updatedHost = True
             else:
                 self.templines.append(line)
     if updatedName:
         try:
             self.c.execute("""
                 UPDATE zones
                 SET updated = 0, update_type = NULL, name = ?
                 WHERE old_value LIKE ?
                 """,[zone.name, zone.old_value])
             self.db.commit()
         except Exception, e:
             errormsg = u"Unsuccessful database update transaction:" + str(e)
             log.exception(errormsg, self.__class__.__name__)
Exemplo n.º 8
0
 def deleteZone(self,zone):
     checkZoneName = False
     for line in self.lines:
         if zone.updateType == "DELETE":
             if app.config["ZONES_END_POINT"] in line:
                 checkZoneName = False
             if app.config["ZONES_START_POINT"] in line:
                 checkZoneName = True
             if checkZoneName and zone.name in line:
                 # This will remove duplicates
                 continue
             else:
                 self.templines.append(line)
     try:
         self.c.execute("""
             DELETE FROM zones
             WHERE name LIKE ?
             """,[zone.name])
         self.db.commit()
     except Exception, e:
         errormsg = u"Unsuccessful database delete transaction:" + str(e)
         log.exception(errormsg, self.__class__.__name__)
Exemplo n.º 9
0
 def add(self, name, host):
     data = {}
     # Check if name exists
     db = DBHandler(app.config["DBFILE"])
     c = db.getCursor()
     if db.exists("zones", "name", name):
         data["error"] = u"Duplicate name entry in db"
         data["success"] = False
     else:
         try:
             c.execute("""
                 INSERT INTO zones(name,host,updated,update_type)
                 VALUES(?,?,1,'CREATE')
                        """,[name,host])
             db.commit()
             data["success"] = True
             data["message"] = u"Entry %s inserted"%(name)
         except Exception, e:
             errormsg = u"Unsuccessful database insert transaction:" + str(e)
             log.exception(errormsg, self.__class__.__name__)
             data["success"] = False
             data["error"] = errormsg
Exemplo n.º 10
0
 def delete(self, name):
     data = {}
     db = DBHandler(app.config["DBFILE"])
     c = db.getCursor()
     zone = list(c.execute("""
         SELECT name FROM zones
         WHERE name LIKE ?
         """,[name]))
     if len(zone) > 0 and zone[0][0] == name:
         try:
             c.execute("""
                 UPDATE zones
                 SET updated = 1, update_type = 'DELETE'
                 WHERE name LIKE ?
                 """,[name])
             db.commit()
             data["success"] = True
             data["message"] = u"Entry %s deleted"%(name)
         except Exception, e:
             errormsg = u"Unsuccessful database delete transaction:" + str(e)
             log.exception(errormsg, self.__class__.__name__)
             data["success"] = False
             data["error"] = errormsg
Exemplo n.º 11
0
 def add(self, name, host):
     data = {}
     # Check if name exists
     db = DBHandler(app.config["DBFILE"])
     c = db.getCursor()
     if db.exists("zones", "name", name):
         data["error"] = u"Duplicate name entry in db"
         data["success"] = False
     else:
         try:
             c.execute(
                 """
                 INSERT INTO zones(name,host,updated,update_type)
                 VALUES(?,?,1,'CREATE')
                        """, [name, host])
             db.commit()
             data["success"] = True
             data["message"] = u"Entry %s inserted" % (name)
         except Exception, e:
             errormsg = u"Unsuccessful database insert transaction:" + str(
                 e)
             log.exception(errormsg, self.__class__.__name__)
             data["success"] = False
             data["error"] = errormsg
Exemplo n.º 12
0
 def reloadBind(self):
     if call(app.config["BIND_RELOAD_CMD"], shell=True) != 0:
         errormsg = u"Couldn't reload BIND."
         log.exception(errormsg, self.__class__.__name__)
Exemplo n.º 13
0
                 """,[zone.name, zone.old_value])
             self.db.commit()
         except Exception, e:
             errormsg = u"Unsuccessful database update transaction:" + str(e)
             log.exception(errormsg, self.__class__.__name__)
     if updatedHost:
         try:
             self.c.execute("""
                 UPDATE zones
                 SET updated = 0, update_type = NULL, host = ?
                 WHERE name LIKE ?
                 """,[zone.host, zone.name])
             self.db.commit()
         except Exception, e:
             errormsg = u"Unsuccessful database update transaction:" + str(e)
             log.exception(errormsg, self.__class__.__name__)
 
 def deleteZone(self,zone):
     checkZoneName = False
     for line in self.lines:
         if zone.updateType == "DELETE":
             if app.config["ZONES_END_POINT"] in line:
                 checkZoneName = False
             if app.config["ZONES_START_POINT"] in line:
                 checkZoneName = True
             if checkZoneName and zone.name in line:
                 # This will remove duplicates
                 continue
             else:
                 self.templines.append(line)
     try: