Browse Source

remove the workaround introduced in 36acf1a00a and update the Dockerfile

pull/18/head
Jannik 2 years ago
parent
commit
46c9a61124
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 8
      Dockerfile
  2. 42
      src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/CourseListParser.kt
  3. 40
      src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/TimetableParser.kt
  4. 2
      src/main/resources/application.properties

8
Dockerfile

@ -1,4 +1,8 @@
FROM openjdk:11
FROM adoptopenjdk/openjdk11:alpine-jre
RUN addgroup -S spring && adduser -S spring -G spring
#RUN groupadd -r spring && useradd -r -g spring spring # for openjdk:xx builds
USER spring:spring
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} thecitadelofricks.jar
ENTRYPOINT ["java","-jar","/thecitadelofricks.jar"]
ENTRYPOINT ["java","-Djavax.net.ssl.trustStore=/tcor/cacerts", "-Djavax.net.ssl.trustStorePassword=changeit", "-jar","/thecitadelofricks.jar"]
VOLUME /tcor

42
src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/CourseListParser.kt

@ -26,17 +26,10 @@ import org.jsoup.Jsoup
import org.mosad.thecitadelofricks.Course
import org.slf4j.LoggerFactory
import java.net.SocketTimeoutException
import java.security.KeyManagementException
import java.security.cert.CertificateException
import java.security.cert.X509Certificate
import javax.net.ssl.SSLContext
import javax.net.ssl.SSLSocketFactory
import javax.net.ssl.TrustManager
import javax.net.ssl.X509TrustManager
class CourseListParser {
private var logger: org.slf4j.Logger = LoggerFactory.getLogger(MensaParser::class.java)
private var logger: org.slf4j.Logger = LoggerFactory.getLogger(CourseListParser::class.java)
/**
* return a list of all courses at courseListURL
@ -46,7 +39,7 @@ class CourseListParser {
fun getCourseLinks(courseListURL: String): HashMap<String, Course>? {
val courseLinkList = HashMap<String, Course>()
try {
val courseHTML = Jsoup.connect(courseListURL).sslSocketFactory(socketFactory()).get()
val courseHTML = Jsoup.connect(courseListURL).get()
courseHTML.select("ul.index-group").select("li.Class").select("a[href]").forEachIndexed { _, element ->
courseLinkList[element.text()] = Course(
@ -54,6 +47,7 @@ class CourseListParser {
element.attr("href").replace("http", "https")
)
}
logger.info("successfully retrieved course List")
} catch (ex: SocketTimeoutException) {
logger.warn("timeout from hs-offenburg.de, updating on next attempt!")
return null
@ -64,34 +58,4 @@ class CourseListParser {
return courseLinkList
}
// Hack to ignore ssl errors while reading
private fun socketFactory(): SSLSocketFactory {
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
@Throws(CertificateException::class)
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
}
@Throws(CertificateException::class)
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
}
override fun getAcceptedIssuers(): Array<X509Certificate> {
return arrayOf()
}
})
try {
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
return sslContext.socketFactory
} catch (e: Exception) {
when (e) {
is RuntimeException, is KeyManagementException -> {
throw RuntimeException("Failed to create a SSL socket factory", e)
}
else -> throw e
}
}
}
}

40
src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/TimetableParser.kt

@ -27,13 +27,6 @@ import org.jsoup.nodes.Document
import org.mosad.thecitadelofricks.Lesson
import org.mosad.thecitadelofricks.TimetableWeek
import org.slf4j.LoggerFactory
import java.security.KeyManagementException
import java.security.cert.CertificateException
import java.security.cert.X509Certificate
import javax.net.ssl.SSLContext
import javax.net.ssl.SSLSocketFactory
import javax.net.ssl.TrustManager
import javax.net.ssl.X509TrustManager
class TimetableParser {
private var logger: org.slf4j.Logger = LoggerFactory.getLogger(TimetableParser::class.java)
@ -47,7 +40,7 @@ class TimetableParser {
*/
fun getTimeTable(timetableURL: String): TimetableWeek {
return try {
parseTimeTable(Jsoup.connect(timetableURL).sslSocketFactory(socketFactory()).get())
parseTimeTable(Jsoup.connect(timetableURL).get())
} catch (gex: Exception) {
logger.error("general TimetableParser error", gex)
TimetableWeek()
@ -129,7 +122,7 @@ class TimetableParser {
*/
fun getWeekNumberYear(timetableURL: String): Int {
return try {
parseWeekNumberYear(Jsoup.connect(timetableURL).sslSocketFactory(socketFactory()).get())
parseWeekNumberYear(Jsoup.connect(timetableURL).get())
} catch (gex: Exception) {
logger.error("general TimetableParser error", gex)
0
@ -189,33 +182,4 @@ class TimetableParser {
println(" \n")
}
// Hack to ignore ssl errors while reading
private fun socketFactory(): SSLSocketFactory {
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
@Throws(CertificateException::class)
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
}
@Throws(CertificateException::class)
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
}
override fun getAcceptedIssuers(): Array<X509Certificate> {
return arrayOf()
}
})
try {
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
return sslContext.socketFactory
} catch (e: Exception) {
when (e) {
is RuntimeException, is KeyManagementException -> {
throw RuntimeException("Failed to create a SSL socket factory", e)
}
else -> throw e
}
}
}
}

2
src/main/resources/application.properties

@ -11,5 +11,5 @@ logging.level.org.springframework.web=INFO
# ----------------------------------------
# EMBEDDED SERVER CONFIGURATION (ServerProperties)
server.address=127.0.0.1
server.address=0.0.0.0
server.port=8080
Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close