113 lines
2.8 KiB
PHP
Executable File
113 lines
2.8 KiB
PHP
Executable File
<?php
|
||
|
||
namespace App\Http\Controllers;
|
||
|
||
use App\Module\Base;
|
||
use App\Tasks\DeleteTmpTask;
|
||
use Hhxsv5\LaravelS\Swoole\Task\Task;
|
||
use Redirect;
|
||
|
||
|
||
/**
|
||
* 页面
|
||
* Class IndexController
|
||
* @package App\Http\Controllers
|
||
*/
|
||
class IndexController extends InvokeController
|
||
{
|
||
public function __invoke($method, $action = '', $child = '')
|
||
{
|
||
$app = $method ?: 'main';
|
||
if ($action) {
|
||
$app .= "__" . $action;
|
||
}
|
||
if (!method_exists($this, $app)) {
|
||
$app = method_exists($this, $method) ? $method : 'main';
|
||
}
|
||
return $this->$app($child);
|
||
}
|
||
|
||
/**
|
||
* 首页
|
||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||
*/
|
||
public function main()
|
||
{
|
||
return view('main', ['version' => Base::getVersion()]);
|
||
}
|
||
|
||
/**
|
||
* 接口文档
|
||
* @return \Illuminate\Http\RedirectResponse
|
||
*/
|
||
public function api()
|
||
{
|
||
return Redirect::to(Base::fillUrl('docs/index.html'), 301);
|
||
}
|
||
|
||
/**
|
||
* 系统定时任务,限制内网访问(1分钟/次)
|
||
* @return string
|
||
*/
|
||
public function crontab()
|
||
{
|
||
if (!Base::is_internal_ip()) {
|
||
// 限制内网访问
|
||
return "Forbidden Access";
|
||
}
|
||
// 删除过期的临时表数据
|
||
Task::deliver(new DeleteTmpTask('wg_tmp_msgs', 1));
|
||
Task::deliver(new DeleteTmpTask('tmp', 24));
|
||
|
||
return "success";
|
||
}
|
||
|
||
/**
|
||
* 提取所有中文
|
||
* @return array|string
|
||
*/
|
||
public function allcn()
|
||
{
|
||
if (!Base::is_internal_ip()) {
|
||
// 限制内网访问
|
||
return "Forbidden Access";
|
||
}
|
||
$list = Base::readDir(resource_path());
|
||
$array = [];
|
||
foreach ($list as $item) {
|
||
$content = file_get_contents($item);
|
||
preg_match_all("/\\\$L\((.*?)\)/", $content, $matchs);
|
||
if ($matchs) {
|
||
foreach ($matchs[1] as $text) {
|
||
$array[trim(trim($text, '"'), "'")] = trim(trim($text, '"'), "'");
|
||
}
|
||
}
|
||
}
|
||
return array_values($array);
|
||
}
|
||
|
||
/**
|
||
* 提取所有中文
|
||
* @return array|string
|
||
*/
|
||
public function allcn__php()
|
||
{
|
||
if (!Base::is_internal_ip()) {
|
||
// 限制内网访问
|
||
return "Forbidden Access";
|
||
}
|
||
$list = Base::readDir(app_path());
|
||
$array = [];
|
||
foreach ($list as $item) {
|
||
$content = file_get_contents($item);
|
||
preg_match_all("/(retSuccess|retError|ApiException)\((.*?)[,|)]/", $content, $matchs);
|
||
if ($matchs) {
|
||
foreach ($matchs[2] as $text) {
|
||
$array[trim(trim($text, '"'), "'")] = trim(trim($text, '"'), "'");
|
||
}
|
||
}
|
||
}
|
||
return array_values($array);
|
||
}
|
||
}
|