@@ -342,6 +342,18 @@ def onConnected(interface):
342342 if args .set_owner or args .set_owner_short :
343343 closeNow = True
344344 waitForAckNak = True
345+
346+ # Validate owner names before connecting to device
347+ if args .set_owner is not None :
348+ stripped_long_name = args .set_owner .strip ()
349+ if not stripped_long_name :
350+ meshtastic .util .our_exit ("ERROR: Long Name cannot be empty or contain only whitespace characters" )
351+
352+ if hasattr (args , 'set_owner_short' ) and args .set_owner_short is not None :
353+ stripped_short_name = args .set_owner_short .strip ()
354+ if not stripped_short_name :
355+ meshtastic .util .our_exit ("ERROR: Short Name cannot be empty or contain only whitespace characters" )
356+
345357 if args .set_owner and args .set_owner_short :
346358 print (f"Setting device owner to { args .set_owner } and short name to { args .set_owner_short } " )
347359 elif args .set_owner :
@@ -402,6 +414,8 @@ def onConnected(interface):
402414 print (" " .join (fieldNames ))
403415
404416 if args .set_ham :
417+ if not args .set_ham .strip ():
418+ meshtastic .util .our_exit ("ERROR: Ham radio callsign cannot be empty or contain only whitespace characters" )
405419 closeNow = True
406420 print (f"Setting Ham ID to { args .set_ham } and turning off encryption" )
407421 interface .getNode (args .dest , ** getNode_kwargs ).setOwner (args .set_ham , is_licensed = True )
@@ -644,12 +658,20 @@ def onConnected(interface):
644658 interface .getNode (args .dest , False , ** getNode_kwargs ).beginSettingsTransaction ()
645659
646660 if "owner" in configuration :
661+ # Validate owner name before setting
662+ owner_name = str (configuration ["owner" ]).strip ()
663+ if not owner_name :
664+ meshtastic .util .our_exit ("ERROR: Long Name cannot be empty or contain only whitespace characters" )
647665 print (f"Setting device owner to { configuration ['owner' ]} " )
648666 waitForAckNak = True
649667 interface .getNode (args .dest , False , ** getNode_kwargs ).setOwner (configuration ["owner" ])
650668 time .sleep (0.5 )
651669
652670 if "owner_short" in configuration :
671+ # Validate owner short name before setting
672+ owner_short_name = str (configuration ["owner_short" ]).strip ()
673+ if not owner_short_name :
674+ meshtastic .util .our_exit ("ERROR: Short Name cannot be empty or contain only whitespace characters" )
653675 print (
654676 f"Setting device owner short to { configuration ['owner_short' ]} "
655677 )
@@ -660,6 +682,10 @@ def onConnected(interface):
660682 time .sleep (0.5 )
661683
662684 if "ownerShort" in configuration :
685+ # Validate owner short name before setting
686+ owner_short_name = str (configuration ["ownerShort" ]).strip ()
687+ if not owner_short_name :
688+ meshtastic .util .our_exit ("ERROR: Short Name cannot be empty or contain only whitespace characters" )
663689 print (
664690 f"Setting device owner short to { configuration ['ownerShort' ]} "
665691 )
@@ -1096,6 +1122,7 @@ def export_config(interface) -> str:
10961122 configObj ["location" ]["alt" ] = alt
10971123
10981124 config = MessageToDict (interface .localNode .localConfig ) #checkme - Used as a dictionary here and a string below
1125+ #was used as a string here and a Dictionary above
10991126 if config :
11001127 # Convert inner keys to correct snake/camelCase
11011128 prefs = {}
@@ -1190,6 +1217,22 @@ def common():
11901217 meshtastic .util .support_info ()
11911218 meshtastic .util .our_exit ("" , 0 )
11921219
1220+ # Early validation for owner names before attempting device connection
1221+ if hasattr (args , 'set_owner' ) and args .set_owner is not None :
1222+ stripped_long_name = args .set_owner .strip ()
1223+ if not stripped_long_name :
1224+ meshtastic .util .our_exit ("ERROR: Long Name cannot be empty or contain only whitespace characters" )
1225+
1226+ if hasattr (args , 'set_owner_short' ) and args .set_owner_short is not None :
1227+ stripped_short_name = args .set_owner_short .strip ()
1228+ if not stripped_short_name :
1229+ meshtastic .util .our_exit ("ERROR: Short Name cannot be empty or contain only whitespace characters" )
1230+
1231+ if hasattr (args , 'set_ham' ) and args .set_ham is not None :
1232+ stripped_ham_name = args .set_ham .strip ()
1233+ if not stripped_ham_name :
1234+ meshtastic .util .our_exit ("ERROR: Ham radio callsign cannot be empty or contain only whitespace characters" )
1235+
11931236 if have_powermon :
11941237 create_power_meter ()
11951238
0 commit comments