This page lists files in the current directory. You can view content, get download/execute commands for Wget, Curl, or PowerShell, or filter the list using wildcards (e.g., `*.sh`).
wget 'https://sme10.lists2.roe3.org/kodbox/plugins/msgWarning/lib/evntApi.class.php'
<?php
/**
* 通知事件
*/
class evntApi {
protected $plugin;
protected $pluginName;
function __construct($plugin) {
$this->plugin = $plugin;
$this->pluginName = $plugin->pluginName;
require_once(__DIR__ .'/data/ntc.evnt.php');
}
public function getAppConfig($key=false, $def=null){
$config = $this->plugin->getConfig();
return isset($key) ? _get($config, $key, $def) : $config;
}
public function setAppConfig($value){
$this->plugin->setConfig($value);
}
/**
* 初始化通知事件(写入数据库)
* @return void
*/
public function initData() {
$list = NtcEvnt::listData();
$data = $this->getAppConfig('ntcEvntList', array());
$update = array();
foreach ($list as $item) {
$event = $item['event'];
if (isset($data[$event])) continue;
if (!$item['policy']) $item['policy'] = array();
$policy = array();
foreach ($item['policy'] as $key => $value) {
if (!isset($value['value'])) continue;
$policy[$key] = $value['value'];
}
$update[$event] = array(
// 'type' => $item['type'], // 通知方式
'status' => $item['status'],// 事件状态
'policy' => $policy, // 通知策略
'notice' => $item['notice'],// 通知设置
'result' => array(
'cntToday' => 0,
'cntTotal' => 0,
'ntcTime' => 0,
'tskTime' => 0,
), // 通知结果
);
}
if (!empty($update)) {
$this->setAppConfig(array('ntcEvntList' => array_merge($data, $update)));
}
}
/**
* 通知事件列表:获取全部(包含详情),用于通知任务执行
* @return void
*/
public function listData() {
$list = $this->get(array(), true);
foreach ($list as &$item) {
$policy = array();
foreach ($item['policy'] as $key => $val) {
if (!$val || !isset($val['value'])) continue;
$policy[$key] = $val['value'];
}
$item['policy'] = $policy;
}
unset($item);
return $list;
}
/**
* 通知事件列表
* @return void
*/
public function get($req, $ret=false){
$list = NtcEvnt::listData();
// 获取追加事件
$list = Hook::filter('msgWarning.evnt.list', $list);
$this->evntListFilter($list);
// 筛选条件
$where = array();
if ($req['class'] && $req['class'] != 'all') {
$where['class'] = $req['class'];
}
if ($req['level'] && $req['level'] != 'all') {
$where['level'] = intval(str_replace('level','',$req['level']));
}
if (isset($req['status']) && $req['status'] != 'all') {
$where['status'] = $req['status'] == '1' ? 1 : 0;
}
// 查询详情,覆盖更新
$data = $this->getAppConfig('ntcEvntList', array());
$update = array();
foreach ($list as $i => &$item) {
$event = $item['event'];
// 赋值
$dbopt = _get($data, $event, array());
foreach ($dbopt['policy'] as $key => $value) {
if (!isset($item['policy'][$key])) continue;
$item['policy'][$key]['value'] = $value;
}
foreach ($dbopt['notice'] as $key => $value) {
if (!isset($item['notice'][$key])) continue;
$item['notice'][$key] = $value;
}
$item['result'] = array(
'cntToday' => intval(_get($dbopt, 'result.cntToday', 0)),
'cntTotal' => intval(_get($dbopt, 'result.cntTotal', 0)),
'ntcTime' => intval(_get($dbopt, 'result.ntcTime', 0)),
'tskTime' => intval(_get($dbopt, 'result.tskTime', 0)),
);
if (isset($dbopt['status'])) {
$item['status'] = $dbopt['status'];
}
// // 解析通知方式
// if (!$ret) $this->parseEvntType($item);
// 重置今日通知次数
if ($item['result']['ntcTime'] < strtotime('today') && $item['result']['cntToday'] > 0) {
$item['result']['cntToday'] = $dbopt['result']['cntToday'] = 0;
$update[$event] = $dbopt;
}
// 前端请求,按条件过滤
foreach (array('class','level','status') as $key) {
if (isset($where[$key]) && $item[$key] != $where[$key]) {
unset($list[$i]);
}
}
}
// 重置今日通知次数
if (!empty($update)) {
$this->setAppConfig(array('ntcEvntList' => array_merge($data, $update)));
}
$list = array_values($list);
if ($ret) return $list;
show_json(array('list' => $list));
}
// 获取通知方式名称——弃用
private function parseEvntType(&$item) {
static $list;
if (!$list) {
// require_once(__DIR__ .'/data/ntc.type.php');
// $list = NtcType::listData();
// $list = array_to_keyvalue($list, 'type', 'name');
$data = $this->plugin->loadLib('type')->listData();
$list = array();
foreach ($data as $value) {
if (!$value['status']) continue;
$list[$value['type']] = $value['name'];
}
}
$method = _get($item,'notice.method',''); // 通知方式
$mtdArr = explode(',', $method);
foreach ($mtdArr as &$mthd) {
// $mthd = _get($list, $mthd, $mthd);
$mthd = _get($list, $mthd, '');
}
$item['type'] = $method; // 为与前端统一,这里保留原始值
$item['typeText'] = implode(',', $mtdArr);
$item['typeList'] = $list; // 获取可用的通知方式列表
}
// 过滤不支持的通知事件
private function evntListFilter(&$list) {
$plugin = Model('Plugin')->loadList('oemCockpit');
if ($plugin && $plugin['status'] == '1') return;
// 非teamos,排除硬件类、及文件系统检测、默认存储设置通知
foreach ($list as $i => $item) {
if ($item['class'] == 'dev' || in_array($item['event'], array('svrFileSysErr','sysStoreDefErr'))) {
unset($list[$i]);
}
}
}
/**
* 通知事件操作
* @return void
*/
public function action ($req) {
$action = $req['action'];
switch ($action) {
case 'getConfig':
$this->getConfig($req);
break;
case 'setConfig':
$this->setConfig($req);
break;
case 'getRawData':
$this->getRawData($req);
break;
default:break;
}
show_json(LNG('common.illegalRequest'), false);
}
/**
* 通知事件信息获取
* @return void
*/
public function getConfig($req) {
}
/**
* 通知事件信息保存
* @return void
*/
public function setConfig($req, $ret=false) {
$event = $req['event'];
$data = _get($req, 'data', array());
if (!is_array($data)) $data = json_decode($data,true);
// 前端提交且为详情保存,检查参数——启/禁用不处理
if (!$ret && isset($data['notice'])) {
$timeFreq = intval(_get($data, 'notice.timeFreq', 0));
if (in_array($event, array('svrCpuErr','svrMemErr'))) {
if ($timeFreq < intval(_get($data, 'policy.useTime', 0))) {
show_json(LNG('msgWarning.evnt.freqLsUseTimeErr'), false);
}
}
$info = $this->getRawList($event);
$taskFreq = _get($info, 'taskFreq', 0);
if ($timeFreq < $taskFreq) {
show_json(sprintf(LNG('msgWarning.evnt.freqLsTimeErr'), $taskFreq), false);
}
}
// 获取列表,覆盖对应项
$list = $this->getAppConfig('ntcEvntList', array());
if (!isset($list[$event])) $list[$event] = array();
// // TODO 启用状态会被覆盖,可能来自计划任务,待确认
// write_log(array('更新evnt---',$req, $list[$event],get_caller_info()), 'msgwarning');
$list[$event] = array_merge($list[$event], $data);
// write_log(array('更新evnt2---',$req, $list[$event]), 'msgwarning');
$this->setAppConfig(array('ntcEvntList'=>$list));
if ($ret) return true;
show_json(LNG('explorer.success'), true);
}
/**
* 获取通知事件列表原始数据——目前仅通知方式,后续可按需扩展
* @param [type] $req
* @return void
*/
public function getRawData($req, $ret=false) {
$list = $this->getRawList();
foreach ($list as &$item) {
$item = $item['notice']['method'];
};unset($item);
show_json($list);
}
private function getRawList($event=false){
$list = NtcEvnt::listData();
$data = array();
foreach ($list as $item) {
$data[$item['event']] = $item;
}
return $event ? $data[$event] : $data;
}
}
wget 'https://sme10.lists2.roe3.org/kodbox/plugins/msgWarning/lib/logsApi.class.php'
<?php
/**
* 通知日志
*/
class logsApi {
protected $plugin;
protected $pluginName;
protected $tableName;
function __construct($plugin) {
$this->plugin = $plugin;
$this->pluginName = $plugin->pluginName;
$this->tableName = 'plugin_msgwarning_log';
}
public function getAppConfig($key=false, $def=null){
$config = $this->plugin->getConfig();
return isset($key) ? _get($config, $key, $def) : $config;
}
public function setAppConfig($value){
$this->plugin->setConfig($value);
}
/**
* 初始化日志表
* @return void
*/
public function initTable() {
if ($this->getAppConfig('initDbTable')) return;
// 判断插件表是否已存在,不存在则新建
$tables = Model()->db()->getTables();
if (in_array($this->tableName, $tables)) {
return $this->setAppConfig(array('initDbTable' => 1));
}
$path = __DIR__.'/data/plugin_msgwarning_log.sql';
if(stristr($GLOBALS['config']['database']['DB_TYPE'],'sqlite')){
$path = __DIR__.'/data/plugin_msgwarning_log.sqlite.sql';
}
$sqlArr = sqlSplit(file_get_contents($path));
foreach($sqlArr as $sql){
$result = Model()->db()->execute($sql);
}
$this->setAppConfig(array('initDbTable' => 1));
}
/**
* 通知日志列表
* @return void
*/
public function get($req) {
$this->initTable();
$page = _get($req, 'page', 1);
$pageNum = _get($req, 'pageNum', 50);
$where = array();
$time = _get($req, 'time', 30); // 默认近30天
if ($time != 'all') {
if ($time == 'diy') {
$timeFrom = strtotime($req['timeFrom']);
$timeTo = strtotime($req['timeTo'].' 23:59:59');
} else {
$timeFrom = strtotime(date('Y-m-d', strtotime('-'.$time.' days')));
$timeTo = strtotime(date('Y-m-d 23:59:59'));
}
$where['createTime'] = array('between', array($timeFrom, $timeTo));
}
$result = Model($this->tableName)->where($where)->order('createTime desc')->selectPage($pageNum, $page);
if (empty($result['list'])) show_json($result);
$evntList = $this->plugin->loadLib('evnt')->listData();
$evntList = array_to_keyvalue($evntList, 'event', 'title');
$userArray = array_to_keyvalue($result['list'], '', 'userID');
$userArray = Model('User')->userListInfo(array_unique($userArray));
foreach ($result['list'] as &$item) {
$item['title'] = _get($evntList, $item['event'], '');
$item['userInfo'] = _get($userArray, $item['userID'], array());
}
unset($item);
show_json($result);
}
/**
* 写入通知日志
* @param [type] $data
* @return void
*/
public function add($data){
// 日志:通知事件、通知对象、通知方式、通知结果、通知时间
$data = array(
'event' => _get($data, 'event', ''),
'userID' => _get($data, 'userID', 0),
'method' => _get($data, 'method', ''), // 通知方式
'target' => _get($data, 'target', ''), // 通知目标(联系方式)
'status' => _get($data, 'status', 0), // 通知结果状态
'desc' => _get($data, 'desc', ''), // 通知结果详情
'createTime'=> time()
);
Model($this->tableName)->setDataAuto(false); // 取消自动处理字段
return Model($this->tableName)->add($data);
}
}
wget 'https://sme10.lists2.roe3.org/kodbox/plugins/msgWarning/lib/typeApi.class.php'
<?php
/**
* 通知方式
*/
class typeApi {
protected $plugin;
protected $pluginName;
function __construct($plugin) {
$this->plugin = $plugin;
$this->pluginName = $plugin->pluginName;
}
public function getAppConfig($key=false, $def=null){
$config = $this->plugin->getConfig();
return isset($key) ? _get($config, $key, $def) : $config;
}
public function setAppConfig($value){
$this->plugin->setConfig($value);
}
/**
* 获取通知方式列表
* @return void
*/
public function listData() {
return $this->get(array(), true);
}
/**
* 通知方式列表
* @return void
*/
public function get($req, $ret=false){
require_once(__DIR__ .'/data/ntc.type.php');
$list = NtcType::listData();
// 查询状态,覆盖更新
foreach ($list as &$item) {
$type = $item['type'];
if (in_array($type, array('ktips', 'kwarn'))) continue;
$this->typeUpdate($type, $item);
}
if ($ret) return $list;
show_json(array('list'=>$list));
}
// 通知方式项检测更新
private function typeUpdate($type, &$item){
switch ($type) {
case 'email':
$this->checkEmail($item);
break;
case 'sms':
$this->checkSms($item);
break;
case 'weixin':
case 'dding':
$this->check3rdMsg($type, $item);
if ($item['data'] == '1') {
$list = $this->getAppConfig('ntcTypeList', array());
$item['status'] = intval($list[$type]);
}
break;
default: break;
}
}
// 检查邮箱
private function checkEmail(&$item){
$model = Model('systemOption');
$type = $model->get('emailType');
if ($type != '1') return;
$info = $model->get('email');
if (empty($info)) return;
$stat = 1;
foreach (array('smtp','host','email','password') as $key) {
if (empty($info[$key])) {
$stat = 0; break;
}
}
$item['data'] = $stat;
}
// 检查短信;后续考虑增加自定义模板以适应自定义通知事件
private function checkSms(&$item){
if (Model('SystemOption')->get('versionType') == 'A') return;
$item['status'] = 1; // 默认启用
$plugin = Model('Plugin')->loadList('smsGateway');
if (!$plugin || $plugin['status'] != '1') return;
$data = array('aliSecretId', 'aliSecretKey', 'aliSignName', 'aliTplCode', 'length');
if (_get($plugin, 'config.type', 'ali') == 'tx') {
$data = array('txAppID', 'txSecretId', 'txSecretKey', 'txSignName', 'txTplCode', 'length');
}
$stat = 1;
foreach ($data as $key) {
if (empty($plugin['config'][$key])) {
$stat = 0; break;
}
}
$item['data'] = $stat;
}
// 检查第三方同步消息(钉钉、企业微信);依赖msgGateway插件,后续可以整合到此(同时调整调用处)
private function check3rdMsg($type, &$item){
if (Model('SystemOption')->get('versionType') == 'A') return;
$plugin = Model('Plugin')->loadList('msgGateway');
if (!$plugin || $plugin['status'] != '1') return;
if (_get($plugin, 'config.isOpen', 0) != '1') return;
$appList = array(
'weixin'=> 'weChat',
'dding' => 'dingTalk',
);
if (_get($plugin, 'config.type') != $appList[$type]) return;
$item['data'] = 1;
// $item['status'] = 1; // 前端启/禁用
}
/**
* 通知方式操作
* @return void
*/
public function action ($req) {
$action = $req['action'];
switch ($action) {
case 'getConfig':
$this->getConfig($req);
break;
case 'setConfig':
$this->setConfig($req);
break;
default:break;
}
show_json(LNG('common.illegalRequest'), false);
}
/**
* 通知方式配置信息获取——仅邮件
* @return void
*/
public function getConfig($req) {
if ($req['type'] != 'email') {
show_json(LNG('explorer.share.errorParam'), false);
}
$emailType = Model('systemOption')->get('emailType');
$email = Model('systemOption')->get('email');
$data = array('type' => intval($emailType));
if (!$email) $email = array();
$data = array_merge($data, $email);
show_json($data);
}
/**
* 通知方式配置信息保存
* @return void
*/
public function setConfig($req) {
$type = $req['type'];
$data = json_decode($req['data'],true);
if (!in_array($type, array('sms','email','weixin','dding')) || empty($data)) {
show_json(LNG('explorer.share.errorParam'), false);
}
// 邮件、短信
if ($type == 'sms') show_json(LNG('explorer.success'));
if ($type == 'email') {
Model('systemOption')->set('emailType', $data['type']);
unset($data['type'],$data['tested']);
Model('systemOption')->set('email', $data);
show_json(LNG('explorer.success'));
}
// 企业微信、钉钉
$status = intval($data['status']);
$item = array('status'=>$status);
if ($status === 1) {
$this->check3rdMsg($type, $item);
if ($item['data'] != 1) {
show_json(LNG('msgWarning.type.setAppFirst'), false);
}
}
$list = $this->getAppConfig('ntcTypeList', array());
$list[$type] = $status;
$this->setAppConfig(array('ntcTypeList'=>$list));
show_json(LNG('explorer.success'), true);
}
}