@@ -113,6 +113,27 @@ public function client_get_id($session_id, $sys_userid)
113113 }
114114
115115 }
116+
117+ //* Get the contact details to send a email like email address, name, etc.
118+ public function client_get_emailcontact ($ session_id , $ client_id ) {
119+ global $ app ;
120+
121+ if (!$ this ->checkPerm ($ session_id , 'client_get_emailcontact ' )) {
122+ throw new SoapFault ('permission_denied ' , 'You do not have the permissions to access this function. ' );
123+ return false ;
124+ }
125+
126+ $ client_id = $ app ->functions ->intval ($ client_id );
127+
128+ $ rec = $ app ->db ->queryOneRecord ("SELECT company_name,contact_name,gender,email,language FROM client WHERE client_id = " .$ client_id );
129+
130+ if (is_array ($ rec )) {
131+ return $ rec ;
132+ } else {
133+ throw new SoapFault ('no_client_found ' , 'There is no client with this client ID. ' );
134+ return false ;
135+ }
136+ }
116137
117138 public function client_get_groupid ($ session_id , $ client_id )
118139 {
@@ -489,6 +510,123 @@ public function client_templates_get_all($session_id) {
489510 $ result = $ app ->db ->queryAllRecords ($ sql );
490511 return $ result ;
491512 }
513+
514+ public function client_login_get ($ session_id ,$ username ,$ password ,$ remote_ip = '' ) {
515+ global $ app ;
516+
517+ //* Check permissions
518+ if (!$ this ->checkPerm ($ session_id , 'client_get ' )) {
519+ throw new SoapFault ('permission_denied ' , 'You do not have the permissions to access this function. ' );
520+ return false ;
521+ }
522+
523+ //* Check username and password
524+ if (!preg_match ("/^[\w\.\-\_\@]{1,128}$/ " , $ username )) {
525+ throw new SoapFault ('user_regex_error ' , 'Username contains invalid characters. ' );
526+ return false ;
527+ }
528+ if (!preg_match ("/^.{1,64}$/i " , $ password )) {
529+ throw new SoapFault ('password_length_error ' , 'Invalid password length or no password provided. ' );
530+ return false ;
531+ }
532+
533+ //* Check failed logins
534+ $ sql = "SELECT * FROM `attempts_login` WHERE `ip`= ' " .$ app ->db ->quote ($ remote_ip )."' AND `login_time` > (NOW() - INTERVAL 1 MINUTE) LIMIT 1 " ;
535+ $ alreadyfailed = $ app ->db ->queryOneRecord ($ sql );
536+
537+ //* too many failedlogins
538+ if ($ alreadyfailed ['times ' ] > 5 ) {
539+ throw new SoapFault ('error_user_too_many_logins ' , 'Too many failed logins. ' );
540+ return false ;
541+ }
542+
543+
544+ //*Set variables
545+ $ returnval == false ;
546+
547+ if (strstr ($ username ,'@ ' )) {
548+ // Check against client table
549+ $ sql = "SELECT * FROM client WHERE email = ' " .$ app ->db ->quote ($ username )."' " ;
550+ $ user = $ app ->db ->queryOneRecord ($ sql );
551+
552+ if ($ user ) {
553+ $ saved_password = stripslashes ($ user ['password ' ]);
554+
555+ if (substr ($ saved_password , 0 , 3 ) == '$1$ ' ) {
556+ //* The password is crypt-md5 encrypted
557+ $ salt = '$1$ ' .substr ($ saved_password , 3 , 8 ).'$ ' ;
558+
559+ if (crypt (stripslashes ($ password ), $ salt ) != $ saved_password ) {
560+ $ user = false ;
561+ }
562+ } else {
563+
564+ //* The password is md5 encrypted
565+ if (md5 ($ password ) != $ saved_password ) {
566+ $ user = false ;
567+ }
568+ }
569+ }
570+
571+ if (is_array ($ user )) {
572+ $ returnval = array ( 'username ' => $ user ['username ' ],
573+ 'type ' => 'user ' ,
574+ 'client_id ' => $ user ['client_id ' ],
575+ 'language ' => $ user ['language ' ],
576+ 'country ' => $ user ['country ' ]);
577+ }
578+
579+ } else {
580+ // Check against sys_user table
581+ $ sql = "SELECT * FROM sys_user WHERE username = ' " .$ app ->db ->quote ($ username )."' " ;
582+ $ user = $ app ->db ->queryOneRecord ($ sql );
583+
584+ if ($ user ) {
585+ $ saved_password = stripslashes ($ user ['passwort ' ]);
586+
587+ if (substr ($ saved_password , 0 , 3 ) == '$1$ ' ) {
588+ //* The password is crypt-md5 encrypted
589+ $ salt = '$1$ ' .substr ($ saved_password , 3 , 8 ).'$ ' ;
590+
591+ if (crypt (stripslashes ($ password ), $ salt ) != $ saved_password ) {
592+ $ user = false ;
593+ }
594+ } else {
595+
596+ //* The password is md5 encrypted
597+ if (md5 ($ password ) != $ saved_password ) {
598+ $ user = false ;
599+ }
600+ }
601+ }
602+
603+ if (is_array ($ user )) {
604+ $ returnval = array ( 'username ' => $ user ['username ' ],
605+ 'type ' => $ user ['typ ' ],
606+ 'client_id ' => $ user ['client_id ' ],
607+ 'language ' => $ user ['language ' ],
608+ 'country ' => 'de ' );
609+ } else {
610+ throw new SoapFault ('login_failed ' , 'Login failed. ' );
611+ }
612+ }
613+
614+ //* Log failed login attempts
615+ if ($ user === false ) {
616+ $ time = time ();
617+ if (!$ alreadyfailed ['times ' ] ) {
618+ //* user login the first time wrong
619+ $ sql = "INSERT INTO `attempts_login` (`ip`, `times`, `login_time`) VALUES (' " .$ app ->db ->quote ($ remote_ip )."', 1, NOW()) " ;
620+ $ app ->db ->query ($ sql );
621+ } elseif ($ alreadyfailed ['times ' ] >= 1 ) {
622+ //* update times wrong
623+ $ sql = "UPDATE `attempts_login` SET `times`=`times`+1, `login_time`=NOW() WHERE `login_time` >= ' " .$ time ."' LIMIT 1 " ;
624+ $ app ->db ->query ($ sql );
625+ }
626+ }
627+
628+ return $ returnval ;
629+ }
492630
493631}
494632
0 commit comments