Skip to content
Open
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
11 changes: 11 additions & 0 deletions androidApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.iml
.gradle
/local.properties
/.idea/
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
2 changes: 2 additions & 0 deletions androidApp/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
.idea/
48 changes: 48 additions & 0 deletions androidApp/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdk 32
packagingOptions {
exclude 'META-INF/*'
}

defaultConfig {
applicationId "ru.svyat.ovf"
minSdk 16
targetSdk 32
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}
21 changes: 21 additions & 0 deletions androidApp/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
37 changes: 37 additions & 0 deletions androidApp/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.svyat.ovf">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.OVFinder"
android:usesCleartextTraffic="true"
tools:targetApi="m">
<activity
android:name=".activity.OVFinder"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.VpnLoad"
android:exported="true">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.OVFinder" />
</activity>
</application>

</manifest>
Binary file added androidApp/app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions androidApp/app/src/main/java/ru/svyat/ovf/activity/OVFinder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.svyat.ovf.activity

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.floatingactionbutton.FloatingActionButton
import ru.svyat.ovf.R
import ru.svyat.ovf.services.getSavedConfigs
import ru.svyat.ovf.ui.FileRVAdapter

class OVFinder : AppCompatActivity(R.layout.init){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
with(findViewById<RecyclerView>(R.id.file_list)){
adapter = FileRVAdapter(getSavedConfigs())
layoutManager = LinearLayoutManager(this@OVFinder)
}
findViewById<FloatingActionButton>(R.id.btn_get_vpns).setOnClickListener{
Log.i(null, "vpn updating gonna be started")
startActivity(Intent(this, VpnLoad::class.java))
}
}
}
20 changes: 20 additions & 0 deletions androidApp/app/src/main/java/ru/svyat/ovf/activity/VpnLoad.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.svyat.ovf.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import ru.svyat.ovf.R
import ru.svyat.ovf.services.loadVpns
import ru.svyat.ovf.ui.VpnRVAdapter

class VpnLoad: AppCompatActivity(R.layout.vpns) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val vpns = loadVpns()
with(findViewById<RecyclerView>(R.id.vpn_list)){
adapter = VpnRVAdapter(vpns)
layoutManager = LinearLayoutManager(this@VpnLoad)
}
}
}
42 changes: 42 additions & 0 deletions androidApp/app/src/main/java/ru/svyat/ovf/dto/VpnInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@file:Suppress("MemberVisibilityCanBePrivate")

package ru.svyat.ovf.dto

import android.util.Base64

data class VpnInfo(private val line: String) {
val name: String
val ip: String
val score: Int?
val ping: Int?
val speed: Long?
val countryName: String
val countryCode: String
val sessionsCount: Long?
val uptime: Long?
val usersCount: Long?
val totalTraffic: Long?
val logLevel: String
val operator: String
val message: String
val config: String

init {
val values = line.split(",")
name = values[0]
ip = values[1]
score = values[2].toIntOrNull()
ping = values[3].toIntOrNull()
speed = values[4].toLongOrNull()
countryName = values[5]
countryCode = values[6]
sessionsCount = values[7].toLongOrNull()
uptime = values[8].toLongOrNull()
usersCount = values[9].toLongOrNull()
totalTraffic = values[10].toLongOrNull()
logLevel = values[11]
operator = values[12]
message = values[13]
config = String(Base64.decode(values[14], Base64.DEFAULT))
}
}
44 changes: 44 additions & 0 deletions androidApp/app/src/main/java/ru/svyat/ovf/services/FileUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ru.svyat.ovf.services

import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.KITKAT
import android.os.Environment.*
import android.util.Log
import java.io.File
import java.io.FileWriter
import java.util.concurrent.atomic.AtomicInteger

const val EXTENSION = ".ovpn"
const val DIR_NAME = "/OVFinder"

val FILES_STORAGE =
if (SDK_INT >= KITKAT) "${getExternalStoragePublicDirectory(DIRECTORY_DOCUMENTS).absolutePath}$DIR_NAME"
else "${getExternalStorageDirectory().absolutePath}/Download/$DIR_NAME"

fun getSavedConfigs(): List<File> = File(FILES_STORAGE).listFiles()?.asList() ?: emptyList()
fun saveConfig(name: String, content: String) = createFile(name, content)
fun deleteConfig(absPath: String){
val file = File(absPath)
file.delete()
}

private fun createFile(fileName: String, content: String): File {
createBaseDir()
var configFile = File("$FILES_STORAGE/$fileName$EXTENSION")
val counter = AtomicInteger()
while (configFile.exists()) {
configFile = File("$FILES_STORAGE/$fileName-${counter.incrementAndGet()}$EXTENSION")
Log.w("FILE", "${configFile.absolutePath} already exist, new file is")
}
configFile.createNewFile()
FileWriter(configFile).use { it.write(content) }
Log.i("FILE", configFile.absolutePath)
return configFile
}
private fun createBaseDir() {
val dir = File(FILES_STORAGE)
if (!dir.exists()) {
dir.mkdirs()
Log.i("FILE", "Created $FILES_STORAGE")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ru.svyat.ovf.services

import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import ru.svyat.ovf.dto.VpnInfo
import java.io.InputStreamReader
import java.net.HttpURLConnection
import java.net.URL
import java.util.*
import java.util.concurrent.atomic.AtomicInteger

const val URL = "http://www.vpngate.net/api/iphone/"

fun loadVpns() = runBlocking(Dispatchers.IO) {
val start = Date()
val url = URL(URL)
Log.i("INTERNET", "$start start loading vpns from $URL")
(url.openConnection() as HttpURLConnection).run {
requestMethod = "GET"
doOutput = true
connectTimeout = 10000
val result = mutableListOf<VpnInfo>()
val counter = AtomicInteger()
inputStream.use {
InputStreamReader(it).forEachLine { line ->
if (counter.getAndIncrement() > 2 &&
line != "*"
)
result.add(VpnInfo(line))
}
}
Log.i("INTERNET", "downloaded in ${(Date().time - start.time)} seconds")
return@runBlocking result
}
}
36 changes: 36 additions & 0 deletions androidApp/app/src/main/java/ru/svyat/ovf/ui/FileRVAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ru.svyat.ovf.ui

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import ru.svyat.ovf.R
import ru.svyat.ovf.services.deleteConfig
import java.io.File

class FileRVAdapter(private val files: List<File>): RecyclerView.Adapter<FileRVAdapter.FileHolder>() {
inner class FileHolder(itemView: View): RecyclerView.ViewHolder(itemView){
init {
itemView.setOnClickListener{
Toast.makeText(itemView.context.applicationContext, "call connector app", Toast.LENGTH_LONG).show()
}
itemView.findViewById<Button>(R.id.btn_delete).setOnClickListener{
deleteConfig(files[adapterPosition].absolutePath)
}
}
val name: TextView = itemView.findViewById(R.id.txt_file_name)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FileHolder =
FileHolder(LayoutInflater.from(parent.context)
.inflate(R.layout.file_item, parent, false))

override fun onBindViewHolder(holder: FileHolder, position: Int) {
holder.name.text = files[position].name
}

override fun getItemCount(): Int = files.size
}
48 changes: 48 additions & 0 deletions androidApp/app/src/main/java/ru/svyat/ovf/ui/VpnRVAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ru.svyat.ovf.ui

import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import ru.svyat.ovf.R
import ru.svyat.ovf.dto.VpnInfo
import ru.svyat.ovf.services.saveConfig

class VpnRVAdapter(private val vpns: List<VpnInfo>) :
RecyclerView.Adapter<VpnRVAdapter.VpnHolder>() {
inner class VpnHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
init {
itemView.setOnClickListener {
saveConfig(vpns[adapterPosition].name, vpns[adapterPosition].config)
}
}

private val ip: TextView = itemView.findViewById(R.id.txt_ip)
private val speed: TextView = itemView.findViewById(R.id.txt_speed)
private val ping: TextView = itemView.findViewById(R.id.txt_ping)
private val countryCode: TextView = itemView.findViewById(R.id.txt_country_code)
private val logLevel: TextView = itemView.findViewById(R.id.txt_log_level)

fun bind(vpn: VpnInfo) {
ip.text = vpn.ip
countryCode.text = vpn.countryCode
speed.text = vpn.speed?.let { "%.2fMB/s".format(it / (1024*1024F)) }?.toString() ?: "-"
ping.text = vpn.ping?.toString() ?: "-"
logLevel.text = vpn.logLevel
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VpnHolder =
VpnHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.vpn_item, parent, false)
)

override fun onBindViewHolder(holder: VpnHolder, position: Int) {
holder.bind(vpns[position])
}

override fun getItemCount(): Int = vpns.size
}
Loading