@@ -23,10 +23,12 @@ import curses
23
23
import curses .ascii
24
24
import curses .textpad
25
25
import sys
26
+ import signal
26
27
import os
27
28
import logging
28
29
import subprocess
29
30
from typing import List , Any , Tuple , Generator
31
+ from netifaces import interfaces , ifaddresses , AF_INET
30
32
31
33
STATUS_HEADER : str = "STATUS\t \t \t SERVICE\t \t \t "
32
34
LAYOUT_STR : str = "Keyboard layout (press 9 to change):"
@@ -201,6 +203,11 @@ def getstatus() -> str:
201
203
status = ""
202
204
for i in getstatus_pair (list (run_svcs ("Description" ))):
203
205
#
206
+ # Don't print any inactive services
207
+ #
208
+ if i [- 1 ].strip () == "inactive" :
209
+ continue
210
+ #
204
211
# Switch the state and description
205
212
#
206
213
status += f"{ i [- 1 ]} \t { i [0 ]} \n "
@@ -209,22 +216,17 @@ def getstatus() -> str:
209
216
210
217
def get_network_status () -> Tuple [str , str ]:
211
218
"""
212
- Returns a tuple of (hostname, ipaddr) for the main interface .
219
+ Returns a tuple of (hostname, ipaddrs) .
213
220
"""
214
221
215
- #
216
- # We get the primary address based on the default route. The
217
- # address we use follows the 'src' key in the output.
218
- #
219
- cmd = ['ip' , 'route' , 'show' , '0.0.0.0/0' ]
220
- cp = subprocess .run (cmd ,
221
- stdout = subprocess .PIPE ,
222
- universal_newlines = True ,
223
- check = True )
224
- output = cp .stdout .split ()
225
- ipaddr = output [output .index ("src" ) + 1 ]
222
+ ipaddrs = []
223
+ for interface in interfaces ():
224
+ if interface == "lo" :
225
+ continue
226
+ for link in ifaddresses (interface )[AF_INET ]:
227
+ ipaddrs .append (link ['addr' ])
226
228
hostname = os .uname ()[1 ]
227
- return (hostname , ipaddr )
229
+ return (hostname , ", " . join ( ipaddrs ) )
228
230
229
231
230
232
# pylint: disable-msg=too-many-locals
@@ -239,11 +241,11 @@ def display_status(stdscr, win):
239
241
layout = get_keyboard_layout ()
240
242
241
243
width = X - 10
242
- height = Y - 8
244
+ height = Y - 6
243
245
status = 0
244
246
245
247
x = int ((X - width ) / 2 ) + 2
246
- y = (Y - height - 1 )
248
+ y = (Y - height )
247
249
248
250
win .clear ()
249
251
win .box ()
@@ -270,10 +272,12 @@ def display_status(stdscr, win):
270
272
sys .stdout .flush ()
271
273
sys .stderr .flush ()
272
274
273
- (hostname , ipaddr ) = get_network_status ()
275
+ (hostname , ipaddrs ) = get_network_status ()
274
276
netwin .clear ()
275
- netwin .addstr (0 , 0 , "Host: http://" + hostname + "/" , curses .A_BOLD )
276
- netwin .addstr (1 , 0 , "IP: " + ipaddr , curses .A_BOLD )
277
+ if hostname :
278
+ hostname = "https://" + hostname
279
+ netwin .addstr (0 , 0 , "Host: " + hostname , curses .A_BOLD )
280
+ netwin .addstr (1 , 0 , "IPs: " + ipaddrs , curses .A_BOLD )
277
281
netwin .noutrefresh ()
278
282
279
283
# We get status every 10 secs
@@ -373,7 +377,7 @@ def display_keyboard_layout_selection(stdscr, win):
373
377
#
374
378
# Main function.
375
379
#
376
- def installer_main (stdscr ):
380
+ def console_main (stdscr ):
377
381
"""
378
382
Main
379
383
"""
@@ -389,6 +393,27 @@ def installer_main(stdscr):
389
393
390
394
391
395
if __name__ == '__main__' :
392
- logging .basicConfig (filename = log_file , level = logging .DEBUG )
396
+ #
397
+ # We need to ensure that any errors in the rest of the script won't
398
+ # prevent us from logging into the system.
399
+ #
400
+ try :
401
+ logging .basicConfig (filename = log_file , level = logging .DEBUG )
393
402
394
- curses .wrapper (installer_main )
403
+ #
404
+ # Since we are going to invoke the login process directly
405
+ # from the startup screen, we want to ensure that we ignore
406
+ # any signals which would cause the status screen to restart.
407
+ # This way the login prompt behaves the same as if it were
408
+ # invoked from the getty service.
409
+ #
410
+ signal .signal (signal .SIGTTOU , signal .SIG_IGN )
411
+ signal .signal (signal .SIGTSTP , signal .SIG_IGN )
412
+ signal .signal (signal .SIGHUP , signal .SIG_IGN )
413
+ signal .signal (signal .SIGINT , signal .SIG_IGN )
414
+ signal .signal (signal .SIGQUIT , signal .SIG_IGN )
415
+
416
+ curses .wrapper (console_main )
417
+ finally :
418
+ login_cmd : List [str ] = ['/bin/login' , '-p' ]
419
+ subprocess .run (login_cmd , shell = False , check = True )
0 commit comments