]>
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 | ||
139 | package PMG::Config; | |
140 | ||
141 | use strict; | |
142 | use warnings; | |
143 | ||
144 | use Data::Dumper; | |
145 | ||
146 | use PVE::Tools; | |
147 | use PVE::INotify; | |
148 | ||
149 | PMG::Config::Administration->register(); | |
150 | PMG::Config::Spam->register(); | |
151 | PMG::Config::LDAP->register(); | |
152 | ||
153 | # initialize all plugins | |
154 | PMG::Config::Base->init(); | |
155 | ||
156 | #print Dumper(PMG::Config::Base->private()); | |
157 | sub 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 | ||
167 | sub 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 | ||
175 | PVE::INotify::register_file('pmg.conf', "/etc/proxmox/pmg.conf", | |
176 | \&read_pmg_conf, | |
177 | \&write_pmg_conf); | |
178 | ||
179 | ||
180 | 1; |