diff --git a/Dockerfile b/Dockerfile index 2950a0e..b4f68a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,16 +3,26 @@ FROM ubuntu:16.04 LABEL maintainer="bludesign" # Set Default Timezone -RUN echo GMT > /etc/timezone +ENV TZ=GMT +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone # Install CURL and tzdata RUN apt-get update && \ - apt-get -y install curl libcurl4-openssl-dev tzdata && \ + apt-get -y install wget curl openssl libssl-dev libcurl4-openssl-dev libavahi-compat-libdnssd-dev tzdata build-essential && \ rm -rf /var/lib/apt/lists/*; # Configure tzdata RUN dpkg-reconfigure -f noninteractive tzdata +# Install libsodium +RUN wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.16.tar.gz && \ + tar xzf libsodium-1.0.16.tar.gz && \ + cd libsodium-1.0.16 && \ + ./configure && \ + make && make check && \ + make install && \ + ldconfig + # Get Vapor repo including Swift RUN curl -sL https://apt.vapor.sh | bash; diff --git a/Resources/Views/account.leaf b/Resources/Views/account.leaf index 56ee6b2..9b5890d 100644 --- a/Resources/Views/account.leaf +++ b/Resources/Views/account.leaf @@ -79,7 +79,7 @@
- +
diff --git a/Resources/Views/user.leaf b/Resources/Views/user.leaf index 1b53221..cacd14d 100644 --- a/Resources/Views/user.leaf +++ b/Resources/Views/user.leaf @@ -2,7 +2,7 @@ #set("scripts") { } #set("main") { diff --git a/Sources/Server/MainApplication.swift b/Sources/Server/MainApplication.swift index 6e4410d..482f816 100644 --- a/Sources/Server/MainApplication.swift +++ b/Sources/Server/MainApplication.swift @@ -42,7 +42,7 @@ public final class MainApplication { services.registerMiddlewares() services.register { container -> NIOServerConfig in - var config = NIOServerConfig.default() + var config = NIOServerConfig.default(maxBodySize: 250_000_000) if environment.isRelease == false { config.hostname = "0.0.0.0" } @@ -55,7 +55,7 @@ public final class MainApplication { services: services ) } catch { - print(error) + Logger.error("Start Error: \(error)") exit(1) } } diff --git a/Sources/Server/Models/Fax.swift b/Sources/Server/Models/Fax.swift index c621a3f..cf80e80 100644 --- a/Sources/Server/Models/Fax.swift +++ b/Sources/Server/Models/Fax.swift @@ -36,6 +36,11 @@ extension String { } } +struct TwilioError: Codable { + let code: Int + let message: String +} + struct TwilioFax: Codable { // MARK: - Parameters diff --git a/Sources/Server/Providers/MongoProvider.swift b/Sources/Server/Providers/MongoProvider.swift index 1b7abb7..06e65b6 100644 --- a/Sources/Server/Providers/MongoProvider.swift +++ b/Sources/Server/Providers/MongoProvider.swift @@ -46,7 +46,7 @@ final class MongoProvider: Provider { // } database = server[databaseName] } catch let error { - print(error) + Logger.error("Mongo Provider Start Error: \(error)") exit(1) } } diff --git a/Sources/Server/Providers/PushProvider.swift b/Sources/Server/Providers/PushProvider.swift index e49d54f..f6b659c 100644 --- a/Sources/Server/Providers/PushProvider.swift +++ b/Sources/Server/Providers/PushProvider.swift @@ -110,7 +110,7 @@ final class PushProvider: Vapor.Provider { struct Notification: Content { let username: String = "fax" - let icon_url = "https://reaumur.tk/logo.png" // TODO: FIX LOGO + let icon_url = "https://bludesign.biz/faxserver.png" let attachments: [Attachment] struct Attachment: Content { diff --git a/Sources/Server/Routes/Account+Routes.swift b/Sources/Server/Routes/Account+Routes.swift index 74acb79..c62e55d 100644 --- a/Sources/Server/Routes/Account+Routes.swift +++ b/Sources/Server/Routes/Account+Routes.swift @@ -111,7 +111,7 @@ struct AccountRouter { if let accountSid = formData.accountSid { document["accountSid"] = accountSid } - if let authToken = formData.authToken, authToken.isEmpty == false { + if let authToken = formData.authToken, authToken.isEmpty == false, authToken != Constants.hiddenText { document["authToken"] = authToken } @@ -134,12 +134,14 @@ struct AccountRouter { if request.jsonResponse { return promise.submit(try document.makeResponse(request)) } else { + let hasAuthToken = document["authToken"] as? String != nil let context = TemplateData.dictionary([ "accountName": .string(try document.extract("accountName") as String), "notificationEmail": .string(try document.extract("notificationEmail") as String), "phoneNumber": .string(try document.extract("phoneNumber") as String), "accountSid": .string(try document.extract("accountSid") as String), "accountId": .string(objectId.hexString), + "authToken": .string(hasAuthToken ? Constants.hiddenText : ""), "admin": .bool(authentication.permission.isAdmin), "contactsEnabled": .bool(Admin.settings.googleClientId != nil && Admin.settings.googleClientSecret != nil) ]) @@ -196,8 +198,10 @@ struct AccountRouter { ("Accept", "application/json"), ]) requestClient.get("\(Constants.Twilio.messageUrl)/Accounts/\(accountSid)/IncomingPhoneNumbers.json?PhoneNumber=\(accountPhoneNumber)", headers: headers).do { response in - Logger.info("Response: \(response)") guard response.http.status.isValid else { + if let error = try? response.content.syncDecode(TwilioError.self) { + return promise.fail(error: ServerAbort(response.http.status, reason: "\(error.code): \(error.message)")) + } return promise.fail(error: ServerAbort(response.http.status, reason: "Twilio reponse error")) } do { @@ -211,8 +215,10 @@ struct AccountRouter { requestClient.post("\(Constants.Twilio.messageUrl)/Accounts/\(accountSid)/IncomingPhoneNumbers/\(phoneNumber.sid).json", headers: headers, beforeSend: { request in try request.content.encode(Request(smsUrl: "\(url)/message/twiml", smsMethod: "POST"), as: .urlEncodedForm) }).do { response in - Logger.info("POST Response: \(response)") guard response.http.status.isValid else { + if let error = try? response.content.syncDecode(TwilioError.self) { + return promise.fail(error: ServerAbort(response.http.status, reason: "\(error.code): \(error.message)")) + } return promise.fail(error: ServerAbort(response.http.status, reason: "Twilio reponse error")) } return promise.succeed(result: request.serverStatusRedirect(status: .ok, to: "/account/\(objectId.hexString)")) diff --git a/Sources/Server/Routes/Fax+Routes.swift b/Sources/Server/Routes/Fax+Routes.swift index ce9beea..eeb7d31 100644 --- a/Sources/Server/Routes/Fax+Routes.swift +++ b/Sources/Server/Routes/Fax+Routes.swift @@ -234,6 +234,9 @@ struct FaxRouter { guard response.http.status.isValid else { document["status"] = "failed" try Fax.collection.update("_id" == objectId, to: document) + if let error = try? response.content.syncDecode(TwilioError.self) { + throw ServerAbort(response.http.status, reason: "\(error.code): \(error.message)") + } throw ServerAbort(response.http.status, reason: "Twilio reponse error") } @@ -535,6 +538,9 @@ struct FaxRouter { ]) requestClient.get("\(Constants.Twilio.faxUrl)/Faxes/\(twilioFax.sid)", headers: headers).do { response in guard response.http.status.isValid else { + if let error = try? response.content.syncDecode(TwilioError.self) { + return promise.fail(error: ServerAbort(response.http.status, reason: "\(error.code): \(error.message)")) + } return promise.fail(error: ServerAbort(response.http.status, reason: "Twilio reponse error")) } do { diff --git a/Sources/Server/Routes/Message+Routes.swift b/Sources/Server/Routes/Message+Routes.swift index 6d69e48..406dedb 100644 --- a/Sources/Server/Routes/Message+Routes.swift +++ b/Sources/Server/Routes/Message+Routes.swift @@ -322,6 +322,9 @@ struct MessageRouter { guard response.http.status.isValid else { document["status"] = "failed" try Message.collection.update("_id" == objectId, to: document) + if let error = try? response.content.syncDecode(TwilioError.self) { + throw ServerAbort(response.http.status, reason: "\(error.code): \(error.message)") + } throw ServerAbort(response.http.status, reason: "Twilio reponse error") } diff --git a/Sources/Server/Utilities/Extensions.swift b/Sources/Server/Utilities/Extensions.swift index 79fccfe..922b151 100644 --- a/Sources/Server/Utilities/Extensions.swift +++ b/Sources/Server/Utilities/Extensions.swift @@ -445,7 +445,7 @@ struct Email { var html: String? } var formData = FormData() - formData.from = "Reaumur Server <\(Admin.settings.mailgunFromEmail)>" + formData.from = "Fax Server <\(Admin.settings.mailgunFromEmail)>" formData.to = to formData.subject = subject guard let htmlBodyString = String(data: htmlBody, encoding: .utf8) else {