Post by Jsf » Sun Jan 26, 2014 4:29 am

Hello,
I need to Schedule admin module function, so trying to login with curl, but without success.

I want to set up cron job to:
http://www.example.com/admin/index.php? ... nctionname

But can't, because need to login... Maybe someone have a solution how to do this?

/*
My personal OpenCart modules list
*/


User avatar
Jsf
New member

Posts

Joined
Sun Jan 26, 2014 4:08 am

Post by billynoah » Sun Jan 26, 2014 4:39 am

assuming it's a database related task, why not just write the cron script to execute the query directly to the mysql server?

Image


User avatar
Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by billynoah » Sun Jan 26, 2014 4:43 am

not sure if this would be helpful but here's another thread where we discussed a cron job to auto update specials end date: http://forum.opencart.com/viewtopic.php?f=20&t=116126

all you really need to do is form your query and you should be able to do pretty much anything.

Image


User avatar
Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by Jsf » Sun Jan 26, 2014 6:31 am

billynoah wrote:assuming it's a database related task, why not just write the cron script to execute the query directly to the mysql server?
Yes, but also need execute the function manually from admin and I need quite a few things already written in admin models files, so I do not want write function in admin and do the same similar job with queries directly to mysql...

I found only this solution: http://opencart.hostjars.com/blog/16 , but it is old and not safe enough :(

/*
My personal OpenCart modules list
*/


User avatar
Jsf
New member

Posts

Joined
Sun Jan 26, 2014 4:08 am

Post by billynoah » Sun Jan 26, 2014 8:20 am

you could easily write some code in your module to execute the bash script and have it available in the admin as well.

also, sounds like the link you gave is compatible with 1.5.. might need a few tweaks but i'm sure you could get it working if you know your way around the framework.

Image


User avatar
Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

User avatar
Active Member

Posts

Joined
Sun May 22, 2011 12:54 pm

Post by Jsf » Sun Jan 26, 2014 4:47 pm

nvedia wrote:This can help
You can first login to admin and then invoke your actions
http://blog.andyhunt.info/2011/12/21/us ... a-website/
I try this example, but also without success. I get blank page or echo just "1"... I think I need to add &token=xxx to URL, but how to get token value after login?

/*
My personal OpenCart modules list
*/


User avatar
Jsf
New member

Posts

Joined
Sun Jan 26, 2014 4:08 am

Post by MarketInSG » Sun Jan 26, 2014 7:18 pm

You cannot use curl to get to your admin page. The admin page requires the session token and the user to be logined. The easiest way is to move it to your front end, and adding a secret key which only your system knows.


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by nvedia » Sun Jan 26, 2014 9:45 pm

Another option is to use an automation script like php selenium webdriver to get to admin page and perform your actions

Donate here to show support if you think I have helped you today!

Opencart Documentation


User avatar
Active Member

Posts

Joined
Sun May 22, 2011 12:54 pm

Post by Tania201 » Sun Feb 16, 2014 3:43 pm

Try Webcron Service EasyCron.com, use the "Cookie Support" feature.

Newbie

Posts

Joined
Tue Jan 14, 2014 9:55 pm

Post by olgri » Wed Jul 02, 2014 5:07 pm

MarketInSG wrote:You cannot use curl to get to your admin page. The admin page requires the session token and the user to be logined.
You CAN use curl to get to OC admin area. You just have to pass $_SESSION over with the curl call. I.e.:

Code: Select all

session_start();
$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
session_write_close();

//create cURL connection
$curl_connection = curl_init('http://yourdomainname.com/admin/index.php?route=common/login');

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_COOKIE, $strCookie );

//create array of data to be posted
$post_data['username'] = 'yourusername';
$post_data['password'] = 'yourpassword';

//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);

//show information regarding the request
//print_r(curl_getinfo($curl_connection));
//echo curl_errno($curl_connection) . '-' . curl_error($curl_connection); 

//close the connection
curl_close($curl_connection);
Source:
http://nz1.php.net/curl_setopt#87112
and
http://thehungrycoder.com/general/how-t ... kopen.html

http://allweblong.wordpress.com


Newbie

Posts

Joined
Mon Sep 09, 2013 7:14 am

Post by Jsf » Tue Sep 23, 2014 1:54 am

Thanks for help. Finally it works! Only the one thing I need to know $token to access next page.
Do not know if it the best way, bet maybe would helpfull for others...

Code: Select all

$url = curl_getinfo($curl_connection)['url'];
$token = strstr($url, 'token='); 
and then

Code: Select all

curl_setopt($curl_connection, CURLOPT_URL, 'http://www.yourdomain.com/admin/index.php?route=module/yourmodule/funkction&'.$token);

/*
My personal OpenCart modules list
*/


User avatar
Jsf
New member

Posts

Joined
Sun Jan 26, 2014 4:08 am

Post by MarketInSG » Sat Sep 27, 2014 5:28 pm

well, what's the use of a cron job if you need to know the token as it will always be changing.


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore
Who is online

Users browsing this forum: No registered users and 23 guests