PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_csvimproved/classes/csvi_class_cron.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 200 lines | 132 code | 12 blank | 56 comment | 13 complexity | 54e775c56b7bca99fc5288fde190717f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Cron handler
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * @package CSVImproved
  20. * @author Roland Dalmulder
  21. * @link http://www.csvimproved.com
  22. * @copyright Copyright (C) 2006 - 2008 Roland Dalmulder
  23. * @version $Id: csvi_class_cron.php 210 2008-04-21 07:32:34Z Suami $
  24. */
  25. /**
  26. * Cron handler
  27. */
  28. /* Get the Joomla framework */
  29. /* Set flag that this is a parent file */
  30. define( '_VALID_MOS', 1 );
  31. $basepath = str_ireplace('administrator/components/com_csvimproved/classes/csvi_class_cron.php', '', str_ireplace('\\', '/', __FILE__));
  32. require( $basepath.'/globals.php' );
  33. $basepath = str_ireplace('administrator/components/com_csvimproved/classes/csvi_class_cron.php', '', str_ireplace('\\', '/', __FILE__));
  34. require( $basepath.'/configuration.php' );
  35. require_once( $basepath.'/includes/joomla.php' );
  36. /**
  37. * Handles all cron requests
  38. *
  39. * @package CSVImproved
  40. */
  41. class CsviCron {
  42. /** @var $basepath string the base of the installation */
  43. var $basepath = '';
  44. /**
  45. * Initialise some settings
  46. */
  47. function CsviCron() {
  48. global $database;
  49. /* Collect the variables */
  50. $this->CollectVariables();
  51. /* First check if we deal with a valid user */
  52. if ($this->Login()) {
  53. /* Second check if any template is set to process */
  54. $template_name = stripslashes(strval(mosGetParam($_REQUEST, 'template_name', '')));
  55. if ($template_name) {
  56. /* There is a template name, get some details to streamline processing */
  57. $q = "SELECT ID, template_type FROM #__csvi_templates WHERE template_name = '".$template_name."'";
  58. $database->setQuery($q);
  59. $database->loadObject($row);
  60. if (is_object($row)) {
  61. if ($row->template_type) {
  62. /* Set the export type */
  63. if (stristr($row->template_type, 'export')) $_REQUEST['task'] = 'export';
  64. else $_REQUEST['task'] = 'import';
  65. /* Set the template ID */
  66. $_REQUEST['templateid'] = $row->ID;
  67. /* Set the file details */
  68. /* Set output to file as we cannot download anything */
  69. $_REQUEST['exportto'] = 'tofile';
  70. /* Get the filename from the user input */
  71. if (isset($_REQUEST['filename'])) {
  72. $_REQUEST['local_csv_file'] = stripslashes(strval(mosGetParam($_REQUEST, 'filename')));
  73. /* Tell the system it is a local file */
  74. $_REQUEST['selectfile'] = 2;
  75. }
  76. else {
  77. /* Tell the system there is no file */
  78. $_REQUEST['selectfile'] = 0;
  79. }
  80. $this->ExecuteJob();
  81. $this->CronOutput();
  82. }
  83. }
  84. else echo 'No template found with the name '.$template_name;
  85. }
  86. else echo 'No template name specified';
  87. }
  88. else echo 'No valid user';
  89. }
  90. /**
  91. * Collect the variables
  92. *
  93. * Running from the command line, the variables are stored in $argc and $argv.
  94. * Here we put them in $_REQUEST so that they are available to the script
  95. */
  96. function CollectVariables() {
  97. /* Take the argument values and put them in $_REQUEST */
  98. if (isset($_SERVER['argv'])) {
  99. foreach ($_SERVER['argv'] as $key => $argument) {
  100. if ($key > 0) {
  101. list($name, $value) = split("=", $argument);
  102. $_REQUEST[$name] = $value;
  103. }
  104. }
  105. }
  106. /* Get the basepath */
  107. $this->basepath = str_ireplace('administrator/components/com_csvimproved/classes/csvi_class_cron.php', '', str_ireplace('\\', '/', __FILE__));
  108. }
  109. /**
  110. * Check if the user exists
  111. */
  112. function Login() {
  113. global $database;
  114. $username = stripslashes( strval( mosGetParam( $_REQUEST, 'username', '' ) ) );
  115. $passwd = stripslashes( strval( mosGetParam( $_REQUEST, 'passwd', '' ) ) );
  116. $query = "SELECT id, name, username, password, usertype, block, gid"
  117. . "\n FROM #__users"
  118. . "\n WHERE username = ". $database->Quote( $username )
  119. ;
  120. $database->setQuery( $query );
  121. $database->loadObject( $row );
  122. if (is_object($row)) {
  123. if ($row->block == 1) {
  124. echo 'User is blocked';
  125. return false;
  126. }
  127. if ((strpos($row->password, ':') === false) && $row->password == md5($passwd)) {
  128. // Old password hash storage but authentic ... lets convert it
  129. $salt = mosMakePassword(16);
  130. $crypt = md5($passwd.$salt);
  131. $row->password = $crypt.':'.$salt;
  132. }
  133. list($hash, $salt) = explode(':', $row->password);
  134. $cryptpass = md5($passwd.$salt);
  135. if ($hash != $cryptpass) {
  136. echo 'Password incorrect';
  137. return false;
  138. }
  139. else {
  140. echo 'User '.$row->username.' logged in at '.date('Y-m-d H:i:s', time())."\n";
  141. return true;
  142. }
  143. }
  144. else return false;
  145. }
  146. /**
  147. * Process the requested job
  148. */
  149. function ExecuteJob() {
  150. $cron = true;
  151. require( $this->basepath.'/administrator/components/com_csvimproved/admin.csvimproved.php' );
  152. }
  153. /**
  154. * Output cron results
  155. */
  156. function CronOutput() {
  157. $csviregistry =& $GLOBALS['csviregistry'];
  158. $csvilog = $csviregistry->GetObject('logger');
  159. $csvilang = $csviregistry->GetObject('language');
  160. /* strings to find */
  161. $find = array();
  162. $find[] = '<br />';
  163. $find[] = '<strong>';
  164. $find[] = '</strong>';
  165. /* strings to replace with */
  166. $replace = array();
  167. $replace[] = "";
  168. $replace[] = "";
  169. $replace[] = "";
  170. foreach ($csvilog->stats as $action => $stats) {
  171. if ($stats['count'] > 0) {
  172. $action = strtoupper("OUTPUT_".$action);
  173. echo $csvilang->$action.": ".$stats['count']."\n";
  174. echo str_repeat("=", 25)."\n";
  175. echo str_replace($find, $replace, $stats['message'])."\n";
  176. }
  177. }
  178. }
  179. }
  180. $csvicron = new CsviCron;
  181. ?>