feat: 添加F8来客应用发布系统
- 实现APK文件上传功能,包括版本验证和自动更新最新版本 - 添加访问令牌验证机制保障安全性 - 创建README文档说明项目结构和使用方法 - 添加图片资源和日志记录功能
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
# F8app_publish
|
||||
|
||||
这是一个用于发布F8来客应用的PHP项目。
|
||||
|
||||
## 目录结构
|
||||
|
||||
- `app.html`: 主页面
|
||||
- `f8app/`: 包含APK文件和上传脚本
|
||||
- `access_token.txt`: 访问令牌
|
||||
- `upload.php`: 上传脚本
|
||||
- `uploads/`: 存放APK文件
|
||||
- 包含多个版本的F8来客APK
|
||||
- `f8img/`: 存放图片资源
|
||||
|
||||
## 使用说明
|
||||
|
||||
1. 将APK文件放入`f8app/uploads/`目录
|
||||
2. 通过`app.html`访问主页面
|
||||
3. 使用`upload.php`进行文件上传
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 确保服务器有写入`uploads/`目录的权限
|
||||
- 定期清理旧版本APK文件
|
||||
@@ -0,0 +1 @@
|
||||
872ef3f99b0d6fd75a6476482ceb190d
|
||||
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
// 生成随机16位访问字符串
|
||||
$accessToken = substr(md5(uniqid(mt_rand(), true)), 0, 32);
|
||||
$accessFile = 'access_token.txt';
|
||||
|
||||
// 检查或生成访问令牌
|
||||
if (!file_exists($accessFile)) {
|
||||
file_put_contents($accessFile, $accessToken);
|
||||
} else {
|
||||
$accessToken = trim(file_get_contents($accessFile));
|
||||
}
|
||||
|
||||
// 验证访问令牌
|
||||
if (!isset($_GET['token']) || $_GET['token'] !== $accessToken) {
|
||||
die('无效访问令牌');
|
||||
}
|
||||
|
||||
$message = '';
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['apk'])) {
|
||||
$targetDir = 'uploads/';
|
||||
$apkFile = $_FILES['apk'];
|
||||
$fileName = basename($apkFile['name']);
|
||||
$targetPath = $targetDir . $fileName;
|
||||
|
||||
// 检查文件类型
|
||||
$fileType = strtolower(pathinfo($targetPath, PATHINFO_EXTENSION));
|
||||
if ($fileType != 'apk') {
|
||||
$message = '只允许上传APK文件';
|
||||
} else {
|
||||
// 检查包名
|
||||
$tempPath = $apkFile['tmp_name'];
|
||||
$packageName = shell_exec("aapt dump badging \"$tempPath\" | grep package | awk -F\"'\" '{print $2}'");
|
||||
$packageName = trim($packageName);
|
||||
|
||||
if ($packageName !== 'com.f8com.f8laike') {
|
||||
$message = '非法的APK';
|
||||
} else {
|
||||
// 获取版本号
|
||||
$versionInfo = shell_exec("aapt dump badging \"$tempPath\" | grep -E 'versionName|versionCode'");
|
||||
$versionName = preg_match("/versionName='([^']*)'/", $versionInfo, $matches) ? $matches[1] : '';
|
||||
$versionName = trim($versionName);
|
||||
|
||||
// 创建上传目录
|
||||
if (!file_exists($targetDir)) {
|
||||
mkdir($targetDir, 0755, true);
|
||||
}
|
||||
|
||||
// 移动文件
|
||||
if (move_uploaded_file($tempPath, $targetPath)) {
|
||||
// 获取客户端IP
|
||||
$ip = $_SERVER['HTTP_CLIENT_IP'] ??
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] ??
|
||||
$_SERVER['REMOTE_ADDR'] ??
|
||||
'unknown';
|
||||
|
||||
// 记录日志
|
||||
$log = date('Y-m-d H:i:s') . " - IP: $ip, 上传文件: $fileName, 版本号: $versionName\n";
|
||||
file_put_contents($targetDir . 'upload.log', $log, FILE_APPEND);
|
||||
|
||||
// 更新最新版本
|
||||
$latestPath = $targetDir . 'F8来客_latest.apk';
|
||||
|
||||
// 获取当前上传APK的版本号
|
||||
$newVersion = $versionName;
|
||||
|
||||
// 获取现有最新APK的版本号
|
||||
$currentLatestVersion = '0';
|
||||
if (file_exists($latestPath)) {
|
||||
$versionInfo = shell_exec("aapt dump badging \"$latestPath\" | grep -E 'versionName|versionCode'");
|
||||
$currentLatestVersion = preg_match("/versionName='([^']*)'/", $versionInfo, $matches) ? $matches[1] : '0';
|
||||
$currentLatestVersion = trim($currentLatestVersion);
|
||||
}
|
||||
|
||||
// 比较版本号,只有当新版本更高时才覆盖
|
||||
if (version_compare($newVersion, $currentLatestVersion) > 0) {
|
||||
if (file_exists($latestPath)) {
|
||||
unlink($latestPath);
|
||||
}
|
||||
if (!copy($targetPath, $latestPath)) {
|
||||
$message = '更新最新版本失败';
|
||||
}
|
||||
$message = '上传成功! 已更新为最新版本: ' . $versionName;
|
||||
} else {
|
||||
$message = '上传成功! 当前版本: ' . $versionName . ' (未更新,已有更高版本: ' . $currentLatestVersion . ')';
|
||||
}
|
||||
} else {
|
||||
$message = '上传失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getLatestVersionName($dir) {
|
||||
$files = glob($dir . '*.apk');
|
||||
$maxVersion = '0';
|
||||
foreach ($files as $file) {
|
||||
if (basename($file) === 'F8来客_latest.apk') continue;
|
||||
$version = shell_exec("aapt dump badging \"$file\" | grep versionName | awk -F\"'\" '{print $2}'");
|
||||
$version = trim($version);
|
||||
if (version_compare($version, $maxVersion) > 0) {
|
||||
$maxVersion = $version;
|
||||
}
|
||||
}
|
||||
return $maxVersion;
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
|
||||
<title>F8来客 - APK上传</title>
|
||||
<style>
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
margin: 0; padding: 20px; background-color: #fff;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px; margin: 0 auto;
|
||||
}
|
||||
.logo {
|
||||
width: 60px; height: 60px; border-radius: 5px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 18px; color: #2a2a2a; font-weight: 700;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.message {
|
||||
padding: 10px; margin-bottom: 20px;
|
||||
border-radius: 5px; text-align: center;
|
||||
}
|
||||
.success { background-color: #d4edda; color: #155724; }
|
||||
.error { background-color: #f8d7da; color: #721c24; }
|
||||
.upload-form {
|
||||
border: 1px dashed #007aff; padding: 30px;
|
||||
text-align: center; border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.file-input {
|
||||
display: none;
|
||||
}
|
||||
.file-label {
|
||||
display: inline-block;
|
||||
padding: 12px 24px;
|
||||
background-color: #007aff;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
.submit-btn {
|
||||
padding: 12px 24px;
|
||||
background-color: #28a745;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
margin-top: 15px;
|
||||
}
|
||||
.logout {
|
||||
color: #007aff; text-decoration: none;
|
||||
display: inline-block; margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<img src="https://www.bltcxj.cn/f8img/logo.jpg" class="logo">
|
||||
<h1>APK上传</h1>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div class="message <?php echo strpos($message, '成功') !== false ? 'success' : 'error'; ?>">
|
||||
<?php echo htmlspecialchars($message); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post" enctype="multipart/form-data" class="upload-form">
|
||||
<input type="file" name="apk" id="apk" accept=".apk" class="file-input">
|
||||
<label for="apk" class="file-label">选择APK文件</label>
|
||||
<div id="fileName" style="margin-top: 10px;"></div>
|
||||
<button type="submit" class="submit-btn">上传APK</button>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<h2>最近上传记录</h2>
|
||||
<div class="upload-history">
|
||||
<?php
|
||||
$logFile = 'uploads/upload.log';
|
||||
if (file_exists($logFile)) {
|
||||
$lines = file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
$recentLines = array_slice(array_reverse($lines), 0, 5);
|
||||
echo '<ul>';
|
||||
foreach ($recentLines as $line) {
|
||||
echo '<li>' . htmlspecialchars($line) . '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
} else {
|
||||
echo '<p>暂无上传记录</p>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('apk').addEventListener('change', function(e) {
|
||||
var fileName = e.target.files[0] ? e.target.files[0].name : '未选择文件';
|
||||
document.getElementById('fileName').textContent = fileName;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
2025-06-01 16:03:12 - IP: 220.171.171.18, 上传文件: F8来客_latest.apk, 版本号: v2.20.2
|
||||
2025-06-01 16:16:54 - IP: 220.171.171.18, 上传文件: F8来客_v2.20.0.apk, 版本号: v2.20.0
|
||||
2025-06-01 16:34:47 - IP: 220.171.171.18, 上传文件: F8来客_v2.20.2.apk, 版本号: v2.20.2
|
||||
2025-06-01 16:41:11 - IP: 220.171.171.18, 上传文件: F8来客_v2.99.3.apk, 版本号: v2.19.3
|
||||
2025-06-03 12:35:14 - IP: 220.171.171.18, 上传文件: F8来客_v2.99.3.apk, 版本号: v2.19.3
|
||||
2025-06-05 16:21:07 - IP: 220.171.171.18, 上传文件: F8来客_v2.21.0.apk, 版本号: v2.21.0
|
||||
2025-06-13 13:15:36 - IP: 220.171.168.171, 上传文件: F8来客_v2.22.3.apk, 版本号: v2.22.3
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 159 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 141 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 133 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 132 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 144 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.7 KiB |
Reference in New Issue
Block a user