This repository was archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathViewControllerSsh.swift
171 lines (149 loc) · 5.05 KB
/
ViewControllerSsh.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//
// ViewControllerSsh.swift
// RsyncOSX
//
// Created by Thomas Evensen on 23.04.2017.
// Copyright © 2017 Thomas Evensen. All rights reserved.
//
// swiftlint:disable line_length
import Cocoa
import Foundation
protocol Loadsshparameters: AnyObject {
func loadsshparameters()
}
protocol GetSource: AnyObject {
func getSourceindex(index: Int)
}
class ViewControllerSsh: NSViewController, SetConfigurations, VcMain, Checkforrsync, Help {
var sshcmd: Ssh?
var hiddenID: Int?
var data: [String]?
var outputprocess: OutputfromProcess?
// Send messages to the sidebar
weak var sidebaractionsDelegate: Sidebaractions?
@IBOutlet var rsaCheck: NSButton!
@IBOutlet var detailsTable: NSTableView!
@IBOutlet var copykeycommand: NSTextField!
@IBOutlet var sshport: NSTextField!
@IBOutlet var sshkeypathandidentityfile: NSTextField!
@IBOutlet var verifykeycommand: NSTextField!
// Selecting profiles
@IBAction func profiles(_: NSButton) {
presentAsModalWindow(viewControllerProfile!)
}
@IBAction func showHelp(_: AnyObject?) {
help()
}
// Sidebar create keys
func createPublicPrivateRSAKeyPair() {
outputprocess = OutputfromProcess()
sshcmd = Ssh(processtermination: processtermination)
guard sshcmd?.islocalpublicrsakeypresent() ?? true == false else { return }
sshcmd?.creatersakeypair()
}
// Sidebar kilde
var viewControllerSource: NSViewController? {
return sheetviewstoryboard?.instantiateController(withIdentifier: "CopyFilesID")
as? NSViewController
}
func source() {
guard sshcmd != nil else { return }
presentAsModalWindow(viewControllerSource!)
}
override func viewDidLoad() {
super.viewDidLoad()
SharedReference.shared.setvcref(viewcontroller: .vcssh, nsviewcontroller: self)
detailsTable.delegate = self
detailsTable.dataSource = self
outputprocess = nil
}
override func viewDidAppear() {
super.viewDidAppear()
sidebaractionsDelegate = SharedReference.shared.getvcref(viewcontroller: .vcsidebar) as? ViewControllerSideBar
sidebaractionsDelegate?.sidebaractions(action: .sshviewbuttons)
loadsshparameters()
}
override func viewDidDisappear() {
super.viewDidDisappear()
copykeycommand.stringValue = ""
verifykeycommand.stringValue = ""
}
func checkforPrivateandPublicRSAKeypair() {
sshcmd = Ssh(processtermination: processtermination)
if sshcmd?.islocalpublicrsakeypresent() ?? false {
rsaCheck.state = .on
} else {
rsaCheck.state = .off
}
}
func copylocalpubrsakeyfile() {
guard sshcmd?.islocalpublicrsakeypresent() ?? false == true else { return }
outputprocess = OutputfromProcess()
sshcmd = Ssh(processtermination: processtermination)
if let hiddenID = hiddenID {
sshcmd?.copykeyfile(hiddenID: hiddenID)
copykeycommand.stringValue = sshcmd?.commandCopyPasteTerminal ?? ""
sshcmd?.verifyremotekey(hiddenID: hiddenID)
verifykeycommand.stringValue = sshcmd?.commandCopyPasteTerminal ?? ""
}
}
}
extension ViewControllerSsh: GetSource {
func getSourceindex(index: Int) {
hiddenID = index
copylocalpubrsakeyfile()
loadsshparameters()
}
}
extension ViewControllerSsh: NSTableViewDataSource {
func numberOfRows(in _: NSTableView) -> Int {
return data?.count ?? 0
}
}
extension ViewControllerSsh: NSTableViewDelegate {
func tableView(_ tableView: NSTableView, viewFor _: NSTableColumn?, row: Int) -> NSView? {
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "outputID"), owner: nil) as? NSTableCellView {
cell.textField?.stringValue = data?[row] ?? ""
return cell
} else {
return nil
}
}
}
extension ViewControllerSsh {
func processtermination(data: [String]?) {
globalMainQueue.async { () in
self.checkforPrivateandPublicRSAKeypair()
self.data = data
self.detailsTable.reloadData()
}
}
}
extension ViewControllerSsh: DismissViewController {
func dismiss_view(viewcontroller: NSViewController) {
dismiss(viewcontroller)
}
}
extension ViewControllerSsh: Loadsshparameters {
func loadsshparameters() {
sshkeypathandidentityfile.stringValue = SharedReference.shared.sshkeypathandidentityfile ?? ""
if let sshport = SharedReference.shared.sshport {
self.sshport.stringValue = String(sshport)
} else {
sshport.stringValue = ""
}
checkforPrivateandPublicRSAKeypair()
}
}
extension ViewControllerSsh: Sidebarbuttonactions {
func sidebarbuttonactions(action: Sidebaractionsmessages) {
switch action {
case .CreateKey:
createPublicPrivateRSAKeyPair()
case .Remote:
source()
default:
return
}
}
}