1+ <?php
2+
3+ class remoting {
4+
5+ //* remote session timeout in seconds
6+ private $ session_timeout = 600 ;
7+
8+ //* remote login function
9+ public function login ($ username , $ password ) {
10+ global $ app ,$ conf ,$ server ;
11+
12+ if (empty ($ username )) {
13+ $ server ->fault ('login_username_empty ' ,'The login username is empty ' );
14+ return false ;
15+ }
16+
17+ if (empty ($ password )) {
18+ $ server ->fault ('login_password_empty ' ,'The login password is empty ' );
19+ return false ;
20+ }
21+
22+ $ username = $ app ->db ->quote ($ username );
23+ $ password = $ app ->db ->quote ($ password );
24+
25+ $ sql = "SELECT * FROM remote_user WHERE remote_username = ' $ username' and remote_password = md5(' $ password') " ;
26+ $ remote_user = $ app ->db ->queryOneRecord ($ sql );
27+ if ($ remote_user ['remote_userid ' ] > 0 ) {
28+ //* Create a remote user session
29+ srand ((double )microtime ()*1000000 );
30+ $ remote_session = md5 (rand ());
31+ $ remote_userid = $ remote_user ['remote_userid ' ];
32+ $ remote_functions = $ remote_user ['remote_functions ' ];
33+ $ tstamp = time () + $ this ->session_timeout ;
34+ $ sql = "INSERT INTO remote_session (remote_session,remote_userid,remote_functions,tstamp) VALUES (' $ remote_session', $ remote_userid,' $ remote_functions', $ tstamp) " ;
35+ $ app ->db ->query ($ sql );
36+ return $ remote_session ;
37+ } else {
38+ $ server ->fault ('login_failed ' ,'The login failed. Username or password wrong. ' );
39+ return false ;
40+ }
41+
42+ }
43+
44+
45+ //* remote logout function
46+ public function logout ($ session_id ) {
47+ global $ app ,$ conf ,$ server ;
48+
49+ if (empty ($ session_id )) {
50+ $ server ->fault ('session_id_empty ' ,'The SessionID is empty. ' );
51+ return false ;
52+ }
53+
54+ $ session_id = $ app ->db ->quote ($ session_id );
55+
56+ $ sql = "DELETE FROM remote_session WHERE remote_session = ' $ session_id' " ;
57+ $ app ->db ->query ($ sql );
58+ if ($ app ->db ->affectedRows () == 1 ) {
59+ return true ;
60+ } else {
61+ return false ;
62+ }
63+ }
64+
65+ public function mail_domain_add ($ session_id , $ params ) {
66+ global $ app ,$ conf ,$ server ;
67+
68+ if (!$ this ->checkPerm ($ session_id ,'mail_domain_add ' )) {
69+ $ server ->fault ('permission_denied ' ,'You do not have the permissions to access this function. ' );
70+ return false ;
71+ }
72+
73+ //* Form definition file, that is used for this table in the interafce
74+ $ formdef = '../mail/form/mail_domain.tform.php ' ;
75+
76+ //* check the variables against the form definition and build the sql query automatically.
77+ // I will use a modified version of the tform class for this.
78+
79+
80+
81+
82+ }
83+
84+
85+
86+ //* private functions -----------------------------------------------------------------------------------
87+
88+ private function updateQuery ($ formdef ,$ params ) {
89+
90+ }
91+
92+
93+ private function checkPerm ($ session_id ,$ function_name ) {
94+
95+ $ session = $ this ->getSession ($ session_id );
96+ if ($ session ) {
97+ $ remote_functions = explode (', ' ,$ session ['remote_functions ' ]);
98+ if (in_array ($ function_name ,$ remote_functions )) {
99+ return true ;
100+ } else {
101+ return false ;
102+ }
103+ } else {
104+ return false ;
105+ }
106+ }
107+
108+
109+ private function getSession ($ session_id ) {
110+ global $ app ,$ conf ,$ server ;
111+
112+ if (empty ($ session_id )) {
113+ $ server ->fault ('session_id_empty ' ,'The SessionID is empty. ' );
114+ return false ;
115+ }
116+
117+ $ session_id = $ app ->db ->quote ($ session_id );
118+
119+ $ now = time ();
120+ $ sql = "SELECT * FROM remote_session WHERE remote_session = ' $ session_id' AND tstamp >= $ now " ;
121+ $ session = $ app ->db ->queryOneRecord ($ sql );
122+ if ($ session ['remote_userid ' ] > 0 ) {
123+ return $ session ;
124+ } else {
125+ $ server ->fault ('session_does_not_exist ' ,'The Session is expired or does not exist. ' );
126+ return false ;
127+ }
128+
129+ }
130+
131+
132+ }
133+
134+ ?>
0 commit comments