render the output of a script to a concrete5 block

Permalink 3 users found helpful
Do you know of a block that will render the output of a script, as near real time as possible (similar to a tail -f in linux)

I have an cron that runs a python script and would like to render the output on a concrete5 block.

 
goutnet replied on at Permalink Reply
Short answer :

Well, I doubt you could find any block that would fit as it would create quite a big security issue by doing so.

In detail :

- First of all, such a block would get rejected by the Peer Review Board (PRB), and could not be sent to the marketplace. Check out the video athttp://www.concrete5.org/developers/marketplace-submission-rules/... for more explainations (relevant part starts at 9'32 about forbidden functions).

That said, there is a good reason for not allowing a block to call an external command, if the PRB would let such a function being used, a block could do almost anything onto a website (including, but not limited to hijacking some page, or other really bad things).

Now, if you really, *really* want to do so, you might find somebody able to develop that for you, but you will then have to install the block/package by hand, (in that case, contact me I might find some time to do that).

You might want to consider other approaches, such as writting the output of the script into a php file somewhere within the site, and just include that content. If it is about nearly real time, you can also run that script from within cron every 1 min or so (if possible). There might be other approaches, but at least that one will greatly limit the security risk.
navteca replied on at Permalink Reply
The approach I am taking is the python script creates a log file (flat file). That log file is getting written often.
Do you think it would be a security problem to continously read and render a log file in php? it seems to me that this is pretty standard, reading the content of a file, a mysql database, a url, should all be within the security compliance.

Best regards

Ramon

PS: i am not talking about php executing shell commands.
goutnet replied on at Permalink Reply
Well yeah, in that case, that should be pretty straightforward.

I don’t know any block that could do that currently though... I'll see what I can do.

(sounds like an easy block to start with :) )
JohntheFish replied on at Permalink Reply
JohntheFish
It should be possible to adapt my quick log view block to do this, especially the blocks by ajax version of the block (to periodically ajax update the display)
goutnet replied on at Permalink Reply
Actually, I am almost done with this block. Just trying to figure out why concrete5 is rendering the whole template when using this code instead of just calling the responder :

$btId = $this->getBlockObject()->getBlockId();
$action = $this->action( 'on_file_refresh' );
?>
<script type="text/javascript">
$(document).ready( function() {
   // Is this still necessary with IE ? :
   $.ajaxSetup({ cache: false });
   setInterval( function() {
   $("#file_render_<?=$btId?>").load("<?=$action?>");
   }, <?=$refresh?>);
});
</script>


the code of the action is

public function printFile()
   {
      $filename = $this->get('filename');
      if ( !file_exists( $filename ) )
      {
         echo t("File not found ") . $filename;
         return;
      }
      if ( !is_readable( $filename ) )
      {
         echo t("Access denied to " ). $filename;
         return;
      }
      echo '<pre class="file_render">';
      echo file_get_contents( $filename );


Opening the link generated by $action displays only the action (not the complete page), but refreshing via javascript include everything ... O_O


Any idea ?
goutnet replied on at Permalink Reply
argl !! found it, stupid me !

need to html_entity_decode the action ....

/me slaps himself ...
navteca replied on at Permalink Reply
i have been looking at your block by ajax product.

Pretty cool, i think it is going to be a must for any of the portals i am doing.

Thanks
navteca replied on at Permalink Reply
I imagine it is not as easy as changing the dashboard/reports/logs/ for the location of my logs, right?


Ramon

Any tips on how will you customize it?

I have a demo on Wednesday
navteca replied on at Permalink Reply
I was referring to the quick log view, is it as easy as changing the path to the location
JohntheFish replied on at Permalink Reply
JohntheFish
Quick log view reads log report entries from the database. You would need to change that to read lines from a file.

As a quicker and probably better targeted solution, maybe @goutnet could provide you with a beta copy of his block.
goutnet replied on at Permalink Reply
I just submitted a package containing a block that does what you need.

As soon as it is (if it is ?) approuved by the PRB, it will be available for free under the handle "file_reader".

http://www.concrete5.org/marketplace/addons/file-reader/...

stay tuned.
navteca replied on at Permalink Reply
Thanks, Ill be willing to pay for it once is ready.
How long does it takes to get approved?
goutnet replied on at Permalink Reply
You won’t have to :) (although if you need some more specific stuff, I might create an non-free "advanced" version).

Well, PRB can be pretty quick, I think a few days should be enough.
goutnet replied on at Permalink Reply 1 Attachment
some PRB members already reviewed the addon, and made me improve the code to the extent I can now safely hand a beta version to you.

I attach the package to this post if you need it fast, it is not yet available on the market, but it shall be soon (I hope).

to install it manually, uncompress the zip in your packages directory, then activate the package in "Extend concret5" dashboard menu.
navteca replied on at Permalink Reply
excellent, thank you i will check it out.
goutnet replied on at Permalink Reply
Just to notify you that the addon had been officially approuved by concrete5 :

http://www.concrete5.org/marketplace/addons/file-reader/...
BillHeintz replied on at Permalink Reply
BillHeintz
Is there currently a way to do this on Version 7 and Above?
JohntheFish replied on at Permalink Reply
JohntheFish
My Universal Content Puller may be of use for applications such as this.
https://c5magic.co.uk/addons/universal-content-puller...

Have a look through the documentation and some of the examples and see if that fits with your requirement.

You would probably want to configure your host script to write the tail you want to display to a fixed file location, then use UCP to pull the file and display it.
If the host script is making database enquiries, you could also use UCP to go straight to the database being queried.