2 Commits 62e46ef47e ... be2ff6a2cd

Auteur SHA1 Message Date
  Sven Velt be2ff6a2cd Fix for awk/os-release with different OS il y a 5 ans
  Sven Velt f8934c59f9 Converted to python3 il y a 5 ans
1 fichiers modifiés avec 7 ajouts et 7 suppressions
  1. 7 7
      ssh-wrapper.py

+ 7 - 7
ssh-wrapper.py

@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import os
 import re
@@ -10,7 +10,7 @@ allowed = [
 		##### System informations
 		r'^/usr/bin/lsb_release\s+-d$',		# Linux
 		r'^/(usr/)?bin/uname\s+-mrs$',		# Linux, BSD & others
-		r'''^/(usr/)?s?bin/awk -F'"' -e '/PRETTY_NAME/{ print \$2; }' /etc/os-release''',		# Linux: /etc/os-release via awk for get_os.py
+		r'''^/(usr/)?s?bin/awk -F'"' (-e\s*)?'/PRETTY_NAME/{ print \$2; }' /etc/os-release''',		# Linux: /etc/os-release via awk for get_os.py
 
 		##### Complete command lines (Monitoring-Plugins on Debian)
 		r'^/usr/lib/nagios/plugins/check_disk -w \d+% -c \d+% -p /[/a-z]*$',
@@ -33,7 +33,7 @@ allowed = [
 
 cmdline = os.getenv('SSH_ORIGINAL_COMMAND')
 if not cmdline:
-	print 'This is just a wrapper, no command specified!'
+	print('This is just a wrapper, no command specified!')
 	sys.exit(3)
 
 for maybe in allowed:
@@ -42,13 +42,13 @@ for maybe in allowed:
 
 		try:
 			cmd = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
-		except Exception, exc:
-			print 'Could not execute plugin ("%s"): %s' % (' '.join(cmdline), exc)
+		except Exception as exc:
+			print('Could not execute plugin ("%s"): %s' % (' '.join(cmdline), exc))
 			sys.exit(3)
 		else:
-			print cmd.communicate()[0].rstrip()
+			print(cmd.communicate()[0].rstrip().decode('utf-8'))
 			sys.exit(cmd.returncode)
 
-print '%s: No allowed command found!' % sys.argv[0]
+print('%s: No allowed command found!' % sys.argv[0])
 sys.exit(3)