1
sceilig
How to allow a cron job to access a xoops module?
  • 2006/6/22 0:41

  • sceilig

  • Just popping in

  • Posts: 53

  • Since: 2006/3/1 1


I want to setup a cron job to execute a script within a XOOPS module on a daily basis - and that module is set up to only have administration access. Is this possible? How do I go about authenticating the cron job so that XOOPS allows it to execute the script?

2
brash
Re: How to allow a cron job to access a xoops module?
  • 2006/6/22 1:21

  • brash

  • Friend of XOOPS

  • Posts: 2206

  • Since: 2003/4/10


Possibly via WGET, or even the PHP cli.
IT Headquarters
Innovative IT Solutions

3
sceilig
Re: How to allow a cron job to access a xoops module?
  • 2006/6/22 2:05

  • sceilig

  • Just popping in

  • Posts: 53

  • Since: 2006/3/1 1


Accessing the php script in a cron job is fine - its just authentication I think i would have the problem with.
e.g.
a cron job to access
http://www.domainname.com/modules/modname/admin/index.php?op=runcron

would just redirect to the XOOPS login page - just as what would happen to a guest user visiting that page since it is only allowed access by XOOPS administrators.

4
ghettonet
Re: How to allow a cron job to access a xoops module?
  • 2006/6/22 3:18

  • ghettonet

  • Not too shy to talk

  • Posts: 176

  • Since: 2005/12/4


hm, but running the php script just as an absolute path with the php bin (****crontab stuff php /home/user/public_html/script.php) shouldn't require authentication should it? If it does I don't know what i'm talking about so ignore me.

5
sceilig
Re: How to allow a cron job to access a xoops module?
  • 2006/6/27 10:43

  • sceilig

  • Just popping in

  • Posts: 53

  • Since: 2006/3/1 1


I did manage to answer my own question. In case anyone else might be looking to perform the same task, this can be done using cURL.

First you use curl to post login credentials to XOOPS and then you can access the module function that requires administrator access.

e.g.
$url "http://www.domainname.com/user.php";
$login_data 
    
"op=login"
    
."&uname=admin"
    
."&pass=password";
$user_agent "php" phpversion();

$ch curl_init($url);    // initialize curl handle
curl_setopt($chCURLOPT_RETURNTRANSFER1);
curl_setopt($chCURLOPT_VERBOSE1);
curl_setopt($chCURLOPT_USERAGENT$user_agent);
curl_setopt($chCURLOPT_COOKIEJAR"curl_cookies");
curl_setopt($chCURLOPT_COOKIEFILE"curl_cookies"); // file where the cookies will be stored
curl_setopt($chCURLOPT_POSTFIELDS$login_data); 
$result curl_exec($ch); // run the whole process

// you should now be logged in 

// now access the admin only page
$url2 "http://www.domainname.com/modules/modulename/admin/index.php?op=process_admin_function";
curl_setopt($chCURLOPT_URL$url2);
$result curl_exec($ch);
echo 
$result// $result contains the page contents which you can parse for the success or error message you are looking for

//close cURL connection
curl_close($ch);

Login

Who's Online

297 user(s) are online (268 user(s) are browsing Support Forums)


Members: 0


Guests: 297


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits