define('CLI') should bypass auth_setup() in init.php

Bug #1111066 reported by Aaron Wells
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
Low
Aaron Wells

Bug Description

If you create a command-line script as described on https://wiki.mahara.org/index.php/Developer_Area/CLI_Framework , putting define('CLI'); and define('INTERNAL'); at the top, it will error out every time in init.php because auth_setup() detects that you haven't logged in.

I think this has gone unnoticed because the two existing CLI scripts in Mahara core both also use define('INSTALLER'), and if that's defined then init.php doesn't check auth_setup(). I propose that define('CLI') should also bypass auth_setup() in init.php

Sample script to demonstrate this problem:

<?php

define('CLI', 1);
define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(__FILE__).'/init.php');
require(get_config('libroot').'cli.php');

cli::cli_exit('Hello');

Expected Result: When executed via the command-line, it should print "Hello" and quit
Actual Result: It prints a terminal full of the HTML for the Mahara login page and dies.

Revision history for this message
Aaron Wells (u-aaronw) wrote :

Was initially pushed as a patch for 1.6: https://reviews.mahara.org/#/c/2024/

I've abandoned that one and submitted a patch for 1.7 instead: https://reviews.mahara.org/2066

Changed in mahara:
milestone: none → 1.7.0
status: New → In Progress
importance: Undecided → Low
assignee: nobody → Aaron Wells (u-aaronw)
Aaron Wells (u-aaronw)
Changed in mahara:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.