-
-
Save escopecz/9a1a0b10861941a457f4 to your computer and use it in GitHub Desktop.
Script to run Mautic (https://mautic.org) commands from a URL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!isset($_GET['ILoveMauticReallyIDo'])) { | |
echo 'The secret phrase is wrong.'; | |
die; | |
} | |
$link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; | |
$allowedTasks = array( | |
'cache:clear', | |
'mautic:leadlists:update', | |
'mautic:campaigns:update', | |
'mautic:campaigns:trigger', | |
'mautic:email:process', | |
'mautic:fetch:email', | |
'doctrine:migrations:migrate', | |
'doctrine:schema:update --dump-sql', | |
'doctrine:schema:update --force' | |
); | |
if (!isset($_GET['task'])) { | |
echo 'Specify what task to run. You can run these:'; | |
foreach ($allowedTasks as $task) { | |
$href = $link . '&task=' . urlencode($task); | |
echo '<br><a href="' . $href . '">' . $href . '</a>'; | |
} | |
echo '<br><a href="https://www.mautic.org/docs/setup/index.html">Read more</a>'; | |
echo '<br><b style="color:red">Please, backup your database before executing the doctrine commands!</b>'; | |
die; | |
} | |
$task = urldecode($_GET['task']); | |
if (!in_array($task, $allowedTasks)) { | |
echo 'Task ' . $task . ' is not allowed.'; | |
die; | |
} | |
$fullCommand = explode(' ', $task); | |
$command = $fullCommand[0]; | |
$argsCount = count($fullCommand) - 1; | |
$args = array('console', $command); | |
if ($argsCount) { | |
for ($i = 1; $i <= $argsCount; $i++) { | |
$args[] = $fullCommand[$i]; | |
} | |
} | |
echo '<h3>Executing ' . implode(' ', $args) . '</h3>'; | |
require_once __DIR__.'/app/bootstrap.php.cache'; | |
require_once __DIR__.'/app/AppKernel.php'; | |
use Symfony\Bundle\FrameworkBundle\Console\Application; | |
use Symfony\Component\Console\Input\ArgvInput; | |
use Symfony\Component\Console\Output\BufferedOutput; | |
defined('IN_MAUTIC_CONSOLE') or define('IN_MAUTIC_CONSOLE', 1); | |
try { | |
$input = new ArgvInput($args); | |
$output = new BufferedOutput(); | |
$kernel = new AppKernel('prod', false); | |
$app = new Application($kernel); | |
$app->setAutoExit(false); | |
$result = $app->run($input, $output); | |
echo "<pre>\n".$output->fetch().'</pre>'; | |
} catch (\Exception $exception) { | |
echo $exception->getMessage(); | |
} |
Just "commands" added in .htaccess after upgrade_V3
Except those whitelisted bellow.
<FilesMatch "^(index|index_dev|filemanager|upgrade|upgrade_v3|commands)\.php$">
Require all granted
</FilesMatch>
Just "commands" added in .htaccess after upgrade_V3
Except those whitelisted bellow.
<FilesMatch "^(index|index_dev|filemanager|upgrade|upgrade_v3|commands)\.php$"> Require all granted </FilesMatch>
I got it. Thank you.
Hello Brother and sisters
i am creating commands.php file but i access it thorogh my browser i receive this error
Please help me to resolve this issue i have installed latest version of mautic and facing this error
Uh oh! I think I broke it. If I do it again, please report me to the system administrator!
500 Internal Server Error
mautic not give access to login to my administrator account and i receive this error
Let me know what to do to resolve this prompt
Best Regards
Muhammad Ashfaq
Hey Muhammad, please read the post above yours - but maybe you solved it meanwhile ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for your prompt response. I have also edited my last comment.
I am a rookie please, just one last clarification, please, I'll be grateful.
Do you commands like this as found in the script:
'cache:clear',
'cache:clear --no-warmup',
'mautic:install:data',
'mautic:campaigns:trigger',
'mautic:campaigns:rebuild',
'mautic:social:monitoring',
'mautic:iplookup:download',
'mautic:emails:send',
'mautic:email:fetch',
'mautic:messages:send',
'mautic:integration:fetchleads -i Salesforce',
'mautic:integration:fetchleads --integration=Hubspot',
'mautic:segments:update',
'doctrine:migration:status',
'doctrine:migrations:migrate',
'doctrine:schema:update --dump-sql',
'doctrine:schema:update --force',
'mautic:maintenance:cleanup --days-old=365 --dry-run'
);
or
https://myurl.com/commands.php?secretphase
Kindly assist, I'll be grateful.