Skip to content

Commit e8a29cf

Browse files
author
jmontoya
committed
Adding new functions to the Remoting class
1 parent 3b78336 commit e8a29cf

File tree

1 file changed

+231
-9
lines changed

1 file changed

+231
-9
lines changed

interface/lib/classes/remoting.inc.php

Lines changed: 231 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ public function logout($session_id)
122122
return ($app->db->affectedRows() == 1);
123123
}
124124

125-
// Get server details
126-
/**
127-
Gets the server configuration
128-
@param int session id
129-
@param int server id
130-
@param string section of the config field in the server table. Could be 'web', 'dns', 'mail', 'dns', 'cron', etc
131-
@author Julio Montoya <gugli100@gmail.com>
132-
*/
125+
126+
/**
127+
Gets the server configuration
128+
@param int session id
129+
@param int server id
130+
@param string section of the config field in the server table. Could be 'web', 'dns', 'mail', 'dns', 'cron', etc
131+
@author Julio Montoya <gugli100@gmail.com> BeezNest 2010
132+
*/
133133
public function server_get($session_id, $server_id, $section ='') {
134134
global $app;
135135
if(!$this->checkPerm($session_id, 'server_get')) {
@@ -2084,7 +2084,7 @@ private function deleteQuery($formdef_file, $primary_id)
20842084

20852085
private function checkPerm($session_id, $function_name)
20862086
{
2087-
$dobre=Array();
2087+
$dobre=array();
20882088
$session = $this->getSession($session_id);
20892089
if(!$session){
20902090
return false;
@@ -2116,5 +2116,227 @@ private function getSession($session_id)
21162116
return false;
21172117
}
21182118
}
2119+
2120+
//---
2121+
2122+
2123+
/**
2124+
* Gets sites by $sys_userid & $sys_groupid
2125+
* @param int session id
2126+
* @param int user id
2127+
* @param array list of groups
2128+
* @return mixed array with sites by user
2129+
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
2130+
*/
2131+
public function client_get_sites_by_user($session_id, $sys_userid, $sys_groupid) {
2132+
global $app;
2133+
if(!$this->checkPerm($session_id, 'client_get_sites_by_user')) {
2134+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2135+
return false;
2136+
}
2137+
$sys_userid = intval($sys_userid);
2138+
$sys_groupid = explode(',', $sys_groupid);
2139+
$new_group = array();
2140+
foreach($sys_groupid as $group_id) {
2141+
$new_group[] = intval( $group_id);
2142+
}
2143+
$group_list = implode(',', $new_group);
2144+
$sql ="SELECT domain, domain_id, document_root FROM web_domain WHERE ( (sys_userid = $sys_userid AND sys_perm_user LIKE '%r%') OR (sys_groupid IN ($group_list) AND sys_perm_group LIKE '%r%') OR sys_perm_other LIKE '%r%') AND type = 'vhost'";
2145+
$result = $app->db->queryAllRecords($sql);
2146+
if(isset($result)) {
2147+
return $result;
2148+
} else {
2149+
$this->server->fault('no_client_found', 'There is no site for this user');
2150+
return false;
2151+
}
2152+
}
2153+
2154+
/**
2155+
* Change domains status
2156+
* @param int session id
2157+
* @param int site id
2158+
* @param string active or inactive string
2159+
* @return mixed false if error
2160+
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
2161+
*/
2162+
2163+
public function sites_web_domain_set_status($session_id, $primary_id, $status) {
2164+
global $app;
2165+
if(!$this->checkPerm($session_id, 'sites_web_domain_set_status')) {
2166+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2167+
return false;
2168+
}
2169+
if(in_array($status, array('active', 'inactive'))) {
2170+
if ($status == 'active') {
2171+
$status = 'y';
2172+
} else {
2173+
$status = 'n';
2174+
}
2175+
$sql = "UPDATE web_domain SET active = '$status' WHERE domain_id = ".intval($primary_id);
2176+
$app->db->query($sql);
2177+
$result = $app->db->affectedRows();
2178+
return $result;
2179+
} else {
2180+
$this->server->fault('status_undefined', 'The status is not available');
2181+
return false;
2182+
}
2183+
}
2184+
2185+
/**
2186+
* Get sys_user information by username
2187+
* @param int session id
2188+
* @param string user's name
2189+
* @return mixed false if error
2190+
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
2191+
*/
2192+
public function client_get_by_username($session_id, $username) {
2193+
global $app;
2194+
if(!$this->checkPerm($session_id, 'client_get_by_username')) {
2195+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2196+
return false;
2197+
}
2198+
$username = $app->db->quote($username);
2199+
$rec = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE username = '".$username."'");
2200+
if (isset($rec)) {
2201+
return $rec;
2202+
} else {
2203+
$this->server->fault('no_client_found', 'There is no user account for this user name.');
2204+
return false;
2205+
}
2206+
}
2207+
2208+
/**
2209+
* Changes client password
2210+
*
2211+
* @param int session id
2212+
* @param int client id
2213+
* @param string new password
2214+
* @return bool true if success
2215+
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
2216+
*
2217+
*/
2218+
public function client_change_password($session_id, $client_id, $new_password) {
2219+
global $app;
2220+
2221+
if(!$this->checkPerm($session_id, 'client_change_password')) {
2222+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2223+
return false;
2224+
}
2225+
$client_id = intval($client_id);
2226+
$client = $app->db->queryOneRecord("SELECT client_id FROM client WHERE client_id = ".$client_id);
2227+
if($client['client_id'] > 0) {
2228+
$new_password = $app->db->quote($new_password);
2229+
$sql = "UPDATE client SET password = md5('".($new_password)."') WHERE client_id = ".$client_id;
2230+
$app->db->query($sql);
2231+
$sql = "UPDATE sys_user SET passwort = md5('".($new_password)."') WHERE client_id = ".$client_id;
2232+
$app->db->query($sql);
2233+
return true;
2234+
} else {
2235+
$this->server->fault('no_client_found', 'There is no user account for this client_id');
2236+
return false;
2237+
}
2238+
}
2239+
2240+
2241+
/**
2242+
* Get a list of functions
2243+
* @param int session id
2244+
* @return mixed array of the available functions
2245+
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
2246+
*/
2247+
public function get_function_list($session_id)
2248+
{
2249+
if(!$this->checkPerm($session_id, 'get_function_list')) {
2250+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2251+
return false;
2252+
}
2253+
return get_class_methods($this);
2254+
}
2255+
2256+
/**
2257+
* Get all databases by user
2258+
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
2259+
*/
2260+
public function sites_database_get_all_by_user($session_id, $client_id)
2261+
{
2262+
global $app;
2263+
if(!$this->checkPerm($session_id, 'sites_database_get_all_by_user')) {
2264+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2265+
return false;
2266+
}
2267+
$client_id = intval($client_id);
2268+
$sql = "SELECT database_id, database_name, database_user, database_password FROM web_database WHERE sys_userid = $client_id ";
2269+
$all = $app->db->queryAllRecords($sql);
2270+
return $all;
2271+
}
2272+
2273+
/**
2274+
* Get all client templates
2275+
* @param int session id
2276+
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
2277+
*/
2278+
public function client_templates_get_all($session_id) {
2279+
global $app;
2280+
if(!$this->checkPerm($session_id, 'client_templates_get_all')) {
2281+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2282+
return false;
2283+
}
2284+
$sql = "SELECT * FROM client_template";
2285+
$result = $app->db->queryAllRecords($sql);
2286+
return $result;
2287+
}
2288+
2289+
/**
2290+
* Get all DNS zone by user
2291+
*@author Julio Montoya <gugli100@gmail.com> BeezNest 2010
2292+
*/
2293+
/*
2294+
I will update this function
2295+
public function dns_zone_get_by_user($session_id, $client_id, $server_id) {
2296+
global $app;
2297+
if(!$this->checkPerm($session_id, 'dns_zone_get')) {
2298+
//$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2299+
//return false;
2300+
}
2301+
if (!empty($client_id) && !empty($server_id)) {
2302+
$server_id = intval($server_id);
2303+
$client_id = intval($client_id);
2304+
$sql = "SELECT id, origin FROM dns_soa d INNER JOIN sys_user s on(d.sys_groupid = s.default_group) WHERE client_id = '$client_id' AND server_id = $server_id";
2305+
$result = $app->db->queryAllRecords($sql);
2306+
return $result;
2307+
}
2308+
return false;
2309+
}
2310+
*/
2311+
2312+
/**
2313+
* Changes DNS zone status
2314+
* @param int session id
2315+
* @param int dns soa id
2316+
* @param string status active or inactive string
2317+
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
2318+
*/
2319+
2320+
public function dns_zone_set_status($session_id, $primary_id, $status) {
2321+
global $app;
2322+
if(!$this->checkPerm($session_id, 'dns_zone_set_status')) {
2323+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
2324+
return false;
2325+
}
2326+
if(in_array($status, array('active', 'inactive'))) {
2327+
if ($status == 'active') {
2328+
$status = 'y';
2329+
} else {
2330+
$status = 'n';
2331+
}
2332+
$sql = "UPDATE dns_soa SET active = '$status' WHERE id = ".intval($primary_id);
2333+
$app->db->query($sql);
2334+
$result = $app->db->affectedRows();
2335+
return $result;
2336+
} else {
2337+
$this->server->fault('status_undefined', 'The status is not available');
2338+
return false;
2339+
}
2340+
}
21192341
}
21202342
?>

0 commit comments

Comments
 (0)