comparison mod_checkcerts/mod_checkcerts.lua @ 2945:ec7f9c8f2a5f

mod_checkcerts: Fixed luacheck warnings
author Michel Le Bihan <michel@lebihan.pl>
date Fri, 23 Mar 2018 21:55:32 +0100
parents a7c1f1b6ef05
children c8ccaac78f64
comparison
equal deleted inserted replaced
2944:37ec4c2f319a 2945:ec7f9c8f2a5f
1 local config = require "core.configmanager";
1 local ssl = require"ssl"; 2 local ssl = require"ssl";
2 local datetime_parse = require"util.datetime".parse; 3 local datetime_parse = require"util.datetime".parse;
3 local load_cert = ssl.loadcertificate; 4 local load_cert = ssl.loadcertificate;
4 local st = require"util.stanza" 5 local st = require"util.stanza"
5 6
43 end 44 end
44 if not ssl_config or not ssl_config.certificate then 45 if not ssl_config or not ssl_config.certificate then
45 ssl_config = config.get("*", "ssl"); 46 ssl_config = config.get("*", "ssl");
46 end 47 end
47 if not ssl_config or not ssl_config.certificate then 48 if not ssl_config or not ssl_config.certificate then
48 log("warn", "Could not find a certificate to check"); 49 module:log("warn", "Could not find a certificate to check");
49 return; 50 return;
50 end 51 end
51 52
52 local certfile = ssl_config.certificate; 53 local certfile = ssl_config.certificate;
53 local fh, ferr = io.open(certfile); -- Load the file. 54 local fh, ferr = io.open(certfile); -- Load the file.
54 if not fh then 55 if not fh then
55 log("warn", "Could not open certificate %s", ferr); 56 module:log("warn", "Could not open certificate %s", ferr);
56 return; 57 return;
57 end 58 end
58 local cert, lerr = load_cert(fh:read("*a")); -- And parse 59 local cert, lerr = load_cert(fh:read("*a")); -- And parse
59 fh:close(); 60 fh:close();
60 if not cert then 61 if not cert then
61 log("warn", "Could not parse certificate %s: %s", certfile, lerr or ""); 62 module:log("warn", "Could not parse certificate %s: %s", certfile, lerr or "");
62 return; 63 return;
63 end 64 end
64 65
65 local expires_at = parse_x509_datetime(cert:notafter()); 66 local expires_at = parse_x509_datetime(cert:notafter());
66 local expires_in = os.difftime(expires_at, now); 67 local expires_in = os.difftime(expires_at, now);