how to use other libraries in the php sandbox or php class?

77 views
Skip to first unread message

Pedro Ponte

unread,
Nov 15, 2021, 5:55:40 PM11/15/21
to Fusio
Is is possible to use other PHP functions such as openssl_decrypt in php classes?
What and how would I import that into the php file? TIA

Christoph Kappestein

unread,
Nov 16, 2021, 2:13:35 PM11/16/21
to Fusio
Hi Pedro,

yes you can simply use those functions since in action is also a normal PHP class. If you use the PHP-Sandbox action we have a security manager which allows you to use only specific functions and classes in a white list s.

This is for security reason since if a malicious user gains access to the backend we dont want that such a user can compromise the complete server.

best regards
Christoph

Pedro Ponte

unread,
Nov 16, 2021, 3:13:11 PM11/16/21
to Christoph Kappestein, Fusio
Thank you very much.
 
Please see images below with the steps I’ve taken (and propose to create a video for).
Would you be able to give me some pointers on what I might be doing wrong?
 
Action Empacota load products
 
 
 
file location
 
file contents
 
 
designer run
 
action designer console output
 
Thank you!
 
 
 
--
You received this message because you are subscribed to a topic in the Google Groups "Fusio" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fusio/mbaCGCIV2QQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fusio+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fusio/71ef5378-025b-4d94-b550-5552be68b894n%40googlegroups.com.

Pedro Ponte

unread,
Nov 16, 2021, 3:29:23 PM11/16/21
to Pedro Ponte, Christoph Kappestein, Fusio
update, I have changed the code to the following
 
 
 

Christoph Kappestein

unread,
Nov 16, 2021, 3:34:56 PM11/16/21
to Fusio
Hey,

ok, so from the first look the namespace of your action should match the folder path so it should be "App\Action\Empacota"
If you create a class in the src/ folder you can then simply use this class directly as action by clicking on the right edit button
at the action dropdown, there you can then enter the complete class name "App\Action\Empacota\LoadProducts".

If you use the PhpProcessor you can simply write a simple PHP file without a class which contains the action code.

Regarding the file_get_contents API call in your class, you could also create a HTTP connection where you configure the base url and then you can
use this connection in your action to make the HTTP call. The connection returns then a configured instance of Guzzle s. https://docs.guzzlephp.org/en/stable/

best regards
Christoph

Pedro Ponte

unread,
Nov 16, 2021, 5:47:27 PM11/16/21
to Christoph Kappestein, Fusio
Many thanks, very useful!
 
If you use the PhpProcessor you can simply write a simple PHP file without a class which contains the action code."
How can I specify the path to the php file directly?
 
 

Christoph Kappestein

unread,
Nov 20, 2021, 5:51:18 AM11/20/21
to Fusio
If you specify the path directly, you need to use the complete path from the root including src/ if you use the class then we use the composer autoloader
to automatically resolve the fitting file for a class s.

action_edit.png

best regards
Christoph

Pedro Ponte

unread,
Nov 23, 2021, 8:53:56 AM11/23/21
to Christoph Kappestein, Fusio
Can you provide an example please?
 
I have tried 
 
/src/App/Action/Headwind/Encrypt.php
 
\src\App\Action\Headwind\Encrypt.php
 
with and without php.
 
TIA
 
 
 

Pedro Ponte

unread,
Nov 25, 2021, 4:56:23 PM11/25/21
to Fusio
Any update please :) ?

Christoph Kappestein

unread,
Nov 25, 2021, 5:00:04 PM11/25/21
to Fusio
Hey, could you show me the content of the "/src/App/Action/Headwind/Encrypt.php" action, Iam currently not sure whether you have
created a PHP Class as action or a simple PHP file which can be used by the PHP-Processor

Pedro Ponte

unread,
Nov 25, 2021, 5:36:28 PM11/25/21
to Fusio
Simple php file. TIA

<?php
try {
    return $response->build(201, [], [
                'success' => false,
                'message' =>  "ok",
            ]);
    
} //end try
catch(Exception $e){
    return $response->build(500, [], [ //return server error
        'success' => false,
        //'message' => $responseMsg.$decryptedMessage
        'message' => $e->getMessage()
    ]);
}


Christoph Kappestein

unread,
Nov 25, 2021, 5:55:44 PM11/25/21
to Fusio
ok, then you could try to use "../src/App/Action/Headwind/Encrypt.php"
as path, since the path is relative to the public folder.

Pedro Ponte

unread,
Nov 25, 2021, 6:19:53 PM11/25/21
to Fusio
Can't seem to get it to work :(

Pics enclosed with errors listed in console.

Is the path with commas? TIA
Screenshot 2021-11-25 at 23.18.17.png
Screenshot 2021-11-25 at 23.18.31.png

Christoph Kappestein

unread,
Nov 26, 2021, 2:32:01 PM11/26/21
to Fusio
could you use an absolute path to the file on your machine, then we could ensure that we load the correct file but maybe there is also a syntax error in your file?
Could you check your PHP error logs for more error details.

Reply all
Reply to author
Forward
0 new messages