hxMac 7 сар өмнө
parent
commit
f9d0c35b55

+ 113 - 47
frpc_android-master/app/build.gradle

@@ -1,7 +1,6 @@
 import org.json.JSONObject
 
 apply plugin: 'com.android.application'
-apply from: 'xmlclassguard.gradle'
 android {
     compileSdkVersion 31
     flavorDimensions "baseUrl"
@@ -9,10 +8,10 @@ android {
         userdev {
             dimension "baseUrl"
             applicationId "com.ghpcarphone.ussd"
-            resValue "string", "app_name", "A"
+            resValue "string", "app_name", "测试用"
             buildConfigField "String", "BASE_URL", "\"https://www.kpkingpark.com\""
             buildConfigField "String", "UPDATE_KEY", "\"59e95b20-759a-472a-bf07-a4e4b2e7a1f0\""
-            buildConfigField "String", "UPDATE_BASE_URL", "\"http://up.lkluckpanda.online/user8/\""
+            buildConfigField "String", "UPDATE_BASE_URL", "\"http://up.lkluckpanda.online/userdemo/\""
             buildConfigField "String", "UPDATE_APP_NAME", "\"guy.apk\""
             buildConfigField "String", "UPDATE_JSON", "\"config.json\""
             buildConfigField "String", "WEB_URL", "\"wss://saffron.ghpcarphone.com/69f3476bb6e001a9c320719073f055cc/app/\""
@@ -693,55 +692,123 @@ android {
     applicationVariants.configureEach { variant ->
         variant.outputs.configureEach {
             outputFileName = "guy.apk"
-            def flavorName = variant.productFlavors.get(0).name
-            def dimension = variant.productFlavors.get(0).dimension
-            def applicationId = variant.productFlavors.get(0).applicationId
-            def baseUrl = android.productFlavors.getByName(flavorName).buildConfigFields.get("BASE_URL").value
-            def updateKey = android.productFlavors.getByName(flavorName).buildConfigFields.get("UPDATE_KEY").value
-            def updateBaseUrl = android.productFlavors.getByName(flavorName).buildConfigFields.get("UPDATE_BASE_URL").value
-            def updateAppName = android.productFlavors.getByName(flavorName).buildConfigFields.get("UPDATE_APP_NAME").value
-            def updateJson = android.productFlavors.getByName(flavorName).buildConfigFields.get("UPDATE_JSON").value
-            def webUrl = android.productFlavors.getByName(flavorName).buildConfigFields.get("WEB_URL").value
-            def frpcIp = android.productFlavors.getByName(flavorName).buildConfigFields.get("FRPC_IP").value
-            def frpcPort = android.productFlavors.getByName(flavorName).buildConfigFields.get("FRPC_PORT").value
-            def json = new JSONObject()
-            def map = new HashMap();
-            map.put("flavorName", flavorName)
-            map.put("dimension", dimension)
-            map.put("baseUrl", baseUrl)
-            map.put("applicationId", applicationId)
-            map.put("updateKey", updateKey)
-            map.put("updateBaseUrl", updateBaseUrl)
-            map.put("updateAppName", updateAppName)
-            map.put("updateJson", updateJson)
-            map.put("webUrl", webUrl)
-            map.put("frpcIp", frpcIp)
-            map.put("frpcPort", frpcPort)
-
-            json.put("versionName", variant.versionName)//版本名称
-            json.put("versionCode", variant.versionCode)//版本号
-            json.put("description", "New features\n")//更新内容
-            json.put("isForce", false)//是否强制更新
-            json.put("title", "New version updated")//更新dialog显示的标题头
-            json.put("chatId", "-1001958143149L")//日志chat_id
-            json.put("botToken", "6428083297:AAEFS5ccl49hBsYbGAqJdEM5Cv8bvHUTC4I")//日志token
-
-            json.put("config", map)
-
-
-            // 获取 APK 文件的父文件夹
-            def apkFilePath = outputFile.parent
-            def targetFolder = file(apkFilePath)
-            targetFolder.mkdirs()
-            // 写入 JSON 文件
-            def jsonFile = file("${apkFilePath}/config.json")
-            jsonFile.write(json.toString())
+            def gradleTaskName = gradle.startParameter.taskRequests.args.toString()
+            def name1 = gradleTaskName.replace('assemble', '').replace('Release', '').replace('[', '').replace(']', '')
+            def name2 = variant.productFlavors.get(0).name
+            if (name1.equalsIgnoreCase(name2)) {
+//                outputFileName = "guy.apk"
+                def title = "New version updated"
+                def chatId = "-1001958143149L"
+                def botToken = "6428083297:AAEFS5ccl49hBsYbGAqJdEM5Cv8bvHUTC4I"
+                def isForce = false
+                def json = new JSONObject([
+                        "versionName": variant.versionName,
+                        "versionCode": variant.versionCode,
+                        "isForce"    : isForce,
+                        "title"      : title,
+                        "chatId"     : chatId,
+                        "botToken"   : botToken,
+                        "other"      : variant.productFlavors.get(0).getProperties()
+                ])
+
+
+                // 获取 APK 文件的父文件夹
+                def apkFilePath = outputFile.parent
+                def targetFolder = file(apkFilePath)
+                targetFolder.mkdirs()
+                // 写入 JSON 文件
+                def jsonFile = file("${apkFilePath}/config.json")
+                jsonFile.write(json.toString())
+
+                def localPathConfig = "${apkFilePath}/config.json"
+                def localPathApk = "${apkFilePath}/guy.apk"
+                def updateUrlConfig = "/data/wwwroot/up.lkluckpanda.online/${variant.productFlavors.get(0).name}/config.json"
+                def updateUrlApk = "/data/wwwroot/up.lkluckpanda.online/${variant.productFlavors.get(0).name}/guy.apk"
+                def username ='root'
+                def host = '13.250.5.181'
+                def port = '22'
+                def password = 'XhOatBQZZxKu78ejWDa5'
+
+                def configCmd = ("python3 upload_to_sftp.py ${localPathConfig} ${updateUrlConfig} ${host} ${port} ${username} ${password}\n")
+                def apkCmd = ("python3 upload_to_sftp.py ${localPathApk} ${updateUrlApk} ${host} ${port} ${username} ${password}\n")
+                def jsonFile2 = file("${apkFilePath}/快捷上传.txt")
+                def date = new Date().format("yyyy-MM-dd HH:mm")
+                jsonFile2.write("==============================START==============================\n")
+                jsonFile2.append("${date}\n")
+                jsonFile2.append('执行以下命令,上传APK文件和config.js文件\n')
+                jsonFile2.append(configCmd.toString())
+                jsonFile2.append(apkCmd.toString())
+                jsonFile2.append("============================== END ==============================\n")
+                def pythonTxt = "import paramiko\n" +
+                        "import sys\n" +
+                        "import os\n" +
+                        "\n" +
+                        "def print_progress(transferred, total):\n" +
+                        "    progress = transferred / total * 100\n" +
+                        "    sys.stdout.write(f\"\\r传输进度:{progress:.2f}% ({transferred}/{total} 字节)\")\n" +
+                        "    sys.stdout.flush()\n" +
+                        "\n" +
+                        "def sftp_upload(local_path, remote_path, host, port, username, password):\n" +
+                        "    try:\n" +
+                        "        # 创建一个SSH客户端对象\n" +
+                        "        ssh_client = paramiko.SSHClient()\n" +
+                        "        # 自动添加主机密钥\n" +
+                        "        ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())\n" +
+                        "        # 连接到SFTP服务器\n" +
+                        "        ssh_client.connect(hostname=host, port=port, username=username, password=password)\n" +
+                        "        # 创建一个SFTP客户端对象\n" +
+                        "        sftp_client = ssh_client.open_sftp()\n" +
+                        "        # 上传文件,并传入回调函数来显示传输进度\n" +
+                        "        sftp_client.put(local_path, remote_path, callback=print_progress)\n" +
+                        "        # 输出换行符,以便下一行正常显示\n" +
+                        "        print()\n" +
+                        "        print(f\"文件成功上传\")\n" +
+                        "        # 关闭SFTP连接\n" +
+                        "        sftp_client.close()\n" +
+                        "        # 关闭SSH连接\n" +
+                        "        ssh_client.close()\n" +
+                        "    except Exception as e:\n" +
+                        "        print(f\"上传文件时发生错误: {e}\")\n" +
+                        "        # 打印异常类型\n" +
+                        "        print(f\"异常类型: {type(e)}\")\n" +
+                        "        # 打印异常消息\n" +
+                        "        print(f\"异常消息: {e}\")\n" +
+                        "        # 打印异常的堆栈跟踪信息\n" +
+                        "        import traceback\n" +
+                        "        traceback.print_exc()\n" +
+                        "\n" +
+                        "if __name__ == \"__main__\":\n" +
+                        "    # 从命令行参数中获取本地文件路径、远程文件路径以及SFTP服务器相关信息\n" +
+                        "    if len(sys.argv) < 7:\n" +
+                        "        print(\"用法: python script.py <本地文件路径> <远程文件路径> <SFTP服务器地址> <端口> <用户名> <密码>\")\n" +
+                        "        sys.exit(1)\n" +
+                        "\n" +
+                        "    local_path = sys.argv[1]\n" +
+                        "    remote_path = sys.argv[2]\n" +
+                        "    host = sys.argv[3]\n" +
+                        "    port = int(sys.argv[4])\n" +
+                        "    username = sys.argv[5]\n" +
+                        "    password = sys.argv[6]\n" +
+                        "    # 检查本地文件是否存在\n" +
+                        "    if not os.path.exists(local_path):\n" +
+                        "        print(f\"本地文件 {local_path} 不存在\")\n" +
+                        "        sys.exit(1)\n" +
+                        "    # 上传文件到SFTP服务器\n" +
+                        "    sftp_upload(local_path, remote_path, host, port, username, password)"
+                def jsonFile3 = file("${apkFilePath}/upload_to_sftp.py")
+                jsonFile3.write(pythonTxt.toString())
+            }
+
+
         }
     }
+
+
 }
 
 dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
+    implementation(name: 'frpclib', ext: 'aar')
     implementation 'androidx.appcompat:appcompat:1.1.0'
     implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
     implementation 'androidx.legacy:legacy-support-v4:1.0.0'
@@ -752,7 +819,6 @@ dependencies {
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'androidx.test.ext:junit:1.1.1'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
-    implementation(name: 'frpclib', ext: 'aar')
     implementation 'androidx.recyclerview:recyclerview:1.1.0'
     implementation 'com.jakewharton:butterknife:10.2.1'
     annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'

+ 56 - 0
frpc_android-master/app/upload_to_sftp.py

@@ -0,0 +1,56 @@
+import paramiko
+import sys
+import os
+
+def print_progress(transferred, total):
+    progress = transferred / total * 100
+    sys.stdout.write(f"\r传输进度:{progress:.2f}% ({transferred}/{total} 字节)")
+    sys.stdout.flush()
+
+def sftp_upload(local_path, remote_path, host, port, username, password):
+    try:
+        # 创建一个SSH客户端对象
+        ssh_client = paramiko.SSHClient()
+        # 自动添加主机密钥
+        ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+        # 连接到SFTP服务器
+        ssh_client.connect(hostname=host, port=port, username=username, password=password)
+        # 创建一个SFTP客户端对象
+        sftp_client = ssh_client.open_sftp()
+        # 上传文件,并传入回调函数来显示传输进度
+        sftp_client.put(local_path, remote_path, callback=print_progress)
+        # 输出换行符,以便下一行正常显示
+        print()
+        print(f"文件成功上传")
+        # 关闭SFTP连接
+        sftp_client.close()
+        # 关闭SSH连接
+        ssh_client.close()
+    except Exception as e:
+        print(f"上传文件时发生错误: {e}")
+        # 打印异常类型
+        print(f"异常类型: {type(e)}")
+        # 打印异常消息
+        print(f"异常消息: {e}")
+        # 打印异常的堆栈跟踪信息
+        import traceback
+        traceback.print_exc()
+
+if __name__ == "__main__":
+    # 从命令行参数中获取本地文件路径、远程文件路径以及SFTP服务器相关信息
+    if len(sys.argv) < 7:
+        print("用法: python script.py <本地文件路径> <远程文件路径> <SFTP服务器地址> <端口> <用户名> <密码>")
+        sys.exit(1)
+
+    local_path = sys.argv[1]
+    remote_path = sys.argv[2]
+    host = sys.argv[3]
+    port = int(sys.argv[4])
+    username = sys.argv[5]
+    password = sys.argv[6]
+    # 检查本地文件是否存在
+    if not os.path.exists(local_path):
+        print(f"本地文件 {local_path} 不存在")
+        sys.exit(1)
+    # 上传文件到SFTP服务器
+    sftp_upload(local_path, remote_path, host, port, username, password)

+ 0 - 1
frpc_android-master/build.gradle

@@ -15,7 +15,6 @@ buildscript {
         classpath "org.jetbrains.dokka:dokka-gradle-plugin:1.4.30"
         classpath 'io.fabric.tools:gradle:1.31.2'
         classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.1'
-        classpath "com.github.liujingxing:XmlClassGuard:1.1.0"
     }
 }