forked from aaPanel/BaoTa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanel_php_run.php
157 lines (136 loc) · 4.19 KB
/
panel_php_run.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
// +-------------------------------------------------------------------
// | 宝塔Linux面板
// +-------------------------------------------------------------------
// | Copyright (c) 2015-2099 宝塔软件(http://bt.cn) All rights reserved.
// +-------------------------------------------------------------------
// | Author: 黄文良 <[email protected]>
// +-------------------------------------------------------------------
// +-------------------------------------------------------------------
// | PHP插件前置处理模块
// +-------------------------------------------------------------------
class bt_panel_plugin
{
//启动PHP插件
public function run(){
$this->init();
return $this->plugin_main();
}
//初始化插件环境
private function init(){
//获取命令行参数
$args_arr = getopt('',array('plugin_name:','args_tmp:','fun:'));
if(!$args_arr['plugin_name']){
return_status(false,'指定插件不存在!');
}
if(!$args_arr['args_tmp']){
return_status(false,'请传入正确的参数位置!');
}
//初始化插件配置
define('PLU_PATH', '/www/server/panel/plugin/'.trim($args_arr['plugin_name']));
define('PLU_NAME',trim($args_arr['plugin_name']));
define('PLU_ARGS_TMP', trim($args_arr['args_tmp']));
define('PLU_FUN',trim($args_arr['fun']));
//检查
if(!file_exists(PLU_PATH.'/index.php')) return_status(false,'指定插件不存在!');
if(!preg_match("/^[\w-]+$/",PLU_FUN)) return_status(false,'指定方法不存在!');
chdir(PLU_PATH);
}
//调用插件主程序
private function plugin_main(){
include_once PLU_PATH . '/index.php';
if(!class_exists('bt_main')) return_status(false,'没有找到bt_main类');
$plu = new bt_main();
if(!method_exists($plu, PLU_FUN)) return_status(false,'指定方法不存在');
return call_user_func(array($plu,PLU_FUN));
}
}
class db extends SQLite3
{
function __construct($db_file = '/www/server/panel/data/default.db')
{
$this->open($db_file);
}
public function queryute($sql){
$result = $this->query($sql);
$data = $result->fetchArray(SQLITE3_ASSOC);
return $data;
}
public function execute(){
$result = $this->exec($sql);
return $result;
}
}
//取指安参数
function _args($_t,$key){
if(!file_exists(PLU_ARGS_TMP)) {
if($key) return null;
return array();
}
$args_tmp = json_decode(file_get_contents(PLU_ARGS_TMP),1);
if($key){
if(!array_key_exists($key, $args_tmp[$_t])) return false;
return $args_tmp[$_t][$key];
}
return $args_tmp[$_t];
}
function _version(){
$comm_body = file_get_contents('/www/server/panel/class/common.py');
preg_match("/g\.version\s*=\s*'(\d+\.\d+\.\d+)'/",$comm_body,$m_version);
return $m_version[1];
}
//取GET参数
function _get($key = null){
return _args('GET',$key);
}
//取POST参数
function _post($key=null){
return _args('POST',$key);
}
//通用返回状态
function return_status($status,$msg){
exit(json_encode(array('status'=>$status,'msg'=>$msg)));
}
//返回数据
function _return($data){
exit(json_encode($data));
}
/**
* 发起GET请求
* @param String $url 目标网填,带http://
* @return bool
*/
function _httpGet($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 6);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Accept-Encoding: gzip, deflate'));
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_USERAGENT, "BT-Panel for PHP-Plugin");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 3);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
//发起POST请求
function _httpPost($url,$data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "BT-Panel for PHP-Plugin");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
//启动插件
$p = new bt_panel_plugin();
_return($p->run());
?>