Skip to content

Commit

Permalink
added authentication control
Browse files Browse the repository at this point in the history
  • Loading branch information
Aybars committed Jul 6, 2011
1 parent 72ea379 commit 6db93c6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
5 changes: 1 addition & 4 deletions config.py
@@ -1,6 +1,3 @@
#! /usr/bin/python

apikey ='pil'
apisecret = ''
# leave this as '' to listen to all interfaces, else put your local ip address
ip_address = ''
ip_address = ''
28 changes: 9 additions & 19 deletions putio-ftp-connector.py
Expand Up @@ -73,7 +73,6 @@ def read(self, size=65536):


def seek(self, frombytes, **kwargs):
print ">>>>>>>>>> seek"
self.seekpos = frombytes
return

Expand Down Expand Up @@ -172,7 +171,6 @@ def remove(self, path):
self.remove_from_cache(path)

def rename(self, src, dst):
print "src>>>>>>", src, dst
apifile = self._getitem(src)
if not apifile:
raise OSError(2, 'No such file or directory')
Expand Down Expand Up @@ -216,7 +214,6 @@ def isdir(self, path):
return False

def getsize(self, path):
print ">>>>>>>>>>>>> GETSIZE"
apifile = self._getitem(path)
if not apifile:
raise OSError(1, 'No such file or directory')
Expand All @@ -225,23 +222,19 @@ def getsize(self, path):
#return self.stat(path).st_size

def getmtime(self, path):
print "mtime"
return self.stat(path).st_mtime

def realpath(self, path):
return path

def lexists(self, path):
print "lexists"
apifile = self._getitem(path)
if not apifile:
raise OSError(2, 'No such file or directory')
return apifile


def _getitem(self, filename):
print "filename: ", filename

if filename in self.dirlistcache:
apifile = self.dirlistcache[filename]
print 'found........', apifile.id, apifile.name
Expand All @@ -259,9 +252,7 @@ def _getitem(self, filename):


def stat(self, path):
print ">>>>>> stat:", path
apifile = self._getitem(path)

return os.stat_result((666, 0L, 0L, 0, 0, 0, apifile.size, 0, 0, 0))

exists = lexists
Expand Down Expand Up @@ -294,16 +285,9 @@ def get_list_dir(self, path):
return self.format_list_items(items)

def format_mlsx(self, basedir, listing, perms, facts, ignore_err=True):

print 'facts', facts
print 'basedir', basedir
print 'listing', listing

# find item in cache...
if basedir in self.dirlistcache:
print 'found............'
fnd = self.dirlistcache[basedir]
print 'found........', fnd.id, fnd.name
try:
items = operations.api.get_items(parent_id = fnd.id)
except:
Expand Down Expand Up @@ -357,8 +341,14 @@ def authenticate(self, username, password):
self.password = password
config.apisecret = password
config.apikey = username
print "here !..............."
self.api = putio.Api(config.apikey,config.apisecret)

print "checking user & passwd"
username = self.api.get_user_name()
if not username:
return False

print "> welcome ", username
return True


Expand All @@ -376,8 +366,7 @@ class HttpAuthorizer(ftpserver.DummyAuthorizer):

def validate_authentication(self, username, password):
try:
operations.authenticate(username, password)
return True
return operations.authenticate(username, password)
except:
return False

Expand Down Expand Up @@ -406,6 +395,7 @@ def main():
ftp_handler = ftpserver.FTPHandler
ftp_handler.authorizer = HttpAuthorizer()
ftp_handler.abstracted_fs = HttpFS

# ftp_handler.passive_ports = range(60000, 65535)
# try:
# ftp_handler.masquerade_address = gethostbyname(options.bind_address)
Expand Down

0 comments on commit 6db93c6

Please sign in to comment.