You are here

function hosting_client_sanitize in Hostmaster (Aegir) 6

Return a machine-usable name for a client.

This aims to be usable for unix group/user names and shells.

It adds a prefix configured in the frontend settings (defaulting to 'cl-'), and strips the total length of the string (including the prefix) to MAX_GROUP_LENGTH.

This can also be used to validate user-provided client unames, as it strips and readds the prefix and performs the same validation and corrections on the field.

This is inspired from the context sanitization stuff.

See also

MAX_GROUP_LENGTH

5 calls to hosting_client_sanitize()
hosting_client_insert in modules/hosting/client/hosting_client.module
Implementation of hook_insert().
hosting_client_update in modules/hosting/client/hosting_client.module
Implementation of hook_update().
hosting_client_update_6000 in modules/hosting/client/hosting_client.install
Cleanup the hosting_client fields
hosting_client_validate in modules/hosting/client/hosting_client.module
Implementation of hook_validate() .
hosting_client_validate_suggest in modules/hosting/client/hosting_client.module
Helper for hosting_client_validate to suggest a new client title.

File

modules/hosting/client/hosting_client.module, line 972

Code

function hosting_client_sanitize($title) {
  $prefix = variable_get('hosting_client_prefix', '');

  // remove anything but "word characters", dots and dashes
  // remove the prefix in case we are validating an existing uname
  // TODO: optimize in one call
  $title = preg_replace("/[!\\W\\.\\-]/", "", preg_replace("/^{$prefix}/", "", $title));
  return substr(strtolower($prefix . $title), 0, MAX_GROUP_LENGTH);
}