]> git.proxmox.com Git - pmg-api.git/blame - PMG/Config.pm
add dummy class for new configuration file pmg.conf
[pmg-api.git] / PMG / Config.pm
CommitLineData
7e0e6dbe
DM
1package PMG::Config::Base;
2
3use strict;
4use warnings;
5use Data::Dumper;
6
7use PVE::Tools;
8use PVE::JSONSchema qw(get_standard_option);
9use PVE::SectionConfig;
10
11use base qw(PVE::SectionConfig);
12
13my $defaultData = {
14 propertyList => {
15 type => { description => "Section type." },
16 section_id => {
17 description => "Secion ID.",
18 type => 'string', format => 'pve-configid',
19 },
20 },
21};
22
23sub private {
24 return $defaultData;
25}
26
27sub format_section_header {
28 my ($class, $type, $sectionId) = @_;
29
30 if ($type eq 'ldap') {
31 $sectionId =~ s/^ldap_//;
32 return "$type: $sectionId\n";
33 } else {
34 return "section: $type\n";
35 }
36}
37
38
39sub parse_section_header {
40 my ($class, $line) = @_;
41
42 if ($line =~ m/^(ldap|section):\s*(\S+)\s*$/) {
43 my ($raw_type, $raw_id) = (lc($1), $2);
44 my $type = $raw_type eq 'section' ? $raw_id : $raw_type;
45 my $section_id = "${raw_type}_${raw_id}";
46 my $errmsg = undef; # set if you want to skip whole section
47 eval { PVE::JSONSchema::pve_verify_configid($raw_id); };
48 $errmsg = $@ if $@;
49 my $config = {}; # to return additional attributes
50 return ($type, $section_id, $errmsg, $config);
51 }
52 return undef;
53}
54
55package PMG::Config::Administration;
56
57use strict;
58use warnings;
59
60use base qw(PMG::Config::Base);
61
62sub type {
63 return 'administration';
64}
65
66sub properties {
67 return {
68 dailyreport => {
69 description => "Send daily reports.",
70 type => 'boolean',
71 default => 1,
72 },
73 };
74}
75
76sub options {
77 return {
78 dailyreport => { optional => 1 },
79 };
80}
81
82package PMG::Config::Spam;
83
84use strict;
85use warnings;
86
87use base qw(PMG::Config::Base);
88
89sub type {
90 return 'spam';
91}
92
93sub properties {
94 return {
95 bounce_score => {
96 description => "Additional score for bounce mails.",
97 type => 'integer',
98 minimum => 0,
99 maximum => 1000,
100 default => 0,
101 },
102 };
103}
104
105sub options {
106 return {
107 bounce_score => { optional => 1 },
108 };
109}
110
111package PMG::Config::LDAP;
112
113use strict;
114use warnings;
115
116use base qw(PMG::Config::Base);
117
118sub type {
119 return 'ldap';
120}
121
122sub properties {
123 return {
124 mode => {
125 description => "LDAP protocol mode ('ldap' or 'ldaps').",
126 type => 'string',
127 enum => ['ldap', 'ldaps'],
128 default => 'ldap',
129 },
130 };
131}
132
133sub options {
134 return {
135 mode => { optional => 1 },
136 };
137}
138
139package PMG::Config;
140
141use strict;
142use warnings;
143
144use Data::Dumper;
145
146use PVE::Tools;
147use PVE::INotify;
148
149PMG::Config::Administration->register();
150PMG::Config::Spam->register();
151PMG::Config::LDAP->register();
152
153# initialize all plugins
154PMG::Config::Base->init();
155
156#print Dumper(PMG::Config::Base->private());
157sub read_pmg_conf {
158 my ($filename, $fh) = @_;
159
160 local $/ = undef; # slurp mode
161
162 my $raw = <$fh>;
163
164 return PMG::Config::Base->parse_config($filename, $raw);
165}
166
167sub write_pmg_conf {
168 my ($filename, $fh, $cfg) = @_;
169
170 my $raw = PMG::Config::Base->write_config($filename, $cfg);
171
172 PVE::Tools::safe_print($filename, $fh, $raw);
173}
174
175PVE::INotify::register_file('pmg.conf', "/etc/proxmox/pmg.conf",
176 \&read_pmg_conf,
177 \&write_pmg_conf);
178
179
1801;