mirror of
https://github.com/newnius/YAO-portal.git
synced 2025-12-13 00:56:44 +00:00
init & add agent & add job
This commit is contained in:
65
agent.logic.php
Normal file
65
agent.logic.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
require_once('predis/autoload.php');
|
||||
|
||||
require_once('util4p/util.php');
|
||||
require_once('util4p/CRObject.class.php');
|
||||
require_once('util4p/Random.class.php');
|
||||
require_once('util4p/AccessController.class.php');
|
||||
require_once('util4p/CRLogger.class.php');
|
||||
|
||||
require_once('Code.class.php');
|
||||
require_once('AgentManager.class.php');
|
||||
|
||||
require_once('config.inc.php');
|
||||
require_once('init.inc.php');
|
||||
|
||||
function agent_add(CRObject $agent)
|
||||
{
|
||||
if (!AccessController::hasAccess(Session::get('role', 'visitor'), 'agent.add')) {
|
||||
$res['errno'] = Code::NO_PRIVILEGE;
|
||||
return $res;
|
||||
}
|
||||
if (AgentManager::getByIP($agent->get('ip')) !== null) {
|
||||
$res['errno'] = Code::RECORD_ALREADY_EXIST;
|
||||
} else {
|
||||
$token = Random::randomString(32);
|
||||
$agent->set('token', $token);
|
||||
$res['errno'] = AgentManager::add($agent) ? Code::SUCCESS : Code::UNKNOWN_ERROR;
|
||||
}
|
||||
$log = new CRObject();
|
||||
$log->set('scope', Session::get('uid'));
|
||||
$log->set('tag', 'agent.add');
|
||||
$content = array('agent' => $agent, 'response' => $res['errno']);
|
||||
$log->set('content', json_encode($content));
|
||||
CRLogger::log($log);
|
||||
return $res;
|
||||
}
|
||||
|
||||
function agent_remove(CRObject $agent)
|
||||
{
|
||||
if (!AccessController::hasAccess(Session::get('role', 'visitor'), 'agent.remove')) {
|
||||
$res['errno'] = Code::NO_PRIVILEGE;
|
||||
return $res;
|
||||
}
|
||||
$res['errno'] = AgentManager::remove($agent) ? Code::SUCCESS : Code::UNKNOWN_ERROR;
|
||||
$log = new CRObject();
|
||||
$log->set('scope', Session::get('uid'));
|
||||
$log->set('tag', 'agent.remove');
|
||||
$content = array('agent' => $agent, 'response' => $res['errno']);
|
||||
$log->set('content', json_encode($content));
|
||||
CRLogger::log($log);
|
||||
return $res;
|
||||
}
|
||||
|
||||
function agent_list(CRObject $rule)
|
||||
{
|
||||
if (!AccessController::hasAccess(Session::get('role', 'visitor'), 'agent.list')) {
|
||||
$res['errno'] = Code::NO_PRIVILEGE;
|
||||
return $res;
|
||||
}
|
||||
$res['agents'] = AgentManager::gets($rule);
|
||||
$res['count'] = AgentManager::count($rule);
|
||||
$res['errno'] = $res['agents'] === null ? Code::FAIL : Code::SUCCESS;
|
||||
return $res;
|
||||
}
|
||||
Reference in New Issue
Block a user