Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object ConfigUtils {

val apiObject = JSONObject()
apiObject.put("tag", "api")
apiObject.put("listen", "127.0.0.1:${prefs.apiPort}")
apiObject.put("listen", "${prefs.apiAddress}:${prefs.apiPort}")
val servicesArray = org.json.JSONArray()
servicesArray.put("StatsService")
apiObject.put("services", servicesArray)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/kotlin/com/simplexray/an/prefs/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ class Preferences(context: Context) {
setValueInProvider(GEOSITE_URL, value)
}

var apiAddress: String
get() = getPrefData(API_ADDRESS).first ?: "127.0.0.1"
set(address) {
setValueInProvider(API_ADDRESS, address)
}

var apiPort: Int
get() {
val value = getPrefData(API_PORT).first
Expand Down Expand Up @@ -331,6 +337,7 @@ class Preferences(context: Context) {
const val CONNECTIVITY_TEST_TIMEOUT: String = "ConnectivityTestTimeout"
const val GEOIP_URL: String = "GeoipUrl"
const val GEOSITE_URL: String = "GeositeUrl"
const val API_ADDRESS: String = "ApiAddress"
const val API_PORT: String = "ApiPort"
const val BYPASS_SELECTED_APPS: String = "BypassSelectedApps"
const val THEME: String = "Theme"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ class TProxyService : VpnService() {
prefs.apiPort = apiPort
Log.d(TAG, "Found and set API port: $apiPort")

val octet2 = (0..255).random()
val octet3 = (0..255).random()
val octet4 = (1..254).random()
prefs.apiAddress = "127.$octet2.$octet3.$octet4"
Log.d(TAG, "Randomized API address: ${prefs.apiAddress}")

val processBuilder = getProcessBuilder(xrayPath)
currentProcess = processBuilder.start()
this.xrayProcess = currentProcess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class MainViewModel(application: Application) :
suspend fun updateCoreStats() {
if (!_isServiceEnabled.value) return
if (coreStatsClient == null)
coreStatsClient = CoreStatsClient.create("127.0.0.1", prefs.apiPort)
coreStatsClient = CoreStatsClient.create(prefs.apiAddress, prefs.apiPort)

val stats = coreStatsClient?.getSystemStats()
val traffic = coreStatsClient?.getTraffic()
Expand Down
Loading