[1575] | 1 | #!/usr/bin/env python
|
---|
| 2 |
|
---|
| 3 | """
|
---|
| 4 | FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
---|
| 5 | Copyright (C) 2003-2009 Frederico Caldeira Knabben
|
---|
| 6 |
|
---|
| 7 | == BEGIN LICENSE ==
|
---|
| 8 |
|
---|
| 9 | Licensed under the terms of any of the following licenses at your
|
---|
| 10 | choice:
|
---|
| 11 |
|
---|
| 12 | - GNU General Public License Version 2 or later (the "GPL")
|
---|
| 13 | http://www.gnu.org/licenses/gpl.html
|
---|
| 14 |
|
---|
| 15 | - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
|
---|
| 16 | http://www.gnu.org/licenses/lgpl.html
|
---|
| 17 |
|
---|
| 18 | - Mozilla Public License Version 1.1 or later (the "MPL")
|
---|
| 19 | http://www.mozilla.org/MPL/MPL-1.1.html
|
---|
| 20 |
|
---|
| 21 | == END LICENSE ==
|
---|
| 22 |
|
---|
| 23 | This is the "File Uploader" for Python
|
---|
| 24 |
|
---|
| 25 | """
|
---|
| 26 | import os
|
---|
| 27 |
|
---|
| 28 | from fckutil import *
|
---|
| 29 | from fckcommands import * # default command's implementation
|
---|
| 30 | from fckconnector import FCKeditorConnectorBase # import base connector
|
---|
| 31 | import config as Config
|
---|
| 32 |
|
---|
| 33 | class FCKeditorQuickUpload( FCKeditorConnectorBase,
|
---|
| 34 | UploadFileCommandMixin,
|
---|
| 35 | BaseHttpMixin, BaseHtmlMixin):
|
---|
| 36 | def doResponse(self):
|
---|
| 37 | "Main function. Process the request, set headers and return a string as response."
|
---|
| 38 | # Check if this connector is disabled
|
---|
| 39 | if not(Config.Enabled):
|
---|
| 40 | return self.sendUploadResults(1, "This file uploader is disabled. Please check the \"editor/filemanager/connectors/py/config.py\"")
|
---|
| 41 | command = 'QuickUpload'
|
---|
| 42 | # The file type (from the QueryString, by default 'File').
|
---|
| 43 | resourceType = self.request.get('Type','File')
|
---|
| 44 | currentFolder = "/"
|
---|
| 45 | # Check for invalid paths
|
---|
| 46 | if currentFolder is None:
|
---|
| 47 | return self.sendUploadResults(102, '', '', "")
|
---|
| 48 |
|
---|
| 49 | # Check if it is an allowed command
|
---|
| 50 | if ( not command in Config.ConfigAllowedCommands ):
|
---|
| 51 | return self.sendUploadResults( 1, '', '', 'The %s command isn\'t allowed' % command )
|
---|
| 52 |
|
---|
| 53 | if ( not resourceType in Config.ConfigAllowedTypes ):
|
---|
| 54 | return self.sendUploadResults( 1, '', '', 'Invalid type specified' )
|
---|
| 55 |
|
---|
| 56 | # Setup paths
|
---|
| 57 | self.userFilesFolder = Config.QuickUploadAbsolutePath[resourceType]
|
---|
| 58 | self.webUserFilesFolder = Config.QuickUploadPath[resourceType]
|
---|
| 59 | if not self.userFilesFolder: # no absolute path given (dangerous...)
|
---|
| 60 | self.userFilesFolder = mapServerPath(self.environ,
|
---|
| 61 | self.webUserFilesFolder)
|
---|
| 62 |
|
---|
| 63 | # Ensure that the directory exists.
|
---|
| 64 | if not os.path.exists(self.userFilesFolder):
|
---|
| 65 | try:
|
---|
| 66 | self.createServerFoldercreateServerFolder( self.userFilesFolder )
|
---|
| 67 | except:
|
---|
| 68 | 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. ")
|
---|
| 69 |
|
---|
| 70 | # File upload doesn't have to return XML, so intercept here
|
---|
| 71 | return self.uploadFile(resourceType, currentFolder)
|
---|
| 72 |
|
---|
| 73 | # Running from command line (plain old CGI)
|
---|
| 74 | if __name__ == '__main__':
|
---|
| 75 | try:
|
---|
| 76 | # Create a Connector Instance
|
---|
| 77 | conn = FCKeditorQuickUpload()
|
---|
| 78 | data = conn.doResponse()
|
---|
| 79 | for header in conn.headers:
|
---|
| 80 | if not header is None:
|
---|
| 81 | print '%s: %s' % header
|
---|
| 82 | print
|
---|
| 83 | print data
|
---|
| 84 | except:
|
---|
| 85 | print "Content-Type: text/plain"
|
---|
| 86 | print
|
---|
| 87 | import cgi
|
---|
| 88 | cgi.print_exception()
|
---|