Created feature to run the pending cronjobs with cron.php
* Fixes for the accounts suspend API
This commit is contained in:
parent
ebe97d05f7
commit
2a0ce78f3c
|
@ -4,8 +4,8 @@ $_ = function() {
|
||||||
if (!isset($_GET['id']) && !isset($_GET['name']))
|
if (!isset($_GET['id']) && !isset($_GET['name']))
|
||||||
return apiresult(['error' => '<id> or <name> parameter must be specified'], 400);
|
return apiresult(['error' => '<id> or <name> parameter must be specified'], 400);
|
||||||
|
|
||||||
$id = trim($_GET['id']);
|
$id = trim(isset($_GET['id']) ? $_GET['id'] : '');
|
||||||
$name = trim($_GET['name']);
|
$name = trim(isset($_GET['name']) ? $_GET['name'] : '');
|
||||||
if (!valid_for_path($id) || !valid_for_path($name))
|
if (!valid_for_path($id) || !valid_for_path($name))
|
||||||
return apiresult(['error' => '<id> or <name> parameter is incorrect'], 400);
|
return apiresult(['error' => '<id> or <name> parameter is incorrect'], 400);
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ $_ = function() {
|
||||||
if (!isset($_GET['id']) && !isset($_GET['name']))
|
if (!isset($_GET['id']) && !isset($_GET['name']))
|
||||||
return apiresult(['error' => '<id> or <name> parameter must be specified'], 400);
|
return apiresult(['error' => '<id> or <name> parameter must be specified'], 400);
|
||||||
|
|
||||||
$id = trim($_GET['id']);
|
$id = trim(isset($_GET['id']) ? $_GET['id'] : '');
|
||||||
$name = trim($_GET['name']);
|
$name = trim(isset($_GET['name']) ? $_GET['name'] : '');
|
||||||
if (!valid_for_path($id) || !valid_for_path($name))
|
if (!valid_for_path($id) || !valid_for_path($name))
|
||||||
return apiresult(['error' => '<id> or <name> parameter is incorrect'], 400);
|
return apiresult(['error' => '<id> or <name> parameter is incorrect'], 400);
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,3 @@
|
||||||
<?php chdir('../../../../../../') ?>
|
<?php chdir('../../../../../../') ?>
|
||||||
<?php require 'base.php' ?>
|
<?php require 'base.php' ?>
|
||||||
<?php
|
<?php mod_php() ?>
|
||||||
|
|
||||||
$id = trim($_GET['id']);
|
|
||||||
if (!valid_mastodon_account_id($id))
|
|
||||||
apiresult(['error' => 'id parameter has incorrect format'], 400);
|
|
||||||
|
|
||||||
instance_http_post('/api/v1/admin/accounts/'.$id.'/action',['type' => 'suspend']);
|
|
||||||
$output = instance_http_delete('/api/v1/admin/accounts/'.$id);
|
|
||||||
apiresult($output);
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$_ = function() {
|
||||||
|
$id = trim($_GET['id']);
|
||||||
|
if (!valid_mastodon_account_id($id))
|
||||||
|
return apiresult(['error' => 'id parameter has incorrect format'], 400);
|
||||||
|
|
||||||
|
instance_http_post('/api/v1/admin/accounts/'.$id.'/action',['type' => 'suspend']);
|
||||||
|
$output = instance_http_delete('/api/v1/admin/accounts/'.$id);
|
||||||
|
return apiresult($output);
|
||||||
|
};
|
||||||
|
$_();
|
12
base.php
12
base.php
|
@ -61,6 +61,8 @@ function mod_php($module_name=null) {
|
||||||
$GLOBALS['IS_PHP'] = true;
|
$GLOBALS['IS_PHP'] = true;
|
||||||
unset($GLOBALS['api_data']);
|
unset($GLOBALS['api_data']);
|
||||||
}
|
}
|
||||||
|
if (!file_exists($module_name.'/mod.php'))
|
||||||
|
return 'does_not_exist';
|
||||||
require $module_name.'/mod.php';
|
require $module_name.'/mod.php';
|
||||||
if (!$null_mod) {
|
if (!$null_mod) {
|
||||||
if (!$is_php_set)
|
if (!$is_php_set)
|
||||||
|
@ -129,12 +131,18 @@ function instance_http_get($url) { return instance_http_request($url, 'GET'); }
|
||||||
function instance_http_post($url, $data=null) { return instance_http_request($url, 'POST', $data); }
|
function instance_http_post($url, $data=null) { return instance_http_request($url, 'POST', $data); }
|
||||||
function instance_http_delete($url) { return instance_http_request($url, 'DELETE'); }
|
function instance_http_delete($url) { return instance_http_request($url, 'DELETE'); }
|
||||||
function instance_http_request($url, $method, $data=null) {
|
function instance_http_request($url, $method, $data=null) {
|
||||||
|
$software = null;
|
||||||
|
if (isset($_SERVER['REQUEST_URI'])) {
|
||||||
$huri = substr(trim($_SERVER['REQUEST_URI']), 7);
|
$huri = substr(trim($_SERVER['REQUEST_URI']), 7);
|
||||||
$ps = explode('/', trim($huri, '/'));
|
$ps = explode('/', trim($huri, '/'));
|
||||||
if ($ps[0] !== 'http' || !in_array($ps[1], $GLOBALS['supported_ap_software']))
|
if ($ps[0] !== 'http' || !in_array($ps[1], $GLOBALS['supported_ap_software']))
|
||||||
apiresult(['error' => 'this method can only be called from api/v1/http/<software> URIs'], 500);
|
return apiresult(['error' => 'this method can only be called from api/v1/http/<software> URIs'], 500);
|
||||||
|
|
||||||
$software = $ps[1];
|
$software = $ps[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($software === null && isset($GLOBALS['ap_software']))
|
||||||
|
$software = $GLOBALS['ap_software'];
|
||||||
|
|
||||||
$config = instance_config($software);
|
$config = instance_config($software);
|
||||||
$url = $config['instance_url'].$url;
|
$url = $config['instance_url'].$url;
|
||||||
|
|
||||||
|
|
36
cron.php
36
cron.php
|
@ -179,6 +179,42 @@ run__cronjobs_filter_jobs();
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////
|
//////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////
|
||||||
|
// CRONJOBS for running the actual jobs
|
||||||
|
//
|
||||||
|
function run_cronjobs() {
|
||||||
|
$max = 1000;
|
||||||
|
if (isset($GLOBALS['appconf']['cron__max_jobs']))
|
||||||
|
$max = intval($GLOBALS['appconf']['cron__max_jobs']);
|
||||||
|
$_GET = ['max' => $max];
|
||||||
|
$jobs = mod_php('api/v1/cron/jobs');
|
||||||
|
foreach ($jobs as $job) {
|
||||||
|
$_GET = ['id' => $job];
|
||||||
|
$job_data = mod_php('api/v1/cron/job/get');
|
||||||
|
if (isset($job_data['args']['_get']))
|
||||||
|
$_GET = $job_data['args']['_get'];
|
||||||
|
if (isset($job_data['args']['_post']))
|
||||||
|
$_POST = $job_data['args']['_post'];
|
||||||
|
logi('Running job with data: '.serialize($job_data));
|
||||||
|
$r = mod_php($job_data['module']);
|
||||||
|
if ($r === 'does_not_exist') {
|
||||||
|
loge('Could not find module (mod.php file) for: '.$job_data['module']);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$_GET = ['id' => $job];
|
||||||
|
$result = mod_php('api/v1/cron/job/del');
|
||||||
|
if (isset($result['ok']))
|
||||||
|
logi($result['ok']);
|
||||||
|
else if (isset($result['error']))
|
||||||
|
loge($result['error']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run_cronjobs();
|
||||||
|
//
|
||||||
|
///////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
$ms_total = time() - $time_start;
|
$ms_total = time() - $time_start;
|
||||||
logi("Cron has finished in {$ms_total} seconds");
|
logi("Cron has finished in {$ms_total} seconds");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue