You are here

function webfm_enum_validate in Web File Manager 5

Same name and namespace in other branches
  1. 5.2 webfm.module \webfm_enum_validate()
2 calls to webfm_enum_validate()
webfm_insert_file in ./webfm_file.inc
webfm_insert_file - inserts a file into the webfm_file table
webfm_rename in ./webfm_file.inc
webfm_rename -called from the ajax action - switch case 'rename':

File

./webfm.module, line 2693

Code

function webfm_enum_validate($file, &$err_msg) {
  global $user;
  $name = $file->filename ? $file->filename : strrev(substr(strrev($file->filepath), 0, strpos(strrev($file->filepath), '/')));
  if (strlen($name) > 255) {
    $err_msg[] = 'file name has invalid length';
    return FALSE;
  }
  if ($user->uid == 1 || user_access('administer webfm')) {
    return TRUE;
  }
  $webfm_access_roles = webfm_get_access_roles();
  $num_roles = 0;
  $error = 0;
  foreach ($user->roles as $rid => $role) {
    if (array_key_exists($rid, $webfm_access_roles)) {
      $num_roles++;

      //compare file to extension whitelist for each role with 'access webfm'
      $regex = webfm_get_extensions_regex($rid);
      if (!preg_match($regex, $name)) {
        $err_msg[] = $name . ' has invalid extension for ' . $role . ' role.';
        $error++;
      }
    }
  }
  return $error == $num_roles ? FALSE : TRUE;
}