Skip to content

Commit eabdde5

Browse files
author
Marius Burkard
committed
- dont use md5 on remote users
1 parent dbfb249 commit eabdde5

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

interface/lib/classes/remoting.inc.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,23 @@ public function login($username, $password, $client_login = false)
128128
$app->db->query($sql, $remote_session,$remote_userid,$remote_functions,$tstamp);
129129
return $remote_session;
130130
} else {
131-
$sql = "SELECT * FROM remote_user WHERE remote_username = ? and remote_password = md5(?)";
132-
$remote_user = $app->db->queryOneRecord($sql, $username, $password);
131+
$sql = "SELECT * FROM remote_user WHERE remote_username = ? and remote_password = ?";
132+
$remote_user = $app->db->queryOneRecord($sql, $username, $app->auth->crypt_password($password));
133+
if(!$remote_user) {
134+
// fallback to md5
135+
$sql = "SELECT * FROM remote_user WHERE remote_username = ? and remote_password = ?";
136+
$remote_user = $app->db->queryOneRecord($sql, $username, md5($password));
137+
if($remote_user) {
138+
// update hash algo
139+
$sql = 'UPDATE `remote_user` SET `remote_password` = ? WHERE `remote_username` = ?';
140+
$app->db->query($sql, $app->auth->crypt_password($password), $username);
141+
}
142+
}
133143
if($remote_user['remote_userid'] > 0) {
134144
if (trim($remote_user['remote_ips']) != '') {
135145
$allowed_ips = explode(',',$remote_user['remote_ips']);
136-
foreach($allowed_ips as $i => $allowed) {
137-
if(!filter_var($allowed, FILTER_VALIDATE_IP)) {
146+
foreach($allowed_ips as $i => $allowed) {
147+
if(!filter_var($allowed, FILTER_VALIDATE_IP)) {
138148
// get the ip for a hostname
139149
unset($allowed_ips[$i]);
140150
$temp=dns_get_record($allowed, DNS_A+DNS_AAAA);
@@ -169,7 +179,7 @@ public function login($username, $password, $client_login = false)
169179
if(!$remote_allowed) {
170180
throw new SoapFault('login_failed', 'The login is not allowed from '.$_SERVER['REMOTE_ADDR']);
171181
return false;
172-
}
182+
}
173183
//* Create a remote user session
174184
//srand ((double)microtime()*1000000);
175185
$remote_session = md5(mt_rand().uniqid('ispco'));
@@ -368,22 +378,22 @@ protected function updateQueryPrepare($formdef_file, $client_id, $primary_id, $p
368378

369379
//* Load the form definition
370380
$app->remoting_lib->loadFormDef($formdef_file);
371-
381+
372382
//* get old record and merge with params, so only new values have to be set in $params
373383
$old_rec = $app->remoting_lib->getDataRecord($primary_id, $client_id);
374-
384+
375385
foreach ($app->remoting_lib->formDef['fields'] as $fieldName => $fieldConf)
376386
{
377387
if ($fieldConf['formtype'] === 'PASSWORD' && empty($params[$fieldName])) {
378388
unset($old_rec[$fieldName]);
379389
}
380390
}
381-
391+
382392
$params = $app->functions->array_merge($old_rec,$params);
383393

384394
//* Get the SQL query
385395
$sql = $app->remoting_lib->getSQL($params, 'UPDATE', $primary_id);
386-
396+
387397
// throw new SoapFault('debug', $sql);
388398
if($app->remoting_lib->errorMessage != '') {
389399
throw new SoapFault('data_processing_error', $app->remoting_lib->errorMessage);
@@ -546,7 +556,7 @@ public function server_get($session_id, $server_id = null, $section ='') {
546556
return false;
547557
}
548558
}
549-
559+
550560
/**
551561
Gets a list of all servers
552562
@param int session_id

interface/web/admin/form/remote_user.tform.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
'errmsg' => 'weak_password_txt'
110110
)
111111
),
112-
'encryption' => 'MD5',
112+
'encryption' => 'CRYPT',
113113
'default' => '',
114114
'value' => '',
115115
'width' => '30',
@@ -124,11 +124,11 @@
124124
'remote_ips' => array (
125125
'datatype' => 'TEXT',
126126
'formtype' => 'TEXT',
127-
'validators' => array (
127+
'validators' => array (
128128
0 => array (
129-
'type' => 'CUSTOM',
130-
'class' => 'validate_remote_user',
131-
'function' => 'valid_remote_ip',
129+
'type' => 'CUSTOM',
130+
'class' => 'validate_remote_user',
131+
'function' => 'valid_remote_ip',
132132
'errmsg' => 'remote_user_error_ips'),
133133
),
134134
'default' => '',

0 commit comments

Comments
 (0)