Skip to content

Commit

Permalink
i18n: Translate core plugins!
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Hancock committed Apr 2, 2015
1 parent f581f5f commit 47ae22e
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 87 deletions.
18 changes: 16 additions & 2 deletions auth-ldap/authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,24 @@ function lookupAndSync($username, $dn) {
class StaffLDAPAuthentication extends StaffAuthenticationBackend
implements AuthDirectorySearch {

static $name = "Active Directory or LDAP";
static $name = /* trans */ "Active Directory or LDAP";
static $id = "ldap";

function __construct($config) {
$this->_ldap = new LDAPAuthentication($config);
$this->config = $config;
}

function authenticate($username, $password=false, $errors=array()) {
return $this->_ldap->authenticate($username, $password);
}

function getName() {
$config = $this->config;
list($__, $_N) = $config::translate();
return $__(static::$name);
}

function lookup($dn) {
$hit = $this->_ldap->lookup($dn);
if ($hit) {
Expand All @@ -439,15 +446,22 @@ function search($query) {
}

class ClientLDAPAuthentication extends UserAuthenticationBackend {
static $name = "Active Directory or LDAP";
static $name = /* trans */ "Active Directory or LDAP";
static $id = "ldap.client";

function __construct($config) {
$this->_ldap = new LDAPAuthentication($config, 'client');
$this->config = $config;
if ($domain = $config->get('domain'))
self::$name .= sprintf(' (%s)', $domain);
}

function getName() {
$config = $this->config;
list($__, $_N) = $config::translate();
return $__(static::$name);
}

function authenticate($username, $password=false, $errors=array()) {
$object = $this->_ldap->authenticate($username, $password);
if ($object instanceof ClientCreateRequest)
Expand Down
116 changes: 66 additions & 50 deletions auth-ldap/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,142 +3,157 @@
require_once(INCLUDE_DIR.'/class.plugin.php');
require_once(INCLUDE_DIR.'/class.forms.php');


class LdapConfig extends PluginConfig {

// Provide compatibility function for versions of osTicket prior to
// translation support (v1.9.4)
function translate() {
if (!method_exists('Plugin', 'translate')) {
return array(
function($x) { return $x; },
function($x, $y, $n) { return $n != 1 ? $y : $x; },
);
}
return Plugin::translate('auth-ldap');
}

function getOptions() {
list($__, $_N) = self::translate();
return array(
'msad' => new SectionBreakField(array(
'label' => 'Microsoft® Active Directory',
'hint' => 'This section should be complete for Active
Directory domains',
'hint' => $__('This section should be all that is required for Active Directory domains'),
)),
'domain' => new TextboxField(array(
'label' => 'Default Domain',
'hint' => 'Default domain used in authentication and searches',
'label' => $__('Default Domain'),
'hint' => $__('Default domain used in authentication and searches'),
'configuration' => array('size'=>40, 'length'=>60),
'validators' => array(
function($self, $val) {
if (strpos($val, '.') === false)
$self->addError(
'Fully-qualified domain name is expected');
$__('Fully-qualified domain name is expected'));
}),
)),
'dns' => new TextboxField(array(
'label' => 'DNS Servers',
'hint' => '(optional) DNS servers to query about AD servers.
'label' => $__('DNS Servers'),
'hint' => $__('(optional) DNS servers to query about AD servers.
Useful if the AD server is not on the same network as
this web server or does not have its DNS configured to
point to the AD servers',
point to the AD servers'),
'configuration' => array('size'=>40),
'validators' => array(
function($self, $val) {
if (!$val) return;
$servers = explode(',', $val);
foreach ($servers as $s) {
if (!Validator::is_ip(trim($s)))
$self->addError($s.': Expected an IP address');
$self->addError(sprintf(
$__('%s: Expected an IP address', $s)));
}
}),
)),

'ldap' => new SectionBreakField(array(
'label' => 'Generic configuration for LDAP',
'hint' => 'Not necessary if Active Directory is configured above',
'label' => $__('Generic configuration for LDAP'),
'hint' => $__('Not necessary if Active Directory is configured above'),
)),
'servers' => new TextareaField(array(
'id' => 'servers',
'label' => 'LDAP servers',
'label' => $__('LDAP servers'),
'configuration' => array('html'=>false, 'rows'=>2, 'cols'=>40),
'hint' => 'Use "server" or "server:port". Place one server '
.'entry per line',
'hint' => $__('Use "server" or "server:port". Place one server entry per line'),
)),
'tls' => new BooleanField(array(
'id' => 'tls',
'label' => 'Use TLS',
'label' => $__('Use TLS'),
'configuration' => array(
'desc' => 'Use TLS to communicate with the LDAP server')
'desc' => $__('Use TLS to communicate with the LDAP server'))
)),

'conn_info' => new SectionBreakField(array(
'label' => 'Connection Information',
'hint' => 'Useful only for information lookups. Not
'label' => $__('Connection Information'),
'hint' => $__('Useful only for information lookups. Not
necessary for authentication. NOTE that this data is not
necessary if your server allows anonymous searches'
necessary if your server allows anonymous searches')
)),
'bind_dn' => new TextboxField(array(
'label' => 'Search User',
'hint' => 'Bind DN (distinguised name) to bind to the LDAP
server as in order to perform searches',
'label' => $__('Search User'),
'hint' => $__('Bind DN (distinguised name) to bind to the LDAP
server as in order to perform searches'),
'configuration' => array('size'=>40, 'length'=>120),
)),
'bind_pw' => new TextboxField(array(
'widget' => 'PasswordWidget',
'label' => 'Password',
'hint' => "Password associated with the DN's account",
'label' => $__('Password'),
'hint' => $__("Password associated with the DN's account"),
'configuration' => array('size'=>40),
)),
'search_base' => new TextboxField(array(
'label' => 'Search Base',
'hint' => 'Used when searching for users',
'label' => $__('Search Base'),
'hint' => $__('Used when searching for users'),
'configuration' => array('size'=>70, 'length'=>120),
)),
'schema' => new ChoiceField(array(
'label' => 'LDAP Schema',
'hint' => 'Layout of the user data in the LDAP server',
'label' => $__('LDAP Schema'),
'hint' => $__('Layout of the user data in the LDAP server'),
'default' => 'auto',
'choices' => array(
'auto' => '-- Automatically Detect --',
'msad' => 'Microsoft Active Directory',
'2307' => 'Posix Account',
'auto' => ''.$__('Automatically Detect').'',
'msad' => 'Microsoft® Active Directory',
'2307' => 'Posix Account (rfc 2307)',
),
)),

'auth' => new SectionBreakField(array(
'label' => 'Authentication Modes',
'hint' => 'Accounts must be created locally for both clients and staff before they can be authenticated',
'hint' => 'Authentication modes for clients and staff
members can be enabled independently',
'label' => $__('Authentication Modes'),
'hint' => $__('Authentication modes for clients and staff
members can be enabled independently'),
)),
'auth-staff' => new BooleanField(array(
'label' => 'Staff Authentication',
'label' => $__('Staff Authentication'),
'default' => true,
'configuration' => array(
'desc' => 'Enable authentication of staff members'
'desc' => $__('Enable authentication of staff members')
)
)),
'auth-client' => new BooleanField(array(
'label' => 'Client Authentication',
'label' => $__('Client Authentication'),
'default' => false,
'configuration' => array(
'desc' => 'Enable authentication of clients'
'desc' => $__('Enable authentication of clients')
)
)),
);
}

function pre_save(&$config, &$errors) {
require_once('include/Net/LDAP2.php');
list($__, $_N) = self::translate();

global $ost;
if ($ost && !extension_loaded('ldap')) {
$ost->setWarning('LDAP extension is not available');
$errors['err'] = 'LDAP extension is not available. Please
install or enable the `php-ldap` extension on your web server';
$ost->setWarning($__('LDAP extension is not available'));
$errors['err'] = $__('LDAP extension is not available. Please
install or enable the `php-ldap` extension on your web
server');
return;
}

if ($config['domain'] && !$config['servers']) {
if (!($servers = LDAPAuthentication::autodiscover($config['domain'],
preg_split('/,?\s+/', $config['dns']))))
$this->getForm()->getField('servers')->addError(
"Unable to find LDAP servers for this domain. Try giving
$__("Unable to find LDAP servers for this domain. Try giving
an address of one of the DNS servers or manually specify
the LDAP servers for this domain below.");
the LDAP servers for this domain below."));
}
else {
if (!$config['servers'])
$this->getForm()->getField('servers')->addError(
"No servers specified. Either specify a Active Directory
domain or a list of servers");
$__("No servers specified. Either specify a Active Directory
domain or a list of servers"));
else {
$servers = array();
foreach (preg_split('/\s+/', $config['servers']) as $host)
Expand Down Expand Up @@ -179,8 +194,9 @@ function pre_save(&$config, &$errors) {
}
}
if (PEAR::isError($r)) {
$connection_error =
$r->getMessage() .': Unable to bind to '.$info['host'];
$connection_error = sprintf($__(
'%s: Unable to bind to server %s'),
$r->getMessage(), $info['host']);
}
else {
$connection_error = false;
Expand All @@ -189,7 +205,7 @@ function pre_save(&$config, &$errors) {
}
if ($connection_error) {
$this->getForm()->getField('servers')->addError($connection_error);
$errors['err'] = 'Unable to connect any listed LDAP servers';
$errors['err'] = $__('Unable to connect any listed LDAP servers');
}

if (!$errors && $config['bind_pw'])
Expand All @@ -200,7 +216,7 @@ function pre_save(&$config, &$errors) {

global $msg;
if (!$errors)
$msg = 'LDAP configuration updated successfully';
$msg = $__('LDAP configuration updated successfully');

return !$errors;
}
Expand Down
30 changes: 22 additions & 8 deletions auth-oauth/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,40 @@
require_once INCLUDE_DIR . 'class.plugin.php';

class OauthPluginConfig extends PluginConfig {

// Provide compatibility function for versions of osTicket prior to
// translation support (v1.9.4)
function translate() {
if (!method_exists('Plugin', 'translate')) {
return array(
function($x) { return $x; },
function($x, $y, $n) { return $n != 1 ? $y : $x; },
);
}
return Plugin::translate('auth-oauth');
}

function getOptions() {
list($__, $_N) = self::translate();
$modes = new ChoiceField(array(
'label' => 'Authenticate',
'label' => $__('Authentication'),
'choices' => array(
'0' => 'Disabled',
'staff' => 'Agents Only',
'client' => 'Clients Only',
'all' => 'Agents and Clients',
'0' => $__('Disabled'),
'staff' => $__('Agents Only'),
'client' => $__('Clients Only'),
'all' => $__('Agents and Clients'),
),
));
return array(
'google' => new SectionBreakField(array(
'label' => 'Google+ Authentication',
'label' => $__('Google+ Authentication'),
)),
'g-client-id' => new TextboxField(array(
'label' => 'Client ID',
'label' => $__('Client ID'),
'configuration' => array('size'=>60, 'length'=>100),
)),
'g-client-secret' => new TextboxField(array(
'label' => 'Client Secret',
'label' => $__('Client Secret'),
'configuration' => array('size'=>60, 'length'=>100),
)),
'g-enabled' => clone $modes,
Expand Down
Loading

0 comments on commit 47ae22e

Please sign in to comment.