summaryrefslogtreecommitdiffstats
path: root/inc/validator.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2013-10-31 12:38:25 +0100
committerSimon Rettberg2013-10-31 12:38:25 +0100
commita362ac12b119b49519f5af51b92ebb7d6e127b87 (patch)
treea2334426c8af99f864e2dd90c2f275e3ed50083a /inc/validator.inc.php
parentRemodel zeug mit settings und so (diff)
downloadslx-admin-a362ac12b119b49519f5af51b92ebb7d6e127b87.tar.gz
slx-admin-a362ac12b119b49519f5af51b92ebb7d6e127b87.tar.xz
slx-admin-a362ac12b119b49519f5af51b92ebb7d6e127b87.zip
Comments, minor refactoring, possiblity to validate configuration parameters
Diffstat (limited to 'inc/validator.inc.php')
-rw-r--r--inc/validator.inc.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/inc/validator.inc.php b/inc/validator.inc.php
new file mode 100644
index 00000000..72b7fa0b
--- /dev/null
+++ b/inc/validator.inc.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * This class contains all the helper functions that
+ * can be referenced by a config setting. Every function
+ * here is supposed to validate the given config value
+ * and wither return the validated and possibly sanitized
+ * value, or false to indicate that the given value is invalid.
+ */
+class Validator
+{
+
+ public static function validate($condition, $value)
+ {
+ if (empty($condition)) return $value;
+ $data = explode(':', $condition, 2);
+ switch ($data[0]) {
+ case 'regex':
+ if (preg_match($data[1], $value)) return $value;
+ return false;
+ case 'function':
+ return self::$data[1]($value);
+ default:
+ Util::traceError('Unknown validation method: ' . $data[0]);
+ }
+ }
+
+ /**
+ * Validate linux password. If already in $6$ hash form,
+ * the unchanged value will be returned.
+ * if empty, an empty string will also be returned.
+ * Otherwise it it assumed that the value is a plain text
+ * password that is supposed to be hashed.
+ */
+ private static function linuxPassword($value)
+ {
+ if (empty($value)) return '';
+ if (preg_match('/^\$6\$.+\$./', $value)) return $value;
+ return Crypto::hash6($value);
+ }
+
+}
+