Add frp interface

This commit is contained in:
Jtun-coder 2024-11-29 17:15:04 +08:00
parent 3b4d8df7f0
commit cfab3a7222
3 changed files with 131 additions and 6 deletions

View File

@ -17,4 +17,5 @@ object Config {
const val V2RAY_PACKAGE_NAME = "com.v2ray.ang" const val V2RAY_PACKAGE_NAME = "com.v2ray.ang"
const val ALIST_PACKAGE_NAME = "com.leohao.android.alistlite" const val ALIST_PACKAGE_NAME = "com.leohao.android.alistlite"
const val OPENVPN_PACKAGE_NAME = "de.blinkt.openvpn" const val OPENVPN_PACKAGE_NAME = "de.blinkt.openvpn"
const val FRP_PACKAGE_NAME = "com.jtun.frpc_android"
} }

View File

@ -36,6 +36,14 @@ object HttpInterface {
const val OPENVPN_LIST = "/openvpnList"//获取列表 const val OPENVPN_LIST = "/openvpnList"//获取列表
const val OPENVPN_REMOVE = "/openvpnRemove"//删除配置信息 const val OPENVPN_REMOVE = "/openvpnRemove"//删除配置信息
const val FRP_LIST = "/frpList"//获取配置列表
const val FRP_REMOVE = "/frpRemove"//删除配置
const val FRP_ADD = "/frpAdd"//增加配置
const val FRP_START = "/frpStart"//启动服务
const val FRP_STOP = "/frpStop"//停止服务
const val FRP_CONFIG = "/frpConfig"//获取服务详情
const val FRP_EDIT = "/frpEdit"//修改服务
const val APP_INSTALL = "/appInstall"//安装 const val APP_INSTALL = "/appInstall"//安装
const val APP_UNINSTALL = "/appUninstall"//卸载 const val APP_UNINSTALL = "/appUninstall"//卸载
const val INSTALL_INFO = "/appInstallInfo"//获取安装信息 const val INSTALL_INFO = "/appInstallInfo"//获取安装信息

View File

@ -23,6 +23,7 @@ import com.jtun.router.http.response.DeviceInfo
import com.jtun.router.http.response.NetSpeed import com.jtun.router.http.response.NetSpeed
import com.jtun.router.http.response.openvpn.OpenvpnItem import com.jtun.router.http.response.openvpn.OpenvpnItem
import com.jtun.router.http.response.UsedDataInfo import com.jtun.router.http.response.UsedDataInfo
import com.jtun.router.http.response.frp.FrpConfig
import com.jtun.router.http.response.v2ray.Configs import com.jtun.router.http.response.v2ray.Configs
import com.jtun.router.http.response.v2ray.ServersCache import com.jtun.router.http.response.v2ray.ServersCache
import com.jtun.router.room.AppDatabase import com.jtun.router.room.AppDatabase
@ -359,6 +360,33 @@ class HttpServer : NanoHTTPD(Config.HTTP_PORT) {
val uuid = jsonObject.getString("uuid") val uuid = jsonObject.getString("uuid")
resp = openvpnRemove(uuid) resp = openvpnRemove(uuid)
} }
HttpInterface.FRP_LIST->{
resp = frpList()
}
HttpInterface.FRP_REMOVE->{
val uid = jsonObject.getString("uid")
resp = frpRemove(uid)
}
HttpInterface.FRP_ADD->{
val config = jsonObject.getString("config")
resp = frpImport(config)
}
HttpInterface.FRP_START->{
val uid = jsonObject.getString("uid")
resp = frpStart(uid)
}
HttpInterface.FRP_STOP->{
val uid = jsonObject.getString("uid")
resp = frpStop(uid)
}
HttpInterface.FRP_CONFIG->{
val uid = jsonObject.getString("uid")
resp = frpConfig(uid)
}
HttpInterface.FRP_EDIT->{
val config = jsonObject.getString("config")
resp = frpEdit(config)
}
else -> { else -> {
resp = BaseResponse(500,"Api not found") resp = BaseResponse(500,"Api not found")
} }
@ -667,10 +695,10 @@ class HttpServer : NanoHTTPD(Config.HTTP_PORT) {
val cmdStr = client.receiveCmd() val cmdStr = client.receiveCmd()
val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<Any?>>(cmdStr) val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<Any?>>(cmdStr)
configCmd?.let { configCmd?.let {
JLog.t(tag,"OpenVpn import success $cmdStr") JLog.t(tag,"OpenVpn start success $cmdStr")
return BaseResponse(message = configCmd.message) return BaseResponse(message = configCmd.message)
} }
JLog.t(tag,"OpenVpn import failed") JLog.t(tag,"OpenVpn start failed")
return BaseResponse(500, message = "Failed") return BaseResponse(500, message = "Failed")
} }
private fun openvpnStop(uuid:String):BaseResponse{ private fun openvpnStop(uuid:String):BaseResponse{
@ -679,10 +707,10 @@ class HttpServer : NanoHTTPD(Config.HTTP_PORT) {
val cmdStr = client.receiveCmd() val cmdStr = client.receiveCmd()
val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<Any?>>(cmdStr) val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<Any?>>(cmdStr)
configCmd?.let { configCmd?.let {
JLog.t(tag,"OpenVpn import success $cmdStr") JLog.t(tag,"OpenVpn stop success $cmdStr")
return BaseResponse(message = configCmd.message) return BaseResponse(message = configCmd.message)
} }
JLog.t(tag,"OpenVpn import failed") JLog.t(tag,"OpenVpn stop failed")
return BaseResponse(500, message = "Failed") return BaseResponse(500, message = "Failed")
} }
private fun openvpnList():BaseResponse{ private fun openvpnList():BaseResponse{
@ -691,10 +719,10 @@ class HttpServer : NanoHTTPD(Config.HTTP_PORT) {
val cmdStr = client.receiveCmd() val cmdStr = client.receiveCmd()
val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<List<OpenvpnItem>>>(cmdStr) val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<List<OpenvpnItem>>>(cmdStr)
configCmd?.let { configCmd?.let {
JLog.t(tag,"OpenVpn import success $cmdStr") JLog.t(tag,"OpenVpn list success $cmdStr")
return BaseResponse(message = configCmd.message, data = configCmd.data) return BaseResponse(message = configCmd.message, data = configCmd.data)
} }
JLog.t(tag,"OpenVpn import failed") JLog.t(tag,"OpenVpn list failed")
return BaseResponse(500, message = "Failed") return BaseResponse(500, message = "Failed")
} }
private fun openvpnRemove(uuid:String):BaseResponse{ private fun openvpnRemove(uuid:String):BaseResponse{
@ -709,6 +737,94 @@ class HttpServer : NanoHTTPD(Config.HTTP_PORT) {
JLog.t(tag,"OpenVpn remove failed") JLog.t(tag,"OpenVpn remove failed")
return BaseResponse(500, message = "Failed") return BaseResponse(500, message = "Failed")
} }
private fun frpList():BaseResponse{
val client = LocalServer.instance.getClient(Config.FRP_PACKAGE_NAME) ?: return BaseResponse(message = "Frp not start")
client.send(BaseLocalCmd<Any?>(LocalCmd.FRP_LIST).toString())
val cmdStr = client.receiveCmd()
val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<List<FrpConfig>>>(cmdStr)
configCmd?.let {
JLog.t(tag,"Frp list success $cmdStr")
return BaseResponse(message = configCmd.message, data = configCmd.data)
}
JLog.t(tag,"Frp list failed")
return BaseResponse(500, message = "Failed")
}
private fun frpRemove(uid:String):BaseResponse{
val client = LocalServer.instance.getClient(Config.FRP_PACKAGE_NAME) ?: return BaseResponse(message = "Frp not start")
client.send(BaseLocalCmd(LocalCmd.FRP_REMOVE, data = uid).toString())
val cmdStr = client.receiveCmd()
val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<Any?>>(cmdStr)
configCmd?.let {
JLog.t(tag,"Frp remove success $cmdStr")
return BaseResponse(message = configCmd.message)
}
JLog.t(tag,"Frp remove failed")
return BaseResponse(500, message = "Failed")
}
private fun frpImport(configStr:String):BaseResponse{
val client = LocalServer.instance.getClient(Config.FRP_PACKAGE_NAME) ?: return BaseResponse(message = "Frp not start")
client.send(BaseLocalCmd(LocalCmd.FRP_IMPORT, data = configStr).toString())
val cmdStr = client.receiveCmd()
val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<Any?>>(cmdStr)
configCmd?.let {
JLog.t(tag,"Frp import success $cmdStr")
return BaseResponse(message = configCmd.message)
}
JLog.t(tag,"Frp import failed")
return BaseResponse(500, message = "Failed")
}
private fun frpStart(uid:String):BaseResponse{
val client = LocalServer.instance.getClient(Config.FRP_PACKAGE_NAME) ?: return BaseResponse(message = "Frp not start")
client.send(BaseLocalCmd(LocalCmd.FRP_START, data = uid).toString())
val cmdStr = client.receiveCmd()
val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<Any?>>(cmdStr)
configCmd?.let {
JLog.t(tag,"Frp start success $cmdStr")
return BaseResponse(message = configCmd.message)
}
JLog.t(tag,"Frp start failed")
return BaseResponse(500, message = "Failed")
}
private fun frpStop(uid:String):BaseResponse{
val client = LocalServer.instance.getClient(Config.FRP_PACKAGE_NAME) ?: return BaseResponse(message = "Frp not start")
client.send(BaseLocalCmd(LocalCmd.FRP_STOP, data = uid).toString())
val cmdStr = client.receiveCmd()
val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<Any?>>(cmdStr)
configCmd?.let {
JLog.t(tag,"Frp stop success $cmdStr")
return BaseResponse(message = configCmd.message)
}
JLog.t(tag,"Frp stop failed")
return BaseResponse(500, message = "Failed")
}
private fun frpConfig(uid:String):BaseResponse{
val client = LocalServer.instance.getClient(Config.FRP_PACKAGE_NAME) ?: return BaseResponse(message = "Frp not start")
client.send(BaseLocalCmd(LocalCmd.FRP_CONFIG,data = uid).toString())
val cmdStr = client.receiveCmd()
val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<FrpConfig>>(cmdStr)
configCmd?.let {
JLog.t(tag,"Frp config success $cmdStr")
return BaseResponse(message = configCmd.message, data = configCmd.data)
}
JLog.t(tag,"Frp config failed")
return BaseResponse(500, message = "Failed")
}
private fun frpEdit(configStr:String):BaseResponse{
val client = LocalServer.instance.getClient(Config.FRP_PACKAGE_NAME) ?: return BaseResponse(message = "Frp not start")
client.send(BaseLocalCmd(LocalCmd.FRP_EDIT, data = configStr).toString())
val cmdStr = client.receiveCmd()
val configCmd = GsonUtil.getGsonObject<BaseLocalCmd<Any?>>(cmdStr)
configCmd?.let {
JLog.t(tag,"Frp edit success $cmdStr")
return BaseResponse(message = configCmd.message)
}
JLog.t(tag,"Frp edit failed")
return BaseResponse(500, message = "Failed")
}
private fun login() : BaseResponse { private fun login() : BaseResponse {
JLog.o(tag,"login success") JLog.o(tag,"login success")
return BaseResponse() return BaseResponse()