Skip to content

Instantly share code, notes, and snippets.

@1d10t
Last active November 30, 2016 16:44
Show Gist options
  • Save 1d10t/7d617ec654ceda6509b17f3f48b037f6 to your computer and use it in GitHub Desktop.
Save 1d10t/7d617ec654ceda6509b17f3f48b037f6 to your computer and use it in GitHub Desktop.
cs-cart cron wrapper
#!/usr/bin/php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('memory_limit','1G');
set_time_limit(0);
$opt = getopt('', array(
'host:',
'dir:',
'dispatch:',
'method::',
'script::',
'scheme::',
// 'user_id::',
'get::',
'console::',
));
$defaults = array(
'method' => 'GET',
'script' => '/index.php',
'scheme' => 'http',
);
foreach($defaults as $option => $default){
if(!isset($opt[$option])) $opt[$option] = $default;
}
//var_dump($opt); die;
if($opt === false || isset($opt['help']) || !isset($opt['host'], $opt['dir'], $opt['dispatch'])){
echo "Usage:\r\n"
,"php -f ".__FILE__." -- \\\r\n"
,"\t--scheme=".escapeshellarg($defaults['scheme'])." \\\r\n"
,"\t--host='domain.ru' \\\r\n"
,"\t--dir='/home/u/user/domain.ru/public_html' \\\r\n"
,"\t--dispatch='controller.action' \\\r\n"
,"\t--script=".escapeshellarg($defaults['script'])." \\\r\n"
,"\t--method=".escapeshellarg($defaults['method'])." \\\r\n"
,"\t--console \\\r\n"
// ,"\t--user_id=31 # not working\\\r\n"
;
die;
}
extract($opt);
if(isset($console)){
define('CONSOLE', true);
}
foreach(include dirname(__FILE__).'/cscart_cron_request.php' as $k => $v){
${$k} = $v;
//var_dump(compact($k));
}
chdir($opt['dir']);
include ".{$opt['script']}";
<?php
if(empty($get)){
$get = '';
$get_array = array();
}else{
parse_str($get, $get_array);
}
return array (
'_GET' =>
array (
'dispatch' => $dispatch,
) + $get_array,
'_REQUEST' =>
array (
'dispatch' => $dispatch,
) + $get_array,
'_SERVER' =>
array (
'HTTP_AUTHORIZATION' => '',
'LANG' => 'ru_RU.UTF-8',
'MM_CHARSET' => 'UTF-8',
'HTTP_HOST' => $host,
'HTTP_USER_AGENT' => 'Cscart-Cron-Wrapper/0.0.1',
'HTTP_ACCEPT' => '*/*',
'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
'SERVER_SIGNATURE' => '',
'SERVER_SOFTWARE' => 'Bash',
'SERVER_NAME' => $host,
'SERVER_ADDR' => '127.0.0.1',
'SERVER_PORT' => $scheme == 'https' ? '443' : '80',
'REMOTE_ADDR' => '127.0.0.1',
'DOCUMENT_ROOT' => $dir,
'REQUEST_SCHEME' => $scheme,
'HTTPS' => $scheme == 'https' ? '1' : null,
'CONTEXT_PREFIX' => '',
'CONTEXT_DOCUMENT_ROOT' => $dir,
'SERVER_ADMIN' => 'support@'.$host,
'SCRIPT_FILENAME' => "{$dir}{$script}",
'REMOTE_PORT' => '15695',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'REQUEST_METHOD' => $method,
'QUERY_STRING' => 'dispatch='.$dispatch.($get?"&$get":''),
'REQUEST_URI' => $script.'?dispatch='.$dispatch.($get?"&$get":''),
'SCRIPT_NAME' => $script,
'PHP_SELF' => $script,
'REQUEST_TIME_FLOAT' => time(),
'REQUEST_TIME' => time(),
),
'_ENV' =>
array (
),
'_SESSION' => empty($user_id) ? array() : array(
'auth' => array (
'area' => 'A',
'user_id' => '1',
'user_type' => 'A',
),
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment