mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-05 12:08:58 +00:00
1. 全面改写项目-管理面板的路由; 2. 拆分过于Contoller; 3. 优化了按钮过多的图表的显示; 4. 初步应用 Laravel的 表单验证功能; 5. 初步应用 Laravel的 component 功能 拆分/模块化前端代码; 6. 优化部分系统的判断逻辑; 7. 针对2.4.0以前的面板,追加辅助矫正数据库的sql文件;
89 lines
2.8 KiB
PHP
89 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\NodeCertificate;
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Log;
|
|
use Response;
|
|
|
|
class CertController extends Controller
|
|
{
|
|
// 域名证书列表
|
|
public function index(Request $request)
|
|
{
|
|
$DvList = NodeCertificate::orderBy('id')->paginate(15)->appends($request->except('page'));
|
|
foreach ($DvList as $Dv) {
|
|
if ($Dv->pem) {
|
|
$DvInfo = openssl_x509_parse($Dv->pem);
|
|
if ($DvInfo) {
|
|
$Dv->issuer = $DvInfo['issuer']['O'] ?? null;
|
|
$Dv->from = date('Y-m-d', $DvInfo['validFrom_time_t']) ?: null;
|
|
$Dv->to = date('Y-m-d', $DvInfo['validTo_time_t']) ?: null;
|
|
}
|
|
}
|
|
}
|
|
$view['list'] = $DvList;
|
|
|
|
return view('admin.node.cert.index', $view);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('admin.node.cert.info');
|
|
}
|
|
|
|
// 添加域名证书
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$cert = new NodeCertificate();
|
|
$cert->domain = $request->input('domain');
|
|
$cert->key = str_replace(["\r", "\n"], '', $request->input('key'));
|
|
$cert->pem = str_replace(["\r", "\n"], '', $request->input('pem'));
|
|
$cert->save();
|
|
|
|
if ($cert->id) {
|
|
return Response::json(['status' => 'success', 'message' => '生成成功']);
|
|
}
|
|
|
|
return Response::json(['status' => 'fail', 'message' => '生成失败']);
|
|
}
|
|
|
|
// 编辑域名证书
|
|
public function edit($id)
|
|
{
|
|
$view['Dv'] = NodeCertificate::find($id);
|
|
|
|
return view('admin.node.cert.info', $view);
|
|
}
|
|
|
|
public function update(Request $request, $id): JsonResponse
|
|
{
|
|
$Dv = NodeCertificate::findOrFail($id);
|
|
if ($Dv->update(['domain' => $request->input('domain'), 'key' => $request->input('key'), 'pem' => $request->input('pem')])) {
|
|
return Response::json(['status' => 'success', 'message' => '修改成功']);
|
|
}
|
|
|
|
return Response::json(['status' => 'fail', 'message' => '修改失败']);
|
|
}
|
|
|
|
// 删除域名证书
|
|
public function destroy($id): JsonResponse
|
|
{
|
|
try {
|
|
if (NodeCertificate::whereId($id)->delete()) {
|
|
return Response::json(['status' => 'success', 'message' => '操作成功']);
|
|
}
|
|
} catch (Exception $e) {
|
|
Log::error('删除域名证书失败:'.$e->getMessage());
|
|
|
|
return Response::json(['status' => 'fail', 'message' => '删除域名证书失败:'.$e->getMessage()]);
|
|
}
|
|
|
|
return Response::json(['status' => 'fail', 'message' => '删除域名证书失败']);
|
|
}
|
|
}
|