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 | Connector for Python (CGI and WSGI).
|
---|
24 |
|
---|
25 | See config.py for configuration settings
|
---|
26 |
|
---|
27 | """
|
---|
28 | import os
|
---|
29 |
|
---|
30 | from fckutil import *
|
---|
31 | from fckcommands import * # default command's implementation
|
---|
32 | from fckoutput import * # base http, xml and html output mixins
|
---|
33 | from fckconnector import FCKeditorConnectorBase # import base connector
|
---|
34 | import config as Config
|
---|
35 |
|
---|
36 | class FCKeditorConnector( FCKeditorConnectorBase,
|
---|
37 | GetFoldersCommandMixin,
|
---|
38 | GetFoldersAndFilesCommandMixin,
|
---|
39 | CreateFolderCommandMixin,
|
---|
40 | UploadFileCommandMixin,
|
---|
41 | BaseHttpMixin, BaseXmlMixin, BaseHtmlMixin ):
|
---|
42 | "The Standard connector class."
|
---|
43 | def doResponse(self):
|
---|
44 | "Main function. Process the request, set headers and return a string as response."
|
---|
45 | s = ""
|
---|
46 | # Check if this connector is disabled
|
---|
47 | if not(Config.Enabled):
|
---|
48 | return self.sendError(1, "This connector is disabled. Please check the connector configurations in \"editor/filemanager/connectors/py/config.py\" and try again.")
|
---|
49 | # Make sure we have valid inputs
|
---|
50 | for key in ("Command","Type","CurrentFolder"):
|
---|
51 | if not self.request.has_key (key):
|
---|
52 | return
|
---|
53 | # Get command, resource type and current folder
|
---|
54 | command = self.request.get("Command")
|
---|
55 | resourceType = self.request.get("Type")
|
---|
56 | currentFolder = getCurrentFolder(self.request.get("CurrentFolder"))
|
---|
57 | # Check for invalid paths
|
---|
58 | if currentFolder is None:
|
---|
59 | if (command == "FileUpload"):
|
---|
60 | return self.sendUploadResults( errorNo = 102, customMsg = "" )
|
---|
61 | else:
|
---|
62 | return self.sendError(102, "")
|
---|
63 |
|
---|
64 | # Check if it is an allowed command
|
---|
65 | if ( not command in Config.ConfigAllowedCommands ):
|
---|
66 | return self.sendError( 1, 'The %s command isn\'t allowed' % command )
|
---|
67 |
|
---|
68 | if ( not resourceType in Config.ConfigAllowedTypes ):
|
---|
69 | return self.sendError( 1, 'Invalid type specified' )
|
---|
70 |
|
---|
71 | # Setup paths
|
---|
72 | if command == "QuickUpload":
|
---|
73 | self.userFilesFolder = Config.QuickUploadAbsolutePath[resourceType]
|
---|
74 | self.webUserFilesFolder = Config.QuickUploadPath[resourceType]
|
---|
75 | else:
|
---|
76 | self.userFilesFolder = Config.FileTypesAbsolutePath[resourceType]
|
---|
77 | self.webUserFilesFolder = Config.FileTypesPath[resourceType]
|
---|
78 |
|
---|
79 | if not self.userFilesFolder: # no absolute path given (dangerous...)
|
---|
80 | self.userFilesFolder = mapServerPath(self.environ,
|
---|
81 | self.webUserFilesFolder)
|
---|
82 | # Ensure that the directory exists.
|
---|
83 | if not os.path.exists(self.userFilesFolder):
|
---|
84 | try:
|
---|
85 | self.createServerFolder( self.userFilesFolder )
|
---|
86 | except:
|
---|
87 | 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. ")
|
---|
88 |
|
---|
89 | # File upload doesn't have to return XML, so intercept here
|
---|
90 | if (command == "FileUpload"):
|
---|
91 | return self.uploadFile(resourceType, currentFolder)
|
---|
92 |
|
---|
93 | # Create Url
|
---|
94 | url = combinePaths( self.webUserFilesFolder, currentFolder )
|
---|
95 |
|
---|
96 | # Begin XML
|
---|
97 | s += self.createXmlHeader(command, resourceType, currentFolder, url)
|
---|
98 | # Execute the command
|
---|
99 | selector = {"GetFolders": self.getFolders,
|
---|
100 | "GetFoldersAndFiles": self.getFoldersAndFiles,
|
---|
101 | "CreateFolder": self.createFolder,
|
---|
102 | }
|
---|
103 | s += selector[command](resourceType, currentFolder)
|
---|
104 | s += self.createXmlFooter()
|
---|
105 | return s
|
---|
106 |
|
---|
107 | # Running from command line (plain old CGI)
|
---|
108 | if __name__ == '__main__':
|
---|
109 | try:
|
---|
110 | # Create a Connector Instance
|
---|
111 | conn = FCKeditorConnector()
|
---|
112 | data = conn.doResponse()
|
---|
113 | for header in conn.headers:
|
---|
114 | print '%s: %s' % header
|
---|
115 | print
|
---|
116 | print data
|
---|
117 | except:
|
---|
118 | print "Content-Type: text/plain"
|
---|
119 | print
|
---|
120 | import cgi
|
---|
121 | cgi.print_exception()
|
---|