";
}
$optionlist[] = array( media_cat => $kategorie,
media_cat_id => $val->id,
depth => $tiefe);
$this->ptree($val, $tiefe, $optionlist);
}
}
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/custom_datasource.inc.php 0000664 0000000 0000000 00000016125 12600761333 0030273 0 ustar 00root root 0000000 0000000 db->queryAllRecords("SELECT template_id,template_name FROM client_template WHERE template_type ='m' and ".$app->tform->getAuthSQL('r'));
$records_new[0] = $app->lng('Custom');
foreach($records as $rec) {
$key = $rec['template_id'];
$records_new[$key] = $rec['template_name'];
}
return $records_new;
}
function dns_servers($field, $record) {
global $app, $conf;
if($_SESSION["s"]["user"]["typ"] == 'user') {
// Get the limits of the client
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
$client = $app->db->queryOneRecord("SELECT default_dnsserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
$sql = "SELECT server_id,server_name FROM server WHERE server_id = ?";
} else {
$sql = "SELECT server_id,server_name FROM server WHERE dns_server = 1 ORDER BY server_name AND mirror_server_id = 0";
}
$records = $app->db->queryAllRecords($sql, $client['default_dnsserver']);
$records_new = array();
if(is_array($records)) {
foreach($records as $rec) {
$key = $rec['server_id'];
$records_new[$key] = $rec['server_name'];
}
}
return $records_new;
}
function slave_dns_servers($field, $record) {
global $app, $conf;
if($_SESSION["s"]["user"]["typ"] == 'user') {
// Get the limits of the client
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
$client = $app->db->queryOneRecord("SELECT default_slave_dnsserver FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
$sql = "SELECT server_id,server_name FROM server WHERE server_id = ?";
} else {
$sql = "SELECT server_id,server_name FROM server WHERE dns_server = 1 ORDER BY server_name AND mirror_server_id = 0";
}
$records = $app->db->queryAllRecords($sql, $client['default_slave_dnsserver']);
$records_new = array();
if(is_array($records)) {
foreach($records as $rec) {
$key = $rec['server_id'];
$records_new[$key] = $rec['server_name'];
}
}
return $records_new;
}
function webdav_domains($field, $record) {
global $app, $conf;
$servers = $app->db->queryAllRecords("SELECT * FROM server WHERE active = 1 AND mirror_server_id = 0");
$server_ids = array();
$app->uses('getconf');
if(is_array($servers) && !empty($servers)){
foreach($servers as $server){
$web_config = $app->getconf->get_server_config($server['server_id'], 'web');
if($web_config['server_type'] != 'nginx') $server_ids[] = $server['server_id'];
}
}
if(count($server_ids) == 0) return array();
$server_ids = implode(',', $server_ids);
$records = $app->db->queryAllRecords("SELECT web_domain.domain_id, CONCAT(web_domain.domain, ' :: ', server.server_name) AS parent_domain FROM web_domain, server WHERE web_domain.type = 'vhost' AND web_domain.server_id IN (?) AND web_domain.server_id = server.server_id AND ".$app->tform->getAuthSQL('r', 'web_domain')." ORDER BY web_domain.domain", $server_ids);
$records_new = array();
if(is_array($records)) {
foreach($records as $rec) {
$key = $rec['domain_id'];
$records_new[$key] = $rec['parent_domain'];
}
}
return $records_new;
}
function client_servers($field, $record) {
global $app, $conf;
$server_type = $field['name'];
switch($server_type) {
case 'default_mailserver':
$field = 'mail_server';
break;
case 'default_webserver':
$field = 'web_server';
break;
case 'default_dnsserver':
$field = 'dns_server';
break;
case 'default_slave_dnsserver':
$field = 'dns_server';
break;
case 'default_fileserver':
$field = 'file_server';
break;
case 'default_dbserver':
$field = 'db_server';
break;
case 'default_vserverserver':
$field = 'vserver_server';
break;
case 'mail_servers':
$field = 'mail_server';
break;
case 'web_servers':
$field = 'web_server';
break;
case 'dns_servers':
$field = 'dns_server';
break;
case 'db_servers':
$field = 'db_server';
break;
default:
$field = 'web_server';
break;
}
if($_SESSION["s"]["user"]["typ"] == 'user') {
// Get the limits of the client
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
$sql = "SELECT $server_type as server_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?";
$client = $app->db->queryOneRecord($sql, $client_group_id);
if($client['server_id'] > 0) {
//* Select the default server for the client
$sql = "SELECT server_id,server_name FROM server WHERE server_id = ?";
$records = $app->db->queryAllRecords($sql, $client['server_id']);
} else {
//* Not able to find the clients defaults, use this as fallback and add a warning message to the log
$app->log('Unable to find default server for client in custom_datasource.inc.php', 1);
$sql = "SELECT server_id,server_name FROM server WHERE ?? = 1 AND mirror_server_id = 0 ORDER BY server_name";
$records = $app->db->queryAllRecords($sql, $field);
}
} else {
//* The logged in user is admin, so we show him all available servers of a specific type.
$sql = "SELECT server_id,server_name FROM server WHERE ?? = 1 AND mirror_server_id = 0 ORDER BY server_name";
$records = $app->db->queryAllRecords($sql, $field);
}
$records_new = array();
if(is_array($records)) {
foreach($records as $rec) {
$key = $rec['server_id'];
$records_new[$key] = $rec['server_name'];
}
}
return $records_new;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/db_mysql.inc.php 0000664 0000000 0000000 00000104676 12600761333 0026372 0 ustar 00root root 0000000 0000000 dbHost = $conf[$prefix.'db_host'];
$this->dbPort = $conf[$prefix.'db_port'];
$this->dbName = $conf[$prefix.'db_database'];
$this->dbUser = $conf[$prefix.'db_user'];
$this->dbPass = $conf[$prefix.'db_password'];
$this->dbCharset = $conf[$prefix.'db_charset'];
$this->dbNewLink = $conf[$prefix.'db_new_link'];
$this->dbClientFlags = $conf[$prefix.'db_client_flags'];
$this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, '', (int)$this->dbPort);
$try = 0;
while((!is_object($this->_iConnId) || mysqli_connect_error()) && $try < 5) {
if($try > 0) sleep(1);
$try++;
$this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, '', (int)$this->dbPort);
}
if(!is_object($this->_iConnId) || mysqli_connect_error()) {
$this->_iConnId = null;
$this->_sqlerror('Zugriff auf Datenbankserver fehlgeschlagen! / Database server not accessible!');
return false;
}
if(!((bool)mysqli_query( $this->_iConnId, 'USE `' . $this->dbName . '`'))) {
$this->close();
$this->_sqlerror('Datenbank nicht gefunden / Database not found');
return false;
}
$this->_setCharset();
}
public function __destruct() {
if($this->_iConnId) mysqli_close($this->_iConnId);
}
public function close() {
if($this->_iConnId) mysqli_close($this->_iConnId);
$this->_iConnId = null;
}
public function _build_query_string($sQuery = '') {
$iArgs = func_num_args();
if($iArgs > 1) {
$aArgs = func_get_args();
if($iArgs == 3 && $aArgs[1] === true && is_array($aArgs[2])) {
$aArgs = $aArgs[2];
$iArgs = count($aArgs);
} else {
array_shift($aArgs); // delete the query string that is the first arg!
}
$iPos = 0;
$iPos2 = 0;
foreach($aArgs as $sKey => $sValue) {
$iPos2 = strpos($sQuery, '??', $iPos2);
$iPos = strpos($sQuery, '?', $iPos);
if($iPos === false && $iPos2 === false) break;
if($iPos2 !== false && ($iPos === false || $iPos2 <= $iPos)) {
$sTxt = $this->escape($sValue);
$sTxt = str_replace('`', '', $sTxt);
if(strpos($sTxt, '.') !== false) {
$sTxt = preg_replace('/^(.+)\.(.+)$/', '`$1`.`$2`', $sTxt);
$sTxt = str_replace('.`*`', '.*', $sTxt);
} else $sTxt = '`' . $sTxt . '`';
$sQuery = substr_replace($sQuery, $sTxt, $iPos2, 2);
$iPos2 += strlen($sTxt);
$iPos = $iPos2;
} else {
if(is_int($sValue) || is_float($sValue)) {
$sTxt = $sValue;
} elseif(is_null($sValue) || (is_string($sValue) && (strcmp($sValue, '#NULL#') == 0))) {
$sTxt = 'NULL';
} elseif(is_array($sValue)) {
if(isset($sValue['SQL'])) {
$sTxt = $sValue['SQL'];
} else {
$sTxt = '';
foreach($sValue as $sVal) $sTxt .= ',\'' . $this->escape($sVal) . '\'';
$sTxt = '(' . substr($sTxt, 1) . ')';
if($sTxt == '()') $sTxt = '(0)';
}
} else {
$sTxt = '\'' . $this->escape($sValue) . '\'';
}
$sQuery = substr_replace($sQuery, $sTxt, $iPos, 1);
$iPos += strlen($sTxt);
$iPos2 = $iPos;
}
}
}
return $sQuery;
}
/**#@-*/
/**#@+
* @access private
*/
private function _setCharset() {
mysqli_query($this->_iConnId, 'SET NAMES '.$this->dbCharset);
mysqli_query($this->_iConnId, "SET character_set_results = '".$this->dbCharset."', character_set_client = '".$this->dbCharset."', character_set_connection = '".$this->dbCharset."', character_set_database = '".$this->dbCharset."', character_set_server = '".$this->dbCharset."'");
}
private function securityScan($string) {
global $app, $conf;
// get security config
if(isset($app)) {
$app->uses('getconf');
$ids_config = $app->getconf->get_security_config('ids');
if($ids_config['sql_scan_enabled'] == 'yes') {
// Remove whitespace
$string = trim($string);
if(substr($string,-1) == ';') $string = substr($string,0,-1);
// Save original string
$string_orig = $string;
//echo $string;
$chars = array(';', '#', '/*', '*/', '--', '\\\'', '\\"');
$string = str_replace('\\\\', '', $string);
$string = preg_replace('/(^|[^\\\])([\'"])\\2/is', '$1', $string);
$string = preg_replace('/(^|[^\\\])([\'"])(.*?[^\\\])\\2/is', '$1', $string);
$ok = true;
if(substr_count($string, "`") % 2 != 0 || substr_count($string, "'") % 2 != 0 || substr_count($string, '"') % 2 != 0) {
$app->log("SQL injection warning (" . $string_orig . ")",2);
$ok = false;
} else {
foreach($chars as $char) {
if(strpos($string, $char) !== false) {
$ok = false;
$app->log("SQL injection warning (" . $string_orig . ")",2);
break;
}
}
}
if($ok == true) {
return true;
} else {
if($ids_config['sql_scan_action'] == 'warn') {
// we return false in warning level.
return false;
} else {
// if sql action = 'block' or anything else then stop here.
$app->error('Possible SQL injection. All actions have been logged.');
}
}
}
}
}
private function _query($sQuery = '') {
global $app;
if ($sQuery == '') {
$this->_sqlerror('Keine Anfrage angegeben / No query given');
return false;
}
$try = 0;
do {
$try++;
$ok = mysqli_ping($this->_iConnId);
if(!$ok) {
if(!mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass, $this->dbName, (int)$this->dbPort)) {
if($try > 4) {
$this->_sqlerror('DB::query -> reconnect');
return false;
} else {
sleep(1);
}
} else {
$this->_setCharset();
$ok = true;
}
}
} while($ok == false);
$aArgs = func_get_args();
$sQuery = call_user_func_array(array(&$this, '_build_query_string'), $aArgs);
$this->securityScan($sQuery);
$this->_iQueryId = @mysqli_query($this->_iConnId, $sQuery);
if (!$this->_iQueryId) {
$this->_sqlerror('Falsche Anfrage / Wrong Query', 'SQL-Query = ' . $sQuery);
return false;
}
return is_bool($this->_iQueryId) ? $this->_iQueryId : new db_result($this->_iQueryId, $this->_iConnId);
}
/**#@-*/
/**
* Executes a query
*
* Executes a given query string, has a variable amount of parameters:
* - 1 parameter
* executes the given query
* - 2 parameters
* executes the given query, replaces the first ? in the query with the second parameter
* - 3 parameters
* if the 2nd parameter is a boolean true, the 3rd parameter has to be an array containing all the replacements for every occuring ? in the query, otherwise the second parameter replaces the first ?, the third parameter replaces the second ? in the query
* - 4 or more parameters
* all ? in the query are replaced from left to right by the parameters 2 to x
*
* @access public
* @param string $sQuery query string
* @param mixed ... one or more parameters
* @return db_result the result object of the query
*/
public function query($sQuery = '') {
$aArgs = func_get_args();
return call_user_func_array(array(&$this, '_query'), $aArgs);
}
/**
* Execute a query and get first result array
*
* Executes a query and returns the first result row as an array
* This is like calling $result = $db->query(), $result->get(), $result->free()
* Use of this function @see query
*
* @access public
* @param string $sQuery query to execute
* @param ... further params (see query())
* @return array result row or NULL if none found
*/
public function queryOneRecord($sQuery = '') {
if(!preg_match('/limit \d+\s*,\s*\d+$/i', $sQuery)) $sQuery .= ' LIMIT 0,1';
$aArgs = func_get_args();
$oResult = call_user_func_array(array(&$this, 'query'), $aArgs);
if(!$oResult) return null;
$aReturn = $oResult->get();
$oResult->free();
return $aReturn;
}
public function queryOne($sQuery = '') {
return call_user_func_array(array(&$this, 'queryOneRecord'), func_get_args());
}
public function query_one($sQuery = '') {
return call_user_func_array(array(&$this, 'queryOneRecord'), func_get_args());
}
/**
* Execute a query and return all rows
*
* Executes a query and returns all result rows in an array
* Use this with extreme care!!! Uses lots of memory on big result sets.
*
* @access public
* @param string $sQuery query to execute
* @param ... further params (see query())
* @return array all the rows in the result set
*/
public function queryAllRecords($sQuery = '') {
$aArgs = func_get_args();
$oResult = call_user_func_array(array(&$this, 'query'), $aArgs);
if(!$oResult) return array();
$aResults = array();
while($aRow = $oResult->get()) {
$aResults[] = $aRow;
}
$oResult->free();
return $aResults;
}
public function queryAll($sQuery = '') {
return call_user_func_array(array(&$this, 'queryAllRecords'), func_get_args());
}
public function query_all($sQuery = '') {
return call_user_func_array(array(&$this, 'queryAllRecords'), func_get_args());
}
/**
* Execute a query and return all rows as simple array
*
* Executes a query and returns all result rows in an array with elements
* Only first column is returned Uses lots of memory on big result sets.
*
* @access public
* @param string $sQuery query to execute
* @param ... further params (see query())
* @return array all the rows in the result set
*/
public function queryAllArray($sQuery = '') {
$aArgs = func_get_args();
$oResult = call_user_func_array(array(&$this, 'query'), $aArgs);
if(!$oResult) return array();
$aResults = array();
while($aRow = $oResult->get()) {
$aResults[] = reset($aRow);
}
$oResult->free();
return $aResults;
}
public function query_all_array($sQuery = '') {
return $this->queryAllArray($sQuery);
}
/**
* Get id of last inserted row
*
* Gives you the id of the last inserted row in a table with an auto-increment primary key
*
* @access public
* @return int id of last inserted row or 0 if none
*/
public function insert_id() {
$iRes = mysqli_query($this->_iConnId, 'SELECT LAST_INSERT_ID() as `newid`');
if(!is_object($iRes)) return false;
$aReturn = mysqli_fetch_assoc($iRes);
mysqli_free_result($iRes);
return $aReturn['newid'];
}
/**
* get affected row count
*
* Gets the amount of rows affected by the previous query
*
* @access public
* @return int affected rows
*/
public function affected() {
if(!is_object($this->_iConnId)) return 0;
$iRows = mysqli_affected_rows($this->_iConnId);
if(!$iRows) $iRows = 0;
return $iRows;
}
/**
* check if a utf8 string is valid
*
* @access public
* @param string $string the string to check
* @return bool true if it is valid utf8, false otherwise
*/
private function check_utf8($str) {
$len = strlen($str);
for($i = 0; $i < $len; $i++){
$c = ord($str[$i]);
if ($c > 128) {
if (($c > 247)) return false;
elseif ($c > 239) $bytes = 4;
elseif ($c > 223) $bytes = 3;
elseif ($c > 191) $bytes = 2;
else return false;
if (($i + $bytes) > $len) return false;
while ($bytes > 1) {
$i++;
$b = ord($str[$i]);
if ($b < 128 || $b > 191) return false;
$bytes--;
}
}
}
return true;
} // end of check_utf8
/**
* Escape a string for usage in a query
*
* @access public
* @param string $sString query string to escape
* @return string escaped string
*/
public function escape($sString) {
global $app;
if(!is_string($sString) && !is_numeric($sString)) {
$app->log('NON-String given in escape function! (' . gettype($sString) . ')', LOGLEVEL_INFO);
//$sAddMsg = getDebugBacktrace();
$app->log($sAddMsg, LOGLEVEL_DEBUG);
$sString = '';
}
$cur_encoding = mb_detect_encoding($sString);
if($cur_encoding != "UTF-8") {
if($cur_encoding != 'ASCII') {
if(is_object($app) && method_exists($app, 'log')) $app->log('String ' . substr($sString, 0, 25) . '... is ' . $cur_encoding . '.', LOGLEVEL_INFO);
if($cur_encoding) $sString = mb_convert_encoding($sString, 'UTF-8', $cur_encoding);
else $sString = mb_convert_encoding($sString, 'UTF-8');
}
} elseif(!$this->check_utf8($sString)) {
$sString = utf8_encode($sString);
}
if($this->_iConnId) return mysqli_real_escape_string($this->_iConnId, $sString);
else return addslashes($sString);
}
/**
*
*
* @access private
*/
private function _sqlerror($sErrormsg = 'Unbekannter Fehler', $sAddMsg = '') {
global $app, $conf;
$mysql_error = (is_object($this->_iConnId) ? mysqli_error($this->_iConnId) : mysqli_connect_error());
$mysql_errno = (is_object($this->_iConnId) ? mysqli_errno($this->_iConnId) : mysqli_connect_errno());
$this->errorMessage = $mysql_error;
//$sAddMsg .= getDebugBacktrace();
if($this->show_error_messages && $conf['demo_mode'] === false) {
echo $sErrormsg . $sAddMsg;
} else if(is_object($app) && method_exists($app, 'log')) {
$app->log($sErrormsg . $sAddMsg . ' -> ' . $mysql_errno . ' (' . $mysql_error . ')', LOGLEVEL_WARN);
}
}
public function affectedRows() {
return $this->affected();
}
// returns mySQL insert id
public function insertID() {
return $this->insert_id();
}
//* Function to quote strings
public function quote($formfield) {
return $this->escape($formfield);
}
//* Function to unquotae strings
public function unquote($formfield) {
return stripslashes($formfield);
}
public function toLower($record) {
if(is_array($record)) {
foreach($record as $key => $val) {
$key = strtolower($key);
$out[$key] = $val;
}
}
return $out;
}
public function insertFromArray($tablename, $data) {
if(!is_array($data)) return false;
$k_query = '';
$v_query = '';
$params = array($tablename);
$v_params = array();
foreach($data as $key => $value) {
$k_query .= ($k_query != '' ? ', ' : '') . '??';
$v_query .= ($v_query != '' ? ', ' : '') . '?';
$params[] = $key;
$v_params[] = $value;
}
$query = 'INSERT INTO ?? (' . $k_query . ') VALUES (' . $v_query . ')';
return $this->query($query, true, $params + $v_params);
}
public function diffrec($record_old, $record_new) {
$diffrec_full = array();
$diff_num = 0;
if(is_array($record_old) && count($record_old) > 0) {
foreach($record_old as $key => $val) {
// if(!isset($record_new[$key]) || $record_new[$key] != $val) {
if(@$record_new[$key] != $val) {
// Record has changed
$diffrec_full['old'][$key] = $val;
$diffrec_full['new'][$key] = @$record_new[$key];
$diff_num++;
} else {
$diffrec_full['old'][$key] = $val;
$diffrec_full['new'][$key] = $val;
}
}
} elseif(is_array($record_new)) {
foreach($record_new as $key => $val) {
if(isset($record_new[$key]) && @$record_old[$key] != $val) {
// Record has changed
$diffrec_full['new'][$key] = $val;
$diffrec_full['old'][$key] = @$record_old[$key];
$diff_num++;
} else {
$diffrec_full['new'][$key] = $val;
$diffrec_full['old'][$key] = $val;
}
}
}
return array('diff_num' => $diff_num, 'diff_rec' => $diffrec_full);
}
//** Function to fill the datalog with a full differential record.
public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new, $force_update = false) {
global $app, $conf;
// Check fields
if(!preg_match('/^[a-zA-Z0-9\-\_\.]{1,64}$/',$db_table)) $app->error('Invalid table name '.$db_table);
if(!preg_match('/^[a-zA-Z0-9\-\_]{1,64}$/',$primary_field)) $app->error('Invalid primary field '.$primary_field.' in table '.$db_table);
$primary_id = intval($primary_id);
if($force_update == true) {
//* We force a update even if no record has changed
$diffrec_full = array('new' => $record_new, 'old' => $record_old);
$diff_num = count($record_new);
} else {
//* get the difference record between old and new record
$tmp = $this->diffrec($record_old, $record_new);
$diffrec_full = $tmp['diff_rec'];
$diff_num = $tmp['diff_num'];
unset($tmp);
}
// Insert the server_id, if the record has a server_id
$server_id = (isset($record_old['server_id']) && $record_old['server_id'] > 0)?$record_old['server_id']:0;
if(isset($record_new['server_id'])) $server_id = $record_new['server_id'];
if($diff_num > 0) {
//print_r($diff_num);
//print_r($diffrec_full);
$diffstr = serialize($diffrec_full);
$username = $_SESSION['s']['user']['username'];
$dbidx = $primary_field.':'.$primary_id;
if($action == 'INSERT') $action = 'i';
if($action == 'UPDATE') $action = 'u';
if($action == 'DELETE') $action = 'd';
$sql = "INSERT INTO sys_datalog (dbtable,dbidx,server_id,action,tstamp,user,data) VALUES (?, ?, ?, ?, ?, ?, ?)";
$app->db->query($sql, $db_table, $dbidx, $server_id, $action, time(), $username, $diffstr);
}
return true;
}
//** Inserts a record and saves the changes into the datalog
public function datalogInsert($tablename, $insert_data, $index_field) {
global $app;
// Check fields
if(!preg_match('/^[a-zA-Z0-9\-\_\.]{1,64}$/',$tablename)) $app->error('Invalid table name '.$tablename);
if(!preg_match('/^[a-zA-Z0-9\-\_]{1,64}$/',$index_field)) $app->error('Invalid index field '.$index_field.' in table '.$tablename);
if(is_array($insert_data)) {
$key_str = '';
$val_str = '';
$params = array($tablename);
$v_params = array();
foreach($insert_data as $key => $val) {
$key_str .= '??,';
$params[] = $key;
$val_str .= '?,';
$v_params[] = $val;
}
$key_str = substr($key_str, 0, -1);
$val_str = substr($val_str, 0, -1);
$insert_data_str = '('.$key_str.') VALUES ('.$val_str.')';
$this->query("INSERT INTO ?? $insert_data_str", true, array_merge($params, $v_params));
} else {
/* TODO: deprecate this method! */
$insert_data_str = $insert_data;
$this->query("INSERT INTO ?? $insert_data_str", $tablename);
$app->log("deprecated use of passing values to datalogInsert() - table " . $tablename, 1);
}
$old_rec = array();
$index_value = $this->insertID();
$new_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ? = ?", $tablename, $index_field, $index_value);
$this->datalogSave($tablename, 'INSERT', $index_field, $index_value, $old_rec, $new_rec);
return $index_value;
}
//** Updates a record and saves the changes into the datalog
public function datalogUpdate($tablename, $update_data, $index_field, $index_value, $force_update = false) {
global $app;
// Check fields
if(!preg_match('/^[a-zA-Z0-9\-\_\.]{1,64}$/',$tablename)) $app->error('Invalid table name '.$tablename);
if(!preg_match('/^[a-zA-Z0-9\-\_]{1,64}$/',$index_field)) $app->error('Invalid index field '.$index_field.' in table '.$tablename);
$old_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
if(is_array($update_data)) {
$params = array($tablename);
$update_data_str = '';
foreach($update_data as $key => $val) {
$update_data_str .= '?? = ?,';
$params[] = $key;
$params[] = $val;
}
$params[] = $index_field;
$params[] = $index_value;
$update_data_str = substr($update_data_str, 0, -1);
$this->query("UPDATE ?? SET $update_data_str WHERE ?? = ?", true, $params);
} else {
/* TODO: deprecate this method! */
$update_data_str = $update_data;
$this->query("UPDATE ?? SET $update_data_str WHERE ?? = ?", $tablename, $index_field, $index_value);
$app->log("deprecated use of passing values to datalogUpdate() - table " . $tablename, 1);
}
$new_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
$this->datalogSave($tablename, 'UPDATE', $index_field, $index_value, $old_rec, $new_rec, $force_update);
return true;
}
//** Deletes a record and saves the changes into the datalog
public function datalogDelete($tablename, $index_field, $index_value) {
global $app;
// Check fields
if(!preg_match('/^[a-zA-Z0-9\-\_\.]{1,64}$/',$tablename)) $app->error('Invalid table name '.$tablename);
if(!preg_match('/^[a-zA-Z0-9\-\_]{1,64}$/',$index_field)) $app->error('Invalid index field '.$index_field.' in table '.$tablename);
$old_rec = $this->queryOneRecord("SELECT * FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
$this->query("DELETE FROM ?? WHERE ?? = ?", $tablename, $index_field, $index_value);
$new_rec = array();
$this->datalogSave($tablename, 'DELETE', $index_field, $index_value, $old_rec, $new_rec);
return true;
}
//* get the current datalog status for the specified login (or currently logged in user)
public function datalogStatus($login = '') {
global $app;
$return = array('count' => 0, 'entries' => array());
if($_SESSION['s']['user']['typ'] == 'admin') return $return; // these information should not be displayed to admin users
if($login == '' && isset($_SESSION['s']['user'])) {
$login = $_SESSION['s']['user']['username'];
}
$result = $this->queryAllRecords("SELECT COUNT( * ) AS cnt, sys_datalog.action, sys_datalog.dbtable FROM sys_datalog, server WHERE server.server_id = sys_datalog.server_id AND sys_datalog.user = ? AND sys_datalog.datalog_id > server.updated GROUP BY sys_datalog.dbtable, sys_datalog.action", $login);
foreach($result as $row) {
if(!$row['dbtable'] || in_array($row['dbtable'], array('aps_instances', 'aps_instances_settings', 'mail_access', 'mail_content_filter'))) continue; // ignore some entries, maybe more to come
$return['entries'][] = array('table' => $row['dbtable'], 'action' => $row['action'], 'count' => $row['cnt'], 'text' => $app->lng('datalog_status_' . $row['action'] . '_' . $row['dbtable']));
$return['count'] += $row['cnt'];
}
unset($result);
return $return;
}
/*
$columns = array(action => add | alter | drop
name => Spaltenname
name_new => neuer Spaltenname, nur bei 'alter' belegt
type => 42go-Meta-Type: int16, int32, int64, double, char, varchar, text, blob
typeValue => Wert z.B. bei Varchar
defaultValue => Default Wert
notNull => true | false
autoInc => true | false
option => unique | primary | index)
*/
public function createTable($table_name, $columns) {
$index = '';
$sql = "CREATE TABLE ?? (";
foreach($columns as $col){
$sql .= $col['name'].' '.$this->mapType($col['type'], $col['typeValue']).' ';
if($col['defaultValue'] != '') $sql .= "DEFAULT '".$col['defaultValue']."' ";
if($col['notNull'] == true) {
$sql .= 'NOT NULL ';
} else {
$sql .= 'NULL ';
}
if($col['autoInc'] == true) $sql .= 'auto_increment ';
$sql.= ',';
// key Definitionen
if($col['option'] == 'primary') $index .= 'PRIMARY KEY ('.$col['name'].'),';
if($col['option'] == 'index') $index .= 'INDEX ('.$col['name'].'),';
if($col['option'] == 'unique') $index .= 'UNIQUE ('.$col['name'].'),';
}
$sql .= $index;
$sql = substr($sql, 0, -1);
$sql .= ')';
/* TODO: secure parameters */
$this->query($sql, $table_name);
return true;
}
/*
$columns = array(action => add | alter | drop
name => Spaltenname
name_new => neuer Spaltenname, nur bei 'alter' belegt
type => 42go-Meta-Type: int16, int32, int64, double, char, varchar, text, blob
typeValue => Wert z.B. bei Varchar
defaultValue => Default Wert
notNull => true | false
autoInc => true | false
option => unique | primary | index)
*/
public function alterTable($table_name, $columns) {
$index = '';
$sql = "ALTER TABLE ?? ";
foreach($columns as $col){
if($col['action'] == 'add') {
$sql .= 'ADD '.$col['name'].' '.$this->mapType($col['type'], $col['typeValue']).' ';
} elseif ($col['action'] == 'alter') {
$sql .= 'CHANGE '.$col['name'].' '.$col['name_new'].' '.$this->mapType($col['type'], $col['typeValue']).' ';
} elseif ($col['action'] == 'drop') {
$sql .= 'DROP '.$col['name'].' ';
}
if($col['action'] != 'drop') {
if($col['defaultValue'] != '') $sql .= "DEFAULT '".$col['defaultValue']."' ";
if($col['notNull'] == true) {
$sql .= 'NOT NULL ';
} else {
$sql .= 'NULL ';
}
if($col['autoInc'] == true) $sql .= 'auto_increment ';
$sql.= ',';
// Index definitions
if($col['option'] == 'primary') $index .= 'PRIMARY KEY ('.$col['name'].'),';
if($col['option'] == 'index') $index .= 'INDEX ('.$col['name'].'),';
if($col['option'] == 'unique') $index .= 'UNIQUE ('.$col['name'].'),';
}
}
$sql .= $index;
$sql = substr($sql, 0, -1);
/* TODO: secure parameters */
//die($sql);
$this->query($sql, $table_name);
return true;
}
public function dropTable($table_name) {
$this->check($table_name);
$sql = "DROP TABLE ??";
return $this->query($sql, $table_name);
}
// gibt Array mit Tabellennamen zur�ck
public function getTables($database_name = '') {
if(!is_object($this->_iConnId)) return false;
if($database_name == '') $database_name = $this->dbName;
$tb_names = $this->queryAllArray("SHOW TABLES FROM ??", $database_name);
return $tb_names;
}
// gibt Feldinformationen zur Tabelle zur�ck
/*
$columns = array(action => add | alter | drop
name => Spaltenname
name_new => neuer Spaltenname, nur bei 'alter' belegt
type => 42go-Meta-Type: int16, int32, int64, double, char, varchar, text, blob
typeValue => Wert z.B. bei Varchar
defaultValue => Default Wert
notNull => true | false
autoInc => true | false
option => unique | primary | index)
*/
function tableInfo($table_name) {
global $go_api, $go_info, $app;
// Tabellenfelder einlesen
if($rows = $app->db->queryAllRecords('SHOW FIELDS FROM ??', $table_name)){
foreach($rows as $row) {
/*
$name = $row[0];
$default = $row[4];
$key = $row[3];
$extra = $row[5];
$isnull = $row[2];
$type = $row[1];
*/
$name = $row['Field'];
$default = $row['Default'];
$key = $row['Key'];
$extra = $row['Extra'];
$isnull = $row['Null'];
$type = $row['Type'];
$column = array();
$column['name'] = $name;
//$column['type'] = $type;
$column['defaultValue'] = $default;
if(stristr($key, 'PRI')) $column['option'] = 'primary';
if(stristr($isnull, 'YES')) {
$column['notNull'] = false;
} else {
$column['notNull'] = true;
}
if($extra == 'auto_increment') $column['autoInc'] = true;
// Type in Metatype umsetzen
if(stristr($type, 'int(')) $metaType = 'int32';
if(stristr($type, 'bigint')) $metaType = 'int64';
if(stristr($type, 'char')) {
$metaType = 'char';
$tmp_typeValue = explode('(', $type);
$column['typeValue'] = substr($tmp_typeValue[1], 0, -1);
}
if(stristr($type, 'varchar')) {
$metaType = 'varchar';
$tmp_typeValue = explode('(', $type);
$column['typeValue'] = substr($tmp_typeValue[1], 0, -1);
}
if(stristr($type, 'text')) $metaType = 'text';
if(stristr($type, 'double')) $metaType = 'double';
if(stristr($type, 'blob')) $metaType = 'blob';
$column['type'] = $metaType;
$columns[] = $column;
}
return $columns;
} else {
return false;
}
//$this->createTable('tester',$columns);
/*
$result = mysql_list_fields($go_info["server"]["db_name"],$table_name);
$fields = mysql_num_fields ($result);
$i = 0;
$table = mysql_field_table ($result, $i);
while ($i < $fields) {
$name = mysql_field_name ($result, $i);
$type = mysql_field_type ($result, $i);
$len = mysql_field_len ($result, $i);
$flags = mysql_field_flags ($result, $i);
print_r($flags);
$columns = array(name => $name,
type => "",
defaultValue => "",
isnull => 1,
option => "");
$returnvar[] = $columns;
$i++;
}
*/
}
public function mapType($metaType, $typeValue) {
global $go_api;
$metaType = strtolower($metaType);
switch ($metaType) {
case 'int16':
return 'smallint';
break;
case 'int32':
return 'int';
break;
case 'int64':
return 'bigint';
break;
case 'double':
return 'double';
break;
case 'char':
return 'char';
break;
case 'varchar':
if($typeValue < 1) die('Database failure: Lenght required for these data types.');
return 'varchar('.$typeValue.')';
break;
case 'text':
return 'text';
break;
case 'blob':
return 'blob';
break;
case 'date':
return 'date';
break;
}
}
}
/**
* database query result class
*
* @package pxFramework
*
*/
class db_result {
/**
*
*
* @access private
*/
private $_iResId = null;
private $_iConnection = null;
/**
*
*
* @access private
*/
public function db_result($iResId, $iConnection) {
$this->_iResId = $iResId;
$this->_iConnection = $iConnection;
}
/**
* get count of result rows
*
* Returns the amount of rows in the result set
*
* @access public
* @return int amount of rows
*/
public function rows() {
if(!is_object($this->_iResId)) return 0;
$iRows = mysqli_num_rows($this->_iResId);
if(!$iRows) $iRows = 0;
return $iRows;
}
/**
* Get number of affected rows
*
* Returns the amount of rows affected by the previous query
*
* @access public
* @return int amount of affected rows
*/
public function affected() {
if(!is_object($this->_iConnection)) return 0;
$iRows = mysqli_affected_rows($this->_iConnection);
if(!$iRows) $iRows = 0;
return $iRows;
}
/**
* Frees the result set
*
* @access public
*/
public function free() {
if(!is_object($this->_iResId)) return;
mysqli_free_result($this->_iResId);
return;
}
/**
* Get a result row (associative)
*
* Returns the next row in the result set. To be used in a while loop like while($currow = $result->get()) { do something ... }
*
* @access public
* @return array result row
*/
public function get() {
$aItem = null;
if(is_object($this->_iResId)) {
$aItem = mysqli_fetch_assoc($this->_iResId);
if(!$aItem) $aItem = null;
}
return $aItem;
}
/**
* Get a result row (array with numeric index)
*
* @access public
* @return array result row
*/
public function getAsRow() {
$aItem = null;
if(is_object($this->_iResId)) {
$aItem = mysqli_fetch_row($this->_iResId);
if(!$aItem) $aItem = null;
}
return $aItem;
}
}
/**
* database query result class
*
* emulates a db result set out of an array so you can use array results and db results the same way
*
* @package pxFramework
* @see db_result
*
*
*/
class fakedb_result {
/**
*
*
* @access private
*/
private $aResultData = array();
/**
*
*
* @access private
*/
private $aLimitedData = array();
/**
*
*
* @access private
*/
public function fakedb_result($aData) {
$this->aResultData = $aData;
$this->aLimitedData = $aData;
reset($this->aLimitedData);
}
/**
* get count of result rows
*
* Returns the amount of rows in the result set
*
* @access public
* @return int amount of rows
*/
// Gibt die Anzahl Zeilen zurück
public function rows() {
return count($this->aLimitedData);
}
/**
* Frees the result set
*
* @access public
*/
// Gibt ein Ergebnisset frei
public function free() {
$this->aResultData = array();
$this->aLimitedData = array();
return;
}
/**
* Get a result row (associative)
*
* Returns the next row in the result set. To be used in a while loop like while($currow = $result->get()) { do something ... }
*
* @access public
* @return array result row
*/
// Gibt eine Ergebniszeile zurück
public function get() {
$aItem = null;
if(!is_array($this->aLimitedData)) return $aItem;
if(list($vKey, $aItem) = each($this->aLimitedData)) {
if(!$aItem) $aItem = null;
}
return $aItem;
}
/**
* Get a result row (array with numeric index)
*
* @access public
* @return array result row
*/
public function getAsRow() {
return $this->get();
}
/**
* Limit the result (like a LIMIT x,y in a SQL query)
*
* @access public
* @param int $iStart offset to start read
* @param int iLength amount of datasets to read
*/
public function limit_result($iStart, $iLength) {
$this->aLimitedData = array_slice($this->aResultData, $iStart, $iLength, true);
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/functions.inc.php 0000664 0000000 0000000 00000033410 12600761333 0026553 0 ustar 00root root 0000000 0000000 error("Mail sending disabled in demo mode.");
$app->uses('getconf,ispcmail');
$mail_config = $app->getconf->get_global_config('mail');
if($mail_config['smtp_enabled'] == 'y') {
$mail_config['use_smtp'] = true;
$app->ispcmail->setOptions($mail_config);
}
$app->ispcmail->setSender($from, $from_name);
$app->ispcmail->setSubject($subject);
$app->ispcmail->setMailText($text);
if($filepath != '') {
if(!file_exists($filepath)) $app->error("Mail attachement does not exist ".$filepath);
$app->ispcmail->readAttachFile($filepath);
}
if($cc != '') $app->ispcmail->setHeader('Cc', $cc);
if($bcc != '') $app->ispcmail->setHeader('Bcc', $bcc);
$app->ispcmail->send($to);
$app->ispcmail->finish();
return true;
}
public function array_merge($array1, $array2) {
$out = $array1;
foreach($array2 as $key => $val) {
$out[$key] = $val;
}
return $out;
}
public function currency_format($number, $view = '') {
global $app;
if($view != '') $number_format_decimals = (int)$app->lng('number_format_decimals_'.$view);
if(!$number_format_decimals) $number_format_decimals = (int)$app->lng('number_format_decimals');
$number_format_dec_point = $app->lng('number_format_dec_point');
$number_format_thousands_sep = $app->lng('number_format_thousands_sep');
if($number_format_thousands_sep == 'number_format_thousands_sep') $number_format_thousands_sep = '';
return number_format((double)$number, $number_format_decimals, $number_format_dec_point, $number_format_thousands_sep);
}
//* convert currency formatted number back to floating number
public function currency_unformat($number) {
global $app;
$number_format_dec_point = $app->lng('number_format_dec_point');
$number_format_thousands_sep = $app->lng('number_format_thousands_sep');
if($number_format_thousands_sep == 'number_format_thousands_sep') $number_format_thousands_sep = '';
if($number_format_thousands_sep != '') $number = str_replace($number_format_thousands_sep, '', $number);
if($number_format_dec_point != '.' && $number_format_dec_point != '') $number = str_replace($number_format_dec_point, '.', $number);
return (double)$number;
}
public function get_ispconfig_url() {
global $app;
$url = (stristr($_SERVER['SERVER_PROTOCOL'], 'HTTPS') || stristr($_SERVER['HTTPS'], 'on'))?'https':'http';
if($_SERVER['SERVER_NAME'] != '_') {
$url .= '://'.$_SERVER['SERVER_NAME'];
if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
$url .= ':'.$_SERVER['SERVER_PORT'];
}
} else {
$app->uses("getconf");
$server_config = $app->getconf->get_server_config(1, 'server');
$url .= '://'.$server_config['hostname'];
if($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
$url .= ':'.$_SERVER['SERVER_PORT'];
}
}
return $url;
}
public function json_encode($data) {
if(!function_exists('json_encode')){
if(is_array($data) || is_object($data)){
$islist = is_array($data) && (empty($data) || array_keys($data) === range(0, count($data)-1));
if($islist){
$json = '[' . implode(',', array_map(array($this, "json_encode"), $data) ) . ']';
} else {
$items = array();
foreach( $data as $key => $value ) {
$items[] = $this->json_encode("$key") . ':' . $this->json_encode($value);
}
$json = '{' . implode(',', $items) . '}';
}
} elseif(is_string($data)){
// Escape non-printable or Non-ASCII characters.
// I also put the \\ character first, as suggested in comments on the 'addclashes' page.
$string = '"'.addcslashes($data, "\\\"\n\r\t/".chr(8).chr(12)).'"';
$json = '';
$len = strlen($string);
// Convert UTF-8 to Hexadecimal Codepoints.
for($i = 0; $i < $len; $i++){
$char = $string[$i];
$c1 = ord($char);
// Single byte;
if($c1 <128){
$json .= ($c1 > 31) ? $char : sprintf("\\u%04x", $c1);
continue;
}
// Double byte
$c2 = ord($string[++$i]);
if(($c1 & 32) === 0){
$json .= sprintf("\\u%04x", ($c1 - 192) * 64 + $c2 - 128);
continue;
}
// Triple
$c3 = ord($string[++$i]);
if(($c1 & 16) === 0){
$json .= sprintf("\\u%04x", (($c1 - 224) <<12) + (($c2 - 128) << 6) + ($c3 - 128));
continue;
}
// Quadruple
$c4 = ord($string[++$i]);
if(($c1 & 8) === 0){
$u = (($c1 & 15) << 2) + (($c2>>4) & 3) - 1;
$w1 = (54<<10) + ($u<<6) + (($c2 & 15) << 2) + (($c3>>4) & 3);
$w2 = (55<<10) + (($c3 & 15)<<6) + ($c4-128);
$json .= sprintf("\\u%04x\\u%04x", $w1, $w2);
}
}
} else {
// int, floats, bools, null
$json = strtolower(var_export($data, true));
}
return $json;
} else {
return json_encode($data);
}
}
public function suggest_ips($type = 'IPv4'){
global $app;
if($type == 'IPv4'){
// $regex = "/^[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}(\.)[0-9]{1,3}$/";
$regex = "/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/";
} else {
// IPv6
$regex = "/^(\:\:([a-f0-9]{1,4}\:){0,6}?[a-f0-9]{0,4}|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){0,6}?\:\:|[a-f0-9]{1,4}(\:[a-f0-9]{1,4}){1,6}?\:\:([a-f0-9]{1,4}\:){1,6}?[a-f0-9]{1,4})(\/\d{1,3})?$/i";
}
$server_by_id = array();
$server_by_ip = array();
$servers = $app->db->queryAllRecords("SELECT * FROM server");
if(is_array($servers) && !empty($servers)){
foreach($servers as $server){
$server_by_id[$server['server_id']] = $server['server_name'];
}
}
$ips = array();
$results = $app->db->queryAllRecords("SELECT ip_address AS ip, server_id FROM server_ip WHERE ip_type = ?", $type);
if(!empty($results) && is_array($results)){
foreach($results as $result){
if(preg_match($regex, $result['ip'])){
$ips[] = $result['ip'];
$server_by_ip[$result['ip']] = $server_by_id[$result['server_id']];
}
}
}
$results = $app->db->queryAllRecords("SELECT ip_address AS ip FROM openvz_ip");
if(!empty($results) && is_array($results)){
foreach($results as $result){
if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
}
}
$results = $app->db->queryAllRecords("SELECT data AS ip FROM dns_rr WHERE type = 'A' OR type = 'AAAA'");
if(!empty($results) && is_array($results)){
foreach($results as $result){
if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
}
}
$results = $app->db->queryAllRecords("SELECT ns AS ip FROM dns_slave");
if(!empty($results) && is_array($results)){
foreach($results as $result){
if(preg_match($regex, $result['ip'])) $ips[] = $result['ip'];
}
}
$results = $app->db->queryAllRecords("SELECT remote_ips FROM web_database WHERE remote_ips != ''");
if(!empty($results) && is_array($results)){
foreach($results as $result){
$tmp_ips = explode(',', $result['remote_ips']);
foreach($tmp_ips as $tmp_ip){
$tmp_ip = trim($tmp_ip);
if(preg_match($regex, $tmp_ip)) $ips[] = $tmp_ip;
}
}
}
$ips = array_unique($ips);
sort($ips, SORT_NUMERIC);
$result_array = array('cheader' => array(), 'cdata' => array());
if(!empty($ips)){
$result_array['cheader'] = array('title' => 'IPs',
'total' => count($ips),
'limit' => count($ips)
);
foreach($ips as $ip){
$result_array['cdata'][] = array( 'title' => $ip,
'description' => $type.($server_by_ip[$ip] != ''? ' > '.$server_by_ip[$ip] : ''),
'onclick' => '',
'fill_text' => $ip
);
}
}
return $result_array;
}
public function intval($string, $force_numeric = false) {
if(intval($string) == 2147483647 || ($string > 0 && intval($string) < 0)) {
if($force_numeric == true) return floatval($string);
elseif(preg_match('/^([-]?)[0]*([1-9][0-9]*)([^0-9].*)*$/', $string, $match)) return $match[1].$match[2];
else return 0;
} else {
return intval($string);
}
}
/**
* Function to change bytes to kB, MB, GB or TB
* @param int $size - size in bytes
* @param int precicion - after-comma-numbers (default: 2)
* @return string - formated bytes
*/
public function formatBytes($size, $precision = 2) {
$base=log($size)/log(1024);
$suffixes=array('', ' kB', ' MB', ' GB', ' TB');
return round(pow(1024, $base-floor($base)), $precision).$suffixes[floor($base)];
}
/** IDN converter wrapper.
* all converter classes should be placed in ISPC_CLASS_PATH.'/idn/'
*/
private function _idn_encode_decode($domain, $encode = true) {
if($domain == '') return '';
if(preg_match('/^[0-9\.]+$/', $domain)) return $domain; // may be an ip address - anyway does not need to bee encoded
// get domain and user part if it is an email
$user_part = false;
if(strpos($domain, '@') !== false) {
$user_part = substr($domain, 0, strrpos($domain, '@'));
$domain = substr($domain, strrpos($domain, '@') + 1);
}
if($encode == true) {
if(function_exists('idn_to_ascii')) {
$domain = idn_to_ascii($domain, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
} elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) {
/* use idna class:
* @author Matthias Sommerfeld
* @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de
* @version 0.8.0 2011-03-11
*/
if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') {
include_once ISPC_CLASS_PATH.'/idn/idna_convert.class.php';
$this->idn_converter = new idna_convert(array('idn_version' => 2008));
$this->idn_converter_name = 'idna_convert.class';
}
$domain = $this->idn_converter->encode($domain);
}
} else {
if(function_exists('idn_to_utf8')) {
$domain = idn_to_utf8($domain, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
} elseif(file_exists(ISPC_CLASS_PATH.'/idn/idna_convert.class.php')) {
/* use idna class:
* @author Matthias Sommerfeld
* @copyright 2004-2011 phlyLabs Berlin, http://phlylabs.de
* @version 0.8.0 2011-03-11
*/
if(!is_object($this->idn_converter) || $this->idn_converter_name != 'idna_convert.class') {
include_once ISPC_CLASS_PATH.'/idn/idna_convert.class.php';
$this->idn_converter = new idna_convert(array('idn_version' => 2008));
$this->idn_converter_name = 'idna_convert.class';
}
$domain = $this->idn_converter->decode($domain);
}
}
if($user_part !== false) return $user_part . '@' . $domain;
else return $domain;
}
public function idn_encode($domain) {
$domains = explode("\n", $domain);
for($d = 0; $d < count($domains); $d++) {
$domains[$d] = $this->_idn_encode_decode($domains[$d], true);
}
return implode("\n", $domains);
}
public function idn_decode($domain) {
$domains = explode("\n", $domain);
for($d = 0; $d < count($domains); $d++) {
$domains[$d] = $this->_idn_encode_decode($domains[$d], false);
}
return implode("\n", $domains);
}
public function is_allowed_user($username, $restrict_names = false) {
global $app;
$name_blacklist = array('root','ispconfig','vmail','getmail');
if(in_array($username,$name_blacklist)) return false;
if(preg_match('/^[a-zA-Z0-9\.\-_]{1,32}$/', $username) == false) return false;
if($restrict_names == true && preg_match('/^web\d+$/', $username) == false) return false;
return true;
}
public function is_allowed_group($groupname, $restrict_names = false) {
global $app;
$name_blacklist = array('root','ispconfig','vmail','getmail');
if(in_array($groupname,$name_blacklist)) return false;
if(preg_match('/^[a-zA-Z0-9\.\-_]{1,32}$/', $groupname) == false) return false;
if($restrict_names == true && preg_match('/^client\d+$/', $groupname) == false) return false;
return true;
}
public function getimagesizefromstring($string){
if (!function_exists('getimagesizefromstring')) {
$uri = 'data://application/octet-stream;base64,' . base64_encode($string);
return getimagesize($uri);
} else {
return getimagesizefromstring($string);
}
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/getconf.inc.php 0000664 0000000 0000000 00000006257 12600761333 0026201 0 ustar 00root root 0000000 0000000 config[$server_id])) {
$app->uses('ini_parser');
$server_id = $app->functions->intval($server_id);
$server = $app->db->queryOneRecord('SELECT config FROM server WHERE server_id = ?', $server_id);
$this->config[$server_id] = $app->ini_parser->parse_ini_string(stripslashes($server['config']));
}
return ($section == '') ? $this->config[$server_id] : $this->config[$server_id][$section];
}
public function get_global_config($section = '') {
global $app;
if(!isset($this->config['global'])) {
$app->uses('ini_parser');
$tmp = $app->db->queryOneRecord('SELECT config FROM sys_ini WHERE sysini_id = 1');
$this->config['global'] = $app->ini_parser->parse_ini_string(stripslashes($tmp['config']));
}
return ($section == '') ? $this->config['global'] : $this->config['global'][$section];
}
// Function has been moved to $app->get_security_config($section)
public function get_security_config($section = '') {
global $app;
if(is_array($this->security_config)) {
return ($section == '') ? $this->security_config : $this->security_config[$section];
} else {
$app->uses('ini_parser');
$security_config_path = '/usr/local/ispconfig/security/security_settings.ini';
if(!is_file($security_config_path)) $security_config_path = realpath(ISPC_ROOT_PATH.'/../security/security_settings.ini');
$this->security_config = $app->ini_parser->parse_ini_string(file_get_contents($security_config_path));
return ($section == '') ? $this->security_config : $this->security_config[$section];
}
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/idn/ 0000775 0000000 0000000 00000000000 12600761333 0024033 5 ustar 00root root 0000000 0000000 ispconfig3-master-interface-lib/interface/lib/classes/idn/empty.dir 0000664 0000000 0000000 00000000055 12600761333 0025671 0 ustar 00root root 0000000 0000000 This empty directory is needed by ISPConfig.
ispconfig3-master-interface-lib/interface/lib/classes/ids.inc.php 0000664 0000000 0000000 00000012474 12600761333 0025331 0 ustar 00root root 0000000 0000000 getconf->get_security_config('ids');
set_include_path(
get_include_path()
. PATH_SEPARATOR
. ISPC_CLASS_PATH.'/'
);
require_once(ISPC_CLASS_PATH.'/IDS/Init.php');
require_once(ISPC_CLASS_PATH.'/IDS/Monitor.php');
require_once(ISPC_CLASS_PATH.'/IDS/Filter.php');
require_once(ISPC_CLASS_PATH.'/IDS/Filter/Storage.php');
require_once(ISPC_CLASS_PATH.'/IDS/Report.php');
require_once(ISPC_CLASS_PATH.'/IDS/Event.php');
require_once(ISPC_CLASS_PATH.'/IDS/Converter.php');
$ids_request = array(
'GET' => $_GET,
'POST' => $_POST,
'COOKIE' => $_COOKIE
);
$ids_init = IDS\Init::init(ISPC_CLASS_PATH.'/IDS/Config/Config.ini.php');
$ids_init->config['General']['base_path'] = ISPC_CLASS_PATH.'/IDS/';
$ids_init->config['General']['tmp_path'] = '../../../temp';
$ids_init->config['General']['use_base_path'] = true;
$ids_init->config['Caching']['caching'] = 'none';
$ids_init->config['Logging']['path'] = '../../../temp/ids.log';
$current_script_name = trim($_SERVER['SCRIPT_NAME']);
// Get whitelist
$whitelist_path = '/usr/local/ispconfig/security/ids.whitelist';
if(is_file('/usr/local/ispconfig/security/ids.whitelist.custom')) $whitelist_path = '/usr/local/ispconfig/security/ids.whitelist.custom';
if(!is_file($whitelist_path)) $whitelist_path = realpath(ISPC_ROOT_PATH.'/../security/ids.whitelist');
$whitelist_lines = file($whitelist_path);
if(is_array($whitelist_lines)) {
foreach($whitelist_lines as $line) {
$line = trim($line);
if(substr($line,0,1) != '#') {
list($user,$path,$varname) = explode(':',$line);
if($current_script_name == $path) {
if($user = 'any'
|| ($user == 'user' && ($_SESSION['s']['user']['typ'] == 'user' || $_SESSION['s']['user']['typ'] == 'admin'))
|| ($user == 'admin' && $_SESSION['s']['user']['typ'] == 'admin')) {
$ids_init->config['General']['exceptions'][] = $varname;
}
}
}
}
}
// Get HTML fields
$htmlfield_path = '/usr/local/ispconfig/security/ids.htmlfield';
if(is_file('/usr/local/ispconfig/security/ids.htmlfield.custom')) $htmlfield_path = '/usr/local/ispconfig/security/ids.htmlfield.custom';
if(!is_file($htmlfield_path)) $htmlfield_path = realpath(ISPC_ROOT_PATH.'/../security/ids.htmlfield');
$htmlfield_lines = file($htmlfield_path);
if(is_array($htmlfield_lines)) {
foreach($htmlfield_lines as $line) {
$line = trim($line);
if(substr($line,0,1) != '#') {
list($user,$path,$varname) = explode(':',$line);
if($current_script_name == $path) {
if($user = 'any'
|| ($user == 'user' && ($_SESSION['s']['user']['typ'] == 'user' || $_SESSION['s']['user']['typ'] == 'admin'))
|| ($user == 'admin' && $_SESSION['s']['user']['typ'] == 'admin')) {
$ids_init->config['General']['html'][] = $varname;
}
}
}
}
}
$ids = new IDS\Monitor($ids_init);
$ids_result = $ids->run($ids_request);
if (!$ids_result->isEmpty()) {
$impact = $ids_result->getImpact();
if($impact >= $security_config['ids_log_level']) {
$ids_log = ISPC_ROOT_PATH.'/temp/ids.log';
if(!is_file($ids_log)) touch($ids_log);
$user = isset($_SESSION['s']['user']['typ'])?$_SESSION['s']['user']['typ']:'any';
$log_lines = '';
foreach ($ids_result->getEvents() as $event) {
$log_lines .= $user.':'.$current_script_name.':'.$event->getName()."\n";
}
file_put_contents($ids_log,$log_lines,FILE_APPEND);
}
if($impact >= $security_config['ids_warn_level']) {
$app->log("PHP IDS Alert.".$ids_result, 2);
}
if($impact >= $security_config['ids_block_level']) {
$app->error("Possible attack detected. This action has been logged.",'', true, 2);
}
}
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/importer.inc.php 0000664 0000000 0000000 00000005314 12600761333 0026406 0 ustar 00root root 0000000 0000000 faultMessage = $message;
$this->faultText = $text;
}
public function getFault() {
$ret = $this->faultMessage . ' (' . $this->faultText . ')';
$this->faultMessage = null;
$this->faultText = null;
return $ret;
}
}
class importer extends remoting {
public function __construct()
{
$this->server = new fakeserver();
}
//* remote login function - overridden just to make sure it cannot be called from importer scripts
public function login($username, $password)
{
}
//* remote logout function - overridden just to make sure it cannot be called from importer scripts
public function logout($session_id)
{
}
public function getFault() {
return $this->server->getFault();
}
protected function checkPerm($session_id, $function_name)
{
// always return true as this is used from inside the application not through remote calls
return true;
}
protected function getSession($session_id)
{
return array(); // we have no sessions here
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/ini_parser.inc.php 0000664 0000000 0000000 00000005033 12600761333 0026676 0 ustar 00root root 0000000 0000000 config[$section][$item] = trim($matches[2]);
}
}
}
return $this->config;
}
//* Converts a config array to a string
public function get_ini_string($config_array = '') {
if($config_array == '') $config_array = $this->config;
$content = '';
foreach($config_array as $section => $data) {
$content .= "[$section]\n";
foreach($data as $item => $value) {
if($item != ''){
$value = trim($value);
$item = trim($item);
$content .= "$item=$value\n";
}
}
$content .= "\n";
}
return $content;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/ispcmail.inc.php 0000664 0000000 0000000 00000060304 12600761333 0026346 0 ustar 00root root 0000000 0000000 mime_boundary = '==Multipart_Boundary_x' . $rand . 'x';
$this->headers = array();
$this->attachments = array();
$this->headers['MIME-Version'] = '1.0';
$this->headers['User-Agent'] = $this->user_agent;
if(is_array($options) && count($options) > 0) $this->setOptions($options);
}
public function __destruct() {
$this->finish();
}
/**
* Set option
*
* @param string $key the option to set
* @param string $value the option value to set
*/
public function setOption($key, $value) {
switch($key) {
case 'smtp_helo':
$this->smtp_helo = $value;
break;
case 'smtp_host':
$this->smtp_host = $value;
break;
case 'smtp_server':
$this->smtp_host = $value;
break;
case 'smtp_port':
$this->smtp_port = $value;
break;
case 'smtp_user':
$this->smtp_user = $value;
break;
case 'smtp_pass':
$this->smtp_pass = $value;
break;
case 'smtp_max_mails':
$this->smtp_max_mails = intval($value);
if($this->smtp_max_mails < 1) $this->smtp_max_mails = 1;
break;
case 'use_smtp':
$this->use_smtp = ($value == true ? true : false);
if($value == true) $this->_crlf = "\r\n";
break;
case 'smtp_crypt':
if($value != 'ssl' && $value != 'tls') $value = '';
$this->smtp_crypt = $value;
break;
case 'sign_email':
$this->sign_email = ($value == true ? true : false);
break;
case 'sign_key':
$this->sign_key = $value;
break;
case 'sign_key_pass':
$this->sign_key_pass = $value;
break;
case 'sign_cert':
$this->sign_cert = $value;
break;
case 'sign_bundle':
$this->sign_bundle = $value;
break;
case 'mail_charset':
$this->mail_charset = $value;
break;
case 'notify':
$this->notification = ($value == true ? true : false);
break;
}
}
/** Detect the helo string if none given
*
*/
private function detectHelo() {
if(isset($_SERVER['HTTP_HOST'])) $this->smtp_helo = (strpos($_SERVER['HTTP_HOST'], ':') !== false ? substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')) : $_SERVER['HTTP_HOST']);
elseif(isset($_SERVER['SERVER_NAME'])) $this->smtp_helo = $_SERVER['SERVER_NAME'];
else $this->smtp_helo = php_uname('n');
if($this->smtp_helo == '') $this->smtp_helo = 'localhost';
return $this->smtp_helo;
}
/**
* Set options
*
* @param array $options the options to set as an associative array key => value
*/
public function setOptions($options) {
foreach($options as $key => $value) $this->setOption($key, $value);
}
/**
* Read a file's contents
*
* Simply gets the file's content
*
* @access public
* @param string $filename name and path of file to read
* @return string file content (can be binary)
*/
public function read_File($filename) {
$content = '';
$fp = fopen($filename, 'r');
if(!$fp) return false;
while(!feof($fp)) {
$content .= fread($fp, 1024);
}
fclose($fp);
return $content;
}
/**
* set smtp connection encryption
*
* @access public
* @param string $mode encryption mode (tls, ssl or empty string)
*/
public function setSMTPEncryption($mode = '') {
if($mode != 'ssl' && $mode != 'tls') $mode = '';
$this->smtp_crypt = $mode;
}
/**
* set a mail header
*
* Sets a single mail header to a given value
*
* @access public
* @param string $header header name to set
* @param string $value value to set in header field
*/
public function setHeader($header, $value) {
if(strtolower($header) == 'bcc') $header = 'Bcc';
elseif(strtolower($header) == 'cc') $header = 'Cc';
elseif(strtolower($header) == 'from') $header = 'From';
$this->headers["$header"] = $value;
}
/**
* get a mail header value
*
* Returns a value of a single mail header
*
* @access public
* @param string $header header name to get
* @return string header value
*/
public function getHeader($header) {
if(strtolower($header) == 'bcc') $header = 'Bcc';
elseif(strtolower($header) == 'cc') $header = 'Cc';
elseif(strtolower($header) == 'from') $header = 'From';
return isset($this->headers["$header"]) ? $this->headers["$header"] : '';
}
/**
* Set email sender
*
* Sets the email sender and optionally the sender's name
*
* @access public
* @param string $email sender email address
* @param string $name sender name
*/
public function setSender($email, $name = '') {
if($name) $header = '"' . $name . '" <' . $email . '>';
else $header = '<' . $email . '>';
$this->_mail_sender = $email;
$this->setHeader('From', $header);
}
/**
* Set mail subject
*
* @access public
* @param string $subject the mail subject
* @return string where-string for db query
*/
public function setSubject($subject) {
$this->setHeader('Subject', $subject);
}
/**
* Get current mail subject
*
* @access public
* @return string mail subject
*/
public function getSubject() {
return $this->headers['Subject'];
}
/**
* Set mail content
*
* Sets the mail html and plain text content
*
* @access public
* @param string $text plain text mail content (can be empty)
* @param string $html html mail content
*/
public function setMailText($text, $html = '') {
$this->text_part = $text;
$this->html_part = $html;
}
/**
* Read and attach a file
*
* Reads a file and attaches it to the current email
*
* @access public
* @param string $filename the file to read and attach
* @param string $display_name the name that will be displayed in the mail
* @see read_File
*/
public function readAttachFile($filename, $display_name = '') {
if($display_name == '') {
$path_parts = pathinfo($filename);
$display_name = $path_parts["basename"];
unset($path_parts);
}
$this->attachFile($this->read_File($filename), $display_name);
}
/**
* Attach a file
*
* Attaches a string (can be binary) as a file to the mail
*
* @access public
* @param string $content attachment data string
* @param string $filename name for file attachment
*/
public function attachFile($content, $filename) {
$attachment = array('content' => $content,
'filename' => $filename,
'type' => 'application/octet-stream',
'encoding' => 'base64'
);
$this->attachments[] = $attachment;
}
/**
* @access private
*/
private function create() {
$attach = false;
$html = false;
$text = false;
if($this->html_part) $html = true;
if($this->text_part) $text = true;
if(count($this->attachments) > 0) $attach = true;
$textonly = false;
$htmlonly = false;
if($text == true && $html == false && $attach == false) {
// only text
$content_type = 'text/plain; charset="' . strtolower($this->mail_charset) . '"';
$textonly = true;
} elseif($text == true && $html == false && $attach == true) {
// text and attachment
$content_type = 'multipart/mixed;';
$content_type .= "\n" . ' boundary="' . $this->mime_boundary . '"';
} elseif($html == true && $text == true && $attach == false) {
// html only (or text too)
$content_type = 'multipart/alternative;';
$content_type .= "\n" . ' boundary="' . $this->mime_boundary . '"';
} elseif($html == true && $text == false && $attach == false) {
// html only (or text too)
$content_type = 'text/html; charset="' . strtolower($this->mail_charset) . '"';
$htmlonly = true;
} elseif($html == true && $attach == true) {
// html and attachments
$content_type = 'multipart/mixed;';
$content_type .= "\n" . ' boundary="' . $this->mime_boundary . '"';
}
$this->headers['Content-Type'] = $content_type;
if($textonly == false && $htmlonly == false) {
$this->body = "This is a multi-part message in MIME format.\n\n";
if($text) {
/*$this->body .= "--{$this->mime_boundary}\n" .
"Content-Type:text/plain; charset=\"" . strtolower($this->mail_charset) . "\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $this->text_part . "\n\n";*/
$this->body .= "--{$this->mime_boundary}\n" .
"Content-Type:text/plain; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 8bit\n\n" . $this->text_part . "\n\n";
}
if($html) {
/*$this->body .= "--{$this->mime_boundary}\n" .
"Content-Type:text/html; charset=\"" . strtolower($this->mail_charset) . "\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $this->html_part . "\n\n";*/
$this->body .= "--{$this->mime_boundary}\n" .
"Content-Type:text/html; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 8bit\n\n" . $this->html_part . "\n\n";
}
if($attach) {
foreach($this->attachments as $att) {
$this->body .= "--{$this->mime_boundary}\n" .
"Content-Type: " . $att['type'] . ";\n" .
" name=\"" . $att['filename'] . "\"\n" .
"Content-Transfer-Encoding: base64\n" .
"Content-Disposition: attachment;\n\n" .
chunk_split(base64_encode($att['content'])) . "\n\n";
}
}
$this->body .= "--{$this->mime_boundary}--\n";
} elseif($htmlonly == true) {
$this->body = $this->html_part;
} else {
$this->body = $this->text_part;
}
if (isset($this->body)) {
// Add message ID header
$message_id = sprintf('<%s.%s@%s>', base_convert(time(), 10, 36), base_convert(rand(), 10, 36), $this->smtp_helo != '' ? $this->smtp_helo : $this->detectHelo());
$this->headers['Message-ID'] = $message_id;
return true;
} else {
return false;
}
}
/**
* Function to sign an email body
*/
private function sign() {
if($this->sign_email == false || $this->sign_key == '' || $this->sign_cert == '') return false;
if(function_exists('openssl_pkcs7_sign') == false) return false;
$tmpin = tempnam(sys_get_temp_dir(), 'sign');
$tmpout = tempnam(sys_get_temp_dir(), 'sign');
if(!file_exists($tmpin) || !is_writable($tmpin)) return false;
file_put_contents($tmpin, 'Content-Type: ' . $this->getHeader('Content-Type') . "\n\n" . $this->body);
$tmpf_key = tempnam(sys_get_temp_dir(), 'sign');
file_put_contents($tmpf_key, $this->sign_key);
$tmpf_cert = tempnam(sys_get_temp_dir(), 'sign');
file_put_contents($tmpf_cert, $this->sign_cert);
if($this->sign_bundle != '') {
$tmpf_bundle = tempnam(sys_get_temp_dir(), 'sign');
file_put_contents($tmpf_bundle, $this->sign_bundle);
openssl_pkcs7_sign($tmpin, $tmpout, 'file://' . realpath($tmpf_cert), array('file://' . realpath($tmpf_key), $this->sign_key_pass), array(), PKCS7_DETACHED, realpath($tmpf_bundle));
} else {
openssl_pkcs7_sign($tmpin, $tmpout, 'file://' . realpath($tmpf_cert), array('file://' . realpath($tmpf_key), $this->sign_key_pass), array());
}
unlink($tmpin);
unlink($tmpf_cert);
unlink($tmpf_key);
if(file_exists($tmpf_bundle)) unlink($tmpf_bundle);
if(!file_exists($tmpout) || !is_readable($tmpout)) return false;
$this->body = file_get_contents($tmpout);
unlink($tmpout);
unset($this->headers['Content-Type']);
unset($this->headers['MIME-Version']);
$this->_is_signed = true;
}
private function _char_to_hex($matches) {
return '=' . strtoupper(dechex(ord($matches[1])));
}
/**
* Function to encode a header if necessary
* according to RFC2047
* @access private
*/
private function _encodeHeader($input, $charset = 'ISO-8859-1') {
preg_match_all('/(\s?\w*[\x80-\xFF]+\w*\s?)/', $input, $matches);
foreach ($matches[1] as $value) {
$replacement = preg_replace_callback('/([\x20\x80-\xFF])/', array($this, '_char_to_hex'), $value);
$input = str_replace($value, '=?' . $charset . '?Q?' . $replacement . '?=', $input);
}
return $input;
}
/**
* Function to encode the subject if necessary
* according to RFC2047
* @access private
*/
private function _encodeSubject($input, $charset = 'ISO-8859-1') {
/*
if($charset == 'UTF-8' && function_exists('imap_8bit')) {
$input = "=?utf-8?Q?" . imap_8bit($input) . "?=";
} else {
preg_match_all('/(\s?\w*[\x80-\xFF]+\w*\s?)/', $input, $matches);
foreach ($matches[1] as $value) {
$replacement = preg_replace('/([\x20\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $value);
$input = str_replace($value, '=?' . $charset . '?Q?' . $replacement . '?=', $input);
}
}*/
$input='=?UTF-8?B?'.base64_encode($input).'?=';
return $input;
}
/**
* @access private
*/
private function _smtp_login() {
$this->_smtp_conn = fsockopen(($this->smtp_crypt == 'ssl' ? 'tls://' : '') . $this->smtp_host, $this->smtp_port, $errno, $errstr, 30);
$response = fgets($this->_smtp_conn, 515);
if(empty($this->_smtp_conn)) return false;
//Say Hello to SMTP
if($this->smtp_helo == '') $this->detectHelo();
fputs($this->_smtp_conn, 'HELO ' . $this->smtp_helo . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
// ENCRYPTED?
if($this->smtp_crypt == 'tls') {
fputs($this->_smtp_conn, 'STARTTLS' . $this->_crlf);
fgets($this->_smtp_conn, 515);
stream_socket_enable_crypto($this->_smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
}
//AUTH LOGIN
fputs($this->_smtp_conn, 'AUTH LOGIN' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
//Send username
fputs($this->_smtp_conn, base64_encode($this->smtp_user) . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
//Send password
fputs($this->_smtp_conn, base64_encode($this->smtp_pass) . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
$this->_logged_in = true;
return true;
}
/**
* @access private
*/
private function _smtp_close() {
$this->_logged_in = false;
if(empty($this->_smtp_conn)) {
return false;
}
fputs($this->_smtp_conn, 'QUIT' . $this->_crlf);
$response = @fgets($this->_smtp_conn, 515);
return true;
}
private function _extract_names($data) {
$senders = array();
$data = stripslashes(preg_replace("'(\t|\r|\n)'", '', $data));
if(trim($data) == '') return $senders;
$armail = array();
$counter = 0; $inthechar = 0;
$chartosplit = ',;'; $protectchar = '"'; $temp = '';
$closed = 1;
for($i = 0; $i < strlen($data); $i++) {
$thischar = $data[$i];
if($thischar == '<' && $closed) $closed = 0;
if($thischar == '>' && !$closed) $closed = 1;
if($thischar == $protectchar) $inthechar = ($inthechar) ? 0 : 1;
if((strpos($chartosplit, $thischar) !== false) && !$inthechar && $closed) {
$armail[] = $temp;
$temp = '';
} else {
$temp .= $thischar;
}
}
if(trim($temp) != '') {
$armail[] = trim($temp);
unset($temp);
}
foreach($armail as $thisPart) {
$thisPart = trim(preg_replace('/^"(.*)"$/i', '$1', trim($thisPart)));
if($thisPart != '') {
$email = '';
$name = '';
if(preg_match('/(.*)<(.*)>/i', $thisPart, $matches)) {
$email = trim($matches[2]);
$name = trim($matches[1]);
} else {
if(preg_match('/([-a-z0-9_$+.]+@[-a-z0-9_.]+[-a-z0-9_]+)((.*))/i', $thisPart, $matches)) {
$email = $matches[1];
$name = $matches[2];
} else {
$email = $thisPart;
}
}
$email = preg_replace('/<(.*)\\>/', '$1', $email);
$name = preg_replace('/"(.*)"/', '$1', trim($name));
$name = preg_replace('/\((.*)\)/', '$1', $name);
if($name == '') $name = $email;
if($email == '') $email = $name;
$senders[] = array(
'name' => $name,
'mail' => $email
);
unset($name);
unset($email);
}
}
unset($armail);
unset($thisPart);
return $senders;
}
/**
* Send the mail to one or more recipients
*
* The recipients can be either a string (1 recipient email without name) or an associative array of recipients with names as keys and email addresses as values.
*
* @access public
* @param mixed $recipients one email address or array of recipients with names as keys and email addresses as values
*/
public function send($recipients) {
if(!is_array($recipients)) $recipients = array($recipients);
if($this->use_smtp == true) $this->_crlf = "\r\n";
else $this->_crlf = "\n";
$this->create();
if($this->sign_email == true) $this->sign();
$subject = '';
if (!empty($this->headers['Subject'])) {
//$subject = $this->_encodeHeader($this->headers['Subject'], $this->mail_charset);
$subject = $this->headers['Subject'];
//$enc_subject = $this->_encodeHeader($subject, $this->mail_charset);
$enc_subject = $this->_encodeSubject($subject, $this->mail_charset);
unset($this->headers['Subject']);
}
if($this->notification == true) $this->setHeader('Disposition-Notification-To', $this->getHeader('From'));
unset($this->headers['To']); // always reset the To header to prevent from sending to multiple users at once
$this->headers['Date'] = date('r'); //date('D, d M Y H:i:s O');
// Get flat representation of headers
foreach ($this->headers as $name => $value) {
if(strtolower($name) == 'to' || strtolower($name) == 'cc' || strtolower($name) == 'bcc') continue; // never add the To header
$headers[] = $name . ': ' . $this->_encodeHeader($value, $this->mail_charset);
}
if($this->use_smtp == true) {
if(!$this->_logged_in || !$this->_smtp_conn) {
$result = $this->_smtp_login();
if(!$result) return false;
}
$bcc_cc_sent = false;
foreach($recipients as $recipname => $recip) {
if($this->_sent_mails >= $this->smtp_max_mails) {
// close connection to smtp and reconnect
$this->_sent_mails = 0;
$this->_smtp_close();
$result = $this->_smtp_login();
if(!$result) return false;
}
$this->_sent_mails += 1;
$recipname = trim(str_replace('"', '', $recipname));
$recip = $this->_encodeHeader($recip, $this->mail_charset);
$recipname = $this->_encodeHeader($recipname, $this->mail_charset);
//Email From
fputs($this->_smtp_conn, 'MAIL FROM: <' . $this->_mail_sender . '>' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
//Email To
fputs($this->_smtp_conn, 'RCPT TO: <' . $recip . '>' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
if($bcc_cc_sent == false) {
$add_recips = array();
if($this->getHeader('Cc') != '') $add_recips = array_merge($add_recips, $this->_extract_names($this->getHeader('Cc')));
if($this->getHeader('Bcc') != '') $add_recips = array_merge($add_recips, $this->_extract_names($this->getHeader('Bcc')));
foreach($add_recips as $add_recip) {
if(!$add_recip['mail']) continue;
fputs($this->_smtp_conn, 'RCPT TO: <' . $this->_encodeHeader($add_recip['mail'], $this->mail_charset) . '>' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
}
unset($add_recips);
$bcc_cc_sent = true;
}
//The Email
fputs($this->_smtp_conn, 'DATA' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
//Construct Headers
if($recipname && !is_numeric($recipname)) $this->setHeader('To', $recipname . ' <' . $recip . '>');
else $this->setHeader('To', $recip);
$mail_content = 'Subject: ' . $enc_subject . $this->_crlf;
$mail_content .= 'To: ' . $this->getHeader('To') . $this->_crlf;
if($this->getHeader('Cc') != '') $mail_content .= 'Cc: ' . $this->_encodeHeader($this->getHeader('Cc'), $this->mail_charset) . $this->_crlf;
$mail_content .= implode($this->_crlf, $headers) . $this->_crlf . ($this->_is_signed == false ? $this->_crlf : '') . $this->body;
fputs($this->_smtp_conn, $mail_content . $this->_crlf . '.' . $this->_crlf);
$response = fgets($this->_smtp_conn, 515);
// hopefully message was correctly sent now
$result = true;
}
} else {
if($this->getHeader('Bcc') != '') $headers[] = 'Bcc: ' . $this->_encodeHeader($this->getHeader('Bcc'), $this->mail_charset);
if($this->getHeader('Cc') != '') $headers[] = 'Cc: ' . $this->_encodeHeader($this->getHeader('Cc'), $this->mail_charset);
$rec_string = '';
foreach($recipients as $recipname => $recip) {
$recipname = trim(str_replace('"', '', $recipname));
if($rec_string != '') $rec_string .= ', ';
if($recipname && !is_numeric($recipname)) $rec_string .= $recipname . '<' . $recip . '>';
else $rec_string .= $recip;
}
$to = $this->_encodeHeader($rec_string, $this->mail_charset);
//$result = mail($to, $subject, $this->body, implode($this->_crlf, $headers));
$result = mail($to, $enc_subject, $this->body, implode($this->_crlf, $headers));
}
// Reset the subject in case mail is resent
if ($subject !== '') {
$this->headers['Subject'] = $subject;
}
// Return
return $result;
}
/**
* Close mail connections
*
* This closes an open smtp connection so you should always call this function in your script if you have finished sending all emails
*
* @access public
*/
public function finish() {
if($this->use_smtp == true) $this->_smtp_close();
$rand = md5(microtime());
$this->mime_boundary = '==Multipart_Boundary_x' . $rand . 'x';
$this->headers = array();
$this->attachments = array();
$this->text_part = '';
$this->html_part = '';
$this->headers['MIME-Version'] = '1.0';
$this->headers['User-Agent'] = $this->user_agent;
$this->smtp_helo = '';
$this->smtp_host = '';
$this->smtp_port = '';
$this->smtp_user = '';
$this->smtp_pass = '';
$this->use_smtp = false;
$this->smtp_crypt = false;
$this->mail_charset = 'UTF-8';
$this->_sent_mails = 0;
return;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/ispconfig_request.inc.php 0000664 0000000 0000000 00000021330 12600761333 0030272 0 ustar 00root root 0000000 0000000 0) {
if($store_in) fclose($outfp);
return $self::get_with_headers($headers['location'], $store_in, $follow_redirects);
}
if($store_in) {
fclose($outfp);
$code = intval(preg_replace('/^HTTP\/\d+\.\d+\s+(\d+)\s+.*$/', '$1', $headers['status']));
if($code != 200) {
return false;
}
return $headers;
} else {
return array($headers, $data);
}
} else {
if($store_in) {
fclose($outfp);
@unlink($store_in);
}
return false;
}
}
/**
* Gets the content of an url
*
* Checks for the php function file_get_contents and uses an alternative if not found
*
* @access public
* @param string $url url to get
* @return string url data including headers
* @see file_get_contents
*/
public static function get($url) {
if(function_exists('file_get_contents')) return file_get_contents($url);
$fp = fopen($url, 'r');
$data = '';
while(!feof($fp)) {
$data .= fgets($fp, 8192);
}
fclose($fp);
return $data;
}
/**
* Make a post request and get data
*
* Calls an url with a post request and returns the data - and optionally the header content
*
* @access public
* @param string $url the url to call
* @param string $data the post data to send
* @param bool $get_headers if true, the function will return an array like PXUrl::get_with_headers(), otherwise the content is returned as a string
* @return mixed Content data as string or - if get_headers is true - the array with header data at index 0 and page content at index 1
* @see get_url_and_headers
*/
public static function post($url, $data, $get_headers = false, $user_agent = false) {
$url_info = parse_url($url);
if((isset($url_info['scheme']) && $url_info['scheme'] == 'https') || $url_info['port'] == 443) {
$port = (!isset($url_info['port']) || !$url_info['port'] || $url_info['port'] == 443 || $url_info['port'] == 80) ? 443 : $url_info['port'];
@$fp = fsockopen('tls://' . $url_info['host'], $port, $errno, $errstr, 10);
} else {
$port = isset($url_info['port']) ? $url_info['port'] : 80;
@$fp = fsockopen($url_info['host'], $port, $errno, $errstr, 10);
}
if(!$fp) return '';
if(!$user_agent) $user_agent = 'pxFW GET proxy';
$header = 'POST ' . (isset($url_info['path']) ? $url_info['path'] : '/') . (isset($url_info['query']) ? '?' . @$url_info['query'] : '') . " HTTP/1.1\r\n";
$header .= "Host: " . @$url_info['host'] . "\r\n";
$header .= "User-Agent: " . $user_agent . "\r\n";
if(isset($url_info['user'])) {
if(!array_key_exists('pass', $url_info)) $url_info['pass'] = '';
$header .= "Authorization: basic " . base64_encode($url_info['user'] . ':' . $url_info['pass']) . "\r\n";
}
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($data) . "\r\n";
$header .= "Connection: close\r\n\r\n";
$header .= $data . "\r\n\r\n";
fwrite($fp, $header);
$response = '';
$eoheader = false;
$header = '';
$tmpdata = '';
$chunked = false;
$chunklen = 0;
while(!feof($fp)) {
if($header = @fgets($fp, 1024)) {
if($eoheader == true) {
$response .= $header;
continue;
}
if ($header == "\r\n") {
$eoheader = true;
continue;
} else {
$tmpdata .= $header;
if(preg_match('/Transfer-Encoding:\s+chunked/i', $tmpdata)) $chunked = true;
}
}
}
//var_dump($response, $chunked, $header);
if($chunked == true) {
$lines = explode("\n", $response);
$response = '';
$chunklen = 0;
foreach($lines as $line) {
$line .= "\n";
if($chunklen <= 0) {
if(preg_match('/^([0-9a-f]+)\s*$/is', $line, $matches)) {
$chunklen = hexdec($matches[1]);
}
continue;
}
if(strlen($line) > $chunklen) {
//echo "Warnung: " . strlen($line) . " > " . $chunklen . "\n";
$line = substr($line, 0, $chunklen);
}
$response .= $line;
$chunklen -= strlen($line);
}
$start = strpos($response, '');
if($start !== false && $end !== false) $response = substr($response, $start, $end - $start + 1);
}
fclose($fp);
if($get_headers == true) {
$tmpheaders = explode("\n", $tmpdata);
$headers = array();
foreach($tmpheaders as $cur) {
if(preg_match('/^(\w+)\:\s*(.*)$/is', $cur, $matches)) {
$headers["$matches[1]"] = trim($matches[2]);
}
}
return array($headers, $response);
} else return $response;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/json_handler.inc.php 0000664 0000000 0000000 00000007741 12600761333 0027221 0 ustar 00root root 0000000 0000000 load('remoting');
// load all remote classes and get their methods
$dir = dirname(realpath(__FILE__)) . '/remote.d';
$d = opendir($dir);
while($f = readdir($d)) {
if($f == '.' || $f == '..') continue;
if(!is_file($dir . '/' . $f) || substr($f, strrpos($f, '.')) != '.php') continue;
$name = substr($f, 0, strpos($f, '.'));
include $dir . '/' . $f;
$class_name = 'remoting_' . $name;
if(class_exists($class_name, false)) {
$this->classes[$class_name] = new $class_name();
foreach(get_class_methods($this->classes[$class_name]) as $method) {
$this->methods[$method] = $class_name;
}
}
}
closedir($d);
// add main methods
$this->methods['login'] = 'remoting';
$this->methods['logout'] = 'remoting';
$this->methods['get_function_list'] = 'remoting';
// create main class
$this->classes['remoting'] = new remoting(array_keys($this->methods));
}
private function _return_json($code, $message, $data = false) {
$ret = new stdClass;
$ret->code = $code;
$ret->message = $message;
$ret->response = $data;
header('Content-Type: application/json; charset="utf-8"');
print json_encode($ret);
exit;
}
public function run() {
if(!isset($_GET) || !is_array($_GET) || count($_GET) < 1) {
$this->_return_json('invalid_method', 'Method not provided in json call');
}
$keys = array_keys($_GET);
$method = reset($keys);
$params = array();
if(is_array($_POST)) {
foreach($_POST as $key => $val) {
$tmp = json_decode($val);
if(!$tmp) $params[] = $val;
else $params[] = (array)$tmp;
}
}
if(array_key_exists($method, $this->methods) == false) {
$this->_return_json('invalid_method', 'Method ' . $method . ' does not exist');
}
$class_name = $this->methods[$method];
if(array_key_exists($class_name, $this->classes) == false) {
$this->_return_json('invalid_class', 'Class ' . $class_name . ' does not exist');
}
if(method_exists($this->classes[$class_name], $method) == false) {
$this->_return_json('invalid_method', 'Method ' . $method . ' does not exist in the class it was expected (' . $class_name . ')');
}
try {
$this->_return_json('ok', '', call_user_func_array(array($this->classes[$class_name], $method), $params));
} catch(SoapFault $e) {
$this->_return_json('remote_fault', $e->getMessage());
}
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/listform.inc.php 0000664 0000000 0000000 00000054306 12600761333 0026411 0 ustar 00root root 0000000 0000000 listDef = $liste;
$this->module = $module;
//* Fill datasources
if(@is_array($this->listDef['item'])) {
foreach($this->listDef['item'] as $key => $field) {
if(@is_array($field['datasource'])) {
$this->listDef['item'][$key]['value'] = $this->getDatasourceData($field);
}
}
}
//* Set local Language File
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_'.$this->listDef['name'].'_list.lng';
if(!file_exists($lng_file)) $lng_file = 'lib/lang/en_'.$this->listDef['name'].'_list.lng';
include $lng_file;
$this->wordbook = $wb;
return true;
}
/**
* Get the key => value array of a form filed from a datasource definitiom
*
* @param field = array with field definition
* @param record = Dataset as array
* @return array key => value array for the value field of a form
*/
private function getDatasourceData($field)
{
global $app;
$values = array();
if($field['datasource']['type'] == 'SQL') {
//** Preparing SQL string. We will replace some common placeholders
$querystring = $field['datasource']['querystring'];
$querystring = str_replace('{USERID}', $_SESSION['s']['user']['userid'], $querystring);
$querystring = str_replace('{GROUPID}', $_SESSION['s']['user']['default_group'], $querystring);
$querystring = str_replace('{GROUPS}', $_SESSION['s']['user']['groups'], $querystring);
//TODO:
//$table_idx = $this->formDef['db_table_idx'];
//$querystring = str_replace("{RECORDID}",$record[$table_idx],$querystring);
$app->uses('tform');
$querystring = str_replace("{AUTHSQL}", $app->tform->getAuthSQL('r'), $querystring);
$querystring = str_replace("{AUTHSQL-A}", $app->tform->getAuthSQL('r', 'a'), $querystring);
$querystring = str_replace("{AUTHSQL-B}", $app->tform->getAuthSQL('r', 'b'), $querystring);
$querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', create_function('$matches','global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;'), $querystring);
//* Getting the records
$tmp_records = $app->db->queryAllRecords($querystring);
if($app->db->errorMessage != '') die($app->db->errorMessage);
if(is_array($tmp_records)) {
$key_field = $field['datasource']['keyfield'];
$value_field = $field['datasource']['valuefield'];
foreach($tmp_records as $tmp_rec) {
$tmp_id = $tmp_rec[$key_field];
$values[$tmp_id] = $tmp_rec[$value_field];
}
}
}
if($field['datasource']['type'] == 'CUSTOM') {
//* Calls a custom class to validate this record
if($field['datasource']['class'] != '' and $field['datasource']['function'] != '') {
$datasource_class = $field['datasource']['class'];
$datasource_function = $field['datasource']['function'];
$app->uses($datasource_class);
$record = array();
$values = $app->$datasource_class->$datasource_function($field, $record);
} else {
$this->errorMessage .= "Custom datasource class or function is empty \r\n";
}
}
if($api == false && isset($field['filters']) && is_array($field['filters'])) {
$new_values = array();
foreach($values as $index => $value) {
$new_index = $app->tform->filterField($index, $index, $field['filters'], 'SHOW');
$new_values[$new_index] = $app->tform->filterField($index, (isset($values[$index]))?$values[$index]:'', $field['filters'], 'SHOW');
}
$values = $new_values;
unset($new_values);
unset($new_index);
}
return $values;
}
public function getSearchSQL($sql_where = '')
{
global $app, $db;
//* Get config variable
$list_name = $this->listDef['name'];
$search_prefix = $this->listDef['search_prefix'];
if(isset($_REQUEST['Filter']) && !isset($_SESSION['search'][$list_name])) {
//* Jump back to page 1 of the list when a new search gets started.
$_SESSION['search'][$list_name]['page'] = 0;
}
//* store retrieval query
if(@is_array($this->listDef['item'])) {
foreach($this->listDef['item'] as $i) {
$field = $i['field'];
//* The search string has been changed
if(isset($_REQUEST[$search_prefix.$field]) && isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_REQUEST[$search_prefix.$field] != $_SESSION['search'][$list_name][$search_prefix.$field]){
$this->searchChanged = 1;
//* Jump back to page 1 of the list when search has changed.
$_SESSION['search'][$list_name]['page'] = 0;
}
//* Store field in session
if(isset($_REQUEST[$search_prefix.$field]) && !stristr($_REQUEST[$search_prefix.$field], "'")){
$_SESSION['search'][$list_name][$search_prefix.$field] = $_REQUEST[$search_prefix.$field];
if(preg_match("/['\\\\]/", $_SESSION['search'][$list_name][$search_prefix.$field])) $_SESSION['search'][$list_name][$search_prefix.$field] = '';
}
if(isset($i['formtype']) && $i['formtype'] == 'SELECT'){
if(is_array($i['value'])) {
$out = '';
foreach($i['value'] as $k => $v) {
// TODO: this could be more elegant
$selected = (isset($_SESSION['search'][$list_name][$search_prefix.$field])
&& $k == $_SESSION['search'][$list_name][$search_prefix.$field]
&& $_SESSION['search'][$list_name][$search_prefix.$field] != '')
? ' SELECTED' : '';
$out .= "\r\n";
}
}
$this->searchValues[$search_prefix.$field] = $out;
} else {
if(isset($_SESSION['search'][$list_name][$search_prefix.$field])){
$this->searchValues[$search_prefix.$field] = htmlspecialchars($_SESSION['search'][$list_name][$search_prefix.$field]);
}
}
}
}
//* Store variables in object | $this->searchValues = $_SESSION["search"][$list_name];
if(@is_array($this->listDef['item'])) {
foreach($this->listDef['item'] as $i) {
$field = $i['field'];
$table = $i['table'];
$searchval = $_SESSION['search'][$list_name][$search_prefix.$field];
// IDN
if($searchval != ''){
foreach($i['filters'] as $searchval_filter) {
if($searchval_filter['event'] == 'SHOW') {
switch ($searchval_filter['type']) {
case 'IDNTOUTF8':
$searchval = $app->functions->idn_encode($searchval);
//echo $searchval;
break;
}
}
}
}
// format user date format to MySQL date format 0000-00-00
if($i['datatype'] == 'DATE' && $this->lng('conf_format_dateshort') != 'Y-m-d'){
$dateformat = preg_replace("@[^Ymd]@", "", $this->lng('conf_format_dateshort'));
$yearpos = strpos($dateformat, 'Y') + 1;
$monthpos = strpos($dateformat, 'm') + 1;
$daypos = strpos($dateformat, 'd') + 1;
$full_date_trans = array ('Y' => '((?:19|20)\d\d)',
'm' => '(0[1-9]|1[012])',
'd' => '(0[1-9]|[12][0-9]|3[01])'
);
// d.m.Y Y/m/d
$full_date_regex = strtr(preg_replace("@[^Ymd]@", "[^0-9]", $this->lng('conf_format_dateshort')), $full_date_trans);
//echo $full_date_regex;
if (preg_match("@^\d+$@", $_SESSION['search'][$list_name][$search_prefix.$field])) { // we just have digits
$searchval = $_SESSION['search'][$list_name][$search_prefix.$field];
} elseif(preg_match("@^[^0-9]?\d+[^0-9]?$@", $_SESSION['search'][$list_name][$search_prefix.$field])){ // 10. or .10.
$searchval = preg_replace("@[^0-9]@", "", $_SESSION['search'][$list_name][$search_prefix.$field]);
} elseif(preg_match("@^[^0-9]?(\d{1,2})[^0-9]((?:19|20)\d\d)$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)){ // 10.2013
$month = $matches[1];
$year = $matches[2];
$searchval = $year.'-'.$month;
} elseif(preg_match("@^((?:19|20)\d\d)[^0-9](\d{1,2})[^0-9]?$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)){ // 2013-10
$month = $matches[2];
$year = $matches[1];
$searchval = $year.'-'.$month;
} elseif(preg_match("@^[^0-9]?(\d{1,2})[^0-9](\d{1,2})[^0-9]?$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)){ // 04.10.
if($monthpos < $daypos){
$month = $matches[1];
$day = $matches[2];
} else {
$month = $matches[2];
$day = $matches[1];
}
$searchval = $month.'-'.$day;
} elseif (preg_match("@^".$full_date_regex."$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)) {
//print_r($matches);
$day = $matches[$daypos];
$month = $matches[$monthpos];
$year = $matches[$yearpos];
$searchval = $year.'-'.$month.'-'.$day;
}
}
// if($_REQUEST[$search_prefix.$field] != '') $sql_where .= " $field ".$i["op"]." '".$i["prefix"].$_REQUEST[$search_prefix.$field].$i["suffix"]."' and";
if(isset($searchval) && $searchval != ''){
$sql_where .= " ".($table != ''? $table.'.' : $this->listDef['table'].'.')."$field ".$i['op']." '".$app->db->quote($i['prefix'].$searchval.$i['suffix'])."' and";
}
}
}
return ( $sql_where != '' ) ? $sql_where = substr($sql_where, 0, -3) : '1';
}
public function getPagingValue($key) {
if(!is_array($this->pagingValues)) return null;
if(!array_key_exists($key, $this->pagingValues)) return null;
return $this->pagingValues[$key];
}
/* TODO: maybe rewrite sql */
public function getPagingSQL($sql_where = '1')
{
global $app, $conf;
$old_search_limit = intval($_SESSION['search']['limit']);
//* Add Global Limit from selectbox
if(!empty($_POST['search_limit']) and $app->functions->intval($_POST['search_limit']) > 0){
$_SESSION['search']['limit'] = $app->functions->intval($_POST['search_limit']);
}
//if(preg_match('{^[0-9]$}',$_SESSION['search']['limit'])){
// $_SESSION['search']['limit'] = 15;
//}
if(intval($_SESSION['search']['limit']) < 1) $_SESSION['search']['limit'] = 15;
//* Get Config variables
$list_name = $this->listDef['name'];
$search_prefix = $this->listDef['search_prefix'];
$records_per_page = (empty($_SESSION['search']['limit']) ? $app->functions->intval($this->listDef['records_per_page']) : $app->functions->intval($_SESSION['search']['limit'])) ;
$table = $this->listDef['table'];
//* set PAGE to zero, if in session not set
if(!isset($_SESSION['search'][$list_name]['page']) || $_SESSION['search'][$list_name]['page'] == ''){
$_SESSION['search'][$list_name]['page'] = 0;
}
//* set PAGE to worth request variable "PAGE" - ? setze page auf wert der request variablen "page"
if(isset($_REQUEST["page"])) $_SESSION["search"][$list_name]["page"] = $app->functions->intval($_REQUEST["page"]);
//* Set search to changed when search limit has been changed.
if(intval($_SESSION['search']['limit']) != $old_search_limit) $this->searchChanged = 1;
//* PAGE to 0 set, if look for themselves ? page auf 0 setzen, wenn suche sich ge�ndert hat.
if($this->searchChanged == 1) $_SESSION['search'][$list_name]['page'] = 0;
$sql_von = $app->functions->intval($_SESSION['search'][$list_name]['page'] * $records_per_page);
$record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM ??".($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')." WHERE $sql_where", $table);
$pages = $app->functions->intval(($record_count['anzahl'] - 1) / $records_per_page);
$vars['list_file'] = $_SESSION['s']['module']['name'].'/'.$this->listDef['file'];
$vars['page'] = $_SESSION['search'][$list_name]['page'];
$vars['last_page'] = $_SESSION['search'][$list_name]['page'] - 1;
$vars['next_page'] = $_SESSION['search'][$list_name]['page'] + 1;
$vars['pages'] = $pages;
$vars['max_pages'] = $pages + 1;
$vars['records_gesamt'] = $record_count['anzahl'];
$vars['page_params'] = (isset($this->listDef['page_params'])) ? $this->listDef['page_params'] : '';
$vars['offset'] = $sql_von;
$vars['records_per_page'] = $records_per_page;
//$vars['module'] = $_SESSION['s']['module']['name'];
if($_SESSION['search'][$list_name]['page'] > 0) $vars['show_page_back'] = 1;
if($_SESSION['search'][$list_name]['page'] <= $vars['pages'] - 1) $vars['show_page_next'] = 1;
$this->pagingValues = $vars;
$this->pagingHTML = $this->getPagingHTML($vars);
//* Return limit sql
return "LIMIT $sql_von, $records_per_page";
}
public function getPagingHTML($vars)
{
global $app;
// we want to show at max 17 page numbers (8 left, current, 8 right)
$show_pages_count = 17;
$show_pages = array(0); // first page
if($vars['pages'] > 0) $show_pages[] = $vars['pages']; // last page
for($p = $vars['page'] - 2; $p <= $vars['page'] + 2; $p++) { // surrounding pages
if($p > 0 && $p < $vars['pages']) $show_pages[] = $p;
}
$l_start = $vars['page'] - 13;
$l_start -= ($l_start % 10) + 1;
$h_end = $vars['page'] + 23;
$h_end -= ($h_end % 10) + 1;
for($p = $l_start; $p <= $h_end; $p += 10) { // surrounding pages
if($p > 0 && $p < $vars['pages'] && !in_array($p, $show_pages, true) && count($show_pages) < $show_pages_count) $show_pages[] = $p;
}
$l_start = $vars['page'] - 503;
$l_start -= ($l_start % 100) + 1;
$h_end = $vars['page'] + 603;
$h_end -= ($h_end % 100) + 1;
for($p = $l_start; $p <= $h_end; $p += 100) { // surrounding pages
if($p > 0 && $p < $vars['pages'] && !in_array($p, $show_pages, true) && count($show_pages) < $show_pages_count) $show_pages[] = $p;
}
$l_start = $vars['page'] - 203;
$l_start -= ($l_start % 25) + 1;
$h_end = $vars['page'] + 228;
$h_end -= ($h_end % 25) + 1;
for($p = $l_start; $p <= $h_end; $p += 25) { // surrounding pages
if($p > 0 && $p < $vars['pages'] && abs($p - $vars['page']) > 30 && !in_array($p, $show_pages, true) && count($show_pages) < $show_pages_count) $show_pages[] = $p;
}
sort($show_pages);
$show_pages = array_unique($show_pages);
$content = '';
return $content;
}
public function getPagingHTMLasTXT($vars)
{
global $app;
$content = '[|<< ]';
if($vars['show_page_back'] == 1){
$content .= '[<< '.$app->lng('page_back_txt').'] ';
}
$content .= ' '.$this->lng('page_txt').' '.$vars['next_page'].' '.$this->lng('page_of_txt').' '.$vars['max_pages'].' ';
if($vars['show_page_next'] == 1){
$content .= '['.$app->lng('page_next_txt').' >>] ';
}
$content .= '[ >>|]';
return $content;
}
public function getSortSQL()
{
global $app, $conf;
//* Get config vars
$sort_field = $this->listDef['sort_field'];
$sort_direction = $this->listDef['sort_direction'];
return ($sort_field != '' && $sort_direction != '') ? "ORDER BY $sort_field $sort_direction" : '';
}
public function decode($record)
{
global $conf, $app;
if(is_array($record) && count($record) > 0 && is_array($this->listDef['item'])) {
foreach($this->listDef['item'] as $field){
$key = $field['field'];
//* Apply filter to record value.
if(isset($field['filters']) && is_array($field['filters'])) {
$app->uses('tform');
$record[$key] = $app->tform->filterField($key, (isset($record[$key]))?$record[$key]:'', $field['filters'], 'SHOW');
}
if(isset($record[$key])) {
switch ($field['datatype']){
case 'VARCHAR':
case 'TEXT':
$record[$key] = htmlentities(stripslashes($record[$key]), ENT_QUOTES, $conf["html_content_encoding"]);
break;
case 'DATETSTAMP':
if ($record[$key] > 0) {
// is value int?
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) {
$record[$key] = date($this->lng('conf_format_dateshort'), $record[$key]);
} else {
$record[$key] = date($this->lng('conf_format_dateshort'), strtotime($record[$key]));
}
}
break;
case 'DATETIMETSTAMP':
if ($record[$key] > 0) {
// is value int?
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) {
$record[$key] = date($this->lng('conf_format_datetime'), $record[$key]);
} else {
$record[$key] = date($this->lng('conf_format_datetime'), strtotime($record[$key]));
}
}
break;
case 'DATE':
if ($record[$key] > 0) {
// is value int?
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) {
$record[$key] = date($this->lng('conf_format_dateshort'), $record[$key]);
} else {
$record[$key] = date($this->lng('conf_format_dateshort'), strtotime($record[$key]));
}
}
break;
case 'DATETIME':
if ($record[$key] > 0) {
// is value int?
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) {
$record[$key] = date($this->lng('conf_format_datetime'), $record[$key]);
} else {
$record[$key] = date($this->lng('conf_format_datetime'), strtotime($record[$key]));
}
}
break;
case 'INTEGER':
$record[$key] = $app->functions->intval($record[$key]);
break;
case 'DOUBLE':
$record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf["html_content_encoding"]);
break;
case 'CURRENCY':
$record[$key] = $app->functions->currency_format($record[$key]);
break;
default:
$record[$key] = htmlentities(stripslashes($record[$key]), ENT_QUOTES, $conf["html_content_encoding"]);
}
}
}
}
return $record;
}
/* TODO: check double quoting of SQL */
public function encode($record)
{
global $app;
if(is_array($record)) {
foreach($this->listDef['item'] as $field){
$key = $field['field'];
switch($field['datatype']){
case 'VARCHAR':
case 'TEXT':
if(!is_array($record[$key])) {
$record[$key] = $app->db->quote($record[$key]);
} else {
$record[$key] = implode($this->tableDef[$key]['separator'], $record[$key]);
}
break;
case 'DATETSTAMP':
if($record[$key] > 0) {
$record[$key] = date('Y-m-d', strtotime($record[$key]));
}
break;
case 'DATETIMETSTAMP':
if($record[$key] > 0) {
$record[$key] = date('Y-m-d H:i:s', strtotime($record[$key]));
}
break;
case 'DATE':
if($record[$key] != '' && $record[$key] != '0000-00-00') {
$record[$key] = $record[$key];
}
break;
case 'DATETIME':
if($record[$key] > 0) {
$record[$key] = date('Y-m-d H:i:s', strtotime($record[$key]));
}
break;
case 'INTEGER':
$record[$key] = $app->functions->intval($record[$key]);
break;
case 'DOUBLE':
$record[$key] = $app->db->quote($record[$key]);
break;
case 'CURRENCY':
$record[$key] = str_replace(',', '.', $record[$key]);
break;
}
}
}
return $record;
}
function lng($msg) {
global $app;
if(isset($this->wordbook[$msg])) {
return $this->wordbook[$msg];
} else {
return $app->lng($msg);
}
}
function escapeArrayValues($search_values) {
global $conf;
$out = array();
if(is_array($search_values)) {
foreach($search_values as $key => $val) {
$out[$key] = htmlentities($val, ENT_QUOTES, $conf["html_content_encoding"]);
}
}
return $out;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/listform_actions.inc.php 0000664 0000000 0000000 00000026365 12600761333 0030135 0 ustar 00root root 0000000 0000000 sortKeys)) $this->sortKeys = array($this->sortKeys);
foreach($this->sortKeys as $sKey => $sDir) {
if(is_numeric($sKey)) {
$sKey = $sDir;
$sDir = 'ASC';
}
$a = $aOne[$sKey];
$b = $aTwo[$sKey];
if(is_string($a)) $a = strtolower($a);
if(is_string($b)) $b = strtolower($b);
if($a < $b) return $sDir == 'DESC' ? 1 : -1;
elseif($a > $b) return $sDir == 'DESC' ? -1 : 1;
}
return 0;
}
public function onLoad()
{
global $app, $conf, $list_def_file;
$app->uses('tpl,listform,tform');
//* Clear session variable that is used when lists are embedded with the listview plugin
$_SESSION['s']['form']['return_to'] = '';
// Load list definition
$app->listform->loadListDef($list_def_file);
if(!is_file('templates/'.$app->listform->listDef["name"].'_list.htm')) {
$app->uses('listform_tpl_generator');
$app->listform_tpl_generator->buildHTML($app->listform->listDef);
}
$app->tpl->newTemplate("listpage.tpl.htm");
$app->tpl->setInclude('content_tpl', 'templates/'.$app->listform->listDef["name"].'_list.htm');
//* Manipulate order by for sorting / Every list has a stored value
//* Against notice error
if(!isset($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'])){
$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'] = '';
}
$php_sort = false;
if(!empty($_GET['orderby'])){
$order = str_replace('tbl_col_', '', $_GET['orderby']);
//* Check the css class submited value
if (preg_match("/^[a-z\_]{1,}$/", $order)) {
if(isset($app->listform->listDef['phpsort']) && is_array($app->listform->listDef['phpsort']) && in_array($order, $app->listform->listDef['phpsort'])) {
$php_sort = true;
} else {
// prepend correct table
$prepend_table = $app->listform->listDef['table'];
if(trim($app->listform->listDef['additional_tables']) != '' && is_array($app->listform->listDef['item']) && count($app->listform->listDef['item']) > 0) {
foreach($app->listform->listDef['item'] as $field) {
if($field['field'] == $order && $field['table'] != ''){
$prepend_table = $field['table'];
break;
}
}
}
$order = $prepend_table.'.'.$order;
}
if($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'] == $order){
$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'] = $order.' DESC';
} else {
$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'] = $order;
}
$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order_in_php'] = $php_sort;
}
}
// If a manuel oder by like customers isset the sorting will be infront
if(!empty($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order']) && !$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order_in_php']){
if(empty($this->SQLOrderBy)){
$this->SQLOrderBy = "ORDER BY ".$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'];
} else {
$this->SQLOrderBy = str_replace("ORDER BY ", "ORDER BY ".$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'].', ', $this->SQLOrderBy);
}
}
if($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order_in_php']) $php_sort = true;
// Getting Datasets from DB
$records = $app->db->queryAllRecords($this->getQueryString($php_sort));
$this->DataRowColor = "#FFFFFF";
$records_new = '';
if(is_array($records)) {
$this->idx_key = $app->listform->listDef["table_idx"];
foreach($records as $rec) {
$records_new[] = $this->prepareDataRow($rec);
}
}
if(!empty($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order']) && $_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order_in_php']) {
$order_by = $_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'];
$order_dir = 'ASC';
if(substr($order_by, -5) === ' DESC') {
$order_by = substr($order_by, 0, -5);
$order_dir = 'DESC';
}
$this->sortKeys = array($order_by => $order_dir);
uasort($records_new, array($this, '_sort'));
}
if($php_sort) {
$records_new = array_slice($records_new, $app->listform->getPagingValue('offset'), $app->listform->getPagingValue('records_per_page'));
}
$app->tpl->setLoop('records', $records_new);
$this->onShow();
}
public function prepareDataRow($rec)
{
global $app;
$rec = $app->listform->decode($rec);
//* Alternating datarow colors
$this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF';
$rec['bgcolor'] = $this->DataRowColor;
//* substitute value for select fields
if(is_array($app->listform->listDef['item']) && count($app->listform->listDef['item']) > 0) {
foreach($app->listform->listDef['item'] as $field) {
$key = $field['field'];
if(isset($field['formtype']) && $field['formtype'] == 'SELECT') {
if(strtolower($rec[$key]) == 'y' or strtolower($rec[$key]) == 'n') {
// Set a additional image variable for bolean fields
$rec['_'.$key.'_'] = (strtolower($rec[$key]) == 'y')?'x16/tick_circle.png':'x16/cross_circle.png';
}
//* substitute value for select field
$rec[$key] = @$field['value'][$rec[$key]];
}
}
}
//* The variable "id" contains always the index variable
$rec['id'] = $rec[$this->idx_key];
return $rec;
}
/* TODO: maybe rewrite SQL */
public function getQueryString($no_limit = false) {
global $app;
$sql_where = '';
//* Generate the search sql
if($app->listform->listDef['auth'] != 'no') {
if($_SESSION['s']['user']['typ'] == "admin") {
$sql_where = '';
} else {
$sql_where = $app->tform->getAuthSQL('r', $app->listform->listDef['table']).' and';
//$sql_where = $app->tform->getAuthSQL('r').' and';
}
}
if($this->SQLExtWhere != '') {
$sql_where .= ' '.$this->SQLExtWhere.' and';
}
$sql_where = $app->listform->getSearchSQL($sql_where);
if($app->listform->listDef['join_sql']) $sql_where .= ' AND '.$app->listform->listDef['join_sql'];
$app->tpl->setVar($app->listform->searchValues);
$order_by_sql = $this->SQLOrderBy;
//* Generate SQL for paging
$limit_sql = $app->listform->getPagingSQL($sql_where);
$app->tpl->setVar('paging', $app->listform->pagingHTML);
$extselect = '';
$join = '';
if($this->SQLExtSelect != '') {
if(substr($this->SQLExtSelect, 0, 1) != ',') $this->SQLExtSelect = ','.$this->SQLExtSelect;
$extselect .= $this->SQLExtSelect;
}
$table_selects = array();
$table_selects[] = trim($app->listform->listDef['table']).'.*';
$app->listform->listDef['additional_tables'] = trim($app->listform->listDef['additional_tables']);
if($app->listform->listDef['additional_tables'] != ''){
$additional_tables = explode(',', $app->listform->listDef['additional_tables']);
foreach($additional_tables as $additional_table){
$table_selects[] = trim($additional_table).'.*';
}
}
$select = implode(', ', $table_selects);
$sql = 'SELECT '.$select.$extselect.' FROM '.$app->listform->listDef['table'].($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')."$join WHERE $sql_where $order_by_sql";
if($no_limit == false) $sql .= " $limit_sql";
//echo $sql;
return $sql;
}
public function onShow()
{
global $app;
//* Set global Language File
$lng_file = ISPC_LIB_PATH.'/lang/'.$_SESSION['s']['language'].'.lng';
if(!file_exists($lng_file))
$lng_file = ISPC_LIB_PATH.'/lang/en.lng';
include $lng_file;
$app->tpl->setVar($wb);
//* Limit each page
$limits = array('5'=>'5', '15'=>'15', '25'=>'25', '50'=>'50', '100'=>'100', '999999999' => 'all');
//* create options and set selected, if default -> 15 is selected
$options = '';
foreach($limits as $key => $val){
$options .= '';
}
$app->tpl->setVar('search_limit', '');
$app->tpl->setVar('toolsarea_head_txt', $app->lng('toolsarea_head_txt'));
$app->tpl->setVar($app->listform->wordbook);
$app->tpl->setVar('form_action', $app->listform->listDef['file']);
if(isset($_SESSION['show_info_msg'])) {
$app->tpl->setVar('show_info_msg', $_SESSION['show_info_msg']);
unset($_SESSION['show_info_msg']);
}
if(isset($_SESSION['show_error_msg'])) {
$app->tpl->setVar('show_error_msg', $_SESSION['show_error_msg']);
unset($_SESSION['show_error_msg']);
}
//* Parse the templates and send output to the browser
$this->onShowEnd();
}
public function onShowEnd()
{
global $app;
$app->tpl_defaults();
$app->tpl->pparse();
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/listform_tpl_generator.inc.php 0000664 0000000 0000000 00000014565 12600761333 0031341 0 ustar 00root root 0000000 0000000
';
if($module == '') {
$filename = 'templates/'.$listDef["name"].'_list.htm';
} else {
$filename = '../'.$module.'/templates/'.$listDef["name"].'_list.htm';
}
// save template
if (!$handle = fopen($filename, 'w')) {
print "Cannot open file ($filename)";
exit;
}
if (!fwrite($handle, $html)) {
print "Cannot write to file ($filename)";
exit;
}
fclose($handle);
/*$lang["page_txt"] = 'Page';
$lang["page_of_txt"] = 'of';
$lang["page_next_txt"] = 'Next';
$lang["page_back_txt"] = 'Back';
$lang["delete_txt"] = 'Delete';
$lang["filter_txt"] = 'Filter';
$lang["add_new_record_txt"] = 'Add new record';
*/
// save language file
$this->lng_add($lang, $listDef, $module);
}
function lng_add($lang, $listDef, $module = '') {
global $go_api, $go_info, $conf;
if($module == '') {
$lng_file = "lib/lang/".$conf["language"]."_".$listDef['name']."_list.lng";
} else {
$lng_file = '../'.$module."/lib/lang/en_".$listDef['name']."_list.lng";
}
if(is_file($lng_file)) {
include_once $lng_file;
} else {
$wb = array();
}
$wb_out = array_merge($lang, $wb);
if(is_array($wb_out)) {
$fp = fopen($lng_file, "w");
fwrite($fp, " $val) {
$new_line = '$wb["'.$key.'"] = '."'$val';\n";
fwrite($fp, $new_line);
}
fwrite($fp, "?>");
fclose($fp);
}
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/plugin.inc.php 0000664 0000000 0000000 00000013546 12600761333 0026051 0 ustar 00root root 0000000 0000000 $file) {
include_once $plugins_dir.$file;
if($this->debug) $app->log('Loading plugin: '.$plugin_name, LOGLEVEL_DEBUG);
$app->loaded_plugins[$plugin_name] = new $plugin_name;
$app->loaded_plugins[$plugin_name]->onLoad();
}
} else {
$app->log('Unable to open the plugins directory: '.$plugins_dir, LOGLEVEL_ERROR);
}
} else {
$app->log('Plugins directory missing: '.$plugins_dir, LOGLEVEL_ERROR);
}
}
/*
This function is called by the plugin to register for an event which is saved into the plugin cache
for faster lookups without the need to load all plugins for every page.
*/
public function registerEvent($event_name, $plugin_name, $function_name) {
global $app;
$_SESSION['s']['plugin_cache'][$event_name][] = array('plugin' => $plugin_name, 'function' => $function_name);
if($this->debug) $app->log("Plugin '$plugin_name' has registered the function '$function_name' for the event '$event_name'", LOGLEVEL_DEBUG);
}
/*
This function is called when a certian action occurs, e.g. a form gets saved or a user is logged in.
*/
public function raiseEvent($event_name, $data) {
global $app;
if(!isset($_SESSION['s']['plugin_cache'])) {
$this->loadPluginCache();
if($this->debug) $app->log('Loaded the plugin cache.', LOGLEVEL_DEBUG);
}
$sub_events = explode(':', $event_name);
if(is_array($sub_events)) {
if(count($sub_events) == 3) {
$tmp_event = $sub_events[2];
if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG);
$this->callPluginEvent($tmp_event, $data);
$tmp_event = $sub_events[0].':'.$sub_events[2];
if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG);
$this->callPluginEvent($tmp_event, $data);
$tmp_event = $sub_events[0].':'.$sub_events[1].':'.$sub_events[2];
if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG);
$this->callPluginEvent($tmp_event, $data);
/*$sub_events = array_reverse($sub_events);
$tmp_event = '';
foreach($sub_events as $n => $sub_event) {
$tmp_event = ($n == 0)?$sub_event:$sub_event.':'.$tmp_event;
if($this->debug) $app->log("Called Event '$tmp_event'",LOGLEVEL_DEBUG);
$this->callPluginEvent($tmp_event,$data);
}
*/
} else {
if($this->debug) $app->log("Called Event '$sub_events[0]'", LOGLEVEL_DEBUG);
$this->callPluginEvent($sub_events[0], $data);
}
}
} // end function raiseEvent
//* Internal function to load the plugin and call the event function in the plugin.
private function callPluginEvent($event_name, $data) {
global $app;
//* execute the functions for the events
if(@is_array($_SESSION['s']['plugin_cache'][$event_name])) {
foreach($_SESSION['s']['plugin_cache'][$event_name] as $rec) {
$plugin_name = $rec['plugin'];
$function_name = $rec['function'];
$plugin_file = ISPC_LIB_PATH.FS_DIV.'plugins'.FS_DIV.$plugin_name.'.inc.php';
if(is_file($plugin_file)) {
if(!isset($app->loaded_plugins[$plugin_name])) {
include_once $plugin_file;
$app->loaded_plugins[$plugin_name] = new $plugin_name;
}
if($this->debug) $app->log("Called method: '$function_name' in plugin '$plugin_name' for event '$event_name'", LOGLEVEL_DEBUG);
// call_user_method($function_name,$app->loaded_plugins[$plugin_name],$event_name,$data);
call_user_func(array($app->loaded_plugins[$plugin_name], $function_name), $event_name, $data);
}
}
}
} // end functiom callPluginEvent
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/plugin_backuplist.inc.php 0000664 0000000 0000000 00000015061 12600761333 0030264 0 ustar 00root root 0000000 0000000 newTemplate('templates/web_backup_list.htm');
//* Loading language file
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_web_backup_list.lng";
include $lng_file;
$listTpl->setVar($wb);
$message = '';
$error = '';
if(isset($_GET['backup_action'])) {
$backup_id = $app->functions->intval($_GET['backup_id']);
//* check if the user is owner of the parent domain
$domain_backup = $app->db->queryOneRecord("SELECT parent_domain_id FROM web_backup WHERE backup_id = ?", $backup_id);
$check_perm = 'u';
if($_GET['backup_action'] == 'download') $check_perm = 'r'; // only check read permissions on download, not update permissions
$get_domain = $app->db->queryOneRecord("SELECT domain_id FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL($check_perm), $domain_backup["parent_domain_id"]);
if(empty($get_domain) || !$get_domain) {
$app->error($app->tform->lng('no_domain_perm'));
}
if($_GET['backup_action'] == 'download' && $backup_id > 0) {
$server_id = $this->form->dataRecord['server_id'];
$backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = ?", $backup_id);
if($backup['server_id'] > 0) $server_id = $backup['server_id'];
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_download' AND action_param = ?";
$tmp = $app->db->queryOneRecord($sql, $backup_id);
if($tmp['number'] == 0) {
$message .= $wb['download_info_txt'];
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
"VALUES (?, UNIX_TIMESTAMP(), 'backup_download', ?, 'pending', '')";
$app->db->query($sql, $server_id, $backup_id);
} else {
$error .= $wb['download_pending_txt'];
}
}
if($_GET['backup_action'] == 'restore' && $backup_id > 0) {
$server_id = $this->form->dataRecord['server_id'];
$backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = ?", $backup_id);
if($backup['server_id'] > 0) $server_id = $backup['server_id'];
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore' AND action_param = '$backup_id'";
$tmp = $app->db->queryOneRecord($sql);
if($tmp['number'] == 0) {
$message .= $wb['restore_info_txt'];
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
"VALUES (?, UNIX_TIMESTAMP(), 'backup_restore', ?, 'pending', '')";
$app->db->query($sql, $server_id, $backup_id);
} else {
$error .= $wb['restore_pending_txt'];
}
}
}
//* Get the data
$server_ids = array();
$web = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ?", $this->form->id);
$databases = $app->db->queryAllRecords("SELECT server_id FROM web_database WHERE parent_domain_id = ?", $this->form->id);
if($app->functions->intval($web['server_id']) > 0) $server_ids[] = $app->functions->intval($web['server_id']);
if(is_array($databases) && !empty($databases)){
foreach($databases as $database){
if($app->functions->intval($database['server_id']) > 0) $server_ids[] = $app->functions->intval($database['server_id']);
}
}
$server_ids = array_unique($server_ids);
$sql = "SELECT * FROM web_backup WHERE parent_domain_id = ? AND server_id IN ? ORDER BY tstamp DESC, backup_type ASC";
$records = $app->db->queryAllRecords($sql, $this->form->id, $server_ids);
$bgcolor = "#FFFFFF";
if(is_array($records)) {
foreach($records as $rec) {
// Change of color
$bgcolor = ($bgcolor == "#FFFFFF")?"#EEEEEE":"#FFFFFF";
$rec["bgcolor"] = $bgcolor;
$rec['date'] = date($app->lng('conf_format_datetime'), $rec['tstamp']);
$rec['backup_type'] = $wb[('backup_type_'.$rec['backup_type'])];
$rec['download_available'] = true;
if($rec['server_id'] != $web['server_id']) $rec['download_available'] = false;
if($rec['filesize'] > 0){
$rec['filesize'] = $app->functions->currency_format($rec['filesize']/(1024*1024), 'client').' MB';
}
$records_new[] = $rec;
}
}
$listTpl->setLoop('records', @$records_new);
$listTpl->setVar('parent_id', $this->form->id);
$listTpl->setVar('msg', $message);
$listTpl->setVar('error', $error);
// Setting Returnto information in the session
$list_name = 'backup_list';
// $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
$_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
$_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
$_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
$_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
$_SESSION["s"]["form"]["return_to"] = $list_name;
return $listTpl->grab();
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/plugin_backuplist_mail.inc.php 0000664 0000000 0000000 00000010043 12600761333 0031261 0 ustar 00root root 0000000 0000000 uses('functions');
$listTpl = new tpl;
$listTpl->newTemplate('templates/mail_user_backup_list.htm');
//* Loading language file
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_mail_backup_list.lng";
include($lng_file);
$listTpl->setVar($wb);
$message = '';
$error = '';
if(isset($_GET['backup_action'])) {
$backup_id = $app->functions->intval($_GET['backup_id']);
if($_GET['backup_action'] == 'restore_mail' && $backup_id > 0) {
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore_mail' AND action_param = ?";
$tmp = $app->db->queryOneRecord($sql, $backup_id);
if($tmp['number'] == 0) {
$message .= $wb['restore_info_txt'];
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
"VALUES (?, ? 'backup_restore_mail', ?, 'pending','')";
$app->db->query($sql, $this->form->dataRecord['server_id'], time(), $backup_id);
} else {
$error .= $wb['restore_pending_txt'];
}
}
}
//* Get the data
$sql = "SELECT * FROM mail_backup WHERE mailuser_id = ? ORDER BY tstamp DESC";
$records = $app->db->queryAllRecords($sql, $this->form->id);
$bgcolor = "#FFFFFF";
if(is_array($records)) {
foreach($records as $rec) {
// Change of color
$bgcolor = ($bgcolor == "#FFFFFF")?"#EEEEEE":"#FFFFFF";
$rec["bgcolor"] = $bgcolor;
$rec['date'] = date($app->lng('conf_format_datetime'),$rec['tstamp']);
$rec['backup_type'] = $wb[('backup_type_'.$rec['backup_type'])];
$rec['filesize'] = $app->functions->formatBytes($rec['filesize']);
$records_new[] = $rec;
}
}
$listTpl->setLoop('records',@$records_new);
$listTpl->setVar('parent_id',$this->form->id);
$listTpl->setVar('msg',$message);
$listTpl->setVar('error',$error);
// Setting Returnto information in the session
$list_name = 'backup_list';
$_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
$_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
$_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
$_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
$_SESSION["s"]["form"]["return_to"] = $list_name;
return $listTpl->grab();
} // end function
} // end class
?>
ispconfig3-master-interface-lib/interface/lib/classes/plugin_base.inc.php 0000664 0000000 0000000 00000003511 12600761333 0027032 0 ustar 00root root 0000000 0000000 options = $options;
$this->plugin_name = $plugin_name;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/plugin_dbhistory.inc.php 0000664 0000000 0000000 00000005050 12600761333 0030127 0 ustar 00root root 0000000 0000000 tform->formDef["db_table"];
$db_table_idx = $app->tform->formDef["db_table_idx"];
$primary_id = $this->form->id;
if($_SESSION["s"]["user"]["typ"] == 'admin') {
$sql = "SELECT action, tstamp, user, data FROM sys_datalog WHERE dbtable = ? AND dbidx = ?";
$records = $app->db->queryAllRecords($sql, $db_table, $db_table_idx.":".$primary_id);
} else {
$sql = "SELECT action, tstamp, user, data FROM sys_datalog WHERE user = ? AND dbtable = ? AND dbidx = ?";
$records = $app->db->queryAllRecords($sql, $_SESSION["s"]["user"]["username"], $db_table, $db_table_idx.":".$primary_id);
}
if(is_array($records)) {
$content .= '
';
foreach($records as $rec) {
$content .= "
".date("d.m.Y", $rec["tstamp"])."
".$rec["user"]."
";
}
$content .= '
';
}
return $content;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/plugin_directive_snippets.inc.php 0000664 0000000 0000000 00000004354 12600761333 0032031 0 ustar 00root root 0000000 0000000 newTemplate('templates/web_directive_snippets.htm');
//* Loading language file
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_web_directive_snippets.lng";
include $lng_file;
$listTpl->setVar($wb);
$message = '';
$error = '';
$server_type = $app->getconf->get_server_config($this->form->dataRecord['server_id'], 'web');
$server_type = $server_type['server_type'];
$records = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND type = ? ORDER BY name ASC", $server_type);
for ($i = 0, $c = count($records); $i < $c; $i++)
{
$records[$i]['is_selected'] = false;
if ($this->form->dataRecord['directive_snippets_id'] === $records[$i]['directive_snippets_id'])
$records[$i]['is_selected'] = true;
}
$listTpl->setLoop('records', $records);
$list_name = 'directive_snippets_list';
$_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
$_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
$_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
$_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
$_SESSION["s"]["form"]["return_to"] = $list_name;
return $listTpl->grab();
}
public function onUpdate()
{
global $app, $conf;
if (isset($this->form->dataRecord['directive_snippets_id']) && $this->form->oldDataRecord['directive_snippets_id'] !== $this->form->dataRecord['directive_snippets_id']) {
$app->db->query('UPDATE web_domain SET directive_snippets_id = ? WHERE domain_id = ?', $this->form->dataRecord['directive_snippets_id'], $this->form->id);
}
}
public function onInsert()
{
global $app, $conf;
if (isset($this->form->dataRecord['directive_snippets_id'])) {
$app->db->query('UPDATE web_domain SET directive_snippets_id = ? WHERE domain_id = ?', $this->form->dataRecord['directive_snippets_id'], $this->form->id);
}
}
}
?> ispconfig3-master-interface-lib/interface/lib/classes/plugin_listview.inc.php 0000664 0000000 0000000 00000022222 12600761333 0027766 0 ustar 00root root 0000000 0000000 uses('listform');
$app->listform->loadListDef($this->options["listdef"]);
//$app->listform->SQLExtWhere = "type = 'alias'";
$listTpl = new tpl;
$listTpl->newTemplate('templates/'.$app->listform->listDef["name"].'_list.htm');
//die(print_r($app->tform_actions));
// Changing some of the list values to reflect that the list is called within a tform page
$app->listform->listDef["file"] = $app->tform->formDef["action"];
// $app->listform->listDef["page_params"] = "&id=".$app->tform_actions->id."&next_tab=".$_SESSION["s"]["form"]["tab"];
$app->listform->listDef["page_params"] = "&id=".$this->form->id."&next_tab=".$_SESSION["s"]["form"]["tab"];
$listTpl->setVar('parent_id', $this->form->id);
$listTpl->setVar('theme', $_SESSION['s']['theme']);
// Generate the SQL for searching
$sql_where = "";
if($app->listform->listDef["auth"] != 'no') {
if($_SESSION["s"]["user"]["typ"] != "admin") {
$sql_where = $app->tform->getAuthSQL('r')." and";
}
}
if($this->options["sqlextwhere"] != '') {
$sql_where .= " ".$this->options["sqlextwhere"]." and";
}
$sql_where = $app->listform->getSearchSQL($sql_where);
$listTpl->setVar($app->listform->searchValues);
// Generate SQL for paging
$limit_sql = $app->listform->getPagingSQL($sql_where);
$listTpl->setVar("paging", $app->listform->pagingHTML);
$sql_order_by = '';
if(isset($this->options["sql_order_by"])) {
$sql_order_by = $this->options["sql_order_by"];
}
//* Limit each page
$limits = array('5'=>'5', '15'=>'15', '25'=>'25', '50'=>'50', '100'=>'100', '999999999' => 'all');
//* create options and set selected, if default -> 15 is selected
$options='';
foreach($limits as $key => $val){
$options .= '';
}
$listTpl->setVar('search_limit', '');
//Sorting
if(!isset($_SESSION['search'][$app->listform->listDef["name"]]['order'])){
$_SESSION['search'][$app->listform->listDef["name"]]['order'] = '';
}
if(!empty($_GET['orderby'])){
$order = str_replace('tbl_col_', '', $_GET['orderby']);
//* Check the css class submited value
if (preg_match("/^[a-z\_]{1,}$/", $order)) {
if($_SESSION['search'][$app->listform->listDef["name"]]['order'] == $order){
$_SESSION['search'][$app->listform->listDef["name"]]['order'] = $order.' DESC';
} else {
$_SESSION['search'][$app->listform->listDef["name"]]['order'] = $order;
}
}
}
// If a manuel oder by like customers isset the sorting will be infront
if(!empty($_SESSION['search'][$app->listform->listDef["name"]]['order'])){
if(empty($sql_order_by)){
$sql_order_by = "ORDER BY ".$_SESSION['search'][$app->listform->listDef["name"]]['order'];
} else {
$sql_order_by = str_replace("ORDER BY ", "ORDER BY ".$_SESSION['search'][$app->listform->listDef["name"]]['order'].', ', $sql_order_by);
}
}
// Loading language field
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_".$app->listform->listDef['name']."_list.lng";
include $lng_file;
$listTpl->setVar($wb);
// Get the data
$records = $app->db->queryAllRecords("SELECT * FROM ?? WHERE $sql_where $sql_order_by $limit_sql", $app->listform->listDef["table"]);
$bgcolor = "#FFFFFF";
if(is_array($records)) {
$idx_key = $app->listform->listDef["table_idx"];
foreach($records as $rec) {
$rec = $app->listform->decode($rec);
// Change of color
$bgcolor = ($bgcolor == "#FFFFFF")?"#EEEEEE":"#FFFFFF";
$rec["bgcolor"] = $bgcolor;
// substitute value for select fields
foreach($app->listform->listDef["item"] as $field) {
$key = $field["field"];
if($field['formtype'] == "SELECT") {
if(strtolower($rec[$key]) == 'y' or strtolower($rec[$key]) == 'n') {
// Set a additional image variable for bolean fields
$rec['_'.$key.'_'] = (strtolower($rec[$key]) == 'y')?'x16/tick_circle.png':'x16/cross_circle.png';
}
//* substitute value for select field
@$rec[$key] = $field['value'][$rec[$key]];
}
// Create a lowercase version of every item
$rec[$key.'_lowercase'] = strtolower($rec[$key]);
}
// The variable "id" contains always the index field
$rec["id"] = $rec[$idx_key];
$rec["delete_confirmation"] = $wb['delete_confirmation'];
$records_new[] = $rec;
}
}
$listTpl->setLoop('records', @$records_new);
// Setting Returnto information in the session
$list_name = $app->listform->listDef["name"];
// $_SESSION["s"]["list"][$list_name]["parent_id"] = $app->tform_actions->id;
$_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
$_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
$_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
$_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
$_SESSION["s"]["form"]["return_to"] = $list_name;
//die(print_r($_SESSION["s"]["list"][$list_name]));
// defaults
$listTpl->setVar('app_title', $app->_conf['app_title']);
if(isset($_SESSION['s']['user'])) {
$listTpl->setVar('app_version', $app->_conf['app_version']);
// get pending datalog changes
$datalog = $app->db->datalogStatus();
$listTpl->setVar('datalog_changes_txt', $app->lng('datalog_changes_txt'));
$listTpl->setVar('datalog_changes_end_txt', $app->lng('datalog_changes_end_txt'));
$listTpl->setVar('datalog_changes_count', $datalog['count']);
$listTpl->setLoop('datalog_changes', $datalog['entries']);
} else {
$listTpl->setVar('app_version', '');
}
$listTpl->setVar('app_link', $app->_conf['app_link']);
$listTpl->setVar('app_logo', $app->_conf['logo']);
$listTpl->setVar('phpsessid', session_id());
$listTpl->setVar('theme', $_SESSION['s']['theme']);
$listTpl->setVar('html_content_encoding', $app->_conf['html_content_encoding']);
$listTpl->setVar('delete_confirmation', $app->lng('delete_confirmation'));
//print_r($_SESSION);
if(isset($_SESSION['s']['module']['name'])) {
$listTpl->setVar('app_module', $_SESSION['s']['module']['name']);
}
if(isset($_SESSION['s']['user']) && $_SESSION['s']['user']['typ'] == 'admin') {
$listTpl->setVar('is_admin', 1);
}
if(isset($_SESSION['s']['user']) && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
$listTpl->setVar('is_reseller', 1);
}
/* Show username */
if(isset($_SESSION['s']['user'])) {
$listTpl->setVar('cpuser', $_SESSION['s']['user']['username']);
$listTpl->setVar('logout_txt', $app->lng('logout_txt'));
/* Show search field only for normal users, not mail users */
if(stristr($_SESSION['s']['user']['username'], '@')){
$listTpl->setVar('usertype', 'mailuser');
} else {
$listTpl->setVar('usertype', 'normaluser');
}
}
/* Global Search */
$listTpl->setVar('globalsearch_resultslimit_of_txt', $app->lng('globalsearch_resultslimit_of_txt'));
$listTpl->setVar('globalsearch_resultslimit_results_txt', $app->lng('globalsearch_resultslimit_results_txt'));
$listTpl->setVar('globalsearch_noresults_text_txt', $app->lng('globalsearch_noresults_text_txt'));
$listTpl->setVar('globalsearch_noresults_limit_txt', $app->lng('globalsearch_noresults_limit_txt'));
$listTpl->setVar('globalsearch_searchfield_watermark_txt', $app->lng('globalsearch_searchfield_watermark_txt'));
return $listTpl->grab();
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/quota_lib.inc.php 0000664 0000000 0000000 00000026736 12600761333 0026537 0 ustar 00root root 0000000 0000000 db->queryAllRecords("SELECT data from monitor_data WHERE type = 'harddisk_quota' ORDER BY created DESC");
$monitor_data = array();
if(is_array($tmp_rec)) {
foreach ($tmp_rec as $tmp_mon) {
$monitor_data = array_merge_recursive($monitor_data, unserialize($app->db->unquote($tmp_mon['data'])));
}
}
//print_r($monitor_data);
// select all websites or websites belonging to client
$sites = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' AND type = 'vhost'".(($clientid != null)?" AND sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)":''), $clientid);
//print_r($sites);
if(is_array($sites) && !empty($sites)){
for($i=0;$i $sites[$i]['used'][1]){
$sites[$i]['used'] = $sites[$i]['used'][0];
} else {
$sites[$i]['used'] = $sites[$i]['used'][1];
}
}
if (!is_numeric($sites[$i]['soft'])) $sites[$i]['soft']=$sites[$i]['soft'][1];
if (!is_numeric($sites[$i]['hard'])) $sites[$i]['hard']=$sites[$i]['hard'][1];
if (!is_numeric($sites[$i]['files'])) $sites[$i]['files']=$sites[$i]['files'][1];
$sites[$i]['used_raw'] = $sites[$i]['used'];
$sites[$i]['soft_raw'] = $sites[$i]['soft'];
$sites[$i]['hard_raw'] = $sites[$i]['hard'];
$sites[$i]['files_raw'] = $sites[$i]['files'];
$sites[$i]['used_percentage'] = ($sites[$i]['soft'] > 0 && $sites[$i]['used'] > 0 ? round($sites[$i]['used'] * 100 / $sites[$i]['soft']) : 0);
if ($readable) {
// colours
$sites[$i]['display_colour'] = '#000000';
if($sites[$i]['soft'] > 0){
$used_ratio = $sites[$i]['used']/$sites[$i]['soft'];
} else {
$used_ratio = 0;
}
if($used_ratio >= 0.8) $sites[$i]['display_colour'] = '#fd934f';
if($used_ratio >= 1) $sites[$i]['display_colour'] = '#cc0000';
if($sites[$i]['used'] > 1024) {
$sites[$i]['used'] = round($sites[$i]['used'] / 1024, 2).' MB';
} else {
if ($sites[$i]['used'] != '') $sites[$i]['used'] .= ' KB';
}
if($sites[$i]['soft'] > 1024) {
$sites[$i]['soft'] = round($sites[$i]['soft'] / 1024, 2).' MB';
} else {
$sites[$i]['soft'] .= ' KB';
}
if($sites[$i]['hard'] > 1024) {
$sites[$i]['hard'] = round($sites[$i]['hard'] / 1024, 2).' MB';
} else {
$sites[$i]['hard'] .= ' KB';
}
if($sites[$i]['soft'] == " KB") $sites[$i]['soft'] = $app->lng('unlimited');
if($sites[$i]['hard'] == " KB") $sites[$i]['hard'] = $app->lng('unlimited');
if($sites[$i]['soft'] == '0 B' || $sites[$i]['soft'] == '0 KB' || $sites[$i]['soft'] == '0') $sites[$i]['soft'] = $app->lng('unlimited');
if($sites[$i]['hard'] == '0 B' || $sites[$i]['hard'] == '0 KB' || $sites[$i]['hard'] == '0') $sites[$i]['hard'] = $app->lng('unlimited');
/*
if(!strstr($sites[$i]['used'],'M') && !strstr($sites[$i]['used'],'K')) $sites[$i]['used'].= ' B';
if(!strstr($sites[$i]['soft'],'M') && !strstr($sites[$i]['soft'],'K')) $sites[$i]['soft'].= ' B';
if(!strstr($sites[$i]['hard'],'M') && !strstr($sites[$i]['hard'],'K')) $sites[$i]['hard'].= ' B';
*/
}
else {
if (empty($sites[$i]['soft'])) $sites[$i]['soft'] = -1;
if (empty($sites[$i]['hard'])) $sites[$i]['hard'] = -1;
if($sites[$i]['soft'] == '0 B' || $sites[$i]['soft'] == '0 KB' || $sites[$i]['soft'] == '0') $sites[$i]['soft'] = -1;
if($sites[$i]['hard'] == '0 B' || $sites[$i]['hard'] == '0 KB' || $sites[$i]['hard'] == '0') $sites[$i]['hard'] = -1;
}
}
}
return $sites;
}
public function get_trafficquota_data($clientid = null, $lastdays = 0) {
global $app;
$traffic_data = array();
// select vhosts (belonging to client)
if($clientid != null){
$sql_where = " AND sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)";
}
$sites = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' AND (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias')".$sql_where, $clientid);
$hostnames = array();
$traffic_data = array();
foreach ($sites as $site) {
$hostnames[] = $site['domain'];
$traffic_data[$site['domain']]['domain_id'] = $site['domain_id'];
}
// fetch all traffic-data of selected vhosts
if (!empty($hostnames)) {
$tmp_year = date('Y');
$tmp_month = date('m');
// This Month
$tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE YEAR(traffic_date) = ? AND MONTH(traffic_date) = ? AND hostname IN ? GROUP BY hostname", $tmp_year, $tmp_month, $hostnames);
foreach ($tmp_recs as $tmp_rec) {
$traffic_data[$tmp_rec['hostname']]['this_month'] = $tmp_rec['t'];
}
// This Year
$tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE YEAR(traffic_date) = ? AND hostname IN ? GROUP BY hostname", $tmp_year, $hostnames);
foreach ($tmp_recs as $tmp_rec) {
$traffic_data[$tmp_rec['hostname']]['this_year'] = $tmp_rec['t'];
}
$tmp_year = date('Y', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
$tmp_month = date('m', mktime(0, 0, 0, date("m")-1, date("d"), date("Y")));
// Last Month
$tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE YEAR(traffic_date) = ? AND MONTH(traffic_date) = ? AND hostname IN ? GROUP BY hostname", $tmp_year, $tmp_month, $hostnames);
foreach ($tmp_recs as $tmp_rec) {
$traffic_data[$tmp_rec['hostname']]['last_month'] = $tmp_rec['t'];
}
$tmp_year = date('Y', mktime(0, 0, 0, date("m"), date("d"), date("Y")-1));
// Last Year
$tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE YEAR(traffic_date) = ? AND hostname IN ? GROUP BY hostname", $tmp_year, $hostnames);
foreach ($tmp_recs as $tmp_rec) {
$traffic_data[$tmp_rec['hostname']]['last_year'] = $tmp_rec['t'];
}
if (is_int($lastdays) && ($lastdays > 0)) {
// Last xx Days
$tmp_recs = $app->db->queryAllRecords("SELECT hostname, SUM(traffic_bytes) as t FROM web_traffic WHERE (traffic_date >= DATE_SUB(NOW(), INTERVAL ? DAY)) AND hostname IN ? GROUP BY hostname", $lastdays, $hostnames);
foreach ($tmp_recs as $tmp_rec) {
$traffic_data[$tmp_rec['hostname']]['lastdays'] = $tmp_rec['t'];
}
}
}
return $traffic_data;
}
public function get_mailquota_data($clientid = null, $readable = true) {
global $app;
$tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'email_quota' ORDER BY created DESC");
$monitor_data = array();
if(is_array($tmp_rec)) {
foreach ($tmp_rec as $tmp_mon) {
//$monitor_data = array_merge_recursive($monitor_data,unserialize($app->db->unquote($tmp_mon['data'])));
$tmp_array = unserialize($app->db->unquote($tmp_mon['data']));
if(is_array($tmp_array)) {
foreach($tmp_array as $username => $data) {
if(!$monitor_data[$username]['used']) $monitor_data[$username]['used'] = $data['used'];
}
}
}
}
//print_r($monitor_data);
// select all email accounts or email accounts belonging to client
$emails = $app->db->queryAllRecords("SELECT * FROM mail_user".(($clientid != null)? " WHERE sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)" : ''), $clientid);
//print_r($emails);
if(is_array($emails) && !empty($emails)){
for($i=0;$i 0);
if (!is_numeric($emails[$i]['used'])) $emails[$i]['used']=$emails[$i]['used'][1];
$emails[$i]['quota_raw'] = $emails[$i]['quota'];
$emails[$i]['used_raw'] = $emails[$i]['used'];
$emails[$i]['used_percentage'] = ($emails[$i]['quota'] > 0 && $emails[$i]['used'] > 0 ? round($emails[$i]['used'] * 100 / $emails[$i]['quota']) : 0);
if ($readable) {
// colours
$emails[$i]['display_colour'] = '#000000';
if($emails[$i]['quota'] > 0){
$used_ratio = $emails[$i]['used']/$emails[$i]['quota'];
} else {
$used_ratio = 0;
}
if($used_ratio >= 0.8) $emails[$i]['display_colour'] = '#fd934f';
if($used_ratio >= 1) $emails[$i]['display_colour'] = '#cc0000';
if($emails[$i]['quota'] == 0){
$emails[$i]['quota'] = $app->lng('unlimited');
} else {
$emails[$i]['quota'] = round($emails[$i]['quota'] / 1048576, 4).' MB';
}
if($emails[$i]['used'] < 1544000) {
$emails[$i]['used'] = round($emails[$i]['used'] / 1024, 4).' KB';
} else {
$emails[$i]['used'] = round($emails[$i]['used'] / 1048576, 4).' MB';
}
}
}
}
return $emails;
}
public function get_databasequota_data($clientid = null, $readable = true) {
global $app;
$tmp_rec = $app->db->queryAllRecords("SELECT data from monitor_data WHERE type = 'database_size' ORDER BY created DESC");
$monitor_data = array();
if(is_array($tmp_rec)) {
foreach ($tmp_rec as $tmp_mon) {
$tmp_array = unserialize($app->db->unquote($tmp_mon['data']));
if(is_array($tmp_array)) {
foreach($tmp_array as $key => $data) {
if(!isset($monitor_data[$data['database_name']]['size'])) $monitor_data[$data['database_name']]['size'] = $data['size'];
}
}
}
}
//print_r($monitor_data);
// select all databases belonging to client
$databases = $app->db->queryAllRecords("SELECT * FROM web_database".(($clientid != null)? " WHERE sys_groupid = (SELECT default_group FROM sys_user WHERE client_id=?)" : ''), $clientid);
//print_r($databases);
if(is_array($databases) && !empty($databases)){
for($i=0;$i 0) && ($databases[$i]['used'] > 0)) ? round($databases[$i]['used'] * 100 / $databases[$i]['database_quota']) : 0;
if ($readable) {
// colours
$databases[$i]['display_colour'] = '#000000';
if($databases[$i]['database_quota'] > 0){
$used_ratio = $databases[$i]['used']/$databases[$i]['database_quota'];
} else {
$used_ratio = 0;
}
if($used_ratio >= 0.8) $databases[$i]['display_colour'] = '#fd934f';
if($used_ratio >= 1) $databases[$i]['display_colour'] = '#cc0000';
if($databases[$i]['database_quota'] == 0){
$databases[$i]['database_quota'] = $app->lng('unlimited');
} else {
$databases[$i]['database_quota'] = round($databases[$i]['database_quota'] / 1048576, 4).' MB';
}
if($databases[$i]['used'] < 1544000) {
$databases[$i]['used'] = round($databases[$i]['used'] / 1024, 4).' KB';
} else {
$databases[$i]['used'] = round($databases[$i]['used'] / 1048576, 4).' MB';
}
}
}
}
return $databases;
}
} ispconfig3-master-interface-lib/interface/lib/classes/remote.d/ 0000775 0000000 0000000 00000000000 12600761333 0024776 5 ustar 00root root 0000000 0000000 ispconfig3-master-interface-lib/interface/lib/classes/remote.d/admin.inc.php 0000664 0000000 0000000 00000010171 12600761333 0027347 0 ustar 00root root 0000000 0000000
*/
class remoting_admin extends remoting {
/**
* set record permissions in any table
* @param string session_id
* @param string index_field
* @param string index_value
* @param array permissions
* @author "ispcomm", improved by M. Cramer
*/
public function update_record_permissions($tablename, $index_field, $index_value, $permissions) {
global $app;
if(!$this->checkPerm($session_id, 'admin_record_permissions')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
foreach($permissions as $key => $value) { // make sure only sys_ fields are updated
switch($key) {
case 'sys_userid':
// check if userid is valid
$check = $app->db->queryOneRecord('SELECT userid FROM sys_user WHERE userid = ?', $app->functions->intval($value));
if(!$check || !$check['userid']) {
$this->server->fault('invalid parameters', $value . ' is no valid sys_userid.');
return false;
}
$permissions[$key] = $app->functions->intval($value);
break;
case 'sys_groupid':
// check if groupid is valid
$check = $app->db->queryOneRecord('SELECT groupid FROM sys_group WHERE groupid = ?', $app->functions->intval($value));
if(!$check || !$check['groupid']) {
$this->server->fault('invalid parameters', $value . ' is no valid sys_groupid.');
return false;
}
$permissions[$key] = $app->functions->intval($value);
break;
case 'sys_perm_user':
case 'sys_perm_group':
// check if permissions are valid
$value = strtolower($value);
if(!preg_match('/^[riud]+$/', $value)) {
$this->server->fault('invalid parameters', $value . ' is no valid permission string.');
return false;
}
$newvalue = '';
if(strpos($value, 'r') !== false) $newvalue .= 'r';
if(strpos($value, 'i') !== false) $newvalue .= 'i';
if(strpos($value, 'u') !== false) $newvalue .= 'u';
if(strpos($value, 'd') !== false) $newvalue .= 'd';
$permissions[$key] = $newvalue;
unset($newvalue);
break;
default:
$this->server->fault('invalid parameters', 'Only sys_userid, sys_groupid, sys_perm_user and sys_perm_group parameters can be changed with this function.');
break;
}
}
return $app->db->datalogUpdate( $tablename, $permissions, $index_field, $index_value ) ;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/remote.d/aps.inc.php 0000664 0000000 0000000 00000026641 12600761333 0027053 0 ustar 00root root 0000000 0000000
Copyright (c) Profi Webdesign Dominik Müller
*/
class remoting_aps extends remoting {
//* Functions for APS
public function sites_aps_update_package_list($session_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_aps_update_package_list')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
require_once '../../../lib/config.inc.php';
$app->load('aps_crawler');
$aps = new ApsCrawler($app, true); // true = Interface mode, false = Server mode
$aps->startCrawler();
$aps->parseFolderToDB();
$aps->fixURLs();
return true;
}
public function sites_aps_available_packages_list($session_id, $params = array())
{
global $app;
if(!$this->checkPerm($session_id, 'sites_aps_available_packages_list')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->load('aps_base');
if (isset($params['all_packages']) && ($params['all_packages'] == true)) {
$where = '(aps_packages.package_status = '.PACKAGE_ENABLED.' OR aps_packages.package_status = '.PACKAGE_LOCKED.')';
}
else {
$where = 'aps_packages.package_status = '.PACKAGE_ENABLED;
}
$sql = 'SELECT * FROM aps_packages WHERE '.$where.' ORDER BY aps_packages.name, aps_packages.version';
return $app->db->queryAllRecords($sql);
}
public function sites_aps_get_package_details($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_aps_get_package_details')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->load('aps_guicontroller');
$gui = new ApsGUIController($app);
// Package-ID Check
if (isset($primary_id))
{
$newest_pkg_id = $gui->getNewestPackageID($pkg_id);
if($newest_pkg_id != 0) $primary_id = $newest_pkg_id;
}
// Make sure an integer ID is given
if (!isset($primary_id) || !$gui->isValidPackageID($primary_id, true)) {// always adminflag
$this->server->fault('package_error', 'The given Package ID is not valid.');
return false;
}
// Get package details
$details = $gui->getPackageDetails($primary_id);
if (isset($details['error'])) {
$this->server->fault('package_error', $details['error']);
return false;
}
// encode all parts to ensure SOAP-XML-format
array_walk_recursive($details, function(&$item, &$key) { $item = utf8_encode($item); } );
// Special handling for license-text because of too much problems with soap-transport
$details['License content'] = base64_encode($details['License content']);
return $details;
}
public function sites_aps_get_package_file($session_id, $primary_id, $filename) {
global $app;
if(!$this->checkPerm($session_id, 'sites_aps_get_package_file')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->load('aps_guicontroller');
$gui = new ApsGUIController($app);
// Package-ID Check
if (isset($primary_id))
{
$newest_pkg_id = $gui->getNewestPackageID($pkg_id);
if($newest_pkg_id != 0) $primary_id = $newest_pkg_id;
}
// Make sure an integer ID is given
if (!isset($primary_id) || !$gui->isValidPackageID($primary_id, true)) {// always adminflag
$this->server->fault('package_error', 'The given Package ID is not valid.');
return false;
}
// Get package details
$details = $gui->getPackageDetails($primary_id);
if (isset($details['error'])) {
$this->server->fault('package_error', $details['error']);
return false;
}
// find file in details
$found = false;
if (basename($details['Icon']) == $filename) $found = true;
if (!$found && isset($details['Screenshots']) && is_array($details['Screenshots']))
foreach ($details['Screenshots'] as $screen) { if (basename($screen['ScreenPath']) == $filename) { $found = true; break; } }
if (!$found) {
$this->server->fault('package_error', 'File not found in package.');
return false;
}
return base64_encode(file_get_contents(ISPC_ROOT_PATH.'/web/sites/aps_meta_packages/'.$details['path'].'/'.$filename));
}
public function sites_aps_get_package_settings($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_aps_get_package_details')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->load('aps_guicontroller');
$gui = new ApsGUIController($app);
// Package-ID Check
if (isset($primary_id))
{
$newest_pkg_id = $gui->getNewestPackageID($pkg_id);
if($newest_pkg_id != 0) $primary_id = $newest_pkg_id;
}
// Make sure an integer ID is given
if (!isset($primary_id) || !$gui->isValidPackageID($primary_id, true)) {// always adminflag
$this->server->fault('package_error', 'The given Package ID is not valid.');
return false;
}
// Get package settings
$settings = $gui->getPackageSettings($primary_id);
if (isset($settings['error'])) {
$this->server->fault('package_error', $settings['error']);
return false;
}
// encode all parts to ensure SOAP-XML-format
array_walk_recursive($settings, function(&$item, &$key) { $item = utf8_encode($item); } );
return $settings;
}
public function sites_aps_change_package_status($session_id, $primary_id, $params)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_aps_change_package_status')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->load('aps_base');
$app->load('aps_guicontroller');
$gui = new ApsGUIController($app);
// Make sure an integer ID is given
if (!isset($primary_id) || !$gui->isValidPackageID($primary_id, true)) {// always adminflag
$this->server->fault('package_error', 'The given Package ID is not valid.');
return false;
}
if(!isset($params['package_status']) || (($params['package_status'] != PACKAGE_ENABLED) && ($params['package_status'] != PACKAGE_LOCKED))) {
$this->server->fault('package_error', 'Wrong new status: '.$params['package_status']);
return false;
}
$sql = "UPDATE aps_packages SET package_status = ? WHERE id = ?";
$app->db->query($sql, $params['package_status'], $app->functions->intval($primary_id));
return true;
}
public function sites_aps_install_package($session_id, $primary_id, $params)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_aps_install_package')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->load('aps_guicontroller');
$gui = new ApsGUIController($app);
// Package-ID Check
if (isset($primary_id))
{
$newest_pkg_id = $gui->getNewestPackageID($primary_id);
if($newest_pkg_id != 0) $primary_id = $newest_pkg_id;
}
// Make sure an integer ID is given
if (!isset($primary_id) || !$gui->isValidPackageID($primary_id, true)) {// always adminflag
$this->server->fault('package_error', 'The given Package ID is not valid.');
return false;
}
// Get package details
$details = $gui->getPackageDetails($primary_id);
if (isset($details['error'])) {
$this->server->fault('package_error', $details['error']);
return false;
}
$settings = $gui->getPackageSettings($primary_id);
if (isset($settings['error'])) {
$this->server->fault('package_error', $settings['error']);
return false;
}
// Check given Site/VHostDomain
if (!isset($params['main_domain'])) {
$this->server->fault('invalid parameters', 'No valid domain given.');
return false;
}
$sql = "SELECT * FROM web_domain WHERE domain = ?";
$domain = $app->db->queryOneRecord($sql, $params['main_domain']);
if (!$domain) {
$this->server->fault('invalid parameters', 'No valid domain given.');
return false;
}
$domains = array($domain['domain']); // Simulate correct Domain-List
$result = $gui->validateInstallerInput($params, $details, $domains, $settings);
if(empty($result['error']))
{
return $gui->createPackageInstance($result['input'], $primary_id);
}
$this->server->fault('invalid parameters', implode(' ', $result['error']));
return false;
}
public function sites_aps_instance_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_aps_instance_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$sql = "SELECT * FROM aps_instances WHERE id = ?";
$result = $app->db->queryOneRecord($sql, $app->functions->intval($primary_id));
return $result;
}
public function sites_aps_instance_settings_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_aps_instance_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$sql = "SELECT * FROM aps_instances_settings WHERE instance_id = ?";
$result = $app->db->queryAllRecords($sql, $app->functions->intval($primary_id));
return $result;
}
public function sites_aps_instance_delete($session_id, $primary_id, $params = array())
{
global $app;
if(!$this->checkPerm($session_id, 'sites_aps_instance_delete')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->load('aps_guicontroller');
$gui = new ApsGUIController($app);
// Check if Instance exists
$sql = "SELECT * FROM aps_instances WHERE id = ?";
$result = $app->db->queryOneRecord($sql, $primary_id);
if (!$result) {
$this->server->fault('instance_error', 'No valid instance id given.');
return false;
}
$gui->deleteInstance($primary_id, (isset($params['keep_database']) && ($params['keep_database'] === true)));
return true;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/remote.d/client.inc.php 0000664 0000000 0000000 00000057077 12600761333 0027555 0 ustar 00root root 0000000 0000000
*/
class remoting_client extends remoting {
/*
*
*
*
* * Client functions
*
*
*/
//* Get client details
public function client_get($session_id, $client_id)
{
global $app;
if(!$this->checkPerm($session_id, 'client_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../client/form/client.tform.php');
$data = $app->remoting_lib->getDataRecord($client_id);
// we need to get the new-style templates for backwards-compatibility - maybe we remove this in a later version
if(is_array($data) && count($data) > 0) {
if(isset($data['client_id'])) {
// this is a single record
if($data['template_additional'] == '') {
$tpls = $app->db->queryAllRecords('SELECT CONCAT(`assigned_template_id`, \':\', `client_template_id`) as `item` FROM `client_template_assigned` WHERE `client_id` = ?', $data['client_id']);
$tpl_arr = array();
if($tpls) {
foreach($tpls as $tpl) $tpl_arr[] = $tpl['item'];
}
$data['template_additional'] = implode('/', $tpl_arr);
unset($tpl_arr);
unset($tpls);
}
} elseif(isset($data[0]['client_id'])) {
// multiple client records
foreach($data as $index => $client) {
if($client['template_additional'] == '') {
$tpls = $app->db->queryAllRecords('SELECT CONCAT(`assigned_template_id`, \':\', `client_template_id`) as `item` FROM `client_template_assigned` WHERE `client_id` = ?', $client['client_id']);
$tpl_arr = array();
if($tpls) {
foreach($tpls as $tpl) $tpl_arr[] = $tpl['item'];
}
$data[$index]['template_additional'] = implode('/', $tpl_arr); // dont use the $client array here - changes would not be returned to soap
}
unset($tpl_arr);
unset($tpls);
}
}
}
return $data;
}
public function client_get_id($session_id, $sys_userid)
{
global $app;
if(!$this->checkPerm($session_id, 'client_get_id')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$sys_userid = $app->functions->intval($sys_userid);
$rec = $app->db->queryOneRecord("SELECT client_id FROM sys_user WHERE userid = ?", $sys_userid);
if(isset($rec['client_id'])) {
return $app->functions->intval($rec['client_id']);
} else {
throw new SoapFault('no_client_found', 'There is no sysuser account for this client ID.');
return false;
}
}
//* Get the contact details to send a email like email address, name, etc.
public function client_get_emailcontact($session_id, $client_id) {
global $app;
if(!$this->checkPerm($session_id, 'client_get_emailcontact')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$client_id = $app->functions->intval($client_id);
$rec = $app->db->queryOneRecord("SELECT company_name,contact_name,gender,email,language FROM client WHERE client_id = ?", $client_id);
if(is_array($rec)) {
return $rec;
} else {
throw new SoapFault('no_client_found', 'There is no client with this client ID.');
return false;
}
}
public function client_get_groupid($session_id, $client_id)
{
global $app;
if(!$this->checkPerm($session_id, 'client_get_id')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$client_id = $app->functions->intval($client_id);
$rec = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client_id);
if(isset($rec['groupid'])) {
return $app->functions->intval($rec['groupid']);
} else {
throw new SoapFault('no_group_found', 'There is no group for this client ID.');
return false;
}
}
public function client_add($session_id, $reseller_id, $params)
{
global $app;
if (!$this->checkPerm($session_id, 'client_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if(!isset($params['parent_client_id']) || $params['parent_client_id'] == 0) $params['parent_client_id'] = $reseller_id;
if($params['parent_client_id']) {
// check if this one is reseller
$check = $app->db->queryOneRecord('SELECT `limit_client` FROM `client` WHERE `client_id` = ?', intval($params['parent_client_id']));
if($check['limit_client'] == 0) {
$this->server->fault('Invalid reseller', 'Selected client is not a reseller.');
return false;
}
if(isset($params['limit_client']) && $params['limit_client'] != 0) {
$this->server->fault('Invalid reseller', 'Reseller cannot be client of another reseller.');
return false;
}
}
$affected_rows = $this->klientadd('../client/form/' . (isset($params['limit_client']) && $params['limit_client'] != 0 ? 'reseller' : 'client') . '.tform.php', $reseller_id, $params);
return $affected_rows;
}
public function client_update($session_id, $client_id, $reseller_id, $params)
{
global $app;
if (!$this->checkPerm($session_id, 'client_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../client/form/' . (isset($params['limit_client']) && $params['limit_client'] != 0 ? 'reseller' : 'client') . '.tform.php');
$old_rec = $app->remoting_lib->getDataRecord($client_id);
//* merge old record with params, so only new values have to be set in $params
$params = $app->functions->array_merge($old_rec,$params);
if(!isset($params['parent_client_id']) || $params['parent_client_id'] == 0) $params['parent_client_id'] = $reseller_id;
if($params['parent_client_id']) {
// check if this one is reseller
$check = $app->db->queryOneRecord('SELECT `limit_client` FROM `client` WHERE `client_id` = ?', intval($params['parent_client_id']));
if($check['limit_client'] == 0) {
$this->server->fault('Invalid reseller', 'Selected client is not a reseller.');
return false;
}
if(isset($params['limit_client']) && $params['limit_client'] != 0) {
$this->server->fault('Invalid reseller', 'Reseller cannot be client of another reseller.');
return false;
}
}
// we need the previuos templates assigned here
$this->oldTemplatesAssigned = $app->db->queryAllRecords('SELECT * FROM `client_template_assigned` WHERE `client_id` = ?', $client_id);
if(!is_array($this->oldTemplatesAssigned) || count($this->oldTemplatesAssigned) < 1) {
// check previous type of storing templates
$tpls = explode('/', $old_rec['template_additional']);
$this->oldTemplatesAssigned = array();
foreach($tpls as $item) {
$item = trim($item);
if(!$item) continue;
$this->oldTemplatesAssigned[] = array('assigned_template_id' => 0, 'client_template_id' => $item, 'client_id' => $client_id);
}
unset($tpls);
}
if(isset($params['template_additional'])) {
$app->uses('client_templates');
$templates = explode('/', $params['template_additional']);
$params['template_additional'] = '';
$app->client_templates->update_client_templates($client_id, $templates);
unset($templates);
}
$affected_rows = $this->updateQuery('../client/form/' . (isset($params['limit_client']) && $params['limit_client'] != 0 ? 'reseller' : 'client') . '.tform.php', $reseller_id, $client_id, $params, 'client:' . ($reseller_id ? 'reseller' : 'client') . ':on_after_update');
$app->remoting_lib->ispconfig_sysuser_update($params, $client_id);
return $affected_rows;
}
public function client_template_additional_get($session_id, $client_id) {
global $app;
if(!$this->checkPerm($session_id, 'client_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if(@is_numeric($client_id)) {
$sql = "SELECT * FROM `client_template_assigned` WHERE `client_id` = ?";
return $app->db->queryOneRecord($sql, $client_id);
} else {
$this->server->fault('The ID must be an integer.');
return array();
}
}
private function _set_client_formdata($client_id) {
global $app;
$this->id = $client_id;
$this->dataRecord = $app->db->queryOneRecord('SELECT * FROM `client` WHERE `client_id` = ?', $client_id);
$this->oldDataRecord = $this->dataRecord;
$this->oldTemplatesAssigned = $app->db->queryAllRecords('SELECT * FROM `client_template_assigned` WHERE `client_id` = ?', $client_id);
if(!is_array($this->oldTemplatesAssigned) || count($this->oldTemplatesAssigned) < 1) {
// check previous type of storing templates
$tpls = explode('/', $this->oldDataRecord['template_additional']);
$this->oldTemplatesAssigned = array();
foreach($tpls as $item) {
$item = trim($item);
if(!$item) continue;
$this->oldTemplatesAssigned[] = array('assigned_template_id' => 0, 'client_template_id' => $item, 'client_id' => $client_id);
}
unset($tpls);
}
}
public function client_template_additional_add($session_id, $client_id, $template_id) {
global $app;
if(!$this->checkPerm($session_id, 'client_update')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if(@is_numeric($client_id) && @is_numeric($template_id)) {
// check if client exists
$check = $app->db->queryOneRecord('SELECT `client_id` FROM `client` WHERE `client_id` = ?', $client_id);
if(!$check) {
$this->server->fault('Invalid client');
return false;
}
// check if template exists
$check = $app->db->queryOneRecord('SELECT `template_id` FROM `client_template` WHERE `template_id` = ?', $template_id);
if(!$check) {
$this->server->fault('Invalid template');
return false;
}
// for the update event we have to cheat a bit
$this->_set_client_formdata($client_id);
$sql = "INSERT INTO `client_template_assigned` (`client_id`, `client_template_id`) VALUES (?, ?)";
$app->db->query($sql, $client_id, $template_id);
$insert_id = $app->db->insertID();
$app->plugin->raiseEvent('client:client:on_after_update', $this);
return $insert_id;
} else {
$this->server->fault('The IDs must be of type integer.');
return false;
}
}
public function client_template_additional_delete($session_id, $client_id, $assigned_template_id) {
global $app;
if(!$this->checkPerm($session_id, 'client_update')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if(@is_numeric($client_id) && @is_numeric($template_id)) {
// check if client exists
$check = $app->db->queryOneRecord('SELECT `client_id` FROM `client` WHERE `client_id` = ?', $client_id);
if(!$check) {
$this->server->fault('Invalid client');
return false;
}
// check if template exists
$check = $app->db->queryOneRecord('SELECT `assigned_template_id` FROM `client_template_assigned` WHERE `assigned_template_id` = ?', $assigned_template_id);
if(!$check) {
$this->server->fault('Invalid template');
return false;
}
// for the update event we have to cheat a bit
$this->_set_client_formdata($client_id);
$sql = "DELETE FROM `client_template_assigned` WHERE `assigned_template_id` = ? AND `client_id` = ?";
$app->db->query($sql, $template_id, $client_id);
$affected_rows = $app->db->affectedRows();
$app->plugin->raiseEvent('client:client:on_after_update', $this);
return $affected_rows;
} else {
$this->server->fault('The IDs must be of type integer.');
return false;
}
}
public function client_delete($session_id, $client_id)
{
global $app;
if (!$this->checkPerm($session_id, 'client_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../client/form/client.tform.php', $client_id);
$app->remoting_lib->ispconfig_sysuser_delete($client_id);
return $affected_rows;
}
// -----------------------------------------------------------------------------------------------
public function client_delete_everything($session_id, $client_id)
{
global $app, $conf;
if(!$this->checkPerm($session_id, 'client_delete_everything')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$client_id = $app->functions->intval($client_id);
if($client_id > 0) {
//* remove the group of the client from the resellers group
$parent_client_id = $app->functions->intval($this->dataRecord['parent_client_id']);
$parent_user = $app->db->queryOneRecord("SELECT userid FROM sys_user WHERE client_id = ?", $parent_client_id);
$client_group = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client_id);
$app->auth->remove_group_from_user($parent_user['userid'], $client_group['groupid']);
//* delete the group of the client
$app->db->query("DELETE FROM sys_group WHERE client_id = ?", $client_id);
//* delete the sys user(s) of the client
$app->db->query("DELETE FROM sys_user WHERE client_id = ?", $client_id);
//* Delete all records (sub-clients, mail, web, etc....) of this client.
$tables = 'client,dns_rr,dns_soa,dns_slave,ftp_user,mail_access,mail_content_filter,mail_domain,mail_forwarding,mail_get,mail_user,mail_user_filter,shell_user,spamfilter_users,support_message,web_database,web_database_user,web_domain,web_traffic';
$tables_array = explode(',', $tables);
$client_group_id = $app->functions->intval($client_group['groupid']);
if($client_group_id > 1) {
foreach($tables_array as $table) {
if($table != '') {
$records = $app->db->queryAllRecords("SELECT * FROM $table WHERE sys_groupid = ?", $client_group_id);
//* find the primary ID of the table
$table_info = $app->db->tableInfo($table);
$index_field = '';
foreach($table_info as $tmp) {
if($tmp['option'] == 'primary') $index_field = $tmp['name'];
}
//* Delete the records
if($index_field != '') {
if(is_array($records)) {
foreach($records as $rec) {
$app->db->datalogDelete($table, $index_field, $rec[$index_field]);
//* Delete traffic records that dont have a sys_groupid column
if($table == 'web_domain') {
$app->db->query("DELETE FROM web_traffic WHERE hostname = ?", $rec['domain']);
}
//* Delete mail_traffic records that dont have a sys_groupid
if($table == 'mail_user') {
$app->db->query("DELETE FROM mail_traffic WHERE mailuser_id = ?", $rec['mailuser_id']);
}
}
}
}
}
}
}
}
if (!$this->checkPerm($session_id, 'client_delete')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../client/form/client.tform.php', $client_id);
return $affected_rows;
}
/**
* Get sys_user information by username
* @param int session id
* @param string user's name
* @return mixed false if error
* @author Julio Montoya BeezNest 2010
*/
public function client_get_by_username($session_id, $username) {
global $app;
if(!$this->checkPerm($session_id, 'client_get_by_username')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$rec = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE username = ?", $username);
if (isset($rec)) {
return $rec;
} else {
throw new SoapFault('no_client_found', 'There is no user account for this user name.');
return false;
}
}
public function client_get_by_customer_no($session_id, $customer_no) {
global $app;
if(!$this->checkPerm($session_id, 'client_get_by_customer_no')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$customer_no = trim($customer_no);
if($customer_no == '') {
throw new SoapFault('permission_denied', 'There was no customer number specified.');
return false;
}
$customer_no = $app->db->quote($customer_no);
$rec = $app->db->queryOneRecord("SELECT * FROM client WHERE customer_no = '".$customer_no."'");
if (isset($rec)) {
return $rec;
} else {
throw new SoapFault('no_client_found', 'There is no user account for this customer number.');
return false;
}
}
/**
* Get All client_id's from database
* @param int session_id
* @return Array of all client_id's
*/
public function client_get_all($session_id) {
global $app;
if(!$this->checkPerm($session_id, 'client_get_all')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$result = $app->db->queryAllRecords("SELECT client_id FROM client WHERE 1");
if(!$result) {
return false;
}
foreach( $result as $record) {
$rarrary[] = $record['client_id'];
}
return $rarrary;
}
/**
* Changes client password
*
* @param int session id
* @param int client id
* @param string new password
* @return bool true if success
* @author Julio Montoya BeezNest 2010
*
*/
public function client_change_password($session_id, $client_id, $new_password) {
global $app;
if(!$this->checkPerm($session_id, 'client_change_password')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$client_id = $app->functions->intval($client_id);
$client = $app->db->queryOneRecord("SELECT client_id FROM client WHERE client_id = ?", $client_id);
if($client['client_id'] > 0) {
$sql = "UPDATE client SET password = md5(?) WHERE client_id = ?";
$app->db->query($sql, $new_password, $client_id);
$sql = "UPDATE sys_user SET passwort = md5(?) WHERE client_id = ?";
$app->db->query($sql, $new_password, $client_id);
return true;
} else {
throw new SoapFault('no_client_found', 'There is no user account for this client_id');
return false;
}
}
/**
* Get all client templates
* @param int session id
* @author Julio Montoya BeezNest 2010
*/
public function client_templates_get_all($session_id) {
global $app;
if(!$this->checkPerm($session_id, 'client_templates_get_all')) {
throw new SoapFault('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;
}
public function client_login_get($session_id,$username,$password,$remote_ip = '') {
global $app;
//* Check permissions
if(!$this->checkPerm($session_id, 'client_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//* Check username and password
if(!preg_match("/^[\w\.\-\_\@]{1,128}$/", $username)) {
throw new SoapFault('user_regex_error', 'Username contains invalid characters.');
return false;
}
if(!preg_match("/^.{1,64}$/i", $password)) {
throw new SoapFault('password_length_error', 'Invalid password length or no password provided.');
return false;
}
//* Check failed logins
$sql = "SELECT * FROM `attempts_login` WHERE `ip`= ? AND `login_time` > (NOW() - INTERVAL 1 MINUTE) LIMIT 1";
$alreadyfailed = $app->db->queryOneRecord($sql, $remote_ip);
//* too many failedlogins
if($alreadyfailed['times'] > 5) {
throw new SoapFault('error_user_too_many_logins', 'Too many failed logins.');
return false;
}
//*Set variables
$returnval == false;
if(strstr($username,'@')) {
// Check against client table
$sql = "SELECT * FROM client WHERE email = ?";
$user = $app->db->queryOneRecord($sql, $username);
if($user) {
$saved_password = stripslashes($user['password']);
if(substr($saved_password, 0, 3) == '$1$') {
//* The password is crypt-md5 encrypted
$salt = '$1$'.substr($saved_password, 3, 8).'$';
if(crypt(stripslashes($password), $salt) != $saved_password) {
$user = false;
}
} else {
//* The password is md5 encrypted
if(md5($password) != $saved_password) {
$user = false;
}
}
}
if(is_array($user)) {
$returnval = array( 'username' => $user['username'],
'type' => 'user',
'client_id' => $user['client_id'],
'language' => $user['language'],
'country' => $user['country']);
}
} else {
// Check against sys_user table
$sql = "SELECT * FROM sys_user WHERE username = ?";
$user = $app->db->queryOneRecord($sql, $username);
if($user) {
$saved_password = stripslashes($user['passwort']);
if(substr($saved_password, 0, 3) == '$1$') {
//* The password is crypt-md5 encrypted
$salt = '$1$'.substr($saved_password, 3, 8).'$';
if(crypt(stripslashes($password), $salt) != $saved_password) {
$user = false;
}
} else {
//* The password is md5 encrypted
if(md5($password) != $saved_password) {
$user = false;
}
}
}
if(is_array($user)) {
$returnval = array( 'username' => $user['username'],
'type' => $user['typ'],
'client_id' => $user['client_id'],
'language' => $user['language'],
'country' => 'de');
} else {
throw new SoapFault('login_failed', 'Login failed.');
}
}
//* Log failed login attempts
if($user === false) {
if(!$alreadyfailed['times'] ) {
//* user login the first time wrong
$sql = "INSERT INTO `attempts_login` (`ip`, `times`, `login_time`) VALUES (?, 1, NOW())";
$app->db->query($sql, $remote_ip);
} elseif($alreadyfailed['times'] >= 1) {
//* update times wrong
$sql = "UPDATE `attempts_login` SET `times`=`times`+1, `login_time`=NOW() WHERE `ip` = ? AND `login_time` > (NOW() - INTERVAL 1 MINUTE) ORDER BY `login_time` DESC LIMIT 1";
$app->db->query($sql, $remote_ip);
}
}
return $returnval;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/remote.d/dns.inc.php 0000664 0000000 0000000 00000072773 12600761333 0027063 0 ustar 00root root 0000000 0000000
*/
class remoting_dns extends remoting {
// 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')) {
throw new SoapFault('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 = ?", $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' => $parts[1],
'type' => $parts[0],
'data' => $parts[2],
'aux' => $parts[3],
'ttl' => $parts[4]
);
}
}
}
} // end foreach
if($vars['origin'] == '') $error .= $app->lng('error_origin_empty').' ';
if($vars['ns'] == '') $error .= $app->lng('error_ns_empty').' ';
if($vars['mbox'] == '') $error .= $app->lng('error_mbox_empty').' ';
if($vars['refresh'] == '') $error .= $app->lng('error_refresh_empty').' ';
if($vars['retry'] == '') $error .= $app->lng('error_retry_empty').' ';
if($vars['expire'] == '') $error .= $app->lng('error_expire_empty').' ';
if($vars['minimum'] == '') $error .= $app->lng('error_minimum_empty').' ';
if($vars['ttl'] == '') $error .= $app->lng('error_ttl_empty').' ';
if($error == '') {
// Insert the soa record
$tmp = $app->db->queryOneRecord("SELECT userid,default_group FROM sys_user WHERE client_id = ?", $client_id);
$sys_userid = $tmp['userid'];
$sys_groupid = $tmp['default_group'];
unset($tmp);
$origin = $vars['origin'];
$ns = $vars['ns'];
$mbox = str_replace('@', '.', $vars['mbox']);
$refresh = $vars['refresh'];
$retry = $vars['retry'];
$expire = $vars['expire'];
$minimum = $vars['minimum'];
$ttl = $vars['ttl'];
$xfer = $vars['xfer'];
$also_notify = $vars['also_notify'];
$update_acl = $vars['update_acl'];
$serial = $app->validate_dns->increase_serial(0);
$insert_data = array(
"sys_userid" => $sys_userid,
"sys_groupid" => $sys_groupid,
"sys_perm_user" => 'riud',
"sys_perm_group" => 'riud',
"sys_perm_other" => '',
"server_id" => $server_id,
"origin" => $origin,
"ns" => $ns,
"mbox" => $mbox,
"serial" => $serial,
"refresh" => $refresh,
"retry" => $retry,
"expire" => $expire,
"minimum" => $minimum,
"ttl" => $ttl,
"active" => 'Y',
"xfer" => $xfer,
"also_notify" => $also_notify,
"update_acl" => $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 = array(
"sys_userid" => $sys_userid,
"sys_groupid" => $sys_groupid,
"sys_perm_user" => 'riud',
"sys_perm_group" => 'riud',
"sys_perm_other" => '',
"server_id" => $server_id,
"zone" => $dns_soa_id,
"name" => $rr['name'],
"type" => $rr['type'],
"data" => $rr['data'],
"aux" => $rr['aux'],
"ttl" => $rr['ttl'],
"active" => 'Y'
);
$dns_rr_id = $app->db->datalogInsert('dns_rr', $insert_data, 'id');
}
}
exit;
} else {
throw new SoapFault('permission_denied', $error);
}
}
//* Get record details
public function dns_zone_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'dns_zone_get')) {
throw new SoapFault('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')) {
throw new SoapFault('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)){
throw new SoapFault('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 {
throw new SoapFault('no_domain_found', 'There is no domain ID with informed domain name.');
return false;
}
}
//* Add a record
public function dns_zone_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_zone_add')) {
throw new SoapFault('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);
}
//* Update a record
public function dns_zone_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_zone_update')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function dns_zone_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'dns_zone_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------------
//* Get record details
public function dns_aaaa_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'dns_aaaa_get')) {
throw new SoapFault('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);
}
//* Add a record
public function dns_aaaa_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_aaaa_add')) {
throw new SoapFault('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);
}
//* Update a record
public function dns_aaaa_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_aaaa_update')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function dns_aaaa_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'dns_aaaa_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------------
//* Get record details
public function dns_a_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'dns_a_get')) {
throw new SoapFault('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);
}
//* Add a record
public function dns_a_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_a_add')) {
throw new SoapFault('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);
}
//* Update a record
public function dns_a_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_a_update')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function dns_a_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'dns_a_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------------
//* Get record details
public function dns_alias_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'dns_alias_get')) {
throw new SoapFault('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);
}
//* Add a record
public function dns_alias_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_alias_add')) {
throw new SoapFault('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);
}
//* Update a record
public function dns_alias_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_alias_update')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function dns_alias_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'dns_alias_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------------
//* Get record details
public function dns_cname_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'dns_cname_get')) {
throw new SoapFault('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);
}
//* Add a record
public function dns_cname_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_cname_add')) {
throw new SoapFault('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);
}
//* Update a record
public function dns_cname_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_cname_update')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function dns_cname_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'dns_cname_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------------
//* Get record details
public function dns_hinfo_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'dns_hinfo_get')) {
throw new SoapFault('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);
}
//* Add a record
public function dns_hinfo_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_hinfo_add')) {
throw new SoapFault('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);
}
//* Update a record
public function dns_hinfo_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_hinfo_update')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function dns_hinfo_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'dns_hinfo_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------------
//* Get record details
public function dns_mx_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'dns_mx_get')) {
throw new SoapFault('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);
}
//* Add a record
public function dns_mx_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_mx_add')) {
throw new SoapFault('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);
}
//* Update a record
public function dns_mx_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_mx_update')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function dns_mx_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'dns_mx_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------------
//* Get record details
public function dns_ns_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'dns_ns_get')) {
throw new SoapFault('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);
}
//* Add a record
public function dns_ns_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_ns_add')) {
throw new SoapFault('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);
}
//* Update a record
public function dns_ns_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_ns_update')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function dns_ns_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'dns_ns_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------------
//* Get record details
public function dns_ptr_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'dns_ptr_get')) {
throw new SoapFault('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);
}
//* Add a record
public function dns_ptr_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_ptr_add')) {
throw new SoapFault('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);
}
//* Update a record
public function dns_ptr_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_ptr_update')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function dns_ptr_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'dns_ptr_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------------
//* Get record details
public function dns_rp_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'dns_rp_get')) {
throw new SoapFault('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);
}
//* Add a record
public function dns_rp_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_rp_add')) {
throw new SoapFault('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);
}
//* Update a record
public function dns_rp_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'dns_rp_update')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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;
}
/**
* Get all DNS zone by user
*@author Julio Montoya 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')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if (!empty($client_id) && !empty($server_id)) {
$server_id = $app->functions->intval($server_id);
$client_id = $app->functions->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 = ? AND server_id = ?";
$result = $app->db->queryAllRecords($sql, $client_id, $server_id);
return $result;
}
return false;
}
/**
* Get all dns records for a zone
* @param int session id
* @param int dns zone id
* @author Sebastian Mogilowski 2011
*/
public function dns_rr_get_all_by_zone($session_id, $zone_id) {
global $app;
if(!$this->checkPerm($session_id, 'dns_zone_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$sql = "SELECT * FROM dns_rr WHERE zone = ?";
$result = $app->db->queryAllRecords($sql, $zone_id);
return $result;
}
/**
* Changes DNS zone status
* @param int session id
* @param int dns soa id
* @param string status active or inactive string
* @author Julio Montoya BeezNest 2010
*/
public function dns_zone_set_status($session_id, $primary_id, $status) {
global $app;
if(!$this->checkPerm($session_id, 'dns_zone_set_status')) {
throw new SoapFault('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 = ? WHERE id = ?";
$app->db->query($sql, $status, $primary_id);
$result = $app->db->affectedRows();
return $result;
} else {
throw new SoapFault('status_undefined', 'The status is not available');
return false;
}
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/remote.d/domains.inc.php 0000664 0000000 0000000 00000007205 12600761333 0027715 0 ustar 00root root 0000000 0000000
*/
class remoting_domains extends remoting {
// -----------------------------------------------------------------------------------------------
//* Get record details
public function domains_domain_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'domains_domain_get')) {
throw new SoapFault('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');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add a record
public function domains_domain_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'domains_domain_add')) {
throw new SoapFault('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);
}
//* Delete a record
public function domains_domain_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'domains_domain_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
// -----------------------------------------------------------------------------------------------
public function domains_get_all_by_user($session_id, $group_id)
{
global $app;
if(!$this->checkPerm($session_id, 'domains_get_all_by_user')) {
throw new SoapFault('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 = ?";
$all = $app->db->queryAllRecords($sql, $group_id);
return $all;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/remote.d/mail.inc.php 0000664 0000000 0000000 00000114000 12600761333 0027175 0 ustar 00root root 0000000 0000000
*/
class remoting_mail extends remoting {
//* Get mail domain details
public function mail_domain_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_domain_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_domain.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add a mail domain
public function mail_domain_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'mail_domain_add')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$primary_id = $this->insertQuery('../mail/form/mail_domain.tform.php', $client_id, $params);
return $primary_id;
}
//* Update a mail domain
public function mail_domain_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'mail_domain_update')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_domain.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
//* Delete a mail domain
public function mail_domain_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'mail_domain_delete')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_domain.tform.php', $primary_id);
return $affected_rows;
}
//* Get alias details
public function mail_aliasdomain_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_aliasdomain_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_aliasdomain.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* aliasy email
public function mail_aliasdomain_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_aliasdomain_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/mail_aliasdomain.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_aliasdomain_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_aliasdomain_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_aliasdomain.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_aliasdomain_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_aliasdomain_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_aliasdomain.tform.php', $primary_id);
return $affected_rows;
}
//* Get mail mailinglist details
public function mail_mailinglist_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_mailinglist_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_mailinglist.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add a mail mailinglist
public function mail_mailinglist_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'mail_mailinglist_add')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$primary_id = $this->insertQuery('../mail/form/mail_mailinglist.tform.php', $client_id, $params);
return $primary_id;
}
//* Update a mail mailinglist
public function mail_mailinglist_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'mail_mailinglist_update')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_mailinglist.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
//* Delete a mail mailinglist
public function mail_mailinglist_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'mail_mailinglist_delete')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_mailinglist.tform.php', $primary_id);
return $affected_rows;
}
//* Get mail user details
public function mail_user_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_user_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_user.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add mail domain
public function mail_user_add($session_id, $client_id, $params){
global $app;
if (!$this->checkPerm($session_id, 'mail_user_add')){
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//* Check if mail domain exists
$email_parts = explode('@', $params['email']);
$tmp = $app->db->queryOneRecord("SELECT domain FROM mail_domain WHERE domain = ?", $email_parts[1]);
if($tmp['domain'] != $email_parts[1]) {
throw new SoapFault('mail_domain_does_not_exist', 'Mail domain - '.$email_parts[1].' - does not exist.');
return false;
}
//* Set a few params to non empty values that will be overwritten by mail_plugin
if (!isset($params['uid'])) $params['uid'] = -1;
if (!isset($params['gid'])) $params['gid'] = -1;
$affected_rows = $this->insertQuery('../mail/form/mail_user.tform.php', $client_id, $params);
return $affected_rows;
}
//* Update mail user
public function mail_user_update($session_id, $client_id, $primary_id, $params)
{
global $app;
if (!$this->checkPerm($session_id, 'mail_user_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//* Check if mail domain exists
$email_parts = explode('@', $params['email']);
$tmp = $app->db->queryOneRecord("SELECT domain FROM mail_domain WHERE domain = ?", $email_parts[1]);
if($tmp['domain'] != $email_parts[1]) {
throw new SoapFault('mail_domain_does_not_exist', 'Mail domain - '.$email_parts[1].' - does not exist.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_user.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
//* Delete mail user
public function mail_user_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_user_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_user.tform.php', $primary_id);
return $affected_rows;
}
//* Get mail user filter details
public function mail_user_filter_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_user_filter_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_user_filter.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
public function mail_user_filter_add($session_id, $client_id, $params)
{
global $app;
if (!$this->checkPerm($session_id, 'mail_user_filter_add')){
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/mail_user_filter.tform.php', $client_id, $params, 'mail:mail_user_filter:on_after_insert');
// $app->plugin->raiseEvent('mail:mail_user_filter:on_after_insert',$this);
return $affected_rows;
}
public function mail_user_filter_update($session_id, $client_id, $primary_id, $params)
{
global $app;
if (!$this->checkPerm($session_id, 'mail_user_filter_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_user_filter.tform.php', $client_id, $primary_id, $params, 'mail:mail_user_filter:on_after_update');
// $app->plugin->raiseEvent('mail:mail_user_filter:on_after_update',$this);
return $affected_rows;
}
public function mail_user_filter_delete($session_id, $primary_id)
{
global $app;
if (!$this->checkPerm($session_id, 'mail_user_filter_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_user_filter.tform.php', $primary_id, 'mail:mail_user_filter:on_after_delete');
// $app->plugin->raiseEvent('mail:mail_user_filter:on_after_delete',$this);
return $affected_rows;
}
// Mail backup list function by Dominik Mller, info@profi-webdesign.net
public function mail_user_backup_list($session_id, $primary_id = null)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_user_backup')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$params = array();
if ($site_id != null) {
$params[] = $site_id;
$sql = "SELECT * FROM mail_backup WHERE parent_domain_id = ?";
}
else {
$sql = "SELECT * FROM mail_backup";
}
$result = $app->db->queryAllRecords($sql, true, $params);
return $result;
}
// Mail backup restore/download functions by Dominik Mller, info@profi-webdesign.net
public function mail_user_backup($session_id, $primary_id, $action_type)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_user_backup')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//*Set variables
$backup_record = $app->db->queryOneRecord("SELECT * FROM `mail_backup` WHERE `backup_id`=?", $primary_id);
$server_id = $backup_record['server_id'];
//*Set default action state
$action_state = "pending";
$tstamp = time();
//* Basic validation of variables
if ($server_id <= 0) {
$this->server->fault('invalid_backup_id', "Invalid or non existant backup_id $primary_id");
return false;
}
if (/*$action_type != 'backup_download_mail' and*/ $action_type != 'backup_restore_mail') {
$this->server->fault('invalid_action', "Invalid action_type $action_type");
return false;
}
//* Validate instance
$instance_record = $app->db->queryOneRecord("SELECT * FROM `sys_remoteaction` WHERE `action_param`=? and `action_type`=? and `action_state`='pending'", $primary_id, $action_type);
if ($instance_record['action_id'] >= 1) {
$this->server->fault('duplicate_action', "There is already a pending $action_type action");
return false;
}
//* Save the record
if ($app->db->query("INSERT INTO `sys_remoteaction` SET `server_id` = ?, `tstamp` = ?, `action_type` = ?, `action_param` = ?, `action_state` = ?", $server_id, $tstamp, $action_type, $primary_id, $action_state)) {
return true;
} else {
return false;
}
}
//* Get alias details
public function mail_alias_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_alias_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_alias.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* aliasy email
public function mail_alias_add($session_id, $client_id, $params)
{
global $app;
if (!$this->checkPerm($session_id, 'mail_alias_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//* Check if there is no active mailbox with this address
$tmp = $app->db->queryOneRecord("SELECT count(mailuser_id) as number FROM mail_user WHERE postfix = 'y' AND email = ?", $params["source"]);
if($tmp['number'] > 0) {
throw new SoapFault('duplicate', 'There is already a mailbox with this email address.');
}
unset($tmp);
$affected_rows = $this->insertQuery('../mail/form/mail_alias.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_alias_update($session_id, $client_id, $primary_id, $params)
{
global $app;
if (!$this->checkPerm($session_id, 'mail_alias_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//* Check if there is no active mailbox with this address
$tmp = $app->db->queryOneRecord("SELECT count(mailuser_id) as number FROM mail_user WHERE postfix = 'y' AND email = ?", $params["source"]);
if($tmp['number'] > 0) {
throw new SoapFault('duplicate', 'There is already a mailbox with this email address.');
}
unset($tmp);
$affected_rows = $this->updateQuery('../mail/form/mail_alias.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_alias_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_alias_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_alias.tform.php', $primary_id);
return $affected_rows;
}
//* Get mail forwarding details
public function mail_forward_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_forward_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_forward.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* przekierowania email
public function mail_forward_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_forward_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/mail_forward.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_forward_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_forward_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_forward.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_forward_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_forward_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_forward.tform.php', $primary_id);
return $affected_rows;
}
//* Get catchall details
public function mail_catchall_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_catchall_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_domain_catchall.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* catchall e-mail
public function mail_catchall_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_catchall_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/mail_domain_catchall.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_catchall_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_catchall_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_domain_catchall.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_catchall_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_catchall_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_domain_catchall.tform.php', $primary_id);
return $affected_rows;
}
//* Get transport details
public function mail_transport_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_transport_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_transport.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* przeniesienia e-mail
public function mail_transport_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_transport_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/mail_transport.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_transport_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_transport_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_transport.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_transport_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_transport_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_transport.tform.php', $primary_id);
return $affected_rows;
}
//* Get mail relay_recipient details
public function mail_relay_recipient_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_relay_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('../mail/form/mail_relay_recipient.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* relay recipient email
public function mail_relay_recipient_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_relay_add'))
{
$this->server->fault('permission_denied','You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/mail_relay_recipient.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_relay_recipient_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_relay_update'))
{
$this->server->fault('permission_denied','You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_relay_recipient.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_relay_recipient_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_relay_delete'))
{
$this->server->fault('permission_denied','You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_relay_recipient.tform.php', $primary_id);
return $affected_rows;
}
//* Get spamfilter whitelist details
public function mail_spamfilter_whitelist_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/spamfilter_whitelist.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* biała lista e-mail
public function mail_spamfilter_whitelist_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/spamfilter_whitelist.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_spamfilter_whitelist_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/spamfilter_whitelist.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_spamfilter_whitelist_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_spamfilter_whitelist_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/spamfilter_whitelist.tform.php', $primary_id);
return $affected_rows;
}
//* Get spamfilter blacklist details
public function mail_spamfilter_blacklist_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/spamfilter_blacklist.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* czarna lista e-mail
public function mail_spamfilter_blacklist_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/spamfilter_blacklist.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_spamfilter_blacklist_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/spamfilter_blacklist.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_spamfilter_blacklist_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_spamfilter_blacklist_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/spamfilter_blacklist.tform.php', $primary_id);
return $affected_rows;
}
//* Get spamfilter user details
public function mail_spamfilter_user_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_spamfilter_user_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/spamfilter_users.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* filtr spamu użytkowników e-mail
public function mail_spamfilter_user_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_spamfilter_user_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/spamfilter_users.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_spamfilter_user_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_spamfilter_user_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/spamfilter_users.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_spamfilter_user_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_spamfilter_user_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/spamfilter_users.tform.php', $primary_id);
return $affected_rows;
}
//* Get policy details
public function mail_policy_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_policy_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/spamfilter_policy.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* polityki filtrów spamu e-mail
public function mail_policy_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_policy_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/spamfilter_policy.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_policy_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_policy_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/spamfilter_policy.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_policy_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_policy_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/spamfilter_policy.tform.php', $primary_id);
return $affected_rows;
}
//* Get fetchmail details
public function mail_fetchmail_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_fetchmail_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_get.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* fetchmail
public function mail_fetchmail_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_fetchmail_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/mail_get.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_fetchmail_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_fetchmail_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_get.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_fetchmail_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_fetchmail_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_get.tform.php', $primary_id);
return $affected_rows;
}
//* Get whitelist details
public function mail_whitelist_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_whitelist_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_whitelist.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* wpisy białej listy
public function mail_whitelist_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_whitelist_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/mail_whitelist.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_whitelist_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_whitelist_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_whitelist.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_whitelist_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_whitelist_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_whitelist.tform.php', $primary_id);
return $affected_rows;
}
//* Get Blacklist details
public function mail_blacklist_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_blacklist_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_blacklist.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* wpisy białej listy
public function mail_blacklist_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_blacklist_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/mail_blacklist.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_blacklist_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_blacklist_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_blacklist.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_blacklist_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_blacklist_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_blacklist.tform.php', $primary_id);
return $affected_rows;
}
//* Get filter details
public function mail_filter_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'mail_filter_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../mail/form/mail_content_filter.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* wpisy filtrow e-mail
public function mail_filter_add($session_id, $client_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_filter_add'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->insertQuery('../mail/form/mail_content_filter.tform.php', $client_id, $params);
return $affected_rows;
}
public function mail_filter_update($session_id, $client_id, $primary_id, $params)
{
if (!$this->checkPerm($session_id, 'mail_filter_update'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../mail/form/mail_content_filter.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
public function mail_filter_delete($session_id, $primary_id)
{
if (!$this->checkPerm($session_id, 'mail_filter_delete'))
{
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../mail/form/mail_content_filter.tform.php', $primary_id);
return $affected_rows;
}
/**
* 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')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if (!empty($domain)) {
$sql = "SELECT * FROM mail_domain WHERE domain = ?";
$result = $app->db->queryAllRecords($sql, $domain);
return $result;
}
return false;
}
public function mail_domain_set_status($session_id, $primary_id, $status) {
global $app;
if(!$this->checkPerm($session_id, 'mail_domain_set_status')) {
throw new SoapFault('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 = ? WHERE domain_id = ?";
$app->db->query($sql, $status, $primary_id);
$result = $app->db->affectedRows();
return $result;
} else {
throw new SoapFault('status_undefined', 'The status is not available');
return false;
}
}
//** quota functions -----------------------------------------------------------------------------------
public function mailquota_get_by_user($session_id, $client_id)
{
global $app;
$app->uses('quota_lib');
if(!$this->checkPerm($session_id, 'mailquota_get_by_user')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $app->quota_lib->get_mailquota_data($client_id, false);
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/remote.d/openvz.inc.php 0000664 0000000 0000000 00000042072 12600761333 0027605 0 ustar 00root root 0000000 0000000
*/
class remoting_openvz extends remoting {
//* 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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$server_id = $app->functions->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 = ? LIMIT 0,1", $server_id);
} 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 {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if (!empty($client_id)) {
$client_id = $app->functions->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 = ?";
$result = $app->db->queryAllRecords($sql, $tmp['groupid']);
return $result;
}
return false;
}
//* Add a openvz vm record
public function openvz_vm_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'vm_openvz')) {
throw new SoapFault('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')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$template_id = $app->functions->intval($template_id);
$ostemplate_id = $app->functions->intval($ostemplate_id);
//* Verify parameters
if($template_id == 0) {
throw new SoapFault('template_id_error', 'Template ID must be > 0.');
return false;
}
if($ostemplate_id == 0) {
throw new SoapFault('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)) {
throw new SoapFault('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)) {
throw new SoapFault('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 = ? LIMIT 0,1", $override_params['server_id']);
} 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)) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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;
}
//* Start VM
public function openvz_vm_start($session_id, $vm_id)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
throw new SoapFault('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)) {
throw new SoapFault('action_pending', 'No VM with this ID available.');
return false;
}
if($vm['active'] == 'n') {
throw new SoapFault('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 = ?
AND action_type = ?
AND action_param = ?
AND action_state = 'pending'", $vm['server_id'], $action, $vm['veid']);
if($tmp['actions'] > 0) {
throw new SoapFault('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 (?, ?, ?, ?, 'pending', '')";
$app->db->query($sql, (int)$vm['server_id'], time(), $action, $vm['veid']);
}
}
//* Stop VM
public function openvz_vm_stop($session_id, $vm_id)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
throw new SoapFault('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)) {
throw new SoapFault('action_pending', 'No VM with this ID available.');
return false;
}
if($vm['active'] == 'n') {
throw new SoapFault('action_pending', 'VM is not in active state.');
return false;
}
$action = 'openvz_stop_vm';
$tmp = $app->db->queryOneRecord("SELECT count(action_id) as actions FROM sys_remoteaction
WHERE server_id = ?
AND action_type = ?
AND action_param = ?
AND action_state = 'pending'", $vm['server_id'], $action, $vm['veid']);
if($tmp['actions'] > 0) {
throw new SoapFault('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 (?, ?, ?, ?, 'pending', '')";
$app->db->query($sql, (int)$vm['server_id'], time(), $action, $vm['veid']);
}
}
//* Restart VM
public function openvz_vm_restart($session_id, $vm_id)
{
global $app;
if(!$this->checkPerm($session_id, 'vm_openvz')) {
throw new SoapFault('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)) {
throw new SoapFault('action_pending', 'No VM with this ID available.');
return false;
}
if($vm['active'] == 'n') {
throw new SoapFault('action_pending', 'VM is not in active state.');
return false;
}
$action = 'openvz_restart_vm';
$tmp = $app->db->queryOneRecord("SELECT count(action_id) as actions FROM sys_remoteaction
WHERE server_id = ?
AND action_type = ?
AND action_param = ?
AND action_state = 'pending'", $vm['server_id'], $action, $vm['veid']);
if($tmp['actions'] > 0) {
throw new SoapFault('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 (?, ?, ?, ?, 'pending', '')";
$app->db->query($sql, (int)$vm['server_id'], time(), $action, $vm['veid']);
}
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/remote.d/server.inc.php 0000664 0000000 0000000 00000016301 12600761333 0027566 0 ustar 00root root 0000000 0000000
*/
class remoting_server extends remoting {
/**
Gets the server configuration
@param int session id
@param int server id
@param string section of the config field in the server table. Could be 'web', 'dns', 'mail', 'dns', 'cron', etc
@author Julio Montoya BeezNest 2010
*/
public function server_get_serverid_by_ip($session_id, $ipaddress)
{
global $app;
if(!$this->checkPerm($session_id, 'server_get_serverid_by_ip')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$sql = "SELECT server_id FROM server_ip WHERE ip_address = ? LIMIT 1";
$all = $app->db->queryAllRecords($sql, $ipaddress);
return $all;
}
//* Get server ips
public function server_ip_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'server_ip_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('../admin/form/server_ip.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add a IP address record
public function server_ip_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'server_ip_add')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $this->insertQuery('../admin/form/server_ip.tform.php', $client_id, $params);
}
//* Update IP address record
public function server_ip_update($session_id, $client_id, $ip_id, $params)
{
if(!$this->checkPerm($session_id, 'server_ip_update')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../admin/form/server_ip.tform.php', $client_id, $ip_id, $params);
return $affected_rows;
}
//* Delete IP address record
public function server_ip_delete($session_id, $ip_id)
{
if(!$this->checkPerm($session_id, 'server_ip_delete')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../admin/form/server_ip.tform.php', $ip_id);
return $affected_rows;
}
/**
Gets the server configuration
@param int session id
@param int server id
@param string section of the config field in the server table. Could be 'web', 'dns', 'mail', 'dns', 'cron', etc
@author Julio Montoya BeezNest 2010
*/
public function server_get($session_id, $server_id = null, $section ='') {
global $app;
if(!$this->checkPerm($session_id, 'server_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if (!empty($session_id)) {
$app->uses('remoting_lib , getconf');
if(!empty($server_id)) {
$section_config = $app->getconf->get_server_config($server_id, $section);
return $section_config;
} else {
$servers = array();
$sql = "SELECT server_id FROM server WHERE 1";
$all = $app->db->queryAllRecords($sql);
foreach($all as $s) {
$servers[$s['server_id']] = $app->getconf->get_server_config($s['server_id'], $section);
}
unset($all);
unset($s);
return $servers;
}
} else {
return false;
}
}
/**
Gets a list of all servers
@param int session_id
@param int server_name
@author Marius Cramer 2014
*/
public function server_get_all($session_id)
{
global $app;
if(!$this->checkPerm($session_id, 'server_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if (!empty($session_id)) {
$sql = "SELECT server_id, server_name FROM server WHERE 1";
$servers = $app->db->queryAllRecords($sql);
return $servers;
} else {
return false;
}
}
/**
Gets the server_id by server_name
@param int session_id
@param int server_name
@author Sascha Bay TheCry 2013
*/
public function server_get_serverid_by_name($session_id, $server_name)
{
global $app;
if(!$this->checkPerm($session_id, 'server_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if (!empty($session_id) && !empty($server_name)) {
$sql = "SELECT server_id FROM server WHERE server_name = ? LIMIT 1";
$all = $app->db->queryAllRecords($sql, $server_name);
return $all;
} else {
return false;
}
}
/**
Gets the functions of a server by server_id
@param int session_id
@param int server_id
@author Sascha Bay TheCry 2013
*/
public function server_get_functions($session_id, $server_id)
{
global $app;
if(!$this->checkPerm($session_id, 'server_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if (!empty($session_id) && !empty($server_id)) {
$sql = "SELECT mail_server, web_server, dns_server, file_server, db_server, vserver_server, proxy_server, firewall_server FROM server WHERE server_id = ? LIMIT 1 ";
$all = $app->db->queryAllRecords($sql, $server_id);
return $all;
} else {
return false;
}
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/remote.d/sites.inc.php 0000664 0000000 0000000 00000113536 12600761333 0027417 0 ustar 00root root 0000000 0000000
*/
class remoting_sites extends remoting {
// Website functions ---------------------------------------------------------------------------------------
//* Get cron details
public function sites_cron_get($session_id, $cron_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_cron_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../sites/form/cron.tform.php');
return $app->remoting_lib->getDataRecord($cron_id);
}
//* Add a cron record
public function sites_cron_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_cron_add')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $this->insertQuery('../sites/form/cron.tform.php', $client_id, $params);
}
//* Update cron record
public function sites_cron_update($session_id, $client_id, $cron_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_cron_update')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../sites/form/cron.tform.php', $client_id, $cron_id, $params);
return $affected_rows;
}
//* Delete cron record
public function sites_cron_delete($session_id, $cron_id)
{
if(!$this->checkPerm($session_id, 'sites_cron_delete')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../sites/form/cron.tform.php', $cron_id);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------
//* Get record details
public function sites_database_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_database_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../sites/form/database.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
/* TODO: secure queries! */
//* Add a record
public function sites_database_add($session_id, $client_id, $params)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_database_add')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//* Check for duplicates
$tmp = $app->db->queryOneRecord("SELECT count(database_id) as dbnum FROM web_database WHERE database_name = ? AND server_id = ?", $params['database_name'], $params["server_id"]);
if($tmp['dbnum'] > 0) {
throw new SoapFault('database_name_error_unique', 'There is already a database with that name on the same server.');
return false;
}
$sql = $this->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params);
if($sql !== false) {
$app->uses('sites_database_plugin');
$this->id = 0;
$this->dataRecord = $params;
$app->sites_database_plugin->processDatabaseInsert($this);
$retval = $this->insertQueryExecute($sql, $params);
// set correct values for backup_interval and backup_copies
if(isset($params['backup_interval']) || isset($params['backup_copies'])){
$sql_set = array();
if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
$this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$retval, $retval, $params);
}
return $retval;
}
return false;
}
//* Update a record
public function sites_database_update($session_id, $client_id, $primary_id, $params)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_database_update')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$sql = $this->updateQueryPrepare('../sites/form/database.tform.php', $client_id, $primary_id, $params);
if($sql !== false) {
$app->uses('sites_database_plugin');
$this->id = $primary_id;
$this->dataRecord = $params;
$app->sites_database_plugin->processDatabaseUpdate($this);
$retval = $this->updateQueryExecute($sql, $primary_id, $params);
// set correct values for backup_interval and backup_copies
if(isset($params['backup_interval']) || isset($params['backup_copies'])){
$sql_set = array();
if(isset($params['backup_interval'])) $sql_set[] = "backup_interval = '".$app->db->quote($params['backup_interval'])."'";
if(isset($params['backup_copies'])) $sql_set[] = "backup_copies = ".$app->functions->intval($params['backup_copies']);
$this->updateQueryExecute("UPDATE web_database SET ".implode(', ', $sql_set)." WHERE database_id = ".$primary_id, $primary_id, $params);
}
return $retval;
}
return false;
}
//* Delete a record
public function sites_database_delete($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_database_delete')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('sites_database_plugin');
$app->sites_database_plugin->processDatabaseDelete($primary_id);
$affected_rows = $this->deleteQuery('../sites/form/database.tform.php', $primary_id);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------
//* Get record details
public function sites_database_user_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_database_user_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../sites/form/database_user.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add a record
public function sites_database_user_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_database_user_add')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $this->insertQuery('../sites/form/database_user.tform.php', $client_id, $params);
}
//* Update a record
public function sites_database_user_update($session_id, $client_id, $primary_id, $params)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_database_user_update')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../sites/form/database_user.tform.php');
$old_rec = $app->remoting_lib->getDataRecord($primary_id);
$result = $this->updateQuery('../sites/form/database_user.tform.php', $client_id, $primary_id, $params);
$new_rec = $app->remoting_lib->getDataRecord($primary_id);
$records = $app->db->queryAllRecords("SELECT DISTINCT server_id FROM web_database WHERE database_user_id = ? UNION SELECT DISTINCT server_id FROM web_database WHERE database_ro_user_id = ?", $primary_id, $primary_id);
foreach($records as $rec) {
$tmp_rec = $new_rec;
$tmp_rec['server_id'] = $rec['server_id'];
$app->remoting_lib->datalogSave('UPDATE', $primary_id, $old_rec, $tmp_rec);
}
unset($new_rec);
unset($old_rec);
unset($records);
return $result;
}
//* Delete a record
public function sites_database_user_delete($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_database_user_delete')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->db->datalogDelete('web_database_user', 'database_user_id', $primary_id);
$affected_rows = $this->deleteQuery('../sites/form/database_user.tform.php', $primary_id);
$records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE database_user_id = ?", $primary_id);
foreach($records as $rec) {
$app->db->datalogUpdate('web_database', array('database_user_id' => null), 'database_id', $rec['database_id']);
}
$records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE database_ro_user_id = ?", $primary_id);
foreach($records as $rec) {
$app->db->datalogUpdate('web_database', array('database_ro_user_id' => null), 'database_id', $rec['database_id']);
}
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------
//* Get record details
public function sites_ftp_user_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_ftp_user_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../sites/form/ftp_user.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add a record
public function sites_ftp_user_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_ftp_user_add')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $this->insertQuery('../sites/form/ftp_user.tform.php', $client_id, $params);
}
//* Update a record
public function sites_ftp_user_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_ftp_user_update')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../sites/form/ftp_user.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
//* Delete a record
public function sites_ftp_user_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'sites_ftp_user_delete')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../sites/form/ftp_user.tform.php', $primary_id);
return $affected_rows;
}
//* Get server for an ftp user
public function sites_ftp_user_server_get($session_id, $ftp_user)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_ftp_user_server_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$data = $app->db->queryOneRecord("SELECT server_id FROM ftp_user WHERE username = ?", $ftp_user);
//file_put_contents('/tmp/test.txt', serialize($data));
if(!isset($data['server_id'])) return false;
$server = $this->server_get($session_id, $data['server_id'], 'server');
//file_put_contents('/tmp/test2.txt', serialize($server));
return $server;
}
// ----------------------------------------------------------------------------------------------------------
//* Get record details
public function sites_shell_user_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_shell_user_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../sites/form/shell_user.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add a record
public function sites_shell_user_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_shell_user_add')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $this->insertQuery('../sites/form/shell_user.tform.php', $client_id, $params);
}
//* Update a record
public function sites_shell_user_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_shell_user_update')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->updateQuery('../sites/form/shell_user.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
//* Delete a record
public function sites_shell_user_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'sites_shell_user_delete')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../sites/form/shell_user.tform.php', $primary_id);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------
//* Get record details
public function sites_web_domain_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_domain_get')) {
throw new SoapFault('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_vhost_domain.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add a record
public function sites_web_domain_add($session_id, $client_id, $params, $readonly = false)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_domain_add')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if(!isset($params['client_group_id']) or (isset($params['client_group_id']) && empty($params['client_group_id']))) {
$rec = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client_id);
$params['client_group_id'] = $rec['groupid'];
}
//* Set a few params to "not empty" values which get overwritten by the sites_web_domain_plugin
if($params['document_root'] == '') $params['document_root'] = '-';
if($params['system_user'] == '') $params['system_user'] = '-';
if($params['system_group'] == '') $params['system_group'] = '-';
//* Set a few defaults for nginx servers
if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
$domain_id = $this->insertQuery('../sites/form/web_vhost_domain.tform.php', $client_id, $params, 'sites:web_domain:on_after_insert');
if ($readonly === true)
$app->db->query("UPDATE web_domain SET `sys_userid` = '1' WHERE domain_id = ?", $domain_id);
return $domain_id;
}
//* Update a record
public function sites_web_domain_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_web_domain_update')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//* Set a few defaults for nginx servers
if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
$affected_rows = $this->updateQuery('../sites/form/web_vhost_domain.tform.php', $client_id, $primary_id, $params);
return $affected_rows;
}
//* Delete a record
public function sites_web_domain_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'sites_web_domain_delete')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../sites/form/web_vhost_domain.tform.php', $primary_id);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------
//* Get record details
public function sites_web_vhost_aliasdomain_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_get')) {
throw new SoapFault('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_vhost_aliasdomain.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add a record
public function sites_web_vhost_aliasdomain_add($session_id, $client_id, $params)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_add')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//* Set a few params to "not empty" values which get overwritten by the sites_web_domain_plugin
if($params['document_root'] == '') $params['document_root'] = '-';
if($params['system_user'] == '') $params['system_user'] = '-';
if($params['system_group'] == '') $params['system_group'] = '-';
//* Set a few defaults for nginx servers
if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
$domain_id = $this->insertQuery('../sites/form/web_vhost_aliasdomain.tform.php', $client_id, $params, 'sites:web_vhost_aliasdomain:on_after_insert');
return $domain_id;
}
//* Update a record
public function sites_web_vhost_aliasdomain_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_update')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//* Set a few defaults for nginx servers
if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
$affected_rows = $this->updateQuery('../sites/form/web_vhost_aliasdomain.tform.php', $client_id, $primary_id, $params, 'sites:web_vhost_aliasdomain:on_after_insert');
return $affected_rows;
}
//* Delete a record
public function sites_web_vhost_aliasdomain_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_delete')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../sites/form/web_vhost_aliasdomain.tform.php', $primary_id);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------
//* Get record details
public function sites_web_vhost_subdomain_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_subdomain_get')) {
throw new SoapFault('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_vhost_subdomain.tform.php');
return $app->remoting_lib->getDataRecord($primary_id);
}
//* Add a record
public function sites_web_vhost_subdomain_add($session_id, $client_id, $params)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_subdomain_add')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//* Set a few params to "not empty" values which get overwritten by the sites_web_domain_plugin
if($params['document_root'] == '') $params['document_root'] = '-';
if($params['system_user'] == '') $params['system_user'] = '-';
if($params['system_group'] == '') $params['system_group'] = '-';
//* Set a few defaults for nginx servers
if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
$domain_id = $this->insertQuery('../sites/form/web_vhost_subdomain.tform.php', $client_id, $params, 'sites:web_vhost_subdomain:on_after_insert');
return $domain_id;
}
//* Update a record
public function sites_web_vhost_subdomain_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_web_subdomain_update')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//* Set a few defaults for nginx servers
if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
$affected_rows = $this->updateQuery('../sites/form/web_vhost_subdomain.tform.php', $client_id, $primary_id, $params, 'sites:web_vhost_subdomain:on_after_insert');
return $affected_rows;
}
//* Delete a record
public function sites_web_vhost_subdomain_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'sites_web_subdomain_delete')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$affected_rows = $this->deleteQuery('../sites/form/web_vhost_subdomain.tform.php', $primary_id);
return $affected_rows;
}
// -----------------------------------------------------------------------------------------------
//* Get record details
public function sites_web_aliasdomain_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_get')) {
throw new SoapFault('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);
}
//* Add a record
public function sites_web_aliasdomain_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_add')) {
throw new SoapFault('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);
}
//* Update a record
public function sites_web_aliasdomain_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_update')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function sites_web_aliasdomain_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'sites_web_aliasdomain_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------
//* Get record details
public function sites_web_subdomain_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_subdomain_get')) {
throw new SoapFault('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);
}
//* Add a record
public function sites_web_subdomain_add($session_id, $client_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_web_subdomain_add')) {
throw new SoapFault('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);
}
//* Update a record
public function sites_web_subdomain_update($session_id, $client_id, $primary_id, $params)
{
if(!$this->checkPerm($session_id, 'sites_web_subdomain_update')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function sites_web_subdomain_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'sites_web_subdomain_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
// ----------------------------------------------------------------------------------------------------------
//* Get record details
public function sites_web_folder_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_folder_get')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function sites_web_folder_delete($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_folder_delete')) {
throw new SoapFault('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 = ?", $primary_id);
foreach($records as $rec) {
$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);
return $affected_rows;
}
// -----------------------------------------------------------------------------------------------
//* Get record details
public function sites_web_folder_user_get($session_id, $primary_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_folder_user_get')) {
throw new SoapFault('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')) {
throw new SoapFault('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')) {
throw new SoapFault('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);
return $affected_rows;
}
//* Delete a record
public function sites_web_folder_user_delete($session_id, $primary_id)
{
if(!$this->checkPerm($session_id, 'sites_web_folder_user_delete')) {
throw new SoapFault('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);
return $affected_rows;
}
/**
* 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 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')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$sys_userid = $app->functions->intval($sys_userid);
$sys_groupid = explode(',', $sys_groupid);
$new_group = array();
foreach($sys_groupid as $group_id) {
$new_group[] = $app->functions->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 {
throw new SoapFault('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 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')) {
throw new SoapFault('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';
}
$app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php');
$params = $app->remoting_lib->getDataRecord($primary_id);
$params['active'] = $status;
$affected_rows = $this->updateQuery('../sites/form/web_vhost_domain.tform.php', 0, $primary_id, $params);
return $affected_rows;
} else {
throw new SoapFault('status_undefined', 'The status is not available');
return false;
}
}
/**
* Get all databases by user
* @author Julio Montoya BeezNest 2010
*/
public function sites_database_get_all_by_user($session_id, $client_id)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_database_get')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$client_id = $app->functions->intval($client_id);
$sql = "SELECT d.database_id, d.database_name, d.database_user_id, d.database_ro_user_id, du.database_user, du.database_password FROM web_database d LEFT JOIN web_database_user du ON (du.database_user_id = d.database_user_id) INNER JOIN sys_user s on(d.sys_groupid = s.default_group) WHERE client_id = ?";
$all = $app->db->queryAllRecords($sql, $client_id);
return $all;
}
//** backup functions -----------------------------------------------------------------------------------
public function sites_web_domain_backup_list($session_id, $site_id = null)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_domain_backup')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
$result = $app->db->queryAllRecords("SELECT * FROM web_backup".(($site_id != null)?' WHERE parent_domain_id = ?':''), $site_id);
return $result;
}
//* Backup download and restoration by Abdi Joseph
public function sites_web_domain_backup($session_id, $primary_id, $action_type)
{
global $app;
if(!$this->checkPerm($session_id, 'sites_web_domain_backup')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
//*Set variables
$backup_record = $app->db->queryOneRecord("SELECT * FROM `web_backup` WHERE `backup_id`= ?", $primary_id);
$server_id = $backup_record['server_id'];
//*Set default action state
$action_state = "pending";
$tstamp = time();
//* Basic validation of variables
if ($server_id <= 0) {
$this->server->fault('invalid_backup_id', "Invalid or non existant backup_id $primary_id");
return false;
}
if ($action_type != 'backup_download' and $action_type != 'backup_restore') {
$this->server->fault('invalid_action', "Invalid action_type $action_type");
return false;
}
//* Validate instance
$instance_record = $app->db->queryOneRecord("SELECT * FROM `sys_remoteaction` WHERE `action_param`= ? and `action_type`= ? and `action_state`= ?", $primary_id, $action_type, 'pending');
if ($instance_record['action_id'] >= 1) {
$this->server->fault('duplicate_action', "There is already a pending $action_type action");
return false;
}
//* Save the record
if ($app->db->query("INSERT INTO `sys_remoteaction` SET `server_id` = ?, `tstamp` = ?, `action_type` = ?, `action_param` = ?, `action_state` = ?", $server_id, $tstamp, $action_type, $primary_id, $action_state)) {
return true;
} else {
return false;
}
}
//** quota functions -----------------------------------------------------------------------------------
public function quota_get_by_user($session_id, $client_id)
{
global $app;
$app->uses('quota_lib');
if(!$this->checkPerm($session_id, 'quota_get_by_user')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $app->quota_lib->get_quota_data($client_id, false);
}
public function trafficquota_get_by_user($session_id, $client_id, $lastdays = 0)
{
global $app;
$app->uses('quota_lib');
if(!$this->checkPerm($session_id, 'trafficquota_get_by_user')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if ($client_id != null)
$client_id = $app->functions->intval($client_id);
return $app->quota_lib->get_trafficquota_data($client_id, $lastdays);
}
public function databasequota_get_by_user($session_id, $client_id)
{
global $app;
$app->uses('quota_lib');
if(!$this->checkPerm($session_id, 'databasequota_get_by_user')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $app->quota_lib->get_databasequota_data($client_id, false);
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/remoting.inc.php 0000664 0000000 0000000 00000042671 12600761333 0026400 0 ustar 00root root 0000000 0000000 uses('remoting_lib');
$this->_methods = $methods;
/*
$this->app = $app;
$this->conf = $conf;
*/
}
//* remote login function
public function login($username, $password, $client_login = false)
{
global $app, $conf;
// Maintenance mode
$app->uses('ini_parser,getconf');
$server_config_array = $app->getconf->get_global_config('misc');
if($server_config_array['maintenance_mode'] == 'y'){
throw new SoapFault('maintenance_mode', 'This ISPConfig installation is currently under maintenance. We should be back shortly. Thank you for your patience.');
return false;
}
if(empty($username)) {
throw new SoapFault('login_username_empty', 'The login username is empty.');
return false;
}
if(empty($password)) {
throw new SoapFault('login_password_empty', 'The login password is empty.');
return false;
}
//* Delete old remoting sessions
$sql = "DELETE FROM remote_session WHERE tstamp < UNIX_TIMESTAMP()";
$app->db->query($sql);
if($client_login == true) {
$sql = "SELECT * FROM sys_user WHERE USERNAME = ?";
$user = $app->db->queryOneRecord($sql, $username);
if($user) {
$saved_password = stripslashes($user['passwort']);
if(substr($saved_password, 0, 3) == '$1$') {
//* The password is crypt-md5 encrypted
$salt = '$1$'.substr($saved_password, 3, 8).'$';
if(crypt(stripslashes($password), $salt) != $saved_password) {
throw new SoapFault('client_login_failed', 'The login failed. Username or password wrong.');
return false;
}
} else {
//* The password is md5 encrypted
if(md5($password) != $saved_password) {
throw new SoapFault('client_login_failed', 'The login failed. Username or password wrong.');
return false;
}
}
} else {
throw new SoapFault('client_login_failed', 'The login failed. Username or password wrong.');
return false;
}
if($user['active'] != 1) {
throw new SoapFault('client_login_failed', 'The login failed. User is blocked.');
return false;
}
// now we need the client data
$client = $app->db->queryOneRecord("SELECT client.can_use_api FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $user['default_group']);
if(!$client || $client['can_use_api'] != 'y') {
throw new SoapFault('client_login_failed', 'The login failed. Client may not use api.');
return false;
}
//* Create a remote user session
//srand ((double)microtime()*1000000);
$remote_session = md5(mt_rand().uniqid('ispco'));
$remote_userid = $user['userid'];
$remote_functions = '';
$tstamp = time() + $this->session_timeout;
$sql = 'INSERT INTO remote_session (remote_session,remote_userid,remote_functions,client_login,tstamp'
.') VALUES (?, ?, ?, 1, $tstamp)';
$app->db->query($sql, $remote_session,$remote_userid,$remote_functions,$tstamp);
return $remote_session;
} else {
$sql = "SELECT * FROM remote_user WHERE remote_username = ? and remote_password = md5(?)";
$remote_user = $app->db->queryOneRecord($sql, $username, $password);
if($remote_user['remote_userid'] > 0) {
//* Create a remote user session
//srand ((double)microtime()*1000000);
$remote_session = md5(mt_rand().uniqid('ispco'));
$remote_userid = $remote_user['remote_userid'];
$remote_functions = $remote_user['remote_functions'];
$tstamp = time() + $this->session_timeout;
$sql = 'INSERT INTO remote_session (remote_session,remote_userid,remote_functions,tstamp'
.') VALUES (?, ?, ?, ?)';
$app->db->query($sql, $remote_session,$remote_userid,$remote_functions,$tstamp);
return $remote_session;
} else {
throw new SoapFault('login_failed', 'The login failed. Username or password wrong.');
return false;
}
}
}
//* remote logout function
public function logout($session_id)
{
global $app;
if(empty($session_id)) {
throw new SoapFault('session_id_empty', 'The SessionID is empty.');
return false;
}
$sql = "DELETE FROM remote_session WHERE remote_session = ?";
if($app->db->query($sql, $session_id) != false) {
return true;
} else {
return false;
}
}
//** protected functions -----------------------------------------------------------------------------------
protected function klientadd($formdef_file, $reseller_id, $params)
{
global $app;
//* Load the form definition
$app->remoting_lib->loadFormDef($formdef_file);
//* load the user profile of the client
$app->remoting_lib->loadUserProfile($reseller_id);
//* Get the SQL query
$sql = $app->remoting_lib->getSQL($params, 'INSERT', 0);
//* Check if no system user with that username exists
$username = $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 ";
//* Stop on error while preparing the sql query
if($app->remoting_lib->errorMessage != '') {
throw new SoapFault('data_processing_error', $app->remoting_lib->errorMessage);
return false;
}
//* Execute the SQL query
$app->db->query($sql);
$insert_id = $app->db->insertID();
//* Stop on error while executing the sql query
if($app->remoting_lib->errorMessage != '') {
throw new SoapFault('data_processing_error', $app->remoting_lib->errorMessage);
return false;
}
$this->id = $insert_id;
$this->dataRecord = $params;
$app->plugin->raiseEvent('client:' . (isset($params['limit_client']) && $params['limit_client'] > 0 ? 'reseller' : 'client') . ':on_after_insert', $this);
/*
if($app->db->errorMessage != '') {
throw new SoapFault('database_error', $app->db->errorMessage . ' '.$sql);
return false;
}
*/
/* copied from the client_edit php */
exec('ssh-keygen -t rsa -C '.$username.'-rsa-key-'.time().' -f /tmp/id_rsa -N ""');
$app->db->query("UPDATE client SET created_at = UNIX_TIMESTAMP(), id_rsa = ?, ssh_rsa = ? WHERE client_id = ?", @file_get_contents('/tmp/id_rsa'), @file_get_contents('/tmp/id_rsa.pub'), $this->id);
exec('rm -f /tmp/id_rsa /tmp/id_rsa.pub');
//$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 = ? WHERE client_id = ?", $reseller_id, $insert_id);
}
}
return $insert_id;
}
protected function insertQuery($formdef_file, $client_id, $params, $event_identifier = '')
{
$sql = $this->insertQueryPrepare($formdef_file, $client_id, $params);
if($sql !== false) return $this->insertQueryExecute($sql, $params, $event_identifier);
else return false;
}
protected function insertQueryPrepare($formdef_file, $client_id, $params)
{
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, 'INSERT', 0);
if($app->remoting_lib->errorMessage != '') {
throw new SoapFault('data_processing_error', $app->remoting_lib->errorMessage);
return false;
}
$app->log('Executed insertQueryPrepare', LOGLEVEL_DEBUG);
return $sql;
}
protected function insertQueryExecute($sql, $params, $event_identifier = '')
{
global $app;
$app->uses('remoting_lib');
$app->db->query($sql);
if($app->db->errorMessage != '') {
throw new SoapFault('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;
$app->log('Executed insertQueryExecute, raising events now if any: ' . $event_identifier, LOGLEVEL_DEBUG);
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 = '')
{
global $app;
$sql = $this->updateQueryPrepare($formdef_file, $client_id, $primary_id, $params);
if($sql !== false) return $this->updateQueryExecute($sql, $primary_id, $params, $event_identifier);
else return false;
}
protected function updateQueryPrepare($formdef_file, $client_id, $primary_id, $params)
{
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 old record and merge with params, so only new values have to be set in $params
$old_rec = $app->remoting_lib->getDataRecord($primary_id);
foreach ($app->remoting_lib->formDef['fields'] as $fieldName => $fieldConf)
{
if ($fieldConf['formtype'] === 'PASSWORD' && empty($params[$fieldName])) {
unset($old_rec[$fieldName]);
}
}
$params = $app->functions->array_merge($old_rec,$params);
//* Get the SQL query
$sql = $app->remoting_lib->getSQL($params, 'UPDATE', $primary_id);
// throw new SoapFault('debug', $sql);
if($app->remoting_lib->errorMessage != '') {
throw new SoapFault('data_processing_error', $app->remoting_lib->errorMessage);
return false;
}
return $sql;
}
protected function updateQueryExecute($sql, $primary_id, $params, $event_identifier = '')
{
global $app;
$app->uses('remoting_lib');
$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 != '') {
throw new SoapFault('database_error', $app->db->errorMessage . ' '.$sql);
return false;
}
$affected_rows = $app->db->affectedRows();
$app->log('Executed updateQueryExecute, raising events now if any: ' . $event_identifier, LOGLEVEL_DEBUG);
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 = '')
{
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 = $old_rec;
$app->log('Executed deleteQuery, raising events now if any: ' . $event_identifier, LOGLEVEL_DEBUG);
//$this->dataRecord = $params;
//* Get the SQL query
$sql = $app->remoting_lib->getDeleteSQL($primary_id);
$app->db->errorMessage = '';
$app->db->query($sql);
$affected_rows = $app->db->affectedRows();
if($app->db->errorMessage != '') {
throw new SoapFault('database_error', $app->db->errorMessage . ' '.$sql);
return false;
}
if($event_identifier != '') {
$app->plugin->raiseEvent($event_identifier, $this);
}
//* 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)
{
global $app;
$dobre=array();
$session = $this->getSession($session_id);
if(!$session){
return false;
}
$_SESSION['client_login'] = $session['client_login'];
if($session['client_login'] == 1) {
// permissions are checked at an other place
$_SESSION['client_sys_userid'] = $session['remote_userid'];
$app->remoting_lib->loadUserProfile(); // load the profile - we ALWAYS need this on client logins!
return true;
} else {
$_SESSION['client_sys_userid'] = 0;
}
$dobre= str_replace(';', ',', $session['remote_functions']);
$check = in_array($function_name, explode(',', $dobre) );
if(!$check) {
$app->log("REMOTE-LIB DENY: ".$session_id ." /". $function_name, LOGLEVEL_WARN);
}
return $check;
}
protected function getSession($session_id)
{
global $app;
if(empty($session_id)) {
throw new SoapFault('session_id_empty', 'The SessionID is empty.');
return false;
}
$sql = "SELECT * FROM remote_session WHERE remote_session = ? AND tstamp >= UNIX_TIMESTAMP()";
$session = $app->db->queryOneRecord($sql, $session_id);
if($session['remote_userid'] > 0) {
return $session;
} else {
throw new SoapFault('session_does_not_exist', 'The Session is expired or does not exist.');
return false;
}
}
public function server_get($session_id, $server_id = null, $section ='') {
global $app;
if(!$this->checkPerm($session_id, 'server_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if (!empty($session_id)) {
if(!empty($server_id)) {
$app->uses('remoting_lib , getconf');
$section_config = $app->getconf->get_server_config($server_id, $section);
return $section_config;
} else {
$servers = array();
$sql = "SELECT server_id FROM server WHERE 1";
$all = $app->db->queryAllRecords($sql);
foreach($all as $s) {
$servers[$s['server_id']] = $app->getconf->get_server_config($s['server_id'], $section);
}
unset($all);
unset($s);
return $servers;
}
} else {
return false;
}
}
/**
Gets a list of all servers
@param int session_id
@param int server_name
@author Marius Cramer 2014
*/
public function server_get_all($session_id)
{
global $app;
if(!$this->checkPerm($session_id, 'server_get')) {
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
if (!empty($session_id)) {
$sql = "SELECT server_id, server_name FROM server WHERE 1";
$servers = $app->db->queryAllRecords($sql);
return $servers;
} else {
return false;
}
}
/**
* Get a list of functions
* @param int session id
* @return mixed array of the available functions
* @author Julio Montoya BeezNest 2010
*/
public function get_function_list($session_id)
{
if(!$this->checkPerm($session_id, 'get_function_list')) {
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
return false;
}
return $this->_methods;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/remoting_lib.inc.php 0000664 0000000 0000000 00000026065 12600761333 0027225 0 ustar 00root root 0000000 0000000 load('tform_base');
class remoting_lib extends tform_base {
// additional class variables
var $sys_username;
var $sys_userid;
var $sys_default_group;
var $sys_groups;
var $client_id;
var $dataRecord;
//* Load the form definition from file. - special version for remoting
// module parameter is only for compatibility with base class
function loadFormDef($file, $module = '') {
global $app, $conf;
include $file;
$this->formDef = $form;
unset($this->formDef['tabs']);
//* Copy all fields from all tabs into one form definition
foreach($form['tabs'] as $tab) {
foreach($tab['fields'] as $key => $value) {
$this->formDef['fields'][$key] = $value;
}
}
unset($form);
$this->dateformat = $app->lng('conf_format_dateshort');
return true;
}
//* Load the user profile
function loadUserProfile($client_id_param = 0) {
global $app, $conf;
$client_login = false;
if(isset($_SESSION['client_login']) && isset($_SESSION['client_sys_userid']) && $_SESSION['client_login'] == 1) {
$client_sys_userid = $app->functions->intval($_SESSION['client_sys_userid']);
$client = $app->db->queryOneRecord("SELECT client.client_id FROM sys_user, client WHERE sys_user.client_id = client.client_id and sys_user.userid = ?", $client_sys_userid);
$this->client_id = $client['client_id'];
$client_login = true;
} else {
$this->client_id = $app->functions->intval($client_id_param);
}
if($this->client_id == 0) {
$this->sys_username = 'admin';
$this->sys_userid = 1;
$this->sys_default_group = 1;
$this->sys_groups = 1;
$_SESSION["s"]["user"]["typ"] = 'admin';
} else {
$user = $app->db->queryOneRecord("SELECT * FROM sys_user WHERE client_id = ?", $this->client_id);
$this->sys_username = $user['username'];
$this->sys_userid = $user['userid'];
$this->sys_default_group = $user['default_group'];
$this->sys_groups = $user['groups'];
// we have to force admin priveliges for the remoting API as some function calls might fail otherwise.
if($client_login == false) $_SESSION["s"]["user"]["typ"] = 'admin';
}
$_SESSION["s"]["user"]["username"] = $this->sys_username;
$_SESSION["s"]["user"]["userid"] = $this->sys_userid;
$_SESSION["s"]["user"]["default_group"] = $this->sys_default_group;
$_SESSION["s"]["user"]["groups"] = $this->sys_groups;
$_SESSION["s"]["user"]["client_id"] = $this->client_id;
return true;
}
/**
* Converts the data in the array to human readable format
* Datatype conversion e.g. to show the data in lists
* tab parameter is only there for compatibility with params of base class
*
* @param record
* @return record
*/
function decode($record, $tab = '') {
return $this->_decode($record, '', true);
}
/**
* Get the key => value array of a form filled from a datasource definitiom
* dummy parameter is only there for compatibility with params of base class
*
* @param field = array with field definition
* @param record = Dataset as array
* @return key => value array for the value field of a form
*/
function getDatasourceData($field, $record, $dummy = '') {
return $this->_getDatasourceData($field, $record, true);
}
/**
/**
* Rewrite the record data to be stored in the database
* and check values with regular expressions.
*
* @param record = Datensatz als Array
* @return record
*/
function encode($record, $tab = '', $dbencode = true) {
$new_record = $this->_encode($record, '', $dbencode, true);
if(isset($record['_ispconfig_pw_crypted'])) $new_record['_ispconfig_pw_crypted'] = $record['_ispconfig_pw_crypted']; // this one is not in form definitions!
return $new_record;
}
/**
* Create SQL statement
* dummy parameter is only there for compatibility with params of base class
*
* @param record = Datensatz als Array
* @param action = INSERT oder UPDATE
* @param primary_id
* @return record
*/
function getSQL($record, $action = 'INSERT', $primary_id = 0, $sql_ext_where = '', $dummy = '') {
global $app;
if(!is_array($this->formDef)) $app->error("Form definition not found.");
$this->dataRecord = $record;
return $this->_getSQL($record, '', $action, $primary_id, $sql_ext_where, true);
}
function getDeleteSQL($primary_id) {
if(stristr($this->formDef['db_table'], '.')) {
$escape = '';
} else {
$escape = '`';
}
$sql = "DELETE FROM ".$escape.$this->formDef['db_table'].$escape." WHERE ".$this->formDef['db_table_idx']." = ".$primary_id. " AND " . $this->getAuthSQL('d', $this->formDef['db_table']);
return $sql;
}
function getDataRecord($primary_id) {
global $app;
$escape = '`';
$this->loadUserProfile();
if(@is_numeric($primary_id)) {
if($primary_id > 0) {
// Return a single record
return parent::getDataRecord($primary_id);
} elseif($primary_id == -1) {
// Return a array with all records
$sql = "SELECT * FROM ??";
return $app->db->queryAllRecords($sql, $this->formDef['db_table']);
} else {
throw new SoapFault('invalid_id', 'The ID has to be > 0 or -1.');
return array();
}
} elseif (@is_array($primary_id) || @is_object($primary_id)) {
if(@is_object($primary_id)) $primary_id = get_object_vars($primary_id); // do not use cast (array)xxx because it returns private and protected properties!
$sql_offset = 0;
$sql_limit = 0;
$sql_where = '';
$params = array($this->formDef['db_table']);
foreach($primary_id as $key => $val) {
if($key == '#OFFSET#') $sql_offset = $app->functions->intval($val);
elseif($key == '#LIMIT#') $sql_limit = $app->functions->intval($val);
elseif(stristr($val, '%')) {
$sql_where .= "?? like ? AND ";
} else {
$sql_where .= "?? = ? AND ";
}
$params[] = $key;
$params[] = $val;
}
$sql_where = substr($sql_where, 0, -5);
if($sql_where == '') $sql_where = '1';
$sql = "SELECT * FROM ?? WHERE ".$sql_where. " AND " . $this->getAuthSQL('r', $this->formDef['db_table']);
if($sql_offset >= 0 && $sql_limit > 0) $sql .= ' LIMIT ' . $sql_offset . ',' . $sql_limit;
return $app->db->queryAllRecords($sql, true, $params);
} else {
$this->errorMessage = 'The ID must be either an integer or an array.';
return array();
}
}
function ispconfig_sysuser_add($params, $insert_id){
global $conf, $app, $sql1;
$username = $params["username"];
$password = $params["password"];
if(!isset($params['modules'])) {
$modules = $conf['interface_modules_enabled'];
} else {
$modules = $params['modules'];
}
if(isset($params['limit_client']) && $params['limit_client'] > 0) {
$modules .= ',client';
}
if(!isset($params['startmodule'])) {
$startmodule = 'dashboard';
} else {
$startmodule = $params["startmodule"];
if(!preg_match('/'.$startmodule.'/', $modules)) {
$_modules = explode(',', $modules);
$startmodule=$_modules[0];
}
}
$usertheme = $params["usertheme"];
$type = 'user';
$active = 1;
$insert_id = $app->functions->intval($insert_id);
$language = $params["language"];
$groupid = $app->db->datalogInsert('sys_group', array("name" => $username, "description" => "", "client_id" => $insert_id), 'groupid');
$groups = $groupid;
if(!isset($params['_ispconfig_pw_crypted']) || $params['_ispconfig_pw_crypted'] != 1) $password = $app->auth->crypt_password(stripslashes($password));
$sql1 = "INSERT INTO sys_user (username,passwort,modules,startmodule,app_theme,typ,active,language,groups,default_group,client_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$app->db->query($sql1, $username,$password,$modules,$startmodule,$usertheme,$type,$active,$language,$groups,$groupid,$insert_id);
}
function ispconfig_sysuser_update($params, $client_id){
global $app;
$username = $params["username"];
$clear_password = $params["password"];
$client_id = $app->functions->intval($client_id);
if(!isset($params['_ispconfig_pw_crypted']) || $params['_ispconfig_pw_crypted'] != 1) $password = $app->auth->crypt_password(stripslashes($clear_password));
else $password = $clear_password;
$params = array($username);
if ($clear_password) {
$pwstring = ", passwort = ?";
$params[] = $password;
} else {
$pwstring ="" ;
}
$params[] = $client_id;
$sql = "UPDATE sys_user set username = ? $pwstring WHERE client_id = ?";
$app->db->query($sql, true, $params);
}
function ispconfig_sysuser_delete($client_id){
global $app;
$client_id = $app->functions->intval($client_id);
$sql = "DELETE FROM sys_user WHERE client_id = ?";
$app->db->query($sql, $client_id);
$sql = "DELETE FROM sys_group WHERE client_id = ?";
$app->db->query($sql, $client_id);
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/searchform.inc.php 0000664 0000000 0000000 00000027564 12600761333 0026711 0 ustar 00root root 0000000 0000000 listDef = $liste;
$this->module = $module;
//* Fill datasources
foreach($this->listDef['item'] as $key => $field) {
if(is_array($field['datasource'])) {
$this->listDef['item'][$key]['value'] = $this->getDatasourceData($field);
}
}
return true;
}
/**
* Get the key => value array of a form filed from a datasource definitiom
*
* @param field = array with field definition
* @param record = Dataset as array
* @return key => value array for the value field of a form
*/
public function getDatasourceData($field)
{
global $app;
$values = array();
if($field['datasource']['type'] == 'SQL') {
//* Preparing SQL string. We will replace some common placeholders
$querystring = $field['datasource']['querystring'];
$querystring = str_replace('{USERID}', $_SESSION['s']['user']['userid'], $querystring);
$querystring = str_replace('{GROUPID}', $_SESSION['s']['user']['default_group'], $querystring);
$querystring = str_replace('{GROUPS}', $_SESSION['s']['user']['groups'], $querystring);
$table_idx = $this->formDef['db_table_idx'];
//$querystring = str_replace('{RECORDID}',$record[$table_idx],$querystring);
$app->uses('tform');
$querystring = str_replace('{AUTHSQL}', $app->tform->getAuthSQL('r'), $querystring);
//* Getting the records
$tmp_records = $app->db->queryAllRecords($querystring);
if($app->db->errorMessage != ''){
die($app->db->errorMessage);
}
if(is_array($tmp_records)) {
$key_field = $field['datasource']['keyfield'];
$value_field = $field['datasource']['valuefield'];
foreach($tmp_records as $tmp_rec) {
$values[$tmp_rec[$key_field]] = $tmp_rec[$value_field];
}
}
}
if($field['datasource']['type'] == 'CUSTOM') {
//* Calls a custom class to validate this record
if($field['datasource']['class'] != '' and $field['datasource']['function'] != '') {
$datasource_class = $field['datasource']['class'];
$datasource_function = $field['datasource']['function'];
$app->uses($datasource_class);
$record = array();
$values = $app->$datasource_class->$datasource_function($field, $record);
}else{
$this->errorMessage .= "Custom datasource class or function is empty \r\n";
}
}
return $values;
}
public function getSearchSQL($sql_where = '')
{
global $db;
//* Config vars
$list_name = $this->listDef['name'];
$search_prefix = $this->listDef['search_prefix'];
//* store retrieval query
foreach($this->listDef['item'] as $i) {
$field = $i['field'];
//* TODO ? hat sich die suche ge�ndert - has itself search ?
$ki = $search_prefix.$field;
if(isset($_REQUEST) and $_REQUEST[$ki] != $_SESSION['search'][$list_name][$ki]){
$this->searchChanged = 1;
}
//* suchfield in session store.
if(isset($_REQUEST[$ki])){
$_SESSION['search'][$list_name][$ki] = $_REQUEST[$ki];
}
if($i['formtype'] == 'SELECT'){
if(is_array($i['value'])) {
$out = '';
foreach($i['value'] as $k => $v) {
$selected = ($k == $_SESSION['search'][$list_name][$ki] && $_SESSION['search'][$list_name][$ki] != '') ? ' SELECTED' : '';
$out .= "\r\n";
}
}
$this->searchValues[$ki] = $out;
}else{
$this->searchValues[$ki] = $_SESSION['search'][$list_name][$ki];
}
}
//* store variables in object. $this->searchValues = $_SESSION["search"][$list_name];
foreach($this->listDef['item'] as $i) {
$field = $i['field'];
//if($_REQUEST[$search_prefix.$field] != '') $sql_where .= " $field ".$i["op"]." '".$i["prefix"].$_REQUEST[$search_prefix.$field].$i["suffix"]."' and";
if($_SESSION['search'][$list_name][$ki] != ''){
$sql_where .= " $field ".$i['op']." '".$i['prefix'].$_SESSION['search'][$list_name][$ki].$i['suffix']."' and";
}
}
return ($sql_where != '') ? substr($sql_where, 0, -3) : '1';
}
public function getPagingSQL($sql_where = '1') {
global $app, $conf;
$list_name = $this->listDef['name'];
$search_prefix = $this->listDef['search_prefix'];
$records_per_page = $this->listDef['records_per_page'];
$table = $this->listDef['table'];
//* set page to seror id session not set
if($_SESSION['search'][$list_name]['page'] == '') $_SESSION['search'][$list_name]['page'] = 0;
//* Set page size to request if set
if(isset($_REQUEST['page'])) $_SESSION['search'][$list_name]['page'] = $_REQUEST['page'];
//* TODO PAGE to 0 set, if look for themselves ge?ndert. = page auf 0 setzen, wenn suche sich ge�ndert hat.
if($this->searchChanged == 1) $_SESSION['search'][$list_name]['page'] = 0;
$sql_von = $_SESSION['search'][$list_name]['page'] * $records_per_page;
$record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM ?? WHERE $sql_where", $table);
$pages = $app->functions->intval(($record_count['anzahl'] - 1) / $records_per_page);
$vars['list_file'] = $this->listDef['file'];
$vars['page'] = $_SESSION['search'][$list_name]['page'];
$vars['last_page'] = $_SESSION['search'][$list_name]['page'] - 1;
$vars['next_page'] = $_SESSION['search'][$list_name]['page'] + 1;
$vars['pages'] = $pages;
$vars['max_pages'] = $pages + 1;
$vars['records_gesamt'] = $record_count['anzahl'];
$vars['page_params'] = $this->listDef['page_params'];
if($_SESSION['search'][$list_name]['page'] > 0) $vars['show_page_back'] = 1;
if($_SESSION['search'][$list_name]['page'] <= $vars['pages'] - 1) $vars['show_page_next'] = 1;
$this->pagingValues = $vars;
$this->pagingHTML = $this->getPagingHTML($vars);
return "LIMIT $sql_von, $records_per_page";
}
public function getPagingHTML($vars) {
global $app;
$page_params = $vars['page_params'];
$list_file = $vars['list_file'];
$content = ' ';
if($vars['show_page_back'] == 1){
$content .= ' ';
}
$content .= ' '.$app->lng('Page').' '.$vars['next_page'].' '.$app->lng('of').' '.$vars['max_pages'].' ';
if($vars['show_page_next'] == 1){
$content .= ' ';
} else{
$content .= ' ';
}
$content .= '';
return $content;
}
public function getPagingHTMLasTXT($vars)
{
global $app;
$page_params = $vars['page_params'];
$list_file = $vars['list_file'];
$content = '[|<< ]';
if($vars['show_page_back'] == 1){
$content .= '[<< '.$app->lng('Back').'] ';
}
$content .= ' '.$app->lng('Page').' '.$vars['next_page'].' '.$app->lng('of').' '.$vars['max_pages'].' ';
if($vars['show_page_next'] == 1){
$content .= '['.$app->lng('Next').' >>] ';
}
$content .= '[ >>|]';
return $content;
}
public function getSortSQL()
{
$sort_field = $this->listDef['sort_field'];
$sort_direction = $this->listDef['sort_direction'];
return ($sort_field != '' && $sort_direction != '') ? "ORDER BY $sort_field $sort_direction" : '';
}
public function saveSearchSettings($searchresult_name)
{
global $app, $conf;
$list_name = $this->listDef['name'];
$settings = $_SESSION['search'][$list_name];
unset($settings['page']);
$data = serialize($settings);
$userid = $_SESSION['s']['user']['userid'];
$groupid = $_SESSION['s']['user']['default_group'];
$sys_perm_user = 'riud';
$sys_perm_group = 'r';
$sys_perm_other = '';
$module = $_SESSION['s']['module']['name'];
$searchform = $this->listDef['name'];
$title = $searchresult_name;
$sql = 'INSERT INTO `searchform` ( '
.'`sys_userid` , `sys_groupid` , `sys_perm_user` , `sys_perm_group` , `sys_perm_other` , `module` , `searchform` , `title` , `data` '
.')VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)';
$app->db->query($sql, $userid, $groupid, $sys_perm_user, $sys_perm_group, $sys_perm_other, $module, $searchform, $title, $data);
}
public function decode($record)
{
global $app;
if(is_array($record)) {
foreach($this->listDef['item'] as $field) {
$key = $field['field'];
switch ($field['datatype'])
{
case 'DATE':
if($val > 0) {
$record[$key] = date($this->dateformat, $record[$key]);
}
break;
case 'INTEGER':
$record[$key] = $app->functions->intval($record[$key]);
break;
case 'DOUBLE':
$record[$key] = $record[$key];
break;
case 'CURRENCY':
$record[$key] = number_format($record[$key], 2, ',', '');
break;
case 'VARCHAR':
case 'TEXT':
default:
$record[$key] = stripslashes($record[$key]);
break;
}
}
}
return $record;
}
/* TODO: check for double quoting mysql value */
public function encode($record)
{
global $app;
if(is_array($record)) {
foreach($this->listDef['item'] as $field) {
$key = $field['field'];
switch ($field['datatype'])
{
case 'VARCHAR':
case 'TEXT':
if(!is_array($record[$key])) {
$record[$key] = $app->db->quote($record[$key]);
} else {
$record[$key] = implode($this->tableDef[$key]['separator'], $record[$key]);
}
break;
case 'DATE':
if($record[$key] > 0) {
list($tag, $monat, $jahr) = explode('.', $record[$key]);
$record[$key] = mktime(0, 0, 0, $monat, $tag, $jahr);
}
break;
case 'INTEGER':
$record[$key] = $app->functions->intval($record[$key]);
break;
case 'DOUBLE':
$record[$key] = $app->db->quote($record[$key]);
break;
case 'CURRENCY':
$record[$key] = str_replace(',', '.', $record[$key]);
break;
}
}
}
return $record;
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/searchform_actions.inc.php 0000664 0000000 0000000 00000014454 12600761333 0030423 0 ustar 00root root 0000000 0000000 tpl)) $app->uses('tpl');
if(!is_object($app->searchform)) $app->uses('searchform');
if(!is_object($app->tform)) $app->uses('tform');
// Load list definition
$app->searchform->loadListDef($list_def_file);
// Delete the search form contents, if requested
if($_REQUEST["empty_searchfields"] == 'yes') {
$list_name = $app->searchform->listDef["name"];
unset($_SESSION["search"][$list_name]);
}
// Save the search for later usage
if($_REQUEST["btn_submit_search_save"] && $_REQUEST["search_save_as"] != '') {
$app->searchform->saveSearchSettings($_REQUEST["search_save_as"]);
}
// Set th returnto value for forms
$_SESSION["s"]["form"]["return_to_url"] = $app->searchform->listDef["file"];
if(!is_file('templates/'.$app->searchform->listDef["name"].'_search.htm')) {
$app->uses('searchform_tpl_generator');
$app->searchform_tpl_generator->buildHTML($app->searchform->listDef);
}
$app->tpl->newTemplate("searchpage.tpl.htm");
$app->tpl->setInclude('content_tpl', 'templates/'.$app->searchform->listDef["name"].'_search.htm');
// Getting Datasets from DB
$records = $app->db->queryAllRecords($this->getQueryString());
$this->DataRowColor = "#FFFFFF";
if(is_array($records)) {
$this->idx_key = $app->searchform->listDef["table_idx"];
foreach($records as $rec) {
$records_new[] = $this->prepareDataRow($rec);
}
}
$app->tpl->setLoop('records', $records_new);
//print_r($records_new);
$this->onShow();
}
function prepareDataRow($rec) {
global $app;
$rec = $app->searchform->decode($rec);
// Alternating datarow colors
$this->DataRowColor = ($this->DataRowColor == "#FFFFFF")?"#EEEEEE":"#FFFFFF";
$rec["bgcolor"] = $this->DataRowColor;
// substitute value for select fields
foreach($app->searchform->listDef["item"] as $field) {
$key = $field["field"];
if($field['formtype'] == "SELECT") {
if($rec[$key] == 'y' or $rec[$key] == 'n') {
// Set a additional image variable for bolean fields
$rec['_'.$key.'_'] = ($rec[$key] == 'y')?'list_icon_true.png':'list_icon_false.png';
}
// substitute value for select field
$rec[$key] = $field['value'][$rec[$key]];
}
}
// The variable "id" contains always the index variable
$rec["id"] = $rec[$this->idx_key];
return $rec;
}
function getQueryString() {
global $app;
// Generate the search sql
if($app->searchform->listDef["auth"] != 'no') {
if($_SESSION["s"]["user"]["typ"] == "admin") {
$sql_where = "";
} else {
$sql_where = $app->tform->getAuthSQL('r')." and";
}
}
if($this->SQLExtWhere != '') {
$sql_where .= " ".$this->SQLExtWhere." and";
}
$sql_where = $app->searchform->getSearchSQL($sql_where);
$app->tpl->setVar($app->searchform->searchValues);
$order_by_sql = $this->SQLOrderBy;
// Generate SQL for paging
$limit_sql = $app->searchform->getPagingSQL($sql_where);
$app->tpl->setVar("paging", $app->searchform->pagingHTML);
return "SELECT * FROM ".$app->searchform->listDef["table"]." WHERE $sql_where $order_by_sql $limit_sql";
}
function onShow() {
global $app;
// Language File setzen
$lng_file = ISPC_WEB_PATH.'/lang/lib/lang/'.$_SESSION['s']['language'].'_list.lng';
if(!file_exists($lng_file)) $lng_file = ISPC_WEB_PATH.'/lang/lib/lang/en_'.'_list.lng';
include $lng_file;
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_".$app->searchform->listDef['name']."_search.lng";
if(!file_exists($lng_file)) $lng_file = 'lib/lang/en_'.$app->searchform->listDef['name']."_search.lng";
include $lng_file;
$app->tpl->setVar($wb);
$app->tpl->setVar("form_action", $app->searchform->listDef["file"]);
// Parse the templates and send output to the browser
$this->onShowEnd();
}
function onShowEnd() {
global $app;
if(count($_REQUEST) > 0) {
$app->tpl->setVar('searchresult_visible', 1);
if($_REQUEST['searchresult_visible'] == 'no') $app->tpl->setVar('searchresult_visible', 0);
if($_REQUEST['searchform_visible'] == 'yes') {
$app->tpl->setVar('searchform_visible', 1);
} else {
$app->tpl->setVar('searchform_visible', 0);
}
} else {
$app->tpl->setVar('searchform_visible', 1);
if($_REQUEST['searchform_visible'] == 'no') $app->tpl->setVar('searchform_visible', 0);
if($_REQUEST['searchresult_visible'] == 'yes') {
$app->tpl->setVar('searchresult_visible', 1);
} else {
$app->tpl->setVar('searchresult_visible', 0);
}
}
// make columns visible
$visible_columns = explode(",", $app->searchform->listDef['default_columns']);
foreach($visible_columns as $col) {
$app->tpl->setVar($col.'_visible', 1);
}
$app->tpl_defaults();
$app->tpl->pparse();
}
}
?>
ispconfig3-master-interface-lib/interface/lib/classes/searchform_tpl_generator.inc.php 0000664 0000000 0000000 00000011454 12600761333 0031625 0 ustar 00root root 0000000 0000000