Exemplo n.º 1
0
 def _saveTrackings(self):
     if self.trackingsSaved: return
     try:
         self.trackingsLock.acquire()
         trackingFile = h.makePath(self.basePath, ".tracking")
         tmpTrackingFile = h.makePath(self.basePath, ".tracking.tmp")
         h.logDebug("Saving trackings saved to file", len(self.trackings),
                    trackingFile)
         headers, datas = [
             "path", "authorized", "password", "ip", "date", "protected",
             "location"
         ], []
         for t in self.trackings:
             datas.append([
                 t.path, t.authorized, t.password, t.ip, t.date,
                 t.protected, t.location
             ])
         h.writeToCSV(datas, tmpTrackingFile, headers=headers, append=True)
         h.delete(trackingFile)
         os.rename(tmpTrackingFile, trackingFile)
         if self.user is not None:
             h.changeFileOwner(trackingFile, self.user)
         self.trackingsSaved = True
         h.logDebug("Trackings saved to file", len(self.trackings),
                    trackingFile)
     except:
         le, lt = h.getLastExceptionAndTrace()
         h.logWarning("Can't save trackings", le)
     finally:
         self.trackingsLock.release()
Exemplo n.º 2
0
 def addShare(self, shareID, paths, duration, password):
     paths = [path.lstrip("/").rstrip("/") for path in paths]
     sharePath = h.makePath(self.sharesPath, shareID)
     password = "" if password is None else password
     lh, lf = None, h.makePath(h.LOCKS_FOLDER,
                               "_sfl_share%s" % h.clean(shareID))
     try:
         lh = h.getLockExclusive(lf, 5)
         s = share(shareID, h.now(), paths, [], password, duration)
         h.writeJsonFile(
             sharePath, {
                 "ID": s.ID,
                 "files": s.files,
                 "creation": s.creation,
                 "views": s.views,
                 "duration": s.duration,
                 "password": s.password
             })
         if self.user is not None: h.changeFileOwner(sharePath, self.user)
         return s, "ok"
     except:
         le, lt = h.getLastExceptionAndTrace()
         return None, le
     finally:
         if lh is not None: h.releaseLock(lh)
    def __init__(self,
                 ap: ap.authProvider,
                 basePath,
                 maxZipSize=50e6,
                 tmpFolder=None,
                 tmpFolderDuratioInDays=7,
                 user=None,
                 hiddenItems=None):
        if hiddenItems is None: hiddenItems = []
        self.hiddenItems = set(hiddenItems)
        self.basePath = os.path.abspath(basePath)
        self.maxZipSize = maxZipSize
        self.tmpFolder = tmpFolder.lstrip("/")
        self.tmpFolderDuration = tmpFolderDuratioInDays * 24 * 60 * 60
        self.user = h.getUserID(user)
        self.ap = ap
        self.cleanTmpThread = None

        if self.tmpFolder is not None:
            tmpPath = h.makePath(self.basePath, self.tmpFolder)
            if not os.path.exists(tmpPath):
                h.makeDir(tmpPath)
                if self.user is not None: h.changeFileOwner(tmpPath, self.user)
            ap.setListingForbidden(self.tmpFolder)
            ap.setDownloadForbidden(self.tmpFolder)
            ap.setShowForbidden(self.tmpFolder)
            ap.setShareForbidden(self.tmpFolder)
            ap.setEditAllowed(self.tmpFolder)
            self.cleanTmpThread = CleanTmp(tmpPath, self.tmpFolderDuration)
            self.cleanTmpThread.start()
Exemplo n.º 4
0
 def __init__(self,
              sharesPath,
              user=None,
              locationEnabled=False,
              locationAPIKey=""):
     self.user = h.getUserID(user)
     self.sharesPath = h.makeDirPath(os.path.abspath(sharesPath))
     if self.user is not None: h.changeFileOwner(self.sharesPath, self.user)
     self.locationEnabled = locationEnabled
     self.locationAPIKey = locationAPIKey
Exemplo n.º 5
0
 def saveShare(self, s: share):
     lh, lf = None, h.makePath(h.LOCKS_FOLDER,
                               "_sfl_share%s" % h.clean(s.ID))
     try:
         lh = h.getLockExclusive(lf, 5)
         sharePath = h.makePath(self.sharesPath, s.ID)
         h.writeJsonFile(
             sharePath, {
                 "ID": s.ID,
                 "files": s.files,
                 "creation": s.creation,
                 "views": s.views,
                 "duration": s.duration,
                 "password": s.password
             })
         if self.user is not None: h.changeFileOwner(sharePath, self.user)
         return True
     except:
         le, lt = h.getLastExceptionAndTrace()
         return False
     finally:
         if lh is not None: h.releaseLock(lh)