@@ -46,6 +46,7 @@ import { ModalError } from "cockpit-components-inline-notification.jsx";
46
46
const _ = cockpit . gettext ;
47
47
48
48
export const codes = {
49
+ "danger" : "connect" ,
49
50
"no-cockpit" : "not-supported" ,
50
51
"not-supported" : "not-supported" ,
51
52
"protocol-error" : "not-supported" ,
@@ -108,6 +109,61 @@ export const CrossMachineWarning = () => {
108
109
title = { _ ( "Malicious pages on a remote machine may affect other connected hosts" ) } /> ;
109
110
} ;
110
111
112
+ class Connect extends React . Component {
113
+ constructor ( props ) {
114
+ super ( props ) ;
115
+
116
+ this . state = {
117
+ inProgress : false ,
118
+ } ;
119
+ }
120
+
121
+ onConnect ( ) {
122
+ console . log ( "CONNECT" , this . props . full_address ) ;
123
+
124
+ this . setState ( { inProgress : true } ) ;
125
+ this . props . run ( this . props . try2Connect ( this . props . full_address ) , ex => {
126
+ if ( ex . problem === "no-host" ) {
127
+ let host_id_port = address ;
128
+ let port = "22" ;
129
+ const port_index = host_id_port . lastIndexOf ( ":" ) ;
130
+ if ( port_index === - 1 )
131
+ host_id_port = address + ":22" ;
132
+ else
133
+ port = host_id_port . substr ( port_index + 1 ) ;
134
+
135
+ ex . message = cockpit . format ( _ ( "Unable to contact the given host $0. Make sure it has ssh running on port $1, or specify another port in the address." ) , host_id_port , port ) ;
136
+ ex . problem = "not-found" ;
137
+ }
138
+ this . setState ( { inProgress : false } ) ;
139
+ this . props . setError ( ex ) ;
140
+ } ) ;
141
+ }
142
+
143
+ render ( ) {
144
+ return (
145
+ < Modal id = "hosts_connect_server_dialog" isOpen
146
+ position = "top" variant = "medium"
147
+ onClose = { this . props . onClose }
148
+ title = { cockpit . format ( _ ( "Connect to $0" ) , this . props . full_address ) }
149
+ footer = { < >
150
+ < Button variant = "primary" isLoading = { this . state . inProgress }
151
+ onClick = { ( ) => this . onConnect ( ) } >
152
+ { _ ( "Connect" ) }
153
+ </ Button >
154
+ < Button variant = "link" className = "btn-cancel" onClick = { this . props . onClose } >
155
+ { _ ( "Cancel" ) }
156
+ </ Button >
157
+ </ > }
158
+ >
159
+ < Stack hasGutter >
160
+ < CrossMachineWarning />
161
+ </ Stack >
162
+ </ Modal >
163
+ ) ;
164
+ }
165
+ }
166
+
111
167
class AddMachine extends React . Component {
112
168
constructor ( props ) {
113
169
super ( props ) ;
@@ -229,22 +285,24 @@ class AddMachine extends React.Component {
229
285
} ) ;
230
286
} ) ;
231
287
232
- this . props . run ( this . props . try2Connect ( address ) , ex => {
233
- if ( ex . problem === "no-host" ) {
234
- let host_id_port = address ;
235
- let port = "22" ;
236
- const port_index = host_id_port . lastIndexOf ( ":" ) ;
237
- if ( port_index === - 1 )
238
- host_id_port = address + ":22" ;
239
- else
240
- port = host_id_port . substr ( port_index + 1 ) ;
241
-
242
- ex . message = cockpit . format ( _ ( "Unable to contact the given host $0. Make sure it has ssh running on port $1, or specify another port in the address." ) , host_id_port , port ) ;
243
- ex . problem = "not-found" ;
244
- }
245
- this . setState ( { inProgress : false } ) ;
246
- this . props . setError ( ex ) ;
247
- } ) ;
288
+ this . props . setError ( { problem : "danger" , command : "close" } ) ;
289
+
290
+ // this.props.run(this.props.try2Connect(address), ex => {
291
+ // if (ex.problem === "no-host") {
292
+ // let host_id_port = address;
293
+ // let port = "22";
294
+ // const port_index = host_id_port.lastIndexOf(":");
295
+ // if (port_index === -1)
296
+ // host_id_port = address + ":22";
297
+ // else
298
+ // port = host_id_port.substr(port_index + 1);
299
+
300
+ // ex.message = cockpit.format(_("Unable to contact the given host $0. Make sure it has ssh running on port $1, or specify another port in the address."), host_id_port, port);
301
+ // ex.problem = "not-found";
302
+ // }
303
+ // this.setState({ inProgress: false });
304
+ // this.props.setError(ex);
305
+ // });
248
306
}
249
307
250
308
render ( ) {
@@ -295,7 +353,6 @@ class AddMachine extends React.Component {
295
353
< Stack hasGutter >
296
354
{ this . props . dialogError && < ModalError dialogError = { this . props . dialogError } /> }
297
355
{ body }
298
- < CrossMachineWarning />
299
356
</ Stack >
300
357
</ Modal >
301
358
) ;
@@ -393,7 +450,6 @@ class MachinePort extends React.Component {
393
450
< Stack hasGutter >
394
451
{ this . props . dialogError && < ModalError dialogError = { this . props . dialogError } /> }
395
452
{ body }
396
- < CrossMachineWarning />
397
453
</ Stack >
398
454
</ Modal >
399
455
) ;
@@ -527,7 +583,6 @@ class HostKey extends React.Component {
527
583
< Stack hasGutter >
528
584
{ this . props . dialogError && < ModalError dialogError = { this . props . dialogError } /> }
529
585
{ body }
530
- < CrossMachineWarning />
531
586
</ Stack >
532
587
</ Modal >
533
588
) ;
@@ -905,13 +960,37 @@ class ChangeAuth extends React.Component {
905
960
< Stack hasGutter >
906
961
{ this . props . dialogError && < ModalError dialogError = { this . props . dialogError } /> }
907
962
{ body }
908
- < CrossMachineWarning />
909
963
</ Stack >
910
964
</ Modal >
911
965
) ;
912
966
}
913
967
}
914
968
969
+ export function try2Connect ( machines_ins , address , options ) {
970
+ return new Promise ( ( resolve , reject ) => {
971
+ const conn_options = { ...options , payload : "echo" , host : address } ;
972
+
973
+ conn_options [ "init-superuser" ] = get_init_superuser_for_options ( conn_options ) ;
974
+
975
+ const machine = machines_ins . lookup ( address ) ;
976
+ if ( machine && machine . host_key && ! machine . on_disk ) {
977
+ conn_options [ 'temp-session' ] = false ; // Compatibility option
978
+ conn_options . session = 'shared' ;
979
+ conn_options [ 'host-key' ] = machine . host_key ;
980
+ }
981
+
982
+ const client = cockpit . channel ( conn_options ) ;
983
+ client . send ( "x" ) ;
984
+ client . addEventListener ( "message" , ( ) => {
985
+ resolve ( ) ;
986
+ client . close ( ) ;
987
+ } ) ;
988
+ client . addEventListener ( "close" , ( event , options ) => {
989
+ reject ( options ) ;
990
+ } ) ;
991
+ } ) ;
992
+ }
993
+
915
994
export class HostModal extends React . Component {
916
995
constructor ( props ) {
917
996
super ( props ) ;
@@ -950,28 +1029,7 @@ export class HostModal extends React.Component {
950
1029
}
951
1030
952
1031
try2Connect ( address , options ) {
953
- return new Promise ( ( resolve , reject ) => {
954
- const conn_options = { ...options , payload : "echo" , host : address } ;
955
-
956
- conn_options [ "init-superuser" ] = get_init_superuser_for_options ( conn_options ) ;
957
-
958
- const machine = this . props . machines_ins . lookup ( address ) ;
959
- if ( machine && machine . host_key && ! machine . on_disk ) {
960
- conn_options [ 'temp-session' ] = false ; // Compatibility option
961
- conn_options . session = 'shared' ;
962
- conn_options [ 'host-key' ] = machine . host_key ;
963
- }
964
-
965
- const client = cockpit . channel ( conn_options ) ;
966
- client . send ( "x" ) ;
967
- client . addEventListener ( "message" , ( ) => {
968
- resolve ( ) ;
969
- client . close ( ) ;
970
- } ) ;
971
- client . addEventListener ( "close" , ( event , options ) => {
972
- reject ( options ) ;
973
- } ) ;
974
- } ) ;
1032
+ return try2Connect ( this . props . machines_ins , address , options ) ;
975
1033
}
976
1034
977
1035
complete ( ) {
@@ -1060,7 +1118,9 @@ export class HostModal extends React.Component {
1060
1118
complete : this . complete ,
1061
1119
} ;
1062
1120
1063
- if ( template === "add-machine" )
1121
+ if ( template === "connect" )
1122
+ return < Connect { ...props } /> ;
1123
+ else if ( template === "add-machine" )
1064
1124
return < AddMachine { ...props } /> ;
1065
1125
else if ( template === "unknown-hostkey" || template === "unknown-host" || template === "invalid-hostkey" )
1066
1126
return < HostKey { ...props } /> ;
0 commit comments