Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
connector.FCKeditorConnector Class Reference
Inheritance diagram for connector.FCKeditorConnector:
Inheritance graph
[legend]
Collaboration diagram for connector.FCKeditorConnector:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def doResponse
def setHeader
def getFolders
def getFoldersAndFiles
def createFolder
def createServerFolder
def uploadFile
def setHttpHeaders
def createXmlHeader
def createXmlFooter
def sendError
def sendErrorNode
def sendUploadResults

Public Attributes

 userFilesFolder
 webUserFilesFolder
 request
 headers
 environ

Detailed Description

Definition at line 41 of file connector.py.


Member Function Documentation

def fckcommands.CreateFolderCommandMixin.createFolder (   self,
  resourceType,
  currentFolder 
) [inherited]
Purpose: command to create a new folder

Reimplemented in zope.FCKeditorConnectorZope.

Definition at line 88 of file fckcommands.py.

00088 
00089        def createFolder(self, resourceType, currentFolder):
00090               """
00091               Purpose: command to create a new folder
00092               """
00093               errorNo = 0; errorMsg ='';
00094               if self.request.has_key("NewFolderName"):
00095                      newFolder = self.request.get("NewFolderName", None)
00096                      newFolder = sanitizeFolderName (newFolder)
00097                      try:
00098                             newFolderPath = mapServerFolder(self.userFilesFolder, combinePaths(currentFolder, newFolder))
00099                             self.createServerFolder(newFolderPath)
00100                      except Exception, e:
00101                             errorMsg = str(e).decode('iso-8859-1').encode('utf-8') # warning with encodigns!!!
00102                             if hasattr(e,'errno'):
00103                                    if e.errno==17: #file already exists
00104                                           errorNo=0
00105                                    elif e.errno==13: # permission denied
00106                                           errorNo = 103
00107                                    elif e.errno==36 or e.errno==2 or e.errno==22: # filename too long / no such file / invalid name
00108                                           errorNo = 102
00109                             else:
00110                                    errorNo = 110
00111               else:
00112                      errorNo = 102
00113               return self.sendErrorNode ( errorNo, errorMsg )

Here is the call graph for this function:

def fckcommands.CreateFolderCommandMixin.createServerFolder (   self,
  folderPath 
) [inherited]

Definition at line 114 of file fckcommands.py.

00114 
00115        def createServerFolder(self, folderPath):
00116               "Purpose: physically creates a folder on the server"
00117               # No need to check if the parent exists, just create all hierachy
00118 
00119               try:
00120                      permissions = Config.ChmodOnFolderCreate
00121                      if not permissions:
00122                             os.makedirs(folderPath)
00123               except AttributeError: #ChmodOnFolderCreate undefined
00124                      permissions = 0755
00125 
00126               if permissions:
00127                      oldumask = os.umask(0)
00128                      os.makedirs(folderPath,mode=0755)
00129                      os.umask( oldumask )

Here is the caller graph for this function:

def fckoutput.BaseXmlMixin.createXmlFooter (   self) [inherited]

Definition at line 85 of file fckoutput.py.

00085 
00086        def createXmlFooter(self):
00087               "Purpose: returns the xml footer"
00088               return """</Connector>"""

def fckoutput.BaseXmlMixin.createXmlHeader (   self,
  command,
  resourceType,
  currentFolder,
  url 
) [inherited]

Definition at line 68 of file fckoutput.py.

00068 
00069        def createXmlHeader(self, command, resourceType, currentFolder, url):
00070               "Purpose: returns the xml header"
00071               self.setHttpHeaders()
00072               # Create the XML document header
00073               s =  """<?xml version="1.0" encoding="utf-8" ?>"""
00074               # Create the main connector node
00075               s += """<Connector command="%s" resourceType="%s">""" % (
00076                             command,
00077                             resourceType
00078                             )
00079               # Add the current folder node
00080               s += """<CurrentFolder path="%s" url="%s" />""" % (
00081                             convertToXmlAttribute(currentFolder),
00082                             convertToXmlAttribute(url),
00083                             )
00084               return s

Here is the call graph for this function:

Definition at line 43 of file connector.py.

00043 
00044        def doResponse(self):
00045               "Main function. Process the request, set headers and return a string as response."
00046               s = ""
00047               # Check if this connector is disabled
00048               if not(Config.Enabled):
00049                      return self.sendError(1, "This connector is disabled.  Please check the connector configurations in \"editor/filemanager/connectors/py/config.py\" and try again.")
00050               # Make sure we have valid inputs
00051               for key in ("Command","Type","CurrentFolder"):
00052                      if not self.request.has_key (key):
00053                             return
00054               # Get command, resource type and current folder
00055               command = self.request.get("Command")
00056               resourceType = self.request.get("Type")
00057               currentFolder = getCurrentFolder(self.request.get("CurrentFolder"))
00058               # Check for invalid paths
00059               if currentFolder is None:
00060                      if (command == "FileUpload"):
00061                             return self.sendUploadResults( errorNo = 102, customMsg = "" )
00062                      else:
00063                             return self.sendError(102, "")
00064 
00065               # Check if it is an allowed command
00066               if ( not command in Config.ConfigAllowedCommands ):
00067                      return self.sendError( 1, 'The %s command isn\'t allowed' % command )
00068 
00069               if ( not resourceType in Config.ConfigAllowedTypes  ):
00070                      return self.sendError( 1, 'Invalid type specified' )
00071 
00072               # Setup paths
00073               if command == "QuickUpload":
00074                      self.userFilesFolder = Config.QuickUploadAbsolutePath[resourceType]
00075                      self.webUserFilesFolder =  Config.QuickUploadPath[resourceType]
00076               else:
00077                      self.userFilesFolder = Config.FileTypesAbsolutePath[resourceType]
00078                      self.webUserFilesFolder = Config.FileTypesPath[resourceType]
00079 
00080               if not self.userFilesFolder: # no absolute path given (dangerous...)
00081                      self.userFilesFolder = mapServerPath(self.environ,
00082                                                                self.webUserFilesFolder)
00083               # Ensure that the directory exists.
00084               if not os.path.exists(self.userFilesFolder):
00085                      try:
00086                             self.createServerFolder( self.userFilesFolder )
00087                      except:
00088                             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. ")
00089 
00090               # File upload doesn't have to return XML, so intercept here
00091               if (command == "FileUpload"):
00092                      return self.uploadFile(resourceType, currentFolder)
00093 
00094               # Create Url
00095               url = combinePaths( self.webUserFilesFolder, currentFolder )
00096 
00097               # Begin XML
00098               s += self.createXmlHeader(command, resourceType, currentFolder, url)
00099               # Execute the command
00100               selector = {"GetFolders": self.getFolders,
00101                                    "GetFoldersAndFiles": self.getFoldersAndFiles,
00102                                    "CreateFolder": self.createFolder,
00103                                    }
00104               s += selector[command](resourceType, currentFolder)
00105               s += self.createXmlFooter()
00106               return s
00107 
# Running from command line (plain old CGI)

Here is the call graph for this function:

def fckcommands.GetFoldersCommandMixin.getFolders (   self,
  resourceType,
  currentFolder 
) [inherited]
Purpose: command to recieve a list of folders

Reimplemented in zope.FCKeditorConnectorZope.

Definition at line 40 of file fckcommands.py.

00040 
00041        def getFolders(self, resourceType, currentFolder):
00042               """
00043               Purpose: command to recieve a list of folders
00044               """
00045               # Map the virtual path to our local server
00046               serverPath = mapServerFolder(self.userFilesFolder,currentFolder)
00047               s = """<Folders>"""   # Open the folders node
00048               for someObject in os.listdir(serverPath):
00049                      someObjectPath = mapServerFolder(serverPath, someObject)
00050                      if os.path.isdir(someObjectPath):
00051                             s += """<Folder name="%s" />""" % (
00052                                           convertToXmlAttribute(someObject)
00053                                           )
00054               s += """</Folders>""" # Close the folders node
00055               return s

Here is the call graph for this function:

def fckcommands.GetFoldersAndFilesCommandMixin.getFoldersAndFiles (   self,
  resourceType,
  currentFolder 
) [inherited]
Purpose: command to recieve a list of folders and files

Definition at line 57 of file fckcommands.py.

00057 
00058        def getFoldersAndFiles(self, resourceType, currentFolder):
00059               """
00060               Purpose: command to recieve a list of folders and files
00061               """
00062               # Map the virtual path to our local server
00063               serverPath = mapServerFolder(self.userFilesFolder,currentFolder)
00064               # Open the folders / files node
00065               folders = """<Folders>"""
00066               files = """<Files>"""
00067               for someObject in os.listdir(serverPath):
00068                      someObjectPath = mapServerFolder(serverPath, someObject)
00069                      if os.path.isdir(someObjectPath):
00070                             folders += """<Folder name="%s" />""" % (
00071                                           convertToXmlAttribute(someObject)
00072                                           )
00073                      elif os.path.isfile(someObjectPath):
00074                             size = os.path.getsize(someObjectPath)
00075                             if size > 0:
00076                                    size = round(size/1024)
00077                                    if size < 1:
00078                                           size = 1
00079                             files += """<File name="%s" size="%d" />""" % (
00080                                           convertToXmlAttribute(someObject),
00081                                           size
00082                                           )
00083               # Close the folders / files node
00084               folders += """</Folders>"""
00085               files += """</Files>"""
00086               return folders + files

Here is the call graph for this function:

def fckoutput.BaseXmlMixin.sendError (   self,
  number,
  text 
) [inherited]

Definition at line 89 of file fckoutput.py.

00089 
00090        def sendError(self, number, text):
00091               "Purpose: in the event of an error, return an xml based error"
00092               self.setHttpHeaders()
00093               return ("""<?xml version="1.0" encoding="utf-8" ?>""" +
00094                             """<Connector>""" +
00095                             self.sendErrorNode (number, text) +
00096                             """</Connector>""" )

Here is the call graph for this function:

Here is the caller graph for this function:

def fckoutput.BaseXmlMixin.sendErrorNode (   self,
  number,
  text 
) [inherited]

Definition at line 97 of file fckoutput.py.

00097 
00098        def sendErrorNode(self, number, text):
00099               if number != 1:
00100                      return """<Error number="%s" />""" % (number)
00101               else:
00102                      return """<Error number="%s" text="%s" />""" % (number, convertToXmlAttribute(text))

Here is the call graph for this function:

Here is the caller graph for this function:

def fckoutput.BaseHtmlMixin.sendUploadResults (   self,
  errorNo = 0,
  fileUrl = '',
  fileName = '',
  customMsg = '' 
) [inherited]

Definition at line 104 of file fckoutput.py.

00104 
00105        def sendUploadResults( self, errorNo = 0, fileUrl = '', fileName = '', customMsg = '' ):
00106               self.setHttpHeaders("text/html")
00107               "This is the function that sends the results of the uploading process"
00108 
00109               "Minified version of the document.domain automatic fix script (#1919)."
00110               "The original script can be found at _dev/domain_fix_template.js"
00111               return """<script type="text/javascript">
00112                      (function(){var d=document.domain;while (true){try{var A=window.parent.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:\.|$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})();
00113 
00114                      window.parent.OnUploadCompleted(%(errorNumber)s,"%(fileUrl)s","%(fileName)s","%(customMsg)s");
00115                      </script>""" % {
00116                      'errorNumber': errorNo,
00117                      'fileUrl': fileUrl.replace ('"', '\\"'),
00118                      'fileName': fileName.replace ( '"', '\\"' ) ,
00119                      'customMsg': customMsg.replace ( '"', '\\"' ),
00120                      }

Here is the call graph for this function:

Here is the caller graph for this function:

def fckconnector.FCKeditorConnectorBase.setHeader (   self,
  key,
  value 
) [inherited]

Reimplemented in zope.FCKeditorConnectorZope.

Definition at line 49 of file fckconnector.py.

00049 
00050        def setHeader(self, key, value):
00051               self.headers.append ((key, value))
00052               return

Here is the caller graph for this function:

def fckoutput.BaseHttpMixin.setHttpHeaders (   self,
  content_type = 'text/xml' 
) [inherited]

Definition at line 50 of file fckoutput.py.

00050 
00051        def setHttpHeaders(self, content_type='text/xml'):
00052               "Purpose: to prepare the headers for the xml to return"
00053               # Prevent the browser from caching the result.
00054               # Date in the past
00055               self.setHeader('Expires','Mon, 26 Jul 1997 05:00:00 GMT')
00056               # always modified
00057               self.setHeader('Last-Modified',strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime()))
00058               # HTTP/1.1
00059               self.setHeader('Cache-Control','no-store, no-cache, must-revalidate')
00060               self.setHeader('Cache-Control','post-check=0, pre-check=0')
00061               # HTTP/1.0
00062               self.setHeader('Pragma','no-cache')
00063 
00064               # Set the response format.
00065               self.setHeader( 'Content-Type', content_type + '; charset=utf-8' )
00066               return

Here is the call graph for this function:

Here is the caller graph for this function:

def fckcommands.UploadFileCommandMixin.uploadFile (   self,
  resourceType,
  currentFolder 
) [inherited]
Purpose: command to upload files to server (same as FileUpload)

Definition at line 131 of file fckcommands.py.

00131 
00132        def uploadFile(self, resourceType, currentFolder):
00133               """
00134               Purpose: command to upload files to server (same as FileUpload)
00135               """
00136               errorNo = 0
00137               if self.request.has_key("NewFile"):
00138                      # newFile has all the contents we need
00139                      newFile = self.request.get("NewFile", "")
00140                      # Get the file name
00141                      newFileName = newFile.filename
00142                      newFileName = sanitizeFileName( newFileName )
00143                      newFileNameOnly = removeExtension(newFileName)
00144                      newFileExtension = getExtension(newFileName).lower()
00145                      allowedExtensions = Config.AllowedExtensions[resourceType]
00146                      deniedExtensions = Config.DeniedExtensions[resourceType]
00147 
00148                      if (allowedExtensions):
00149                             # Check for allowed
00150                             isAllowed = False
00151                             if (newFileExtension in allowedExtensions):
00152                                    isAllowed = True
00153                      elif (deniedExtensions):
00154                             # Check for denied
00155                             isAllowed = True
00156                             if (newFileExtension in deniedExtensions):
00157                                    isAllowed = False
00158                      else:
00159                             # No extension limitations
00160                             isAllowed = True
00161 
00162                      if (isAllowed):
00163                             # Upload to operating system
00164                             # Map the virtual path to the local server path
00165                             currentFolderPath = mapServerFolder(self.userFilesFolder, currentFolder)
00166                             i = 0
00167                             while (True):
00168                                    newFilePath = os.path.join (currentFolderPath,newFileName)
00169                                    if os.path.exists(newFilePath):
00170                                           i += 1
00171                                           newFileName = "%s(%d).%s" % (
00172                                                         newFileNameOnly, i, newFileExtension
00173                                                         )
00174                                           errorNo= 201 # file renamed
00175                                    else:
00176                                           # Read file contents and write to the desired path (similar to php's move_uploaded_file)
00177                                           fout = file(newFilePath, 'wb')
00178                                           while (True):
00179                                                  chunk = newFile.file.read(100000)
00180                                                  if not chunk: break
00181                                                  fout.write (chunk)
00182                                           fout.close()
00183 
00184                                           if os.path.exists ( newFilePath ):
00185                                                  doChmod = False
00186                                                  try:
00187                                                         doChmod = Config.ChmodOnUpload
00188                                                         permissions = Config.ChmodOnUpload
00189                                                  except AttributeError: #ChmodOnUpload undefined
00190                                                         doChmod = True
00191                                                         permissions = 0755
00192                                                  if ( doChmod ):
00193                                                         oldumask = os.umask(0)
00194                                                         os.chmod( newFilePath, permissions )
00195                                                         os.umask( oldumask )
00196 
00197                                           newFileUrl = combinePaths(self.webUserFilesFolder, currentFolder) + newFileName
00198 
00199                                           return self.sendUploadResults( errorNo , newFileUrl, newFileName )
00200                      else:
00201                             return self.sendUploadResults( errorNo = 202, customMsg = "" )
00202               else:
00203                      return self.sendUploadResults( errorNo = 202, customMsg = "No File" )

Here is the call graph for this function:


Member Data Documentation

Definition at line 43 of file fckconnector.py.

Definition at line 41 of file fckconnector.py.

Reimplemented in zope.FCKeditorConnectorZope.

Definition at line 40 of file fckconnector.py.

Definition at line 73 of file connector.py.

Definition at line 74 of file connector.py.


The documentation for this class was generated from the following file: