コード例 #1
0
 def _connect(self):
    import MySQLdb
    sqlHost = rdw_config.getConfigSetting("sqlHost", self.configFilePath)
    sqlUsername = rdw_config.getConfigSetting("sqlUsername", self.configFilePath)
    sqlPassword = rdw_config.getConfigSetting("sqlPassword", self.configFilePath)
    sqlDatabaseName = rdw_config.getConfigSetting("sqlDatabase", self.configFilePath)
    self.sqlConnection = MySQLdb.connect(host=sqlHost, user=sqlUsername, passwd=sqlPassword,db=sqlDatabaseName)
コード例 #2
0
 def areUserCredentialsValid(self, username, password):
    """The valid users string in the config file is in the form:
       username=bill
       password=frank """
    valid_username = rdw_config.getConfigSetting("username", self.configFilePath)
    valid_password = rdw_config.getConfigSetting("password", self.configFilePath)
    return valid_username == username and valid_password == password
コード例 #3
0
   def _migrateExistingData(self):
      """ If we don't have any data, we may be using a sqlite interface for the first time.
      See if they have another database backend specified, and if they do, try to migrate the data."""
      
      if self._getTables(): return
      
      cursor = self.sqlConnection.cursor()
      cursor.execute("BEGIN TRANSACTION")
      for statement in self._getCreateStatements():
         cursor.execute(statement)

      if self._autoConvertDatabase:
         prevDBType = rdw_config.getConfigSetting("UserDB")
         if prevDBType.lower() == "mysql":
            print 'Converting database from mysql...'
            import db_mysql
            prevDB = db_mysql.mysqlUserDB()
            users = prevDB._executeQuery("SELECT UserID, Username, Password, UserRoot, IsAdmin, UserEmail, RestoreFormat FROM users")
            cursor.executemany("INSERT INTO users (UserID, Username, Password, UserRoot, IsAdmin, UserEmail, RestoreFormat) values (?, ?, ?, ?, ?, ?, ?)", users)
            
            repos = prevDB._executeQuery("SELECT UserID, RepoPath, MaxAge FROM repos")
            cursor.executemany("INSERT INTO repos (UserID, RepoPath, MaxAge) values (?, ?, ?)", repos)
         elif prevDBType.lower() == "file":
            print 'Converting database from file...'
            import db_file
            prevDB = db_file.fileUserDB()
            username = rdw_config.getConfigSetting("username")
            password = rdw_config.getConfigSetting("password")
            self.addUser(username)
            self.setUserPassword(username, password)
            self.setUserInfo(username, prevDB.getUserRoot(username), True)
            self.setUserRepos(username, prevDB.getUserRepoPaths(username))
         
      cursor.execute("COMMIT TRANSACTION")
コード例 #4
0
ファイル: db_sqlite.py プロジェクト: chencho/rdiffweb
   def _migrateExistingData(self):
      """ If we don't have any data, we may be using a sqlite interface for the first time.
      See if they have another database backend specified, and if they do, try to migrate the data."""
      
      if self._getTables(): return
      
      cursor = self.sqlConnection.cursor()
      cursor.execute("BEGIN TRANSACTION")
      for statement in self._getCreateStatements():
         cursor.execute(statement)

      if self._autoConvertDatabase:
         prevDBType = rdw_config.getConfigSetting("UserDB")
         if prevDBType.lower() == "mysql":
            print 'Converting database from mysql...'
            import db_mysql
            prevDB = db_mysql.mysqlUserDB()
            users = prevDB._executeQuery("SELECT UserID, Username, Password, UserRoot, IsAdmin, UserEmail, RestoreFormat FROM users")
            cursor.executemany("INSERT INTO users (UserID, Username, Password, UserRoot, IsAdmin, UserEmail, RestoreFormat) values (?, ?, ?, ?, ?, ?, ?)", users)
            
            repos = prevDB._executeQuery("SELECT UserID, RepoPath, MaxAge FROM repos")
            cursor.executemany("INSERT INTO repos (UserID, RepoPath, MaxAge) values (?, ?, ?)", repos)
         elif prevDBType.lower() == "file":
            print 'Converting database from file...'
            import db_file
            prevDB = db_file.fileUserDB()
            username = rdw_config.getConfigSetting("username")
            password = rdw_config.getConfigSetting("password")
            self.addUser(username)
            self.setUserPassword(username, password)
            self.setUserInfo(username, prevDB.getUserRoot(username), True)
            self.setUserRepos(username, prevDB.getUserRepoPaths(username))
         
      cursor.execute("COMMIT TRANSACTION")
コード例 #5
0
 def _connect(self):
    import MySQLdb
    sqlHost = rdw_config.getConfigSetting("sqlHost", self.configFilePath)
    sqlUsername = rdw_config.getConfigSetting("sqlUsername", self.configFilePath)
    sqlPassword = rdw_config.getConfigSetting("sqlPassword", self.configFilePath)
    sqlDatabaseName = rdw_config.getConfigSetting("sqlDatabase", self.configFilePath)
    self.sqlConnection = MySQLdb.connect(host=sqlHost, user=sqlUsername, passwd=sqlPassword,db=sqlDatabaseName)
コード例 #6
0
 def areUserCredentialsValid(self, username, password):
     """The valid users string in the config file is in the form:
      username=bill
      password=frank """
     valid_username = rdw_config.getConfigSetting("username",
                                                  self.configFilePath)
     valid_password = rdw_config.getConfigSetting("password",
                                                  self.configFilePath)
     return valid_username == username and valid_password == password
コード例 #7
0
 def getUserDBModule(self):
    authModuleSetting = rdw_config.getConfigSetting("UserDB");
    if authModuleSetting.lower() == "file":
       return db_file.fileUserDB()
    if authModuleSetting.lower() == "mysql":
       return db_mysql.mysqlUserDB()
    assert(False)
コード例 #8
0
 def getUserDBModule(self):
     authModuleSetting = rdw_config.getConfigSetting("UserDB")
     if authModuleSetting.lower() == "file":
         return db_file.fileUserDB()
     if authModuleSetting.lower() == "mysql":
         return db_mysql.mysqlUserDB()
     assert (False)
コード例 #9
0
def log(message):
    message = message.strip('\r\n')
    print message
    log_file_path = rdw_config.getConfigSetting('ErrorLogFile')
    if log_file_path:
        log_file = open(log_file_path, 'a')
        log_file.write(message + '\n')
        log_file.close()
コード例 #10
0
def log(message):
   message = message.strip('\r\n')
   print message
   log_file_path = rdw_config.getConfigSetting('ErrorLogFile')
   if log_file_path:
      log_file = open(log_file_path, 'a')
      log_file.write(message + '\n')
      log_file.close()
コード例 #11
0
def getFilters():
    filters = [
        filter_authentication.rdwAuthenticationFilter(),
        cherrypy.filters.encodingfilter.EncodingFilter()
    ]
    if rdw_config.getConfigSetting("UseHttps").upper() == "TRUE":
        filters.append(filter_https.rdwHttpsFilter())
    return filters
コード例 #12
0
 def run(self):
    spiderInterval = rdw_config.getConfigSetting("autoUpdateRepos")
    if spiderInterval:
       spiderInterval = int(spiderInterval)         
       while True:
          findReposForAllUsers(False)
          self.killEvent.wait(60*spiderInterval)
          if self.killEvent.isSet():
             return
コード例 #13
0
   def run(self):
      if not self.notifier.notificationsEnabled():
         return;
      emailTimeStr = rdw_config.getConfigSetting("emailNotificationTime")
      while True:
         emailTime = time.strptime(emailTimeStr, "%H:%M")
         now = datetime.datetime.now()
         nextEmailTime = now.replace(hour=emailTime.tm_hour, minute=emailTime.tm_min, second=0, microsecond=0)
         if nextEmailTime < now:
            nextEmailTime = nextEmailTime.replace(day=nextEmailTime.day+1)
         delta = (nextEmailTime - now).seconds
         self.killEvent.wait(delta)
         if self.killEvent.isSet():
            return

         self.notifier.sendEmails()
コード例 #14
0
   def run(self):
      self.notifier = emailNotifier()
      if not self.notifier.notificationsEnabled():
         return
      emailTimeStr = rdw_config.getConfigSetting("emailNotificationTime")
      while True:
         try:
            emailTime = time.strptime(emailTimeStr, "%H:%M")
            now = datetime.datetime.now()
            nextEmailTime = now.replace(hour=emailTime.tm_hour, minute=emailTime.tm_min, second=0, microsecond=0)
            if nextEmailTime < now:
               nextEmailTime = nextEmailTime + datetime.timedelta(days=1)
            delta = (nextEmailTime - now).seconds
            self.killEvent.wait(delta)
            if self.killEvent.isSet():
               return

            self.notifier.sendEmails()
         except Exception:
            rdw_logging.log_exception()
コード例 #15
0
def getFilters():
    filters = [rdwAuthenticationFilter()]
    if rdw_config.getConfigSetting("UseHttps").upper() == "TRUE":
        filters.append(rdwHttpsFilter())
    return filters
コード例 #16
0
 def _getEmailPassword(self):
    return rdw_config.getConfigSetting("emailPassword")
コード例 #17
0
 def getNotificationTimeStr(self):
    return rdw_config.getConfigSetting("emailNotificationTime")
コード例 #18
0
 def _getEmailUsername(self):
    return rdw_config.getConfigSetting("emailUsername")
コード例 #19
0
def getFilters():
   filters = [rdwAuthenticationFilter()]
   if rdw_config.getConfigSetting("UseSTunnel").upper() == "TRUE":
      filters.append(StunnelFilter(rdw_config.getConfigSetting("VisibleServerName")))
   return filters
コード例 #20
0
 def userExists(self, username):
    valid_username = rdw_config.getConfigSetting("username", self.configFilePath)
    return valid_username == username
コード例 #21
0
 def _getEmailHost(self):
    return rdw_config.getConfigSetting("emailHost")
コード例 #22
0
 def _getEmailUsername(self):
    return rdw_config.getConfigSetting("emailUsername")
コード例 #23
0
def getTunnellingFilters():
   if rdw_config.getConfigSetting("UseSTunnel").upper() == "TRUE":
      return [StunnelFilter(rdw_config.getConfigSetting("VisibleServerName"))]
   return []
コード例 #24
0
def getEmailSender():
   return rdw_config.getConfigSetting("emailSender")
コード例 #25
0
 def getUserRepoPaths(self, username):
     """The user home dirs string in the config file is in the form of username:/data/dir|/data/dir2..."""
     if not self.userExists(username): return None
     return rdw_config.getConfigSetting("UserRepoPaths",
                                        self.configFilePath).split("|")
コード例 #26
0
def getTunnellingFilters():
    if rdw_config.getConfigSetting("UseSTunnel").upper() == "TRUE":
        return [
            StunnelFilter(rdw_config.getConfigSetting("VisibleServerName"))
        ]
    return []
コード例 #27
0
 def getUserRoot(self, username):
    if not self.userExists(username): return None
    return rdw_config.getConfigSetting("UserRoot", self.configFilePath)
コード例 #28
0
def getFilters():
   filters = [rdwAuthenticationFilter()]
   if rdw_config.getConfigSetting("UseHttps").upper() == "TRUE":
      filters.append(rdwHttpsFilter())
   return filters
コード例 #29
0
 def _getNotificationTimeStr(self):
    return rdw_config.getConfigSetting("emailNotificationTime")
コード例 #30
0
 def getUserRoot(self, username):
     if not self.userExists(username): return None
     return rdw_config.getConfigSetting("UserRoot", self.configFilePath)
コード例 #31
0
def getFilters():
    filters = [rdwAuthenticationFilter()]
    if rdw_config.getConfigSetting("UseSTunnel").upper() == "TRUE":
        filters.append(
            StunnelFilter(rdw_config.getConfigSetting("VisibleServerName")))
    return filters
コード例 #32
0
    def getParmsForPage(self,
                        root,
                        repos,
                        allowRepoDeletion=False,
                        message='',
                        error=''):
        repoList = []
        for userRepo in repos:
            try:
                repoHistory = librdiff.getLastBackupHistoryEntry(
                    rdw_helpers.joinPaths(root, userRepo))
            except librdiff.FileError:
                repoSize = "0"
                repoDate = "Error"
                repoList.append({
                    "repoName":
                    userRepo,
                    "repoSize":
                    repoSize,
                    "repoDate":
                    repoDate,
                    "repoBrowseUrl":
                    self.buildBrowseUrl(userRepo, "/", False),
                    "repoHistoryUrl":
                    self.buildHistoryUrl(userRepo),
                    'failed':
                    True
                })
            else:
                repoSize = rdw_helpers.formatFileSizeStr(repoHistory.size)
                if repoHistory.inProgress:
                    repoSize = "In Progress"
                repoDate = repoHistory.date.getDisplayString()
                repoList.append({
                    "repoName":
                    userRepo,
                    "repoSize":
                    repoSize,
                    "repoDate":
                    repoDate,
                    "repoBrowseUrl":
                    self.buildBrowseUrl(userRepo, "/", False),
                    "repoHistoryUrl":
                    self.buildHistoryUrl(userRepo),
                    'failed':
                    False
                })

        self._sortLocations(repoList)
        # Make second pass through list, setting the 'altRow' attribute
        for i in range(0, len(repoList)):
            repoList[i]['altRow'] = (i % 2 == 0)
        # Calculate disk usage
        diskUsage = ''
        diskUsageCommand = rdw_config.getConfigSetting('diskUsageCommand')
        if diskUsageCommand:
            diskUsage = subprocess.Popen(
                [
                    diskUsageCommand,
                    self.getUsername(),
                    self.getUserDB().getUserRoot(self.getUsername())
                ],
                stdout=subprocess.PIPE).communicate()[0]
            try:
                diskUsageNum = int(diskUsage)
            except:
                pass
            else:
                diskUsage = rdw_helpers.formatFileSizeStr(diskUsageNum)
        # Allow repository deletion?
        return {
            "title": "browse",
            "repos": repoList,
            "diskUsage": diskUsage,
            "allowRepoDeletion": allowRepoDeletion,
            "message": message,
            "error": error
        }
コード例 #33
0
 def getUserRepoPaths(self, username):
    """The user home dirs string in the config file is in the form of username:/data/dir|/data/dir2..."""
    if not self.userExists(username): return None
    return rdw_config.getConfigSetting("UserRepoPaths", self.configFilePath).split("|")
コード例 #34
0
 def _getEmailSender(self):
    return rdw_config.getConfigSetting("emailSender")
コード例 #35
0
 def getEmailHost(self):
    return rdw_config.getConfigSetting("emailHost")
コード例 #36
0
 def _getEmailPassword(self):
    return rdw_config.getConfigSetting("emailPassword")
コード例 #37
0
 def getEmailSender(self):
    return rdw_config.getConfigSetting("emailSender")
コード例 #38
0
def getEmailHost():
   return rdw_config.getConfigSetting("emailHost")
コード例 #39
0
 def userExists(self, username):
     valid_username = rdw_config.getConfigSetting("username",
                                                  self.configFilePath)
     return valid_username == username