示例#1
0
/**
 * 记录行为日志,并执行该行为的规则
 * @param string $action 行为标识
 * @param string $model 触发行为的模型名
 * @param int $record_id 触发行为的记录id
 * @param int $user_id 执行行为的用户id
 * @return boolean
 */
function action_log($action = null, $model = null, $record_id = null, $user_id = null)
{
    //参数检查
    if (empty($action) || empty($model) || empty($record_id)) {
        return '参数不能为空';
    }
    if (empty($user_id)) {
        $user_id = is_login();
    }
    //查询行为,判断是否执行
    $action_info = apiCall(\Admin\Api\ActionApi::GET_INFO, array(array("name" => $action)));
    if ($action_info['status'] && is_array($action_info['info']) && $action_info['info']['status'] != 1) {
        return '该行为被禁用或删除';
    }
    $action_info = $action_info['info'];
    //插入行为日志
    $data['action_id'] = $action_info['id'];
    $data['user_id'] = $user_id;
    $data['action_ip'] = ip2long(get_client_ip());
    $data['model'] = $model;
    $data['record_id'] = $record_id;
    $data['create_time'] = NOW_TIME;
    //解析日志规则,生成日志备注
    if (!empty($action_info['log'])) {
        if (preg_match_all('/\\[(\\S+?)\\]/', $action_info['log'], $match)) {
            //匹配[],获取[]里的字符串
            $log['user'] = $user_id;
            $log['record'] = $record_id;
            $log['model'] = $model;
            $log['time'] = NOW_TIME;
            $log['data'] = array('user' => $user_id, 'model' => $model, 'record' => $record_id, 'time' => NOW_TIME);
            $replace = array();
            foreach ($match[1] as $value) {
                $param = explode('|', $value);
                //分割字符串通过|
                if (isset($param[1])) {
                    $replace[] = call_user_func($param[1], $log[$param[0]]);
                    //调用函数
                } else {
                    $replace[] = $log[$param[0]];
                }
            }
            $data['remark'] = str_replace($match[0], $replace, $action_info['log']);
        } else {
            $data['remark'] = $action_info['log'];
        }
    } else {
        //未定义日志规则,记录操作url
        $data['remark'] = '操作url:' . $_SERVER['REQUEST_URI'];
    }
    $result = apiCall(\Admin\Api\ActionLogApi::ADD, array($data));
    if (!$result['status']) {
        LogRecord("记录操作日志失败!", $result['info']);
    }
    //    M('ActionLog','common_')->add($data);
    if (!empty($action_info['rule'])) {
        //解析行为
        $rules = parse_action($action, $user_id);
        //执行行为
        $res = execute_action($rules, $action_info['id'], $user_id);
    }
}
示例#2
0
/**
 * 记录行为日志,并执行该行为的规则
 *
 * @param string $action
 *            行为标识
 * @param string $model
 *            触发行为的模型名
 * @param int $record_id
 *            触发行为的记录id
 * @param int $user_id
 *            执行行为的用户id
 * @return boolean
 * @author huajie <*****@*****.**>
 */
function action_log($action = null, $model = null, $record_id = null, $user_id = null)
{
    // 参数检查
    if (empty($action) || empty($model) || empty($record_id)) {
        return '参数不能为空';
    }
    if (empty($user_id)) {
        $user_id = is_login();
    }
    // 查询行为,判断是否执行
    $action_info = M('Action')->getByName($action);
    if ($action_info['status'] != 1) {
        return '该行为被禁用或删除';
    }
    // 插入行为日志
    $data['action_id'] = $action_info['id'];
    $data['user_id'] = $user_id;
    $data['action_ip'] = ip2long(get_client_ip());
    $data['model'] = $model;
    $data['record_id'] = $record_id;
    $data['create_time'] = NOW_TIME;
    // 解析日志规则,生成日志备注
    if (!empty($action_info['log'])) {
        if (preg_match_all('/\\[(\\S+?)\\]/', $action_info['log'], $match)) {
            $log['user'] = $user_id;
            $log['record'] = $record_id;
            $log['model'] = $model;
            $log['time'] = NOW_TIME;
            $log['data'] = array('user' => $user_id, 'model' => $model, 'record' => $record_id, 'time' => NOW_TIME);
            foreach ($match[1] as $value) {
                $param = explode('|', $value);
                if (isset($param[1])) {
                    $replace[] = call_user_func($param[1], $log[$param[0]]);
                } else {
                    $replace[] = $log[$param[0]];
                }
            }
            $data['remark'] = str_replace($match[0], $replace, $action_info['log']);
        } else {
            $data['remark'] = $action_info['log'];
        }
    } else {
        // 未定义日志规则,记录操作url
        $data['remark'] = '操作url:' . $_SERVER['REQUEST_URI'];
    }
    M('ActionLog')->add($data);
    if (!empty($action_info['rule'])) {
        // 解析行为
        $rules = parse_action($action, $user_id);
        // 执行行为
        $res = execute_action($rules, $action_info['id'], $user_id);
    }
}
示例#3
0
/**
 * 记录行为日志,并执行该行为的规则
 * @param string $action 行为标识
 * @param string $model 触发行为的模型名
 * @param int $record_id 触发行为的记录id
 * @param int $user_id 执行行为的用户id
 * @return boolean
 * @author huajie <*****@*****.**>
 */
function action_log($action = null, $model = null, $record_id = null, $user_id = null)
{
    //参数检查
    if (empty($action) || empty($model) || empty($record_id)) {
        return '参数不能为空';
    }
    if (empty($user_id)) {
        $user_id = is_login();
    }
    //查询行为,判断是否执行
    $action_info = M('Action')->getByName($action);
    if ($action_info['status'] != 1) {
        return '该行为被禁用或删除';
    }
    //插入行为日志
    $data['action_id'] = $action_info['id'];
    $data['user_id'] = $user_id;
    $data['action_ip'] = ip2long(get_client_ip());
    $data['model'] = $model;
    $data['record_id'] = $record_id;
    $data['create_time'] = NOW_TIME;
    //系统日志记录操作url参数
    $data['remark'] = '操作url:' . $_SERVER['REQUEST_URI'];
    M('ActionLog')->add($data);
    if (!empty($action_info['rule'])) {
        //解析行为
        $rules = parse_action($action, $user_id);
        //执行行为
        $res = execute_action($rules, $action_info['id'], $user_id);
    }
}
示例#4
0
    $cmid = required_param('cmid', PARAM_INT);
    $userid = required_param('user', PARAM_INT);
    $filenum = required_param('cn', PARAM_INT);
    $vmsession = required_param('sesseionkey', PARAM_FILE);
    $data = required_param('record_data', PARAM_RAW);
    return array($cmid, $userid, $filenum, $vmsession, $data);
}
/* The function is executed which is passed by get */
function execute_action($valid_parameters, $DB)
{
    $getdata = received_get_data();
    if ($getdata && isset($getdata['methodname'])) {
        $postdata = received_post_data();
        if ($postdata) {
            $function_list = unserialize(Functions_list);
            if (in_array($getdata['methodname'], $function_list)) {
                //call_user_func($getdata['methodname'], $getdata, $postdata, $valid_parameters, $DB);
                $getdata['methodname']($getdata, $postdata, $valid_parameters, $DB);
            } else {
                throw new Exception('There is no ' . $getdata['methodname'] . ' method to execute.');
            }
        }
    } else {
        throw new Exception('There is no method to execute.');
    }
}
set_header();
exit_if_request_is_options();
$validparams = validate_request();
execute_action($validparams, $DB);
示例#5
0
function os_add_meta()
{
    execute_action("os_add_meta");
}
 /**
  * Get and handle HTTP request
  *
  * @param void
  * @return null
  */
 function handleHttpRequest()
 {
     $request = $this->router->match(ANGIE_PATH_INFO, ANGIE_QUERY_STRING);
     if (is_error($request)) {
         handle_fatal_error($request);
     } else {
         $execute =& execute_action($request);
         if (is_error($execute)) {
             handle_fatal_error($execute);
         }
         // if
     }
     // if
 }
示例#7
0
 public function run_action($action)
 {
     return execute_action($action);
 }