Results 1 to 10 of 21

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Posts
    10
    Plugin Contributions
    0

    Default Admin auto login for a cron job

    Hi, I need to put some script from admin folder in cron job on my server. In that script I use some function from admin/includes/application_top.php . So I use require_once ('includes/application_top.php'); for call that function. When I call this script he need my interaction to login first like admin. Now, I need information on witch way I can create auto login on admin from my script.
    Best regards

  2. #2
    Join Date
    Jan 2004
    Posts
    66,392
    Blog Entries
    7
    Plugin Contributions
    81

    Default Re: Admin auto login for a cron job

    Here's one approach, which has basic security around it. You can enhance it further if you wish, but this should work as-is:

    1. In your cron PHP script that calls application_top, put this *before* the call to application_top:
    Code:
    define('CRON_ADMIN_USER_ID', 99);
    You can substitute 99 with whatever admin user id *number* you want, as long as it exists.
    So, when you create the user, it'll be assigned a number. THAT is the number you need to enter in the define() statement mentioned above.
    This number will be used to authenticate login, and for tracking admin activity in the admin activity log.

    2. In your /admin/init_includes/init_admin_auth.php script, add the new lines as shown below:
    Code:
    if (! defined('IS_ADMIN_FLAG')) {
      die('Illegal Access');
    }
    
    if (!isset($_SESSION['admin_id']) && defined('CRON_ADMIN_USER_ID') && (int)CRON_ADMIN_USER_ID != 0) {
      $_SESSION['admin_id'] = CRON_ADMIN_USER_ID;
    }
    
    if (!(basename($PHP_SELF) == FILENAME_LOGIN . '.php')) {
    Last edited by DrByte; 9 Aug 2012 at 07:40 AM. Reason: added mention of v1.5.0
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Oct 2008
    Location
    Netherlands
    Posts
    26
    Plugin Contributions
    0

    Default Re: Admin auto login for a cron job

    My host uses a GUI for cron job's, so i'm not able to add any lines.
    Would there be a differend way to achive the same?

  4. #4
    Join Date
    Apr 2004
    Location
    vienna
    Posts
    198
    Plugin Contributions
    9

    Default Re: Admin auto login for a cron job

    Quote Originally Posted by Robbie_79 View Post
    My host uses a GUI for cron job's, so i'm not able to add any lines.
    Would there be a differend way to achive the same?
    you dont need to add a line before your cronjob
    you have to create a file in the admin folder
    for example cron1.php
    PHP Code:
    <?php
    // filename: cron1.php
    // make changes in /admin/init_includes/init_admin_auth.php
    define('CRON_ADMIN_USER_ID''13');
    define('EMAIL_USE_HTML'false);
    require (
    'includes/application_top.php');

    // your code to run via cron 
    // sends an email listing all orders with status $os
    $os 1;
    $sql 'SELECT orders_id, date_purchased, order_total, payment_method, customers_name FROM ' TABLE_ORDERS ' WHERE orders_status=' $os;
    $res $db->execute($sql);
    $content 'orders_status: ' $os "\n\r\n\r";
    while (!
    $res->EOF){
        
    $content .= implode(', '$res->fields) . "\n\r";
        
    $res->MoveNext();
    }
    echo 
    'CRON1 ' date('Ymd H:i:s');
    zen_mail('Admin'STORE_OWNER_EMAIL_ADDRESS'ZC open orders'$content'ZC Cron1'STORE_OWNER_EMAIL_ADDRESS );
    your cronjob command could look like:
    Code:
    /usr/bin/lynx -accept_all_cookies -dump http://localhost/PathTo/admin/cron1.php

  5. #5
    Join Date
    Oct 2008
    Location
    Netherlands
    Posts
    26
    Plugin Contributions
    0

    Default Re: Admin auto login for a cron job

    thank you very much! it's a first-cron for me ;)

  6. #6
    Join Date
    Oct 2008
    Location
    Netherlands
    Posts
    26
    Plugin Contributions
    0

    Default Re: Admin auto login for a cron job

    Will this method also make the cron page browser-accesible?

  7. #7
    Join Date
    Jan 2007
    Posts
    7
    Plugin Contributions
    0

    Default Re: Admin auto login for a cron job

    Hi Hugo...

    I am unclear on what needs to be added to the init_admin_auth.php file in your example do I just need to define the CRON_ADMIN_USER_ID?

    I have already added one to the database via SQL so now I just need to figure out this part and I am golden.

    Thanks in advance.
    Got toast!

  8. #8
    Join Date
    Jan 2012
    Posts
    15
    Plugin Contributions
    0

    Default Re: Admin auto login for a cron job

    hey - I'm trying to get a cron job to work too now. I keep getting an error in sessions.php so I'm guessing it is failing at authenticating the user or something. Anyone still around that knows how to do this and can help? I'm desperate for help!

  9. #9
    Join Date
    Oct 2004
    Posts
    1,045
    Plugin Contributions
    0

    Default Re: Admin auto login for a cron job

    Quote Originally Posted by DrByte View Post
    Here's one approach, which has basic security around it. You can enhance it further if you wish, but this should work as-is:

    1. In your cron PHP script that calls application_top, put this *before* the call to application_top:
    *snip*

    2. In your /admin/init_includes/init_admin_auth.php script, add the new lines as shown below:
    **snip**
    I tried this, but in the e-mail that I get when the cron runs, it says this:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>***</title> <link href="includes/stylesheet.css" rel="stylesheet" type="text/css" /> <meta name="robot" content="noindex, nofollow" /> </head> <body id="login" onload="document.getElementById('admin_name').focus()">
    <form name="login" action="https://www.***.com/storemanager/login.php?zenAdminID=9s5nqcqspgpfgd5v3vls43lor5" method="post">
    <fieldset>
    <legend>Admin Login</legend>
    <label class="loginLabel" for="admin_name">Admin Username:</label> <input style="float: left" type="text" id="admin_name" name="admin_name" value="" /> <br class="clearBoth" />
    <label class="loginLabel" for="admin_pass">Admin Password:</label> <input style="float: left" type="password" id="admin_pass" name="admin_pass" value="" /> <br class="clearBoth" />
    <input type="hidden" name="securityToken" value="bcbc7b1f6748bb93cb3aae681b130bfd">
    <input type="submit" name="submit" class="button" value="Login" />
    <a style="float: right;" href="https://www.***.com/storemanager/password_forgotten.php?zenAdminID=9s5nqcqspgpfgd5v3vls43lor5">Resend Password</a> </fieldset> </form> </body> </html>
    Is there something else I can try?
    Danielle

  10. #10
    Join Date
    Jan 2004
    Posts
    66,392
    Blog Entries
    7
    Plugin Contributions
    81

    Default Re: Admin auto login for a cron job

    If you're using v1.5.x+ or have v1.3.9 and have an Admin Profiles addon installed, you'll need to create the user account and grant it some permissions.
    Similarly, if you're using v1.5.0 you will need to create the user account, which involves assigning it a profile, then take the system-assigned user number and use that number when specifying the CRON_ADMIN_USER_ID definition.

    Otherwise the script will be prompted to login.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. cron job for Recover Cart Sale add-on
    By pdxdoug in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 19 Sep 2015, 02:18 AM
  2. Can I use an auto Import/cron job for this?
    By KNM Computers in forum Templates, Stylesheets, Page Layout
    Replies: 28
    Last Post: 31 Jul 2013, 08:08 PM
  3. Setting up a cron job for the Snapshot add-on?
    By RescoCCC in forum All Other Contributions/Addons
    Replies: 11
    Last Post: 3 Jan 2012, 06:19 PM
  4. Cron Job for Optimize Database
    By Convergence in forum General Questions
    Replies: 4
    Last Post: 24 Jan 2011, 09:36 PM
  5. Cron Job for Updating QTY
    By ryanb4614 in forum General Questions
    Replies: 2
    Last Post: 9 Aug 2010, 07:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR