Skip to content
This repository has been archived by the owner on Nov 4, 2020. It is now read-only.

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chandlerhuff committed Jan 3, 2019
1 parent 36e9a73 commit d718248
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 12 deletions.
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Resources/Views/account.leaf
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<div class="controls">
<div class="input-prepend input-group">
<span class="input-group-addon"><i class="icon-key"></i></span>
<input type="text" spellcheck="false" class="form-control" placeholder="Twilio Auth Token" name="authToken">
<input type="text" spellcheck="false" class="form-control" placeholder="Twilio Auth Token" name="authToken" value="#(authToken)">
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Views/user.leaf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#set("scripts") {
<script type="text/javascript" src="/vendors/js/qrcode.js"></script>
<script>
jQuery('#code').qrcode("otpauth://totp/Fax%20Server:#(email)?secret=#(totpToken)&issuer=Fax%20Server&algorithm=SHA1&digits=6&period=30");
jQuery('#code').qrcode("#(totpToken)");
</script>
}
#set("main") {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Server/MainApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -55,7 +55,7 @@ public final class MainApplication {
services: services
)
} catch {
print(error)
Logger.error("Start Error: \(error)")
exit(1)
}
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/Server/Models/Fax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ extension String {
}
}

struct TwilioError: Codable {
let code: Int
let message: String
}

struct TwilioFax: Codable {

// MARK: - Parameters
Expand Down
2 changes: 1 addition & 1 deletion Sources/Server/Providers/MongoProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Server/Providers/PushProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 9 additions & 3 deletions Sources/Server/Routes/Account+Routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
])
Expand Down Expand Up @@ -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 {
Expand All @@ -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)"))
Expand Down
6 changes: 6 additions & 0 deletions Sources/Server/Routes/Fax+Routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions Sources/Server/Routes/Message+Routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Server/Utilities/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

1 comment on commit d718248

@atoliy
Copy link

@atoliy atoliy commented on d718248 Jan 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Times out if the PDF fax attachment is over 3MB

Please sign in to comment.