Skip to content
remoting.inc.php 140 KiB
Newer Older
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_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('../sites/form/web_aliasdomain.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
latham's avatar
latham committed
	//* Add a record
	public function sites_web_aliasdomain_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../sites/form/web_aliasdomain.tform.php', $client_id, $params);
latham's avatar
latham committed
	//* Update a record
	public function sites_web_aliasdomain_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_update')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->updateQuery('../sites/form/web_aliasdomain.tform.php', $client_id, $primary_id, $params);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function sites_web_aliasdomain_delete($session_id, $primary_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_delete')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->deleteQuery('../sites/form/web_aliasdomain.tform.php', $primary_id);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	// ----------------------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function sites_web_subdomain_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'sites_web_subdomain_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('../sites/form/web_subdomain.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
latham's avatar
latham committed
	//* Add a record
	public function sites_web_subdomain_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'sites_web_subdomain_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../sites/form/web_subdomain.tform.php', $client_id, $params);
latham's avatar
latham committed
	//* Update a record
	public function sites_web_subdomain_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'sites_web_subdomain_update')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->updateQuery('../sites/form/web_subdomain.tform.php', $client_id, $primary_id, $params);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function sites_web_subdomain_delete($session_id, $primary_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'sites_web_subdomain_delete')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->deleteQuery('../sites/form/web_subdomain.tform.php', $primary_id);
latham's avatar
latham committed
		return $affected_rows;
	}
	// ----------------------------------------------------------------------------------------------------------
	//* Get record details
	public function sites_web_folder_get($session_id, $primary_id)
		if(!$this->checkPerm($session_id, 'sites_web_folder_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('../sites/form/web_folder.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
	//* Add a record
	public function sites_web_folder_add($session_id, $client_id, $params)
		if(!$this->checkPerm($session_id, 'sites_web_folder_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../sites/form/web_folder.tform.php', $client_id, $params);
	//* Update a record
	public function sites_web_folder_update($session_id, $client_id, $primary_id, $params)
		if(!$this->checkPerm($session_id, 'sites_web_folder_update')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->updateQuery('../sites/form/web_folder.tform.php', $client_id, $primary_id, $params);
	//* Delete a record
	public function sites_web_folder_delete($session_id, $primary_id)
		global $app;
		if(!$this->checkPerm($session_id, 'sites_web_folder_delete')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}

		// Delete all users that belong to this folder. - taken from web_folder_delete.php
		$records = $app->db->queryAllRecords("SELECT web_folder_user_id FROM web_folder_user WHERE web_folder_id = '".$app->functions->intval($primary_id)."'");
			$this->deleteQuery('../sites/form/web_folder_user.tform.php', $rec['web_folder_user_id']);
			//$app->db->datalogDelete('web_folder_user','web_folder_user_id',$rec['web_folder_user_id']);
		}
		unset($records);

		$affected_rows = $this->deleteQuery('../sites/form/web_folder.tform.php', $primary_id);
	// -----------------------------------------------------------------------------------------------
	//* Get record details
	public function sites_web_folder_user_get($session_id, $primary_id)
		if(!$this->checkPerm($session_id, 'sites_web_folder_user_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('../sites/form/web_folder_user.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
	//* Add a record
	public function sites_web_folder_user_add($session_id, $client_id, $params)
		if(!$this->checkPerm($session_id, 'sites_web_folder_user_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../sites/form/web_folder_user.tform.php', $client_id, $params);
	//* Update a record
	public function sites_web_folder_user_update($session_id, $client_id, $primary_id, $params)
		if(!$this->checkPerm($session_id, 'sites_web_folder_user_update')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->updateQuery('../sites/form/web_folder_user.tform.php', $client_id, $primary_id, $params);
	//* Delete a record
	public function sites_web_folder_user_delete($session_id, $primary_id)
		if(!$this->checkPerm($session_id, 'sites_web_folder_user_delete')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->deleteQuery('../sites/form/web_folder_user.tform.php', $primary_id);
latham's avatar
latham committed
	// -----------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function domains_domain_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'domains_domain_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('../client/form/domain.tform.php');
latham's avatar
latham committed
		return $app->remoting_lib->getDataRecord($primary_id);
	}

	//* Add a record
	public function domains_domain_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'domains_domain_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../client/form/domain.tform.php', $client_id, $params);
latham's avatar
latham committed
	}

	//* Delete a record
	public function domains_domain_delete($session_id, $primary_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'domains_domain_delete')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		$affected_rows = $this->deleteQuery('../client/form/domain.tform.php', $primary_id);
latham's avatar
latham committed
		return $affected_rows;
	}

	// -----------------------------------------------------------------------------------------------
latham's avatar
latham committed

	public function domains_get_all_by_user($session_id, $group_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'domains_get_all_by_user')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		$group_id = $app->functions->intval($group_id);
		$sql = "SELECT domain_id, domain FROM domain WHERE sys_groupid  = $group_id ";
		$all = $app->db->queryAllRecords($sql);
		return $all;
latham's avatar
latham committed
	// DNS Function --------------------------------------------------------------------------------------------------
	//* Create Zone with Template
	public function dns_templatezone_add($session_id, $client_id, $template_id, $domain, $ip, $ns1, $ns2, $email)
	{
		global $app, $conf;
		if(!$this->checkPerm($session_id, 'dns_templatezone_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		$client = $app->db->queryOneRecord("SELECT default_dnsserver FROM client WHERE client_id = ".$app->functions->intval($client_id));
		$server_id = $client["default_dnsserver"];
		$template_record = $app->db->queryOneRecord("SELECT * FROM dns_template WHERE template_id = '$template_id'");
		$fields = explode(',', $template_record['fields']);
		$tform_def_file = "../../web/dns/form/dns_soa.tform.php";
		$app->uses('tform');
		$app->tform->loadFormDef($tform_def_file);
		$app->uses('tpl,validate_dns');
		//* replace template placeholders
		$tpl_content = $template_record['template'];
		if($domain != '') $tpl_content = str_replace('{DOMAIN}', $domain, $tpl_content);
		if($ip != '') $tpl_content = str_replace('{IP}', $ip, $tpl_content);
		if($ns1 != '') $tpl_content = str_replace('{NS1}', $ns1, $tpl_content);
		if($ns2 != '') $tpl_content = str_replace('{NS2}', $ns2, $tpl_content);
		if($email != '') $tpl_content = str_replace('{EMAIL}', $email, $tpl_content);

		//* Parse the template
		$tpl_rows = explode("\n", $tpl_content);
		$section = '';
		$vars = array();
		$dns_rr = array();
		foreach($tpl_rows as $row) {
			$row = trim($row);
			if(substr($row, 0, 1) == '[') {
				if($row == '[ZONE]') {
					$section = 'zone';
				} elseif($row == '[DNS_RECORDS]') {
					$section = 'dns_records';
				} else {
					die('Unknown section type');
				}
			} else {
				if($row != '') {
					//* Handle zone section
					if($section == 'zone') {
						$parts = explode('=', $row);
						$key = trim($parts[0]);
						$val = trim($parts[1]);
						if($key != '') $vars[$key] = $val;
					}
					//* Handle DNS Record rows
					if($section == 'dns_records') {
						$parts = explode('|', $row);
						$dns_rr[] = array(
							'name' => $app->db->quote($parts[1]),
							'type' => $app->db->quote($parts[0]),
							'data' => $app->db->quote($parts[2]),
							'aux'  => $app->db->quote($parts[3]),
							'ttl'  => $app->db->quote($parts[4])
						);
					}
				}
		} // end foreach
		if($vars['origin'] == '') $error .= $app->lng('error_origin_empty').'<br />';
		if($vars['ns'] == '') $error .= $app->lng('error_ns_empty').'<br />';
		if($vars['mbox'] == '') $error .= $app->lng('error_mbox_empty').'<br />';
		if($vars['refresh'] == '') $error .= $app->lng('error_refresh_empty').'<br />';
		if($vars['retry'] == '') $error .= $app->lng('error_retry_empty').'<br />';
		if($vars['expire'] == '') $error .= $app->lng('error_expire_empty').'<br />';
		if($vars['minimum'] == '') $error .= $app->lng('error_minimum_empty').'<br />';
		if($vars['ttl'] == '') $error .= $app->lng('error_ttl_empty').'<br />';

		if($error == '') {
			// Insert the soa record
			$tmp = $app->db->queryOneRecord("SELECT userid,default_group FROM sys_user WHERE client_id = ".$app->functions->intval($client_id));
			$sys_userid = $tmp['userid'];
			$sys_groupid = $tmp['default_group'];
			unset($tmp);
			$origin = $app->db->quote($vars['origin']);
			$ns = $app->db->quote($vars['ns']);
			$mbox = $app->db->quote(str_replace('@', '.', $vars['mbox']));
			$refresh = $app->db->quote($vars['refresh']);
			$retry = $app->db->quote($vars['retry']);
			$expire = $app->db->quote($vars['expire']);
			$minimum = $app->db->quote($vars['minimum']);
			$ttl = $app->db->quote($vars['ttl']);
			$xfer = $app->db->quote($vars['xfer']);
			$also_notify = $app->db->quote($vars['also_notify']);
			$update_acl = $app->db->quote($vars['update_acl']);
			$serial = $app->validate_dns->increase_serial(0);
			$insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `origin`, `ns`, `mbox`, `serial`, `refresh`, `retry`, `expire`, `minimum`, `ttl`, `active`, `xfer`, `also_notify`, `update_acl`) VALUES
			('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$origin', '$ns', '$mbox', '$serial', '$refresh', '$retry', '$expire', '$minimum', '$ttl', 'Y', '$xfer', '$also_notify', '$update_acl')";
			$dns_soa_id = $app->db->datalogInsert('dns_soa', $insert_data, 'id');
			// Insert the dns_rr records
			if(is_array($dns_rr) && $dns_soa_id > 0) {
				foreach($dns_rr as $rr) {
					$insert_data = "(`sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `server_id`, `zone`, `name`, `type`, `data`, `aux`, `ttl`, `active`) VALUES
					('$sys_userid', '$sys_groupid', 'riud', 'riud', '', '$server_id', '$dns_soa_id', '$rr[name]', '$rr[type]', '$rr[data]', '$rr[aux]', '$rr[ttl]', 'Y')";
					$dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
				}
			}
			exit;
		} else {
			$this->server->fault('permission_denied', $error);
		}
	}
latham's avatar
latham committed
	//* Get record details
	public function dns_zone_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		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;
		}
		$app->uses('remoting_lib');
		$app->remoting_lib->loadFormDef('../dns/form/dns_soa.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}

	//* Get record id by origin
	public function dns_zone_get_id($session_id, $origin)
	{
		global $app;

		if(!$this->checkPerm($session_id, 'dns_zone_get_id')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}

		if(!preg_match('/^[a-z0-9][a-z0-9\-]+[a-z0-9](\.[a-z]{2,4})+$/i', $origin)){
			$this->server->fault('no_domain_found', 'Invalid domain name.');
			return false;
		}

		$rec = $app->db->queryOneRecord("SELECT id FROM dns_soa WHERE origin like '".$origin."%'");
		if(isset($rec['id'])) {
			return $app->functions->intval($rec['id']);
		} else {
			$this->server->fault('no_domain_found', 'There is no domain ID with informed domain name.');
			return false;
		}
	}

latham's avatar
latham committed
	//* Add a record
	public function dns_zone_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_zone_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../dns/form/dns_soa.tform.php', $client_id, $params);
latham's avatar
latham committed
	//* Update a record
	public function dns_zone_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_zone_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_soa.tform.php', $client_id, $primary_id, $params);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function dns_zone_delete($session_id, $primary_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_zone_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_soa.tform.php', $primary_id);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	// ----------------------------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function dns_aaaa_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_aaaa_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_aaaa.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
latham's avatar
latham committed
	//* Add a record
	public function dns_aaaa_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_aaaa_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../dns/form/dns_aaaa.tform.php', $client_id, $params);
latham's avatar
latham committed
	//* Update a record
	public function dns_aaaa_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_aaaa_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_aaaa.tform.php', $client_id, $primary_id, $params);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function dns_aaaa_delete($session_id, $primary_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_aaaa_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_aaaa.tform.php', $primary_id);
latham's avatar
latham committed
		return $affected_rows;
	}

	// ----------------------------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function dns_a_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_a_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_a.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
latham's avatar
latham committed
	//* Add a record
	public function dns_a_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_a_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../dns/form/dns_a.tform.php', $client_id, $params);
latham's avatar
latham committed
	//* Update a record
	public function dns_a_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_a_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_a.tform.php', $client_id, $primary_id, $params);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function dns_a_delete($session_id, $primary_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_a_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_a.tform.php', $primary_id);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	// ----------------------------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function dns_alias_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_alias_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_alias.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
latham's avatar
latham committed
	//* Add a record
	public function dns_alias_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_alias_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../dns/form/dns_alias.tform.php', $client_id, $params);
latham's avatar
latham committed
	//* Update a record
	public function dns_alias_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_alias_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_alias.tform.php', $client_id, $primary_id, $params);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function dns_alias_delete($session_id, $primary_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_alias_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_alias.tform.php', $primary_id);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	// ----------------------------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function dns_cname_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_cname_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_cname.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
latham's avatar
latham committed
	//* Add a record
	public function dns_cname_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_cname_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../dns/form/dns_cname.tform.php', $client_id, $params);
latham's avatar
latham committed
	//* Update a record
	public function dns_cname_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_cname_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_cname.tform.php', $client_id, $primary_id, $params);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function dns_cname_delete($session_id, $primary_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_cname_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_cname.tform.php', $primary_id);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	// ----------------------------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function dns_hinfo_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_hinfo_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_hinfo.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
latham's avatar
latham committed
	//* Add a record
	public function dns_hinfo_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_hinfo_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../dns/form/dns_hinfo.tform.php', $client_id, $params);
latham's avatar
latham committed
	//* Update a record
	public function dns_hinfo_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_hinfo_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_hinfo.tform.php', $client_id, $primary_id, $params);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function dns_hinfo_delete($session_id, $primary_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_hinfo_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_hinfo.tform.php', $primary_id);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	// ----------------------------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function dns_mx_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_mx_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_mx.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
latham's avatar
latham committed
	//* Add a record
	public function dns_mx_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_mx_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../dns/form/dns_mx.tform.php', $client_id, $params);
latham's avatar
latham committed
	//* Update a record
	public function dns_mx_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_mx_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_mx.tform.php', $client_id, $primary_id, $params);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function dns_mx_delete($session_id, $primary_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_mx_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_mx.tform.php', $primary_id);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	// ----------------------------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function dns_ns_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_ns_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_ns.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
latham's avatar
latham committed
	//* Add a record
	public function dns_ns_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_ns_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../dns/form/dns_ns.tform.php', $client_id, $params);
latham's avatar
latham committed
	//* Update a record
	public function dns_ns_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_ns_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_ns.tform.php', $client_id, $primary_id, $params);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function dns_ns_delete($session_id, $primary_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_ns_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_ns.tform.php', $primary_id);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	// ----------------------------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function dns_ptr_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_ptr_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_ptr.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
latham's avatar
latham committed
	//* Add a record
	public function dns_ptr_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_ptr_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../dns/form/dns_ptr.tform.php', $client_id, $params);
latham's avatar
latham committed
	//* Update a record
	public function dns_ptr_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_ptr_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_ptr.tform.php', $client_id, $primary_id, $params);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function dns_ptr_delete($session_id, $primary_id)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_ptr_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_ptr.tform.php', $primary_id);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	// ----------------------------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function dns_rp_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_rp_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_rp.tform.php');
		return $app->remoting_lib->getDataRecord($primary_id);
	}
latham's avatar
latham committed
	//* Add a record
	public function dns_rp_add($session_id, $client_id, $params)
latham's avatar
latham committed
		if(!$this->checkPerm($session_id, 'dns_rp_add')) {
			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
			return false;
		}
		return $this->insertQuery('../dns/form/dns_rp.tform.php', $client_id, $params);
latham's avatar
latham committed
	//* Update a record
	public function dns_rp_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		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);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function dns_rp_delete($session_id, $primary_id)
latham's avatar
latham committed
		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);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	// ----------------------------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function dns_srv_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		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);
	}
latham's avatar
latham committed
	//* Add a record
	public function dns_srv_add($session_id, $client_id, $params)
latham's avatar
latham committed
		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);
latham's avatar
latham committed
	//* Update a record
	public function dns_srv_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		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);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function dns_srv_delete($session_id, $primary_id)
latham's avatar
latham committed
		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);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	// ----------------------------------------------------------------------------------------------------------------
latham's avatar
latham committed
	//* Get record details
	public function dns_txt_get($session_id, $primary_id)
latham's avatar
latham committed
		global $app;
latham's avatar
latham committed
		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);
	}
latham's avatar
latham committed
	//* Add a record
	public function dns_txt_add($session_id, $client_id, $params)
latham's avatar
latham committed
		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);
latham's avatar
latham committed
	//* Update a record
	public function dns_txt_update($session_id, $client_id, $primary_id, $params)
latham's avatar
latham committed
		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);
latham's avatar
latham committed
		return $affected_rows;
	}
latham's avatar
latham committed
	//* Delete a record
	public function dns_txt_delete($session_id, $primary_id)
latham's avatar
latham committed
		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);
latham's avatar
latham committed
		return $affected_rows;
	}
	//** protected functions -----------------------------------------------------------------------------------
	protected function klientadd($formdef_file, $reseller_id, $params)
latham's avatar
latham committed
		$app->uses('remoting_lib');
latham's avatar
latham committed
		//* Load the form definition
		$app->remoting_lib->loadFormDef($formdef_file);
latham's avatar
latham committed
		//* load the user profile of the client
		$app->remoting_lib->loadUserProfile($reseller_id);
latham's avatar
latham committed
		//* Get the SQL query
		$sql = $app->remoting_lib->getSQL($params, 'INSERT', 0);

		//* 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 />";
		//* Stop on error while preparing the sql query
latham's avatar
latham committed
		if($app->remoting_lib->errorMessage != '') {
			$this->server->fault('data_processing_error', $app->remoting_lib->errorMessage);
			return false;