Skip to content

Commit

Permalink
Merge pull request #255 from 4x99/develop
Browse files Browse the repository at this point in the history
v1.6.
  • Loading branch information
yoonper authored Mar 10, 2023
2 parents 7319940 + 8d30ba9 commit a2e1e7f
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 70 deletions.
30 changes: 17 additions & 13 deletions app/Console/Commands/JobRunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,23 @@ public function handle()
$this->log->info('Get whitelist success');

while ($job = $this->takeJob()) {
$keyword = $job->keyword;
$this->log->info('Get a job from the queue', ['keyword' => $keyword]);
$configJob = ConfigJob::where('keyword', $keyword)->first();
$configJob->last_scan_at = date('Y-m-d H:i:s');
$page = 1;
do {
$client = $this->service->getClient();
$data = $this->searchCode($client, $keyword, $page);
$count = $this->store($data, $configJob);
$this->log->info('Store record', ['count' => $count]);
$lastResponse = ResponseMediator::getPagination($client->getLastResponse());
} while ($lastResponse['next'] && (++$page <= $configJob->scan_page));
$configJob->save();
try {
$keyword = $job->keyword;
$this->log->info('Get a job from the queue', ['keyword' => $keyword]);
$configJob = ConfigJob::where('keyword', $keyword)->first();
$configJob->last_scan_at = date('Y-m-d H:i:s');
$page = 1;
do {
$client = $this->service->getClient();
$data = $this->searchCode($client, $keyword, $page);
$count = $this->store($data, $configJob);
$this->log->info('Store record', ['count' => $count]);
$lastResponse = ResponseMediator::getPagination($client->getLastResponse());
} while ($lastResponse['next'] && (++$page <= $configJob->scan_page));
$configJob->save();
} catch (Exception $exception) {
$this->log->error($exception->getMessage());
}
$job->delete();
}

Expand Down
17 changes: 12 additions & 5 deletions app/Http/Controllers/CodeLeakController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ public function index(Request $request)
return $query->where('status', $request->input('status'));
});

foreach (['repo_owner', 'repo_name', 'repo_description', 'keyword', 'path'] as $field) {
$query->when($request->input($field), function ($query, $value) use ($field) {
return $query->where($field, 'like', "%$value%");
$query->when($request->input('keyword'), function ($query) use ($request) {
return $query->where('keyword', $request->input('keyword'));
});

$query->when($search = $request->input('search'), function ($query) use ($search) {
$query->where(function ($query) use ($search) {
$query->where('path', 'like', "%$search%");
foreach (['repo_name', 'repo_owner', 'repo_description', 'handle_user', 'description'] as $column) {
$query->orwhere($column, 'like', "%$search%");
}
});
}
});

$perPage = $request->input('limit', 100);
$data = $query->orderByDesc('id')->paginate($perPage);
foreach ($data->items() as &$item){
foreach ($data->items() as &$item) {
$item->repo_description = htmlspecialchars($item->repo_description);
}
return $data;
Expand Down
2 changes: 1 addition & 1 deletion app/Services/NotifyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public function email($title, $content, $config)
{
Config::set('mail', [
'driver' => 'smtp',
'encryption' => 'ssl',
'host' => $config['host'],
'port' => $config['port'] ?? 465,
'username' => $config['username'],
'password' => $config['password'],
'encryption' => $config['encryption'] ?? 'SSL',
]);

try {
Expand Down
22 changes: 12 additions & 10 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/bin/bash

# 项目配置
cp -i .env.example .env
chmod -R 755 storage
chown -R www-data:www-data storage
php artisan key:generate
sed -i "s!DB_HOST=127.0.0.1!DB_HOST=$MYSQL_HOST!" .env
sed -i "s!DB_PORT=3306!DB_PORT=$MYSQL_PORT!" .env
sed -i "s!DB_DATABASE=code6!DB_DATABASE=$MYSQL_DATABASE!" .env
sed -i "s!DB_USERNAME=!DB_USERNAME=$MYSQL_USERNAME!" .env
sed -i "s!DB_PASSWORD=!DB_PASSWORD=$MYSQL_PASSWORD!" .env
php artisan migrate --force
if [ ! -e '.env' ];then
cp -i .env.example .env
chmod -R 755 storage
chown -R www-data:www-data storage
php artisan key:generate
sed -i "s!DB_HOST=127.0.0.1!DB_HOST=$MYSQL_HOST!" .env
sed -i "s!DB_PORT=3306!DB_PORT=$MYSQL_PORT!" .env
sed -i "s!DB_DATABASE=code6!DB_DATABASE=$MYSQL_DATABASE!" .env
sed -i "s!DB_USERNAME=!DB_USERNAME=$MYSQL_USERNAME!" .env
sed -i "s!DB_PASSWORD=!DB_PASSWORD=$MYSQL_PASSWORD!" .env
php artisan migrate --force
fi

# 配置任务调度
service cron start
Expand Down
4 changes: 4 additions & 0 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ textarea::-webkit-input-placeholder, input::-webkit-input-placeholder {
background: url(../image/icon/email.png) no-repeat;
}

.icon-excel {
background: url(../image/icon/excel.png) no-repeat;
}

.icon-feishu {
background: url(../image/icon/feishu.png) no-repeat;
}
Expand Down
Binary file added public/image/icon/excel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions public/js/extjs/plugin/export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* 导出数据
*/
Ext.define('plugin.export', {
extend: 'Ext.Button',
text: '导出数据',
iconCls: 'icon-excel',
onClick: function () {
var data = this.getData();
this.saveCsv(data);
},
// 读取数据
getData: function () {
var header = [], value = [];
var grid = this.up('gridpanel');
var store = grid.store;
var columns = grid.columns ? grid.columns : grid.columnManager.columns;
Ext.each(store.getData().items, function (record, index) {
var row = [];
if (store.filters && !store.filters.filterFn(record)) {
return true;
}
Ext.each(columns, function (column) {
if (column.hidden || column.xtype === 'widgetcolumn') {
return true;
}
if (index === 0) {
header.push(column.text);
}
var value = record.get(column.dataIndex);
if (column.renderer) {
value = column.renderer(value, {}, record);
}
value = String(value).replace(/\n+|(<br\s*\/?>)+/ig, ' '); // 去除换行
value = Ext.util.Format.stripTags(value);
row.push(`"${value}"`);
});
value.push(row.join(','));
});
return header.join(',') + '\n' + value.join('\n');
},
// 保存 CSV 文件
saveCsv: function (data) {
const blob = new Blob([data], {type: 'text/csv'});
const url = window.URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url;
a.download = Ext.Date.format(new Date(), 'YmdHis') + '.csv'
a.click()
a.remove();
}
});
2 changes: 1 addition & 1 deletion public/js/extjs/plugin/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Ext.define('plugin.grid', {
displayInfo: true,
listeners: {
change: function (obj) {
let view = obj.up('grid').getView();
var view = obj.up('grid').getView();
if (typeof(view.scrollTo) == 'function') {
view.scrollTo(0, 0);
}
Expand Down
60 changes: 32 additions & 28 deletions resources/views/codeLeak/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,49 +50,27 @@
format: 'Y-m-d',
maxValue: new Date(),
emptyText: '开始日期',
width: 110,
width: 120,
},
{
xtype: 'datefield',
name: 'edate',
format: 'Y-m-d',
maxValue: new Date(),
emptyText: '结束日期',
width: 110,
width: 120,
},
{
xtype: 'combo',
valueField: 'value',
width: 65,
width: 120,
name: 'status',
emptyText: '状态',
store: {data: status}
},
{
xtype: 'textfield',
name: 'repo_owner',
emptyText: '用户名',
},
{
xtype: 'textfield',
name: 'repo_name',
emptyText: '仓库名',
},
{
xtype: 'textfield',
name: 'path',
emptyText: '文件路径',
width: 130,
},
{
xtype: 'textfield',
name: 'repo_description',
emptyText: '仓库描述',
width: 130,
},
{
xtype: 'combo',
width: 150,
width: 120,
name: 'keyword',
displayField: 'keyword',
valueField: 'keyword',
Expand All @@ -110,6 +88,12 @@
},
},
},
{
xtype: 'textfield',
width: 380,
name: 'search',
emptyText: '用户名 / 仓库名 / 文件路径 / 仓库描述 / 处理人 / 说明',
},
{
xtype: 'buttongroup',
baseCls: '',
Expand Down Expand Up @@ -202,6 +186,25 @@
}
]
},
dockedItems: [
{
xtype: 'pagingtoolbar',
dock: 'bottom',
displayInfo: true,
items: [
'-',
Ext.create('plugin.export'),
],
listeners: {
change: function (obj) {
let view = obj.up('grid').getView();
if (typeof (view.scrollTo) == 'function') {
view.scrollTo(0, 0);
}
}
}
}
],
columns: [
{
text: 'ID',
Expand Down Expand Up @@ -461,7 +464,7 @@ function winForm(value, handler, modal) {
return Ext.create('Ext.window.Window', {
title: '编辑信息',
iconCls: 'icon-add',
width: 350,
width: 600,
modal: modal,
layout: 'fit',
items: [
Expand All @@ -473,8 +476,9 @@ function winForm(value, handler, modal) {
{
fieldLabel: '说明',
name: 'description',
xtype: 'textfield',
xtype: 'textareafield',
value: value,
fieldStyle: 'min-height:150px',
}
],
buttons: [
Expand Down
26 changes: 15 additions & 11 deletions resources/views/configNotify/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@
iconCls: 'icon-email',
items: [
createEnableField('email'),
{
xtype: 'combo',
name: 'encryption',
fieldLabel: '加密方式',
store: {data: [{text: 'SSL'}, {text: 'TLS'}]},
queryMode: 'local',
valueField: 'text',
typeAhead: true,
editable: false,
value: getConfig('email.value.encryption', 'SSL'),
},
{
xtype: 'combo',
name: 'host',
fieldLabel: '',
fieldLabel: '<div style="display:inline-block;margin:0 8px">务</div>',
store: {
data: [
{text: 'smtp.qq.com'},
Expand All @@ -48,14 +59,6 @@
value: getConfig('email.value.port', 465),
allowBlank: true,
allowDecimals: false,
listeners: {
render: function (c) {
Ext.QuickTips.register({
target: c.getEl(),
text: '已启用 SSL 协议,通常使用 465 而非 25 端口',
});
}
}
},
{
name: 'username',
Expand All @@ -75,6 +78,7 @@
fieldLabel: '接收邮箱',
emptyText: '支持多个邮箱(一行一个)',
value: getConfig('email.value.to'),
fieldStyle: 'min-height:50px',
},
createIntervalField('email'),
createTimeField('email'),
Expand Down Expand Up @@ -225,7 +229,7 @@
type: 'help',
tooltip: '企业微信文档',
handler: function () {
tool.winOpen('https://developer.work.weixin.qq.com/document/path/90372');
tool.winOpen('https://developer.work.weixin.qq.com/document/path/91770');
}
}],
items: [
Expand Down Expand Up @@ -498,7 +502,7 @@ function winFormTemplate() {
layout: 'form',
columnWidth: 1 / 3,
margin: 10,
height: 450,
height: 470,
bodyPadding: 20,
bodyStyle: 'background:#FAFAFA',
},
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.3
1.6.4

0 comments on commit a2e1e7f

Please sign in to comment.