Skip to Content
Technical Articles
Author's profile photo Ariel Bravo Ayala

Exploring CPI’s filesystem’s content

While I was doing more in-depth research on how CPI works, I became curious about the content of its own filesystem. In this post, I’ll tell you a little about its content and how you can explore it yourself.

One of the peculiarities of CPI, is that it is very flexible when it comes to establishing an HTTP communication. In this way, it is possible to imitate a web server by modifying some headers and the body of an “exchange”. Ultimately, a web server mainly serves GETs and POSTs requests. Using this technique, and including a couple of lines of groovy script, you can create a file explorer emulator. Logically, due to access privileges, it is not possible to browse all directories. Still, it is possible to get very interesting information and files of CPI. A lot of low hanging fruits.

As a word of warning, check first that you are not breaking any rules and keep in mind that there could be risks involved. I cannot be held responsible for how you use the information offered in this post. Also, beware that the explorer I am presenting is basic, rustic and buggy. Feel free to improve it and share your snippets. 🙂

Creating the Iflow

Short way: you can download the example from this url.
Normal way: we need to create a very simple iflow, with two independent communication channels and running groovy scripts. One channel will be in charge of reviewing the contents of the directories and the other will be responsible for downloading the files.
In my own iflow I have used the following configurations:

Iflow

Channels

Script

import com.sap.gateway.ip.core.customdev.util.Message
import java.util.HashMap

def Message browse(Message message) {
    def mapHeaders = message.getHeaders()
    
    String mainDir = mapHeaders.get("CamelHttpPath") 
    String mainUrl = mapHeaders.get("CamelHttpUrl") 
    String mainSrv = mapHeaders.get("CamelServletContextPath")
    String srvUrl  = mainUrl.minus(mainDir)
    String urlDown = srvUrl.minus(mainSrv)+"/amba/cpifilesystemdownload"
    
    File dir = new File(mainDir)
    StringBuilder strBuilder = new StringBuilder()
    strBuilder << '<meta charset="UTF-8"></br>'
    if (dir.parent != null){strBuilder << "<a href='${srvUrl}${dir.parent}'>&#x1F4C1 ..</a></br>"}
    dir.eachDir {strBuilder << "<a href='${mainUrl}/${it.name}'>&#x1F4C1 ${it.name}</a></br>"}
    dir.eachFile {if (it.isFile()) {strBuilder << "<a href='${urlDown}/${mainDir}/${it.name}'>${it.name}</a></br>" }}
    message.setBody(strBuilder.toString())
    
    mapHeaders = ['content-type':'text/html']
    message.setHeaders(mapHeaders)
    return message
}

def Message download(Message message) {
    def mapHeaders = message.getHeaders()
    
    String filePath = mapHeaders.get("CamelHttpPath") 
    StringBuilder strBuilder = new StringBuilder()
    
    File file = new File(filePath);byte[] fileContent = file.bytes
    strBuilder << fileContent.encodeBase64().toString()    
    message.setBody(strBuilder.toString());
    
    mapHeaders = ['Content-Transfer-Encoding':'base64',
                  'Content-Disposition':'attachment; filename=${file.getName()}']
                  
                  
    return message
}

What directories can you explore?

It’s hard to give an answer, as I haven’t found a way to get available folders to explore. However, by analysing CPÃŽ’s environment variables, I have found the following directories with interesting information. Please, share your findings!

Folder Comments
/usr/sap/ljs/ CPI’s home?
/usr/lib/jvm SAP’s Java Virtual Machine
/usr/sap/ljs/configuration OSGI configuration area
/usr/sap/ljs/configuration/org.eclipse.osgi/bundles  Iflows Contents
/usr/sap/ljs/plugins CPI’s jar files
/tmp Standard Linux temporary folder
/proc       ? (not ‘real’ files) Process Information

 

How to use

Once you load the iflow, copy the endpoint that will give you the channel that scans the directories. Paste that address into your internet browser. At the end of the url, include the folder you want to explore. (Not all routes can be explored as already mentioned)

Example:

 

Please share your findings!

 

Ariel Bravo Ayala

 

Assigned Tags

      17 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Daniel Graversen
      Daniel Graversen

      That is pretty cool and useful. You can even find the error logs that way.

      Just a small modification to make it a little easier to navigate so you can get a table view and get size and last modified of the files.

      import java.text.SimpleDateFormat
      
      // and then this method. 
        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
          File dir = new File(mainDir)
          StringBuilder strBuilder = new StringBuilder()
          strBuilder << '<meta charset="UTF-8"></br><table>'
          if (dir.parent != null){strBuilder << "<tr><td><a href='${srvUrl}${dir.parent}'>&#x1F4C1 ..</a></br></td></tr>"}
          dir.eachDir {strBuilder << "<tr><td><a href='${mainUrl}/${it.name}'>&#x1F4C1 ${it.name}</a></td></tr>"}
          dir.eachFile {if (it.isFile()) {strBuilder << "<tr><td><a href='${urlDown}/${mainDir}/${it.name}'>${it.name}</a></td><td> ${it.length()}</td><td> ${sdf.format(new java.util.Date(it.lastModified()))}</td></tr>" }}
          message.setBody(strBuilder.toString())
      Author's profile photo Ariel Bravo Ayala
      Ariel Bravo Ayala
      Blog Post Author

      You can find many things. Even some leftovers from the SAP developers :-S

      Have you find something useful for daily usage?

      Thanks for the snippet improvement!

       

      Ariel

      Author's profile photo Srinivas Sistu
      Srinivas Sistu

      Really useful and great stuff... Thank you for sharing..

       

      Regards,

      Srinivas

      Author's profile photo Ariel Bravo Ayala
      Ariel Bravo Ayala
      Blog Post Author

      You are welcome!

       

      Author's profile photo Siva Naga Ravi Tejs Bommidala
      Siva Naga Ravi Tejs Bommidala

      Thanks for Sharing this!! , Its Really Helpful.

       

      Thanks

      --Siva

      Author's profile photo Ariel Bravo Ayala
      Ariel Bravo Ayala
      Blog Post Author

      You are welcome Siva!

       

      Author's profile photo Rajath Kodandaramu
      Rajath Kodandaramu

      Hello Guys,

       

      Great stuff.

      Please share if you found anymore useful folders which we can use.

       

       

      Regards,

      Rajath Kodandaramu

      Author's profile photo Richard Kleibl
      Richard Kleibl

      Hello,

       

      very nice blog! Thanks for sharing this.

       

      kind regards

      Author's profile photo Balaji Vemugadda
      Balaji Vemugadda

      I am getting the following error

       

      An internal server error occured: java.io.FileNotFoundException: /opt/karaf/*@ line 34 in script1.groovy.
      The MPL ID for the failed message is : AF4w4-UkDJKVIUIm7TF6QTNhMje4
      For more details please check tail log.
      
      
      
      i am accessing in browser https://<cpihost>/http/amba/cpifilesystem/*
      
      error in groovy at line  "dir.eachDir {strBuilder << "<a href='${mainUrl}/${it.name}'>&#x1F4C1 ${it.name}</a></br>"}"
      
      please let me know how to fix?
      Author's profile photo Stephen Xue
      Stephen Xue

      Hi Balaji

      try http/amba/cpifilesystem//usr/sap/ljs

      Author's profile photo Anirban Mallick
      Anirban Mallick

      I’m also on the same boat as Balaji…I downloaded and deployed the iFlow straight from Github. 

      Ariel Bravo Ayala – do you have any suggestions please?

      Thanks,

      Anirban

      Author's profile photo Ariel Bravo Ayala
      Ariel Bravo Ayala
      Blog Post Author

      What url are you using?

      Br, Ariel

      Author's profile photo Xin Zheng
      Xin Zheng

      Can’t find /usr/ SAP/LJS /plugins, can you send relevant JAR package, com.sap.script.customs-development liuw@sbtjt.com

       

      Author's profile photo Matthew Walker
      Matthew Walker

      Hi, is this method still supported? I have downloaded the iFlow but am receiving the error message "com.sap.it.rt.adapter.http.api.exception.HttpResponseException: An internal server error occured: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.processData() is applicable for argument types: (com.sap.gateway.ip.core.customdev.processor.MessageImpl) values: [com.sap.gateway.ip.core.customdev.processor.MessageImpl@48ec27a4]. The MPL ID for the failed message is : AGCr_MIXzDkzgJWbd5pNvNnhK3_V For more details please check tail log." when accessing the URL at ,<tenant>/http/amba/cpifilesystem//usr/sap/ljs.

       

      I would like to be able to access some of the information (i.e. CPU, memory, disk space, etc.) that this claims to provide, but so far have not been able to.

      Thanks

      Author's profile photo Ariel Bravo Ayala
      Ariel Bravo Ayala
      Blog Post Author

      Hi Matt,

      I wrote this long ago, I am not sure if this is still valid. If so, a few points to consider:

      1.- The snippet implements the functions "browse" and "download". Your error implies you haven't changed the function names in the Groovy Script steps. (The default is processData)

      2.- This works(ed) in Neo. I did not test this in CF.

      3.- If your goal is to access the information like CPU, memory, etc, you have other alternatives, like using the operation APIs. This explorer will give you the info of the worker node that executes the request exclusively, but your tenant is likely to have multiple worker/management nodes.

      The operations APIs you could use are:
      https://{{{operationsURL}}}/com.sap.it.op.srv.commands.dashboard.ParticipantListCommand (Basic info of your account)
      https://{{{operationsURL}}}/com.sap.it.nm.commands.node.GetNodesCommand (Get the node IDs)
      https://{{{operationsURL}}}/com.sap.it.op.srv.commands.dashboard.NodeProcessStatisticCommand (Get the statistics of the nodes)

      I hope this helps.

      Ariel

       

      Author's profile photo Matthew Walker
      Matthew Walker

      Hi Ariel,

       

      Thank you for your response. You were exactly right with your diagnosis of the error. Once I added the script function it seems to be working as you showed in your original post. I'll also check out a blog post I see from you on the operations APIs to get more info on those. Thanks so much for your help and this great information!

       

      Best Regards,

      Matthew

      Author's profile photo Manish Kumar
      Manish Kumar

      Hello,

      It seems that for this iFlow to work in Cloud Foundry CPI we need to adjust the URL and script.

      The issue is that URL should not contain "//"

      1. Change the HTTP connections address and remove the '/' in end:
        • /amba/cpifilesystem*
        • /amba/cpifilesystemdownload*
      2. Change groovy script @ line 19
        • message.setBody(strBuilder.toString().replaceAll("//","/"))

      After this deploy and open like

      • Root directory: <host>/http/amba/cpifilesystem/
      • CPI app directory: <host>/http/amba/cpifilesystem/app