update-cfg.pl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #! /usr/bin/perl -w
  2. use strict;
  3. my ($fname_in, $fname_out);
  4. if ($#ARGV != 0) {
  5. &usage;
  6. }
  7. $fname_in = $ARGV[0];
  8. $fname_out = $fname_in . ".new";
  9. if (&check_ssl) {
  10. print "\n'$fname_in' already has some or all of the\n";
  11. print "new SSL parameters. No processing will be done.\n\n";
  12. exit 0;
  13. }
  14. open IN, $fname_in or die "Could not open '$fname_in' for reading: $!\n";
  15. open OUT, ">$fname_out" or die "Could not open '$fname_out' for writing: $!\n";
  16. while (<IN>) {
  17. print OUT;
  18. &add_ssl if $_ =~ /allow_weak_random_seed/;
  19. }
  20. print "\nConfig file '$fname_in' was read.\n";
  21. print "The new SSL comments and parameters were added and the output written to\n";
  22. print "'$fname_out'\n";
  23. print "Please check this file for accuracy and rename it when you are satisfied.\n\n";
  24. close IN;
  25. close OUT;
  26. # ==========================================================================
  27. sub usage
  28. {
  29. print "\nUsage: update-cfg.pl <path-to-nrpe.cfg-file>\n\n";
  30. print "This perl script will read the nrpe configuration file\n";
  31. print "specified on the command line, and write out a new file\n";
  32. print "with the new SSL comments and parameters added.\n\n";
  33. exit 1;
  34. }
  35. # --------------------------------------------------------------------------
  36. # check_ssl checks if the config file already has the ssl parameters
  37. # --------------------------------------------------------------------------
  38. sub check_ssl
  39. {
  40. my $has_ssl = 0;
  41. open IN, $fname_in or die "Could not open '$fname_in' for reading: $!\n";
  42. while (<IN>) {
  43. if ($_ =~ /ssl_version=/ or
  44. $_ =~ /ssl_use_adh=/ or
  45. $_ =~ /ssl_cipher_list=/ or
  46. $_ =~ /ssl_cacert_file=/ or
  47. $_ =~ /ssl_cert_file=/ or
  48. $_ =~ /ssl_privatekey_file=/ or
  49. $_ =~ /ssl_client_certs=/ or
  50. $_ =~ /ssl_logging=/)
  51. {
  52. $has_ssl = 1;
  53. last;
  54. }
  55. }
  56. close IN;
  57. return $has_ssl;
  58. }
  59. # --------------------------------------------------------------------------
  60. # add_ssl inserts the new SSL comments and parameters into the config file
  61. # --------------------------------------------------------------------------
  62. sub add_ssl
  63. {
  64. my $txt = <<"END_SSL";
  65. # SSL/TLS OPTIONS
  66. # These directives allow you to specify how to use SSL/TLS.
  67. # SSL VERSION
  68. # This can be any of: SSLv2 (only use SSLv2), SSLv2+ (use any version),
  69. # SSLv3 (only use SSLv3), SSLv3+ (use SSLv3 or above), TLSv1 (only use
  70. # TLSv1), TLSv1+ (use TLSv1 or above), TLSv1.1 (only use TLSv1.1),
  71. # TLSv1.1+ (use TLSv1.1 or above), TLSv1.2 (only use TLSv1.2),
  72. # TLSv1.2+ (use TLSv1.2 or above)
  73. # If an "or above" version is used, the best will be negotiated. So if both
  74. # ends are able to do TLSv1.2 and use specify SSLv2, you will get TLSv1.2.
  75. #ssl_version=SSLv2+
  76. # SSL USE ADH
  77. # This is for backward compatibility and is DEPRECATED. Set to 1 to enable
  78. # ADH or 2 to require ADH. 1 is currently the default but will be changed
  79. # in a later version.
  80. #ssl_use_adh=1
  81. # SSL CIPHER LIST
  82. # This lists which ciphers can be used. For backward compatibility, this
  83. # defaults to 'ssl_cipher_list=ALL:!MD5:\@STRENGTH' in this version but
  84. # will be changed to something like the example below in a later version of NRPE.
  85. #ssl_cipher_list=ALL:!MD5:\@STRENGTH
  86. #ssl_cipher_list=ALL:!aNULL:!eNULL:!SSLv2:!LOW:!EXP:!RC4:!MD5:\@STRENGTH
  87. # SSL Certificate and Private Key Files
  88. #ssl_cacert_file=/etc/ssl/servercerts/ca-cert.pem
  89. #ssl_cert_file=/etc/ssl/servercerts/nagios-cert.pem
  90. #ssl_privatekey_file=/etc/ssl/servercerts/nagios-key.pem
  91. # SSL USE CLIENT CERTS
  92. # This options determines client certificate usage.
  93. # Values: 0 = Don't ask for or require client certificates (default)
  94. # 1 = Ask for client certificates
  95. # 2 = Require client certificates
  96. #ssl_client_certs=0
  97. # SSL LOGGING
  98. # This option determines which SSL messages are send to syslog. OR values
  99. # together to specify multiple options.
  100. # Values: 0x00 (0) = No additional logging (default)
  101. # 0x01 (1) = Log startup SSL/TLS parameters
  102. # 0x02 (2) = Log remote IP address
  103. # 0x04 (4) = Log SSL/TLS version of connections
  104. # 0x08 (8) = Log which cipher is being used for the connection
  105. # 0x10 (26) = Log if client has a certificate
  106. # 0x20 (32) = Log details of client's certificate if it has one
  107. # -1 or 0xff or 0x2f = All of the above
  108. #ssl_logging=0x00
  109. END_SSL
  110. print OUT $txt;
  111. }