forked from poppyred/1.6.x
/
exec.pdns.php
executable file
·1427 lines (1209 loc) · 55 KB
/
exec.pdns.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if(posix_getuid()<>0){die("Cannot be used in web server mode\n\n");}
include_once(dirname(__FILE__) . '/ressources/class.mysql.inc');
include_once(dirname(__FILE__) . '/ressources/class.ldap.inc');
include_once(dirname(__FILE__) . '/ressources/class.ccurl.inc');
include_once(dirname(__FILE__) . '/framework/class.unix.inc');
include_once(dirname(__FILE__).'/framework/frame.class.inc');
include_once(dirname(__FILE__) . '/ressources/class.pdns.inc');
include_once(dirname(__FILE__) . '/ressources/class.system.network.inc');
$GLOBALS["SHOWKEYS"]=false;
if(preg_match("#schedule-id=([0-9]+)#",implode(" ",$argv),$re)){$GLOBALS["SCHEDULE_ID"]=$re[1];}
if(is_array($argv)){if(preg_match("#--verbose#",implode(" ",$argv))){$GLOBALS["VERBOSE"]=true; ini_set('html_errors',0);ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);}}
if(preg_match("#--showkeys#",implode(" ",$argv))){$GLOBALS["SHOWKEYS"]=true;}
if($argv[1]=="--mysql"){checkMysql();exit;}
if($argv[1]=="--poweradmin"){poweradmin();exit;}
if($argv[1]=="--dnsseck"){dnsseck();exit;}
if($argv[1]=="--reload"){reload_service();exit;}
if($argv[1]=="--rebuild-database"){rebuild_database();exit;}
if($argv[1]=="--replic-artica"){replic_artica_servers();exit;}
if($argv[1]=="--allow-recursion"){allow_recursion();exit;}
if($argv[1]=="--start-recursor"){start_recursor();exit;}
if($argv[1]=="--stop-recursor"){stop_recursor();exit;}
if($argv[1]=="--listen-ips"){listen_ips();exit;}
if($argv[1]=="--wizard-on"){wizard_on();exit;}
function poweradmin(){
if(!is_file("/usr/share/poweradmin/index.php")){
echo "Starting......: ".date("H:i:s")." PowerAdmin is not installed\n";
return;
}
$sock=new sockets();
$PowerAdminUser=$sock->GET_INFO("PowerAdminUser");
$PowerAdminPassword=$sock->GET_INFO("PowerAdminPassword");
if($PowerAdminUser==null){
$PowerAdminUser=time();
$sock->SET_INFO("PowerAdminUser", $PowerAdminUser);
}
if($PowerAdminPassword==null){
$PowerAdminPassword=microtime(false);
$sock->SET_INFO("PowerAdminPassword", $PowerAdminPassword);
}
$q=new mysql();
$q->PRIVILEGES($PowerAdminUser,$PowerAdminPassword,"powerdns");
$unix=new unix();
$f[]="<?php";
$f[]="\$db_host = '$q->mysql_server';";
$f[]="\$db_user = '$PowerAdminUser';";
$f[]="\$db_pass = '$PowerAdminPassword';";
$f[]="\$db_name = 'powerdns';";
$f[]="\$db_port = '$q->mysql_port';";
$f[]="\$db_type = 'mysql';";
$f[]="\$iface_lang = 'en_EN';";
$f[]="\$cryptokey = '".$unix->hostname_g()."';";
$f[]="\$session_key = '". $unix->hostname_g()."';";
$f[]="\$password_encryption = 'md5'; // or md5salt";
$f[]="\$iface_style = 'example';";
$f[]="\$iface_rowamount = 50;";
$f[]="\$iface_expire = 1800;";
$f[]="\$iface_zonelist_serial = false;";
$f[]="\$iface_title = 'PowerAdmin DNS WebConsole';";
$f[]="\$password_encryption='md5';";
$f[]="\$dns_ttl = 86400;";
$f[]="\$dns_fancy = false;";
$f[]="\$dns_strict_tld_check = true;";
$f[]="\$dns_hostmaster = 'hostmaster.example.net';";
$f[]="\$dns_ns1 = 'ns1.example.net';";
$f[]="\$dns_ns2 = 'ns2.example.net';";
$f[]="\$syslog_use = True;";
$f[]="\$syslog_ident = 'poweradmin';";
$f[]="\$syslog_facility = LOG_USER;";
$f[]="?>";
$sql="DELETE FROM users WHERE id=1";
$q->QUERY_SQL($sql,"powerdns");
$ldap=new clladp();
$pass=md5($ldap->ldap_password);
$sql="SELECT password,fullname,email FROM `users` WHERE id=1";
$ligne=mysql_fetch_array($q->QUERY_SQL($sql,"powerdns"));
if($ligne["password"]<>null){
$sql="UPDATE `users` SET `username`= '$ldap->ldap_admin',`password`='$pass' ,`perm_templ`=1,`active`=1 WHERE id=1";
}else{
$sql="INSERT INTO `users` (`id`, `username`, `password`, `fullname`, `email`, `description`, `perm_templ`, `active`) VALUES
(1, '$ldap->ldap_admin', '$pass', 'Administrator', 'admin@example.net', 'Administrator with full rights.', 1, 1);";
}
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){echo "Starting......: ".date("H:i:s")." PowerAdmin $ldap->ldap_admin failed $q->mysql_error\n";}else{
echo "Starting......: ".date("H:i:s")." PowerAdmin $ldap->ldap_admin ok\n";
}
@file_put_contents("/usr/share/poweradmin/inc/config.inc.php", @implode("\n", $f));
echo "Starting......: ".date("H:i:s")." PowerAdmin config.inc.php done\n";
if(is_dir("/usr/share/poweradmin/install")){shell_exec("/bin/rm -rf /usr/share/poweradmin/install >/dev/null 2>&1");}
}
function rebuild_database($nollop=false){
$unix=new unix();
$MYSQL_DATA_DIR=$unix->MYSQL_DATA_DIR();
echo "Starting......: ".date("H:i:s")." PowerDNS destroy database and recreate it\n";
$q=new mysql();
$q->DELETE_DATABASE("powerdns");
$rm=$unix->find_program("rm");
if(is_dir("$MYSQL_DATA_DIR/powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS removing $MYSQL_DATA_DIR/powerdns\n";
shell_exec("$rm -rf $MYSQL_DATA_DIR/powerdns");
}
checkMysql($nollop);
shell_exec("/etc/init.d/artica-postfix restart pdns");
}
function checkMysql($nollop=false){
$unix=new unix();
$timefile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".time";
if($unix->file_time_min($timefile)<1){
echo "Starting......: ".date("H:i:s")." PowerDNS need at least 1mn, aborting\n";
return;
}
@unlink($timefile);
@file_put_contents($timefile, time());
$passwdcmdline=null;
$mysql=$unix->find_program("mysql");
$q=new mysql();
if(!$q->TestingConnection(true)){
echo "Starting......: ".date("H:i:s")." PowerDNS creating, MySQL seems not ready..\n";
return;
}
forward_zones();
if(!$q->DATABASE_EXISTS("powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'powerdns' database\n";
if(!$q->CREATE_DATABASE("powerdns")){echo "Starting......: ".date("H:i:s")." PowerDNS creating 'powerdns' database failed\n"; return;}
}
echo "Starting......: ".date("H:i:s")." PowerDNS 'powerdns' database OK\n";
$f["cryptokeys"]=true;
$f["domainmetadata"]=true;
$f["domains"]=true;
$f["perm_items"]=true;
$f["perm_templ"]=true;
$f["perm_templ_items"]=true;
$f["records"]=true;
$f["supermasters"]=true;
$f["tsigkeys"]=true;
$f["users"]=true;
$f["zones"]=true;
$f["zone_templ"]=true;
$f["zone_templ_records"]=true;
$resultTables=true;
while (list ($tablename, $line2) = each ($f) ){
if(!$q->TABLE_EXISTS($tablename, "powerdns")){echo "Starting......: ".date("H:i:s")." PowerDNS Table `$tablename` failed...\n";$resultTables=false;continue;}
echo "Starting......: ".date("H:i:s")." PowerDNS Table `$tablename` OK...\n";
}
if($resultTables){
echo "Starting......: ".date("H:i:s")." PowerDNS pass tests Success...\n";
return true;
}
$dumpfile="/usr/share/artica-postfix/bin/install/pdns/powerdns.sql";
if(!is_file($dumpfile)){
echo "Starting......: ".date("H:i:s")." PowerDNS /usr/share/artica-postfix/bin/install/pdns/powerdns.sql no such file...\n";
return;
}
echo "Starting......: ".date("H:i:s")." PowerDNS installing database...\n";
if($q->mysql_password<>null){$passwdcmdline=" -p$q->mysql_password";}
$cmd="$mysql -B -u $q->mysql_admin$passwdcmdline --database=powerdns -E < $dumpfile >/dev/null 2>&1";
shell_exec($cmd);
reset($f);
$resultTables=true;
while (list ($tablename, $line2) = each ($f) ){
if(!$q->TABLE_EXISTS($tablename, "powerdns")){echo "Starting......: ".date("H:i:s")." PowerDNS Table `$tablename` failed...\n";$resultTables=false;continue;}
echo "Starting......: ".date("H:i:s")." PowerDNS Table `$tablename` OK...\n";
}
if($resultTables){echo "Starting......: ".date("H:i:s")." PowerDNS Success...\n";return true;}
if(!$q->TABLE_EXISTS("domains", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'domains' table\n";
$sql="CREATE TABLE IF NOT EXISTS domains (
id INT auto_increment,
name VARCHAR(255) NOT NULL,
master VARCHAR(128) DEFAULT NULL,
last_check INT DEFAULT NULL,
type VARCHAR(6) NOT NULL,
notified_serial INT DEFAULT NULL,
account VARCHAR(40) DEFAULT NULL,
primary key (id)
) Engine=InnoDB;";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){echo "Starting......: ".date("H:i:s")." PowerDNS creating 'domains' table FAILED\n";}else{return;}
echo "Starting......: ".date("H:i:s")." PowerDNS table 'domains' Success\n";
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS table 'domains' Success\n";
$q->QUERY_SQL("CREATE UNIQUE INDEX name_index ON domains(name);","powerdns");
}
if(!$q->TABLE_EXISTS("records", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'records' table\n";
$sql="CREATE TABLE IF NOT EXISTS records (
id INT auto_increment,
domain_id INT DEFAULT NULL,
name VARCHAR(255) DEFAULT NULL,
type VARCHAR(10) DEFAULT NULL,
content VARCHAR(255) DEFAULT NULL,
ttl INT DEFAULT NULL,
prio INT DEFAULT NULL,
change_date INT DEFAULT NULL,
explainthis VARCHAR(255) DEFAULT NULL,
primary key(id)
)Engine=InnoDB;";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'records' table FAILED\n";
return;
}
$q->QUERY_SQL("CREATE INDEX rec_name_index ON records(name);","powerdns");
$q->QUERY_SQL("CREATE INDEX nametype_index ON records(name,type);","powerdns");
$q->QUERY_SQL("CREATE INDEX domain_id ON records(domain_id);","powerdns");
$q->QUERY_SQL("alter table records add ordername VARCHAR(255);","powerdns");
$q->QUERY_SQL("alter table records add auth bool;","powerdns");
$q->QUERY_SQL("create index orderindex on records(ordername);","powerdns");
$q->QUERY_SQL("alter table records change column type type VARCHAR(10);","powerdns");
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'records' table success\n";
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'records' table success\n";
}
if(!$q->TABLE_EXISTS("supermasters", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'supermasters' table\n";
$sql="CREATE TABLE IF NOT EXISTS supermasters (
ip VARCHAR(25) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) DEFAULT NULL
) Engine=InnoDB;";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'supermasters' table FAILED\n";
return;
}
$q->QUERY_SQL("CREATE INDEX rec_name_index ON records(name);","powerdns");
$q->QUERY_SQL("CREATE INDEX nametype_index ON records(name,type);","powerdns");
$q->QUERY_SQL("CREATE INDEX domain_id ON records(domain_id);","powerdns");
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'supermasters' table success\n";
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'supermasters' table success\n";
}
if(!$q->TABLE_EXISTS("domainmetadata", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'domainmetadata' table\n";
$sql="CREATE TABLE IF NOT EXISTS domainmetadata (
id INT auto_increment,
domain_id INT NOT NULL,
kind VARCHAR(16),
content TEXT,
primary key(id)
);";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'domainmetadata' table FAILED\n";
return;
}
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'domainmetadata' table success\n";
$q->QUERY_SQL("create index domainmetaidindex on domainmetadata(domain_id);","powerdns");
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS 'domainmetadata' table success\n";
}
if(!$q->TABLE_EXISTS("cryptokeys", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'cryptokeys' table\n";
$sql="CREATE TABLE IF NOT EXISTS cryptokeys (
id INT auto_increment,
domain_id INT NOT NULL,
flags INT NOT NULL,
active BOOL,
content TEXT,
primary key(id)
); ";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'cryptokeys' table FAILED\n";
return;
}
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'cryptokeys' table success\n";
$q->QUERY_SQL("create index domainidindex on cryptokeys(domain_id);","powerdns");
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS 'cryptokeys' table success\n";
}
if(!$q->TABLE_EXISTS("tsigkeys", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'tsigkeys' table\n";
$sql="CREATE TABLE IF NOT EXISTS tsigkeys (
id INT auto_increment,
name VARCHAR(255),
algorithm VARCHAR(255),
secret VARCHAR(255),
primary key(id)
);";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'tsigkeys' table FAILED\n";
return;
}
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'tsigkeys' table success\n";
$q->QUERY_SQL("create unique index namealgoindex on tsigkeys(name, algorithm);","powerdns");
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS 'tsigkeys' table success\n";
}
if(!$q->TABLE_EXISTS("users", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'users' table\n";
$sql="CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(16) NOT NULL DEFAULT '0', `password` varchar(34) NOT NULL DEFAULT '0', `fullname` varchar(255) NOT NULL DEFAULT '0', `email` varchar(255) NOT NULL DEFAULT '0', `description` varchar(1024) NOT NULL DEFAULT '0', `perm_templ` tinyint(4) NOT NULL DEFAULT '0', `active` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id`))";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){ echo "Starting......: ".date("H:i:s")." PowerDNS creating 'users' table FAILED\n"; return; }
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'users' table success\n";
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS 'users' table success\n";
}
if(!$q->TABLE_EXISTS("perm_items", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'perm_items' table\n";
$sql="CREATE TABLE IF NOT EXISTS `perm_items` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL DEFAULT '0', `descr` varchar(1024) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=62 ;";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){ echo "Starting......: ".date("H:i:s")." PowerDNS creating 'perm_items' table FAILED\n"; return; }
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'perm_items' table success\n";
$sql="INSERT INTO `perm_items` (`id`, `name`, `descr`) VALUES (41, 'zone_master_add', 'User is allowed to add new master zones.'), (42, 'zone_slave_add', 'User is allowed to add new slave zones.'), (43, 'zone_content_view_own', 'User is allowed to see the content and meta data of zones he owns.'), (44, 'zone_content_edit_own', 'User is allowed to edit the content of zones he owns.'), (45, 'zone_meta_edit_own', 'User is allowed to edit the meta data of zones he owns.'), (46, 'zone_content_view_others', 'User is allowed to see the content and meta data of zones he does not own.'), (47, 'zone_content_edit_others', 'User is allowed to edit the content of zones he does not own.'), (48, 'zone_meta_edit_others', 'User is allowed to edit the meta data of zones he does not own.'), (49, 'search', 'User is allowed to perform searches.'), (50, 'supermaster_view', 'User is allowed to view supermasters.'), (51, 'supermaster_add', 'User is allowed to add new supermasters.'), (52, 'supermaster_edit', 'User is allowed to edit supermasters.'), (53, 'user_is_ueberuser', 'User has full access. God-like. Redeemer.'), (54, 'user_view_others', 'User is allowed to see other users and their details.'), (55, 'user_add_new', 'User is allowed to add new users.'), (56, 'user_edit_own', 'User is allowed to edit their own details.'), (57, 'user_edit_others', 'User is allowed to edit other users.'), (58, 'user_passwd_edit_others', 'User is allowed to edit the password of other users.'), (59, 'user_edit_templ_perm', 'User is allowed to change the permission template that is assigned to a user.'), (60, 'templ_perm_add', 'User is allowed to add new permission templates.'), (61, 'templ_perm_edit', 'User is allowed to edit existing permission templates.');";
$q->QUERY_SQL($sql,"powerdns");
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS 'perm_items' table success\n";
}
if(!$q->TABLE_EXISTS("perm_templ", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'perm_templ' table\n";
$sql="CREATE TABLE IF NOT EXISTS `perm_templ` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(128) NOT NULL DEFAULT '0', `descr` varchar(1024) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'perm_templ' table FAILED\n";
}else{
$sql="INSERT INTO `perm_templ` (`id`, `name`, `descr`) VALUES (1, 'Administrator', 'Administrator template with full rights.');";
$q->QUERY_SQL($sql,"powerdns");
}
}
if(!$q->TABLE_EXISTS("perm_templ_items", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'perm_templ_items' table\n";
$sql="CREATE TABLE IF NOT EXISTS `perm_templ_items` ( `id` int(11) NOT NULL AUTO_INCREMENT, `templ_id` int(11) NOT NULL DEFAULT '0', `perm_id` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=250 ;";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){echo "Starting......: ".date("H:i:s")." PowerDNS creating 'perm_templ_items' table FAILED\n";return;}
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'perm_templ_items' table success\n";
$sql="INSERT INTO `perm_templ_items` (`id`, `templ_id`, `perm_id`) VALUES (249, 1, 53);";
$q->QUERY_SQL($sql,"powerdns");
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS 'perm_templ_items' table success\n";
}
if(!$q->TABLE_EXISTS("zones", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'zones' table\n";
$sql="CREATE TABLE IF NOT EXISTS `zones` ( `id` int(11) NOT NULL AUTO_INCREMENT, `domain_id` int(11) NOT NULL DEFAULT '0', `owner` int(11) NOT NULL DEFAULT '0', `comment` varchar(1024) DEFAULT '0', `zone_templ_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){echo "Starting......: ".date("H:i:s")." PowerDNS creating 'zones' table FAILED\n";return;}
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS 'zones' table success\n";
}
if(!$q->TABLE_EXISTS("zone_templ", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'zone_templ' table\n";
$sql="CREATE TABLE IF NOT EXISTS `zone_templ` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL DEFAULT '0',
`descr` varchar(1024) NOT NULL DEFAULT '0',
`owner` bigint(20) NOT NULL DEFAULT '0', PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'zone_templ' table FAILED\n";
return;
}
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'zone_templ' table success\n";
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS 'zone_templ' table success\n";
}
$q->QUERY_SQL("CREATE TABLE IF NOT EXISTS zone_templ_records (
id INTEGER NOT NULL AUTO_INCREMENT,
zone_templ_id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL,
`type` VARCHAR(6) NOT NULL,
content VARCHAR(255) NOT NULL,
ttl INTEGER NOT NULL,
prio INTEGER NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;","powerdns");
$q->QUERY_SQL("CREATE TABLE IF NOT EXISTS records_zone_templ (
domain_id INTEGER NOT NULL,
record_id INTEGER NOT NULL,
zone_templ_id INTEGER NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;"
);
if(!$q->TABLE_EXISTS("zone_templ_records", "powerdns")){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'zone_templ_records' table\n";
$sql="CREATE TABLE IF NOT EXISTS `zone_templ_records` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`zone_templ_id` bigint(20) NOT NULL DEFAULT '0',
`name` varchar(255) NOT NULL DEFAULT '0',
`type` varchar(6) NOT NULL DEFAULT '0',
`content` varchar(255) NOT NULL DEFAULT '0',
`ttl` bigint(20) NOT NULL DEFAULT '0',
`prio` bigint(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
$q->QUERY_SQL($sql,"powerdns");
if(!$q->ok){
echo "Starting......: ".date("H:i:s")." PowerDNS creating 'zone_templ_records' table FAILED\n";
}
}
if(!$q->TABLE_EXISTS("domainmetadata", "powerdns")){
$q->QUERY_SQL("create table domainmetadata ( id INT auto_increment, domain_id INT NOT NULL, kind VARCHAR(16), content TEXT, primary key(id) );","powerdns");
if(!$q->ok){echo "Starting......: ".date("H:i:s")." PowerDNS patching database/domainmetadata failed $q->mysql_error\n"; return;}
echo "Starting......: ".date("H:i:s")." PowerDNS patching database/domainmetadata success\n";
$q->QUERY_SQL("create index domainmetaidindex on domainmetadata(domain_id);","powerdns");
if(!$q->ok){echo "Starting......: ".date("H:i:s")." PowerDNS patching database/domainmetadata failed $q->mysql_error\n"; }
}
else{
echo "Starting......: ".date("H:i:s")." PowerDNS patching database/domainmetadata OK\n";
}
if(!$q->TABLE_EXISTS("cryptokeys", "powerdns")){
$q->QUERY_SQL("create table cryptokeys (
id INT auto_increment,
domain_id INT NOT NULL,
flags INT NOT NULL,
active BOOL,
content TEXT,
primary key(id)
);","powerdns");
if(!$q->ok){
echo "Starting......: ".date("H:i:s")." PowerDNS patching database/cryptokeys failed $q->mysql_error\n";
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS patching database/cryptokeys success\n";
$q->QUERY_SQL("create index domainidindex on cryptokeys(domain_id);","powerdns");
if(!$q->ok){
echo "Starting......: ".date("H:i:s")." PowerDNS patching database/cryptokeys failed $q->mysql_error\n";
}
}
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS patching database/cryptokeys OK\n";
}
if($q->TABLE_EXISTS("records", "powerdns")){
if(!$q->FIELD_EXISTS("records","ordername","powerdns") ){
$q->QUERY_SQL("alter table records add ordername VARCHAR(255)","powerdns");
if(!$q->ok){echo "Starting......: ".date("H:i:s")." PowerDNS patching database/records failed $q->mysql_error\n";}
$q->QUERY_SQL("create index orderindex on records(ordername)","powerdns");
}
if(!$q->FIELD_EXISTS("records","auth","powerdns") ){
$q->QUERY_SQL("alter table records add auth bool","powerdns");
if(!$q->ok){echo "Starting......: ".date("H:i:s")." PowerDNS patching database/records failed $q->mysql_error\n";}
}
if(!$q->FIELD_EXISTS("records","disabled","powerdns") ){
$q->QUERY_SQL("alter table records add `disabled` TINYINT(1) DEFAULT 0, ADD INDEX `disabled`(`disabled`)","powerdns");
if(!$q->ok){echo "Starting......: ".date("H:i:s")." PowerDNS patching database/records/disabled failed $q->mysql_error\n";}
}
$q->QUERY_SQL("alter table records change column type type VARCHAR(10);","powerdns");
}
if(!$q->TABLE_EXISTS("tsigkeys", "powerdns")){
$q->QUERY_SQL("create table tsigkeys (
id INT auto_increment,
name VARCHAR(255),
algorithm VARCHAR(50),
secret VARCHAR(255),
primary key(id)
);","powerdns");
if(!$q->ok){
echo "Starting......: ".date("H:i:s")." PowerDNS patching database/tsigkeys failed $q->mysql_error\n";
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS patching database/tsigkeys success\n";
$q->QUERY_SQL("create unique index namealgoindex on tsigkeys(name, algorithm);","powerdns");
if(!$q->ok){
echo "Starting......: ".date("H:i:s")." PowerDNS patching database/tsigkeys failed $q->mysql_error\n";
}
}
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS patching database/tsigkeys OK\n";
}
echo "Starting......: ".date("H:i:s")." PowerDNS Mysql done...\n";
poweradmin();
}
function dnsseck(){
$unix=new unix();
$pdnssec=$unix->find_program("pdnssec");
if(!is_file($pdnssec)){echo "Starting......: ".date("H:i:s")." PowerDNS pdnssec no such binary !!!\n";return;}
$sql="SELECT id,name FROM domains";
$q=new mysql();
$results=$q->QUERY_SQL($sql,'powerdns');
if(!$q->ok){echo "$q->mysql_error\n";}
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
echo "Starting......: ".date("H:i:s")." PowerDNS pdnssec checking zone {$ligne["name"]}\n";
if(!dnsseck_is_crypto($ligne["id"])){
echo "Starting......: ".date("H:i:s")." PowerDNS pdnssec securing zone {$ligne["name"]}\n";
shell_exec2("$pdnssec add-zone-key {$ligne["name"]} ksk >/dev/null 2>&1");
shell_exec2("$pdnssec set-presigned {$ligne["name"]} >/dev/null 2>&1");
if(!dnsseck_is_crypto($ligne["id"],$ligne["name"])){
echo "Starting......: ".date("H:i:s")." PowerDNS pdnssec securing zone {$ligne["name"]} Failed\n";
continue;
}
}
$DOMAINSZ[$ligne["name"]]=true;
shell_exec2("$pdnssec secure-zone {$ligne["name"]} >/dev/null 2>&1");
}
if(count($DOMAINSZ)>0){
while (list ($domain, $line2) = each ($DOMAINSZ) ){
shell_exec2("$pdnssec rectify-zone $domain >/dev/null 2>&1");
shell_exec2("$pdnssec set-nsec3 $domain '1 1 1 ab' >/dev/null 2>&1");
}
reset($DOMAINSZ);
while (list ($domain, $none) = each ($DOMAINSZ) ){
$zones=array();
$ok=false;
if($GLOBALS["VERBOSE"]){echo "Starting......: ".date("H:i:s")." PowerDNS Execute `$pdnssec show-zone $domain 2>&1` in order to see results\n";}
exec("$pdnssec show-zone $domain 2>&1",$zones);
while (list ($num1, $line2) = each ($zones) ){
if(preg_match("#Zone has.+?semantics#", $line2)){
echo "Starting......: ".date("H:i:s")." PowerDNS pdnssec checking zone $domain OK\n";
$ok=true;
break;
}
}
if(!$ok){echo "Starting......: ".date("H:i:s")." PowerDNS pdnssec checking zone $domain not secure...\n";}
}
}
shell_exec2("$pdnssec rectify-all-zones >/dev/null 2>&1");
}
function shell_exec2($cmd){
if($GLOBALS["VERBOSE"]){echo "Starting......: ".date("H:i:s")." PowerDNS Execute `$cmd`\n";}
shell_exec($cmd);
}
function dnsseck_is_crypto($id,$domain=null){
$q=new mysql();
$mres=false;
$sql="SELECT id,content FROM cryptokeys WHERE domain_id=$id";
$results=$q->QUERY_SQL($sql,'powerdns');
if(!$q->ok){echo "$q->mysql_error\n";}
while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
if(strlen($ligne["content"])>50){
if($GLOBALS["SHOWKEYS"]){
echo "Here it is the crypted key for domain `$domain` ID:$id\n";
echo "***************************************\n";
echo $ligne["content"]."\n";
echo "***************************************\n\n";
}
echo "Starting......: ".date("H:i:s")." PowerDNS pdnssec securing zone Already done with key [{$ligne["id"]}] ". strlen($ligne["content"]). " bytes\n";
$mres=true;
}
}
return $mres;
}
function reload_service(){
$sock=new sockets();
$DisablePowerDnsManagement=$sock->GET_INFO("DisablePowerDnsManagement");
$EnablePDNS=$sock->GET_INFO("EnablePDNS");
if(!is_numeric($DisablePowerDnsManagement)){$DisablePowerDnsManagement=0;}
if(!is_numeric($EnablePDNS)){$EnablePDNS=0;}
$unix=new unix();
$kill=$unix->find_program("kill");
$pdns_server_bin=$unix->find_program("pdns_server");
$pdns_recursor_bin=$unix->find_program("pdns_recursor");
if($DisablePowerDnsManagement==1){echo "Starting......: ".date("H:i:s")." PowerDNS [reload]: management by artica is disabled\n";return;}
if($EnablePDNS==0){echo "Starting......: ".date("H:i:s")." PowerDNS [reload]: is disabled EnablePDNS=$EnablePDNS\n";return;}
if(!is_file($pdns_server_bin)){echo "Starting......: ".date("H:i:s")." PowerDNS [reload]: reloading pdns_server no such binary\n";return;}
if(is_file($pdns_recursor_bin)){
$recursor_pid=$unix->PIDOF($pdns_recursor_bin);
if($unix->process_exists("$recursor_pid")){
echo "Starting......: ".date("H:i:s")." PowerDNS [reload]: recursor pid $recursor_pid\n";
shell_exec("$kill -HUP $recursor_pid");
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS [reload]: recursor not running failed\n";
}
}
$pdns_server_pid=$unix->PIDOF($pdns_server_bin);
if($unix->process_exists("$pdns_server_pid")){
echo "Starting......: ".date("H:i:s")." PowerDNS [reload]: reloading pdns_server pid $pdns_server_pid\n";
shell_exec("$kill -HUP $pdns_server_pid");
}else{
echo "Starting......: ".date("H:i:s")." PowerDNS [reload]: pdns_server not running failed\n";
}
}
function create_rrd(){
$f[]="rrdtool create pdns_recursor.rrd -s 60";
$f[]="DS:questions:COUNTER:600:0:100000";
$f[]="DS:tcp-questions:COUNTER:600:0:100000";
$f[]="DS:cache-entries:GAUGE:600:0:U";
$f[]="DS:packetcache-entries:GAUGE:600:0:U";
$f[]="DS:throttle-entries:GAUGE:600:0:U";
$f[]="DS:concurrent-queries:GAUGE:600:0:50000";
$f[]="DS:noerror-answers:COUNTER:600:0:100000";
$f[]="DS:nxdomain-answers:COUNTER:600:0:100000";
$f[]="DS:servfail-answers:COUNTER:600:0:100000";
$f[]="DS:tcp-outqueries:COUNTER:600:0:100000";
$f[]="DS:outgoing-timeouts:COUNTER:600:0:100000";
$f[]="DS:throttled-out:COUNTER:600:0:100000";
$f[]="DS:nsspeeds-entries:GAUGE:600:0:U";
$f[]="DS:negcache-entries:GAUGE:600:0:U";
$f[]="DS:all-outqueries:COUNTER:600:0:100000";
$f[]="DS:cache-hits:COUNTER:600:0:100000";
$f[]="DS:cache-misses:COUNTER:600:0:100000";
$f[]="DS:packetcache-hits:COUNTER:600:0:100000";
$f[]="DS:packetcache-misses:COUNTER:600:0:100000";
$f[]="DS:answers0-1:COUNTER:600:0:100000";
$f[]="DS:answers1-10:COUNTER:600:0:100000";
$f[]="DS:answers10-100:COUNTER:600:0:100000";
$f[]="DS:answers100-1000:COUNTER:600:0:100000";
$f[]="DS:answers-slow:COUNTER:600:0:100000";
$f[]="DS:udp-overruns:COUNTER:600:0:100000";
$f[]="DS:qa-latency:GAUGE:600:0:10000000";
$f[]="DS:user-msec:COUNTER:600:0:64000";
$f[]="DS:uptime:GAUGE:600:0:U";
$f[]="DS:unexpected-packets:COUNTER:600:0:1000000";
$f[]="DS:resource-limits:COUNTER:600:0:1000000";
$f[]="DS:over-capacity-drops:COUNTER:600:0:1000000";
$f[]="DS:client-parse-errors:COUNTER:600:0:1000000";
$f[]="DS:server-parse-errors:COUNTER:600:0:1000000";
$f[]="DS:unauthorized-udp:COUNTER:600:0:1000000";
$f[]="DS:unauthorized-tcp:COUNTER:600:0:1000000";
$f[]="DS:sys-msec:COUNTER:600:0:6400";
$f[]="RRA:AVERAGE:0.5:1:9600 ";
$f[]="RRA:AVERAGE:0.5:4:9600";
$f[]="RRA:AVERAGE:0.5:24:6000 ";
$f[]="RRA:MAX:0.5:1:9600 ";
$f[]="RRA:MAX:0.5:4:9600";
$f[]="RRA:MAX:0.5:24:6000";
$f=array();
$f[]="#!/usr/bin/env bash";
$f[]="SOCKETDIR=/var/run/";
$f[]="TSTAMP=\$(date +%s)";
$f[]="";
$f[]="OS=`uname`";
$f[]="if [ \"\$OS\" == \"Linux\" ]";
$f[]="then";
$f[]="# echo \"Using Linux netstat directive\"";
$f[]=" NETSTAT_GREP=\"packet receive error\"";
$f[]="elif [ \"\$OS\" == \"FreeBSD\" ]";
$f[]="then";
$f[]="# echo \"Using FreeBSD netstat directive\"";
$f[]=" NETSTAT_GREP=\"dropped due to full socket buffers\"";
$f[]="else";
$f[]=" echo \"Unsupported OS found, please report to the PowerDNS team.\"";
$f[]=" exit 1";
$f[]="fi";
$f[]="";
$f[]="";
$f[]="VARIABLES=\"questions \ ";
$f[]=" tcp-questions \ ";
$f[]=" cache-entries \ ";
$f[]=" packetcache-entries \ ";
$f[]=" concurrent-queries \ ";
$f[]=" nxdomain-answers \ ";
$f[]=" noerror-answers \ ";
$f[]=" servfail-answers \ ";
$f[]=" tcp-outqueries \ ";
$f[]=" outgoing-timeouts \ ";
$f[]=" nsspeeds-entries \ ";
$f[]=" negcache-entries \ ";
$f[]=" all-outqueries \ ";
$f[]=" throttled-out \ ";
$f[]=" packetcache-hits \ ";
$f[]=" packetcache-misses \ ";
$f[]=" cache-hits \ ";
$f[]=" cache-misses \ ";
$f[]=" answers0-1 \ ";
$f[]=" answers1-10 \ ";
$f[]=" answers10-100 \ ";
$f[]=" answers100-1000 \ ";
$f[]=" answers-slow \ ";
$f[]=" qa-latency \ ";
$f[]=" throttle-entries \ ";
$f[]=" sys-msec user-msec \ ";
$f[]=" unauthorized-udp \ ";
$f[]=" unauthorized-tcp \ ";
$f[]=" client-parse-errors \ ";
$f[]=" server-parse-errors \ ";
$f[]=" uptime unexpected-packets \ ";
$f[]=" resource-limits \ ";
$f[]=" over-capacity-drops\"";
$f[]="";
$f[]="UVARIABLES=\$(echo \$VARIABLES | tr '[a-z]' '[A-Z]' | tr - _ )";
$f[]="";
$f[]="rec_control --socket-dir=\$SOCKETDIR GET \$VARIABLES |";
$f[]="(";
$f[]=" for a in \$UVARIABLES";
$f[]=" do";
$f[]=" read \$a";
$f[]=" done";
$f[]=" rrdtool update pdns_recursor.rrd \ ";
$f[]=" -t \"udp-overruns:\"\$(for a in \$VARIABLES ";
$f[]=" do";
$f[]=" echo -n \$a:";
$f[]=" done | sed 's/:\$//' ) \ ";
$f[]="\$TSTAMP\$(";
$f[]=" echo -n : ";
$f[]=" netstat -s | grep \"\$NETSTAT_GREP\" | awk '{printf \$1}' ";
$f[]=" for a in \$UVARIABLES";
$f[]=" do";
$f[]=" echo -n :\${!a}";
$f[]=" done";
$f[]=" )";
$f[]=")";
$f[]="";
$f=array();
$f[]="#!/bin/bash";
$f[]="WWWPREFIX=. ";
$f[]="WSIZE=800";
$f[]="HSIZE=250";
$f[]="";
$f[]="# only recent rrds offer slope-mode:";
$f[]="GRAPHOPTS=--slope-mode";
$f[]="";
$f[]="function makeGraphs()";
$f[]="{";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/questions-\$2.png -w \$WSIZE -h \$HSIZE -l 0\ ";
$f[]=" -t \"Questions and answers per second\" \ ";
$f[]=" -v \"packets\" \ ";
$f[]=" DEF:questions=pdns_recursor.rrd:questions:AVERAGE \ ";
$f[]=" DEF:nxdomainanswers=pdns_recursor.rrd:nxdomain-answers:AVERAGE \ ";
$f[]=" DEF:noerroranswers=pdns_recursor.rrd:noerror-answers:AVERAGE \ ";
$f[]=" DEF:servfailanswers=pdns_recursor.rrd:servfail-answers:AVERAGE \ ";
$f[]=" LINE1:questions#0000ff:\"questions/s\"\ ";
$f[]=" AREA:noerroranswers#00ff00:\"noerror answers/s\" \ ";
$f[]=" STACK:nxdomainanswers#ffa500:\"nxdomain answers/s\"\ ";
$f[]=" STACK:servfailanswers#ff0000:\"servfail answers/s\" ";
$f[]="";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/tcp-questions-\$2.png -w \$WSIZE -h \$HSIZE -l 0\ ";
$f[]=" -t \"TCP questions and answers per second, unauthorized packets/s\" \ ";
$f[]=" -v \"packets\" \ ";
$f[]=" DEF:tcpquestions=pdns_recursor.rrd:tcp-questions:AVERAGE \ ";
$f[]=" DEF:unauthudp=pdns_recursor.rrd:unauthorized-udp:AVERAGE \ ";
$f[]=" DEF:unauthtcp=pdns_recursor.rrd:unauthorized-tcp:AVERAGE \ ";
$f[]=" LINE1:tcpquestions#0000ff:\"tcp questions/s\" \ ";
$f[]=" LINE1:unauthudp#ff0000:\"udp unauth/s\" \ ";
$f[]=" LINE1:unauthtcp#00ff00:\"tcp unauth/s\" ";
$f[]="";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/packet-errors-\$2.png -w \$WSIZE -h \$HSIZE -l 0\ ";
$f[]=" -t \"Packet errors per second\" \ ";
$f[]=" -v \"packets\" \ ";
$f[]=" DEF:clientparseerrors=pdns_recursor.rrd:client-parse-errors:AVERAGE \ ";
$f[]=" DEF:serverparseerrors=pdns_recursor.rrd:server-parse-errors:AVERAGE \ ";
$f[]=" DEF:unexpected=pdns_recursor.rrd:unexpected-packets:AVERAGE \ ";
$f[]=" DEF:udpoverruns=pdns_recursor.rrd:udp-overruns:AVERAGE \ ";
$f[]=" LINE1:clientparseerrors#0000ff:\"bad packets from clients\" \ ";
$f[]=" LINE1:serverparseerrors#00ff00:\"bad packets from servers\" \ ";
$f[]=" LINE1:unexpected#ff0000:\"unexpected packets from servers\" \ ";
$f[]=" LINE1:udpoverruns#ff00ff:\"udp overruns from remotes\" ";
$f[]="";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/limits-\$2.png -w \$WSIZE -h \$HSIZE -l 0\ ";
$f[]=" -t \"Limitations per second\" \ ";
$f[]=" -v \"events\" \ ";
$f[]=" DEF:resourcelimits=pdns_recursor.rrd:resource-limits:AVERAGE \ ";
$f[]=" DEF:overcapacities=pdns_recursor.rrd:over-capacity-drops:AVERAGE \ ";
$f[]=" LINE1:resourcelimits#ff0000:\"outqueries dropped because of resource limits\" \ ";
$f[]=" LINE1:overcapacities#0000ff:\"questions dropped because of mthread limit\" ";
$f[]="";
$f[]="";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/latencies-\$2.png -w \$WSIZE -h \$HSIZE -l 0\ ";
$f[]=" -t \"Questions answered within latency\" \ ";
$f[]=" -v \"questions\" \ ";
$f[]=" DEF:questions=pdns_recursor.rrd:questions:AVERAGE \ ";
$f[]=" DEF:answers00=pdns_recursor.rrd:packetcache-hits:AVERAGE \ ";
$f[]=" DEF:answers01=pdns_recursor.rrd:answers0-1:AVERAGE \ ";
$f[]=" DEF:answers110=pdns_recursor.rrd:answers1-10:AVERAGE \ ";
$f[]=" DEF:answers10100=pdns_recursor.rrd:answers10-100:AVERAGE \ ";
$f[]=" DEF:answers1001000=pdns_recursor.rrd:answers100-1000:AVERAGE \ ";
$f[]=" DEF:answersslow=pdns_recursor.rrd:answers-slow:AVERAGE \ ";
$f[]=" LINE1:questions#0000ff:\"questions/s\" \ ";
$f[]=" AREA:answers00#00ff00:\"<<1 ms\" \ ";
$f[]=" STACK:answers01#00fff0:\"<1 ms\" \ ";
$f[]=" STACK:answers110#0000ff:\"<10 ms\" \ ";
$f[]=" STACK:answers10100#ff9900:\"<100 ms\" \ ";
$f[]=" STACK:answers1001000#ffff00:\"<1000 ms\" \ ";
$f[]=" STACK:answersslow#ff0000:\">1000 ms\" ";
$f[]="";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/qoutq-\$2.png -w \$WSIZE -h \$HSIZE -l 0 \ ";
$f[]=" -t \"Questions/outqueries per second\" \ ";
$f[]=" -v \"packets\" \ ";
$f[]=" DEF:questions=pdns_recursor.rrd:questions:AVERAGE \ ";
$f[]=" DEF:alloutqueries=pdns_recursor.rrd:all-outqueries:AVERAGE \ ";
$f[]=" LINE1:questions#ff0000:\"questions/s\"\ ";
$f[]=" LINE1:alloutqueries#00ff00:\"outqueries/s\" ";
$f[]="";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/qa-latency-\$2.png -w \$WSIZE -h \$HSIZE -l 0 \ ";
$f[]=" -t \"Questions/answer latency in milliseconds\" \ ";
$f[]=" -v \"msec\" \ ";
$f[]=" DEF:qalatency=pdns_recursor.rrd:qa-latency:AVERAGE \ ";
$f[]=" CDEF:mqalatency=qalatency,1000,/ \ ";
$f[]=" LINE1:mqalatency#ff0000:\"questions/s\" ";
$f[]="";
$f[]="";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/timeouts-\$2.png -w \$WSIZE -h \$HSIZE -l 0\ ";
$f[]=" -t \"Outqueries/timeouts per second\" \ ";
$f[]=" -v \"events\" \ ";
$f[]=" DEF:alloutqueries=pdns_recursor.rrd:all-outqueries:AVERAGE \ ";
$f[]=" DEF:outgoingtimeouts=pdns_recursor.rrd:outgoing-timeouts:AVERAGE \ ";
$f[]=" DEF:throttledout=pdns_recursor.rrd:throttled-out:AVERAGE \ ";
$f[]=" LINE1:alloutqueries#ff0000:\"outqueries/s\"\ ";
$f[]=" LINE1:outgoingtimeouts#00ff00:\"outgoing timeouts/s\"\ ";
$f[]=" LINE1:throttledout#0000ff:\"throttled outqueries/s\" ";
$f[]=" ";
$f[]="";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/caches-\$2.png -w \$WSIZE -h \$HSIZE -l 0\ ";
$f[]=" -t \"Cache sizes\" \ ";
$f[]=" -v \"entries\" \ ";
$f[]=" DEF:cacheentries=pdns_recursor.rrd:cache-entries:AVERAGE \ ";
$f[]=" DEF:packetcacheentries=pdns_recursor.rrd:packetcache-entries:AVERAGE \ ";
$f[]=" DEF:negcacheentries=pdns_recursor.rrd:negcache-entries:AVERAGE \ ";
$f[]=" DEF:nsspeedsentries=pdns_recursor.rrd:nsspeeds-entries:AVERAGE \ ";
$f[]=" DEF:throttleentries=pdns_recursor.rrd:throttle-entries:AVERAGE \ ";
$f[]=" LINE1:cacheentries#ff0000:\"cache entries\" \ ";
$f[]=" LINE1:packetcacheentries#ffff00:\"packet cache entries\" \ ";
$f[]=" LINE1:negcacheentries#0000ff:\"negative cache entries\" \ ";
$f[]=" LINE1:nsspeedsentries#00ff00:\"NS speeds entries\" \ ";
$f[]=" LINE1:throttleentries#00fff0:\"throttle map entries\" ";
$f[]=" ";
$f[]="";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/caches2-\$2.png -w \$WSIZE -h \$HSIZE -l 0\ ";
$f[]=" -t \"Cache sizes\" \ ";
$f[]=" -v \"entries\" \ ";
$f[]=" DEF:negcacheentries=pdns_recursor.rrd:negcache-entries:AVERAGE \ ";
$f[]=" DEF:nsspeedsentries=pdns_recursor.rrd:nsspeeds-entries:AVERAGE \ ";
$f[]=" DEF:throttleentries=pdns_recursor.rrd:throttle-entries:AVERAGE \ ";
$f[]=" LINE1:negcacheentries#0000ff:\"negative cache entries\" \ ";
$f[]=" LINE1:nsspeedsentries#00ff00:\"NS speeds entries\" \ ";
$f[]=" LINE1:throttleentries#ffa000:\"throttle map entries\" ";
$f[]="";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/load-\$2.png -w \$WSIZE -h \$HSIZE -l 0\ ";
$f[]=" -v \"MThreads\" \ ";
$f[]=" -t \"Concurrent queries\" \ ";
$f[]=" DEF:concurrentqueries=pdns_recursor.rrd:concurrent-queries:AVERAGE \ ";
$f[]=" LINE1:concurrentqueries#0000ff:\"concurrent queries\" ";
$f[]=" ";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/hitrate-\$2.png -w \$WSIZE -h \$HSIZE -l 0\ ";
$f[]=" -v \"percentage\" \ ";
$f[]=" -t \"cache hits\" \ ";
$f[]=" DEF:cachehits=pdns_recursor.rrd:cache-hits:AVERAGE \ ";
$f[]=" DEF:cachemisses=pdns_recursor.rrd:cache-misses:AVERAGE \ ";
$f[]=" DEF:packetcachehits=pdns_recursor.rrd:packetcache-hits:AVERAGE \ ";
$f[]=" DEF:packetcachemisses=pdns_recursor.rrd:packetcache-misses:AVERAGE \ ";
$f[]=" CDEF:perc=cachehits,100,*,cachehits,cachemisses,+,/ \ ";
$f[]=" CDEF:packetperc=packetcachehits,100,*,packetcachehits,packetcachemisses,+,/ \ ";
$f[]=" LINE1:perc#0000ff:\"percentage cache hits\" \ ";
$f[]=" LINE1:packetperc#ff00ff:\"percentage packetcache hits\" \ ";
$f[]=" COMMENT:\"\l\" \ ";
$f[]=" COMMENT:\"Cache hits \" \ ";
$f[]=" GPRINT:perc:AVERAGE:\"avg %-3.1lf%%\t\" \ ";
$f[]=" GPRINT:perc:LAST:\"last %-3.1lf%%\t\" \ ";
$f[]=" GPRINT:perc:MAX:\"max %-3.1lf%%\" \ ";
$f[]=" COMMENT:\"\l\" \ ";
$f[]=" COMMENT:\"Pkt hits \" \ ";
$f[]=" GPRINT:packetperc:AVERAGE:\"avg %-3.1lf%%\t\" \ ";
$f[]=" GPRINT:packetperc:LAST:\"last %-3.1lf%%\t\" \ ";
$f[]=" GPRINT:packetperc:MAX:\"max %-3.1lf%%\" \ ";
$f[]=" COMMENT:\"\l\" ";
$f[]="";
$f[]=" rrdtool graph \$GRAPHOPTS --start -\$1 \$WWWPREFIX/cpuload-\$2.png -w \$WSIZE -h \$HSIZE -l 0\ ";
$f[]=" -v \"percentage\" \ ";
$f[]=" -t \"cpu load\" \ ";
$f[]=" DEF:usermsec=pdns_recursor.rrd:user-msec:AVERAGE \ ";
$f[]=" DEF:sysmsec=pdns_recursor.rrd:sys-msec:AVERAGE \ ";
$f[]=" DEF:musermsec=pdns_recursor.rrd:user-msec:MAX \ ";
$f[]=" DEF:msysmsec=pdns_recursor.rrd:sys-msec:MAX \ ";
$f[]=" CDEF:userperc=usermsec,10,/ \ ";
$f[]=" CDEF:sysperc=sysmsec,10,/ \ ";
$f[]=" CDEF:totmperc=usermsec,sysmsec,+,10,/ \ ";
$f[]=" LINE1:totmperc#ffff00:\"max cpu use\" \ ";
$f[]=" AREA:userperc#ff0000:\"user cpu percentage\" \ ";
$f[]=" STACK:sysperc#00ff00:\"system cpu percentage\" \ ";
$f[]=" COMMENT:\"\l\" \ ";
$f[]=" COMMENT:\"System cpu \" \ ";
$f[]=" GPRINT:sysperc:AVERAGE:\"avg %-3.1lf%%\t\" \ ";
$f[]=" GPRINT:sysperc:LAST:\"last %-3.1lf%%\t\" \ ";
$f[]=" GPRINT:sysperc:MAX:\"max %-3.1lf%%\t\" \ ";
$f[]=" COMMENT:\"\l\" \ ";
$f[]=" COMMENT:\"User cpu \" \ ";
$f[]=" GPRINT:userperc:AVERAGE:\"avg %-3.1lf%%\t\" \ ";
$f[]=" GPRINT:userperc:LAST:\"last %-3.1lf%%\t\" \ ";
$f[]=" GPRINT:userperc:MAX:\"max %-3.1lf%%\" \ ";
$f[]=" COMMENT:\"\l\" ";
$f[]="";
$f[]="";
$f[]="}";
$f[]=" ";
$f[]="makeGraphs 6h 6h";
$f[]="makeGraphs 24h day";
$f[]="#makeGraphs 7d week";
$f[]="#makeGraphs 1m month";