2

I have PHP script what works fine via browser like

http://example.com/index.php?option=com_acymailing&view=api

Is that possible to call the same using WGET or CURL from Linux CLI (ignoring any output, just run "like browser" and close) ?

Thanks in advance for any hint to try.

The script from Joomla AcyMailing API and here is full content

<?php

define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);

if (file_exists(dirname(__FILE__) . '/defines.php')) {
 include_once dirname(__FILE__) . '/defines.php';
}

if (!defined('_JDEFINES')) {
 define('JPATH_BASE', dirname(__FILE__));
 require_once JPATH_BASE.'/includes/defines.php';
}

require_once JPATH_BASE.'/includes/framework.php';
$app = JFactory::getApplication('site');


if(!include_once(rtrim(JPATH_ADMINISTRATOR,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_acymailing'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php')){
 echo 'This code can not work without the AcyMailing Component';
 return false;
 }
$mailer = acymailing_get('helper.mailer');
$mailer->report = true;
$mailer->trackEmail = true;
$mailer->autoAddUser = false;
$mailer->sendOne(11,'test@example.com');

?>
Serge
  • 679
  • 1
  • 9
  • 23
  • 6
    Short answer: Yes. Long answer: Have you tried it? – aynber Nov 16 '16 at 17:11
  • If you are relying on JavaScript to run, then no. Otherwise yes. – apokryfos Nov 16 '16 at 17:12
  • Good if yes. So my logic question HOW ? and then I try. – Serge Nov 16 '16 at 17:13
  • pure php can be....here is something you might be looking http://stackoverflow.com/questions/6965541/run-php-code-in-command-line and you need something like `$ wget -O - -q http://www.somesite.com/your.php >> log.txt` log.txt would include the result – RohitS Nov 16 '16 at 17:14
  • Unfortunately not. I've added this script - may be it will explain something. – Serge Nov 16 '16 at 17:28

1 Answers1

2

Yes, it is possible in many ways. If you want to ignore any output:

wget --quiet -O /dev/null http://whatever-url/script.php?bla
twicejr
  • 1,319
  • 3
  • 13
  • 21
  • Unfortunately not. When run from browser - this script produces an email to single user. When run from CLI using your way - not. – Serge Nov 16 '16 at 17:17
  • @Serge Then your script is doing some sort of check or expects input. Before you post more relevant information, we cannot help you. – Charlotte Dunois Nov 16 '16 at 17:19
  • Charlotte, that's my thoughts exactly. Probably check the remote_addr usage. Or some other obscure $_SERVER remote address variant – twicejr Nov 16 '16 at 17:20
  • Also, at first don't trash the output; just use wget [url], and check the output for errors. – twicejr Nov 16 '16 at 17:22
  • I've added this Joomla Acymailing API script. May be it says something. – Serge Nov 16 '16 at 17:25
  • Yeah... well actually I don't, but if the script mails, you probably just need to spoof the $_SERVER['HTTP_HOST'] to always comply with what it should be :) , add `$_SERVER['HTTP_HOST'] = 'xxx.whatitshouldbe.com' `at the top of index.php, and try again. Or maybe the plugin allows to hard-define the from hostname/email in the config panel? Or is that a configuration.php thingy in Joomla ;) – twicejr Nov 16 '16 at 17:49
  • 1
    Yes, after some tests I see the script should be adjusted itself to use with curl or wget, so I delete my question because it's not the matter of curl or wget... – Serge Nov 16 '16 at 18:00
  • Well it can be nice of a reference for when someone else has that moment of a blackout for a second :P A nice list of options to check. – twicejr Nov 16 '16 at 18:01