- Ask authentication password at baresip start if authentication username is
given in account configuration, but password is not.
This commit is contained in:
@@ -80,7 +80,8 @@ class Account(val accp: String) {
|
||||
|
||||
if (authUser != "") res = res + ";auth_user=\"${authUser}\""
|
||||
|
||||
if (authPass != "") res = res + ";auth_pass=\"${authPass}\""
|
||||
if ((authPass != "") && !MainActivity.aorPasswords.containsKey(aor))
|
||||
res = res + ";auth_pass=\"${authPass}\""
|
||||
|
||||
if (outbound.size > 0) {
|
||||
res = res + ";outbound=\"${outbound[0]}\""
|
||||
|
||||
@@ -61,7 +61,10 @@ class AccountActivity : AppCompatActivity() {
|
||||
authUser.setText(acc.authUser)
|
||||
|
||||
authPass = findViewById(R.id.AuthPass) as EditText
|
||||
authPass.setText(acc.authPass)
|
||||
if (MainActivity.aorPasswords.containsKey(aor))
|
||||
authPass.setText("")
|
||||
else
|
||||
authPass.setText(acc.authPass)
|
||||
|
||||
outbound1 = findViewById(R.id.Outbound1) as EditText
|
||||
outbound2 = findViewById(R.id.Outbound2) as EditText
|
||||
@@ -223,7 +226,8 @@ class AccountActivity : AppCompatActivity() {
|
||||
|
||||
val au = authUser.text.toString().trim()
|
||||
val ap = authPass.text.toString().trim()
|
||||
if (((au != "") && (ap == "")) || ((au == "") && (ap != ""))) {
|
||||
|
||||
if ((au == "") && (ap != "")) {
|
||||
Utils.alertView(this, getString(R.string.notice),
|
||||
getString(R.string.authentication_username_password_mismatch))
|
||||
return false
|
||||
@@ -245,10 +249,11 @@ class AccountActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
if (ap != acc.authPass) {
|
||||
if (Utils.checkPrintAscii(ap)) {
|
||||
if ((ap != acc.authPass) && (ap != "")) {
|
||||
if (Utils.checkPrintAscii(ap) && (ap.length <= 64)) {
|
||||
if (account_set_auth_pass(acc.accp, ap) == 0) {
|
||||
acc.authPass = account_auth_pass(acc.accp)
|
||||
MainActivity.aorPasswords.remove(aor)
|
||||
// Log.d("Baresip", "New auth password is ${acc.authPass}")
|
||||
save = true
|
||||
} else {
|
||||
@@ -259,6 +264,11 @@ class AccountActivity : AppCompatActivity() {
|
||||
String.format(getString(R.string.invalid_authentication_password), ap))
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
if ((ap == "") && !MainActivity.aorPasswords.containsKey(aor)) {
|
||||
MainActivity.aorPasswords.put(aor, acc.authPass)
|
||||
save = true
|
||||
}
|
||||
}
|
||||
|
||||
val ob = ArrayList<String>()
|
||||
|
||||
@@ -843,6 +843,16 @@ class BaresipService: Service() {
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
|
||||
}
|
||||
|
||||
@Keep
|
||||
fun getPassword(aor: String): String {
|
||||
if (!isServiceRunning) return ""
|
||||
Log.d(LOG_TAG, "getPassword of $aor")
|
||||
if (MainActivity.aorPasswords[aor] != null)
|
||||
return MainActivity.aorPasswords[aor]!!
|
||||
else
|
||||
return ""
|
||||
}
|
||||
|
||||
@Keep
|
||||
fun stopped(error: String) {
|
||||
Log.d(LOG_TAG, "Received 'stopped' from baresip with param '$error'")
|
||||
|
||||
@@ -424,11 +424,13 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
baresipService = Intent(this@MainActivity, BaresipService::class.java)
|
||||
|
||||
if (!BaresipService.isServiceRunning) {
|
||||
baresipService.setAction("Start")
|
||||
startService(baresipService)
|
||||
Utils.requestPermission(this, Manifest.permission.RECORD_AUDIO,
|
||||
RECORD_PERMISSION_REQUEST_CODE)
|
||||
if (File(filesDir.absolutePath + "/accounts").exists()) {
|
||||
var accounts = String(Utils.getFileContents(filesDir.absolutePath + "/accounts")!!,
|
||||
Charsets.UTF_8).lines().toMutableList()
|
||||
askAorPasswords(accounts)
|
||||
}
|
||||
}
|
||||
|
||||
if (intent.hasExtra("onStartup"))
|
||||
@@ -966,6 +968,53 @@ class MainActivity : AppCompatActivity() {
|
||||
builder.show()
|
||||
}
|
||||
|
||||
private fun askAorPasswords(accounts: MutableList<String>) {
|
||||
if (accounts.isNotEmpty()) {
|
||||
val account = accounts.removeAt(0)
|
||||
val params = account.substringAfter(">")
|
||||
if ((Utils.paramValue(params, "auth_user") != "") &&
|
||||
(Utils.paramValue(params, "auth_pass") == "")) {
|
||||
val aor = account.substringAfter("<").substringBefore(">")
|
||||
val builder = AlertDialog.Builder(this)
|
||||
builder.setTitle(String.format(getString(R.string.account_password), Utils.plainAor(aor)))
|
||||
val viewInflated = LayoutInflater.from(this)
|
||||
.inflate(R.layout.password_dialog, findViewById(android.R.id.content) as ViewGroup,
|
||||
false)
|
||||
val input = viewInflated.findViewById(R.id.password) as EditText
|
||||
builder.setView(viewInflated)
|
||||
builder.setPositiveButton(android.R.string.ok) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
val password = input.text.toString()
|
||||
if ((password.length < 1) || (password.length > 64) || !Utils.checkPrintAscii(password)) {
|
||||
Utils.alertView(this, getString(R.string.notice),
|
||||
String.format(getString(R.string.invalid_authentication_password), password))
|
||||
accounts.add(0, account)
|
||||
} else {
|
||||
aorPasswords.put(aor, password)
|
||||
}
|
||||
askAorPasswords(accounts)
|
||||
}
|
||||
builder.setNegativeButton(android.R.string.cancel) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
aorPasswords.put(aor, "")
|
||||
askAorPasswords(accounts)
|
||||
}
|
||||
builder.show()
|
||||
} else {
|
||||
askAorPasswords(accounts)
|
||||
}
|
||||
} else {
|
||||
startBaresip()
|
||||
}
|
||||
}
|
||||
|
||||
private fun startBaresip() {
|
||||
baresipService.setAction("Start")
|
||||
startService(baresipService)
|
||||
Utils.requestPermission(this, Manifest.permission.RECORD_AUDIO,
|
||||
RECORD_PERMISSION_REQUEST_CODE)
|
||||
}
|
||||
|
||||
private fun backup(password: String) {
|
||||
val files = arrayListOf("accounts", "calls", "config", "contacts", "messages", "uuid",
|
||||
"zrtp_cache.dat", "zrtp_zid", "cert.pem", "ca_cert", "ca_certs.crt")
|
||||
@@ -1365,6 +1414,7 @@ class MainActivity : AppCompatActivity() {
|
||||
var resumeUap = ""
|
||||
var resumeCall: Call? = null
|
||||
var resumeUri = ""
|
||||
val aorPasswords = mutableMapOf<String, String>()
|
||||
|
||||
const val ACCOUNTS_CODE = 1
|
||||
const val CONTACTS_CODE = 2
|
||||
|
||||
@@ -97,6 +97,12 @@ object Utils {
|
||||
return if (domain == aor) "" else domain
|
||||
}
|
||||
|
||||
fun plainAor(aor: String): String {
|
||||
return aor.substringAfter(":").substringBefore("@") + "@" +
|
||||
aor.substringAfter("@").substringBefore(";")
|
||||
.substringBefore(":")
|
||||
}
|
||||
|
||||
fun checkAor(aor: String): Boolean {
|
||||
val p = aor.split(":")
|
||||
if (p.size == 2)
|
||||
|
||||
Reference in New Issue
Block a user