Skip to content

Commit 39e7277

Browse files
fix some broken PortalLiberators
Co-authored-by: programminghoch10 <16062290+programminghoch10@users.noreply.github.com>
1 parent 5a17a2b commit 39e7277

7 files changed

Lines changed: 14 additions & 12 deletions

File tree

liberator/src/main/kotlin/de/binarynoise/liberator/Liberator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ class Liberator(
171171
return recurse(response, depth + 1)
172172
}
173173

174-
log("solver ${solver::class.simpleName} found for $response.requestUrl")
174+
log("solver ${solver::class.simpleName} found for ${response.requestUrl}")
175175
solver.solve(client, response, cookies)
176-
log("solver ${solver::class.simpleName} finished processing $response.requestUrl")
176+
log("solver ${solver::class.simpleName} finished processing ${response.requestUrl}")
177177

178178
return LiberationResult.Success(response.requestUrl.toString())
179179
} catch (e: Exception) {

liberator/src/main/kotlin/de/binarynoise/liberator/portals/CloudWifi.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import de.binarynoise.util.okhttp.readText
1313
import de.binarynoise.util.okhttp.requestUrl
1414
import okhttp3.Cookie
1515
import okhttp3.HttpUrl.Companion.toHttpUrl
16+
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
1617
import okhttp3.OkHttpClient
1718
import okhttp3.Response
1819

@@ -73,13 +74,13 @@ object CloudWifiRedirect : PortalLiberator {
7374
.getElementsByTag("script")
7475
.map { it.attr("src") }
7576
.filter { it.isNotEmpty() }
76-
.map { it.toHttpUrl() }
77+
.mapNotNull { it.toHttpUrlOrNull() }
7778
.any { url -> url.host == "start.cloudwifi.de" && url.pathSegments.any { it == "redirect" } }
7879
}
7980

8081
override fun solve(client: OkHttpClient, response: Response, cookies: Set<Cookie>) {
8182
val html1 = response.parseHtml()
82-
val script1 = html1.getElementsByTag("body").single().getElementsByTag("script").single().wholeText()
83+
val script1 = html1.getElementsByTag("body").single().getElementsByTag("script").single().data()
8384
val assignments = RhinoParser().parseAssignments(script1)
8485

8586
val deviceMac = assignments["FX_redirect.0"] ?: error("no deviceMac")

liberator/src/main/kotlin/de/binarynoise/liberator/portals/Conn4.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ object Conn4 : PortalLiberator {
202202
}
203203

204204
fun getTariffPreference(session: JSONObject): List<JSONObject> {
205-
val tariffs = session.getJSONArray("tariffs").filterIsInstance<JSONObject>()
205+
val tariffs = session.getJSONArray("tariffs").asIterable().filterIsInstance<JSONObject>()
206206
if (tariffs.hasOneEntry) return tariffs
207207
fun JSONObject.isBooleanEqualTo(key: String, value: Boolean, default: Boolean): Boolean {
208208
if (!this.has(key)) return default
@@ -359,7 +359,7 @@ object Conn4 : PortalLiberator {
359359
cookies: Set<Cookie>,
360360
) {
361361
val token = cookies.find { it.name == "wbs-token" }?.value ?: error("no wbs-token cookie")
362-
val apiBase = response.requestUrl.resolveOrThrow("/wbs/api/v1") // TODO: properly parse wbs api base from scrips
362+
val apiBase = response.requestUrl.resolveOrThrow("/wbs/api/v1/") // TODO: properly parse wbs api base from scrips
363363
tryPossibleTariffs(client, apiBase, token, site_id)
364364
}
365365
}

liberator/src/main/kotlin/de/binarynoise/liberator/portals/DBWifi.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ object DBWifi : PortalLiberator {
3939
check(JSONObject(response2.readText()).getString("result") == "success") { "response does not contain success" }
4040
}
4141
"sp" == response1.requestUrl.firstPathSegment -> {
42-
// works
4342
log("sp")
4443
client.postForm(
45-
response.requestUrl, "/login", mapOf(
44+
response1.requestUrl, "/login", mapOf(
4645
"login" to "oneclick",
4746
"oneSubscriptionForm_connect_policy_accept" to "on",
4847
)

liberator/src/main/kotlin/de/binarynoise/liberator/portals/SocialwiBox.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ object SocialwiBox : PortalLiberator {
3434
val response3 = client.get(response.requestUrl, location2).followRedirects(client)
3535
val html3 = response3.parseHtml()
3636

37-
val script3 = html3.getElementsByTag("script").find { it.wholeText().contains("redirectPost") }
37+
val script3 = html3.getElementsByTag("script").find { it.data().contains("redirectPost") }
3838
?: error("no script with redirectPost")
3939

4040
val regex = "redirectPost\\('([^']+)',\\s*(\\{.*\\})\\);".toRegex()
41-
val match = regex.find(script3.wholeText()) ?: error("no match for redirectPost regex")
41+
val match = regex.find(script3.data()) ?: error("no match for redirectPost regex")
4242
val url = match.groups[1]?.value ?: error("no url in match")
4343
val data = match.groups[2]?.value ?: error("no data in match")
4444
val json = JSONObject(data)

liberator/src/main/kotlin/de/binarynoise/liberator/portals/Unwired.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package de.binarynoise.liberator.portals
33
import de.binarynoise.liberator.PortalLiberator
44
import de.binarynoise.liberator.PortalLiberatorConfig
55
import de.binarynoise.liberator.SSID
6+
import de.binarynoise.liberator.asIterable
67
import de.binarynoise.liberator.cast
78
import de.binarynoise.util.okhttp.checkSuccess
89
import de.binarynoise.util.okhttp.postJson
@@ -61,7 +62,7 @@ object Unwired : PortalLiberator {
6162
)
6263
val json1 = JSONObject(response1.readText())
6364

64-
val pages = json1.getJSONObject("data").getJSONObject("splashpage").getJSONArray("pages")
65+
val pages = json1.getJSONObject("data").getJSONObject("splashpage").getJSONArray("pages").asIterable()
6566

6667
val widgets = pages.flatMap { it.cast<JSONObject>().getJSONArray("widgets") }
6768

liberator/src/main/kotlin/de/binarynoise/liberator/portals/VodafoneHotspot.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package de.binarynoise.liberator.portals
33
import de.binarynoise.liberator.Experimental
44
import de.binarynoise.liberator.PortalLiberator
55
import de.binarynoise.liberator.SSID
6+
import de.binarynoise.liberator.asIterable
67
import de.binarynoise.liberator.tryOrNull
78
import de.binarynoise.util.okhttp.get
89
import de.binarynoise.util.okhttp.parseJsonObject
@@ -28,7 +29,7 @@ object VodafoneHotspot : PortalLiberator {
2829
override fun solve(client: OkHttpClient, response: Response, cookies: Set<Cookie>) {
2930
val session = client.get(response.requestUrl, "/api/v4/session").parseJsonObject()
3031
val sessionToken = session.getString("session")
31-
val landingPageElements = session.getJSONArray("landingPageElements")
32+
val landingPageElements = session.getJSONArray("landingPageElements").asIterable()
3233
val landingPageLoginProfileId = landingPageElements.filterIsInstance<JSONObject>()
3334
.first { tryOrNull { it.getString("type") } == "loginProfile" }
3435
.getString("value")

0 commit comments

Comments
 (0)