Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions auth/services_keyauth/services_keyauth.admin.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
// $Id: services_keyauth.admin.inc,v 1.1.2.2.2.2 2009/08/08 02:55:05 marcingy Exp $
// $Id: services_keyauth.admin.inc,v 1.1.2.2.2.4 2009/12/03 05:59:35 heyrocker Exp $

/**
* @file
Expand Down Expand Up @@ -78,10 +78,10 @@ function services_keyauth_admin_keys_form() {
'#description' => t('External domain allowed to use this key.'),
'#required' => TRUE,
);

$methods = services_get_all();
foreach ($methods as $method) {
$form_methods[$method['#method']] = $method['#method'];
$form_methods[$method['method']] = $method['method'];
}

$form['method_access'] = array(
Expand Down Expand Up @@ -128,7 +128,7 @@ function services_keyauth_admin_keys_save(&$key) {
db_query("INSERT INTO {services_key_permissions} (kid, method) VALUES ('%s', '%s')", $key['kid'], $value);
}
}
return $return;
return $return;
}

function services_keyauth_admin_keys_delete($kid) {
Expand Down
96 changes: 47 additions & 49 deletions auth/services_keyauth/services_keyauth.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
// $Id: services_keyauth.inc,v 1.1.2.8.2.3 2009/09/05 13:57:58 marcingy Exp $
// $Id: services_keyauth.inc,v 1.1.2.8.2.10 2009/12/11 14:32:42 heyrocker Exp $

/**
* @file
Expand All @@ -11,7 +11,7 @@ function _services_keyauth_security_settings() {
'#type' => 'checkbox',
'#title' => t('Use keys'),
'#default_value' => variable_get('services_use_key', TRUE),
'#description' => t('When enabled all method calls need to provide a validation token to autheciate themselves with the server.'),
'#description' => t('When enabled all method calls need to provide a validation token to authenticate themselves with the server.'),
);
$form['services_key_expiry'] = array(
'#type' => 'textfield',
Expand All @@ -25,7 +25,7 @@ function _services_keyauth_security_settings() {
'#type' => 'checkbox',
'#title' => t('Use sessid'),
'#default_value' => variable_get('services_use_sessid', TRUE),
'#description' => t('When enabled, all method calls must include a valid sessid. Only disable this setting if the application will user browser-based cookies.')
'#description' => t('When enabled, all method calls must include a valid sessid. Only disable this setting if the application will use browser-based cookies.')
);
return $form;
}
Expand All @@ -51,76 +51,74 @@ function _services_keyauth_alter_methods(&$methods) {

// sessid arg
$arg_sessid = array(
'#name' => 'sessid',
'#type' => 'string',
'#description' => t('A valid sessid.'),
'name' => 'sessid',
'type' => 'string',
'description' => t('A valid sessid.'),
);

$arg_domain_time_stamp = array(
'#name' => 'domain_time_stamp',
'#type' => 'string',
'#description' => t('Time stamp used to hash key.'),
'name' => 'domain_time_stamp',
'type' => 'string',
'description' => t('Time stamp used to hash key.'),
);

$arg_nonce = array(
'#name' => 'nonce',
'#type' => 'string',
'#description' => t('One time use nonce also used hash key.'),
'name' => 'nonce',
'type' => 'string',
'description' => t('One time use nonce also used hash key.'),
);

// domain arg
$arg_domain_name = array(
'#name' => 'domain_name',
'#type' => 'string',
'#description' => t('A valid domain for the API key.'),
'name' => 'domain_name',
'type' => 'string',
'description' => t('A valid domain for the API key.'),
);

// api_key arg
$arg_api_key = array(
'#name' => 'hash',
'#type' => 'string',
'#description' => t('A valid API key.'),
'name' => 'hash',
'type' => 'string',
'description' => t('A valid API key.'),
);

foreach ($methods as $key => &$method) {
// set method defaults
switch ($method['#method']) {
switch ($method['method']) {
case 'system.connect':
case 'search.nodes':
case 'search.content':
case 'search.users':
$method['#key'] = FALSE;
$method['#auth'] = FALSE;
$method['key'] = FALSE;
$method['auth'] = FALSE;
break;
default:
$method['#key'] = TRUE;
$method['#auth'] = TRUE;
$method['key'] = isset($method['key']) ? FALSE : TRUE;
$method['auth'] = isset($method['auth']) ? FALSE : TRUE;
break;
}
if ($method['#auth'] && variable_get('services_use_sessid', TRUE)) {
array_unshift($method['#args'], $arg_sessid);

if ($method['auth'] && variable_get('services_use_sessid', TRUE)) {
array_unshift($method['args'], $arg_sessid);
}

if ($method['#key'] && variable_get('services_use_key', TRUE)) {
array_unshift($method['#args'], $arg_nonce);
array_unshift($method['#args'], $arg_domain_time_stamp);
array_unshift($method['#args'], $arg_domain_name);
array_unshift($method['#args'], $arg_api_key);
if ($method['key'] && variable_get('services_use_key', TRUE)) {
array_unshift($method['args'], $arg_nonce);
array_unshift($method['args'], $arg_domain_time_stamp);
array_unshift($method['args'], $arg_domain_name);
array_unshift($method['args'], $arg_api_key);
}
}
}

function _services_keyauth_alter_browse_form(&$form, $method) {

foreach ($method['#args'] as $key => $arg) {
switch ($arg['#name']) {
foreach ($method['args'] as $key => $arg) {
switch ($arg['name']) {
case 'hash':
$form['arg'][$key] = array(
'#title' => 'Hash',
'#type' => 'textfield',
'#value' => t('Gets generated after form submission'),
'#disabled' => TRUE
);
);
break;
case 'sessid':
$form['arg'][$key]['#default_value'] = session_id();
Expand All @@ -130,11 +128,11 @@ function _services_keyauth_alter_browse_form(&$form, $method) {
break;
case 'domain_time_stamp':
$form['arg'][$key] = array(
'#title' => 'Timestamp',
'#type' => 'textfield',
'#value' => t('Gets generated after form submission'),
'#disabled' => TRUE
);
'#title' => 'Timestamp',
'#type' => 'textfield',
'#value' => t('Gets generated after form submission'),
'#disabled' => TRUE
);
break;
case 'nonce':
$form['arg'][$key]['#default_value'] = user_password();
Expand All @@ -144,7 +142,7 @@ function _services_keyauth_alter_browse_form(&$form, $method) {
}

function _services_keyauth_authenticate_call($method, $method_name, &$args) {
if ($method['#key'] && variable_get('services_use_key', TRUE)) {
if ($method['key'] && variable_get('services_use_key', TRUE)) {
$hash = array_shift($args);
$domain = array_shift($args);
$timestamp = array_shift($args);
Expand All @@ -160,7 +158,7 @@ function _services_keyauth_authenticate_call($method, $method_name, &$args) {
if (db_result(db_query("SELECT count(*) FROM {services_timestamp_nonce}
WHERE domain = '%s' AND nonce = '%s'",
$domain, $nonce))) {
return services_error(t('Token has been used previously for a request. Re-try with another nonce key.', 401));
return services_error(t('Token has been used previously for a request. Re-try with another nonce key.'), 401);
}
else{
db_query("INSERT INTO {services_timestamp_nonce} (domain, timestamp, nonce)
Expand All @@ -173,16 +171,16 @@ function _services_keyauth_authenticate_call($method, $method_name, &$args) {
if ($hash != services_get_hash($timestamp, $domain, $nonce, $method, $args)) {
return services_error(t('Invalid API key.'), 401);
}
if (!db_result(db_query("SELECT COUNT(*) FROM {services_key_permissions}

if (!db_result(db_query("SELECT COUNT(*) FROM {services_key_permissions}
WHERE kid = '%s' AND method = '%s'", $api_key, $method_name))) {
return services_error(t('Access denied.'), 401);
}
}

// Add additonal processing for methods requiring session
$session_backup = NULL;
if ($method['#auth'] && variable_get('services_use_sessid', TRUE)) {
if ($method['auth'] && variable_get('services_use_sessid', TRUE)) {
$sessid = array_shift($args);
if (empty($sessid)) {
return t('Invalid sessid.');
Expand All @@ -192,9 +190,9 @@ function _services_keyauth_authenticate_call($method, $method_name, &$args) {
}

function _services_keyauth_alter_browse_form_submit($method, &$args) {
if ($method['#key'] && variable_get('services_use_key', TRUE)) {
if ($method['key'] && variable_get('services_use_key', TRUE)) {
$args_stripped = $args;

for ($i = 1; $i <= 4; $i++) {
array_shift($args_stripped);
}
Expand Down
13 changes: 7 additions & 6 deletions auth/services_keyauth/services_keyauth.install
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
// $Id: services_keyauth.install,v 1.1.2.4.2.2 2009/06/20 19:48:42 marcingy Exp $
// $Id: services_keyauth.install,v 1.1.2.4.2.4 2009/12/05 01:42:38 heyrocker Exp $

/**
* @author Services Dev Team
* @file
* Install, uninstall and update the module.
*/

/**
* Implementation of hook_schema().
*/
Expand Down Expand Up @@ -88,12 +89,12 @@ function services_keyauth_schema() {
'api_key' => array('kid'),
'method' => array('method'),
),
'unique key' => array('key_method' => array('kid','method')),
'unique key' => array('key_method' => array('kid', 'method')),
);
return $schema;
}

function _services_key_auth_permissions (&$update) {
function _services_key_auth_permissions(&$update) {
$schema['services_key_permissions'] = array(
'description' => t('Stores services method\'s access rights on a per API key basis.'),
'fields' => array(
Expand All @@ -116,7 +117,7 @@ function _services_key_auth_permissions (&$update) {
'api_key' => array('kid'),
'method' => array('method'),
),
'unique key' => array('key_method' => array('kid','method')),
'unique key' => array('key_method' => array('kid', 'method')),
);
db_create_table($update, 'services_key_permissions', $schema['services_key_permissions']);

Expand Down Expand Up @@ -178,7 +179,7 @@ function services_keyauth_update_6004() {

function services_keyauth_update_6005() {
$update = array();

// A table might fail to exist in certain circumstances due to an issue with the install.
if (!db_table_exists('services_key_permissions')) {
_services_key_auth_permissions($update);
Expand Down
17 changes: 8 additions & 9 deletions auth/services_keyauth/services_keyauth.module
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
// $Id: services_keyauth.module,v 1.1.2.6.2.2 2009/06/28 22:33:08 marcingy Exp $
// $Id: services_keyauth.module,v 1.1.2.6.2.4 2009/12/05 01:42:38 heyrocker Exp $
/**
* @author Services Dev Team
* @file
* Provides a key based validation system.
*/
Expand Down Expand Up @@ -33,9 +32,9 @@ function services_keyauth_access() {
*/
function services_keyauth_authentication_info() {
return array(
'#file' => 'services_keyauth.inc',
'#title' => t('Key authentication'),
'#description' => t('The default key-based authentication'),
'file' => 'services_keyauth.inc',
'title' => t('Key authentication'),
'description' => t('The default key-based authentication'),
'security_settings' => '_services_keyauth_security_settings',
'security_settings_validate' => '_services_keyauth_security_settings_validate',
'security_settings_submit' => '_services_keyauth_security_settings_submit',
Expand Down Expand Up @@ -94,11 +93,11 @@ function services_keyauth_menu() {
}

function services_get_hash($timestamp, $domain, $nonce, $method, $args) {
$hash_parameters = array($timestamp, $domain, $nonce, $method['#method']);
foreach ($method['#args'] as $key => $arg) {
if ($arg['#signed'] == TRUE) {
$hash_parameters = array($timestamp, $domain, $nonce, $method['method']);
foreach ($method['args'] as $key => $arg) {
if ($arg['signed'] == TRUE) {
if (is_numeric($args[$key]) || !empty($args[$key])) {
if (is_array($args[$key]) || is_object($args[$key])){
if (is_array($args[$key]) || is_object($args[$key])) {
$hash_parameters[] = serialize($args[$key]);
}
else{
Expand Down
5 changes: 2 additions & 3 deletions servers/xmlrpc_server/xmlrpc_server.module
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
// $Id: xmlrpc_server.module,v 1.6.2.14.2.2 2009/06/13 22:43:44 marcingy Exp $
// $Id: xmlrpc_server.module,v 1.6.2.14.2.4 2009/12/05 01:42:38 heyrocker Exp $
/**
* @author Services Dev Team
* @file
* Enable XML-RPC for services module.
*/
Expand All @@ -25,7 +24,7 @@ function xmlrpc_server_server() {
function xmlrpc_server_xmlrpc() {
$callbacks = array();
foreach (services_get_all() as $method) {
$callbacks[$method['#method']] = 'xmlrpc_server_call_wrapper';
$callbacks[$method['method']] = 'xmlrpc_server_call_wrapper';
}
return $callbacks;
}
Expand Down
12 changes: 6 additions & 6 deletions services.install
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
// $Id: services.install,v 1.3.2.21 2009/05/26 02:55:14 heyrocker Exp $
// $Id: services.install,v 1.3.2.21.2.2 2009/12/05 01:42:38 heyrocker Exp $

/**
* @author Services Dev Team
* @file
* Install, uninstall and update the module.
*/
Expand All @@ -26,7 +26,7 @@ function services_install() {
function services_uninstall() {
drupal_uninstall_schema('services');
$ret = array();

// Drop legacy tables
$legacy_tables = array('services_keys', 'services_timestamp_nonce');
foreach ($legacy_tables as $table) {
Expand Down Expand Up @@ -72,9 +72,9 @@ function services_update_6001() {
'default' => ''
),
),
'indexes' => array(
'timestamp' => array('timestamp'),
),
'indexes' => array(
'timestamp' => array('timestamp'),
),
'primary key' => array('nonce'),
);
$update = array();
Expand Down
Loading