@@ -59,14 +59,15 @@ public function __construct($methods = array())
5959 $ app ->uses ('remoting_lib ' );
6060
6161 $ this ->_methods = $ methods ;
62- /*
62+
63+ /*
6364 $this->app = $app;
6465 $this->conf = $conf;
6566 */
6667 }
6768
6869 //* remote login function
69- public function login ($ username , $ password )
70+ public function login ($ username , $ password, $ client_login = false )
7071 {
7172 global $ app , $ conf ;
7273
@@ -95,24 +96,74 @@ public function login($username, $password)
9596 $ username = $ app ->db ->quote ($ username );
9697 $ password = $ app ->db ->quote ($ password );
9798
98- $ sql = "SELECT * FROM remote_user WHERE remote_username = ' $ username' and remote_password = md5(' $ password') " ;
99- $ remote_user = $ app ->db ->queryOneRecord ($ sql );
100- if ($ remote_user ['remote_userid ' ] > 0 ) {
101- //* Create a remote user session
102- srand ((double )microtime ()*1000000 );
103- $ remote_session = md5 (rand ());
104- $ remote_userid = $ remote_user ['remote_userid ' ];
105- $ remote_functions = $ remote_user ['remote_functions ' ];
106- $ tstamp = time () + $ this ->session_timeout ;
107- $ sql = 'INSERT INTO remote_session (remote_session,remote_userid,remote_functions,tstamp '
99+ if ($ client_login == true ) {
100+ $ sql = "SELECT * FROM sys_user WHERE USERNAME = ' $ username' " ;
101+ $ user = $ app ->db ->queryOneRecord ($ sql );
102+ if ($ user ) {
103+ $ saved_password = stripslashes ($ user ['passwort ' ]);
104+
105+ if (substr ($ saved_password ,0 ,3 ) == '$1$ ' ) {
106+ //* The password is crypt-md5 encrypted
107+ $ salt = '$1$ ' .substr ($ saved_password ,3 ,8 ).'$ ' ;
108+
109+ if (crypt (stripslashes ($ password ),$ salt ) != $ saved_password ) {
110+ throw new SoapFault ('client_login_failed ' , 'The login failed. Username or password wrong. ' );
111+ return false ;
112+ }
113+ } else {
114+ //* The password is md5 encrypted
115+ if (md5 ($ password ) != $ saved_password ) {
116+ throw new SoapFault ('client_login_failed ' , 'The login failed. Username or password wrong. ' );
117+ return false ;
118+ }
119+ }
120+ } else {
121+ throw new SoapFault ('client_login_failed ' , 'The login failed. Username or password wrong. ' );
122+ return false ;
123+ }
124+ if ($ user ['active ' ] != 1 ) {
125+ throw new SoapFault ('client_login_failed ' , 'The login failed. User is blocked. ' );
126+ return false ;
127+ }
128+
129+ // now we need the client data
130+ $ client = $ app ->db ->queryOneRecord ("SELECT client.can_use_api FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = " . $ app ->functions ->intval ($ user ['default_group ' ]));
131+ if (!$ client || $ client ['can_use_api ' ] != 'y ' ) {
132+ throw new SoapFault ('client_login_failed ' , 'The login failed. Client may not use api. ' );
133+ return false ;
134+ }
135+
136+ //* Create a remote user session
137+ //srand ((double)microtime()*1000000);
138+ $ remote_session = md5 (mt_rand ().uniqid ('ispco ' ));
139+ $ remote_userid = $ user ['userid ' ];
140+ $ remote_functions = '' ;
141+ $ tstamp = time () + $ this ->session_timeout ;
142+ $ sql = 'INSERT INTO remote_session (remote_session,remote_userid,remote_functions,client_login,tstamp '
108143 .') VALUES ( '
109- ." ' $ remote_session', $ remote_userid,' $ remote_functions', $ tstamp) " ;
110- $ app ->db ->query ($ sql );
111- return $ remote_session ;
144+ ." ' $ remote_session', $ remote_userid,' $ remote_functions',1, $ tstamp) " ;
145+ $ app ->db ->query ($ sql );
146+ return $ remote_session ;
112147 } else {
113- throw new SoapFault ('login_failed ' , 'The login failed. Username or password wrong. ' );
114- return false ;
115- }
148+ $ sql = "SELECT * FROM remote_user WHERE remote_username = ' $ username' and remote_password = md5(' $ password') " ;
149+ $ remote_user = $ app ->db ->queryOneRecord ($ sql );
150+ if ($ remote_user ['remote_userid ' ] > 0 ) {
151+ //* Create a remote user session
152+ //srand ((double)microtime()*1000000);
153+ $ remote_session = md5 (mt_rand ().uniqid ('ispco ' ));
154+ $ remote_userid = $ remote_user ['remote_userid ' ];
155+ $ remote_functions = $ remote_user ['remote_functions ' ];
156+ $ tstamp = time () + $ this ->session_timeout ;
157+ $ sql = 'INSERT INTO remote_session (remote_session,remote_userid,remote_functions,tstamp '
158+ .') VALUES ( '
159+ ." ' $ remote_session', $ remote_userid,' $ remote_functions', $ tstamp) " ;
160+ $ app ->db ->query ($ sql );
161+ return $ remote_session ;
162+ } else {
163+ throw new SoapFault ('login_failed ' , 'The login failed. Username or password wrong. ' );
164+ return false ;
165+ }
166+ }
116167
117168 }
118169
@@ -389,6 +440,16 @@ protected function checkPerm($session_id, $function_name)
389440 return false ;
390441 }
391442
443+ $ _SESSION ['client_login ' ] = $ session ['client_login ' ];
444+ if ($ session ['client_login ' ] == 1 ) {
445+ // permissions are checked at an other place
446+ $ _SESSION ['client_sys_userid ' ] = $ session ['remote_userid ' ];
447+ $ app ->remoting_lib ->loadUserProfile (); // load the profile - we ALWAYS need this on client logins!
448+ return true ;
449+ } else {
450+ $ _SESSION ['client_sys_userid ' ] = 0 ;
451+ }
452+
392453 $ dobre = str_replace ('; ' ,', ' ,$ session ['remote_functions ' ]);
393454 $ check = in_array ($ function_name , explode (', ' , $ dobre ) );
394455 if (!$ check ) {
0 commit comments