Posting Event

Support area for phpBB's mChat extension
Post Reply
Selune
Posts: 6
Joined: 17 Mar 2018, 10:16

Posting Event

#1

Post by Selune » 25 Jun 2018, 13:57

Hello.

I need to exec() a shell script each time a new post or topic is triggered in a specific forum section (I mean a forum and its sub-forums). This shell script will need to get 2 parameters : the post/topic title and its author name.

I tried this in events/main_listener.php :

Code: Select all

    124         public function insert_posting($event)
    125         {
    126                 $this->mchat->insert_posting($event['mode'], $event['data']['forum_id'], $event['data']['post_id']);
    127                 exec(broadcast.sh);
    128         }
But it doesn't seem to do it.
Anyone could help me please ?

Regards,
Selune

User avatar
kasimi
mChat developer
Posts: 710
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: Posting Event

#2

Post by kasimi » 25 Jun 2018, 16:30

:wave:

Using a relative path won't work. Move the script file to your board's root and try this:

Code: Select all

global $phpbb_root_path;
exec($phpbb_root_path . 'broadcast.sh');

Selune
Posts: 6
Joined: 17 Mar 2018, 10:16

Re: Posting Event

#3

Post by Selune » 26 Jun 2018, 15:33

I'm not sure I'm in the right function nor even in the right file, in order to do what I'd like to do ...
And I don't know how to get the needed values to pass as shell command parameters (post title and username)
Did you ever meet such a request before ? I didn't find any similar in this forum.

Added in 4 minutes 28 seconds:
Anyway actually it doesn't work (the exec() is never executed)

User avatar
kasimi
mChat developer
Posts: 710
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: Posting Event

#4

Post by kasimi » 26 Jun 2018, 15:50

Are you sure your PHP environment is actually configured and allowed to use the exec() function? Does echo exec('date'); work?

As for passing arguments, you could do it like this:

Code: Select all

$username = escapeshellarg($event['username']);
$subject = escapeshellarg($event['subject']);
exec("script.sh $username $subject");

Selune
Posts: 6
Joined: 17 Mar 2018, 10:16

Re: Posting Event

#5

Post by Selune » 26 Jun 2018, 17:11

Yes the echo date() does work fine, but not the call for my .sh file. I’m wondering if it could be due to an hidden fork or in a network limitation (different port as apache server for example)

I let you know.

Selune
Posts: 6
Joined: 17 Mar 2018, 10:16

Re: Posting Event

#6

Post by Selune » 27 Jun 2018, 03:12

Okay it seems to work now with this code :

Code: Select all

public function insert_posting($event)
{
if ($event['data']['forum_id']==31){
global $phpbb_root_path;
$username = escapeshellarg($event['username']);
$subject = escapeshellarg($event['subject']);
exec($phpbb_root_path."broadcast.sh $username $subject 2>&1 1>/dev/null");
}
$this->mchat->insert_posting($event['mode'], $event['data']['forum_id'], $event['data']['post_id']
}
Thank you so much !

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests