87 lines
2.8 KiB
PHP
87 lines
2.8 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Api\v1;
|
||
|
||
use Illuminate\Http\Request;
|
||
use App\Http\Controllers\Controller;
|
||
use App\Services\TomTool\Flow;
|
||
use App\Services\TomTool\Telegram\Slave as TeleSlave;
|
||
use Illuminate\Support\Str;
|
||
use Illuminate\Support\Facades\File;
|
||
|
||
class FreenodeController extends Controller
|
||
{
|
||
public function filePut(Request $oRequest)
|
||
{
|
||
|
||
$sObjName = "freenode:filePub";
|
||
$oFlow = Flow::make($sObjName);
|
||
|
||
$aData = $oRequest->all();
|
||
|
||
$sSubSiteCodeShort = $aData["site_code_short"];
|
||
$aRaw = $aData["raw"];
|
||
|
||
$sDate = date('Ymd');
|
||
$sSuffix = "nodes";
|
||
$sRawKey = $sDate . $sSuffix;
|
||
$sUniqueToken = hash_hmac('sha256', $sRawKey, 'wocaonide');
|
||
$sShortToken = Str::substr($sUniqueToken, 0, 16);
|
||
|
||
$aResult = [];
|
||
$sTgLog = "";
|
||
foreach ($aRaw as $sClient => $sContent) {
|
||
|
||
if (!$sContent) {
|
||
$sMsg = "\n {$sObjName}来空?";
|
||
echo $sMsg;
|
||
TeleSlave::warn()->send($sMsg);
|
||
continue;
|
||
}
|
||
|
||
$sExtension = '.txt';
|
||
if ($sClient == "v2ray") {
|
||
$sExtension = ".txt";
|
||
} else if ($sClient == "clash") {
|
||
$sExtension = ".yaml";
|
||
}
|
||
|
||
$sFileSavePath = $sSubSiteCodeShort."/".$sShortToken;
|
||
$sFileSaveName = date("Ymd")."-".$sClient.$sExtension;
|
||
$sFilePathFull = $sFileSavePath."/".$sFileSaveName;
|
||
|
||
if (!File::isDirectory($sFileSavePath)) {
|
||
File::makeDirectory($sFileSavePath, 0755, true);
|
||
}
|
||
|
||
$xSaveLenth = File::put($sFilePathFull, $sContent);
|
||
chmod($sFilePathFull, 0644);
|
||
// chmod($sFilePathFull, 0777);
|
||
|
||
if (!$xSaveLenth) {
|
||
$sMsg = "\n {$sObjName}保存file失败?";
|
||
echo $sMsg;
|
||
TeleSlave::warn()->send($sMsg);
|
||
continue;
|
||
}
|
||
|
||
$sFileUrl = config("app.url")."/".$sFilePathFull;
|
||
|
||
if (config("app.is_loc") == false) {
|
||
$sTgLog .= "\n";
|
||
$sTgLog .= "更新ok的".config("app.site_code_short")."的{$sSubSiteCodeShort}的{$sClient}的长{$xSaveLenth}";
|
||
|
||
// TeleSlave::log()
|
||
// ->enableDetail(false)
|
||
// ->setFileUrl($sFileUrl, "更新ok的".config("app.site_code_short")."的{$sSubSiteCodeShort}的{$sClient}的长{$xSaveLenth}")
|
||
// ->send();
|
||
}
|
||
|
||
}
|
||
|
||
TeleSlave::log()->enableDetail(false)->send($sTgLog);
|
||
|
||
return response()->json($oFlow->done());
|
||
}
|
||
}
|