|
22 | 22 | +-------------------------------------------------------------------------+ |
23 | 23 | */ |
24 | 24 |
|
| 25 | +use Symfony\Component\Validator\Constraints as Assert; |
| 26 | + |
25 | 27 | $dir = dir(CACTI_PATH_INCLUDE . '/themes/'); |
26 | 28 |
|
27 | 29 | // Work around issue where phpstan is not detecting globals |
|
184 | 186 | 'description' => __('The path to your snmpwalk binary.'), |
185 | 187 | 'method' => 'filepath', |
186 | 188 | 'file_type' => 'binary', |
187 | | - 'max_length' => '255' |
| 189 | + 'max_length' => '255', |
| 190 | + 'constraints' => [ |
| 191 | + new Assert\Length(min: 1, max: 255), |
| 192 | + ], |
188 | 193 | ], |
189 | 194 | 'path_snmpget' => [ |
190 | 195 | 'friendly_name' => __('snmpget Binary Path'), |
191 | 196 | 'description' => __('The path to your snmpget binary.'), |
192 | 197 | 'method' => 'filepath', |
193 | 198 | 'file_type' => 'binary', |
194 | | - 'max_length' => '255' |
| 199 | + 'max_length' => '255', |
| 200 | + 'constraints' => [ |
| 201 | + new Assert\Length(min: 1, max: 255), |
| 202 | + ], |
195 | 203 | ], |
196 | 204 | 'path_snmpbulkwalk' => [ |
197 | 205 | 'friendly_name' => __('snmpbulkwalk Binary Path'), |
|
219 | 227 | 'description' => __('The path to the rrdtool binary.'), |
220 | 228 | 'method' => 'filepath', |
221 | 229 | 'file_type' => 'binary', |
222 | | - 'max_length' => '255' |
| 230 | + 'max_length' => '255', |
| 231 | + 'constraints' => [ |
| 232 | + new Assert\NotBlank(), |
| 233 | + new Assert\Length(min: 1, max: 255), |
| 234 | + ], |
223 | 235 | ], |
224 | 236 | 'path_php_binary' => [ |
225 | 237 | 'friendly_name' => __('PHP Binary Path'), |
226 | 238 | 'description' => __('The path to your PHP binary file (may require a php recompile to get this file).'), |
227 | 239 | 'method' => 'filepath', |
228 | 240 | 'file_type' => 'binary', |
229 | | - 'max_length' => '255' |
| 241 | + 'max_length' => '255', |
| 242 | + 'constraints' => [ |
| 243 | + new Assert\NotBlank(), |
| 244 | + new Assert\Length(min: 1, max: 255), |
| 245 | + ], |
230 | 246 | ], |
231 | 247 | 'path_fping' => [ |
232 | 248 | 'friendly_name' => __('FPing Binary Path'), |
|
1001 | 1017 | 'method' => 'textbox', |
1002 | 1018 | 'default' => '500', |
1003 | 1019 | 'max_length' => '10', |
1004 | | - 'size' => '5' |
| 1020 | + 'size' => '5', |
| 1021 | + 'constraints' => [ |
| 1022 | + new Assert\Regex(pattern: '/^\d+$/', message: 'must be a positive integer (milliseconds).'), |
| 1023 | + new Assert\Range(min: 1, max: 600000), |
| 1024 | + ], |
1005 | 1025 | ], |
1006 | 1026 | 'snmp_retries' => [ |
1007 | 1027 | 'friendly_name' => __('Retries'), |
1008 | 1028 | 'description' => __('Default SNMP retries for all new Devices.'), |
1009 | 1029 | 'method' => 'textbox', |
1010 | 1030 | 'default' => '3', |
1011 | 1031 | 'max_length' => '10', |
1012 | | - 'size' => '5' |
| 1032 | + 'size' => '5', |
| 1033 | + 'constraints' => [ |
| 1034 | + new Assert\Regex(pattern: '/^\d+$/', message: 'must be a non-negative integer.'), |
| 1035 | + new Assert\Range(min: 0, max: 100), |
| 1036 | + ], |
1013 | 1037 | ], |
1014 | 1038 | 'snmp_bulk_walk_size' => [ |
1015 | 1039 | 'friendly_name' => __('Bulkwalk Fetch Size'), |
|
1388 | 1412 | 'default' => CACTI_PATH_CACHE . '/realtime/', |
1389 | 1413 | 'max_length' => 255, |
1390 | 1414 | 'size' => 40, |
| 1415 | + 'constraints' => [ |
| 1416 | + new Assert\NotBlank(), |
| 1417 | + new Assert\Regex(pattern: '#^([A-Za-z]:\\\\|/)#', message: 'must be an absolute path.'), |
| 1418 | + new Assert\Length(max: 255), |
| 1419 | + ], |
1391 | 1420 | ], |
1392 | 1421 | 'rrdtool_header' => [ |
1393 | 1422 | 'friendly_name' => __('RRDtool Graph Options'), |
|
1527 | 1556 | 'method' => 'drop_array', |
1528 | 1557 | 'default' => 300, |
1529 | 1558 | 'array' => $poller_intervals, |
| 1559 | + 'constraints' => [ |
| 1560 | + new Assert\Choice(choices: ['10', '15', '20', '30', '60', '300', 10, 15, 20, 30, 60, 300]), |
| 1561 | + ], |
1530 | 1562 | ], |
1531 | 1563 | 'cron_interval' => [ |
1532 | 1564 | 'friendly_name' => __('Cron/Daemon Interval'), |
1533 | 1565 | 'description' => __('The frequency that the Cacti data collector will be started. You can use either crontab, a scheduled task (for windows), or the cactid systemd service to control launching the Cacti data collector. For instructions on using the cactid daemon, review the README.md file in the service directory.'), |
1534 | 1566 | 'method' => 'drop_array', |
1535 | 1567 | 'default' => 300, |
1536 | 1568 | 'array' => $cron_intervals, |
| 1569 | + 'constraints' => [ |
| 1570 | + new Assert\Choice(choices: ['60', '300', 60, 300]), |
| 1571 | + ], |
1537 | 1572 | ], |
1538 | 1573 | 'process_leveling' => [ |
1539 | 1574 | 'friendly_name' => __('Balance Process Load'), |
|
2268 | 2303 | 'method' => 'textbox', |
2269 | 2304 | 'default' => 'localhost', |
2270 | 2305 | 'max_length' => 255, |
| 2306 | + 'constraints' => [ |
| 2307 | + new Assert\NotBlank(), |
| 2308 | + new Assert\Length(max: 255), |
| 2309 | + ], |
2271 | 2310 | ], |
2272 | 2311 | 'settings_smtp_port' => [ |
2273 | 2312 | 'friendly_name' => __('SMTP Port'), |
2274 | 2313 | 'description' => __('The port on the SMTP Server to use.'), |
2275 | 2314 | 'method' => 'textbox', |
2276 | 2315 | 'max_length' => 255, |
2277 | 2316 | 'default' => 25, |
2278 | | - 'size' => 5 |
| 2317 | + 'size' => 5, |
| 2318 | + 'constraints' => [ |
| 2319 | + new Assert\Regex(pattern: '/^\d+$/', message: 'must be a positive integer.'), |
| 2320 | + new Assert\Range(min: 1, max: 65535), |
| 2321 | + ], |
2279 | 2322 | ], |
2280 | 2323 | 'settings_smtp_username' => [ |
2281 | 2324 | 'friendly_name' => __('SMTP Username'), |
|
3130 | 3173 | 'description' => __('The default RRA to use in rare occasions.'), |
3131 | 3174 | 'method' => 'drop_sql', |
3132 | 3175 | 'sql' => 'SELECT id, name FROM data_source_profiles_rra ORDER BY steps', |
3133 | | - 'default' => '1' |
| 3176 | + 'default' => '1', |
| 3177 | + 'constraints' => [ |
| 3178 | + new Assert\Regex(pattern: '/^\d+$/', message: 'must be a positive integer id.'), |
| 3179 | + new Assert\Positive(), |
| 3180 | + ], |
3134 | 3181 | ], |
3135 | 3182 | 'default_timespan' => [ |
3136 | 3183 | 'friendly_name' => __('Default Timespan'), |
|
0 commit comments