Skip to content

Commit 412aa4f

Browse files
committed
First files of the remoting interface.
1 parent c5a08ee commit 412aa4f

File tree

3 files changed

+151
-1
lines changed

3 files changed

+151
-1
lines changed

interface/lib/app.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct()
5555
}
5656

5757
//* Start the session
58-
if($conf["start_session"] == true) {
58+
if($this->_conf['start_session'] == true) {
5959
session_start();
6060

6161
//* Initialize session variables
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
?>

interface/web/remote/index.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
require_once('../../lib/config.inc.php');
4+
$conf['start_session'] = false;
5+
require_once('../../lib/app.inc.php');
6+
7+
$app->load('remoting');
8+
9+
$server = new SoapServer(null, array('uri' => $_SERVER['REQUEST_URI']));
10+
//$server->setPersistence(SOAP_PERSISTENCE_SESSION);
11+
$server->setClass('remoting');
12+
$server->handle();
13+
14+
15+
16+
?>

0 commit comments

Comments
 (0)