summaryrefslogtreecommitdiffstats
path: root/inc/validator.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/validator.inc.php')
-rw-r--r--inc/validator.inc.php50
1 files changed, 35 insertions, 15 deletions
diff --git a/inc/validator.inc.php b/inc/validator.inc.php
index 88be14f2..944ac2ef 100644
--- a/inc/validator.inc.php
+++ b/inc/validator.inc.php
@@ -12,18 +12,20 @@ class Validator
public static function validate($condition, $value)
{
- if (empty($condition)) return $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 'list':
- return self::validateList($data[1], $value);
- case 'function':
- return self::$data[1]($value);
- default:
- Util::traceError('Unknown validation method: ' . $data[0]);
+ case 'regex':
+ if (preg_match($data[1], $value))
+ return $value;
+ return false;
+ case 'list':
+ return self::validateList($data[1], $value);
+ case 'function':
+ return self::$data[1]($value);
+ default:
+ Util::traceError('Unknown validation method: ' . $data[0]);
}
}
@@ -36,11 +38,29 @@ class Validator
*/
private static function linuxPassword($value)
{
- if (empty($value)) return '';
- if (preg_match('/^\$6\$.+\$./', $value)) return $value;
+ if (empty($value))
+ return '';
+ if (preg_match('/^\$6\$.+\$./', $value))
+ return $value;
return Crypto::hash6($value);
}
-
+
+ /**
+ * "Fix" network share path for SMB shares where a backslash
+ * is used instead of a slash.
+ * @param string $value network path
+ * @return string cleaned up path
+ */
+ private static function networkShare($value)
+ {
+ $value = trim($value);
+ if (substr($value, 0, 2) === '\\\\')
+ $value = str_replace('\\', '/', $value);
+ if (substr($value, 0, 2) === '//')
+ $value = str_replace(' ', '\\040', $value);
+ return $value;
+ }
+
/**
* Validate value against list.
* @param string $list The list as a string of items, separated by "|"
@@ -50,9 +70,9 @@ class Validator
private static function validateList($list, $value)
{
$list = explode('|', $list);
- if (in_array($value, $list)) return $value;
+ if (in_array($value, $list))
+ return $value;
return false;
}
}
-