uploadFull.php, downloadFull.php are working. without AES
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.dano.test1
|
||||
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -15,24 +16,35 @@ import kotlin.system.exitProcess
|
||||
object DatabaseUploader {
|
||||
|
||||
private const val DB_NAME = "questionnaire_database"
|
||||
private const val ENCRYPTED_FILE_NAME = "exported_encrypted_database.db"
|
||||
private const val SERVER_UPLOAD_URL = "http://49.13.157.44/upload.php"
|
||||
private const val SERVER_UPLOAD_URL = "http://49.13.157.44/uploadFull.php"
|
||||
private const val API_TOKEN = "MEIN_SUPER_GEHEIMES_TOKEN_12345"
|
||||
|
||||
private val client = OkHttpClient()
|
||||
|
||||
fun uploadEncryptedDatabase(context: Context) {
|
||||
fun uploadDatabase(context: Context) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
val dbFile = context.getDatabasePath(DB_NAME)
|
||||
if (!dbFile.exists()) return@launch
|
||||
if (!dbFile.exists()) {
|
||||
Log.e("UPLOAD", "Datenbankdatei existiert nicht: ${dbFile.absolutePath}")
|
||||
return@launch
|
||||
}
|
||||
|
||||
val encryptedFile = File(context.cacheDir, ENCRYPTED_FILE_NAME)
|
||||
AES256Helper.encryptFile(dbFile, encryptedFile)
|
||||
// WAL-Daten in die Hauptdatei schreiben
|
||||
try {
|
||||
val db = SQLiteDatabase.openDatabase(
|
||||
dbFile.absolutePath,
|
||||
null,
|
||||
SQLiteDatabase.OPEN_READWRITE
|
||||
)
|
||||
db.execSQL("PRAGMA wal_checkpoint(FULL);")
|
||||
db.close()
|
||||
Log.d("UPLOAD", "WAL-Checkpoint erfolgreich durchgeführt.")
|
||||
} catch (e: Exception) {
|
||||
Log.e("UPLOAD", "Fehler beim WAL-Checkpoint", e)
|
||||
}
|
||||
|
||||
Log.d("UPLOAD", "Datei verschlüsselt: ${encryptedFile.absolutePath}")
|
||||
|
||||
uploadFile(encryptedFile, dbFile)
|
||||
uploadFile(dbFile)
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e("UPLOAD", "Fehler beim Hochladen der DB", e)
|
||||
@ -40,7 +52,7 @@ object DatabaseUploader {
|
||||
}
|
||||
}
|
||||
|
||||
private fun uploadFile(file: File, originalDbFile: File) {
|
||||
private fun uploadFile(file: File) {
|
||||
val requestBody = MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.addFormDataPart(
|
||||
@ -63,7 +75,7 @@ object DatabaseUploader {
|
||||
override fun onResponse(call: Call, response: Response) {
|
||||
if (response.isSuccessful) {
|
||||
Log.d("UPLOAD", "Upload erfolgreich: ${response.message}")
|
||||
if (originalDbFile.delete()) {
|
||||
if (file.delete()) {
|
||||
Log.d("UPLOAD", "Lokale DB gelöscht.")
|
||||
exitProcess(0)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user