Jump to content

Action hook question


jpkelly

Recommended Posts

I am creating an action hook for module create. I have the hook triggering but I am unsure how to get values from $vars. The values I want are the username and the domain. Will you tell me the proper way to get these elements from $vars?

Here is my hook code:

 

<?php

function actionhook_AfterModuleCreate($vars) {

$domain = $vars["domain"];
$username = $vars["username"];

$to = 'jp@jpkvideo.com';
$subject = 'the vars';
$message = 'Domain = '.$domain.' Username = '.$username;
$headers = 'From: support@smallgod.net' . "\r\n" .
'Reply-To: support@smallgod.net' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}

add_hook("AfterModuleCreate",0,"actionhook_AfterModuleCreate","");
?>

 

Also, I want this hook to run a shell script. I have added the script to sudoers so it can be executed by php and I have tested it by putting the following code in a php page:

 

$domain = "vcrit.com";
$user = "vcritcom";
$output = shell_exec('/usr/bin/sudo /usr/local/bin/suexenable '.$domain.' '.$user);

 

This works the way I expect when I load the php page.

 

When I add the same code to the hook, it does not work. What user does the hook get run as? apache?

Any ideas why it would not work when run as hook code?

Link to comment
Share on other sites

The vars inside $vars for domain & username are: username & domain.. but they're inside the params array. Eg:

 

$username = $vars["params"]["username"];
$domain = $vars["params"]["domain"];

That will sort that part for you.

 

Next part, if you've added that file to the sudoers, it will run as that file, but if it's being included, which it is (It's a hook) then it wil run as the file including it... eg. In my dev system running 4.4.1 this is: /admin/clientshosting.php when creating the module manually from the admin area.

 

And in the front end, completely different. Add this code to your hook to determine the location to add to sudoers:

 

echo $_SERVER["SCRIPT_NAME"];

 

Correct me if I'm wrong... That's if adding /includes/hooks/hook_file.php to sudoers doen't work.

 

If the code is able to execute via PHP in your test file, it should be running as the same user while running code for WHMCS.

 

Hope this helps you out :)

Link to comment
Share on other sites

Thanks for straightening me out on the $vars array syntax. That worked!

 

As far as the shell_exec() command, it works fine when I run it in my own .php file but does nothing when run within the hook file.

I have tried adding the hook file and the parent file which includes the hook (clientshosting.php) to sudoers but that did not help. I have even tried running /bin/touch from the hook but nothing happens.

 

Putting echo $_SERVER["/usr/local/bin/suexenable"]; in my .php file or the hook file produces nothing.

 

I really appreciate the help.

Any ideas?

Link to comment
Share on other sites

Ok so I figured it out. I had php safe_mode off in my php.ini but for some reason when running via https, safe_mode was on (running via http, safe_mode was off). It turns out I had the safe mode on check box ticked in Plesk (duh). Not sure how it only affected https, but whatever, it works now. Thanks for your help!

Edited by jpkelly
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated