@@ -5,38 +5,50 @@ class remoting {
55 //* remote session timeout in seconds
66 private $ session_timeout = 600 ;
77
8+ private $ app ;
9+ private $ conf ;
10+ private $ server ;
11+
12+ public function __construct ()
13+ {
14+ global $ app , $ conf , $ server ;
15+ $ this ->server = $ server ;
16+ $ this ->app = $ app ;
17+ $ this ->conf = $ conf ;
18+ }
19+
820 //* remote login function
921 public function login ($ username , $ password )
1022 {
11- global $ app , $ conf , $ server ;
12-
1323 if (empty ($ username )) {
14- $ server ->fault ('login_username_empty ' , 'The login username is empty ' );
24+ $ this -> server ->fault ('login_username_empty ' , 'The login username is empty ' );
1525 return false ;
1626 }
1727
1828 if (empty ($ password )) {
19- $ server ->fault ('login_password_empty ' , 'The login password is empty ' );
29+ $ this -> server ->fault ('login_password_empty ' , 'The login password is empty ' );
2030 return false ;
2131 }
2232
23- $ username = $ app ->db ->quote ($ username );
24- $ password = $ app ->db ->quote ($ password );
33+ $ username = $ this -> app ->db ->quote ($ username );
34+ $ password = $ this -> app ->db ->quote ($ password );
2535
2636 $ sql = "SELECT * FROM remote_user WHERE remote_username = ' $ username' and remote_password = md5(' $ password') " ;
27- $ remote_user = $ app ->db ->queryOneRecord ($ sql );
37+ $ remote_user = $ this -> app ->db ->queryOneRecord ($ sql );
2838 if ($ remote_user ['remote_userid ' ] > 0 ) {
2939 //* Create a remote user session
3040 srand ((double )microtime ()*1000000 );
3141 $ remote_session = md5 (rand ());
3242 $ remote_userid = $ remote_user ['remote_userid ' ];
3343 $ remote_functions = $ remote_user ['remote_functions ' ];
3444 $ tstamp = time () + $ this ->session_timeout ;
35- $ sql = "INSERT INTO remote_session (remote_session,remote_userid,remote_functions,tstamp) VALUES (' $ remote_session', $ remote_userid,' $ remote_functions', $ tstamp) " ;
36- $ app ->db ->query ($ sql );
45+ $ sql = 'INSERT INTO remote_session (remote_session,remote_userid,remote_functions,tstamp '
46+ .') VALUES ( '
47+ ." ' $ remote_session', $ remote_userid,' $ remote_functions', $ tstamp) " ;
48+ $ this ->app ->db ->query ($ sql );
3749 return $ remote_session ;
3850 } else {
39- $ server ->fault ('login_failed ' , 'The login failed. Username or password wrong. ' );
51+ $ this -> server ->fault ('login_failed ' , 'The login failed. Username or password wrong. ' );
4052 return false ;
4153 }
4254
@@ -45,31 +57,23 @@ public function login($username, $password)
4557
4658 //* remote logout function
4759 public function logout ($ session_id )
48- {
49- global $ app , $ conf , $ server ;
50-
60+ {
5161 if (empty ($ session_id )) {
52- $ server ->fault ('session_id_empty ' , 'The SessionID is empty. ' );
62+ $ this -> server ->fault ('session_id_empty ' , 'The SessionID is empty. ' );
5363 return false ;
5464 }
5565
5666 $ session_id = $ app ->db ->quote ($ session_id );
5767
5868 $ sql = "DELETE FROM remote_session WHERE remote_session = ' $ session_id' " ;
59- $ app ->db ->query ($ sql );
60- if ($ app ->db ->affectedRows () == 1 ) {
61- return true ;
62- } else {
63- return false ;
64- }
69+ $ this ->app ->db ->query ($ sql );
70+ return ($ this ->app ->db ->affectedRows () == 1 );
6571 }
6672
6773 public function mail_domain_add ($ session_id , $ params )
6874 {
69- global $ app , $ conf , $ server ;
70-
7175 if (!$ this ->checkPerm ($ session_id , 'mail_domain_add ' )) {
72- $ server ->fault ('permission_denied ' ,'You do not have the permissions to access this function. ' );
76+ $ this -> server ->fault ('permission_denied ' , 'You do not have the permissions to access this function. ' );
7377 return false ;
7478 }
7579
@@ -79,9 +83,6 @@ public function mail_domain_add($session_id, $params)
7983 //* check the variables against the form definition and build the sql query automatically.
8084 // I will use a modified version of the tform class for this.
8185
82-
83-
84-
8586 }
8687
8788
@@ -105,23 +106,21 @@ private function checkPerm($session_id, $function_name)
105106
106107
107108 private function getSession ($ session_id )
108- {
109- global $ app , $ conf , $ server ;
110-
109+ {
111110 if (empty ($ session_id )) {
112- $ server ->fault ('session_id_empty ' ,'The SessionID is empty. ' );
111+ $ this -> server ->fault ('session_id_empty ' ,'The SessionID is empty. ' );
113112 return false ;
114113 }
115114
116- $ session_id = $ app ->db ->quote ($ session_id );
115+ $ session_id = $ this -> app ->db ->quote ($ session_id );
117116
118117 $ now = time ();
119118 $ sql = "SELECT * FROM remote_session WHERE remote_session = ' $ session_id' AND tstamp >= $ now " ;
120- $ session = $ app ->db ->queryOneRecord ($ sql );
119+ $ session = $ this -> app ->db ->queryOneRecord ($ sql );
121120 if ($ session ['remote_userid ' ] > 0 ) {
122121 return $ session ;
123122 } else {
124- $ server ->fault ('session_does_not_exist ' ,'The Session is expired or does not exist. ' );
123+ $ this -> server ->fault ('session_does_not_exist ' ,'The Session is expired or does not exist. ' );
125124 return false ;
126125 }
127126 }
0 commit comments