Improved input validation.
| | |
| | | public function is_allowed_user($username, $restrict_names = false) { |
| | | global $app; |
| | | |
| | | if($username == 'root') return false; |
| | | $name_blacklist = array('root','ispconfig','vmail','getmail'); |
| | | if(in_array($username,$name_blacklist)) return false; |
| | | |
| | | if(preg_match('/^[\w\.\-]{0,32}$/', $username) == false) return false; |
| | | |
| | | if($restrict_names == true && preg_match('/^web\d+$/', $username) == false) return false; |
| | | |
| | | return true; |
| | |
| | | public function is_allowed_group($groupname, $restrict_names = false) { |
| | | global $app; |
| | | |
| | | if($groupname == 'root') return false; |
| | | $name_blacklist = array('root','ispconfig','vmail','getmail'); |
| | | if(in_array($groupname,$name_blacklist)) return false; |
| | | |
| | | if(preg_match('/^[\w\.\-]{0,32}$/', $groupname) == false) return false; |
| | | |
| | | if($restrict_names == true && preg_match('/^client\d+$/', $groupname) == false) return false; |
| | | |
| | | return true; |
| | |
| | | 'formtype' => 'TEXT', |
| | | 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', |
| | | 'errmsg'=> 'directory_error_empty'), |
| | | 1 => array ( 'type' => 'REGEX', |
| | | 'regex' => '/^\/[a-zA-Z0-9\ \.\-\_\/]{10,128}$/', |
| | | 'errmsg'=> 'directory_error_regex'), |
| | | ), |
| | | 'default' => '', |
| | | 'value' => '', |
| | |
| | | 'shell' => array ( |
| | | 'datatype' => 'VARCHAR', |
| | | 'formtype' => 'TEXT', |
| | | 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', |
| | | 'errmsg'=> 'shell_error_empty'), |
| | | 1 => array ( 'type' => 'REGEX', |
| | | 'regex' => '/^\/[a-zA-Z0-9\/]{5,20}$/', |
| | | 'errmsg'=> 'shell_error_regex'), |
| | | ), |
| | | 'default' => '/bin/bash', |
| | | 'value' => '', |
| | | 'width' => '30', |
| | |
| | | 'formtype' => 'TEXT', |
| | | 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', |
| | | 'errmsg'=> 'directory_error_empty'), |
| | | 1 => array ( 'type' => 'REGEX', |
| | | 'regex' => '/^\/[a-zA-Z0-9\ \.\-\_\/]{10,128}$/', |
| | | 'errmsg'=> 'directory_error_regex'), |
| | | ), |
| | | 'default' => '', |
| | | 'value' => '', |
| | |
| | | $uid = $app->db->quote($web["system_user"]); |
| | | $gid = $app->db->quote($web["system_group"]); |
| | | |
| | | // Check system user and group |
| | | if($app->functions->is_allowed_user($uid) == false || $app->functions->is_allowed_group($gid) == false) { |
| | | $app->error('Invalid system user or group'); |
| | | } |
| | | |
| | | // The FTP user shall be owned by the same group then the website |
| | | $sys_groupid = $app->functions->intval($web['sys_groupid']); |
| | | |
| | |
| | | function onBeforeUpdate() { |
| | | global $app, $conf, $interfaceConf; |
| | | |
| | | |
| | | // Check system user and group |
| | | if(isset($this->dataRecord['uid'])) { |
| | | if($app->functions->is_allowed_user(strtolower($this->dataRecord['uid']),true) == false || $app->functions->is_allowed_group(strtolower($this->dataRecord['gid']),true) == false) { |
| | | $app->tform->errorMessage .= $app->tform->lng('invalid_system_user_or_group_txt'); |
| | | } |
| | | } |
| | | |
| | | /* |
| | | * If the names should be restricted -> do it! |
| | | */ |
| | |
| | | $wb['repeat_password_txt'] = 'Repeat Password'; |
| | | $wb['password_mismatch_txt'] = 'The passwords do not match.'; |
| | | $wb['password_match_txt'] = 'The passwords do match.'; |
| | | $wb['invalid_system_user_or_group_txt'] = 'Invalid system user or group'; |
| | | $wb['directory_error_regex'] = 'Invalid directory'; |
| | | ?> |
| | |
| | | $wb['password_match_txt'] = 'The passwords do match.'; |
| | | $wb['username_must_not_exceed_32_chars_txt'] = 'The username must not exceed 32 characters.'; |
| | | $wb['username_not_allowed_txt'] = 'The username is not allowed.'; |
| | | $wb['invalid_system_user_or_group_txt'] = 'Invalid system user or group'; |
| | | $wb['directory_error_regex'] = 'Invalid directory'; |
| | | $wb['shell_error_regex'] = 'Invalid shell'; |
| | | ?> |
| | |
| | | } |
| | | unset($blacklist); |
| | | |
| | | if($app->functions->is_allowed_user(trim(strtolower($this->dataRecord['username']))) == false) $app->tform->errorMessage .= $app->tform->lng('username_not_allowed_txt'); |
| | | |
| | | /* |
| | | * If the names should be restricted -> do it! |
| | | */ |
| | |
| | | $uid = $app->db->quote($web["system_user"]); |
| | | $gid = $app->db->quote($web["system_group"]); |
| | | |
| | | // Check system user and group |
| | | if($app->functions->is_allowed_user($uid) == false || $app->functions->is_allowed_group($gid) == false) { |
| | | $app->error($app->tform->lng('invalid_system_user_or_group_txt')); |
| | | } |
| | | |
| | | // The FTP user shall be owned by the same group then the website |
| | | $sys_groupid = $app->functions->intval($web['sys_groupid']); |
| | | |
| | |
| | | } |
| | | unset($blacklist); |
| | | |
| | | // Check system user and group |
| | | if(isset($this->dataRecord['puser'])) { |
| | | if($app->functions->is_allowed_user(strtolower($this->dataRecord['puser']),true) == false || $app->functions->is_allowed_group(strtolower($this->dataRecord['pgroup']),true) == false) { |
| | | $app->tform->errorMessage .= $app->tform->lng('invalid_system_user_or_group_txt'); |
| | | } |
| | | } |
| | | |
| | | /* |
| | | * If the names should be restricted -> do it! |
| | | */ |
| | |
| | | public function is_allowed_user($username, $check_id = true, $restrict_names = false) { |
| | | global $app; |
| | | |
| | | if($username == 'root') return false; |
| | | $name_blacklist = array('root','ispconfig','vmail','getmail'); |
| | | if(in_array($username,$name_blacklist)) return false; |
| | | |
| | | if(preg_match('/^[\w\.\-]{0,32}$/', $username) == false) return false; |
| | | |
| | | if($check_id && intval($this->getuid($username)) < $this->min_uid) return false; |
| | | |
| | | if($restrict_names == true && preg_match('/^web\d+$/', $username) == false) return false; |
| | |
| | | public function is_allowed_group($groupname, $restrict_names = false) { |
| | | global $app; |
| | | |
| | | if($groupname == 'root') return false; |
| | | $name_blacklist = array('root','ispconfig','vmail','getmail'); |
| | | if(in_array($groupname,$name_blacklist)) return false; |
| | | |
| | | if(preg_match('/^[\w\.\-]{0,32}$/', $groupname) == false) return false; |
| | | |
| | | if(intval($this->getgid($groupname)) < $this->min_gid) return false; |
| | | |
| | | if($restrict_names == true && preg_match('/^client\d+$/', $groupname) == false) return false; |