Skip to content

Commit

Permalink
restart and shutdown buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Jul 3, 2022
1 parent 3fd2f6d commit fde13de
Show file tree
Hide file tree
Showing 27 changed files with 1,085 additions and 115 deletions.
10 changes: 10 additions & 0 deletions FakeTrue/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// main.swift
// FakeTrue
//
// Created by Timothy Perfitt on 7/3/22.
//

import Foundation

exit (0)
1 change: 1 addition & 0 deletions XCreds/XCredsLoginPlugin-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

#import "XCredsLoginPlugin.h"
#import "TCSUnifiedLogger.h"
#import "TCSReturnWindow.h"
47 changes: 47 additions & 0 deletions XCredsLoginPlugIn/ContextAndHintHandling.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// ContextAndHintHandling.swift
// NoMADLoginAD
//
// Created by Josh Wisenbaker on 12/18/17.
// Copyright © 2017 NoMAD. All rights reserved.
//

enum HintType: String {
case guestUser
case migratePass
case migrateUser
case networkSignIn
case user
case domain
case pass
case first
case last
case full
case groups
case uid
case gid
case kerberos_principal
case passwordOverwrite // stomp on the password
case ntName
}

// attribute statics

let kODAttributeADUser = "dsAttrTypeStandard:ADUser"
let kODAttributeNetworkSignIn = "dsAttrTypeStandard:NetworkSignIn"

protocol ContextAndHintHandling {
var mech: MechanismRecord? {get}
func setContextString(type: String, value: String)
func setHint(type: HintType, hint: Any)
func getContextString(type: String) -> String?
func getHint(type: HintType) -> Any?
}

//extension ContextAndHintHandling {
// /// Set a NoMAD Login Authorization mechanism hint.
// ///
// /// - Parameters:
// /// - type: A value from `HintType` representing the NoMad Login value to set.
// /// - hint: The hint value to set. Can be `String` or `[String]`
// }
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Sign In" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" titleVisibility="hidden" id="KxT-zM-Vnn" customClass="LoginWindow" customModule="XCredsLoginPlugin" customModuleProvider="target">
<window title="Sign In" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" titleVisibility="hidden" id="KxT-zM-Vnn" customClass="LoginWindow" customModule="XCredsLoginPlugin" customModuleProvider="target">
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="453" y="250" width="628" height="613"/>
<rect key="screenRect" x="0.0" y="0.0" width="1536" height="935"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import WebKit
import OIDCLite

class LoginWebViewController: WebViewController {

var delegate: XCredsMechanismProtocol?
override func windowDidLoad() {
super.windowDidLoad()
setupLoginWindowAppearance()
loadPage()
}
fileprivate func setupLoginWindowAppearance() {
self.window?.level = .screenSaver
self.window?.level = .popUpMenu
self.window?.orderFrontRegardless()
TCSLog("ordering loignwindow front")

self.window?.backgroundColor = NSColor.black

Expand All @@ -45,7 +48,23 @@ class LoginWebViewController: WebViewController {
self.window?.close()
})
}

override func tokensUpdated(tokens: Tokens) {

TCSLog("updating username and password")
guard let delegate = delegate else {
return
}

delegate.setContextString(type: kAuthorizationEnvironmentUsername, value: "tperfitt")
delegate.setContextString(type: kAuthorizationEnvironmentPassword, value: tokens.password)
delegate.allowLogin()
RunLoop.main.perform {
self.loginTransition()

}

}
}


File renamed without changes.
88 changes: 88 additions & 0 deletions XCredsLoginPlugIn/LoginWindow/LoginWindowControls.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<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="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="LoginWindowControlsWindowController" customModule="XCredsLoginPlugin" customModuleProvider="target">
<connections>
<outlet property="window" destination="wkO-FS-5uW" id="ui3-ZB-mfw"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hasShadow="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="wkO-FS-5uW" customClass="TCSReturnWindow">
<windowStyleMask key="styleMask" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="25" y="25" width="872" height="109"/>
<rect key="screenRect" x="0.0" y="0.0" width="1536" height="935"/>
<view key="contentView" id="Tpj-ss-EMv">
<rect key="frame" x="0.0" y="0.0" width="872" height="109"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<customView translatesAutoresizingMaskIntoConstraints="NO" id="sxl-0U-ne5">
<rect key="frame" x="186" y="16" width="500" height="78"/>
<subviews>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6f9-0z-Xqg">
<rect key="frame" x="153" y="1" 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"/>
<font key="font" metaFont="system"/>
</buttonCell>
<color key="contentTintColor" red="0.99999600649999998" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<action selector="shutdownClick:" target="-2" id="W7Z-F0-i5A"/>
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="HyD-ug-de2">
<rect key="frame" x="24" y="1" 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"/>
<font key="font" metaFont="system"/>
</buttonCell>
<color key="contentTintColor" red="0.99999600649999998" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<action selector="restartClick:" target="-2" id="NIy-Js-LHD"/>
</connections>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="LW1-vo-EUl">
<rect key="frame" x="277" y="1" width="67" height="64"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="bevel" title="WiFi" bezelStyle="rounded" image="RestartX" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="pVM-6f-Z04">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<color key="contentTintColor" red="0.99999600649999998" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2By-DW-YEU">
<rect key="frame" x="401" y="1" width="90" height="64"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="bevel" title="Login Window" bezelStyle="rounded" image="RestartX" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="c0y-fU-B6x">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<color key="contentTintColor" red="0.99999600649999998" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</button>
</subviews>
<constraints>
<constraint firstAttribute="width" constant="500" id="aKl-rA-eDh"/>
<constraint firstAttribute="height" constant="78" id="cmM-6M-FrE"/>
</constraints>
</customView>
</subviews>
<constraints>
<constraint firstItem="sxl-0U-ne5" firstAttribute="centerY" secondItem="Tpj-ss-EMv" secondAttribute="centerY" constant="-0.5" id="2Wq-KM-ceX"/>
<constraint firstItem="sxl-0U-ne5" firstAttribute="centerX" secondItem="Tpj-ss-EMv" secondAttribute="centerX" id="eIH-vl-2ht"/>
</constraints>
</view>
<point key="canvasLocation" x="-602" y="703.5"/>
</window>
</objects>
<resources>
<image name="RestartX" width="32" height="32"/>
<image name="ShutdownX" width="32" height="32"/>
</resources>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// LoginWindowControlsWindowController.swift
// XCredsLoginPlugin
//
// Created by Timothy Perfitt on 7/3/22.
//

import Cocoa

class LoginWindowControlsWindowController: NSWindowController {
var delegate: XCredsMechanismProtocol?

override func windowDidLoad() {
super.windowDidLoad()
setupLoginWindowAppearance()
}
fileprivate func setupLoginWindowAppearance() {
self.window?.level = .screenSaver
TCSLog("ordering controls front")
self.window?.orderFrontRegardless()

self.window?.titlebarAppearsTransparent = true

self.window?.isMovable = false
self.window?.canBecomeVisibleWithoutLogin = true

let screenRect = NSScreen.screens[0].frame
let windowRec = NSMakeRect(0, 0, screenRect.width, self.window?.frame.height ?? 100)
self.window?.setFrame(windowRec, display: true, animate: false)

}
@IBAction func restartClick(_ sender: Any) {
TCSLog("Setting restart user")
guard let delegate = delegate else {
TCSLog("No delegate set for restart")

return
}
delegate.setHint(type: .user, hint: SpecialUsers.restart.rawValue)
delegate.allowLogin()
}

@IBAction func shutdownClick(_ sender: Any) {
TCSLog("Setting shutdown user")
guard let delegate = delegate else {
TCSLog("No delegate set for shutdown")
return
}
delegate.setHint(type: .user, hint: SpecialUsers.shutdown.rawValue)
delegate.allowLogin()
}

}


13 changes: 13 additions & 0 deletions XCredsLoginPlugIn/LoginWindow/TCSReturnWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// TCSReturnWindow.h
// Boot Runner
//
// Created by Tim Perfitt on 9/6/17.
//
//

#import <Cocoa/Cocoa.h>

@interface TCSReturnWindow : NSWindow

@end
29 changes: 29 additions & 0 deletions XCredsLoginPlugIn/LoginWindow/TCSReturnWindow.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// TCSReturnWindow.m
// Boot Runner
//
// Created by Tim Perfitt on 9/6/17.
//
//

#import "TCSReturnWindow.h"

@implementation TCSReturnWindow
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(__unused NSWindowStyleMask)aStyle
backing:(__unused NSBackingStoreType)bufferingType
defer:(__unused BOOL)flag {

// Using NSBorderlessWindowMask results in a window without a title bar.
self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
if (self != nil) {
// Start with no transparency for all drawing into the window
[self setAlphaValue:0.5];
//Set backgroundColor to clearColor
self.backgroundColor = NSColor.grayColor;
// Turn off opacity so that the parts of the window that are not drawn into are transparent.
// [self setOpaque:NO];
}
return self;
}
@end
Binary file added XCredsLoginPlugIn/LoginWindow/images/RestartX.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fde13de

Please sign in to comment.