Skip to content

Commit

Permalink
added network changing detection to reload page
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Jul 29, 2022
1 parent 2b022b4 commit de4acf0
Show file tree
Hide file tree
Showing 20 changed files with 1,050 additions and 144 deletions.
9 changes: 2 additions & 7 deletions XCreds Login Overlay/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
*/
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
window.level = .modalPanel
window.canBecomeVisibleWithoutLogin=true
NSApp.activate(ignoringOtherApps: true)
window.hidesOnDeactivate=false
window.isOpaque=false
window.orderFrontRegardless()




var statusWindowRect=window.frame
Expand Down
2 changes: 2 additions & 0 deletions XCreds-Login-Overlay-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<dict>
<key>LSUIElement</key>
<string>1</string>
<key>LogFileName</key>
<string>xcreds.log</string>
</dict>
</plist>
3 changes: 1 addition & 2 deletions XCreds/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var loginPasswordWindow: NSWindow!
@IBOutlet var window: NSWindow!
var mainController:MainController?

var wifiWindowController:WifiWindowController?
func applicationDidFinishLaunching(_ aNotification: Notification) {


let infoPlist = Bundle.main.infoDictionary

if let infoPlist = infoPlist, let build = infoPlist["CFBundleVersion"] {
Expand Down
2 changes: 2 additions & 0 deletions XCreds/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<dict>
<key>LSUIElement</key>
<true/>
<key>LogFileName</key>
<string>xcreds.log</string>
</dict>
</plist>
17 changes: 15 additions & 2 deletions XCreds/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ extension WebViewController: WKNavigationDelegate {


let customURL = UserDefaults.standard.value(forKey: PrefKeys.customURL.rawValue)
let customPasswordElementID = UserDefaults.standard.value(forKey: PrefKeys.customPasswordElementID.rawValue)
let customPasswordElementID = UserDefaults.standard.value(forKey: PrefKeys.customPasswordElementID.rawValue) as? String ?? "passwordInput"
// if it's a POST let's see what we're posting...
if navigationAction.request.httpMethod == "POST" {
if let customURL = customURL as? String, let customPasswordElementID = customPasswordElementID as? String , navigationAction.request.url?.host == customURL {
TCSLogWithMark("POST")
if let customURL = customURL as? String, navigationAction.request.url?.host == customURL {
TCSLogWithMark(customURL.sanitized())

let javaScript = "document.getElementById('\(customPasswordElementID.sanitized())').value"
Expand Down Expand Up @@ -161,11 +162,23 @@ extension WebViewController: WKNavigationDelegate {
TCSLogWithMark(navigationAction.request.url?.path ?? "<<URL EMPTY>>")
}
} else if navigationAction.request.httpMethod == "GET" && navigationAction.request.url?.path.contains("token/redirect") ?? false {
TCSLogWithMark("GET with Token/redirect")
// for Okta
let javaScript = "document.getElementById('input74').value"
webView.evaluateJavaScript(javaScript, completionHandler: { response, error in
})
}
else {
TCSLogWithMark(navigationAction.request.httpMethod ?? "Unknown method")
TCSLogWithMark("path = \(navigationAction.request.url?.path ?? "no path")");

let javaScript = "document.documentElement.outerHTML.toString()"
webView.evaluateJavaScript(javaScript, completionHandler: { response, error in
TCSLogWithMark(response as? String ?? "No HTML")
})


}

decisionHandler(.allow)
}
Expand Down
13 changes: 13 additions & 0 deletions XCredsLoginPlugIn/Bundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Bundle.swift
// NoMADLoginAD
//
// Created by Joel Rennich on 3/31/20.
// Copyright © 2020 Orchard & Grove. All rights reserved.
//

extension Bundle {
static var mainLogin: Bundle {
return Bundle(for: XCredsLoginPlugin.self)
}
}
36 changes: 33 additions & 3 deletions XCredsLoginPlugIn/LoginWindow/LoginWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,52 @@ import Foundation
import Cocoa
import WebKit
import OIDCLite

import Network
class LoginWebViewController: WebViewController {

let uiLog = "uiLog"
let monitor = NWPathMonitor()
var delegate: XCredsMechanismProtocol?
override func windowDidLoad() {
super.windowDidLoad()
NotificationCenter.default.addObserver(forName:NSApplication.didChangeScreenParametersNotification, object: nil, queue: nil) { notification in
TCSLogWithMark("Resolution changed. Resetting size")
self.setupLoginWindowAppearance()

}
TCSLogWithMark("loading webview for login")
setupLoginWindowAppearance()

TCSLogWithMark("loading page")
NotificationCenter.default.addObserver(forName:NSApplication.didChangeScreenParametersNotification, object: nil, queue: nil) { notification in
TCSLogWithMark("Resolution changed. Resetting size")
self.setupLoginWindowAppearance()

}

monitor.pathUpdateHandler = { path in
if path.status == .satisfied {

TCSLogWithMark("network changed")
DispatchQueue.main.async {

self.loadPage()
}

} else {
TCSLogWithMark("No connection.")
}

print(path.isExpensive)
}
let queue = DispatchQueue(label: "Monitor")
monitor.start(queue: queue)

loadPage()
}
fileprivate func setupLoginWindowAppearance() {
DispatchQueue.main.async {
TCSLogWithMark("setting up window")


self.window?.level = .popUpMenu
self.window?.orderFrontRegardless()

Expand Down
21 changes: 18 additions & 3 deletions XCredsLoginPlugIn/LoginWindow/LoginWindowControls.xib
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<capability name="Image references" minToolsVersion="12.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -25,7 +26,7 @@
<rect key="frame" x="0.0" y="20" width="872" height="78"/>
<subviews>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6f9-0z-Xqg">
<rect key="frame" x="402" y="1" width="67" height="64"/>
<rect key="frame" x="461" y="7" width="67" height="64"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="bevel" title="Shutdown" bezelStyle="rounded" image="ShutdownX" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="WRj-LR-MaW">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -37,7 +38,7 @@
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="HyD-ug-de2">
<rect key="frame" x="293" y="7" width="67" height="64"/>
<rect key="frame" x="352" y="7" width="67" height="64"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="bevel" title="Restart" bezelStyle="rounded" image="RestartX" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="UQm-h8-fbd">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -49,7 +50,7 @@
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2By-DW-YEU">
<rect key="frame" x="502" y="1" width="119" height="64"/>
<rect key="frame" x="560" y="7" width="119" height="64"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="bevel" title="Mac Login Window" bezelStyle="rounded" image="loginwindow" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="c0y-fU-B6x">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -60,6 +61,19 @@
<action selector="resetToStandardLoginWindow:" target="-2" id="BdF-GG-oFz"/>
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="DDT-al-AEa">
<rect key="frame" x="224" y="7" width="94" height="64"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="bevel" title="Configure WiFi" bezelStyle="rounded" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="tgY-Vk-PkQ">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<imageReference key="image" image="NSNetwork" symbolScale="small"/>
</buttonCell>
<color key="contentTintColor" red="0.99999600649999998" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<action selector="showNetworkConnection:" target="-2" id="ELP-jD-JSi"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="width" constant="872" id="aKl-rA-eDh"/>
Expand All @@ -76,6 +90,7 @@
</window>
</objects>
<resources>
<image name="NSNetwork" width="32" height="32"/>
<image name="RestartX" width="32" height="32"/>
<image name="ShutdownX" width="32" height="32"/>
<image name="loginwindow" width="41" height="31.5"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@ import Cocoa
class LoginWindowControlsWindowController: NSWindowController {
var delegate: XCredsMechanismProtocol?

let uiLog = "uiLog"

var wifiWindowController:WifiWindowController?
override func windowDidLoad() {
super.windowDidLoad()
setupLoginWindowControlsAppearance()
NotificationCenter.default.addObserver(forName:NSApplication.didChangeScreenParametersNotification, object: nil, queue: nil) { notification in
TCSLogWithMark("Resolution changed. Resetting size")
self.setupLoginWindowControlsAppearance()


}

}
fileprivate func setupLoginWindowControlsAppearance() {
DispatchQueue.main.async {
Expand All @@ -35,6 +45,53 @@ class LoginWindowControlsWindowController: NSWindowController {
}

}
@IBAction func showNetworkConnection(_ sender: Any) {
// username.isHidden = true
TCSLogWithMark()

wifiWindowController = WifiWindowController(windowNibName: NSNib.Name("WifiWindowController"))
TCSLogWithMark()

guard let windowController = wifiWindowController, let window = windowController.window else {
TCSLogWithMark("no window for wifi")
return
}
TCSLogWithMark("setting window level")

window.level = .screenSaver+2
TCSLogWithMark("wifiWindowController ordering controls front")
window.orderFrontRegardless()
TCSLogWithMark()
window.titlebarAppearsTransparent = true
window.isMovable = true
window.canBecomeVisibleWithoutLogin = true
window.makeKeyAndOrderFront(self)

window.titlebarAppearsTransparent = true


let screenRect = NSScreen.screens[0].frame
window.setFrame(screenRect, display: true, animate: false)


TCSLogWithMark()
// guard let wifiWindowController = WifiWindowViewController.createFr.createFromNib(in: .mainLogin) else {
// os_log("Error showing network selection.", log: uiLog, type: .debug)
// return
// }
//

// wifiView.frame = windowContentView.frame
// let completion = {
// os_log("Finished working with wireless networks", log: self.uiLog, type: .debug)
//// self.username.isHidden = false
//// self.username.becomeFirstResponder()
// }
// wifiView.set(completionHandler: completion)
// windowContentView.addSubview(wifiView)
}


@IBAction func restartClick(_ sender: Any) {
TCSLogWithMark("Setting restart user")
guard let delegate = delegate else {
Expand Down
15 changes: 10 additions & 5 deletions XCredsLoginPlugIn/LoginWindow/xcreds_login.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ f_install=0
f_remove=0
f_restore=0

remove_rights () {
"${authrights_path}" -r "XCredsLoginPlugin:LoginWindow" "loginwindow:login"
"${authrights_path}" -d "XCredsLoginPlugin:PowerControl,privileged"
"${authrights_path}" -d "XCredsLoginPlugin:KeychainAdd,privileged"
"${authrights_path}" -d "XCredsLoginPlugin:CreateUser,privileged"
"${authrights_path}" -d "XCredsLoginPlugin:EnableFDE,privileged"

}
while getopts ":ire" o; do
case "${o}" in
i)
Expand Down Expand Up @@ -67,6 +75,7 @@ if [ $f_install -eq 1 ]; then
cp "${launch_agent_source_path}" "${launch_agent_destination_path}"
fi
if [ -e ${authrights_path} ]; then
remove_rights
"${authrights_path}" -r "loginwindow:login" "XCredsLoginPlugin:LoginWindow"
"${authrights_path}" -a "XCredsLoginPlugin:LoginWindow" "XCredsLoginPlugin:PowerControl,privileged"
"${authrights_path}" -a "loginwindow:done" "XCredsLoginPlugin:KeychainAdd,privileged"
Expand All @@ -81,11 +90,7 @@ if [ $f_install -eq 1 ]; then

elif [ $f_remove -eq 1 ]; then

"${authrights_path}" -r "XCredsLoginPlugin:LoginWindow" "loginwindow:login"
"${authrights_path}" -d "XCredsLoginPlugin:PowerControl,privileged"
"${authrights_path}" -d "XCredsLoginPlugin:KeychainAdd,privileged"
"${authrights_path}" -d "XCredsLoginPlugin:CreateUser,privileged"
"${authrights_path}" -d "XCredsLoginPlugin:EnableFDE,privileged"
remove_rights

if [ -e "/Library/Security/SecurityAgentPlugins/XCredsLoginPlugin.bundle" ]; then
rm -rf "/Library/Security/SecurityAgentPlugins/XCredsLoginPlugin.bundle"
Expand Down

0 comments on commit de4acf0

Please sign in to comment.