3434class cronjob_bind_dnssec extends cronjob {
3535
3636 // job schedule
37- protected $ _schedule = '30 3 * * * ' ; //daily at 3:30 a.m.
37+ //protected $_schedule = '30 3 * * *'; //daily at 3:30 a.m.
38+ protected $ _schedule = '* * * * * ' ; //temp 4 test
39+
40+ private function increase_serial ($ serial ){
41+ global $ app , $ conf ;
42+
43+ // increase serial
44+ $ serial_date = $ app ->functions ->intval (substr ($ serial , 0 , 8 ));
45+ $ count = $ app ->functions ->intval (substr ($ serial , 8 , 2 ));
46+ $ current_date = date ("Ymd " );
47+ if ($ serial_date >= $ current_date ){
48+ $ count += 1 ;
49+ if ($ count > 99 ) {
50+ $ serial_date += 1 ;
51+ $ count = 0 ;
52+ }
53+ $ count = str_pad ($ count , 2 , "0 " , STR_PAD_LEFT );
54+ $ new_serial = $ serial_date .$ count ;
55+ } else {
56+ $ new_serial = $ current_date .'01 ' ;
57+ }
58+ return $ new_serial ;
59+ }
3860
3961 public function onRunJob () {
4062 global $ app , $ conf ;
@@ -54,36 +76,13 @@ public function onRunJob() {
5476 $ domain = substr ($ data ['origin ' ], 0 , strlen ($ data ['origin ' ])-1 );
5577 if (!file_exists ($ dns_config ['bind_zonefiles_dir ' ].'/ ' .$ filespre .$ domain )) return false ;
5678
57- $ app ->log ('DNSSEC Auto-Resign: Resigning zone ' .$ domain , LOGLEVEL_INFO );
58-
59- $ zonefile = file_get_contents ($ dns_config ['bind_zonefiles_dir ' ].'/ ' .$ filespre .$ domain );
60- $ keycount =0 ;
61- foreach (glob ($ dns_config ['bind_zonefiles_dir ' ].'/K ' .$ domain .'*.key ' ) as $ keyfile ) {
62- $ includeline = '$INCLUDE ' .basename ($ keyfile );
63- if (!preg_match ('@ ' .preg_quote ($ includeline ).'@ ' , $ zonefile )) $ zonefile .= "\n" .$ includeline ."\n" ;
64- $ keycount ++;
65- }
66- if ($ keycount != 2 ) $ app ->log ('DNSSEC Warning: There are more or less than 2 keyfiles for zone ' .$ domain , LOGLEVEL_WARN );
67- file_put_contents ($ dns_config ['bind_zonefiles_dir ' ].'/ ' .$ filespre .$ domain , $ zonefile );
68-
69- //Sign the zone and set it valid for max. 16 days
70- exec ('cd ' .escapeshellcmd ($ dns_config ['bind_zonefiles_dir ' ]).'; ' .
71- '/usr/sbin/dnssec-signzone -A -e +1382400 -3 $(head -c 1000 /dev/random | sha1sum | cut -b 1-16) -N increment -o ' .escapeshellcmd ($ domain ).' -t ' .$ filespre .escapeshellcmd ($ domain ));
72-
73- //Write Data back into DB
74- $ dnssecdata = "DS-Records: \n" .file_get_contents ($ dns_config ['bind_zonefiles_dir ' ].'/dsset- ' .$ domain .'. ' );
75- $ dnssecdata .= "\n------------------------------------ \n\nDNSKEY-Records: \n" ;
76- foreach (glob ($ dns_config ['bind_zonefiles_dir ' ].'/K ' .$ domain .'*.key ' ) as $ keyfile ) {
77- $ dnssecdata .= file_get_contents ($ keyfile )."\n\n" ;
78- }
79-
80- $ app ->db ->query ('UPDATE dns_soa SET dnssec_info= \'' .$ dnssecdata .'\', dnssec_initialized= \'Y \', dnssec_last_signed= \'' .time ().'\' WHERE id= ' .$ data ['id ' ]);
81- $ data = next ($ soas );
79+ $ app ->log ('DNSSEC Auto-Resign: Touching zone ' .$ domain , LOGLEVEL_INFO );
80+ $ app ->db ->datalogUpdate ('dns_soa ' , array ("serial " => $ this ->increase_serial ($ data ['serial ' ])), 'id ' , $ data ['id ' ]);
8281 }
8382
8483 parent ::onRunJob ();
8584 }
8685
8786}
8887
89- ?>
88+ ?>
0 commit comments