This commit is contained in:
Chenx221 2024-02-26 17:33:53 +08:00
parent a11d6ed6f9
commit d9573b122f
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
6 changed files with 99 additions and 32 deletions

View File

@ -29,6 +29,9 @@
"fortawesome/font-awesome": "^6.5", "fortawesome/font-awesome": "^6.5",
"ext-zip": "*", "ext-zip": "*",
"ext-rar": "*", "ext-rar": "*",
"ext-json": "*",
"ext-gmp": "*",
"ext-bcmath": "*",
"wapmorgan/unified-archive": "^1.2", "wapmorgan/unified-archive": "^1.2",
"symfony/console": "^6.1", "symfony/console": "^6.1",
"gemorroj/archive7z": "^5.7", "gemorroj/archive7z": "^5.7",
@ -36,7 +39,8 @@
"npm-asset/plyr": "^3.7", "npm-asset/plyr": "^3.7",
"ext-fileinfo": "*", "ext-fileinfo": "*",
"npm-asset/ace-builds": "^1.32", "npm-asset/ace-builds": "^1.32",
"yiisoft/yii2-redis": "^2.0" "yiisoft/yii2-redis": "^2.0",
"ramsey/uuid": "^4.7"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-debug": "~2.1.0", "yiisoft/yii2-debug": "~2.1.0",

View File

@ -4,6 +4,8 @@ namespace app\controllers;
use app\models\CollectionTasks; use app\models\CollectionTasks;
use app\models\CollectionSearch; use app\models\CollectionSearch;
use app\models\CollectionUploaded;
use Ramsey\Uuid\Uuid;
use Yii; use Yii;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
@ -116,4 +118,40 @@ class CollectionController extends Controller
throw new NotFoundHttpException('The requested page does not exist.'); throw new NotFoundHttpException('The requested page does not exist.');
} }
/**
* 外部访问接口接受参数id:收集文件任务id,secret:访问密钥,CollectionTasks[secret]:访问密钥(另一种形式)
*
* @param $id
* @param $secret
* @return string
* @throws NotFoundHttpException
*/
public function actionAccess($id = null, $secret = null)
{
$receive_secret = Yii::$app->request->get('CollectionTasks')['secret'] ?? null;
if (!is_null($receive_secret)) {
$secret = $receive_secret;
}
$model = CollectionTasks::findOne(['id' => $id]);
if ($model === null) {
throw new NotFoundHttpException('请求的文件收集任务不存在');
} elseif ($secret === null) {
return $this->render('gateway', [
'model' => new CollectionTasks(),
]);
} elseif ($model->secret !== $secret) {
Yii::$app->session->setFlash('error', '拒绝访问,凭证不正确');
return $this->render('gateway', [
'model' => new CollectionTasks(),
]);
} else {
$model2 = new CollectionUploaded();
$model2->subfolder_name = Uuid::uuid4()->toString();
return $this->render('access', [
'model' => $model,
'model2' => $model2,
]);
}
}
} }

View File

@ -2,6 +2,7 @@
namespace app\controllers; namespace app\controllers;
use app\models\CollectionTasks;
use app\models\CollectionUploaded; use app\models\CollectionUploaded;
use app\models\CollectionUploadedSearch; use app\models\CollectionUploadedSearch;
use yii\web\Controller; use yii\web\Controller;
@ -30,16 +31,6 @@ class CollectionUploadedController extends Controller
); );
} }
/**
* Lists all CollectionUploaded models.
*
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
/** /**
* Finds the CollectionUploaded model based on its primary key value. * Finds the CollectionUploaded model based on its primary key value.

View File

@ -1,21 +0,0 @@
<?php
use app\models\CollectionUploaded;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\ActionColumn;
use yii\grid\GridView;
/** @var yii\web\View $this */
/** @var app\models\CollectionUploadedSearch $searchModel */
/** @var yii\data\ActiveDataProvider $dataProvider */
$this->title = '文件收集';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="collection-uploaded-index">
<h1><?= Html::encode($this->title) ?></h1>
</div>

View File

@ -0,0 +1,26 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var app\models\CollectionTasks $model */
/** @var app\models\CollectionUploaded $model2 */
$this->title = '文件收集';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="collection-access">
<h1><?= Html::encode($this->title) ?></h1>
<p>
收集任务ID: <?= Html::encode($model->id) ?>
</p>
<p>
访问密钥: <?= Html::encode($model->secret) ?>
</p>
<p>
收集目标文件夹: <?= Html::encode($model2->subfolder_name) ?>
</p>
</div>

View File

@ -0,0 +1,29 @@
<?php
use yii\bootstrap5\ActiveForm;
use yii\helpers\Html;
use yii\helpers\Url;
/** @var yii\web\View $this */
/** @var app\models\CollectionTasks $model */
$this->title = '请输入访问凭证';
$this->params['breadcrumbs'][] = '文件收集';
?>
<div class="collection-gateway">
<h1><?= Html::encode($this->title) ?></h1>
<?php $form = ActiveForm::begin([
'action' => Url::to(['collection/access', 'id' => Yii::$app->request->get('id')]),
'method' => 'get',
]); ?>
<?= $form->field($model, 'secret')->textInput(['maxlength' => true])->label('访问凭证:') ?>
<div class="form-group">
<?= Html::submitButton('提交', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>