dd/app/Http/Controllers/CmdController.php
hellcat 55198846ae 1
2026-07-27 14:41:20 +08:00

143 lines
4.1 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers;
//use App\Models\Book as ModelBook;
//use App\Models\BookOption as ModelBookOption;
use App\Services\TomTool\Http;
use App\Services\TomTool\HttpV2;
use App\Models\DoveSite as ModelDoveSite;
class CmdController
{
public function index()
{
return view("cmd", [
// "aSinge" => $aSinge,
// 'aTagNames' => $aTagsName,
// 'sMenu' => 'client',
]);
}
public function imageUploadExec()
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// 检查文件是否上传成功
if (isset($_FILES['files']) && $_FILES['files']['error'][0] == 0) {
$uploadFileDir = './upload/';
foreach ($_FILES['files']['tmp_name'] as $key => $tmpName) {
$fileName = $_FILES['files']['name'][$key];
$fileError = $_FILES['files']['error'][$key];
// 检查文件上传是否有错误
if ($fileError == 0) {
$dest_path = $uploadFileDir . $fileName;
// 移动文件到目标目录
if (move_uploaded_file($tmpName, $dest_path)) {
echo '文件上传成功: ' . $dest_path . '<br>';
} else {
echo '文件上传失败: ' . $fileName . '<br>';
}
} else {
echo '文件上传错误: ' . $fileName . '<br>';
}
}
} else {
echo '没有文件上传或发生错误。';
}
}
}
public function imageUpload()
{
return view("cmd/image/upload");
}
public function ajaxSend_api($sUrl, $sArg)
{
$aArg = json_decode($sArg, true);
$r = HttpV2::make($sUrl)->optMethod("post")->enableJsonSend()->setData($aArg)->send();
echo $r;
}
public function ajaxSend()
{
$sSite = $_POST["site"];
$sValue = $_POST["value"];
$sHook = $_POST["hook"];
$sArea = $_POST["area"];
$sUser = $_POST["user"];
$sEnterType = $_POST["enterType"];
$sOption = $_POST["option"] ?? '';
if ($sOption == "api" || $sOption == "url") {
return $this->ajaxSend_api($sValue, $sArea);
exit;
}
if ($sHook) {
$sValue = $sHook.$sValue;
}
if ($sEnterType == "area") {
$sValue = trim($sValue)." ".$sArea;
}
$aDoveSiteMap = ModelDoveSite::_getMap();
$sUrl = isset($aDoveSiteMap[$sSite]) ? $aDoveSiteMap[$sSite] : false;
if (!$sUrl) {
return "没有这个dove";
}
if ($sUrl == "dd.loc/api/tg/hook") {
$sUrl = "http://".$sUrl;
} else {
$sUrl = "https://".$sUrl;
}
$aData = [
"shell" => "cmd",
'update_id' => 123456789,
'message' => [
'message_id' => 1,
'from' => [
'id' => 7740568271,
'is_bot' => false,
'first_name' => $sUser,
'last_name' => 'Doe',
'username' => 'johndoe',
'language_code' => 'en'
],
'chat' => [
'id' => -4668400285,
'first_name' => 'John',
'last_name' => 'Doe',
'username' => 'johndoe',
'type' => 'private'
],
'date' => 1610000000,
"text" => $sValue,
]
];
$oHttp = new Http();
$oHttp->sMethod = "post";
$oHttp->sToUrl = $sUrl;
$oHttp->bIsJson = true;
$oHttp->aData = $aData;
$r = $oHttp->send();
// echo "<pre>";
echo $r;
exit;
}
}