Skip to content

Commit 7dce4a2

Browse files
committed
Merge branch 'develop' into main
2 parents a5614c0 + 81758ca commit 7dce4a2

39 files changed

+2104
-1007
lines changed

code/app/command/Scan.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected function execute(Input $input, Output $output)
9898
} elseif ($func == 'reptile') {
9999
UrlsModel::reptile();
100100
} elseif ($func == 'getProjectComposer') {
101-
CodeModel::getProjectComposer();
101+
CodeModel::code_php();
102102
} elseif ($func == 'code_python') {
103103
PythonLibraryModel::code_python();
104104
} elseif ($func == 'code_java') {

code/app/common.php

Lines changed: 165 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function getDirFileName($path): array
114114
function getParam($key, $default = null)
115115
{
116116

117-
$paramAll = array_merge($_GET, $_POST);
117+
$paramAll = array_merge(getallheaders(), $_GET, $_POST);
118118
foreach ($paramAll as &$value) {
119119
if (is_string($value)) {
120120
$value = addslashes($value);
@@ -930,6 +930,157 @@ function getFilePath($dir, $filename, $level = 1)
930930
return $files;
931931
}
932932

933+
function getUninstallPath($name)
934+
{
935+
$app = \think\facade\App::getAppPath();
936+
// 获取sql或sh中符号的数据
937+
$sqlOrsh = [];
938+
$sqlOrsh_path = $app . '/plugins/';
939+
foreach (scandir($sqlOrsh_path) as $value) {
940+
if ($value != '.' && $value != '..') {
941+
$preg = "/^{$name}(.*?)/";
942+
if (preg_match($preg, $value)) {
943+
$sqlOrsh[] = $sqlOrsh_path . $value;
944+
}
945+
}
946+
}
947+
948+
// 获取controller中符合的数据
949+
$controller = [];
950+
$controller_path = $app . 'controller/';
951+
foreach (scandir($controller_path) as $value) {
952+
if ($value != '.' && $value != '..') {
953+
$preg = "/^{$name}(.*?)Plugin\.php/";
954+
if (preg_match($preg, $value)) {
955+
$controller[] = $controller_path . $value;
956+
}
957+
}
958+
}
959+
// 获取model中符合的数据
960+
$model = [];
961+
$model_path = $app . 'model/';
962+
foreach (scandir($model_path) as $value) {
963+
if ($value != '.' && $value != '..') {
964+
$preg = "/^{$name}(.*?)PluginModel\.php/";
965+
if (preg_match($preg, $value)) {
966+
$model[] = $model_path . $value;
967+
}
968+
}
969+
}
970+
$name = cc_format($name);
971+
972+
// 获取view中符合的数据
973+
$view = [];
974+
$view_path = \think\facade\App::getRootPath() . 'view/';
975+
foreach (scandir($view_path) as $value) {
976+
if ($value != '.' && $value != '..') {
977+
$preg = "/^{$name}(.*?)_plugin/";
978+
if (preg_match($preg, cc_format($value))) {
979+
$view[] = $view_path . $value;
980+
}
981+
}
982+
}
983+
// 获取tools工具中符合的数据
984+
$tools = [];
985+
//$tools_path = '/data/tools/plugins/';
986+
$tools_path = $app . '../../tools/plugins/';
987+
foreach (scandir($tools_path) as $value) {
988+
if ($value != '.' && $value != '..') {
989+
$preg = "/^{$name}(.*?)/";
990+
if (preg_match($preg, cc_format($value))) {
991+
$tools[] = $tools_path . $value;
992+
}
993+
}
994+
}
995+
996+
return array_merge($sqlOrsh, $controller, $model, $view, $tools);
997+
}
998+
999+
function deldir($path)
1000+
{
1001+
//如果是目录则继续
1002+
if (is_dir($path)) {
1003+
//扫描一个文件夹内的所有文件夹和文件并返回数组
1004+
$p = scandir($path);
1005+
//如果 $p 中有两个以上的元素则说明当前 $path 不为空
1006+
if (count($p) > 2) {
1007+
foreach ($p as $val) {
1008+
//排除目录中的.和..
1009+
if ($val != "." && $val != "..") {
1010+
//如果是目录则递归子目录,继续操作
1011+
if (is_dir($path . $val)) {
1012+
//子目录中操作删除文件夹和文件
1013+
deldir($path . $val . '/');
1014+
} else {
1015+
//如果是文件直接删除
1016+
@unlink($path . '/' . $val);
1017+
}
1018+
}
1019+
}
1020+
}
1021+
}
1022+
//删除目录
1023+
return rmdir($path);
1024+
}
1025+
1026+
1027+
function downloadFile($url, $save_dir = '', $filename = '', $type = 0)
1028+
{
1029+
if (trim($save_dir) == '') {
1030+
$save_dir = './';
1031+
}
1032+
if (0 !== strrpos($save_dir, '/')) {
1033+
$save_dir .= '/';
1034+
}
1035+
//创建保存目录
1036+
if (!file_exists($save_dir) && !mkdir($save_dir, 0777, true)) {
1037+
return '保存目录创建失败';
1038+
}
1039+
//获取远程文件所采用的方法
1040+
$ch = curl_init();
1041+
$timeout = 5;
1042+
curl_setopt($ch, CURLOPT_URL, $url);
1043+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1044+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
1045+
$content = curl_exec($ch);
1046+
//如果有异常,记录到日志当中
1047+
$curl_errno = curl_errno($ch);
1048+
if ($curl_errno > 0) {
1049+
return curl_error($ch);
1050+
}
1051+
curl_close($ch);
1052+
//文件大小
1053+
$fp2 = @fopen($save_dir . $filename, 'a');
1054+
fwrite($fp2, $content);
1055+
fclose($fp2);
1056+
unset($content, $url);
1057+
return true;
1058+
}
1059+
1060+
/*
1061+
* $dirsrc 原目录
1062+
* $dirto 目标目录
1063+
*/
1064+
function copydir($dirsrc, $dirto)
1065+
{
1066+
if (!file_exists($dirto)) {
1067+
mkdir($dirto);
1068+
}
1069+
$dir = opendir($dirsrc);
1070+
while ($filename = readdir($dir)) {
1071+
if ($filename != "." && $filename != "..") {
1072+
$srcfile = $dirsrc . "/" . $filename; //原文件
1073+
$tofile = $dirto . "/" . $filename; //目标文件
1074+
if (is_dir($srcfile)) {
1075+
copydir($srcfile, $tofile); //递归处理所有子目录
1076+
} else {
1077+
//是文件就拷贝到目标目录
1078+
copy($srcfile, $tofile);
1079+
}
1080+
}
1081+
}
1082+
}
1083+
9331084
// 大写字母转"_"下划线
9341085
function cc_format($name)
9351086
{
@@ -1013,6 +1164,18 @@ function readCsv($uploadfile = '')
10131164
return $data;
10141165
}
10151166

1167+
/**
1168+
* 获取code表信息
1169+
* @param int $id
1170+
* @return array|mixed|Db|\think\Model|null
1171+
* @throws \think\db\exception\DataNotFoundException
1172+
* @throws \think\db\exception\DbException
1173+
* @throws \think\db\exception\ModelNotFoundException
1174+
*/
1175+
function getCodeInfo(int $id)
1176+
{
1177+
return Db::table("code")->where(['id' => $id])->find();
1178+
}
10161179

10171180
//转码
10181181
function iconv_gbk_to_uft8($string)
@@ -1036,7 +1199,7 @@ function getScanStatus($appId, $pluginName, $scanType = 0)
10361199
return "$pluginName 任务在{$result[1]['create_time']}扫描失败:{$result[1]['content']}";
10371200
} elseif (count($result) == 2 && $result[1]['log_type'] == 1) {
10381201
return "$pluginName 任务在{$result[1]['create_time']}扫描成功,但无有效结果:{$result[1]['content']}";
1039-
} else{
1202+
} else {
10401203
// var_dump($result);exit;
10411204

10421205
}

code/app/controller/Api.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function addFortify(){
175175
if (!$this->isMyCode()) {
176176
return $this->apiReturn(0, [], '项目信息不存在');
177177
}
178-
$project_id = getParam('code_id');
178+
$code_id = getParam('code_id');
179179
$Category = getParam('category');
180180
$Folder = getParam('folder');
181181
$Kingdom = getParam('kingdom');
@@ -187,7 +187,7 @@ public function addFortify(){
187187
$Source_filename = getParam('source_filename');
188188
$Primary_filename = getParam('primary_filename');
189189
$hash = getParam('hash');
190-
$data['project_id'] = $project_id;
190+
$data['code_id'] = $code_id;
191191
$data['Category'] = $Category;
192192
$data['Folder'] = $Folder;
193193
$data['Kingdom'] = $Kingdom;
@@ -202,7 +202,7 @@ public function addFortify(){
202202
$data['user_id'] = $this->user_id;
203203
$data['create_time'] = date('Y-m-d H:i:s', time());
204204
if (Db::name('fortify')->insert($data)) {
205-
$this->scanTime('code',$project_id,'scan_time');
205+
$this->scanTime('code',$code_id,'scan_time');
206206
return $this->apiReturn(1, [], '数据写入成功');
207207
} else {
208208
addlog('fortify数据写入失败:'.json_encode($data));
@@ -216,7 +216,7 @@ public function addSemgrep(){
216216
return $this->apiReturn(0, [], '项目信息不存在');
217217
}
218218
$check_id = getParam('check_id');
219-
$project_id = getParam('code_id');
219+
$code_id = getParam('code_id');
220220
$end_col = getParam('end_col');
221221
$end_line = getParam('end_line');
222222
$end_offset = getParam('end_offset');
@@ -231,7 +231,7 @@ public function addSemgrep(){
231231
$start_line = getParam('start_line');
232232
$start_offset = getParam('start_offset');
233233
$data['check_id'] = $check_id;
234-
$data['project_id'] = $project_id;
234+
$data['code_id'] = $code_id;
235235
$data['end_col'] = $end_col;
236236
$data['end_line'] = $end_line;
237237
$data['end_offset'] = $end_offset;
@@ -248,7 +248,7 @@ public function addSemgrep(){
248248
$data['user_id'] = $this->user_id;
249249
$data['create_time'] = date('Y-m-d H:i:s', time());
250250
if (Db::name('fortify')->insert($data)) {
251-
$this->scanTime('code',$project_id,'semgrep_scan_time');
251+
$this->scanTime('code',$code_id,'semgrep_scan_time');
252252
return $this->apiReturn(1, [], '数据写入成功');
253253
} else {
254254
addlog('semgrep数据写入失败:'.json_encode($data));

0 commit comments

Comments
 (0)