]>
Commit | Line | Data |
---|---|---|
7e0e6dbe DM |
1 | package PMG::Config::Base; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use Data::Dumper; | |
6 | ||
7 | use PVE::Tools; | |
8 | use PVE::JSONSchema qw(get_standard_option); | |
9 | use PVE::SectionConfig; | |
10 | ||
11 | use base qw(PVE::SectionConfig); | |
12 | ||
13 | my $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 | ||
23 | sub private { | |
24 | return $defaultData; | |
25 | } | |
26 | ||
27 | sub 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 | ||
39 | sub 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 | ||
55 | package PMG::Config::Administration; | |
56 | ||
57 | use strict; | |
58 | use warnings; | |
59 | ||
60 | use base qw(PMG::Config::Base); | |
61 | ||
62 | sub type { | |
63 | return 'administration'; | |
64 | } | |
65 | ||
66 | sub properties { | |
67 | return { | |
68 | dailyreport => { | |
69 | description => "Send daily reports.", | |
70 | type => 'boolean', | |
71 | default => 1, | |
72 | }, | |
73 | }; | |
74 | } | |
75 | ||
76 | sub options { | |
77 | return { | |
78 | dailyreport => { optional => 1 }, | |
79 | }; | |
80 | } | |
81 | ||
82 | package PMG::Config::Spam; | |
83 | ||
84 | use strict; | |
85 | use warnings; | |
86 | ||
87 | use base qw(PMG::Config::Base); | |
88 | ||
89 | sub type { | |
90 | return 'spam'; | |
91 | } | |
92 | ||
93 | sub 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 | ||
105 | sub options { | |
106 | return { | |
107 | bounce_score => { optional => 1 }, | |
108 | }; | |
109 | } | |
110 | ||
111 | package PMG::Config::LDAP; | |
112 | ||
113 | use strict; | |
114 | use warnings; | |
115 | ||
116 | use base qw(PMG::Config::Base); | |
117 | ||
118 | sub type { | |
119 | return 'ldap'; | |
120 | } | |
121 | ||
122 | sub 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 | ||
133 | sub options { | |
134 | return { | |
135 | mode => { optional => 1 }, | |
136 | }; | |
137 | } | |
138 | ||
d9dc3c08 DM |
139 | package PMG::Config::Mail; |
140 | ||
141 | use strict; | |
142 | use warnings; | |
143 | ||
144 | use base qw(PMG::Config::Base); | |
145 | ||
146 | sub type { | |
147 | return 'mail'; | |
148 | } | |
149 | ||
150 | sub properties { | |
151 | return { | |
152 | banner => { | |
153 | description => "ESMTP banner.", | |
154 | type => 'string', | |
155 | maxLength => 1024, | |
156 | default => 'ESMTP Proxmox', | |
157 | }, | |
158 | }; | |
159 | } | |
160 | ||
161 | sub options { | |
162 | return { | |
163 | banner => { optional => 1 }, | |
164 | }; | |
165 | } | |
7e0e6dbe DM |
166 | package PMG::Config; |
167 | ||
168 | use strict; | |
169 | use warnings; | |
170 | ||
171 | use Data::Dumper; | |
172 | ||
173 | use PVE::Tools; | |
174 | use PVE::INotify; | |
175 | ||
176 | PMG::Config::Administration->register(); | |
d9dc3c08 | 177 | PMG::Config::Mail->register(); |
7e0e6dbe DM |
178 | PMG::Config::Spam->register(); |
179 | PMG::Config::LDAP->register(); | |
180 | ||
181 | # initialize all plugins | |
182 | PMG::Config::Base->init(); | |
183 | ||
184 | #print Dumper(PMG::Config::Base->private()); | |
185 | sub read_pmg_conf { | |
186 | my ($filename, $fh) = @_; | |
187 | ||
188 | local $/ = undef; # slurp mode | |
189 | ||
190 | my $raw = <$fh>; | |
191 | ||
192 | return PMG::Config::Base->parse_config($filename, $raw); | |
193 | } | |
194 | ||
195 | sub write_pmg_conf { | |
196 | my ($filename, $fh, $cfg) = @_; | |
197 | ||
198 | my $raw = PMG::Config::Base->write_config($filename, $cfg); | |
199 | ||
200 | PVE::Tools::safe_print($filename, $fh, $raw); | |
201 | } | |
202 | ||
203 | PVE::INotify::register_file('pmg.conf', "/etc/proxmox/pmg.conf", | |
204 | \&read_pmg_conf, | |
205 | \&write_pmg_conf); | |
206 | ||
207 | ||
208 | 1; |