Back to index

moin  1.9.0~rc2
upload.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 """
00004 FCKeditor - The text editor for Internet - http://www.fckeditor.net
00005 Copyright (C) 2003-2009 Frederico Caldeira Knabben
00006 
00007 == BEGIN LICENSE ==
00008 
00009 Licensed under the terms of any of the following licenses at your
00010 choice:
00011 
00012 - GNU General Public License Version 2 or later (the "GPL")
00013 http://www.gnu.org/licenses/gpl.html
00014 
00015 - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
00016 http://www.gnu.org/licenses/lgpl.html
00017 
00018 - Mozilla Public License Version 1.1 or later (the "MPL")
00019 http://www.mozilla.org/MPL/MPL-1.1.html
00020 
00021 == END LICENSE ==
00022 
00023 This is the "File Uploader" for Python
00024 
00025 """
00026 import os
00027 
00028 from fckutil import *
00029 from fckcommands import *   # default command's implementation
00030 from fckconnector import FCKeditorConnectorBase # import base connector
00031 import config as Config
00032 
00033 class FCKeditorQuickUpload( FCKeditorConnectorBase,
00034                                                  UploadFileCommandMixin,
00035                                                  BaseHttpMixin, BaseHtmlMixin):
00036        def doResponse(self):
00037               "Main function. Process the request, set headers and return a string as response."
00038               # Check if this connector is disabled
00039               if not(Config.Enabled):
00040                      return self.sendUploadResults(1, "This file uploader is disabled. Please check the \"editor/filemanager/connectors/py/config.py\"")
00041               command = 'QuickUpload'
00042               # The file type (from the QueryString, by default 'File').
00043               resourceType  = self.request.get('Type','File')
00044               currentFolder = "/"
00045               # Check for invalid paths
00046               if currentFolder is None:
00047                      return self.sendUploadResults(102, '', '', "")
00048 
00049               # Check if it is an allowed command
00050               if ( not command in Config.ConfigAllowedCommands ):
00051                      return self.sendUploadResults( 1, '', '', 'The %s command isn\'t allowed' % command )
00052 
00053               if ( not resourceType in Config.ConfigAllowedTypes  ):
00054                      return self.sendUploadResults( 1, '', '', 'Invalid type specified' )
00055 
00056               # Setup paths
00057               self.userFilesFolder = Config.QuickUploadAbsolutePath[resourceType]
00058               self.webUserFilesFolder =  Config.QuickUploadPath[resourceType]
00059               if not self.userFilesFolder: # no absolute path given (dangerous...)
00060                      self.userFilesFolder = mapServerPath(self.environ,
00061                                                                self.webUserFilesFolder)
00062 
00063               # Ensure that the directory exists.
00064               if not os.path.exists(self.userFilesFolder):
00065                      try:
00066                             self.createServerFoldercreateServerFolder( self.userFilesFolder )
00067                      except:
00068                             return self.sendError(1, "This connector couldn\'t access to local user\'s files directories.  Please check the UserFilesAbsolutePath in \"editor/filemanager/connectors/py/config.py\" and try again. ")
00069 
00070               # File upload doesn't have to return XML, so intercept here
00071               return self.uploadFile(resourceType, currentFolder)
00072 
00073 # Running from command line (plain old CGI)
00074 if __name__ == '__main__':
00075        try:
00076               # Create a Connector Instance
00077               conn = FCKeditorQuickUpload()
00078               data = conn.doResponse()
00079               for header in conn.headers:
00080                      if not header is None:
00081                             print '%s: %s' % header
00082               print
00083               print data
00084        except:
00085               print "Content-Type: text/plain"
00086               print
00087               import cgi
00088               cgi.print_exception()