Skip to content

Commit

Permalink
Stable version 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjunetime committed Jan 9, 2021
1 parent 1faf195 commit 2d4f200
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 53 deletions.
2 changes: 1 addition & 1 deletion docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog
0.6.3 → 0.7.0
- Re-added option to start the server upon app launch
- Server auto-restarts itself without de-authenticating any clients automatically when the host device's network changes
- Added option to automatically restart server without de-authenticating any clients automatically when the host device's network changes
- Added security improvements to prevent brute-forcing of password
- Added significantly more error checking for private API functions
- Added API Documentation & Donation link in Settings
Expand Down
4 changes: 4 additions & 0 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ fi

if [ "$deb" = true ] || [ "$ipa" = true ]
then
pn "\033[34m==>\033[0m Checking LLVM Version..."
llvm_vers=$(llvm-gcc --version | grep -oE "clang\-[0-9]{4,}" | sed 's/clang\-//g')
[ ${llvm_vers} -lt 1200 ] && err "Please use llvm >= 12.0.0 to compile"

rm -rf ${ROOTDIR}/package/SMServer.xcarchive
pn "\033[34m==>\033[0m Cleaning and archiving package..."
xcodebuild clean archive -workspace ${ROOTDIR}/src/SMServer.xcworkspace -scheme SMServer -archivePath ${ROOTDIR}/package/SMServer.xcarchive -destination generic/platform=iOS
Expand Down
Binary file not shown.
10 changes: 10 additions & 0 deletions src/SMServer/html/chats.html
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,9 @@
case "typing":
setChatAsTyping(content);
break;
case "idle":
setChatAsIdle(content);
break;
default:
console.log(`cannot handle request: '${msg}'`);
break;
Expand Down Expand Up @@ -1178,6 +1181,13 @@
}
}

function setChatAsIdle(chat) {
if (debug) console.log(`setting ${chat} as idle`);
var current = document.getElementById("typingIndicator");
if (chat !== current_chat_id || current === null || current === undefined) return;
current.outerHTML = "";
}

function enableSubject() {
if (debug) console.log("enabling subject");
var tbox = document.getElementById("sendbox");
Expand Down
2 changes: 1 addition & 1 deletion src/SMServer/ios/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ struct ContentView: View {
}
}) {
Image(systemName: "trash")
.padding(12)
.padding(8)
.background(Color.blue)
.cornerRadius(40)
.foregroundColor(Color.white)
Expand Down
105 changes: 60 additions & 45 deletions src/SMServer/ios/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,19 @@ struct SettingsView: View {
self.settings.start_on_load = $0
UserDefaults.standard.setValue($0, forKey: "start_on_load")
})

let reload_binding = Binding<Bool>(get: {
self.settings.reload_on_network_change
}, set: {
self.settings.reload_on_network_change = $0
UserDefaults.standard.setValue($0, forKey: "reload_on_network_change")
})

return ScrollView {
VStack(alignment: .leading, spacing: 16) {
Text("Settings")
.font(.largeTitle)

Spacer().frame(height: 8)

Text("Load values")
.font(.headline)

Expand Down Expand Up @@ -236,12 +241,10 @@ struct SettingsView: View {
Toggle("WebSocket Proxy Compatibility", isOn: socket_subdir_enabled_binding)

if socket_subdir_enabled {
HStack {
Text("Socket subdirectory")
Spacer()
VStack(alignment: .leading) {
Text("WebSocket subdirectory")
TextField("e.g. /sms/socket", text: socket_subdir_binding)
.textFieldStyle(RoundedBorderTextFieldStyle())
.frame(width: 180)
.disableAutocorrection(true)
}
}
Expand All @@ -260,11 +263,12 @@ struct SettingsView: View {
Section {
VStack(spacing: 8) {

Toggle("Toggle debug", isOn: debug_binding)
Toggle("Enable debug", isOn: debug_binding)
Toggle("Enable backgrounding", isOn: background_binding)
Toggle("Enable SSL", isOn: secure_binding)
Toggle("Allow operation off of Wifi", isOn: override_binding)
Toggle("Start server on app launch", isOn: load_binding)
Toggle("Restart server on network change", isOn: reload_binding)

}
}.padding(10)
Expand All @@ -281,68 +285,79 @@ struct SettingsView: View {
Alert(title: Text("Settings Reset"), message: Text("Your settings were reset to default"))
})

/// ok so this VStack still has an absurd amount of padding on the top and bottom when you have a large text size, for some reason.
/// I'll fix that eventually
VStack(alignment: .leading) {
GeometryReader { proxy in
LinearGradient(
gradient: Gradient(
colors: [
Color.init(red: cl_red, green: (Double(proxy.frame(in: .named("frameLayer")).minY) - 240) / 400, blue: cl_blu),
Color.init(red: cl_red, green: (Double(proxy.frame(in: .named("frameLayer")).minY) - 310) / 400, blue: cl_blu)
]
),
startPoint: .topLeading, endPoint: .bottomTrailing
).mask(
VStack {
Button(action: {
let github_url = URL.init(string: "https://github.com/iandwelker/smserver/blob/master/docs/API.md")
guard let url = github_url, UIApplication.shared.canOpenURL(url) else { return }
UIApplication.shared.open(url)
}) {
ZStack {
GeometryReader { proxy in
/// makes vibrant, shiny text thing. Very nice. Padding is :( tho
LinearGradient(
gradient: Gradient(
colors: [
Color.init(red: self.cl_red, green: (Double(proxy.frame(in: .named("frameLayer")).minY) - 240) / 400, blue: self.cl_blu),
Color.init(red: self.cl_red, green: (Double(proxy.frame(in: .named("frameLayer")).minY) - 310) / 400, blue: self.cl_blu)
]
),
startPoint: .topLeading, endPoint: .bottomTrailing
).mask(
VStack {
HStack {
Text("View API Documentation")
.aspectRatio(contentMode: .fill)
Spacer()
Image(systemName: "doc.text")
}
}

Spacer().frame(height: 20)
Spacer().frame(height: 20)

Button(action: {
let url = URL.init(string: "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=K3A6WVKT54PH4&item_name=Tweak%2FApplication+Development&currency_code=USD")
guard let github_url = url, UIApplication.shared.canOpenURL(github_url) else { return }
UIApplication.shared.open(github_url)
}) {
HStack {
Text("Donate to support SMServer")
Spacer()
Image(systemName: "link")
}
}

Spacer().frame(height: 20)
Spacer().frame(height: 20)

Button(action: {
self.resetDefaults()
}) {
HStack {
Text("Reset Settings to Default")
Spacer()
Image(systemName: "arrow.clockwise")
}
}
}
)
}.padding(10)
.background(grey_box)
.cornerRadius(8)
.frame(height: 120) /// yeah don't like this but I think it may be the only thing
)
}

Text("Compatible with libSMServer 0.6.0")
.font(.callout)
.foregroundColor(.gray)
VStack {
Button(action: {
let github_url = URL.init(string: "https://github.com/iandwelker/smserver/blob/master/docs/API.md")
guard let url = github_url, UIApplication.shared.canOpenURL(url) else { return }
UIApplication.shared.open(url)
}) {
Text("").foregroundColor(Color.clear)
}.padding(.bottom, 10)

Button(action: {
let paypal_url = URL.init(string: "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=K3A6WVKT54PH4&item_name=Tweak%2FApplication+Development&currency_code=USD")
guard let url = paypal_url, UIApplication.shared.canOpenURL(url) else { return }
UIApplication.shared.open(url)
}) {
Text("").foregroundColor(Color.clear)
}.padding(.init(top: 10, leading: 0, bottom: 10, trailing: 0))

Button(action: {
self.resetDefaults()
}) {
Text("").foregroundColor(Color.clear)
}.padding(.top, 10)
}
}
}.padding(10)
.background(grey_box)
.cornerRadius(8)

}
Text("Compatible with libSMServer 0.6.0")
.font(.callout)
.foregroundColor(.gray)

}.padding()
.animation(.easeInOut(duration: 0.2))
Expand Down
10 changes: 5 additions & 5 deletions src/SMServer/shared/ChatDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,18 @@ final class ChatDelegate {
/// check if it's a group chat
let is_group = num.prefix(4) == "chat" && !num.contains("@") && num.count >= 20
var from_string: String = ""
var fixed_num = num
var fixed_num = "?"

if num.contains(",") {
/// So that you can merge multiple conversations
fixed_num = num.split(separator: ",").joined(separator: "\" or chat_identifier is \"")
fixed_num = [String](repeating: "?", count: num.split(separator: ",").count).joined(separator: " or chat_identifier is ")
}

if from != 0 {
from_string = " and \(is_group ? "m." : "")is_from_me is \(from == 1 ? 1 : 0)"
from_string = " and m.is_from_me is \(from == 1 ? 1 : 0)"
}

var messages: [[String:Any]] = selectFromSql(db: db, columns: ["m.ROWID", "m.guid", "m.text", "m.subject", "m.is_from_me", "m.date", "m.service", "m.cache_has_attachments", "m.balloon_bundle_id", "m.payload_data", "m.associated_message_guid", "m.associated_message_type", "h.id"], table: "message m", condition: "left join handle h on h.ROWID = m.handle_id where m.ROWID in (select message_id from chat_message_join where chat_id in (select ROWID from chat where chat_identifier is ?\(from_string))) order by m.date desc", args: [fixed_num], num_items: num_items, offset: offset, split_ids: true)
var messages: [[String:Any]] = selectFromSql(db: db, columns: ["m.ROWID", "m.guid", "m.text", "m.subject", "m.is_from_me", "m.date", "m.service", "m.cache_has_attachments", "m.balloon_bundle_id", "m.payload_data", "m.associated_message_guid", "m.associated_message_type", "h.id"], table: "message m", condition: "left join handle h on h.ROWID = m.handle_id where m.ROWID in (select message_id from chat_message_join where chat_id in (select ROWID from chat where chat_identifier is \(fixed_num)\(from_string))) order by m.date desc", args: num.split(separator: ",").map({String($0)}), num_items: num_items, offset: offset, split_ids: true)

parseTexts(&messages, db: db, contact_db: contact_db, is_group: is_group)

Expand Down
4 changes: 3 additions & 1 deletion src/SMServer/shared/ServerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class ServerDelegate {
/// This is kinda a hacky way sending the notification into a `CFNotificationCallback`, which then posts a notification in the `NSNotificationCenter`), but
/// it is necessary. The `CFNotificationCallback` can't capture context, but the `NSNotificationCenter` callback can. We need to capture context for our purposes,
/// so this seemed like the most efficient solution to accomplish that.

/// However, it does post the notification like 10 times in 5 seconds, so that's why we have to have the special checks in the `reloadServer(_:)` function

let callback: CFNotificationCallback = { (nc, observer, name, object, info) in
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ianwelker.smserver.system.config.network_change"), object: nil)
Expand All @@ -74,7 +76,7 @@ class ServerDelegate {
}

@objc func reloadServer(_: Notification) {
if restarted_recently { return }
if restarted_recently || !settings.reload_on_network_change { return }

Const.log("Disconnected from wifi, restarting server with current auth list...", debug: self.debug)

Expand Down
1 change: 1 addition & 0 deletions src/SMServer/shared/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Settings {
var send_typing: Bool = UserDefaults.standard.object(forKey: "send_typing") as? Bool ?? true
var combine_contacts: Bool = UserDefaults.standard.object(forKey: "combine_contacts") as? Bool ?? false
var start_on_load: Bool = UserDefaults.standard.object(forKey: "start_on_load") as? Bool ?? false
var reload_on_network_change: Bool = UserDefaults.standard.object(forKey: "reload_on_network_change") as? Bool ?? true

#if os(macOS)
var config_file_url: String = Const.config_file_url.path
Expand Down

0 comments on commit 2d4f200

Please sign in to comment.