VirtualMailManager/Handler.py
branchv0.6.x
changeset 187 38b9a9859749
parent 186 18757fd45e60
child 188 cf1b5f22dbd2
equal deleted inserted replaced
186:18757fd45e60 187:38b9a9859749
    78     def __chkCfgFile(self):
    78     def __chkCfgFile(self):
    79         """Checks the configuration file, returns bool"""
    79         """Checks the configuration file, returns bool"""
    80         self.__findCfgFile()
    80         self.__findCfgFile()
    81         fstat = os.stat(self.__cfgFileName)
    81         fstat = os.stat(self.__cfgFileName)
    82         fmode = int(oct(fstat.st_mode & 0777))
    82         fmode = int(oct(fstat.st_mode & 0777))
    83         if fmode % 100 and fstat.st_uid != fstat.st_gid \
    83         if fmode % 100 and fstat.st_uid != fstat.st_gid or \
    84         or fmode % 10 and fstat.st_uid == fstat.st_gid:
    84             fmode % 10 and fstat.st_uid == fstat.st_gid:
    85             raise VMMPermException(_(
    85               raise VMMPermException(_(
    86                 u'fix permissions (%(perms)s) for “%(file)s”\n\
    86                     u'fix permissions (%(perms)s) for “%(file)s”\n\
    87 `chmod 0600 %(file)s` would be great.') % {'file':
    87 `chmod 0600 %(file)s` would be great.') % {'file':
    88                 self.__cfgFileName, 'perms': fmode}, ERR.CONF_WRONGPERM)
    88                     self.__cfgFileName, 'perms': fmode}, ERR.CONF_WRONGPERM)
    89         else:
    89         else:
    90             return True
    90             return True
    91 
    91 
    92     def __chkenv(self):
    92     def __chkenv(self):
    93         """"""
    93         """"""
   152         return Handler._exists(dbh, sql)
   152         return Handler._exists(dbh, sql)
   153     accountExists = staticmethod(accountExists)
   153     accountExists = staticmethod(accountExists)
   154 
   154 
   155     def aliasExists(dbh, address):
   155     def aliasExists(dbh, address):
   156         sql = "SELECT DISTINCT gid FROM alias WHERE gid = (SELECT gid FROM\
   156         sql = "SELECT DISTINCT gid FROM alias WHERE gid = (SELECT gid FROM\
   157  domain_name WHERE domainname = '%s') AND address = '%s'" %\
   157  domain_name WHERE domainname = '%s') AND address = '%s'" %
   158             (address._domainname, address._localpart)
   158             (address._domainname, address._localpart)
   159         return Handler._exists(dbh, sql)
   159         return Handler._exists(dbh, sql)
   160     aliasExists = staticmethod(aliasExists)
   160     aliasExists = staticmethod(aliasExists)
   161 
   161 
   162     def relocatedExists(dbh, address):
   162     def relocatedExists(dbh, address):
   163         sql = "SELECT gid FROM relocated WHERE gid = (SELECT gid FROM\
   163         sql = "SELECT gid FROM relocated WHERE gid = (SELECT gid FROM\
   164  domain_name WHERE domainname = '%s') AND address = '%s'" %\
   164  domain_name WHERE domainname = '%s') AND address = '%s'" %
   165             (address._domainname, address._localpart)
   165             (address._domainname, address._localpart)
   166         return Handler._exists(dbh, sql)
   166         return Handler._exists(dbh, sql)
   167     relocatedExists = staticmethod(relocatedExists)
   167     relocatedExists = staticmethod(relocatedExists)
   168 
   168 
   169 
   169 
   402 
   402 
   403         Keyword arguments:
   403         Keyword arguments:
   404         section -- the section to configure (default None):
   404         section -- the section to configure (default None):
   405         """
   405         """
   406         if section is None:
   406         if section is None:
   407             self.__Cfg.configure(self.__Cfg.getsections())
   407             self.__Cfg.configure(self.__Cfg.sections())
   408         elif self.__Cfg.has_section(section):
   408         elif self.__Cfg.has_section(section):
   409             self.__Cfg.configure([section])
   409             self.__Cfg.configure([section])
   410         else:
   410         else:
   411             raise VMMException(_(u"Invalid section: “%s”") % section,
   411             raise VMMException(_(u"Invalid section: “%s”") % section,
   412                                ERR.INVALID_SECTION)
   412                                ERR.INVALID_SECTION)
   543 
   543 
   544     def aliasAdd(self, aliasaddress, targetaddress):
   544     def aliasAdd(self, aliasaddress, targetaddress):
   545         alias = self.__getAlias(aliasaddress, targetaddress)
   545         alias = self.__getAlias(aliasaddress, targetaddress)
   546         alias.save(long(self._postconf.read('virtual_alias_expansion_limit')))
   546         alias.save(long(self._postconf.read('virtual_alias_expansion_limit')))
   547         gid = self.__getDomain(alias._dest._domainname).getID()
   547         gid = self.__getDomain(alias._dest._domainname).getID()
   548         if gid > 0 and not Handler.accountExists(self.__dbh,
   548         if gid > 0 and (not Handler.accountExists(self.__dbh, alias._dest) and
   549         alias._dest) and not Handler.aliasExists(self.__dbh,
   549                         not Handler.aliasExists(self.__dbh, alias._dest)):
   550         alias._dest):
       
   551             self.__warnings.append(
   550             self.__warnings.append(
   552                 _(u"The destination account/alias “%s” doesn't exist.")%\
   551                     _(u"The destination account/alias “%s” doesn't exist.") %
   553                         alias._dest)
   552                                    alias._dest)
   554 
   553 
   555     def userDelete(self, emailaddress, force=None):
   554     def userDelete(self, emailaddress, force=None):
   556         if force not in [None, 'delalias']:
   555         if force not in [None, 'delalias']:
   557             raise VMMException(_(u"Invalid argument: “%s”") % force,
   556             raise VMMException(_(u"Invalid argument: “%s”") % force,
   558                     ERR.INVALID_AGUMENT)
   557                     ERR.INVALID_AGUMENT)