@@ -342,6 +342,18 @@ def onConnected(interface):
342342 if args .set_owner or args .set_owner_short or args .set_is_unmessageable or args .set_is_unmessagable :
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 :
@@ -417,6 +429,8 @@ def onConnected(interface):
417429 print (" " .join (fieldNames ))
418430
419431 if args .set_ham :
432+ if not args .set_ham .strip ():
433+ meshtastic .util .our_exit ("ERROR: Ham radio callsign cannot be empty or contain only whitespace characters" )
420434 closeNow = True
421435 print (f"Setting Ham ID to { args .set_ham } and turning off encryption" )
422436 interface .getNode (args .dest , ** getNode_kwargs ).setOwner (args .set_ham , is_licensed = True )
@@ -659,12 +673,20 @@ def onConnected(interface):
659673 interface .getNode (args .dest , False , ** getNode_kwargs ).beginSettingsTransaction ()
660674
661675 if "owner" in configuration :
676+ # Validate owner name before setting
677+ owner_name = str (configuration ["owner" ]).strip ()
678+ if not owner_name :
679+ meshtastic .util .our_exit ("ERROR: Long Name cannot be empty or contain only whitespace characters" )
662680 print (f"Setting device owner to { configuration ['owner' ]} " )
663681 waitForAckNak = True
664682 interface .getNode (args .dest , False , ** getNode_kwargs ).setOwner (configuration ["owner" ])
665683 time .sleep (0.5 )
666684
667685 if "owner_short" in configuration :
686+ # Validate owner short name before setting
687+ owner_short_name = str (configuration ["owner_short" ]).strip ()
688+ if not owner_short_name :
689+ meshtastic .util .our_exit ("ERROR: Short Name cannot be empty or contain only whitespace characters" )
668690 print (
669691 f"Setting device owner short to { configuration ['owner_short' ]} "
670692 )
@@ -675,6 +697,10 @@ def onConnected(interface):
675697 time .sleep (0.5 )
676698
677699 if "ownerShort" in configuration :
700+ # Validate owner short name before setting
701+ owner_short_name = str (configuration ["ownerShort" ]).strip ()
702+ if not owner_short_name :
703+ meshtastic .util .our_exit ("ERROR: Short Name cannot be empty or contain only whitespace characters" )
678704 print (
679705 f"Setting device owner short to { configuration ['ownerShort' ]} "
680706 )
@@ -1111,6 +1137,7 @@ def export_config(interface) -> str:
11111137 configObj ["location" ]["alt" ] = alt
11121138
11131139 config = MessageToDict (interface .localNode .localConfig ) #checkme - Used as a dictionary here and a string below
1140+ #was used as a string here and a Dictionary above
11141141 if config :
11151142 # Convert inner keys to correct snake/camelCase
11161143 prefs = {}
@@ -1205,6 +1232,22 @@ def common():
12051232 meshtastic .util .support_info ()
12061233 meshtastic .util .our_exit ("" , 0 )
12071234
1235+ # Early validation for owner names before attempting device connection
1236+ if hasattr (args , 'set_owner' ) and args .set_owner is not None :
1237+ stripped_long_name = args .set_owner .strip ()
1238+ if not stripped_long_name :
1239+ meshtastic .util .our_exit ("ERROR: Long Name cannot be empty or contain only whitespace characters" )
1240+
1241+ if hasattr (args , 'set_owner_short' ) and args .set_owner_short is not None :
1242+ stripped_short_name = args .set_owner_short .strip ()
1243+ if not stripped_short_name :
1244+ meshtastic .util .our_exit ("ERROR: Short Name cannot be empty or contain only whitespace characters" )
1245+
1246+ if hasattr (args , 'set_ham' ) and args .set_ham is not None :
1247+ stripped_ham_name = args .set_ham .strip ()
1248+ if not stripped_ham_name :
1249+ meshtastic .util .our_exit ("ERROR: Ham radio callsign cannot be empty or contain only whitespace characters" )
1250+
12081251 if have_powermon :
12091252 create_power_meter ()
12101253
0 commit comments