Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
return $this->insertQuery('../dns/form/dns_rp.tform.php',$client_id,$params);
}
//* Update a record
public function dns_rp_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_rp_update')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../dns/form/dns_rp.tform.php',$client_id,$primary_id,$params);
return $affected_rows;
}
//* Delete a record
public function dns_rp_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'dns_rp_delete')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../dns/form/dns_rp.tform.php',$primary_id);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------------
//* Get record details
public function dns_srv_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'dns_srv_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../dns/form/dns_srv.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add a record
public function dns_srv_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_srv_add')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $this->insertQuery('../dns/form/dns_srv.tform.php',$client_id,$params);
}
//* Update a record
public function dns_srv_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_srv_update')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../dns/form/dns_srv.tform.php',$client_id,$primary_id,$params);
return $affected_rows;
}
//* Delete a record
public function dns_srv_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'dns_srv_delete')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../dns/form/dns_srv.tform.php',$primary_id);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------------
//* Get record details
public function dns_txt_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'dns_txt_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../dns/form/dns_txt.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add a record
public function dns_txt_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_txt_add')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $this->insertQuery('../dns/form/dns_txt.tform.php',$client_id,$params);
}
//* Update a record
public function dns_txt_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_txt_update')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../dns/form/dns_txt.tform.php',$client_id,$primary_id,$params);
return $affected_rows;
}
//* Delete a record
public function dns_txt_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'dns_txt_delete')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../dns/form/dns_txt.tform.php',$primary_id);
return $affected_rows;
}
//** protected functions -----------------------------------------------------------------------------------
protected function klientadd($formdef_file, $reseller_id, $params)
{
global $app, $tform, $remoting_lib;
$app->uses('remoting_lib');
//* Load the form definition
$app->remoting_lib->loadFormDef($formdef_file);
//* load the user profile of the client
$app->remoting_lib->loadUserProfile($reseller_id);
//* load the client template
if(isset($params['template_master']) and $params['template_master'] > 0)
{
$template=$app->db->queryOneRecord("SELECT * FROM client_template WHERE template_id=".intval($params['template_master']));
if(is_array($template)) $params=array_merge($params,$template);
}
//* Get the SQL query
$sql = $app->remoting_lib->getSQL($params,'INSERT',0);
$app->db->query($sql);
//* Check if no system user with that username exists
$username = $app->db->quote($params["username"]);
$tmp = $app->db->queryOneRecord("SELECT count(userid) as number FROm sys_user WHERE username = '$username'");
if($tmp['number'] > 0) $app->remoting_lib->errorMessage .= "Duplicate username<br />";
if($app->remoting_lib->errorMessage != '') {
$this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
return false;
}
$insert_id = $app->db->insertID();
$this->id = $insert_id;
$this->dataRecord = $params;
$app->plugin->raiseEvent('client:client:on_after_insert',$this);
/*
if($app->db->errorMessage != '') {
$this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
return false;
}
*/
//$app->uses('tform');
//* Save changes to Datalog
if($app->remoting_lib->formDef["db_history"] == 'yes') {
$new_rec = $app->remoting_lib->getDataRecord($insert_id);
$app->remoting_lib->datalogSave('INSERT',$primary_id,array(),$new_rec);
$app->remoting_lib->ispconfig_sysuser_add($params,$insert_id);
if($reseller_id) {
$client_group = $app->db->queryOneRecord("SELECT * FROM sys_group WHERE client_id = ".$insert_id);
$reseller_user = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE client_id = ".$reseller_id);
$app->auth->add_group_to_user($reseller_user['userid'], $client_group['groupid']);
$app->db->query("UPDATE client SET parent_client_id = ".$reseller_id." WHERE client_id = ".$insert_id);
}
}
return $insert_id;
}
protected function insertQuery($formdef_file, $client_id, $params,$event_identifier = '')
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
{
global $app, $tform, $remoting_lib;
$app->uses('remoting_lib');
//* load the user profile of the client
$app->remoting_lib->loadUserProfile($client_id);
//* Load the form definition
$app->remoting_lib->loadFormDef($formdef_file);
//* Get the SQL query
$sql = $app->remoting_lib->getSQL($params,'INSERT',0);
if($app->remoting_lib->errorMessage != '') {
$this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
return false;
}
$app->db->query($sql);
if($app->db->errorMessage != '') {
$this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
return false;
}
$insert_id = $app->db->insertID();
// set a few values for compatibility with tform actions, mostly used by plugins
$this->id = $insert_id;
$this->dataRecord = $params;
if($event_identifier != '') $app->plugin->raiseEvent($event_identifier,$this);
//$app->uses('tform');
//* Save changes to Datalog
if($app->remoting_lib->formDef["db_history"] == 'yes') {
$new_rec = $app->remoting_lib->getDataRecord($insert_id);
$app->remoting_lib->datalogSave('INSERT',$primary_id,array(),$new_rec);
}
return $insert_id;
}
protected function updateQuery($formdef_file, $client_id, $primary_id, $params, $event_identifier = '')
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
{
global $app;
$app->uses('remoting_lib');
//* load the user profile of the client
$app->remoting_lib->loadUserProfile($client_id);
//* Load the form definition
$app->remoting_lib->loadFormDef($formdef_file);
//* Get the SQL query
$sql = $app->remoting_lib->getSQL($params,'UPDATE',$primary_id);
if($app->remoting_lib->errorMessage != '') {
$this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
return false;
}
$old_rec = $app->remoting_lib->getDataRecord($primary_id);
// set a few values for compatibility with tform actions, mostly used by plugins
$this->oldDataRecord = $old_rec;
$this->id = $primary_id;
$this->dataRecord = $params;
$app->db->query($sql);
if($app->db->errorMessage != '') {
$this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
return false;
}
$affected_rows = $app->db->affectedRows();
if($event_identifier != '') $app->plugin->raiseEvent($event_identifier,$this);
//* Save changes to Datalog
if($app->remoting_lib->formDef["db_history"] == 'yes') {
$new_rec = $app->remoting_lib->getDataRecord($primary_id);
$app->remoting_lib->datalogSave('UPDATE',$primary_id,$old_rec,$new_rec);
}
return $affected_rows;
}
protected function deleteQuery($formdef_file, $primary_id, $event_identifier = '')
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
{
global $app;
$app->uses('remoting_lib');
//* load the user profile of the client
$app->remoting_lib->loadUserProfile(0);
//* Load the form definition
$app->remoting_lib->loadFormDef($formdef_file);
$old_rec = $app->remoting_lib->getDataRecord($primary_id);
// set a few values for compatibility with tform actions, mostly used by plugins
$this->oldDataRecord = $old_rec;
$this->id = $primary_id;
$this->dataRecord = $params;
//* Get the SQL query
$sql = $app->remoting_lib->getDeleteSQL($primary_id);
$app->db->query($sql);
if($app->db->errorMessage != '') {
if($event_identifier != '') $app->plugin->raiseEvent($event_identifier,$this);
$this->server->fault('database_error', $app->db->errorMessage . ' '.$sql);
return false;
}
$affected_rows = $app->db->affectedRows();
//* Save changes to Datalog
if($app->remoting_lib->formDef["db_history"] == 'yes') {
$app->remoting_lib->datalogSave('DELETE',$primary_id,$old_rec,array());
}
return $affected_rows;
}
protected function checkPerm($session_id, $function_name)
{
$dobre=array();
$session = $this->getSession($session_id);
if(!$session){
return false;
}
$dobre= str_replace(';',',',$session['remote_functions']);
return in_array($function_name, explode(',', $dobre) );
}
protected function getSession($session_id)
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
{
global $app;
if(empty($session_id)) {
$this->server->fault('session_id_empty','The SessionID is empty.');
return false;
}
$session_id = $app->db->quote($session_id);
$now = time();
$sql = "SELECT * FROM remote_session WHERE remote_session = '$session_id' AND tstamp >= $now";
$session = $app->db->queryOneRecord($sql);
if($session['remote_userid'] > 0) {
return $session;
} else {
$this->server->fault('session_does_not_exist','The Session is expired or does not exist.');
return false;
}
}
//---
/**
* Gets sites by $sys_userid & $sys_groupid
* @param int session id
* @param int user id
* @param array list of groups
* @return mixed array with sites by user
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*/
public function client_get_sites_by_user($session_id, $sys_userid, $sys_groupid) {
global $app;
if(!$this->checkPerm($session_id, 'client_get_sites_by_user')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$sys_userid = intval($sys_userid);
$sys_groupid = explode(',', $sys_groupid);
$new_group = array();
foreach($sys_groupid as $group_id) {
$new_group[] = intval( $group_id);
}
$group_list = implode(',', $new_group);
$sql ="SELECT domain, domain_id, document_root, active 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'";
$result = $app->db->queryAllRecords($sql);
if(isset($result)) {
return $result;
} else {
$this->server->fault('no_client_found', 'There is no site for this user');
return false;
}
}
/**
* Change domains status
* @param int session id
* @param int site id
* @param string active or inactive string
* @return mixed false if error
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*/
public function sites_web_domain_set_status($session_id, $primary_id, $status) {
global $app;
if(!$this->checkPerm($session_id, 'sites_web_domain_set_status')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if(in_array($status, array('active', 'inactive'))) {
if ($status == 'active') {
$status = 'y';
} else {
$status = 'n';
}
$sql = "UPDATE web_domain SET active = '$status' WHERE domain_id = ".intval($primary_id);
$app->db->query($sql);
$result = $app->db->affectedRows();
return $result;
} else {
$this->server->fault('status_undefined', 'The status is not available');
return false;
}
}
/**
* Get sys_user information by username
* @param int session id
* @param string user's name
* @return mixed false if error
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*/
public function client_get_by_username($session_id, $username) {
global $app;
if(!$this->checkPerm($session_id, 'client_get_by_username')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$username = $app->db->quote($username);
$rec = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE username = '".$username."'");
if (isset($rec)) {
return $rec;
} else {
$this->server->fault('no_client_found', 'There is no user account for this user name.');
return false;
}
}
/**
* Changes client password
*
* @param int session id
* @param int client id
* @param string new password
* @return bool true if success
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*
*/
public function client_change_password($session_id, $client_id, $new_password) {
global $app;
if(!$this->checkPerm($session_id, 'client_change_password')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$client_id = intval($client_id);
$client = $app->db->queryOneRecord("SELECT client_id FROM client WHERE client_id = ".$client_id);
if($client['client_id'] > 0) {
$new_password = $app->db->quote($new_password);
$sql = "UPDATE client SET password = md5('".($new_password)."') WHERE client_id = ".$client_id;
$app->db->query($sql);
$sql = "UPDATE sys_user SET passwort = md5('".($new_password)."') WHERE client_id = ".$client_id;
$app->db->query($sql);
return true;
} else {
$this->server->fault('no_client_found', 'There is no user account for this client_id');
return false;
}
}
/**
* Fetch the mail_domain record for the provided domain.
* @param int session_id
* @param string the fully qualified domain (or subdomain)
* @return array array of arrays corresponding to the mail_domain table's records
* @author till, benlake
*/
public function mail_domain_get_by_domain($session_id, $domain) {
global $app;
if(!$this->checkPerm($session_id, 'mail_domain_get_by_domain')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$sql = "SELECT * FROM mail_domain WHERE domain = '$domain'";
$result = $app->db->queryAllRecords($sql);
return $result;
}
return false;
}
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
/**
* Get a list of functions
* @param int session id
* @return mixed array of the available functions
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*/
public function get_function_list($session_id)
{
if(!$this->checkPerm($session_id, 'get_function_list')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return get_class_methods($this);
}
/**
* Get all databases by user
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*/
public function sites_database_get_all_by_user($session_id, $client_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_database_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$client_id = intval($client_id);
$sql = "SELECT d.database_id, d.database_name, d.database_user, d.database_password FROM web_database d INNER JOIN sys_user s on(d.sys_groupid = s.default_group) WHERE client_id = $client_id";
$all = $app->db->queryAllRecords($sql);
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
return $all;
}
/**
* Get all client templates
* @param int session id
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*/
public function client_templates_get_all($session_id) {
global $app;
if(!$this->checkPerm($session_id, 'client_templates_get_all')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$sql = "SELECT * FROM client_template";
$result = $app->db->queryAllRecords($sql);
return $result;
}
/**
* Get all DNS zone by user
*@author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*/
public function dns_zone_get_by_user($session_id, $client_id, $server_id) {
global $app;
if(!$this->checkPerm($session_id, 'dns_zone_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if (!empty($client_id) && !empty($server_id)) {
$server_id = intval($server_id);
$client_id = intval($client_id);
$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";
$result = $app->db->queryAllRecords($sql);
return $result;
}
return false;
}

sebastianm
committed
/**
* Get all dns records for a zone
* @param int session id
* @param int dns zone id
* @author Sebastian Mogilowski <sebastian@mogilowski.net> 2011
*/
public function dns_rr_get_all_by_zone($session_id, $zone_id) {
global $app;
if(!$this->checkPerm($session_id, 'dns_zone_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$sql = "SELECT * FROM dns_rr WHERE zone = ".intval($zone_id);;
$result = $app->db->queryAllRecords($sql);
return $result;
}
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
/**
* Changes DNS zone status
* @param int session id
* @param int dns soa id
* @param string status active or inactive string
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*/
public function dns_zone_set_status($session_id, $primary_id, $status) {
global $app;
if(!$this->checkPerm($session_id, 'dns_zone_set_status')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if(in_array($status, array('active', 'inactive'))) {
if ($status == 'active') {
$status = 'Y';
} else {
$status = 'N';
}
$sql = "UPDATE dns_soa SET active = '$status' WHERE id = ".intval($primary_id);
$app->db->query($sql);
$result = $app->db->affectedRows();
return $result;
} else {
$this->server->fault('status_undefined', 'The status is not available');
return false;
}
}
public function mail_domain_set_status($session_id, $primary_id, $status) {
global $app;
if(!$this->checkPerm($session_id, 'mail_domain_set_status')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if(in_array($status, array('active', 'inactive'))) {
if ($status == 'active') {
$status = 'y';
} else {
$status = 'n';
}
$sql = "UPDATE mail_domain SET active = '$status' WHERE domain_id = ".intval($primary_id);
$app->db->query($sql);
$result = $app->db->affectedRows();
return $result;
} else {
$this->server->fault('status_undefined', 'The status is not available');
return false;
}
}
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
//* Functions for virtual machine management
//* Get OpenVZ OStemplate details
public function openvz_ostemplate_get($session_id, $ostemplate_id)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../vm/form/openvz_ostemplate.tform.php');
return $app->remoting_lib->getDataRecord($ostemplate_id);
}
//* Add a openvz ostemplate record
public function openvz_ostemplate_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $this->insertQuery('../vm/form/openvz_ostemplate.tform.php',$client_id,$params);
}
//* Update openvz ostemplate record
public function openvz_ostemplate_update($session_id, $client_id, $ostemplate_id, $params)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../vm/form/openvz_ostemplate.tform.php',$client_id,$ostemplate_id,$params);
return $affected_rows;
}
//* Delete openvz ostemplate record
public function openvz_ostemplate_delete($session_id, $ostemplate_id)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../vm/form/openvz_ostemplate.tform.php',$ostemplate_id);
return $affected_rows;
}
//* Get OpenVZ template details
public function openvz_template_get($session_id, $template_id)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../vm/form/openvz_template.tform.php');
return $app->remoting_lib->getDataRecord($template_id);
}
//* Add a openvz template record
public function openvz_template_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $this->insertQuery('../vm/form/openvz_template.tform.php',$client_id,$params);
}
//* Update openvz template record
public function openvz_template_update($session_id, $client_id, $template_id, $params)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../vm/form/openvz_template.tform.php',$client_id,$template_id,$params);
return $affected_rows;
}
//* Delete openvz template record
public function openvz_template_delete($session_id, $template_id)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../vm/form/openvz_template.tform.php',$template_id);
return $affected_rows;
}
//* Get OpenVZ ip details
public function openvz_ip_get($session_id, $ip_id)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../vm/form/openvz_ip.tform.php');
return $app->remoting_lib->getDataRecord($ip_id);
}
//* Get OpenVZ a free IP address
public function openvz_get_free_ip($session_id, $server_id = 0)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$server_id = intval($server_id);
if($server_id > 0) {
$tmp = $app->db->queryOneRecord("SELECT ip_address_id, server_id, ip_address FROM openvz_ip WHERE reserved = 'n' AND vm_id = 0 AND server_id = $server_id LIMIT 0,1");
} else {
$tmp = $app->db->queryOneRecord("SELECT ip_address_id, server_id, ip_address FROM openvz_ip WHERE reserved = 'n' AND vm_id = 0 LIMIT 0,1");
}
if(count($tmp) > 0) {
return $tmp;
} else {
$this->server->fault('no_free_ip', 'There is no free IP available.');
}
}
//* Add a openvz ip record
public function openvz_ip_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $this->insertQuery('../vm/form/openvz_ip.tform.php',$client_id,$params);
}
//* Update openvz ip record
public function openvz_ip_update($session_id, $client_id, $ip_id, $params)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../vm/form/openvz_ip.tform.php',$client_id,$ip_id,$params);
return $affected_rows;
}
//* Delete openvz ip record
public function openvz_ip_delete($session_id, $ip_id)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../vm/form/openvz_ip.tform.php',$ip_id);
return $affected_rows;
}
//* Get OpenVZ vm details
public function openvz_vm_get($session_id, $vm_id)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
return $app->remoting_lib->getDataRecord($vm_id);
}
//* Get OpenVZ list
public function openvz_vm_get_by_client($session_id, $client_id)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if (!empty($client_id)) {
$client_id = intval($client_id);
$tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = $client_id");
$sql = "SELECT * FROM openvz_vm WHERE sys_groupid = ".intval($tmp['groupid']);
$result = $app->db->queryAllRecords($sql);
return $result;
}
return false;
}
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
//* Add a openvz vm record
public function openvz_vm_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $this->insertQuery('../vm/form/openvz_vm.tform.php',$client_id,$params);
}
//* Add a openvz vm record from template
public function openvz_vm_add_from_template($session_id, $client_id, $ostemplate_id, $template_id, $override_params = array())
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$template_id = intval($template_id);
$ostemplate_id = intval($ostemplate_id);
//* Verify parameters
if($template_id == 0) {
$this->server->fault('template_id_error', 'Template ID must be > 0.');
return false;
}
if($ostemplate_id == 0) {
$this->server->fault('ostemplate_id_error', 'OSTemplate ID must be > 0.');
return false;
}
// Verify if template and ostemplate exist
$tmp = $app->db->queryOneRecord("SELECT template_id FROM openvz_template WHERE template_id = $template_id");
if(!is_array($tmp)) {
$this->server->fault('template_id_error', 'Template does not exist.');
return false;
}
$tmp = $app->db->queryOneRecord("SELECT ostemplate_id FROM openvz_ostemplate WHERE ostemplate_id = $ostemplate_id");
if(!is_array($tmp)) {
$this->server->fault('ostemplate_id_error', 'OSTemplate does not exist.');
return false;
}
//* Get the template
$vtpl = $app->db->queryOneRecord("SELECT * FROM openvz_template WHERE template_id = $template_id");
//* Get the IP address and server_id
if($override_params['server_id'] > 0) {
$vmip = $app->db->queryOneRecord("SELECT ip_address_id, server_id, ip_address FROM openvz_ip WHERE reserved = 'n' AND vm_id = 0 AND server_id = ".$override_params['server_id']." LIMIT 0,1");
} else {
$vmip = $app->db->queryOneRecord("SELECT ip_address_id, server_id, ip_address FROM openvz_ip WHERE reserved = 'n' AND vm_id = 0 LIMIT 0,1");
}
if(!is_array($vmip)) {
$this->server->fault('vm_ip_error', 'Unable to get a free VM IP.');
return false;
}
//* Build the $params array
$params = array();
$params['server_id'] = $vmip['server_id'];
$params['ostemplate_id'] = $ostemplate_id;
$params['template_id'] = $template_id;
$params['ip_address'] = $vmip['ip_address'];
$params['hostname'] = (isset($override_params['hostname']))?$override_params['hostname']:$vtpl['hostname'];
$params['vm_password'] = (isset($override_params['vm_password']))?$override_params['vm_password']:$app->auth->get_random_password(10);
$params['start_boot'] = (isset($override_params['start_boot']))?$override_params['start_boot']:'y';
$params['active'] = (isset($override_params['active']))?$override_params['active']:'y';
$params['active_until_date'] = (isset($override_params['active_until_date']))?$override_params['active_until_date']:'0000-00-00';
$params['description'] = (isset($override_params['description']))?$override_params['description']:'';
//* The next params get filled with pseudo values, as the get replaced
//* by the openvz event plugin anyway with values from the template
$params['veid'] = 1;
$params['diskspace'] = 1;
$params['ram'] = 1;
$params['ram_burst'] = 1;
$params['cpu_units'] = 1;
$params['cpu_num'] = 1;
$params['cpu_limit'] = 1;
$params['io_priority'] = 1;
$params['nameserver'] = '8.8.8.8 8.8.4.4';
$params['create_dns'] = 'n';
$params['capability'] = '';
return $this->insertQuery('../vm/form/openvz_vm.tform.php',$client_id,$params,'vm:openvz_vm:on_after_insert');
}
//* Update openvz vm record
public function openvz_vm_update($session_id, $client_id, $vm_id, $params)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../vm/form/openvz_vm.tform.php',$client_id,$vm_id,$params,'vm:openvz_vm:on_after_update');
return $affected_rows;
}
//* Delete openvz vm record
public function openvz_vm_delete($session_id, $vm_id)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../vm/form/openvz_vm.tform.php',$vm_id,'vm:openvz_vm:on_after_delete');
return $affected_rows;
}
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
//* Start VM
public function openvz_vm_start($session_id, $vm_id)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../vm/form/openvz_vm.tform.php');
$vm = $app->remoting_lib->getDataRecord($vm_id);
if(!is_array($vm)) {
$this->server->fault('action_pending', 'No VM with this ID available.');
return false;
}
if($vm['active'] == 'n') {
$this->server->fault('action_pending', 'VM is not in active state.');
return false;
}
$action = 'openvz_start_vm';
$tmp = $app->db->queryOneRecord("SELECT count(action_id) as actions FROM sys_remoteaction
WHERE server_id = '".$vm['server_id']."'
AND action_type = '$action'
AND action_param = '".$vm['veid']."'
AND action_state = 'pending'");
if($tmp['actions'] > 0) {
$this->server->fault('action_pending', 'There is already a action pending for this VM.');
return false;
} else {
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
"VALUES (".
(int)$vm['server_id'] . ", ".