ininitial froxlor commit;

'reverted' old-style update-process;
removed billing-classes, -functions and -templates;
some sql-fixes;
This commit is contained in:
Michael Kaufmann (d00p)
2010-01-20 09:12:52 +00:00
commit 9907afe630
580 changed files with 60898 additions and 0 deletions

View File

@@ -0,0 +1,561 @@
<?php
/**
* Implementation of the Application Packaging Standard from SwSoft/Parallels
* http://apsstandard.com
*
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Sven Skrabal <info@nexpa.de>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Cron
* @version $Id: class.ApsInstaller.php 2724 2009-06-07 14:18:02Z flo $
* @todo logging
* run with user uid/gid
* folder truncation/tar all files
*/
class ApsInstaller extends ApsParser
{
private $db = false;
private $db_root = false;
private $DomainPath = '';
private $Domain = '';
private $RealPath = '';
private $RootDir = '';
private $Hosts = '';
/**
* constructor of class. setup some basic variables
*
* @param settings array with the global settings from syscp
* @param db instance of the database class from syscp
* @param db_root instance of the database class from syscp with root permissions
*/
public function __construct($settings, $db, $db_root)
{
$this->db = $db;
$this->db_root = $db_root;
$this->RootDir = dirname(dirname(__FILE__)) . '/';
$this->Hosts = $settings['system']['mysql_access_host'];
}
/**
* main function of class which handles all
*/
public function InstallHandler()
{
chdir($this->RootDir);
$result = $this->db->query('SELECT * FROM `' . TABLE_APS_TASKS . '` AS `t` INNER JOIN `' . TABLE_APS_INSTANCES . '` AS `i` ON `t`.`InstanceID` = `i`.`ID` INNER JOIN `' . TABLE_APS_PACKAGES . '` AS `p` ON `i`.`PackageID` = `p`.`ID` INNER JOIN `' . TABLE_PANEL_CUSTOMERS . '` AS `c` ON `i`.`CustomerID` = `c`.`customerid` WHERE `TASK` NOT IN (' . TASK_SYSTEM_UPDATE . ', ' . TASK_SYSTEM_DOWNLOAD . ')');
while($Row = $this->db->fetch_array($result))
{
//check for existing aps xml file
if(!file_exists($this->RootDir . 'packages/' . $Row['Path'] . '/APP-META.xml'))
{
$this->db->query('UPDATE `' . TABLE_APS_INSTANCES . '` SET `Status` = ' . INSTANCE_ERROR . ' WHERE `ID` = ' . $this->db->escape($Row['InstanceID']));
continue;
}
//get contents and parse them
$XmlContent = file_get_contents($this->RootDir . 'packages/' . $Row['Path'] . '/APP-META.xml');
$Xml = new SimpleXMLElement($XmlContent);
//check for unparseable xml data
if($Xml == false)
{
$this->db->query('UPDATE `' . TABLE_APS_INSTANCES . '` SET `Status` = ' . INSTANCE_ERROR . ' WHERE `ID` = ' . $this->db->escape($Row['InstanceID']));
continue;
}
$Task = $Row['Task'];
$this->DomainPath = '';
$this->Domain = '';
$this->RealPath = '';
//lock instance so installation cannot be canceled from the panel
$this->db->query('UPDATE `' . TABLE_APS_INSTANCES . '` SET `Status` = ' . INSTANCE_TASK_ACTIVE . ' WHERE `ID` = ' . $this->db->escape($Row['InstanceID']));
//setup environment with data for domain/installation location
self::PrepareBasics($Row);
//create database if necessary and setup environment variables
self::PrepareDatabase($Xml, $Row, $Task);
//unpack installation scripts and package files if necessary
if(self::PrepareFiles($Xml, $Row, $Task))
{
//setup environment variables fetched from installation wizard
self::PrepareWizardData($Xml, $Row, $Task);
//run installation scripts from packages
self::RunInstaller($Xml, $Row, $Task);
}
//remove installation scripts
self::CleanupData($Xml, $Row, $Task);
unset($Xml);
}
}
/**
* run the installation script and log errors if there are some
*
* @param xml instance of a valid xml object with a parsed APP-META.xml file
* @param row current entry from the database for app to handle
* @param task numeric code to specify what to do
* @return success true/error false
*/
private function RunInstaller($Xml, $Row, $Task)
{
//installation
if($Task == TASK_INSTALL)
{
//setup right path and run installation script
chdir($this->RealPath . $this->DomainPath . '/install_scripts/');
$Return = array();
$ReturnStatus = 0;
$Return = safe_exec('php ' . escapeshellcmd($this->RealPath . $this->DomainPath . '/install_scripts/configure install'), $ReturnStatus);
if($ReturnStatus != 0)
{
//write output of script on error into database for admin
$Buffer = '';
$Count = 0;
foreach($Return as $Line)
{
$Count+= 1;
$Buffer.= $Line;
if($Count != count($Return))$Buffer.= "\n";
}
//FIXME error logging
echo ("error : installer\n" . $Buffer . "\n");
$this->db->query('UPDATE `' . TABLE_APS_INSTANCES . '` SET `Status` = ' . INSTANCE_ERROR . ' WHERE `ID` = ' . $this->db->escape($Row['InstanceID']));
return false;
}
else
{
//installation succeeded
//chown all files if installtion script has created some new files. otherwise customers cannot edit the files via ftp
safe_exec('chown ' . (int)$Row['guid'] . ':' . (int)$Row['guid'] . ' -R ' . escapeshellarg($this->RealPath . $this->DomainPath . '/'));
//update database
$this->db->query('UPDATE `' . TABLE_APS_INSTANCES . '` SET `Status` = ' . INSTANCE_SUCCESS . ' WHERE `ID` = ' . $this->db->escape($Row['InstanceID']));
return true;
}
}
}
/**
* remove installation scripts from filesystem and remove tasks and update the database
*
* @param xml instance of a valid xml object with a parsed APP-META.xml file
* @param row current entry from the database for app to handle
* @param task numeric code to specify what to do
*/
private function CleanupData($Xml, $Row, $Task)
{
chdir($this->RootDir);
if($Task == TASK_INSTALL)
{
//cleanup installation
self::UnlinkRecursive($this->RealPath . $this->DomainPath . '/install_scripts/');
//remove task
$this->db->query('DELETE FROM `' . TABLE_APS_TASKS . '` WHERE `Task` = ' . TASK_INSTALL . ' AND `InstanceID` = ' . $this->db->escape($Row['InstanceID']));
}
elseif($Task == TASK_REMOVE)
{
//FIXME cleanup installation
//remove files from: $this->RealPath . $this->DomainPath . '/'
//remove permissions
//drop database
$XmlDb = $Xml->requirements->children('http://apstandard.com/ns/1/db');
if($XmlDb->db->id)
{
//database management
$Database = 'web' . $Row['CustomerID'] . 'aps' . $Row['InstanceID'];
foreach(array_map('trim', explode(',', $this->Hosts)) as $DatabaseHost)
{
$this->db_root->query('REVOKE ALL PRIVILEGES ON * . * FROM `' . $this->db->escape($Database) . '`@`' . $this->db->escape($DatabaseHost) . '`');
$this->db_root->query('REVOKE ALL PRIVILEGES ON `' . $this->db->escape($Database) . '` . * FROM `' . $this->db->escape($Database) . '`@`' . $this->db->escape($DatabaseHost) . '`');
$this->db_root->query('DELETE FROM `mysql`.`user` WHERE `User` = "' . $this->db->escape($Database) . '" AND `Host` = "' . $this->db->escape($DatabaseHost) . '"');
}
$this->db_root->query('DROP DATABASE IF EXISTS `' . $this->db->escape($Database) . '`');
$this->db_root->query('FLUSH PRIVILEGES');
}
//remove task & delete package instance + settings
$this->db->query('DELETE FROM `' . TABLE_APS_TASKS . '` WHERE `Task` = ' . TASK_REMOVE . ' AND `InstanceID` = ' . $this->db->escape($Row['InstanceID']));
$this->db->query('DELETE FROM `' . TABLE_APS_INSTANCES . '` WHERE `ID` = ' . $this->db->escape($Row['InstanceID']));
$this->db->query('DELETE FROM `' . TABLE_APS_SETTINGS . '` WHERE `InstanceID` = ' . $this->db->escape($Row['InstanceID']));
}
}
/**
* setup all environment variables from the wizard, they're all needed by the installation script
*
* @param xml instance of a valid xml object with a parsed APP-META.xml file
* @param row current entry from the database for app to handle
* @param task numeric code to specify what to do
*/
private function PrepareWizardData($Xml, $Row, $Task)
{
//data collected by wizard
//FIXME install_only parameter/reconfigure
$result = $this->db->query('SELECT * FROM `' . TABLE_APS_SETTINGS . '` WHERE `InstanceID` = ' . $this->db->escape($Row['InstanceID']));
while($Row2 = $this->db->fetch_array($result))
{
//skip APS internal data
if($Row2['Name'] == 'main_location'
|| $Row2['Name'] == 'main_domain'
|| $Row2['Name'] == 'main_database_password'
|| $Row2['Name'] == 'license')continue;
putenv('SETTINGS_' . $Row2['Name'] . '=' . $Row2['Value']);
}
}
/**
* extract all needed files from the aps packages
*
* @param xml instance of a valid xml object with a parsed APP-META.xml file
* @param row current entry from the database for app to handle
* @param task numeric code to specify what to do
* @return success true/error false
*/
private function PrepareFiles($Xml, $Row, $Task)
{
if($Task == TASK_INSTALL)
{
//FIXME truncate customer directory
//remove files from: $this->RealPath . $this->DomainPath . '/*'
if(!file_exists($this->RealPath . $this->DomainPath . '/'))mkdir($this->RealPath . $this->DomainPath . '/', 0777, true);
//extract all files and chown them to the customer guid
if(self::ExtractZip($this->RootDir . 'packages/' . $Row['Path'] . '/' . $Row['Path'], $Xml->mapping['path'], $this->RealPath . $this->DomainPath . '/') == false
|| self::ExtractZip($this->RootDir . 'packages/' . $Row['Path'] . '/' . $Row['Path'], 'scripts', $this->RealPath . $this->DomainPath . '/install_scripts/') == false)
{
$this->db->query('UPDATE `' . TABLE_APS_INSTANCES . '` SET `Status` = ' . INSTANCE_ERROR . ' WHERE `ID` = ' . $this->db->escape($Row['InstanceID']));
//FIXME clean up already installed data
//remove files from: $this->RealPath . $this->DomainPath . '/*'
return false;
}
safe_exec('chown ' . (int)$Row['guid'] . ':' . (int)$Row['guid'] . ' -R ' . escapeshellarg($this->RealPath . $this->DomainPath . '/'));
}
else
{
if(self::ExtractZip($this->RootDir . 'packages/' . $Row['Path'] . '/' . $Row['Path'], 'scripts', $this->RealPath . $this->DomainPath . '/install_scripts/') == false)
{
$this->db->query('UPDATE `' . TABLE_APS_INSTANCES . '` SET `Status` = ' . INSTANCE_ERROR . ' WHERE `ID` = ' . $this->db->escape($Row['InstanceID']));
//clean up already installed data
self::UnlinkRecursive($this->RealPath . $this->DomainPath . '/install_scripts/');
return false;
}
//set right file owner
safe_exec('chown ' . (int)$Row['guid'] . ':' . (int)$Row['guid'] . ' -R ' . escapeshellarg($this->RealPath . $this->DomainPath . '/'));
}
//recursive mappings
self::PrepareMappings($Xml->mapping, $Xml->mapping['url'], $this->RealPath . $this->DomainPath . '/');
return true;
}
/**
* setup path environment variables for the installation script
*
* @param parentmapping instance of parsed xml file, current mapping position
* @param url relative path for application specifying the current path within the mapping tree
* @param path absolute path for application specifying the current path within the mapping tree
*/
private function PrepareMappings($ParentMapping, $Url, $Path)
{
//check for special PHP permissions
//must be done with xpath otherwise check not possible (XML parser problem with attributes)
$ParentMapping->registerXPathNamespace('p', 'http://apstandard.com/ns/1/php');
$Result = $ParentMapping->xpath('p:permissions');
if($Result[0]['writable'] == 'true')
{
//fixing file permissions to writeable
if(is_dir($Path))
{
chmod($Path, 0775);
}
else
{
chmod($Path, 0664);
}
}
if($Result[0]['readable'] == 'false')
{
//fixing file permissions to non readable
if(is_dir($Path))
{
chmod($Path, 0333);
}
else
{
chmod($Path, 0222);
}
}
//set environment variables
$EnvVariable = str_replace("/", "_", $Url);
putenv('WEB_' . $EnvVariable . '_DIR=' . $Path);
//resolve deeper mappings
foreach($ParentMapping->mapping as $Mapping)
{
//recursive check of other mappings
if($Url == '/')
{
self::PrepareMappings($Mapping, $Url . $Mapping['url'], $Path . $Mapping['url']);
}
else
{
self::PrepareMappings($Mapping, $Url . '/' . $Mapping['url'], $Path . '/' . $Mapping['url']);
}
}
}
/**
* setup domain environment variables for the installation script
*
* @param xml instance of a valid xml object with a parsed APP-META.xml file
*/
private function PrepareBasics($Row)
{
//domain
$result = $this->db->query('SELECT * FROM `' . TABLE_APS_SETTINGS . '` WHERE `InstanceID` = ' . $this->db->escape($Row['InstanceID']) . ' AND `Name` = "main_domain"');
$Row3 = $this->db->fetch_array($result);
$result2 = $this->db->query('SELECT * FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `id` = ' . $this->db->escape($Row3['Value']));
$Row3 = $this->db->fetch_array($result2);
$this->Domain = $Row3['domain'];
$this->RealPath = $Row3['documentroot'];
//location
$result3 = $this->db->query('SELECT * FROM `' . TABLE_APS_SETTINGS . '` WHERE `InstanceID` = ' . $this->db->escape($Row['InstanceID']) . ' AND `Name` = "main_location"');
$Row3 = $this->db->fetch_array($result3);
$this->DomainPath = $Row3['Value'];
//if application is directly installed on domain remove / at the end
if($this->DomainPath == '')$this->RealPath = substr($this->RealPath, 0, strlen($this->RealPath) - 1);
//url environment variables
putenv('BASE_URL_HOST=' . $this->Domain);
putenv('BASE_URL_PATH=' . $this->DomainPath . '/');
putenv('BASE_URL_SCHEME=http');
}
/**
* create a database if necessary and setup environment variables
*
* @param xml instance of a valid xml object with a parsed APP-META.xml file
* @param row current entry from the database for app to handle
* @param task numeric code to specify what to do
*/
private function PrepareDatabase($Xml, $Row, $Task)
{
global $db_root;
$XmlDb = $Xml->requirements->children('http://apstandard.com/ns/1/db');
if($XmlDb->db->id)
{
//database management
$NewDatabase = 'web' . $Row['CustomerID'] . 'aps' . $Row['InstanceID'];
$result = $this->db->query('SELECT * FROM `' . TABLE_APS_SETTINGS . '` WHERE `InstanceID` = ' . $this->db->escape($Row['InstanceID']) . ' AND `Name` = "main_database_password"');
$Row3 = $this->db->fetch_array($result);
$DbPassword = $Row3['Value'];
if($Task == TASK_INSTALL)
{
$this->db_root->query('DROP DATABASE IF EXISTS `' . $this->db->escape($NewDatabase) . '`');
$this->db_root->query('CREATE DATABASE IF NOT EXISTS `' . $this->db->escape($NewDatabase) . '`');
foreach(array_map('trim', explode(',', $this->Hosts)) as $DatabaseHost)
{
$this->db_root->query('GRANT ALL PRIVILEGES ON `' . $this->db->escape($NewDatabase) . '`.* TO `' . $this->db->escape($NewDatabase) . '`@`' . $this->db->escape($DatabaseHost) . '` IDENTIFIED BY \'password\'');
$this->db_root->query('SET PASSWORD FOR `' . $this->db->escape($NewDatabase) . '`@`' . $this->db->escape($DatabaseHost) . '` = PASSWORD(\'' . $DbPassword . '\')');
}
$this->db_root->query('FLUSH PRIVILEGES');
}
//get first mysql access host
$AccessHosts = array_map('trim', explode(',', $this->Hosts));
//environment variables
putenv('DB_' . $XmlDb->db->id . '_TYPE=mysql');
putenv('DB_' . $XmlDb->db->id . '_NAME=' . $NewDatabase);
putenv('DB_' . $XmlDb->db->id . '_LOGIN=' . $NewDatabase);
putenv('DB_' . $XmlDb->db->id . '_PASSWORD=' . $DbPassword);
putenv('DB_' . $XmlDb->db->id . '_HOST=' . $AccessHosts[0]);
putenv('DB_' . $XmlDb->db->id . '_PORT=3306');
putenv('DB_' . $XmlDb->db->id . '_VERSION=' . mysql_get_server_info());
}
}
/**
* extract complete directories from a zipfile
*
* @param filename path to zipfile to extract
* @param directory which directory in zipfile to extract
* @param destination destination directory for files to extract
* @return success true/error false
*/
private function ExtractZip($Filename, $Directory, $Destination)
{
if(!file_exists($Filename))return false;
//fix slash notation for correct paths
if(substr($Directory, -1, 1) == '/')$Directory = substr($Directory, 0, strlen($Directory) - 1);
if(substr($Destination, -1, 1) != '/')$Destination.= '/';
//open zipfile to read its contents
$ZipHandle = zip_open(realpath($Filename));
if(is_resource($ZipHandle))
{
while($ZipEntry = zip_read($ZipHandle))
{
if(substr(zip_entry_name($ZipEntry), 0, strlen($Directory)) == $Directory)
{
//fix relative path from zipfile
$NewPath = zip_entry_name($ZipEntry);
$NewPath = substr($NewPath, strlen($Directory));
//directory
if(substr($NewPath, -1, 1) == '/')
{
if(!file_exists($Destination . $NewPath))mkdir($Destination . $NewPath, 0777, true);
}
else
{
//files
if(zip_entry_open($ZipHandle, $ZipEntry))
{
$File = fopen($Destination . $NewPath, "wb");
if($File)
{
while($Line = zip_entry_read($ZipEntry))
{
fwrite($File, $Line);
}
fclose($File);
}
else
{
return false;
}
}
}
}
}
zip_close($ZipHandle);
return true;
}
else
{
$ReturnLines = array();
$ReturnVal = - 1;
//on 64 bit systems the zip functions can fail -> use exec to extract the files
$ReturnLines = safe_exec('unzip -o -qq ' . escapeshellarg(realpath($Filename)) . ' ' . escapeshellarg($Directory . '/*') . ' -d ' . escapeshellarg(sys_get_temp_dir()), $ReturnVal);
if($ReturnVal == 0)
{
//fix absolute structure of extracted data
if(!file_exists($Destination))mkdir($Destination, 0777, true);
safe_exec('cp -Rf ' . sys_get_temp_dir() . '/' . $Directory . '/*' . ' ' . escapeshellarg($Destination));
self::UnlinkRecursive(sys_get_temp_dir() . '/' . $Directory . '/');
return true;
}
else
{
return false;
}
}
return false;
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,269 @@
<?php
/**
* Implementation of the Application Packaging Standard from SwSoft/Parallels
* http://apsstandard.com
*
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Sven Skrabal <info@nexpa.de>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Cron
* @version $Id: class.ApsUpdater.php 2724 2009-06-07 14:18:02Z flo $
* @todo logging
* install specific packages by name
* other solution than using url_fopen
* move url for distributionserver into panel
*/
class ApsUpdater extends ApsParser
{
private $settings = array();
private $db = false;
private $RequestDomain = '';
private $RootUrl = '';
private $RootDir = '';
/**
* constructor of class. setup some basic variables needed by class
*
* @param db instance of the database class from syscp
*/
public function __construct($db)
{
$this->db = $db;
$this->RequestDomain = 'apscatalog.com';
$this->RootUrl = '/1/';
$this->RootDir = dirname(dirname(__FILE__)) . '/';
}
/**
* Main function of class which handles all around the update mechanism
*/
public function UpdateHandler()
{
chdir($this->RootDir);
//return if allow_url_fopen is disabled
if(ini_get('allow_url_fopen') == '0')
{
echo ("The APS updater cronjob requires that allow_url_fopen is enabled for the PHP CLI binary!\n");
return;
}
//return if no task exists
$Result = $this->db->query('SELECT * FROM `' . TABLE_APS_TASKS . '` WHERE `Task` IN (' . TASK_SYSTEM_UPDATE . ', ' . TASK_SYSTEM_DOWNLOAD . ')');
if($this->db->num_rows($Result) == 0)
{
return;
}
//query first task -> updater can only do one job within a run
$Task = $this->db->fetch_array($Result);
$this->db->query('DELETE FROM `' . TABLE_APS_TASKS . '` WHERE `Task` = ' . $Task['Task']);
//fetch all vendors
$Vendors = self::FetchSubUrls($this->RootUrl);
foreach($Vendors as $Vendor)
{
//fetch all applications from vendors
$Applications = self::FetchSubUrls($this->RootUrl . $Vendor);
foreach($Applications as $Application)
{
//get newest version of package which is already installed
$CurrentVersion = '';
$Result = $this->db->query('SELECT * FROM `' . TABLE_APS_PACKAGES . '` WHERE `Name` = "' . $this->db->escape(substr($Application, 0, -1)) . '"');
while($Row = $this->db->fetch_array($Result))
{
if(version_compare($Row['Version'] . '-' . $Row['Release'], $CurrentVersion) == 1)
{
$CurrentVersion = $Row['Version'] . '-' . $Row['Release'];
}
}
if($this->db->num_rows($Result) != 0)
{
//package already installed in system, search for newer version
if($Task['Task'] != TASK_SYSTEM_UPDATE)continue;
//fetch different versions of application from distribution server
$NewerVersion = '';
$Versions = self::FetchSubUrls($this->RootUrl . $Vendor . $Application);
foreach($Versions as $Version)
{
$OnlineVersion = substr($Version, 0, -1);
//is package newer than current version?
if(version_compare($OnlineVersion, $CurrentVersion) == 1)
{
//is new package newer than another one found before?
if(version_compare($OnlineVersion, $NewerVersion) == 1)
{
$NewerVersion = $OnlineVersion;
}
}
}
if($NewerVersion != '')
{
//download package as an update
self::DownloadPackage($this->RootUrl . $Vendor . $Application . $NewerVersion, substr($Application, 0, -1), $NewerVersion);
continue;
}
}
else
{
if($Task['Task'] != TASK_SYSTEM_DOWNLOAD)continue;
//new packages
$NewVersion = '';
$Versions = self::FetchSubUrls($this->RootUrl . $Vendor . $Application);
foreach($Versions as $Version)
{
$OnlineVersion = substr($Version, 0, -1);
//is package newer than another one found before?
if(version_compare($OnlineVersion, $NewVersion) == 1)
{
$NewVersion = $OnlineVersion;
}
}
if($NewVersion != '')
{
//download package as a new one
self::DownloadPackage($this->RootUrl . $Vendor . $Application . $NewVersion, substr($Application, 0, -1), $NewVersion);
continue;
}
}
}
}
}
/**
* download a package from the distribution server and move the downloaded file in the temporary directory
*
* @param url url to download
* @param application string identifying the application name
* @param version string identifying the application version
* @return success true/error false
*/
private function DownloadPackage($Url, $Application, $Version)
{
$Downloads = self::FetchSubUrls($Url . '/');
//make url valid
$Url = str_replace(' ', '%20', $Url);
//get content from website url
$Content = @file_get_contents('http://' . $this->RequestDomain . $Url . '.aps' . $Downloads[0]);
if($Content != false)
{
//open file to write contents on disk
$FileHandle = fopen($this->RootDir . 'temp/' . $Application . '-' . $Version . '.app.zip', 'wb');
if($FileHandle == true)
{
//write results to disk
fwrite($FileHandle, $Content);
fclose($FileHandle);
//set right permissions
chmod($this->RootDir . 'temp/' . $Application . '-' . $Version . '.app.zip', 0664);
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
/**
* fetch html content of distribution server and parse all information
*
* @param requestdomain domain to aps-/mirrorserver with package api
* @param url url to fetch sub links from
* @return error false/success array with relative sub links
*/
private function FetchSubUrls($Url)
{
$Return = array();
//make url valid
$Url = str_replace(' ', '%20', $Url);
//get content from website url
$Content = @file('http://' . $this->RequestDomain . $Url);
if($Content != false)
{
foreach($Content as $Temp)
{
//skip empty lines
if($Temp != "\r\n"
&& $Temp != "\r"
&& $Temp != "\n"
&& $Temp != "")
{
//remove unwanted characters
$Temp = trim($Temp);
//grep URLs which match defined format
if(preg_match("/^<a href=\"(.+)\".+class=\"(vendor|application|version|packager)\"/", $Temp, $Matches))
{
if(!in_array(urldecode($Matches[1]), $Return))$Return[] = urldecode($Matches[1]);
}
}
}
return $Return;
}
else
{
return false;
}
}
}
?>

View File

@@ -0,0 +1,341 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: class.db.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Class to manage the connection to the Database
* @package Functions
*/
class db
{
/**
* Link ID for every connection
* @var int
*/
var $link_id = 0;
/**
* Query ID for every query
* @var int
*/
var $query_id = 0;
/**
* Errordescription, if an error occures
* @var string
*/
var $errdesc = '';
/**
* Errornumber, if an error occures
* @var int
*/
var $errno = 0;
/**
* Servername
* @var string
*/
var $server = '';
/**
* Username
* @var string
*/
var $user = '';
/**
* Password
* @var string
*/
var $password = '';
/**
* Database
* @var string
*/
var $database = '';
/**
* Class constructor. Connects to Databaseserver and selects Database
*
* @param string Servername
* @param string Username
* @param string Password
* @param string Database
*/
function db($server, $user, $password, $database = '')
{
// check for mysql extension
if(!extension_loaded('mysql'))
{
$this->showerror('You should install the PHP MySQL extension!', false);
}
$this->server = $server;
$this->user = $user;
$this->password = $password;
$this->database = $database;
$this->link_id = @mysql_connect($this->server, $this->user, $this->password);
if(!$this->link_id)
{
//try to connect with no password an change it afterwards. only for root user
if($this->user == 'root')
{
$this->link_id = @mysql_connect($this->server, $this->user, '');
if($this->link_id)
{
$this->query("SET PASSWORD = PASSWORD('" . $this->escape($this->password) . "')");
}
else
{
$this->showerror('Establishing connection failed, exiting');
}
}
else
{
$this->showerror('Establishing connection failed, exiting');
}
}
if($this->database != '')
{
if(!@mysql_select_db($this->database, $this->link_id))
{
$this->showerror('Trying to use database ' . $this->database . ' failed, exiting');
}
}
}
/**
* Closes connection to Databaseserver
*/
function close()
{
return @mysql_close($this->link_id);
}
/**
* Escapes user input to be used in mysql queries
*
* @param string $input
* @return string escaped string
*/
function escape($input)
{
if(is_int($input))
{
return (int)$input;
}
elseif(is_float($input))
{
return (float)$input;
}
else
{
return mysql_real_escape_string($input, $this->link_id);
}
}
/**
* Query the Database
*
* @param string Querystring
* @param bool Unbuffered query?
* @return string RessourceId
*/
function query($query_str, $unbuffered = false)
{
global $numbqueries;
if(!$unbuffered)
{
$this->query_id = mysql_query($query_str, $this->link_id);
}
else
{
$this->query_id = mysql_unbuffered_query($query_str, $this->link_id);
}
if(!$this->query_id)
{
$this->showerror('Invalid SQL: ' . $query_str);
}
$numbqueries++;
//echo $query_str.' '.$numbqueries.'<br />';
return $this->query_id;
}
/**
* Fetches Row from Query and returns it as array
*
* @param string RessourceId
* @param string Datatype, num or assoc
* @return array The row
*/
function fetch_array($query_id = - 1, $datatype = 'assoc')
{
if($query_id != - 1)
{
$this->query_id = $query_id;
}
if($datatype == 'num')
{
$datatype = MYSQL_NUM;
}
else
{
$datatype = MYSQL_ASSOC;
}
$this->record = mysql_fetch_array($this->query_id, $datatype);
return $this->record;
}
/**
* Query Database and fetche the first row from Query and returns it as array
*
* @param string Querystring
* @param string Datatype, num or assoc
* @return array The first row
*/
function query_first($query_string, $datatype = 'assoc')
{
$this->query($query_string);
return $this->fetch_array($this->query_id, $datatype);
}
/**
* Returns how many rows have been selected
*
* @param string RessourceId
* @return int Number of rows
*/
function num_rows($query_id = - 1)
{
if($query_id != - 1)
{
$this->query_id = $query_id;
}
return mysql_num_rows($this->query_id);
}
/**
* Returns the auto_incremental-Value of the inserted row
*
* @return int auto_incremental-Value
*/
function insert_id()
{
return mysql_insert_id($this->link_id);
}
/**
* Returns the number of rows affected by last query
*
* @return int affected rows
*/
function affected_rows()
{
return mysql_affected_rows($this->link_id);
}
/**
* Returns errordescription and errornumber if an error occured.
*
* @return int Errornumber
*/
function geterrdescno()
{
if($this->link_id != 0)
{
$this->errdesc = mysql_error($this->link_id);
$this->errno = mysql_errno($this->link_id);
}
else
{
// Maybe we don't have any linkid so let's try to catch at least anything
$this->errdesc = mysql_error();
$this->errno = mysql_errno();
}
return $this->errno;
}
/**
* Dies with an errormessage
*
* @param string Errormessage
*/
function showerror($errormsg, $mysqlActive = true)
{
global $filename;
if($mysqlActive)
{
$this->geterrdescno();
$errormsg.= "\n";
$errormsg.= 'mysql error number: ' . $this->errno . "\n";
$errormsg.= 'mysql error desc: ' . $this->errdesc . "\n";
}
$errormsg.= 'Time/date: ' . date('d/m/Y h:i A') . "\n";
if($filename != 'cronscript.php')
{
$errormsg.= 'Script: ' . htmlspecialchars(getenv('REQUEST_URI')) . "\n";
$errormsg.= 'Referer: ' . htmlspecialchars(getenv('HTTP_REFERER')) . "\n";
die(nl2br($errormsg));
}
else
{
$errormsg.= 'Script: -- Cronscript --' . "\n";
die($errormsg);
}
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,143 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Michael Duergner <michael@duergner.com>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: class.idna_convert_wrapper.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Class for wrapping a specific idna conversion class and offering a standard interface
* @package Functions
*/
class idna_convert_wrapper
{
/**
* idna converter we use
* @var object
*/
var $idna_converter;
/**
* Class constructor. Creates a new idna converter
*/
function idna_convert_wrapper()
{
$this->idna_converter = new idna_convert();
}
/**
* Encode a domain name, a email address or a list of one of both.
*
* @param string May be either a single domain name, e single email address or a list of one
* seperated either by ',', ';' or ' '.
*
* @return string Returns either a single domain name, a single email address or a list of one of
* both seperated by the same string as the input.
*/
function encode($to_encode)
{
return $this->_do_action('encode', $to_encode);
}
/**
* Decode a domain name, a email address or a list of one of both.
*
* @param string May be either a single domain name, e single email address or a list of one
* seperated either by ',', ';' or ' '.
*
* @return string Returns either a single domain name, a single email address or a list of one of
* both seperated by the same string as the input.
*/
function decode($to_decode)
{
return $this->_do_action('decode', $to_decode);
}
/**
* Do the real de- or encoding. First checks if a list is submitted and seperates it. Afterwards sends
* each entry to the idna converter to do the converting.
*
* @param string May be either 'decode' or 'encode'.
* @param string The string to de- or endcode.
*
* @return string The input string after being processed.
*/
function _do_action($action, $string)
{
$string = trim($string);
if(strpos($string, ',') !== false)
{
$strings = explode(',', $string);
$sepchar = ',';
}
elseif(strpos($string, ';') !== false)
{
$strings = explode(';', $string);
$sepchar = ';';
}
elseif(strpos($string, ' ') !== false)
{
$strings = explode(' ', $string);
$sepchar = ' ';
}
else
{
$strings = array(
$string
);
$sepchar = '';
}
for ($i = 0;$i < count($strings);$i++)
{
if(strpos($strings[$i], '@') !== false)
{
$split = explode('@', $strings[$i]);
$localpart = $split[0];
$domain = $split[1];
$email = true;
}
else
{
$domain = $strings[$i];
$email = false;
}
if(strlen($domain) !== 0)
{
$domain = utf8_decode($this->idna_converter->$action(utf8_encode($domain . '.none')));
$domain = substr($domain, 0, strlen($domain) - 5);
}
if($email)
{
$strings[$i] = $localpart . '@' . $domain;
}
else
{
$strings[$i] = $domain;
}
}
return implode($sepchar, $strings);
}
}
?>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,100 @@
<?php
/**
* Logger - Abstract-Logger-Class
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @license http://www.gnu.org/licenses/gpl.txt
* @package Functions
* @version CVS: $Id: abstract.AbstractLogger.php 2724 2009-06-07 14:18:02Z flo $
* @link http://www.nutime.de/
*/
/* We're using the syslog constants for all the loggers (partly implemented)
LOG_EMERG system is unusable
LOG_ALERT action must be taken immediately
LOG_CRIT critical conditions
LOG_ERR error conditions
LOG_WARNING warning conditions
LOG_NOTICE normal, but significant, condition
LOG_INFO informational message
LOG_DEBUG debug-level message
*/
abstract class AbstractLogger
{
/**
* Settings array
* @var settings
*/
private $settings = array();
/**
* Enable/Disable Logging
* @var logenabled
*/
private $logenabled = false;
/**
* Enable/Disable Cronjob-Logging
* @var logcronjob
*/
private $logcronjob = false;
/**
* Loggin-Severity
* @var severity
*/
private $severity = 1;
// normal
/**
* setup the main logger
*
* @param array settings
*/
protected function setupLogger($settings)
{
$this->settings = $settings;
$this->logenabled = $this->settings['logger']['enabled'];
$this->logcronjob = $this->settings['logger']['log_cron'];
$this->severity = $this->settings['logger']['severity'];
}
protected function isEnabled()
{
return $this->logenabled;
}
protected function getSeverity()
{
return $this->severity;
}
protected function logCron()
{
return $this->logcronjob;
}
abstract public function logAction();
}
?>

View File

@@ -0,0 +1,188 @@
<?php
/**
* Logger - File-Logger-Class
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @license http://www.gnu.org/licenses/gpl.txt
* @package Functions
* @version CVS: $Id: class.FileLogger.php 2724 2009-06-07 14:18:02Z flo $
* @link http://www.nutime.de/
*/
class FileLogger extends AbstractLogger
{
/**
* Userinfo
* @var array
*/
private $userinfo = array();
/**
* Logfile
* @var logfile
*/
private $logfile = null;
/**
* Syslogger Objects Array
* @var loggers
*/
static private $loggers = array();
/**
* Class constructor.
*
* @param array userinfo
* @param array settings
*/
protected function __construct($userinfo, $settings)
{
parent::setupLogger($settings);
$this->userinfo = $userinfo;
$this->setLogFile($settings['logger']['logfile']);
}
/**
* Singleton ftw ;-)
*
*/
static public function getInstanceOf($_usernfo, $_settings)
{
if(!isset(self::$loggers[$_usernfo['loginname']]))
{
self::$loggers[$_usernfo['loginname']] = new FileLogger($_usernfo, $_settings);
}
return self::$loggers[$_usernfo['loginname']];
}
public function logAction($action = USR_ACTION, $type = LOG_NOTICE, $text = null)
{
if(parent::isEnabled())
{
if(parent::getSeverity() <= 1
&& $type == LOG_NOTICE)
{
return;
}
$_action = 'unknown';
switch($action)
{
case USR_ACTION:
$_action = 'customer';
break;
case RES_ACTION:
$_action = 'reseller';
break;
case ADM_ACTION:
$_action = 'administrator';
break;
case CRON_ACTION:
$_action = 'cronjob';
break;
case LOG_ERROR:
$_action = 'internal';
break;
default:
$_action = 'unknown';
break;
}
$_type = 'unknown';
switch($type)
{
case LOG_INFO:
$_type = 'information';
break;
case LOG_NOTICE:
$_type = 'notice';
break;
case LOG_WARNING:
$_type = 'warning';
break;
case LOG_ERR:
$_type = 'error';
break;
case LOG_CRIT:
$_type = 'critical';
break;
default:
$_type = 'unknown';
break;
}
if(!isset($this->userinfo['loginname'])
|| $this->userinfo['loginname'] == '')
{
$name = 'unknown';
}
else
{
$name = " (" . $this->userinfo['loginname'] . ")";
}
$fp = @fopen($this->logfile, 'a');
if($fp !== false)
{
$now = time();
if($text != null
&& $text != '')
{
fwrite($fp, date("d.m.Y H:i:s", $now) . " [" . $_type . "] [" . $_action . "-action" . $name . "] " . $text . "\n");
}
else
{
fwrite($fp, date("d.m.Y H:i:s", $now) . " [" . $_type . "] [" . $_action . "-action" . $name . "] No text given!!! Check scripts!\n");
}
fclose($fp);
}
else
{
if($this->logfile != null
|| $this->logfile != '')
{
throw new Exception("Cannot open logfile '" . $this->logfile . "' for writing!");
}
}
}
}
private function setLogFile($filename = null)
{
if($filename != null
&& $filename != ''
&& $filename != "."
&& $filename != ".."
&& !is_dir($filename))
{
$this->logfile = $filename;
return true;
}
return false;
}
}
?>

View File

@@ -0,0 +1,113 @@
<?php
/**
* Logger - MySQL-Logger-Class
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @license http://www.gnu.org/licenses/gpl.txt
* @package Functions
* @version CVS: $Id: class.MysqlLogger.php 2724 2009-06-07 14:18:02Z flo $
* @link http://www.nutime.de/
*/
class MysqlLogger extends AbstractLogger
{
/**
* Userinfo
* @var array
*/
private $userinfo = array();
/**
* Database handler
* @var db
*/
private $db = false;
/**
* Syslogger Objects Array
* @var loggers
*/
static private $loggers = array();
/**
* Class constructor.
*
* @param array userinfo
* @param array settings
* @param resource database
*/
protected function __construct($userinfo, $settings, $db)
{
parent::setupLogger($settings);
$this->userinfo = $userinfo;
$this->db = $db;
}
/**
* Singleton ftw ;-)
*
*/
static public function getInstanceOf($_usernfo, $_settings, $_db)
{
if(!isset(self::$loggers[$_usernfo['loginname']]))
{
self::$loggers[$_usernfo['loginname']] = new MysqlLogger($_usernfo, $_settings, $_db);
}
return self::$loggers[$_usernfo['loginname']];
}
public function logAction($action = USR_ACTION, $type = LOG_NOTICE, $text = null)
{
if(parent::isEnabled())
{
if(parent::getSeverity() <= 1
&& $type == LOG_NOTICE)
{
return;
}
if(!isset($this->userinfo['loginname'])
|| $this->userinfo['loginname'] == '')
{
$name = 'unknown';
}
else
{
$name = " (" . $this->userinfo['loginname'] . ")";
}
$now = time();
if($text != null
&& $text != '')
{
$this->db->query("INSERT INTO `panel_syslog` (`type`, `date`, `action`, `user`, `text`)
VALUES ('" . (int)$type . "', '" . $now . "', '" . (int)$action . "', '" . $this->db->escape($name) . "', '" . $this->db->escape($text) . "')");
}
else
{
$this->db->query("INSERT INTO `panel_syslog` (`type`, `date`, `action`, `userid`, `text`)
VALUES ('" . (int)$type . "', '" . $now . "', '" . (int)$action . "', '" . $this->db->escape($name) . "', 'No text given!!! Check scripts!')");
}
}
}
}
?>

View File

@@ -0,0 +1,205 @@
<?php
/**
* Logger - SysCP-Logger Class
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @license http://www.gnu.org/licenses/gpl.txt
* @package Functions
* @version CVS: $Id: class.SysCPLogger.php 2724 2009-06-07 14:18:02Z flo $
* @link http://www.nutime.de/
*/
class SysCPLogger
{
/**
* Userinfo
* @var array
*/
private $userinfo = array();
/**
* Database handler
* @var db
*/
private $db = false;
/**
* Settings array
* @var settings
*/
private $settings = array();
/**
* LogTypes Array
* @var logtypes
*/
static private $logtypes = null;
/**
* Logger-Object-Array
* @var loggers
*/
static private $loggers = null;
/**
* Class constructor.
*
* @param array userinfo
* @param array settings
*/
protected function __construct($userinfo, $db, $settings)
{
$this->userinfo = $userinfo;
$this->db = $db;
$this->settings = $settings;
self::$logtypes = array();
if(!isset($this->settings['logger']['logtypes'])
&& (!isset($this->settings['logger']['logtypes']) || $this->settings['logger']['logtypes'] == '')
&& isset($this->settings['logger']['enabled'])
&& $this->settings['logger']['enabled'])
{
self::$logtypes[0] = 'syslog';
self::$logtypes[1] = 'mysql';
}
else
{
if(isset($this->settings['logger']['logtypes'])
&& $this->settings['logger']['logtypes'] != '')
{
self::$logtypes = explode(',', $this->settings['logger']['logtypes']);
}
else
{
self::$logtypes = null;
}
}
}
/**
* Singleton ftw ;-)
*
*/
static public function getInstanceOf($_usernfo, $_db, $_settings)
{
if(!isset($_usernfo)
|| $_usernfo == null)
{
$_usernfo = array();
$_usernfo['loginname'] = 'unknown';
}
if(!isset(self::$loggers[$_usernfo['loginname']]))
{
self::$loggers[$_usernfo['loginname']] = new SysCPLogger($_usernfo, $_db, $_settings);
}
return self::$loggers[$_usernfo['loginname']];
}
public function logAction($action = USR_ACTION, $type = LOG_NOTICE, $text = null)
{
if(self::$logtypes == null)
{
return;
}
if($this->settings['logger']['log_cron'] == '0'
&& $action == CRON_ACTION)
{
return;
}
foreach(self::$logtypes as $logger)
{
switch($logger)
{
case 'syslog':
$_log = SysLogger::getInstanceOf($this->userinfo, $this->settings);
break;
case 'file':
try
{
$_log = FileLogger::getInstanceOf($this->userinfo, $this->settings);
}
catch(Exception $e)
{
if($action != CRON_ACTION)
{
standard_error('logerror', $e->getMessage());
}
else
{
echo "Log-Error: " . $e->getMessage();
}
}
break;
case 'mysql':
$_log = MysqlLogger::getInstanceOf($this->userinfo, $this->settings, $this->db);
break;
default:
$_log = null;
break;
}
if($_log != null)
{
try
{
$_log->logAction($action, $type, $text);
}
catch(Exception $e)
{
if($action != CRON_ACTION)
{
standard_error('logerror', $e->getMessage());
}
else
{
echo "Log-Error: " . $e->getMessage();
}
}
}
}
}
public function setCronLog($_cronlog = 0)
{
$_cronlog = (int)$_cronlog;
if($_cronlog != 0
&& $_cronlog != 1)
{
$_cronlog = 0;
}
$this->db->query("UPDATE `" . TABLE_PANEL_SETTINGS . "`
SET `value`='" . $this->db->escape($_cronlog) . "'
WHERE `settinggroup`='logger'
AND `varname`='log_cron'");
return true;
}
}
?>

View File

@@ -0,0 +1,128 @@
<?php
/**
* Logger - SysLog-Logger-Class
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @license http://www.gnu.org/licenses/gpl.txt
* @package Functions
* @version CVS: $Id: class.SysLogger.php 2724 2009-06-07 14:18:02Z flo $
* @link http://www.nutime.de/
*/
class SysLogger extends AbstractLogger
{
/**
* Userinfo
* @var array
*/
private $userinfo = array();
/**
* Syslogger Objects Array
* @var loggers
*/
static private $loggers = array();
/**
* Class constructor.
*
* @param array userinfo
* @param array settings
*/
protected function __construct($userinfo, $settings)
{
parent::setupLogger($settings);
$this->userinfo = $userinfo;
}
/**
* Singleton ftw ;-)
*
*/
static public function getInstanceOf($_usernfo, $_settings)
{
if(!isset(self::$loggers[$_usernfo['loginname']]))
{
self::$loggers[$_usernfo['loginname']] = new SysLogger($_usernfo, $_settings);
}
return self::$loggers[$_usernfo['loginname']];
}
public function logAction($action = USR_ACTION, $type = LOG_NOTICE, $text = null)
{
if(parent::isEnabled())
{
if(parent::getSeverity() <= 1
&& $type == LOG_NOTICE)
{
return;
}
$_action = 'unknown';
switch($action)
{
case USR_ACTION:
$_action = 'customer';
break;
case RES_ACTION:
$_action = 'reseller';
break;
case ADM_ACTION:
$_action = 'administrator';
break;
case CRON_ACTION:
$_action = 'cronjob';
break;
case LOG_ERROR:
$_action = 'internal';
break;
default:
$_action = 'unknown';
break;
}
if(!isset($this->userinfo['loginname'])
|| $this->userinfo['loginname'] == '')
{
$name = 'unknown';
}
else
{
$name = " (" . $this->userinfo['loginname'] . ")";
}
openlog("SysCP", LOG_NDELAY, LOG_USER);
if($text != null
&& $text != '')
{
syslog((int)$type, "[" . ucfirst($_action) . " Action" . $name . "] " . $text);
}
else
{
syslog((int)$type, "[" . ucfirst($_action) . " Action" . $name . "] No text given!!! Check scripts!");
}
closelog();
}
}
}
?>

View File

@@ -0,0 +1,518 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: class.paging.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Class to manage paging system
* @package Functions
*/
class paging
{
/**
* Userinfo
* @var array
*/
var $userinfo = array();
/**
* Database handler
* @var db
*/
var $db = false;
/**
* MySQL-Table
* @var string
*/
var $table = '';
/**
* Fields with description which should be selectable
* @var array
*/
var $fields = array();
/**
* Entries per page
* @var int
*/
var $entriesperpage = 0;
/**
* Number of entries of table
* @var int
*/
var $entries = 0;
/**
* Sortorder, asc or desc
* @var string
*/
var $sortorder = 'asc';
/**
* Sortfield
* @var string
*/
var $sortfield = '';
/**
* Searchfield
* @var string
*/
var $searchfield = '';
/**
* Searchtext
* @var string
*/
var $searchtext = '';
/**
* Pagenumber
* @var int
*/
var $pageno = 0;
/**
* Switch natsorting on/off
* @var bool
*/
var $natSorting = false;
/**
* Class constructor. Loads settings from request or from userdata and saves them to session.
*
* @param array userinfo
* @param string Name of Table
* @param array Fields, in format array( 'fieldname_in_mysql' => 'field_caption' )
* @param int entries per page
* @param bool Switch natsorting on/off (global, affects all calls of sort)
*/
function paging($userinfo, $db, $table, $fields, $entriesperpage, $natSorting = false)
{
$this->userinfo = $userinfo;
if(!is_array($this->userinfo['lastpaging']))
{
$this->userinfo['lastpaging'] = unserialize($this->userinfo['lastpaging']);
}
$this->db = $db;
$this->table = $table;
$this->fields = $fields;
$this->entriesperpage = $entriesperpage;
$this->natSorting = $natSorting;
$checklastpaging = (isset($this->userinfo['lastpaging']['table']) && $this->userinfo['lastpaging']['table'] == $this->table);
$this->userinfo['lastpaging']['table'] = $this->table;
if(isset($_REQUEST['sortorder'])
&& (strtolower($_REQUEST['sortorder']) == 'desc' || strtolower($_REQUEST['sortorder']) == 'asc'))
{
$this->sortorder = strtolower($_REQUEST['sortorder']);
}
else
{
if($checklastpaging
&& isset($this->userinfo['lastpaging']['sortorder'])
&& (strtolower($this->userinfo['lastpaging']['sortorder']) == 'desc' || strtolower($this->userinfo['lastpaging']['sortorder']) == 'asc'))
{
$this->sortorder = strtolower($this->userinfo['lastpaging']['sortorder']);
}
else
{
$this->sortorder = 'asc';
}
}
$this->userinfo['lastpaging']['sortorder'] = $this->sortorder;
if(isset($_REQUEST['sortfield'])
&& isset($fields[$_REQUEST['sortfield']]))
{
$this->sortfield = $_REQUEST['sortfield'];
}
else
{
if($checklastpaging
&& isset($this->userinfo['lastpaging']['sortfield'])
&& isset($fields[$this->userinfo['lastpaging']['sortfield']]))
{
$this->sortfield = $this->userinfo['lastpaging']['sortfield'];
}
else
{
$fieldnames = array_keys($fields);
$this->sortfield = $fieldnames[0];
}
}
$this->userinfo['lastpaging']['sortfield'] = $this->sortfield;
if(isset($_REQUEST['searchfield'])
&& isset($fields[$_REQUEST['searchfield']]))
{
$this->searchfield = $_REQUEST['searchfield'];
}
else
{
if($checklastpaging
&& isset($this->userinfo['lastpaging']['searchfield'])
&& isset($fields[$this->userinfo['lastpaging']['searchfield']]))
{
$this->searchfield = $this->userinfo['lastpaging']['searchfield'];
}
else
{
$fieldnames = array_keys($fields);
$this->searchfield = $fieldnames[0];
}
}
$this->userinfo['lastpaging']['searchfield'] = $this->searchfield;
if(isset($_REQUEST['searchtext'])
&& (preg_match("/^[@0-9a-zA-Z<><5A><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\-\*\.]+$/", $_REQUEST['searchtext']) || $_REQUEST['searchtext'] === ''))
{
$this->searchtext = $_REQUEST['searchtext'];
}
else
{
if($checklastpaging
&& isset($this->userinfo['lastpaging']['searchtext'])
&& preg_match("/^[@0-9a-zA-Z<><5A><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\-\*\.]+$/", $this->userinfo['lastpaging']['searchtext']))
{
$this->searchtext = $this->userinfo['lastpaging']['searchtext'];
}
else
{
$this->searchtext = '';
}
}
$this->userinfo['lastpaging']['searchtext'] = $this->searchtext;
if(isset($_REQUEST['pageno'])
&& intval($_REQUEST['pageno']) != 0)
{
$this->pageno = intval($_REQUEST['pageno']);
}
else
{
if($checklastpaging
&& isset($this->userinfo['lastpaging']['pageno'])
&& intval($this->userinfo['lastpaging']['pageno']) != 0)
{
$this->pageno = intval($this->userinfo['lastpaging']['pageno']);
}
else
{
$this->pageno = 1;
}
}
$this->userinfo['lastpaging']['pageno'] = $this->pageno;
$query = 'UPDATE `' . TABLE_PANEL_SESSIONS . '` SET `lastpaging`="' . $this->db->escape(serialize($this->userinfo['lastpaging'])) . '" WHERE `hash`="' . $this->db->escape($userinfo['hash']) . '" AND `userid` = "' . $this->db->escape($userinfo['userid']) . '" AND `ipaddress` = "' . $this->db->escape($userinfo['ipaddress']) . '" AND `useragent` = "' . $this->db->escape($userinfo['useragent']) . '" AND `adminsession` = "' . $this->db->escape($userinfo['adminsession']) . '" ';
$this->db->query($query);
}
/**
* Sets number of entries and adjusts pageno if the number of entries doesn't correspond to the pageno.
*
* @param int entries
*/
function setEntries($entries)
{
$this->entries = $entries;
if(($this->pageno - 1) * $this->entriesperpage > $this->entries)
{
$this->pageno = 1;
}
return true;
}
/**
* Checks if a row should be displayed or not, used in loops
*
* @param int number of row
* @return bool to display or not to display, that's the question
*/
function checkDisplay($count)
{
$begin = (intval($this->pageno) - 1) * intval($this->entriesperpage);
$end = (intval($this->pageno) * intval($this->entriesperpage));
return (($count >= $begin && $count < $end) || $this->entriesperpage == 0);
}
/**
* Returns condition code for sql query
*
* @param bool should returned condition code start with WHERE (false) or AND (true)?
* @return string the condition code
*/
function getSqlWhere($append = false)
{
if($this->searchtext != '')
{
if($append == true)
{
$condition = ' AND ';
}
else
{
$condition = ' WHERE ';
}
$searchfield = explode('.', $this->searchfield);
foreach($searchfield as $id => $field)
{
if(substr($field, -1, 1) != '`')
{
$field.= '`';
}
if($field{0} != '`')
{
$field = '`' . $field;
}
$searchfield[$id] = $field;
}
$searchfield = implode('.', $searchfield);
$searchtext = str_replace('*', '%', $this->searchtext);
$condition.= $searchfield . ' LIKE "' . $this->db->escape($searchtext) . '" ';
}
else
{
$condition = '';
}
return $condition;
}
/**
* Returns "order by"-code for sql query
*
* @param bool Switch natsorting on/off (local, affects just this call)
* @return string the "order by"-code
*/
function getSqlOrderBy($natSorting = null)
{
$sortfield = explode('.', $this->sortfield);
foreach($sortfield as $id => $field)
{
if(substr($field, -1, 1) != '`')
{
$field.= '`';
}
if($field{0} != '`')
{
$field = '`' . $field;
}
$sortfield[$id] = $field;
}
$sortfield = implode('.', $sortfield);
$sortorder = strtoupper($this->sortorder);
if($natSorting == true
|| ($natSorting === null && $this->natSorting == true))
{
// Acts similar to php's natsort(), found in one comment at http://my.opera.com/cpr/blog/show.dml/160556
$sortcode = 'ORDER BY CONCAT( IF( ASCII( LEFT( ' . $sortfield . ', 1 ) ) > 57, LEFT( ' . $sortfield . ', 1 ), \'0\' ), IF( ASCII( RIGHT( ' . $sortfield . ', 1 ) ) > 57, LPAD( ' . $sortfield . ', 255, \'0\' ), LPAD( CONCAT( ' . $sortfield . ', \'-\' ), 255, \'0\' ) ) ) ' . $sortorder;
}
else
{
$sortcode = 'ORDER BY ' . $sortfield . ' ' . $sortorder;
}
return $sortcode;
}
/**
* Currently not used
*
* @return string always empty
*/
function getSqlLimit()
{
/**
* currently not in use
*/
return '';
}
/**
* Returns html code for sorting field
*
* @param array Language array
* @return string the html sortcode
*/
function getHtmlSortCode($lng, $break = false)
{
$sortcode = '<select class="dropdown_noborder" name="sortfield">';
foreach($this->fields as $fieldname => $fieldcaption)
{
$sortcode.= makeoption($fieldcaption, $fieldname, $this->sortfield, true, true);
}
$sortcode.= '</select>' . ($break ? '<br />' : '&nbsp;') . '<select class="dropdown_noborder" name="sortorder">';
foreach(array('asc' => $lng['panel']['ascending'], 'desc' => $lng['panel']['decending']) as $sortordertype => $sortorderdescription)
{
$sortcode.= makeoption($sortorderdescription, $sortordertype, $this->sortorder, true, true);
}
$sortcode.= '</select>&nbsp;<input type="submit" name="Go" value="Go" />';
return $sortcode;
}
/**
* Returns html code for sorting arrows
*
* @param string URL to use as base for links
* @param string If set, only this field will be returned
* @return mixed An array or a string (if field is set) of html code of arrows
*/
function getHtmlArrowCode($baseurl, $field = '')
{
if($field != ''
&& isset($this->fields[$field]))
{
$arrowcode = '<a href="' . htmlspecialchars($baseurl) . '&amp;sortfield=' . htmlspecialchars($field) . '&amp;sortorder=desc"><img src="images/order_desc.gif" border="0" alt="" /></a><a href="' . htmlspecialchars($baseurl) . '&amp;sortfield=' . htmlspecialchars($field) . '&amp;sortorder=asc"><img src="images/order_asc.gif" border="0" alt="" /></a>';
}
else
{
$arrowcode = array();
foreach($this->fields as $fieldname => $fieldcaption)
{
$arrowcode[$fieldname] = '<a href="' . htmlspecialchars($baseurl) . '&amp;sortfield=' . htmlspecialchars($fieldname) . '&amp;sortorder=desc"><img src="images/order_desc.gif" border="0" alt="" /></a><a href="' . htmlspecialchars($baseurl) . '&amp;sortfield=' . htmlspecialchars($fieldname) . '&amp;sortorder=asc"><img src="images/order_asc.gif" border="0" alt="" /></a>';
}
}
return $arrowcode;
}
/**
* Returns html code for searching field
*
* @param array Language array
* @return string the html searchcode
*/
function getHtmlSearchCode($lng)
{
$sortcode = $lng['panel']['search'] . ': <select class="dropdown_noborder" name="searchfield">';
foreach($this->fields as $fieldname => $fieldcaption)
{
$sortcode.= makeoption($fieldcaption, $fieldname, $this->searchfield, true, true);
}
$sortcode.= '</select>&nbsp;<input type="text" name="searchtext" value="' . htmlspecialchars($this->searchtext) . '" />&nbsp;<input type="submit" name="Go" value="Go" />';
return $sortcode;
}
/**
* Returns html code for paging
*
* @param string URL to use as base for links
* @return string the html pagingcode
*/
function getHtmlPagingCode($baseurl)
{
if($this->entriesperpage == 0)
{
return '';
}
else
{
$pages = intval($this->entries / $this->entriesperpage);
}
if($this->entries % $this->entriesperpage != 0)
{
$pages++;
}
if($pages > 1)
{
$start = $this->pageno - 4;
if($start < 1)
{
$start = 1;
}
$stop = $this->pageno + 4;
if($stop > $pages)
{
$stop = $pages;
}
$pagingcode = '<a href="' . htmlspecialchars($baseurl) . '&amp;pageno=1">&laquo;</a> <a href="' . htmlspecialchars($baseurl) . '&amp;pageno=' . ((intval($this->pageno) - 1) == 0 ? '1' : intval($this->pageno) - 1) . '">&lt;</a> ';
for ($i = $start;$i <= $stop;$i++)
{
if($i != $this->pageno)
{
$pagingcode.= ' <a href="' . htmlspecialchars($baseurl) . '&amp;pageno=' . $i . '">' . $i . '</a> ';
}
else
{
$pagingcode.= ' <b>' . $i . '</b> ';
}
}
$pagingcode.= ' <a href="' . htmlspecialchars($baseurl) . '&amp;pageno=' . ((intval($this->pageno) + 1) > $pages ? $pages : intval($this->pageno) + 1) . '">&gt;</a> <a href="' . $baseurl . '&amp;pageno=' . $pages . '">&raquo;</a>';
}
else
{
$pagingcode = '';
}
return $pagingcode;
}
}
?>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,663 @@
<?php
/**
* Support-Tickets - Ticket-Class
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* @copyright (c) the authors
* @author Michael Kaufmann <mkaufmann@nutime.de>
* @license http://www.gnu.org/licenses/gpl.txt
* @package Functions
* @version CVS: $Id: class.ticket.php 2724 2009-06-07 14:18:02Z flo $
* @link http://www.nutime.de/
* @since File available since Release 1.2.18
*/
class ticket
{
/**
* Userinfo
* @var array
*/
private $userinfo = array();
/**
* Database handler
* @var db
*/
private $db = false;
/**
* Settings array
* @var settings
*/
private $settings = array();
/**
* Ticket ID
* @var tid
*/
private $tid = - 1;
/**
* Ticket Data Array
* @var t_data
*/
private $t_data = array();
/**
* Ticket-Object-Array
* @var tickets
*/
static private $tickets = array();
/**
* Class constructor.
*
* @param array userinfo
* @param resource database
* @param array settings
* @param int ticket id
*/
private function __construct($userinfo, $db, $settings, $tid = - 1)
{
$this->userinfo = $userinfo;
$this->db = $db;
$this->settings = $settings;
$this->tid = $tid;
// initialize data array
$this->initData();
// read data from database
$this->readData();
}
/**
* Singleton ftw ;-)
*
* @param int ticket id
*/
static public function getInstanceOf($_usernfo, $_db, $_settings, $_tid)
{
if(!isset(self::$tickets[$_tid]))
{
self::$tickets[$_tid] = new ticket($_usernfo, $_db, $_settings, $_tid);
}
return self::$tickets[$_tid];
}
/**
* Initialize data-array
*/
private function initData()
{
$this->Set('customer', 0, true, true);
$this->Set('admin', 1, true, true);
$this->Set('subject', '', true, true);
$this->Set('category', '0', true, true);
$this->Set('priority', '2', true, true);
$this->Set('message', '', true, true);
$this->Set('dt', 0, true, true);
$this->Set('lastchange', 0, true, true);
$this->Set('ip', '', true, true);
$this->Set('status', '0', true, true);
$this->Set('lastreplier', '0', true, true);
$this->Set('by', '0', true, true);
$this->Set('answerto', '0', true, true);
$this->Set('archived', '0', true, true);
}
/**
* Read ticket data from database.
*/
private function readData()
{
if(isset($this->tid)
&& $this->tid != - 1)
{
$_ticket = $this->db->query_first('SELECT * FROM `' . TABLE_PANEL_TICKETS . '` WHERE `id` = "' . $this->tid . '"');
$this->Set('customer', $_ticket['customerid'], true, false);
$this->Set('admin', $_ticket['adminid'], true, false);
$this->Set('subject', $_ticket['subject'], true, false);
$this->Set('category', $_ticket['category'], true, false);
$this->Set('priority', $_ticket['priority'], true, false);
$this->Set('message', $_ticket['message'], true, false);
$this->Set('dt', $_ticket['dt'], true, false);
$this->Set('lastchange', $_ticket['lastchange'], true, false);
$this->Set('ip', $_ticket['ip'], true, false);
$this->Set('status', $_ticket['status'], true, false);
$this->Set('lastreplier', $_ticket['lastreplier'], true, false);
$this->Set('by', $_ticket['by'], true, false);
$this->Set('answerto', $_ticket['answerto'], true, false);
$this->Set('archived', $_ticket['archived'], true, false);
}
}
/**
* Insert data to database
*/
public function Insert()
{
$this->db->query("INSERT INTO `" . TABLE_PANEL_TICKETS . "`
(`customerid`,
`adminid`,
`category`,
`priority`,
`subject`,
`message`,
`dt`,
`lastchange`,
`ip`,
`status`,
`lastreplier`,
`by`,
`answerto`)
VALUES
('" . (int)$this->Get('customer') . "',
'" . (int)$this->Get('admin') . "',
'" . (int)$this->Get('category') . "',
'" . (int)$this->Get('priority') . "',
'" . $this->db->escape($this->Get('subject')) . "',
'" . $this->db->escape($this->Get('message')) . "',
'" . (int)$this->Get('dt') . "',
'" . (int)$this->Get('lastchange') . "',
'" . $this->db->escape($this->Get('ip')) . "',
'" . (int)$this->Get('status') . "',
'" . (int)$this->Get('lastreplier') . "',
'" . (int)$this->Get('by') . "',
'" . (int)$this->Get('answerto') . "');");
$this->tid = $this->db->insert_id();
return true;
}
/**
* Update data in database
*/
public function Update()
{
// Update "main" ticket
$this->db->query('UPDATE `' . TABLE_PANEL_TICKETS . '` SET
`priority` = "' . (int)$this->Get('priority') . '",
`lastchange` = "' . (int)$this->Get('lastchange') . '",
`status` = "' . (int)$this->Get('status') . '",
`lastreplier` = "' . (int)$this->Get('lastreplier') . '"
WHERE `id` = "' . (int)$this->tid . '";');
return true;
}
/**
* Moves a ticket to the archive
*/
public function Archive()
{
// Update "main" ticket
$this->db->query('UPDATE `' . TABLE_PANEL_TICKETS . '` SET `archived` = "1" WHERE `id` = "' . (int)$this->tid . '";');
// Update "answers" to ticket
$this->db->query('UPDATE `' . TABLE_PANEL_TICKETS . '` SET `archived` = "1" WHERE `answerto` = "' . (int)$this->tid . '";');
return true;
}
/**
* Remove ticket from database
*/
public function Delete()
{
// Delete "main" ticket
$this->db->query('DELETE FROM `' . TABLE_PANEL_TICKETS . '` WHERE `id` = "' . (int)$this->tid . '";');
// Delete "answers" to ticket"
$this->db->query('DELETE FROM `' . TABLE_PANEL_TICKETS . '` WHERE `answerto` = "' . (int)$this->tid . '";');
return true;
}
/**
* Mail notifications
*/
public function sendMail($customerid = - 1, $template_subject = null, $default_subject = null, $template_body = null, $default_body = null)
{
global $mail;
// Some checks are to be made here in the future
if($customerid != - 1)
{
// Get e-mail message for customer
$usr = $this->db->query_first('SELECT `name`, `firstname`, `email`
FROM `' . TABLE_PANEL_CUSTOMERS . '`
WHERE `customerid` = "' . (int)$customerid . '"');
$replace_arr = array(
'FIRSTNAME' => $usr['firstname'],
'NAME' => $usr['name'],
'SUBJECT' => $this->Get('subject', true)
);
}
else
{
$replace_arr = array(
'SUBJECT' => $this->Get('subject', true)
);
}
$result = $this->db->query_first('SELECT `value` FROM `' . TABLE_PANEL_TEMPLATES . '`
WHERE `adminid`=\'' . (int)$this->userinfo['adminid'] . '\'
AND `language`=\'' . $this->db->escape($this->userinfo['def_language']) . '\'
AND `templategroup`=\'mails\'
AND `varname`=\'' . $template_subject . '\'');
$mail_subject = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $default_subject), $replace_arr));
$result = $this->db->query_first('SELECT `value` FROM `' . TABLE_PANEL_TEMPLATES . '`
WHERE `adminid`=\'' . (int)$this->userinfo['adminid'] . '\'
AND `language`=\'' . $this->db->escape($this->userinfo['def_language']) . '\'
AND `templategroup`=\'mails\'
AND `varname`=\'' . $template_body . '\'');
$mail_body = html_entity_decode(replace_variables((($result['value'] != '') ? $result['value'] : $default_body), $replace_arr));
if($customerid != - 1)
{
$mail->From = $this->settings['ticket']['noreply_email'];
$mail->FromName = $this->settings['ticket']['noreply_name'];
$mail->Subject = $mail_subject;
$mail->Body = $mail_body;
$mail->AddAddress($usr['email'], $usr['firstname'] . ' ' . $usr['name']);
if(!$mail->Send())
{
standard_error(array('errorsendingmail', $usr['email']));
}
$mail->ClearAddresses();
}
else
{
$admin = $this->db->query_first("SELECT `email` FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid`='" . (int)$this->userinfo['adminid'] . "'");
$mail->From = $this->settings['ticket']['noreply_email'];
$mail->FromName = $this->settings['ticket']['noreply_name'];
$mail->Subject = $mail_subject;
$mail->Body = $mail_body;
$mail->AddAddress($admin['email'], $admin['firstname'] . ' ' . $admin['name']);
if(!$mail->Send())
{
standard_error(array('errorsendingmail', $admin['email']));
}
$mail->ClearAddresses();
}
}
/**
* Add a support-categories
*/
static public function addCategory($_db, $_category = null, $_admin = 1)
{
if($_category != null
&& $_category != '')
{
$_db->query('INSERT INTO `' . TABLE_PANEL_TICKET_CATS . '` (`name`, `adminid`) VALUES ("' . $_db->escape($_category) . '", "' . (int)$_admin . '")');
return true;
}
return false;
}
/**
* Edit a support-categories
*/
static public function editCategory($_db, $_category = null, $_id = 0)
{
if($_category != null
&& $_category != ''
&& $_id != 0)
{
$_db->query('UPDATE `' . TABLE_PANEL_TICKET_CATS . '` SET `name` = "' . $_db->escape($_category) . '"
WHERE `id` = "' . (int)$_id . '"');
return true;
}
return false;
}
/**
* Delete a support-categories
*/
static public function deleteCategory($_db, $_id = 0)
{
if($_id != 0)
{
$result = $_db->query_first('SELECT COUNT(`id`) as `numtickets` FROM `' . TABLE_PANEL_TICKETS . '`
WHERE `category` = "' . (int)$_id . '"');
if($result['numtickets'] == "0")
{
$_db->query('DELETE FROM `' . TABLE_PANEL_TICKET_CATS . '` WHERE `id` = "' . (int)$_id . '"');
return true;
}
else
{
return false;
}
}
return false;
}
/**
* Return a support-category-name
*/
static public function getCategoryName($_db, $_id = 0)
{
if($_id != 0)
{
$category = $_db->query_first('SELECT `name` FROM `' . TABLE_PANEL_TICKET_CATS . '` WHERE `id` = "' . (int)$_id . '"');
return $category['name'];
}
return null;
}
/**
* returns the last x archived tickets
*/
static public function getLastArchived($_db, $_num = 10, $_admin = 1)
{
if($_num > 0)
{
$archived = array();
$counter = 0;
$result = $_db->query('SELECT *,
(SELECT COUNT(`sub`.`id`)
FROM `' . TABLE_PANEL_TICKETS . '` `sub`
WHERE `sub`.`answerto` = `main`.`id`) as `ticket_answers`
FROM `' . TABLE_PANEL_TICKETS . '` `main`
WHERE `main`.`answerto` = "0"
AND `main`.`archived` = "1" AND `main`.`adminid` = "' . (int)$_admin . '"
ORDER BY `main`.`lastchange` DESC LIMIT 0, ' . (int)$_num);
while($row = $_db->fetch_array($result))
{
$archived[$counter]['id'] = $row['id'];
$archived[$counter]['customerid'] = $row['customerid'];
$archived[$counter]['adminid'] = $row['adminid'];
$archived[$counter]['lastreplier'] = $row['lastreplier'];
$archived[$counter]['ticket_answers'] = $row['ticket_answers'];
$archived[$counter]['category'] = $row['category'];
$archived[$counter]['priority'] = $row['priority'];
$archived[$counter]['subject'] = $row['subject'];
$archived[$counter]['message'] = $row['message'];
$archived[$counter]['dt'] = $row['dt'];
$archived[$counter]['lastchange'] = $row['lastchange'];
$archived[$counter]['status'] = $row['status'];
$archived[$counter]['by'] = $row['by'];
$counter++;
}
if(isset($archived[0]['id']))
{
return $archived;
}
else
{
return false;
}
}
}
/**
* Returns a sql-statement to search the archive
*/
static public function getArchiveSearchStatement($subject = NULL, $priority = NULL, $fromdate = NULL, $todate = NULL, $message = NULL, $customer = - 1, $admin = 1, $categories = NULL)
{
$query = 'SELECT `main`.*,
(SELECT COUNT(`sub`.`id`) FROM `' . TABLE_PANEL_TICKETS . '` `sub`
WHERE `sub`.`answerto` = `main`.`id`) as `ticket_answers`
FROM `' . TABLE_PANEL_TICKETS . '` `main`
WHERE `main`.`archived` = "1" AND `main`.`answerto` = "0" AND `main`.`adminid` = "' . (int)$admin . '"';
if($subject != NULL
&& $subject != '')
{
$query.= 'AND `main`.`subject` LIKE "%' . $subject . '%" ';
}
if($priority != NULL
&& isset($priority[0])
&& $priority[0] != '')
{
if(isset($priority[1])
&& $priority[1] != '')
{
if(isset($priority[2])
&& $priority[2] != '')
{
$query.= 'AND (`main`.`priority` = "1"
OR `main`.`priority` = "2"
OR `main`.`priority` = "3") ';
}
else
{
$query.= 'AND (`main`.`priority` = "1"
OR `main`.`priority` = "2") ';
}
}
elseif(isset($priority[2])
&& $priority[2] != '')
{
$query.= 'AND (`main`.`priority` = "1"
OR `main`.`priority` = "3") ';
}
else
{
$query.= 'AND `main`.`priority` = "1" ';
}
}
elseif($priority != NULL
&& isset($priority[1])
&& $priority[1] != '')
{
if(isset($priority[2])
&& $priority[2] != '')
{
$query.= 'AND (`main`.`priority` = "2"
OR `main`.`priority` = "3") ';
}
else
{
$query.= 'AND `main`.`priority` = "2" ';
}
}
elseif($priority != NULL)
{
if(isset($priority[3])
&& $priority[3] != '')
{
$query.= 'AND `main`.`priority` = "3" ';
}
}
if($fromdate != NULL
&& $fromdate > 0)
{
$query.= 'AND `main`.`lastchange` > "' . $fromdate . '" ';
}
if($todate != NULL
&& $todate > 0)
{
$query.= 'AND `main`.`lastchange` < "' . $todate . '" ';
}
if($message != NULL
&& $message != '')
{
$query.= 'AND `main`.`message` LIKE "%' . $message . '%" ';
}
if($customer != - 1)
{
$query.= 'AND `main`.`customerid` = "' . $customer . '" ';
}
if($categories != NULL)
{
if($categories[0] != '')
{
$query.= 'AND (';
}
foreach($categories as $catid)
{
if(isset($catid)
&& $catid > 0)
{
$query.= '`main`.`category` = "' . $catid . '" OR ';
}
}
if($categories[0] != '')
{
$query = substr($query, 0, strlen($query) - 3);
$query.= ') ';
}
}
return $query;
}
/**
* Get statustext by status-no
*/
static public function getStatusText($_lng, $_status = 0)
{
switch($_status)
{
case 0:
return $_lng['ticket']['open'];
break;
case 1:
return $_lng['ticket']['wait_reply'];
break;
case 2:
return $_lng['ticket']['replied'];
break;
default:
return $_lng['ticket']['closed'];
break;
}
}
/**
* Get prioritytext by priority-no
*/
static public function getPriorityText($_lng, $_priority = 0)
{
switch($_priority)
{
case 1:
return $_lng['ticket']['high'];
break;
case 2:
return $_lng['ticket']['normal'];
break;
default:
return $_lng['ticket']['low'];
break;
}
}
/**
* Get a data-var
*/
public function Get($_var = '', $_vartrusted = false)
{
if($_var != '')
{
if(!$_vartrusted)
{
$_var = htmlspecialchars($_var);
}
if(isset($this->t_data[$_var]))
{
if(strtolower($_var) == 'message')
{
return htmlspecialchars_decode(nl2br($this->t_data[$_var]));
}
else
{
return $this->t_data[$_var];
}
}
else
{
return null;
}
}
}
/**
* Set a data-var
*/
public function Set($_var = '', $_value = '', $_vartrusted = false, $_valuetrusted = false)
{
if($_var != ''
&& $_value != '')
{
if(!$_vartrusted)
{
$_var = htmlspecialchars($_var);
}
if(!$_valuetrusted)
{
$_value = htmlspecialchars($_value);
}
$this->t_data[$_var] = $_value;
}
}
}
?>

View File

@@ -0,0 +1,267 @@
<?php
return Array(
'debian_etch' => Array(
'label' => 'Debian 4.0 (Etch)',
'services' => Array(
'http' => Array(
'label' => $lng['admin']['configfiles']['http'],
'daemons' => Array(
'apache2' => Array(
'label' => 'Apache 2',
'commands' => Array(
'mkdir -p ' . $settings['system']['documentroot_prefix'],
'mkdir -p ' . $settings['system']['logfiles_directory'],
'mkdir -p ' . $settings['system']['mod_fcgid_tmpdir'],
'chmod 1777 ' . $settings['system']['mod_fcgid_tmpdir'],
'a2dismod userdir',
),
'restart' => Array(
'/etc/init.d/apache2 restart'
),
),
'lighttpd' => Array(
'label' => 'Lighttpd Webserver',
'commands_1' => Array(
'apt-get install lighttpd',
),
'files' => Array(
'etc_lighttpd.conf' => '/etc/lighttpd/lighttpd.conf',
),
'commands_2' => Array(
$configcommand['vhost'],
$configcommand['diroptions'],
$configcommand['v_inclighty'],
$configcommand['d_inclighty'],
'mkdir -p ' . $settings['system']['documentroot_prefix'],
'mkdir -p ' . $settings['system']['logfiles_directory'],
'mkdir -p ' . $settings['system']['mod_fcgid_tmpdir'],
'chmod 1777 ' . $settings['system']['mod_fcgid_tmpdir'],
),
'restart' => Array(
'/etc/init.d/lighttpd restart'
)
)
)
),
'dns' => Array(
'label' => $lng['admin']['configfiles']['dns'],
'daemons' => Array(
'bind' => Array(
'label' => 'Bind9',
'commands' => Array(
'apt-get install bind9',
'echo "include \"' . $settings['system']['bindconf_directory'] . 'syscp_bind.conf\";" >> /etc/bind/named.conf',
'touch ' . $settings['system']['bindconf_directory'] . 'syscp_bind.conf'
),
'restart' => Array(
'/etc/init.d/bind9 restart'
)
),
'powerdns' => Array(
'label' => 'PowerDNS',
'files' => Array(
'etc_powerdns_pdns.conf' => '/etc/powerdns/pdns.conf',
'etc_powerdns_pdns-syscp.conf' => '/etc/powerdns/pdns_syscp.conf',
),
'restart' => Array(
'/etc/init.d/pdns restart'
)
),
)
),
'smtp' => Array(
'label' => $lng['admin']['configfiles']['smtp'],
'daemons' => Array(
'postfix' => Array(
'label' => 'Postfix',
'commands' => Array(
'apt-get install postfix postfix-mysql libsasl2 libsasl2-modules libsasl2-modules-sql',
'mkdir -p /etc/postfix/sasl',
'mkdir -p /var/spool/postfix/etc/pam.d',
'mkdir -p /var/spool/postfix/var/run/mysqld',
'groupadd -g ' . $settings['system']['vmail_gid'] . ' vmail',
'useradd -u ' . $settings['system']['vmail_uid'] . ' -g vmail vmail',
'mkdir -p ' . $settings['system']['vmail_homedir'],
'chown -R vmail:vmail ' . $settings['system']['vmail_homedir'],
'touch /etc/postfix/mysql-virtual_alias_maps.cf',
'touch /etc/postfix/mysql-virtual_mailbox_domains.cf',
'touch /etc/postfix/mysql-virtual_mailbox_maps.cf',
'touch /etc/postfix/sasl/smtpd.conf',
'chown root:root /etc/postfix/main.cf',
'chown root:root /etc/postfix/master.cf',
'chown root:postfix /etc/postfix/mysql-virtual_alias_maps.cf',
'chown root:postfix /etc/postfix/mysql-virtual_mailbox_domains.cf',
'chown root:postfix /etc/postfix/mysql-virtual_mailbox_maps.cf',
'chown root:root /etc/postfix/sasl/smtpd.conf',
'chmod 0644 /etc/postfix/main.cf',
'chmod 0644 /etc/postfix/master.cf',
'chmod 0640 /etc/postfix/mysql-virtual_alias_maps.cf',
'chmod 0640 /etc/postfix/mysql-virtual_mailbox_domains.cf',
'chmod 0640 /etc/postfix/mysql-virtual_mailbox_maps.cf',
'chmod 0600 /etc/postfix/sasl/smtpd.conf',
),
'files' => Array(
'etc_postfix_main.cf' => '/etc/postfix/main.cf',
'etc_postfix_master.cf' => '/etc/postfix/master.cf',
'etc_postfix_mysql-virtual_alias_maps.cf' => '/etc/postfix/mysql-virtual_alias_maps.cf',
'etc_postfix_mysql-virtual_mailbox_domains.cf' => '/etc/postfix/mysql-virtual_mailbox_domains.cf',
'etc_postfix_mysql-virtual_mailbox_maps.cf' => '/etc/postfix/mysql-virtual_mailbox_maps.cf',
'etc_postfix_sasl_smtpd.conf' => '/etc/postfix/sasl/smtpd.conf'
),
'restart' => Array(
'/etc/init.d/postfix restart',
'newaliases'
)
),
'exim4' => Array(
'label' => 'Exim4',
'commands_1' => Array(
'dpkg-reconfigure exim4-config',
'# choose "no configuration at this time" and "splitted configuration files" in the dialog'
),
'files' => Array(
'etc_exim4_conf.d_acl_30_exim4-config_check_rcpt.rul' => '/etc/exim4/conf.d/acl/30_exim4-config_check_rcpt.rul',
'etc_exim4_conf.d_auth_30_syscp-config' => '/etc/exim4/conf.d/auth/30_syscp-config',
'etc_exim4_conf.d_main_10_syscp-config_options' => '/etc/exim4/conf.d/main/10_syscp-config_options',
'etc_exim4_conf.d_router_180_syscp-config' => '/etc/exim4/conf.d/router/180_syscp-config',
'etc_exim4_conf.d_transport_30_syscp-config' => '/etc/exim4/conf.d/transport/30_syscp-config'
),
'commands_2' => Array(
'chmod o-rx /var/lib/exim4',
'chmod o-rx /etc/exim4/conf.d/main/10_syscp-config_options'
),
'restart' => Array(
'/etc/init.d/exim4 restart'
)
)
)
),
'mail' => Array(
'label' => $lng['admin']['configfiles']['mail'],
'daemons' => Array(
'courier' => Array(
'label' => 'Courier',
'commands' => Array(
'apt-get install courier-pop courier-imap courier-authlib-mysql'
),
'files' => Array(
'etc_courier_authdaemonrc' => '/etc/courier/authdaemonrc',
'etc_courier_authmysqlrc' => '/etc/courier/authmysqlrc'
),
'restart' => Array(
'/etc/init.d/courier-authdaemon restart',
'/etc/init.d/courier-pop restart'
)
),
'dovecot' => Array(
'label' => 'Dovecot',
'commands' => Array(
'apt-get install dovecot-imapd dovecot-pop3d'
),
'files' => Array(
'etc_dovecot_dovecot.conf' => '/etc/dovecot/dovecot.conf',
'etc_dovecot_dovecot-sql.conf' => '/etc/dovecot/dovecot-sql.conf'
),
'restart' => Array(
'/etc/init.d/dovecot restart'
)
)
)
),
'ftp' => Array(
'label' => $lng['admin']['configfiles']['ftp'],
'daemons' => Array(
'proftpd' => Array(
'label' => 'ProFTPd',
'files' => Array(
'etc_proftpd_modules.conf' => '/etc/proftpd/modules.conf',
'etc_proftpd_proftpd.conf' => '/etc/proftpd/proftpd.conf'
),
'restart' => Array(
'/etc/init.d/proftpd restart'
)
),
'pure-ftpd' => Array(
'label' => 'Pure FTPd',
'commands' => Array(
'apt-get install pure-ftpd-common pure-ftpd-mysql'
),
'files' => Array(
'etc_pure-ftpd_conf_MinUID' => '/etc/pure-ftpd/conf/MinUID',
'etc_pure-ftpd_conf_MySQLConfigFile' => '/etc/pure-ftpd/conf/MySQLConfigFile',
'etc_pure-ftpd_conf_NoAnonymous' => '/etc/pure-ftpd/conf/NoAnonymous',
'etc_pure-ftpd_conf_MaxIdleTime' => '/etc/pure-ftpd/conf/MaxIdleTime',
'etc_pure-ftpd_conf_ChrootEveryone' => '/etc/pure-ftpd/conf/ChrootEveryone',
'etc_pure-ftpd_conf_PAMAuthentication' => '/etc/pure-ftpd/conf/PAMAuthentication',
'etc_pure-ftpd_db_mysql.conf' => '/etc/pure-ftpd/db/mysql.conf',
'etc_pure-ftpd_conf_CustomerProof' => '/etc/pure-ftpd/conf/CustomerProof',
'etc_pure-ftpd_conf_Bind' => '/etc/pure-ftpd/conf/Bind',
'etc_default_pure-ftpd-common' => '/etc/default/pure-ftpd-common'
),
'restart' => Array(
'/etc/init.d/pure-ftpd-mysql restart'
)
),
)
),
'etc' => Array(
'label' => $lng['admin']['configfiles']['etc'],
'daemons' => Array(
'cron' => Array(
'label' => 'Crond (cronscript)',
'files' => Array(
'etc_cron.d_syscp' => '/etc/cron.d/syscp'
),
'restart' => Array(
'/etc/init.d/cron restart'
)
),
'xinetd' => Array(
'label' => 'xinet.d (syscp updates in realtime)',
'commands' => Array(
'apt-get install xinetd',
'echo -e "syscp ' . $settings['system']['realtime_port'] . '/tcp # SysCP Realtime" >> /etc/services'
),
'files' => Array(
'etc_xinet.d_syscp' => '/etc/xinetd.d/syscp'
),
'restart' => Array(
'/etc/init.d/xinetd restart'
)
),
'awstats' => Array(
'label' => 'Awstats',
'files' => Array(
($settings['system']['mod_log_sql'] == 1 ? 'etc_awstats_awstats.model_log_sql.conf.syscp' : 'etc_awstats_awstats.model.conf.syscp') => '/etc/awstats/awstats.model.conf.syscp',
($settings['system']['mod_log_sql'] == 1 ? 'etc_cron.d_awstats_log_sql' : 'etc_cron.d_awstats') => '/etc/cron.d/awstats',
($settings['system']['webserver'] == 'lighttpd' ? 'etc_lighttpd_syscp-awstats.conf' : 'etc_apache_vhosts_05_awstats.conf') => ($settings['system']['webserver'] == 'lighttpd' ? '/etc/lighttpd/syscp-awstats.conf' : '/etc/apache2/sites-enabled/05_awstats.conf')
),
'commands' => Array(
($settings['system']['webserver'] == 'lighttpd' ? 'echo "include \"syscp-awstats.conf\"" >> /etc/lighttpd/lighttpd.conf' : '')
),
'restart' => Array(
($settings['system']['webserver'] == 'lighttpd' ? '/etc/init.d/lighttpd restart' : '/etc/init.d/apache2 restart')
)
),
'libnss' => Array(
'label' => 'libnss (system login with mysql)',
'commands' => Array(
'apt-get install libnss-mysql nscd',
'chmod 600 /etc/nss-mysql.conf /etc/nss-mysql-root.conf'
),
'files' => Array(
'etc_nss-mysql.conf' => '/etc/nss-mysql.conf',
'etc_nss-mysql-root.conf' => '/etc/nss-mysql-root.conf',
'etc_nsswitch.conf' => '/etc/nsswitch.conf',
),
'restart' => Array(
'/etc/init.d/nscd restart'
)
)
)
)
)
)
);
?>

View File

@@ -0,0 +1,290 @@
<?php
return Array(
'gentoo' => Array(
'label' => 'Gentoo',
'services' => Array(
'http' => Array(
'label' => $lng['admin']['configfiles']['http'],
'daemons' => Array(
'apache2' => Array(
'label' => 'Apache2 Webserver',
'commands' => Array(
'touch ' . $settings['system']['apacheconf_vhost'],
'chown root:0 ' . $settings['system']['apacheconf_vhost'],
'chmod 0600 ' . $settings['system']['apacheconf_vhost'],
'touch ' . $settings['system']['apacheconf_diroptions'],
'chown root:0 ' . $settings['system']['apacheconf_diroptions'],
'chmod 0600 ' . $settings['system']['apacheconf_diroptions'],
'mkdir -p ' . $settings['system']['documentroot_prefix'],
'mkdir -p ' . $settings['system']['logfiles_directory'],
'mkdir -p ' . $settings['system']['mod_fcgid_tmpdir'],
'chmod 1777 ' . $settings['system']['mod_fcgid_tmpdir'],
),
'restart' => Array(
'rc-update add apache2 default',
'/etc/init.d/apache2 restart'
)
),
'lighttpd' => Array(
'label' => 'Lighttpd Webserver',
'files' => Array(
'etc_lighttpd.conf' => '/etc/lighttpd/lighttpd.conf'
),
'commands' => Array(
$configcommand['vhost'],
$configcommand['diroptions'],
$configcommand['v_inclighty'],
$configcommand['d_inclighty'],
'mkdir -p ' . $settings['system']['documentroot_prefix'],
'mkdir -p ' . $settings['system']['logfiles_directory']
),
'restart' => Array(
'rc-update add lighttpd default',
'/etc/init.d/lighttpd restart'
)
)
)
),
'dns' => Array(
'label' => $lng['admin']['configfiles']['dns'],
'daemons' => Array(
'bind' => Array(
'label' => 'Bind9 Nameserver',
'files' => Array(
'etc_bind_default.zone' => '/etc/bind/default.zone'
),
'commands' => Array(
'echo "include \"' . $settings['system']['bindconf_directory'] . 'syscp_bind.conf\";" >> /etc/bind/named.conf',
'touch ' . $settings['system']['bindconf_directory'] . 'syscp_bind.conf',
'chown root:0 ' . $settings['system']['bindconf_directory'] . 'syscp_bind.conf',
'chmod 0600 ' . $settings['system']['bindconf_directory'] . 'syscp_bind.conf'
),
'restart' => Array(
'rc-update add named default',
'/etc/init.d/named restart'
)
),
)
),
'smtp' => Array(
'label' => $lng['admin']['configfiles']['smtp'],
'daemons' => Array(
'postfix' => Array(
'label' => 'Postfix',
'commands_1' => Array(
'mkdir -p ' . $settings['system']['vmail_homedir'],
'chown -R vmail:vmail ' . $settings['system']['vmail_homedir'],
'chmod 0750 ' . $settings['system']['vmail_homedir'],
'mv /etc/postfix/main.cf /etc/postfix/main.cf.gentoo',
'touch /etc/postfix/main.cf',
'touch /etc/postfix/master.cf',
'touch /etc/postfix/mysql-virtual_alias_maps.cf',
'touch /etc/postfix/mysql-virtual_mailbox_domains.cf',
'touch /etc/postfix/mysql-virtual_mailbox_maps.cf',
'touch /etc/sasl2/smtpd.conf',
'chown root:root /etc/postfix/main.cf',
'chown root:root /etc/postfix/master.cf',
'chown root:postfix /etc/postfix/mysql-virtual_alias_maps.cf',
'chown root:postfix /etc/postfix/mysql-virtual_mailbox_domains.cf',
'chown root:postfix /etc/postfix/mysql-virtual_mailbox_maps.cf',
'chown root:root /etc/sasl2/smtpd.conf',
'chmod 0644 /etc/postfix/main.cf',
'chmod 0644 /etc/postfix/master.cf',
'chmod 0640 /etc/postfix/mysql-virtual_alias_maps.cf',
'chmod 0640 /etc/postfix/mysql-virtual_mailbox_domains.cf',
'chmod 0640 /etc/postfix/mysql-virtual_mailbox_maps.cf',
'chmod 0600 /etc/sasl2/smtpd.conf',
),
'files' => Array(
'etc_postfix_main.cf' => '/etc/postfix/main.cf',
'etc_postfix_master.cf' => '/etc/postfix/master.cf',
'etc_postfix_mysql-virtual_alias_maps.cf' => '/etc/postfix/mysql-virtual_alias_maps.cf',
'etc_postfix_mysql-virtual_mailbox_domains.cf' => '/etc/postfix/mysql-virtual_mailbox_domains.cf',
'etc_postfix_mysql-virtual_mailbox_maps.cf' => '/etc/postfix/mysql-virtual_mailbox_maps.cf',
'etc_sasl2_smtpd.conf' => '/etc/sasl2/smtpd.conf'
),
'restart' => Array(
'rc-update add postfix default',
'/etc/init.d/postfix restart'
)
),
'dkim' => Array(
'label' => 'DomainKey filter',
'commands_1' => Array(
'mkdir -p /etc/postfix/dkim'
),
'files' => Array(
'dkim-filter.conf' => '/etc/postfix/dkim/dkim-filter.conf'
),
'commands_2' => Array(
'chgrp postfix /etc/postfix/dkim/dkim-filter.conf',
'echo "smtpd_milters = inet:localhost:8891\n
milter_macro_daemon_name = SIGNING\n
milter_default_action = accept\n" >> /etc/postfix/main.cf'
),
'restart' => Array(
'/etc/init.d/dkim-filter restart'
)
)
)
),
'mail' => Array(
'label' => $lng['admin']['configfiles']['mail'],
'daemons' => Array(
'courier' => Array(
'label' => 'Courier-IMAP (POP3/IMAP)',
'files' => Array(
'etc_courier_authlib_authdaemonrc' => '/etc/courier/authlib/authdaemonrc',
'etc_courier_authlib_authmysqlrc' => '/etc/courier/authlib/authmysqlrc',
'etc_courier-imap_pop3d' => '/etc/courier-imap/pop3d',
'etc_courier-imap_imapd' => '/etc/courier-imap/imapd',
'etc_courier-imap_pop3d-ssl' => '/etc/courier-imap/pop3d-ssl',
'etc_courier-imap_imapd-ssl' => '/etc/courier-imap/imapd-ssl'
),
'commands' => Array(
'rm /etc/courier/authlib/authdaemonrc',
'rm /etc/courier/authlib/authmysqlrc',
'rm /etc/courier-imap/pop3d',
'rm /etc/courier-imap/imapd',
'rm /etc/courier-imap/pop3d-ssl',
'rm /etc/courier-imap/imapd-ssl',
'touch /etc/courier/authlib/authdaemonrc',
'touch /etc/courier/authlib/authmysqlrc',
'touch /etc/courier-imap/pop3d',
'touch /etc/courier-imap/imapd',
'touch /etc/courier-imap/pop3d-ssl',
'touch /etc/courier-imap/imapd-ssl',
'chown root:0 /etc/courier/authlib/authdaemonrc',
'chown root:0 /etc/courier/authlib/authmysqlrc',
'chown root:0 /etc/courier-imap/pop3d',
'chown root:0 /etc/courier-imap/imapd',
'chown root:0 /etc/courier-imap/pop3d-ssl',
'chown root:0 /etc/courier-imap/imapd-ssl',
'chmod 0600 /etc/courier/authlib/authdaemonrc',
'chmod 0600 /etc/courier/authlib/authmysqlrc',
'chmod 0600 /etc/courier-imap/pop3d',
'chmod 0600 /etc/courier-imap/imapd',
'chmod 0600 /etc/courier-imap/pop3d-ssl',
'chmod 0600 /etc/courier-imap/imapd-ssl'
),
'restart' => Array(
'rc-update add courier-authlib default',
'rc-update add courier-pop3d default',
'rc-update add courier-imapd default',
'/etc/init.d/courier-authlib restart',
'/etc/init.d/courier-pop3d restart',
'/etc/init.d/courier-imapd restart'
)
),
'dovecot' => Array(
'label' => 'Dovecot',
'commands_1' => Array(
'mv dovecot.conf dovecot.conf.gentoo',
'mv dovecot-sql.conf dovecot-sql.conf.gentoo',
'touch dovecot.conf',
'touch dovecot-sql.conf',
),
'files' => Array(
'etc_dovecot_dovecot.conf' => '/etc/dovecot/dovecot.conf',
'etc_dovecot_dovecot-sql.conf' => '/etc/dovecot/dovecot-sql.conf'
),
'restart' => Array(
'/etc/init.d/dovecot restart'
)
)
)
),
'ftp' => Array(
'label' => $lng['admin']['configfiles']['ftp'],
'daemons' => Array(
'proftpd' => Array(
'label' => 'ProFTPd',
'files' => Array(
'etc_proftpd_proftpd.conf' => '/etc/proftpd/proftpd.conf'
),
'commands' => Array(
'touch /etc/proftpd/proftpd.conf',
'chown root:0 /etc/proftpd/proftpd.conf',
'chmod 0600 /etc/proftpd/proftpd.conf'
),
'restart' => Array(
'rc-update add proftpd default',
'/etc/init.d/proftpd restart'
)
),
)
),
'etc' => Array(
'label' => $lng['admin']['configfiles']['etc'],
'daemons' => Array(
'cron' => Array(
'label' => 'Crond (cronscript)',
'files' => Array(
'etc_php_syscp-cronjob_php.ini' => '/etc/php/syscp-cronjob/php.ini',
'etc_cron.d_syscp' => '/etc/cron.d/syscp'
),
'commands' => Array(
'touch /etc/cron.d/syscp',
'chown root:0 /etc/cron.d/syscp',
'chmod 0640 /etc/cron.d/syscp',
'mkdir -p /etc/php/syscp-cronjob',
'touch /etc/php/syscp-cronjob/php.ini',
'chown -R root:0 /etc/php/syscp-cronjob',
'chmod 0750 /etc/php/syscp-cronjob',
'chmod 0640 /etc/php/syscp-cronjob/php.ini'
),
'restart' => Array(
'rc-update add vixie-cron default',
'/etc/init.d/vixie-cron restart'
)
),
'xinetd' => Array(
'label' => 'xinet.d (syscp updates in realtime)',
'commands' => Array(
'emerge -av xinetd',
'echo -e "syscp ' . $settings['system']['realtime_port'] . '/tcp # SysCP Realtime" >> /etc/services'
),
'files' => Array(
'etc_xinet.d_syscp' => '/etc/xinetd.d/syscp'
),
'restart' => Array(
'/etc/init.d/xinetd restart'
)
),
'awstats' => Array(
'label' => 'Awstats',
'files' => Array(
($settings['system']['mod_log_sql'] == 1 ? 'etc_awstats_awstats.model_log_sql.conf.syscp' : 'etc_awstats_awstats.model.conf.syscp') => '/etc/awstats/awstats.model.conf.syscp',
($settings['system']['mod_log_sql'] == 1 ? 'etc_cron.d_awstats_log_sql' : 'etc_cron.d_awstats') => '/etc/cron.d/awstats',
($settings['system']['webserver'] == 'lighttpd' ? 'etc_lighttpd_syscp-awstats.conf' : 'etc_apache_vhosts_05_awstats.conf') => ($settings['system']['webserver'] == 'lighttpd' ? '/etc/lighttpd/syscp-awstats.conf' : '/etc/apache2/sites-enabled/05_awstats.conf')
),
'commands' => Array(
($settings['system']['webserver'] == 'lighttpd' ? 'echo "include \"syscp-awstats.conf\"" >> /etc/lighttpd/lighttpd.conf' : '')
),
'restart' => Array(
($settings['system']['webserver'] == 'lighttpd' ? '/etc/init.d/lighttpd restart' : '/etc/init.d/apache2 restart')
)
),
'libnss' => Array(
'label' => 'libnss (system login with mysql)',
'files' => Array(
'etc_libnss-mysql.cfg' => '/etc/libnss-mysql.cfg',
'etc_libnss-mysql-root.cfg' => '/etc/libnss-mysql-root.cfg',
'etc_nsswitch.conf' => '/etc/nsswitch.conf',
),
'commands' => Array(
'emerge -av libnss-mysql',
'chmod 600 /etc/libnss-mysql.cfg /etc/libnss-mysql-root.cfg'
),
'restart' => Array(
'rc-update add nscd default',
'/etc/init.d/nscd restart'
)
)
)
)
)
)
);
?>

View File

@@ -0,0 +1,261 @@
<?php
return Array(
'ubuntu_hardy' => Array(
'label' => 'Ubuntu 8.04 (Hardy)',
'services' => Array(
'http' => Array(
'label' => $lng['admin']['configfiles']['http'],
'daemons' => Array(
'apache2' => Array(
'label' => 'Apache 2',
'commands' => Array(
'mkdir -p ' . $settings['system']['documentroot_prefix'],
'mkdir -p ' . $settings['system']['logfiles_directory'],
'mkdir -p ' . $settings['system']['mod_fcgid_tmpdir'],
'chmod 1777 ' . $settings['system']['mod_fcgid_tmpdir'],
'a2dismod userdir',
),
'restart' => Array(
'/etc/init.d/apache2 restart'
)
),
'lighttpd' => Array(
'label' => 'Lighttpd Webserver',
'commands_1' => Array(
'apt-get install lighttpd',
),
'files' => Array(
'etc_lighttpd.conf' => '/etc/lighttpd/lighttpd.conf',
),
'commands_2' => Array(
$configcommand['vhost'],
$configcommand['diroptions'],
$configcommand['v_inclighty'],
$configcommand['d_inclighty'],
'mkdir -p ' . $settings['system']['documentroot_prefix'],
'mkdir -p ' . $settings['system']['logfiles_directory'],
'mkdir -p ' . $settings['system']['mod_fcgid_tmpdir'],
'chmod 1777 ' . $settings['system']['mod_fcgid_tmpdir'],
),
'restart' => Array(
'/etc/init.d/lighttpd restart'
)
)
)
),
'dns' => Array(
'label' => $lng['admin']['configfiles']['dns'],
'daemons' => Array(
'bind' => Array(
'label' => 'Bind9',
'commands' => Array(
'echo "include \"' . $settings['system']['bindconf_directory'] . 'syscp_bind.conf\";" >> /etc/bind/named.conf',
'touch ' . $settings['system']['bindconf_directory'] . 'syscp_bind.conf'
),
'restart' => Array(
'/etc/init.d/bind9 restart'
)
),
'powerdns' => Array(
'label' => 'PowerDNS',
'files' => Array(
'etc_powerdns_pdns.conf' => '/etc/powerdns/pdns.conf',
'etc_powerdns_pdns-syscp.conf' => '/etc/powerdns/pdns_syscp.conf',
),
'restart' => Array(
'/etc/init.d/pdns restart'
)
),
)
),
'smtp' => Array(
'label' => $lng['admin']['configfiles']['smtp'],
'daemons' => Array(
'postfix' => Array(
'label' => 'Postfix',
'commands_1' => Array(
'mkdir -p /etc/postfix/sasl',
'mkdir -p /var/spool/postfix/etc/pam.d',
'mkdir -p /var/spool/postfix/var/run/mysqld',
'groupadd -g ' . $settings['system']['vmail_gid'] . ' vmail',
'useradd -u ' . $settings['system']['vmail_uid'] . ' -g vmail vmail',
'mkdir -p ' . $settings['system']['vmail_homedir'],
'chown -R vmail:vmail ' . $settings['system']['vmail_homedir'],
'mv /etc/postfix/main.cf /etc/postfix/main.cf.ubuntu',
'touch /etc/postfix/main.cf',
'touch /etc/postfix/mysql-virtual_alias_maps.cf',
'touch /etc/postfix/mysql-virtual_mailbox_domains.cf',
'touch /etc/postfix/mysql-virtual_mailbox_maps.cf',
'touch /etc/postfix/sasl/smtpd.conf',
'chown root:root /etc/postfix/main.cf',
'chown root:root /etc/postfix/master.cf',
'chown root:postfix /etc/postfix/mysql-virtual_alias_maps.cf',
'chown root:postfix /etc/postfix/mysql-virtual_mailbox_domains.cf',
'chown root:postfix /etc/postfix/mysql-virtual_mailbox_maps.cf',
'chown root:root /etc/postfix/sasl/smtpd.conf',
'chmod 0644 /etc/postfix/main.cf',
'chmod 0644 /etc/postfix/master.cf',
'chmod 0640 /etc/postfix/mysql-virtual_alias_maps.cf',
'chmod 0640 /etc/postfix/mysql-virtual_mailbox_domains.cf',
'chmod 0640 /etc/postfix/mysql-virtual_mailbox_maps.cf',
'chmod 0600 /etc/postfix/sasl/smtpd.conf',
),
'files' => Array(
'etc_postfix_main.cf' => '/etc/postfix/main.cf',
'etc_postfix_master.cf' => '/etc/postfix/master.cf',
'etc_postfix_mysql-virtual_alias_maps.cf' => '/etc/postfix/mysql-virtual_alias_maps.cf',
'etc_postfix_mysql-virtual_mailbox_domains.cf' => '/etc/postfix/mysql-virtual_mailbox_domains.cf',
'etc_postfix_mysql-virtual_mailbox_maps.cf' => '/etc/postfix/mysql-virtual_mailbox_maps.cf',
'etc_postfix_sasl_smtpd.conf' => '/etc/postfix/sasl/smtpd.conf'
),
'restart' => Array(
'/etc/init.d/postfix restart',
'newaliases'
)
),
'exim4' => Array(
'label' => 'Exim4',
'commands_1' => Array(
'dpkg-reconfigure exim4-config',
'# choose "no configuration at this time" and "splitted configuration files" in the dialog'
),
'files' => Array(
'etc_exim4_conf.d_acl_30_exim4-config_check_rcpt.rul' => '/etc/exim4/conf.d/acl/30_exim4-config_check_rcpt.rul',
'etc_exim4_conf.d_auth_30_syscp-config' => '/etc/exim4/conf.d/auth/30_syscp-config',
'etc_exim4_conf.d_main_10_syscp-config_options' => '/etc/exim4/conf.d/main/10_syscp-config_options',
'etc_exim4_conf.d_router_180_syscp-config' => '/etc/exim4/conf.d/router/180_syscp-config',
'etc_exim4_conf.d_transport_30_syscp-config' => '/etc/exim4/conf.d/transport/30_syscp-config'
),
'commands_2' => Array(
'chmod o-rx /var/lib/exim4',
'chmod o-rx /etc/exim4/conf.d/main/10_syscp-config_options'
),
'restart' => Array(
'/etc/init.d/exim4 restart'
)
)
)
),
'mail' => Array(
'label' => $lng['admin']['configfiles']['mail'],
'daemons' => Array(
'courier' => Array(
'label' => 'Courier',
'files' => Array(
'etc_courier_authdaemonrc' => '/etc/courier/authdaemonrc',
'etc_courier_authmysqlrc' => '/etc/courier/authmysqlrc'
),
'restart' => Array(
'/etc/init.d/courier-authdaemon restart',
'/etc/init.d/courier-pop restart'
)
),
'dovecot' => Array(
'label' => 'Dovecot',
'commands' => Array(
'/etc/init.d/dovecot stop',
),
'files' => Array(
'etc_dovecot_dovecot.conf' => '/etc/dovecot/dovecot.conf',
'etc_dovecot_dovecot-sql.conf' => '/etc/dovecot/dovecot-sql.conf'
),
'restart' => Array(
'/etc/init.d/dovecot restart'
)
)
)
),
'ftp' => Array(
'label' => $lng['admin']['configfiles']['ftp'],
'daemons' => Array(
'proftpd' => Array(
'label' => 'ProFTPd',
'files' => Array(
'etc_proftpd_modules.conf' => '/etc/proftpd/modules.conf',
'etc_proftpd_proftpd.conf' => '/etc/proftpd/proftpd.conf'
),
'restart' => Array(
'/etc/init.d/proftpd restart'
)
),
'pure-ftpd' => Array(
'label' => 'Pure FTPd',
'files' => Array(
'etc_pure-ftpd_conf_MinUID' => '/etc/pure-ftpd/conf/MinUID',
'etc_pure-ftpd_conf_MySQLConfigFile' => '/etc/pure-ftpd/conf/MySQLConfigFile',
'etc_pure-ftpd_conf_NoAnonymous' => '/etc/pure-ftpd/conf/NoAnonymous',
'etc_pure-ftpd_conf_MaxIdleTime' => '/etc/pure-ftpd/conf/MaxIdleTime',
'etc_pure-ftpd_conf_ChrootEveryone' => '/etc/pure-ftpd/conf/ChrootEveryone',
'etc_pure-ftpd_conf_PAMAuthentication' => '/etc/pure-ftpd/conf/PAMAuthentication',
'etc_pure-ftpd_db_mysql.conf' => '/etc/pure-ftpd/db/mysql.conf',
'etc_pure-ftpd_conf_CustomerProof' => '/etc/pure-ftpd/conf/CustomerProof',
'etc_pure-ftpd_conf_Bind' => '/etc/pure-ftpd/conf/Bind',
'etc_default_pure-ftpd-common' => '/etc/default/pure-ftpd-common'
),
'restart' => Array(
'/etc/init.d/pure-ftpd-mysql restart'
)
),
)
),
'etc' => Array(
'label' => $lng['admin']['configfiles']['etc'],
'daemons' => Array(
'cron' => Array(
'label' => 'Crond (cronscript)',
'files' => Array(
'etc_cron.d_syscp' => '/etc/cron.d/syscp'
),
'restart' => Array(
'/etc/init.d/cron restart'
)
),
'xinetd' => Array(
'label' => 'xinet.d (syscp updates in realtime)',
'commands' => Array(
'apt-get install xinetd',
'echo -e "syscp ' . $settings['system']['realtime_port'] . '/tcp # SysCP Realtime" >> /etc/services'
),
'files' => Array(
'etc_xinet.d_syscp' => '/etc/xinetd.d/syscp'
),
'restart' => Array(
'/etc/init.d/xinetd restart'
)
),
'awstats' => Array(
'label' => 'Awstats',
'files' => Array(
($settings['system']['mod_log_sql'] == 1 ? 'etc_awstats_awstats.model_log_sql.conf.syscp' : 'etc_awstats_awstats.model.conf.syscp') => '/etc/awstats/awstats.model.conf.syscp',
($settings['system']['mod_log_sql'] == 1 ? 'etc_cron.d_awstats_log_sql' : 'etc_cron.d_awstats') => '/etc/cron.d/awstats',
($settings['system']['webserver'] == 'lighttpd' ? 'etc_lighttpd_syscp-awstats.conf' : 'etc_apache_vhosts_05_awstats.conf') => ($settings['system']['webserver'] == 'lighttpd' ? '/etc/lighttpd/syscp-awstats.conf' : '/etc/apache2/sites-enabled/05_awstats.conf')
),
'commands' => Array(
($settings['system']['webserver'] == 'lighttpd' ? 'echo "include \"syscp-awstats.conf\"" >> /etc/lighttpd/lighttpd.conf' : '')
),
'restart' => Array(
($settings['system']['webserver'] == 'lighttpd' ? '/etc/init.d/lighttpd restart' : '/etc/init.d/apache2 restart')
)
),
'libnss' => Array(
'label' => 'libnss (system login with mysql)',
'commands' => Array(
'apt-get install libnss-mysql nscd',
'chmod 600 /etc/nss-mysql.conf /etc/nss-mysql-root.conf'
),
'files' => Array(
'etc_nss-mysql.conf' => '/etc/nss-mysql.conf',
'etc_nss-mysql-root.conf' => '/etc/nss-mysql-root.conf',
'etc_nsswitch.conf' => '/etc/nsswitch.conf',
),
'restart' => Array(
'/etc/init.d/nscd restart'
)
)
)
)
)
)
);
?>

View File

@@ -0,0 +1,268 @@
<?php
return Array(
'debian_lenny' => Array(
'label' => 'Debian 5.0 (Lenny)',
'services' => Array(
'http' => Array(
'label' => $lng['admin']['configfiles']['http'],
'daemons' => Array(
'apache2' => Array(
'label' => 'Apache 2',
'commands' => Array(
'mkdir -p ' . $settings['system']['documentroot_prefix'],
'mkdir -p ' . $settings['system']['logfiles_directory'],
'mkdir -p ' . $settings['system']['mod_fcgid_tmpdir'],
'chmod 1777 ' . $settings['system']['mod_fcgid_tmpdir'],
'a2dismod userdir',
),
'restart' => Array(
'/etc/init.d/apache2 restart'
),
),
'lighttpd' => Array(
'label' => 'Lighttpd Webserver',
'commands_1' => Array(
'apt-get install lighttpd',
),
'files' => Array(
'etc_lighttpd.conf' => '/etc/lighttpd/lighttpd.conf',
),
'commands_2' => Array(
$configcommand['vhost'],
$configcommand['diroptions'],
$configcommand['v_inclighty'],
$configcommand['d_inclighty'],
'mkdir -p ' . $settings['system']['documentroot_prefix'],
'mkdir -p ' . $settings['system']['logfiles_directory'],
'mkdir -p ' . $settings['system']['mod_fcgid_tmpdir'],
'chmod 1777 ' . $settings['system']['mod_fcgid_tmpdir'],
),
'restart' => Array(
'/etc/init.d/lighttpd restart'
)
)
)
),
'dns' => Array(
'label' => $lng['admin']['configfiles']['dns'],
'daemons' => Array(
'bind' => Array(
'label' => 'Bind9',
'commands' => Array(
'apt-get install bind9',
'echo "include \"' . $settings['system']['bindconf_directory'] . 'syscp_bind.conf\";" >> /etc/bind/named.conf',
'touch ' . $settings['system']['bindconf_directory'] . 'syscp_bind.conf'
),
'restart' => Array(
'/etc/init.d/bind9 restart'
)
),
'powerdns' => Array(
'label' => 'PowerDNS',
'files' => Array(
'etc_powerdns_pdns.conf' => '/etc/powerdns/pdns.conf',
'etc_powerdns_pdns-syscp.conf' => '/etc/powerdns/pdns_syscp.conf',
),
'restart' => Array(
'/etc/init.d/pdns restart'
)
),
)
),
'smtp' => Array(
'label' => $lng['admin']['configfiles']['smtp'],
'daemons' => Array(
'postfix' => Array(
'label' => 'Postfix',
'commands' => Array(
'apt-get install postfix postfix-mysql libsasl2 libsasl2-modules libsasl2-modules-sql',
'mkdir -p /etc/postfix/sasl',
'mkdir -p /var/spool/postfix/etc/pam.d',
'mkdir -p /var/spool/postfix/var/run/mysqld',
'groupadd -g ' . $settings['system']['vmail_gid'] . ' vmail',
'useradd -u ' . $settings['system']['vmail_uid'] . ' -g vmail vmail',
'mkdir -p ' . $settings['system']['vmail_homedir'],
'chown -R vmail:vmail ' . $settings['system']['vmail_homedir'],
'touch /etc/postfix/mysql-virtual_alias_maps.cf',
'touch /etc/postfix/mysql-virtual_mailbox_domains.cf',
'touch /etc/postfix/mysql-virtual_mailbox_maps.cf',
'touch /etc/postfix/sasl/smtpd.conf',
'chown root:root /etc/postfix/main.cf',
'chown root:root /etc/postfix/master.cf',
'chown root:postfix /etc/postfix/mysql-virtual_alias_maps.cf',
'chown root:postfix /etc/postfix/mysql-virtual_mailbox_domains.cf',
'chown root:postfix /etc/postfix/mysql-virtual_mailbox_maps.cf',
'chown root:root /etc/postfix/sasl/smtpd.conf',
'chmod 0644 /etc/postfix/main.cf',
'chmod 0644 /etc/postfix/master.cf',
'chmod 0640 /etc/postfix/mysql-virtual_alias_maps.cf',
'chmod 0640 /etc/postfix/mysql-virtual_mailbox_domains.cf',
'chmod 0640 /etc/postfix/mysql-virtual_mailbox_maps.cf',
'chmod 0600 /etc/postfix/sasl/smtpd.conf',
),
'files' => Array(
'etc_postfix_main.cf' => '/etc/postfix/main.cf',
'etc_postfix_master.cf' => '/etc/postfix/master.cf',
'etc_postfix_mysql-virtual_alias_maps.cf' => '/etc/postfix/mysql-virtual_alias_maps.cf',
'etc_postfix_mysql-virtual_mailbox_domains.cf' => '/etc/postfix/mysql-virtual_mailbox_domains.cf',
'etc_postfix_mysql-virtual_mailbox_maps.cf' => '/etc/postfix/mysql-virtual_mailbox_maps.cf',
'etc_postfix_sasl_smtpd.conf' => '/etc/postfix/sasl/smtpd.conf'
),
'restart' => Array(
'/etc/init.d/postfix restart',
'newaliases'
)
),
'exim4' => Array(
'label' => 'Exim4',
'commands_1' => Array(
'dpkg-reconfigure exim4-config',
'# choose "no configuration at this time" and "splitted configuration files" in the dialog'
),
'files' => Array(
'etc_exim4_conf.d_acl_30_exim4-config_check_rcpt.rul' => '/etc/exim4/conf.d/acl/30_exim4-config_check_rcpt.rul',
'etc_exim4_conf.d_auth_30_syscp-config' => '/etc/exim4/conf.d/auth/30_syscp-config',
'etc_exim4_conf.d_main_10_syscp-config_options' => '/etc/exim4/conf.d/main/10_syscp-config_options',
'etc_exim4_conf.d_router_180_syscp-config' => '/etc/exim4/conf.d/router/180_syscp-config',
'etc_exim4_conf.d_transport_30_syscp-config' => '/etc/exim4/conf.d/transport/30_syscp-config'
),
'commands_2' => Array(
'chmod o-rx /var/lib/exim4',
'chmod o-rx /etc/exim4/conf.d/main/10_syscp-config_options'
),
'restart' => Array(
'/etc/init.d/exim4 restart'
)
)
)
),
'mail' => Array(
'label' => $lng['admin']['configfiles']['mail'],
'daemons' => Array(
'courier' => Array(
'label' => 'Courier',
'commands' => Array(
'apt-get install courier-pop courier-imap courier-authlib-mysql'
),
'files' => Array(
'etc_courier_authdaemonrc' => '/etc/courier/authdaemonrc',
'etc_courier_authmysqlrc' => '/etc/courier/authmysqlrc'
),
'restart' => Array(
'/etc/init.d/courier-authdaemon restart',
'/etc/init.d/courier-pop restart'
)
),
'dovecot' => Array(
'label' => 'Dovecot',
'commands' => Array(
'apt-get install dovecot-imapd dovecot-pop3d'
),
'files' => Array(
'etc_dovecot_dovecot.conf' => '/etc/dovecot/dovecot.conf',
'etc_dovecot_dovecot-sql.conf' => '/etc/dovecot/dovecot-sql.conf'
),
'restart' => Array(
'/etc/init.d/dovecot restart'
)
)
)
),
'ftp' => Array(
'label' => $lng['admin']['configfiles']['ftp'],
'daemons' => Array(
'proftpd' => Array(
'label' => 'ProFTPd',
'files' => Array(
'etc_proftpd_sql.conf' => '/etc/proftpd/sql.conf',
'etc_proftpd_modules.conf' => '/etc/proftpd/modules.conf',
'etc_proftpd_proftpd.conf' => '/etc/proftpd/proftpd.conf'
),
'restart' => Array(
'/etc/init.d/proftpd restart'
)
),
'pure-ftpd' => Array(
'label' => 'Pure FTPd',
'commands' => Array(
'apt-get install pure-ftpd-common pure-ftpd-mysql'
),
'files' => Array(
'etc_pure-ftpd_conf_MinUID' => '/etc/pure-ftpd/conf/MinUID',
'etc_pure-ftpd_conf_MySQLConfigFile' => '/etc/pure-ftpd/conf/MySQLConfigFile',
'etc_pure-ftpd_conf_NoAnonymous' => '/etc/pure-ftpd/conf/NoAnonymous',
'etc_pure-ftpd_conf_MaxIdleTime' => '/etc/pure-ftpd/conf/MaxIdleTime',
'etc_pure-ftpd_conf_ChrootEveryone' => '/etc/pure-ftpd/conf/ChrootEveryone',
'etc_pure-ftpd_conf_PAMAuthentication' => '/etc/pure-ftpd/conf/PAMAuthentication',
'etc_pure-ftpd_db_mysql.conf' => '/etc/pure-ftpd/db/mysql.conf',
'etc_pure-ftpd_conf_CustomerProof' => '/etc/pure-ftpd/conf/CustomerProof',
'etc_pure-ftpd_conf_Bind' => '/etc/pure-ftpd/conf/Bind',
'etc_default_pure-ftpd-common' => '/etc/default/pure-ftpd-common'
),
'restart' => Array(
'/etc/init.d/pure-ftpd-mysql restart'
)
),
)
),
'etc' => Array(
'label' => $lng['admin']['configfiles']['etc'],
'daemons' => Array(
'cron' => Array(
'label' => 'Crond (cronscript)',
'files' => Array(
'etc_cron.d_syscp' => '/etc/cron.d/syscp'
),
'restart' => Array(
'/etc/init.d/cron restart'
)
),
'xinetd' => Array(
'label' => 'xinet.d (syscp updates in realtime)',
'commands' => Array(
'apt-get install xinetd',
'echo -e "syscp ' . $settings['system']['realtime_port'] . '/tcp # SysCP Realtime" >> /etc/services'
),
'files' => Array(
'etc_xinet.d_syscp' => '/etc/xinetd.d/syscp'
),
'restart' => Array(
'/etc/init.d/xinetd restart'
)
),
'awstats' => Array(
'label' => 'Awstats',
'files' => Array(
($settings['system']['mod_log_sql'] == 1 ? 'etc_awstats_awstats.model_log_sql.conf.syscp' : 'etc_awstats_awstats.model.conf.syscp') => '/etc/awstats/awstats.model.conf.syscp',
($settings['system']['mod_log_sql'] == 1 ? 'etc_cron.d_awstats_log_sql' : 'etc_cron.d_awstats') => '/etc/cron.d/awstats',
($settings['system']['webserver'] == 'lighttpd' ? 'etc_lighttpd_syscp-awstats.conf' : 'etc_apache_vhosts_05_awstats.conf') => ($settings['system']['webserver'] == 'lighttpd' ? '/etc/lighttpd/syscp-awstats.conf' : '/etc/apache2/sites-enabled/05_awstats.conf')
),
'commands' => Array(
($settings['system']['webserver'] == 'lighttpd' ? 'echo "include \"syscp-awstats.conf\"" >> /etc/lighttpd/lighttpd.conf' : '')
),
'restart' => Array(
($settings['system']['webserver'] == 'lighttpd' ? '/etc/init.d/lighttpd restart' : '/etc/init.d/apache2 restart')
)
),
'libnss' => Array(
'label' => 'libnss (system login with mysql)',
'commands' => Array(
'apt-get install libnss-mysql nscd',
'chmod 600 /etc/nss-mysql.conf /etc/nss-mysql-root.conf'
),
'files' => Array(
'etc_nss-mysql.conf' => '/etc/nss-mysql.conf',
'etc_nss-mysql-root.conf' => '/etc/nss-mysql-root.conf',
'etc_nsswitch.conf' => '/etc/nsswitch.conf',
),
'restart' => Array(
'/etc/init.d/nscd restart'
)
)
)
)
)
)
);
?>

View File

@@ -0,0 +1,139 @@
<?php
return Array(
'suse_linux_10_0' => Array(
'label' => 'SUSE Linux 10.0',
'services' => Array(
'http' => Array(
'label' => $lng['admin']['configfiles']['http'],
'daemons' => Array(
'apache' => Array(
'label' => 'Apache',
'commands' => Array(
$configcommand['vhost'],
$configcommand['diroptions'],
$configcommand['include'],
'mkdir -p ' . $settings['system']['documentroot_prefix'],
'mkdir -p ' . $settings['system']['logfiles_directory']
),
'restart' => Array(
'/etc/init.d/apache2 restart'
)
),
)
),
'dns' => Array(
'label' => $lng['admin']['configfiles']['dns'],
'daemons' => Array(
'bind' => Array(
'label' => 'Bind9',
'commands' => Array(
'echo "include \"' . $settings['system']['bindconf_directory'] . 'syscp_bind.conf\";" >> /etc/named.conf',
'touch ' . $settings['system']['bindconf_directory'] . 'syscp_bind.conf'
),
'restart' => Array(
'/etc/init.d/named restart'
)
),
)
),
'smtp' => Array(
'label' => $lng['admin']['configfiles']['smtp'],
'daemons' => Array(
'postfix' => Array(
'label' => 'Postfix',
'files' => Array(
'etc_postfix_main.cf' => '/etc/postfix/main.cf',
'etc_postfix_mysql-virtual_alias_maps.cf' => '/etc/postfix/mysql-virtual_alias_maps.cf',
'etc_postfix_mysql-virtual_mailbox_domains.cf' => '/etc/postfix/mysql-virtual_mailbox_domains.cf',
'etc_postfix_mysql-virtual_mailbox_maps.cf' => '/etc/postfix/mysql-virtual_mailbox_maps.cf',
'usr_lib_sasl2_smtpd.conf' => '/usr/lib/sasl2/smtpd.conf'
),
'commands' => Array(
'mkdir -p /var/spool/postfix/etc/pam.d',
'groupadd -g ' . $settings['system']['vmail_gid'] . ' vmail',
'useradd -u ' . $settings['system']['vmail_uid'] . ' -g vmail vmail',
'mkdir -p ' . $settings['system']['vmail_homedir'],
'chown -R vmail:vmail ' . $settings['system']['vmail_homedir'],
'touch /etc/postfix/mysql-virtual_alias_maps.cf',
'touch /etc/postfix/mysql-virtual_mailbox_domains.cf',
'touch /etc/postfix/mysql-virtual_mailbox_maps.cf',
'touch /usr/lib/sasl2/smtpd.conf',
'chmod 660 /etc/postfix/mysql-virtual_alias_maps.cf',
'chmod 660 /etc/postfix/mysql-virtual_mailbox_domains.cf',
'chmod 660 /etc/postfix/mysql-virtual_mailbox_maps.cf',
'chmod 660 /usr/lib/sasl2/smtpd.conf',
'chgrp postfix /etc/postfix/mysql-virtual_alias_maps.cf',
'chgrp postfix /etc/postfix/mysql-virtual_mailbox_domains.cf',
'chgrp postfix /etc/postfix/mysql-virtual_mailbox_maps.cf',
'chgrp postfix /usr/lib/sasl2/smtpd.conf'
),
'restart' => Array(
'/etc/init.d/postfix restart'
)
)
)
),
'mail' => Array(
'label' => $lng['admin']['configfiles']['mail'],
'daemons' => Array(
'courier' => Array(
'label' => 'Courier',
'files' => Array(
'etc_authlib_authdaemonrc' => '/etc/authlib/authdaemonrc',
'etc_authlib_authmysqlrc' => '/etc/authlib/authmysqlrc'
),
'restart' => Array(
'/etc/init.d/courier-authdaemon restart',
'/etc/init.d/courier-pop restart'
)
),
)
),
'ftp' => Array(
'label' => $lng['admin']['configfiles']['ftp'],
'daemons' => Array(
'proftpd' => Array(
'label' => 'ProFTPd',
'files' => Array(
'etc_proftpd_modules.conf' => '/etc/proftpd/modules.conf',
'etc_proftpd_proftpd.conf' => '/etc/proftpd/proftpd.conf'
),
'restart' => Array(
'/etc/init.d/proftpd restart'
)
),
)
),
'etc' => Array(
'label' => $lng['admin']['configfiles']['etc'],
'daemons' => Array(
'cron' => Array(
'label' => 'Crond (cronscript)',
'files' => Array(
'etc_cron.d_syscp' => '/etc/cron.d/syscp'
),
'restart' => Array(
'/etc/init.d/cron restart'
)
),
'awstats' => Array(
'label' => 'Awstats',
'files' => Array(
($settings['system']['mod_log_sql'] == 1 ? 'etc_awstats_awstats.model_log_sql.conf.syscp' : 'etc_awstats_awstats.model.conf.syscp') => '/etc/awstats/awstats.model.conf.syscp',
($settings['system']['mod_log_sql'] == 1 ? 'etc_cron.d_awstats_log_sql' : 'etc_cron.d_awstats') => '/etc/cron.d/awstats',
($settings['system']['webserver'] == 'lighttpd' ? 'etc_lighttpd_syscp-awstats.conf' : 'etc_apache_vhosts_05_awstats.conf') => ($settings['system']['webserver'] == 'lighttpd' ? '/etc/lighttpd/syscp-awstats.conf' : '/etc/apache2/sites-enabled/05_awstats.conf')
),
'commands' => Array(
($settings['system']['webserver'] == 'lighttpd' ? 'echo "include \"syscp-awstats.conf\"" >> /etc/lighttpd/lighttpd.conf' : '')
),
'restart' => Array(
($settings['system']['webserver'] == 'lighttpd' ? '/etc/init.d/lighttpd restart' : '/etc/init.d/apache2 restart')
)
)
)
)
)
)
);
?>

View File

@@ -0,0 +1,48 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Panel
* @version $Id: configfiles_index.inc.php 2692 2009-03-27 18:04:47Z flo $
*/
$configcommand = array();
if(isConfigDir($settings['system']['apacheconf_vhost']))
{
$configcommand['vhost'] = 'mkdir -p ' . $settings['system']['apacheconf_vhost'];
$configcommand['include'] = 'echo -e "\\nInclude ' . makeCorrectDir($settings['system']['apacheconf_vhost']) . '*.conf" >> ' . makeCorrectFile(makeCorrectDir($settings['system']['apacheconf_vhost']) . '/httpd.conf');
$configcommand['v_inclighty'] = 'echo -e \'\\ninclude_shell "find ' . makeCorrectDir($settings['system']['apacheconf_vhost']) . ' -maxdepth 1 -name \'*.conf\' -exec cat {} \;"\' >> /etc/lighttpd/lighttpd.conf';
}
else
{
$configcommand['vhost'] = 'touch ' . $settings['system']['apacheconf_vhost'];
$configcommand['include'] = 'echo -e "\\nInclude ' . $settings['system']['apacheconf_vhost'] . '" >> ' . makeCorrectFile(dirname($settings['system']['apacheconf_vhost']) . '/httpd.conf');
$configcommand['v_inclighty'] = 'echo -e \'\\ninclude "' . $settings['system']['apacheconf_vhost'] . '"\' >> /etc/lighttpd/lighttpd.conf';
}
if(isConfigDir($settings['system']['apacheconf_diroptions']))
{
$configcommand['diroptions'] = 'mkdir -p ' . $settings['system']['apacheconf_diroptions'];
$configcommand['d_inclighty'] = 'echo -e \'\\ninclude_shell "find ' . makeCorrectDir($settings['system']['apacheconf_diroptions']) . ' -maxdepth 1 -name \'*.conf\' -exec cat {} \;"\' >> /etc/lighttpd/lighttpd.conf';
}
else
{
$configcommand['diroptions'] = 'touch ' . $settings['system']['apacheconf_diroptions'];
$configcommand['d_inclighty'] = 'echo -e \'\\ninclude "' . $settings['system']['apacheconf_diroptions'] . '"\' >> /etc/lighttpd/lighttpd.conf';
}
$cfgPath = 'lib/configfiles/';
$configfiles = Array();
$configfiles = array_merge(include $cfgPath . 'lenny.inc.php', include $cfgPath . 'etch.inc.php', include $cfgPath . 'hardy.inc.php', include $cfgPath . 'gentoo.inc.php', include $cfgPath . 'suse10.inc.php');
?>

248
lib/cron_init.php Normal file
View File

@@ -0,0 +1,248 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @author Florian Aders <eleras@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package System
* @version $Id: cron_init.php 2724 2009-06-07 14:18:02Z flo $
*/
if(@php_sapi_name() != 'cli'
&& @php_sapi_name() != 'cgi'
&& @php_sapi_name() != 'cgi-fcgi')
{
die('This script will only work in the shell.');
}
$cronscriptDebug = false;
$lockdir = '/var/run/';
$lockFilename = 'syscp_' . basename($_SERVER['PHP_SELF'], '.php') . '.lock-';
$lockfName = $lockFilename . getmypid();
$lockfile = $lockdir . $lockfName;
// guess the syscp installation path
// normally you should not need to modify this script anymore, if your
// syscp installation isn't in /var/www/syscp
$pathtophpfiles = dirname(dirname(__FILE__));
// should the syscp installation guessing not work correctly,
// uncomment the following line, and put your path in there!
//$pathtophpfiles = '/var/www/syscp/';
// create and open the lockfile!
$keepLockFile = false;
$debugHandler = fopen($lockfile, 'w');
fwrite($debugHandler, 'Setting Lockfile to ' . $lockfile . "\n");
fwrite($debugHandler, 'Setting SysCP installation path to ' . $pathtophpfiles . "\n");
// open the lockfile directory and scan for existing lockfiles
$lockDirHandle = opendir($lockdir);
while($fName = readdir($lockDirHandle))
{
if($lockFilename == substr($fName, 0, strlen($lockFilename))
&& $lockfName != $fName)
{
// Check if last run jailed out with an exception
$croncontent = file($lockdir . $fName);
$lastline = $croncontent[(count($croncontent) - 1)];
if($lastline == '=== Keep lockfile because of exception ===')
{
fclose($debugHandler);
unlink($lockfile);
die('Last cron jailed out with an exception. Exiting...' . "\n" . 'Take a look into the contents of ' . $lockdir . $fName . '* for more information!' . "\n");
}
// Check if cron is running or has died.
$check_pid = substr(strstr($fName, "-"), 1);
system("kill -CHLD " . $check_pid . " 1> /dev/null 2> /dev/null", $check_pid_return);
if($check_pid_return == 1)
{
// Result: Existing lockfile/pid isnt running
// Most likely it has died
//
// Action: Remove it and continue
//
fwrite($debugHandler, 'Previous cronjob didn\'t exit clean. PID: ' . $check_pid . "\n");
fwrite($debugHandler, 'Removing lockfile: ' . $lockdir . $fName . "\n");
unlink($lockdir . $fName);
}
else
{
// Result: A Cronscript with this pid
// is still running
// Action: remove my own Lock and die
//
// close the current lockfile
fclose($debugHandler);
// ... and delete it
unlink($lockfile);
die('There is already a Cronjob in progress. Exiting...' . "\n" . 'Take a look into the contents of ' . $lockdir . $lockFilename . '* for more information!' . "\n");
}
}
}
/**
* Includes the Usersettings eg. MySQL-Username/Passwort etc.
*/
require ($pathtophpfiles . '/lib/userdata.inc.php');
fwrite($debugHandler, 'Userdatas included' . "\n");
// Legacy sql-root-information
if(isset($sql['root_user']) && isset($sql['root_password']) && (!isset($sql_root) || !is_array($sql_root)))
{
$sql_root = array(0 => array('caption' => 'Default', 'host' => $sql['host'], 'user' => $sql['root_user'], 'password' => $sql['root_password']));
unset($sql['root_user']);
unset($sql['root_password']);
}
/**
* Includes the Functions
*/
require ($pathtophpfiles . '/lib/functions.php');
/**
* Includes the MySQL-Tabledefinitions etc.
*/
require ($pathtophpfiles . '/lib/tables.inc.php');
fwrite($debugHandler, 'Table definitions included' . "\n");
/**
* Includes the MySQL-Connection-Class
*/
fwrite($debugHandler, 'Database Class has been loaded' . "\n");
$db = new db($sql['host'], $sql['user'], $sql['password'], $sql['db']);
// If one cronscript needs root, it should say $needrootdb = true before the include
/*
if(isset($needrootdb)
&& $needrootdb === true)
{
$db_root = new db($sql['host'], $sql['root_user'], $sql['root_password'], '');
if($db_root->link_id == 0)
{
/**
* Do not proceed further if no database connection could be established
*
fclose($debugHandler);
unlink($lockfile);
die('root can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...');
}
unset($db_root->password);
fwrite($debugHandler, 'Database-rootconnection established' . "\n");
}*/
unset($sql['root_user'], $sql['root_password']);
if($db->link_id == 0)
{
/**
* Do not proceed further if no database connection could be established
*/
fclose($debugHandler);
unlink($lockfile);
die('SysCP can\'t connect to mysqlserver. Please check userdata.inc.php! Exiting...');
}
fwrite($debugHandler, 'Database-connection established' . "\n");
unset($sql);
unset($db->password);
$result = $db->query("SELECT `settingid`, `settinggroup`, `varname`, `value` FROM `" . TABLE_PANEL_SETTINGS . "`");
while($row = $db->fetch_array($result))
{
$settings[$row['settinggroup']][$row['varname']] = $row['value'];
}
unset($row);
unset($result);
fwrite($debugHandler, 'SysCP Settings has been loaded from the database' . "\n");
if(!isset($settings['system']['dbversion'])
|| $settings['system']['dbversion'] != $dbversion)
{
/**
* Do not proceed further if the Database version is not the same as the script version
*/
fclose($debugHandler);
unlink($lockfile);
die('Version of File doesnt match Version of Database. Exiting...');
}
fwrite($debugHandler, 'SysCP Version and Database Version are correct' . "\n");
$cronbasedir = makeCorrectDir($pathtophpfiles . '/scripts/');
$crondir = new DirectoryIterator($cronbasedir);
$cronfilename = basename($_SERVER['PHP_SELF'], '.php');
$cronscriptFullName = makeCorrectFile($cronbasedir . basename($_SERVER['PHP_SELF']));
$inc_crons = array();
foreach($crondir as $file)
{
if(!$file->isDot()
&& !$file->isDir()
&& preg_match("/^" . $cronfilename . "\.inc\.(.*)\.php$/D", $file->getFilename()))
{
if(fileowner($cronscriptFullName) == $file->getOwner()
&& filegroup($cronscriptFullName) == $file->getGroup()
&& $file->isReadable())
{
$inc_crons[] = $file->getPathname();
}
else
{
fwrite($debugHandler, 'WARNING! uid and/or gid of "' . $cronscriptFullName . '" and "' . $file->getPathname() . '" don\'t match! Execution aborted!' . "\n");
fclose($debugHandler);
die('WARNING! uid and/or gid of "' . $cronscriptFullName . '" and "' . $file->getPathname() . '" don\'t match! Execution aborted!');
}
}
}
if(isset($inc_crons[0]))
{
natsort($inc_crons);
foreach($inc_crons as $cfile)
{
fwrite($debugHandler, 'Including ...' . $cfile . "\n");
include_once ($cfile);
}
}
unset($file, $crondir, $cronname, $cronscriptFullName, $cronfilename, $cronbasedir);
fwrite($debugHandler, 'Functions have been included' . "\n");
/**
* Initialize logging
*/
$cronlog = SysCPLogger::getInstanceOf(array('loginname' => 'cronjob'), $db, $settings);
fwrite($debugHandler, 'Logger has been included' . "\n");
?>

46
lib/cron_shutdown.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @author Florian Aders <eleras@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package System
* @version $Id: cron_shutdown.php 2692 2009-03-27 18:04:47Z flo $
*/
if($settings['logger']['log_cron'] == '1')
{
$cronlog->setCronLog(0);
fwrite($debugHandler, 'Logging for cron has been shutdown' . "\n");
}
$db->close();
fwrite($debugHandler, 'Closing database connection' . "\n");
if(isset($db_root))
{
$db_root->close();
fwrite($debugHandler, 'Closing database rootconnection' . "\n");
}
if($keepLockFile === true)
{
fwrite($debugHandler, '=== Keep lockfile because of exception ===');
}
fclose($debugHandler);
if($keepLockFile === false
&& $cronscriptDebug === false)
{
unlink($lockfile);
}

76
lib/functions.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: functions.php 2724 2009-06-07 14:18:02Z flo $
*/
$libdirname = dirname(__FILE__);
includeFunctions($libdirname . '/functions/');
function includeFunctions($dirname)
{
$dirhandle = opendir($dirname);
while(false !== ($filename = readdir($dirhandle)))
{
if($filename != '.' && $filename != '..' && $filename != '')
{
if((substr($filename, 0, 9) == 'function.' || substr($filename, 0, 9) == 'constant.') && substr($filename, -4 ) == '.php')
{
include($dirname . $filename);
}
if(is_dir($dirname . $filename))
{
includeFunctions($dirname . $filename . '/');
}
}
}
closedir($dirhandle);
}
function __autoload($classname)
{
global $libdirname;
findIncludeClass($libdirname . '/classes/', $classname);
}
function findIncludeClass($dirname, $classname)
{
$dirhandle = opendir($dirname);
while(false !== ($filename = readdir($dirhandle)))
{
if($filename != '.' && $filename != '..' && $filename != '')
{
if($filename == 'class.' . $classname . '.php' || $filename == 'abstract.' . $classname . '.php')
{
include($dirname . $filename);
return;
}
if(is_dir($dirname . $filename))
{
findIncludeClass($dirname . $filename . '/', $classname);
}
}
}
closedir($dirhandle);
}
function exportDetails($fielddata, $newfieldvalue)
{
print_r($newfieldvalue);
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.storeSettingApsPhpExtensions.php 2724 2009-06-07 14:18:02Z flo $
*/
function storeSettingApsPhpExtensions($fieldname, $fielddata, $newfieldvalue)
{
$returnvalue = storeSettingField($fieldname, $fielddata, $newfieldvalue);
if($returnvalue !== false && is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'aps' && isset($fielddata['varname']) && $fielddata['varname'] == 'php-extension')
{
$newfieldvalue_array = explode(',', $newfieldvalue);
if(in_array('mcrypt', $newfieldvalue_array))
{
$functions = 'mcrypt_encrypt,mcrypt_decrypt';
}
else
{
$functions = '';
}
if($functions != getSetting('aps', 'php-function'))
{
saveSetting('aps', 'php-function', $functions);
}
}
return $returnvalue;
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.storeSettingApsWebserverModules.php 2724 2009-06-07 14:18:02Z flo $
*/
function storeSettingApsWebserverModules($fieldname, $fielddata, $newfieldvalue)
{
if(is_array($fielddata) && isset($fielddata['settinggroup']) && $fielddata['settinggroup'] == 'aps' && isset($fielddata['varname']) && $fielddata['varname'] == 'webserver-module')
{
$newfieldvalue_array = explode(',', $newfieldvalue);
if(in_array('mod_rewrite', $newfieldvalue_array))
{
// Don't have to guess if we have to remove the leading comma as mod_rewrite is set anyways when we're here...
$newfieldvalue .= ',mod_rewrite.c';
}
if(in_array('htaccess', $newfieldvalue_array))
{
$htaccess = 'htaccess';
}
else
{
$htaccess = '';
}
if($htaccess != getSetting('aps', 'webserver-htaccess'))
{
saveSetting('aps', 'webserver-htaccess', $htaccess);
}
}
return storeSettingField($fieldname, $fielddata, $newfieldvalue);
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.sys_get_temp_dir.php 2724 2009-06-07 14:18:02Z flo $
*/
if(!function_exists('sys_get_temp_dir'))
{
/**
* function will return the temporary directory where we can write data
* function exists as a fallback for php versions lower than 5.2.1
* source copied from php.net
*
* @author Sven Skrabal <info@nexpa.de>
*/
function sys_get_temp_dir()
{
// Try to get from environment variable
if(!empty($_ENV['TMP']))
{
return realpath($_ENV['TMP']);
}
elseif(!empty($_ENV['TMPDIR']))
{
return realpath($_ENV['TMPDIR']);
}
elseif(!empty($_ENV['TEMP']))
{
return realpath($_ENV['TEMP']);
}
else
{
// Detect by creating a temporary file
// Try to use system's temporary directory
// as random name shouldn't exist
$temp_file = tempnam(md5(uniqid(rand(), true)), '');
if($temp_file)
{
$temp_dir = realpath(dirname($temp_file));
unlink($temp_file);
return $temp_dir;
}
else
{
return false;
}
}
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.correctMysqlUsers.php 2724 2009-06-07 14:18:02Z flo $
*/
function correctMysqlUsers($mysql_access_host_array)
{
global $db, $settings, $sql, $sql_root;
foreach($sql_root as $mysql_server => $mysql_server_details)
{
$db_root = new db($mysql_server_details['host'], $mysql_server_details['user'], $mysql_server_details['password'], '');
unset($db_root->password);
$users = array();
$users_result = $db_root->query('SELECT * FROM `mysql`.`user`');
while($users_row = $db_root->fetch_array($users_result))
{
if(!isset($users[$users_row['User']])
|| !is_array($users[$users_row['User']]))
{
$users[$users_row['User']] = array(
'password' => $users_row['Password'],
'hosts' => array()
);
}
$users[$users_row['User']]['hosts'][] = $users_row['Host'];
}
$databases = array(
$sql['db']
);
$databases_result = $db->query('SELECT * FROM `' . TABLE_PANEL_DATABASES . '` WHERE `dbserver` = \'' . $mysql_server . '\'');
while($databases_row = $db->fetch_array($databases_result))
{
$databases[] = $databases_row['databasename'];
}
foreach($databases as $username)
{
if(isset($users[$username])
&& is_array($users[$username])
&& isset($users[$username]['hosts'])
&& is_array($users[$username]['hosts']))
{
$password = $users[$username]['password'];
foreach($mysql_access_host_array as $mysql_access_host)
{
$mysql_access_host = trim($mysql_access_host);
if(!in_array($mysql_access_host, $users[$username]['hosts']))
{
$db_root->query('GRANT ALL PRIVILEGES ON `' . str_replace('_', '\_', $db_root->escape($username)) . '`.* TO `' . $db_root->escape($username) . '`@`' . $db_root->escape($mysql_access_host) . '` IDENTIFIED BY \'password\'');
$db_root->query('SET PASSWORD FOR `' . $db_root->escape($username) . '`@`' . $db_root->escape($mysql_access_host) . '` = \'' . $db_root->escape($password) . '\'');
}
}
foreach($users[$username]['hosts'] as $mysql_access_host)
{
if(!in_array($mysql_access_host, $mysql_access_host_array))
{
$db_root->query('REVOKE ALL PRIVILEGES ON * . * FROM `' . $db_root->escape($username) . '`@`' . $db_root->escape($mysql_access_host) . '`');
$db_root->query('REVOKE ALL PRIVILEGES ON `' . str_replace('_', '\_', $db_root->escape($username)) . '` . * FROM `' . $db_root->escape($username) . '`@`' . $db_root->escape($mysql_access_host) . '`');
$db_root->query('DELETE FROM `mysql`.`user` WHERE `User` = "' . $db_root->escape($username) . '" AND `Host` = "' . $db_root->escape($mysql_access_host) . '"');
}
}
}
}
$db_root->query('FLUSH PRIVILEGES');
$db_root->close();
unset($db_root);
}
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getTables.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Returns an array with all tables with keys which are in the currently selected database
*
* @param db A valid DB-object
* @return array Array with tables and keys
*
* @author Florian Lippert <flo@syscp.org>
*/
function getTables(&$db)
{
// This variable is our return-value
$tables = array();
// The fieldname in the associative array which we get by fetch_array()
$tablefieldname = 'Tables_in_' . $db->database;
// Query for a list of tables in the currently selected database
$tables_result = $db->query('SHOW TABLES');
while($tables_row = $db->fetch_array($tables_result))
{
// Extract tablename
$tablename = $tables_row[$tablefieldname];
// Create sub-array with key tablename
$tables[$tablename] = array();
// Query for a list of indexes of the currently selected table
$keys_result = $db->query('SHOW INDEX FROM ' . $tablename);
while($keys_row = $db->fetch_array($keys_result))
{
// Extract keyname
$keyname = $keys_row['Key_name'];
// If there is aleady a key in our tablename-sub-array with has the same name as our key
// OR if the sequence is not one
// then we have more then index-columns for our keyname
if((isset($tables[$tablename][$keyname]) && $tables[$tablename][$keyname] != '')
|| $keys_row['Seq_in_index'] != '1')
{
// If there is no keyname in the tablename-sub-array set ...
if(!isset($tables[$tablename][$keyname]))
{
// ... then create one
$tables[$tablename][$keyname] = array();
}
// If the keyname-sub-array isn't an array ...
elseif (!is_array($tables[$tablename][$keyname]))
{
// temporary move columname
$tmpkeyvalue = $tables[$tablename][$keyname];
// unset keyname-key
unset($tables[$tablename][$keyname]);
// create new array for keyname-key
$tables[$tablename][$keyname] = array();
// keyindex will be 1 by default, if seq is also 1 we'd better use 0 (this case shouldn't ever occur)
$keyindex = ($keys_row['Seq_in_index'] == '1') ? '0' : '1';
// then move back our tmp columname from above
$tables[$tablename][$keyname][$keyindex] = $tmpkeyvalue;
// end unset the variable afterwards
unset($tmpkeyvalue);
}
// set columname
$tables[$tablename][$keyname][$keys_row['Seq_in_index']] = $keys_row['Column_name'];
}
else
{
// set columname
$tables[$tablename][$keyname] = $keys_row['Column_name'];
}
}
}
return $tables;
}

View File

@@ -0,0 +1,38 @@
<?php
//
// remove_remarks will strip the sql comment lines out of an uploaded sql file
// The whole function has been taken from the phpbb installer, copyright by the phpbb team, phpbb in summer 2004.
//
function remove_remarks($sql)
{
$lines = explode("\n", $sql);
// try to keep mem. use down
$sql = "";
$linecount = count($lines);
$output = "";
for ($i = 0;$i < $linecount;$i++)
{
if(($i != ($linecount - 1))
|| (strlen($lines[$i]) > 0))
{
if(substr($lines[$i], 0, 1) != "#")
{
$output.= $lines[$i] . "\n";
}
else
{
$output.= "\n";
}
// Trading a bit of speed for lower mem. use here.
$lines[$i] = "";
}
}
return $output;
}

View File

@@ -0,0 +1,123 @@
<?php
//
// split_sql_file will split an uploaded sql file into single sql statements.
// Note: expects trim() to have already been run on $sql
// The whole function has been taken from the phpbb installer, copyright by the phpbb team, phpbb in summer 2004.
//
function split_sql_file($sql, $delimiter)
{
// Split up our string into "possible" SQL statements.
$tokens = explode($delimiter, $sql);
// try to save mem.
$sql = "";
$output = array();
// we don't actually care about the matches preg gives us.
$matches = array();
// this is faster than calling count($oktens) every time thru the loop.
$token_count = count($tokens);
for ($i = 0;$i < $token_count;$i++)
{
// Don't wanna add an empty string as the last thing in the array.
if(($i != ($token_count - 1))
|| (strlen($tokens[$i] > 0)))
{
// This is the total number of single quotes in the token.
$total_quotes = preg_match_all("/'/", $tokens[$i], $matches);
// Counts single quotes that are preceded by an odd number of backslashes,
// which means they're escaped quotes.
$escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$i], $matches);
$unescaped_quotes = $total_quotes - $escaped_quotes;
// If the number of unescaped quotes is even, then the delimiter did NOT occur inside a string literal.
if(($unescaped_quotes % 2) == 0)
{
// It's a complete sql statement.
$output[] = $tokens[$i];
// save memory.
$tokens[$i] = "";
}
else
{
// incomplete sql statement. keep adding tokens until we have a complete one.
// $temp will hold what we have so far.
$temp = $tokens[$i] . $delimiter;
// save memory..
$tokens[$i] = "";
// Do we have a complete statement yet?
$complete_stmt = false;
for ($j = $i + 1;(!$complete_stmt && ($j < $token_count));$j++)
{
// This is the total number of single quotes in the token.
$total_quotes = preg_match_all("/'/", $tokens[$j], $matches);
// Counts single quotes that are preceded by an odd number of backslashes,
// which means they're escaped quotes.
$escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$j], $matches);
$unescaped_quotes = $total_quotes - $escaped_quotes;
if(($unescaped_quotes % 2) == 1)
{
// odd number of unescaped quotes. In combination with the previous incomplete
// statement(s), we now have a complete statement. (2 odds always make an even)
$output[] = $temp . $tokens[$j];
// save memory.
$tokens[$j] = "";
$temp = "";
// exit the loop.
$complete_stmt = true;
// make sure the outer loop continues at the right point.
$i = $j;
}
else
{
// even number of unescaped quotes. We still don't have a complete statement.
// (1 odd and 1 even always make an odd)
$temp.= $tokens[$j] . $delimiter;
// save memory.
$tokens[$j] = "";
}
}
// for..
}
// else
}
}
return $output;
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.findDirs.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Returns an array of found directories
*
* This function checks every found directory if they match either $uid or $gid, if they do
* the found directory is valid. It uses recursive function calls to find subdirectories. Due
* to the recursive behauviour this function may consume much memory.
*
* @param string path The path to start searching in
* @param integer uid The uid which must match the found directories
* @param integer gid The gid which must match the found direcotries
* @param array _fileList recursive transport array !for internal use only!
* @return array Array of found valid pathes
*
* @author Martin Burchert <martin.burchert@syscp.de>
* @author Manuel Bernhardt <manuel.bernhardt@syscp.de>
*/
function findDirs($path, $uid, $gid)
{
$list = array(
$path
);
$_fileList = array();
while(sizeof($list) > 0)
{
$path = array_pop($list);
$path = makeCorrectDir($path);
$dh = opendir($path);
if($dh === false)
{
standard_error('cannotreaddir', $path);
return null;
}
else
{
while(false !== ($file = @readdir($dh)))
{
if($file == '.'
&& (fileowner($path . '/' . $file) == $uid || filegroup($path . '/' . $file) == $gid))
{
$_fileList[] = makeCorrectDir($path);
}
if(is_dir($path . '/' . $file)
&& $file != '..'
&& $file != '.')
{
array_push($list, $path . '/' . $file);
}
}
@closedir($dh);
}
}
return $_fileList;
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.isConfigDir.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Checks if a given directory is valid for multiple configurations
* or should rather be used as a single file
*
* @param string The dir
* @return bool true if usable as dir, false otherwise
*
* @author Florian Lippert <flo@syscp.org>
*/
function isConfigDir($dir)
{
if(file_exists($dir))
{
if(is_dir($dir))
{
$returnval = true;
}
else
{
$returnval = false;
}
}
else
{
if(substr($dir, -1) == '/')
{
$returnval = true;
}
else
{
$returnval = false;
}
}
return $returnval;
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.makeCorrectDir.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Function which returns a correct dirname, means to add slashes at the beginning and at the end if there weren't some
*
* @param string The dirname
* @return string The corrected dirname
* @author Florian Lippert <flo@syscp.org>
*/
function makeCorrectDir($dir)
{
if(substr($dir, -1, 1) != '/')
{
$dir.= '/';
}
if(substr($dir, 0, 1) != '/')
{
$dir = '/' . $dir;
}
$dir = makeSecurePath($dir);
return $dir;
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.makeCorrectFile.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Function which returns a correct filename, means to add a slash at the beginning if there wasn't one
*
* @param string filename the filename
* @return string the corrected filename
* @author Florian Lippert <flo@syscp.org>
* @author Michael Russ <mr@edvruss.com>
* @author Martin Burchert <eremit@adm1n.de>
*/
function makeCorrectFile($filename)
{
if(substr($filename, 0, 1) != '/')
{
$filename = '/' . $filename;
}
$filename = makeSecurePath($filename);
return $filename;
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.makePathfield.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Returns a valid html tag for the choosen $fieldType for pathes
*
* @param string path The path to start searching in
* @param integer uid The uid which must match the found directories
* @param integer gid The gid which must match the found direcotries
* @param string fieldType Either "Manual" or "Dropdown"
* @return string The html tag for the choosen $fieldType
*
* @author Martin Burchert <martin.burchert@syscp.de>
* @author Manuel Bernhardt <manuel.bernhardt@syscp.de>
*/
function makePathfield($path, $uid, $gid, $fieldType, $value = '')
{
global $lng;
$value = str_replace($path, '', $value);
$field = '';
if($fieldType == 'Manual')
{
$field = '<input type="text" name="path" value="' . htmlspecialchars($value) . '" size="30" />';
}
elseif($fieldType == 'Dropdown')
{
$dirList = findDirs($path, $uid, $gid);
natcasesort($dirList);
if(sizeof($dirList) > 0)
{
$field = '<select name="path">';
foreach($dirList as $key => $dir)
{
if(strpos($dir, $path) === 0)
{
$dir = makeCorrectDir(substr($dir, strlen($path)));
}
$field.= makeoption($dir, $dir, $value);
}
$field.= '</select>';
}
else
{
$field = $lng['panel']['dirsmissing'];
$field.= '<input type="hidden" name="path" value="/" />';
}
}
return $field;
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.makeSecurePath.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Function which returns a secure path, means to remove all multiple dots and slashes
*
* @param string The path
* @return string The corrected path
* @author Florian Lippert <flo@syscp.org>
*/
function makeSecurePath($path)
{
$search = Array(
'#/+#',
'#\.+#',
'#\0+#'
);
$replace = Array(
'/',
'.',
''
);
$path = preg_replace($search, $replace, $path);
return $path;
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.mkDirWithCorrectOwnership.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Creates a directory below a users homedir and sets all directories,
* which had to be created below with correct Owner/Group
* (Copied from cron_tasks.php:rev1189 as we'll need this more often in future)
*
* @param string The homedir of the user
* @param string The dir which should be created
* @param int The uid of the user
* @param int The gid of the user
* @return bool true if everything went okay, false if something went wrong
*
* @author Florian Lippert <flo@syscp.org>
* @author Martin Burchert <martin.burchert@syscp.org>
*/
function mkDirWithCorrectOwnership($homeDir, $dirToCreate, $uid, $gid)
{
$returncode = true;
if($homeDir != ''
&& $dirToCreate != '')
{
$homeDir = makeCorrectDir($homeDir);
$dirToCreate = makeCorrectDir($dirToCreate);
if(substr($dirToCreate, 0, strlen($homeDir)) == $homeDir)
{
$subdir = substr($dirToCreate, strlen($homeDir));
}
else
{
$subdir = $dirToCreate;
}
$subdir = makeCorrectDir($subdir);
$subdirlen = strlen($subdir);
$subdirs = array();
array_push($subdirs, $dirToCreate);
$offset = 0;
while($offset < $subdirlen)
{
$offset = strpos($subdir, '/', $offset);
$subdirelem = substr($subdir, 0, $offset);
$offset++;
array_push($subdirs, makeCorrectDir($homeDir . $subdirelem));
}
$subdirs = array_unique($subdirs);
sort($subdirs);
foreach($subdirs as $sdir)
{
if(!is_dir($sdir))
{
$sdir = makeCorrectDir($sdir);
safe_exec('mkdir -p ' . escapeshellarg($sdir));
safe_exec('chown -R ' . (int)$uid . ':' . (int)$gid . ' ' . escapeshellarg($sdir));
}
}
}
else
{
$returncode = false;
}
return $returncode;
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.safe_exec.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Wrapper around the exec command.
*
* @author Martin Burchert <eremit@adm1n.de>
* @version 1.2
* @param string exec_string String to be executed
* @return string The result of the exec()
*
* History:
* 1.0 : Initial Version
* 1.1 : Added |,&,>,<,`,*,$,~,? as security breaks.
* 1.2 : Removed * as security break
*/
function safe_exec($exec_string, &$return_value = false)
{
global $settings;
//
// define allowed system commands
//
$allowed_commands = array(
'touch',
'chown',
'mkdir',
'webalizer',
'cp',
'du',
'chmod',
'chattr',
$settings['system']['apachereload_command'],
$settings['system']['bindreload_command'],
$settings['dkim']['dkimrestart_command'],
$settings['system']['awstats_updateall_command'],
'openssl',
'unzip',
'php'
);
//
// check for ; in execute command
//
if((stristr($exec_string, ';'))
or (stristr($exec_string, '|'))
or (stristr($exec_string, '&'))
or (stristr($exec_string, '>'))
or (stristr($exec_string, '<'))
or (stristr($exec_string, '`'))
or (stristr($exec_string, '$'))
or (stristr($exec_string, '~'))
or (stristr($exec_string, '?')))
{
die('SECURITY CHECK FAILED!' . "\n" . 'The execute string "' . htmlspecialchars($exec_string) . '" is a possible security risk!' . "\n" . 'Please check your whole server for security problems by hand!' . "\n");
}
//
// check if command is allowed here
//
$ok = false;
foreach($allowed_commands as $allowed_command)
{
if(strpos($exec_string, $allowed_command) == 0
&& (strlen($exec_string) === ($allowed_command_pos = strlen($allowed_command)) || substr($exec_string, $allowed_command_pos, 1) === ' '))
{
$ok = true;
}
}
if(!$ok)
{
die('SECURITY CHECK FAILED!' . "\n" . 'Your command "' . htmlspecialchars($exec_string) . '" is not allowed!' . "\n" . 'Please check your whole server for security problems by hand!' . "\n");
}
//
// execute the command and return output
//
// --- martin @ 08.08.2005 -------------------------------------------------------
// fixing usage of uninitialised variable
$return = '';
// -------------------------------------------------------------------------------
if($return_value == false)
{
exec($exec_string, $return);
}
else
{
exec($exec_string, $return, $return_value);
}
return $return;
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldDataBool.php 2724 2009-06-07 14:18:02Z flo $
*/
function getFormFieldDataBool($fieldname, $fielddata, $input)
{
if(isset($input[$fieldname]) && ($input[$fieldname] === '1' || $input[$fieldname] === 1 || $input[$fieldname] === true || strtolower($input[$fieldname]) === 'yes' || strtolower($input[$fieldname]) === 'ja'))
{
$newfieldvalue = '1';
}
else
{
$newfieldvalue = '0';
}
return $newfieldvalue;
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldOutputBool.php 2724 2009-06-07 14:18:02Z flo $
*/
function getFormFieldOutputBool($fieldname, $fielddata)
{
$label = $fielddata['label'];
$boolswitch = makeYesNo($fieldname, '1', '0', $fielddata['value']);
eval("\$returnvalue = \"" . getTemplate("formfields/bool", true) . "\";");
return $returnvalue;
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.validateFormFieldBool.php 2724 2009-06-07 14:18:02Z flo $
*/
function validateFormFieldBool($fieldname, $fielddata, $newfieldvalue)
{
if($newfieldvalue === '1' || $newfieldvalue === 1 || $newfieldvalue === true || strtolower($newfieldvalue) === 'yes' || strtolower($newfieldvalue) === 'ja' || $newfieldvalue === '0' || $newfieldvalue === 0 || $newfieldvalue === false || strtolower($newfieldvalue) === 'no' || strtolower($newfieldvalue) === 'nein' || strtolower($newfieldvalue) === '')
{
return true;
}
else
{
return 'noboolean';
}
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: constant.formfields.php 2724 2009-06-07 14:18:02Z flo $
*/
if(!defined('FORMFIELDS_PLAUSIBILITY_CHECK_OK'))
define('FORMFIELDS_PLAUSIBILITY_CHECK_OK', 0);
if(!defined('FORMFIELDS_PLAUSIBILITY_CHECK_ERROR'))
define('FORMFIELDS_PLAUSIBILITY_CHECK_ERROR', 1);
if(!defined('FORMFIELDS_PLAUSIBILITY_CHECK_QUESTION'))
define('FORMFIELDS_PLAUSIBILITY_CHECK_QUESTION', 2);

View File

@@ -0,0 +1,26 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldOutputDate.php 2735 2009-11-06 09:52:59Z flo $
*/
function getFormFieldOutputDate($fieldname, $fielddata)
{
if(isset($fielddata['date_timestamp']) && $fielddata['date_timestamp'] === true)
{
$fielddata['value'] = date('Y-m-d', $fielddata['value']);
}
return getFormFieldOutputString($fieldname, $fielddata);
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.manipulateFormFieldDataDate.php 2735 2009-11-06 09:52:59Z flo $
*/
function manipulateFormFieldDataDate($fieldname, $fielddata, $newfieldvalue)
{
if(isset($fielddata['date_timestamp']) && $fielddata['date_timestamp'] === true)
{
$newfieldvalue = strtotime($newfieldvalue);
}
return $newfieldvalue;
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.validateFormFieldDate.php 2735 2009-11-06 09:52:59Z flo $
*/
function validateFormFieldDate($fieldname, $fielddata, $newfieldvalue)
{
if($newfieldvalue == '0000-00-00' || preg_match('/^(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/', $newfieldvalue))
{
$returnvalue = true;
}
else
{
$returnvalue = false;
}
return $returnvalue;
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.buildForm.php 2724 2009-06-07 14:18:02Z flo $
*/
function buildForm($form)
{
$fields = '';
if(validateFormDefinition($form))
{
foreach($form['groups'] as $groupname => $groupdetails)
{
if(isset($groupdetails['title']) && $groupdetails['title'] != '')
{
$fields .= getFormGroupOutput($groupname, $groupdetails);
}
if(validateFieldDefinition($groupdetails))
{
// Prefetch form fields
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
{
$groupdetails['fields'][$fieldname] = array_merge_prefix($fielddetails, $fielddetails['type'], prefetchFormFieldData($fieldname, $fielddetails));
$form['groups'][$groupname]['fields'][$fieldname] = $groupdetails['fields'][$fieldname];
}
// Collect form field output
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
{
$fields .= getFormFieldOutput($fieldname, $fielddetails);
}
}
}
}
return $fields;
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.checkPlausibilityFormField.php 2724 2009-06-07 14:18:02Z flo $
*/
function checkPlausibilityFormField($fieldname, $fielddata, $newfieldvalue, $allnewfieldvalues)
{
$returnvalue = '';
if(is_array($fielddata) && isset($fielddata['plausibility_check_method']) && $fielddata['plausibility_check_method'] != '' && function_exists($fielddata['plausibility_check_method']))
{
$returnvalue = call_user_func($fielddata['plausibility_check_method'], $fieldname, $fielddata, $newfieldvalue, $allnewfieldvalues);
}
else
{
$returnvalue = false;
}
return $returnvalue;
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldData.php 2724 2009-06-07 14:18:02Z flo $
*/
function getFormFieldData($fieldname, $fielddata, $input)
{
if(is_array($fielddata) && isset($fielddata['type']) && $fielddata['type'] != '' && function_exists('getFormFieldData' . ucfirst($fielddata['type'])))
{
$newfieldvalue = call_user_func('getFormFieldData' . ucfirst($fielddata['type']), $fieldname, $fielddata, &$input);
}
else
{
if(isset($input[$fieldname]))
{
$newfieldvalue = $input[$fieldname];
}
elseif(isset($fielddata['default']))
{
$newfieldvalue = $fielddata['default'];
}
else
{
$newfieldvalue = false;
}
}
return $newfieldvalue;
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldOutput.php 2733 2009-11-06 09:32:00Z flo $
*/
function getFormFieldOutput($fieldname, $fielddata)
{
$returnvalue = '';
if(is_array($fielddata) && isset($fielddata['type']) && $fielddata['type'] != '' && function_exists('getFormFieldOutput' . ucfirst($fielddata['type'])))
{
if(isset($fielddata['label']) && is_array($fielddata['label']))
{
if(isset($fielddata['label']['title']) && isset($fielddata['label']['description']))
{
$fielddata['label'] = '<b>' . $fielddata['label']['title'] . '</b><br />' . $fielddata['label']['description'];
}
else
{
$fielddata['label'] = implode(' ', $fielddata['label']);
}
}
if(!isset($fielddata['value']))
{
if(isset($fielddata['default']))
{
$fielddata['value'] = $fielddata['default'];
}
else
{
$fielddata['value'] = null;
}
}
$returnvalue = call_user_func('getFormFieldOutput' . ucfirst($fielddata['type']), $fieldname, $fielddata);
}
return $returnvalue;
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormGroupOutput.php 2724 2009-06-07 14:18:02Z flo $
*/
function getFormGroupOutput($groupname, $groupdetails)
{
global $lng;
eval("\$group = \"" . getTemplate("settings/settings_group") . "\";");
return $group;
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.manipulateFormFieldData.php 2735 2009-11-06 09:52:59Z flo $
*/
function manipulateFormFieldData($fieldname, $fielddata, $newfieldvalue)
{
if(is_array($fielddata) && isset($fielddata['type']) && $fielddata['type'] != '' && function_exists('manipulateFormFieldData' . ucfirst($fielddata['type'])))
{
$newfieldvalue = call_user_func('manipulateFormFieldData' . ucfirst($fielddata['type']), $fieldname, $fielddata, $newfieldvalue);
}
return $newfieldvalue;
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.prefetchFormFieldData.php 2724 2009-06-07 14:18:02Z flo $
*/
function prefetchFormFieldData($fieldname, $fielddata)
{
$returnvalue = array();
if(is_array($fielddata) && isset($fielddata['type']) && $fielddata['type'] != '' && function_exists('prefetchFormFieldData' . ucfirst($fielddata['type'])))
{
$returnvalue = call_user_func('prefetchFormFieldData' . ucfirst($fielddata['type']), $fieldname, $fielddata);
}
return $returnvalue;
}

View File

@@ -0,0 +1,143 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.processForm.php 2733 2009-11-06 09:32:00Z flo $
*/
function processForm($form, $input, $url_params = array())
{
if(validateFormDefinition($form))
{
$submitted_fields = array();
$changed_fields = array();
$saved_fields = array();
foreach($form['groups'] as $groupname => $groupdetails)
{
if(validateFieldDefinition($groupdetails))
{
// Prefetch form fields
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
{
$groupdetails['fields'][$fieldname] = array_merge_prefix($fielddetails, $fielddetails['type'], prefetchFormFieldData($fieldname, $fielddetails));
$form['groups'][$groupname]['fields'][$fieldname] = $groupdetails['fields'][$fieldname];
}
}
}
foreach($form['groups'] as $groupname => $groupdetails)
{
if(validateFieldDefinition($groupdetails))
{
// Validate fields
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
{
$newfieldvalue = getFormFieldData($fieldname, $fielddetails, &$input);
if($newfieldvalue != $fielddetails['value'])
{
if(($error = validateFormField($fieldname, $fielddetails, $newfieldvalue)) !== true)
{
standard_error($error, $fieldname);
}
else
{
$changed_fields[$fieldname] = $newfieldvalue;
}
}
$submitted_fields[$fieldname] = $newfieldvalue;
}
}
}
foreach($form['groups'] as $groupname => $groupdetails)
{
if(validateFieldDefinition($groupdetails))
{
// Check fields for plausibility
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
{
if(($plausibility_check = checkPlausibilityFormField($fieldname, $fielddetails, $submitted_fields[$fieldname], $submitted_fields)) !== false)
{
if(is_array($plausibility_check) && isset($plausibility_check[0]))
{
if($plausibility_check[0] == FORMFIELDS_PLAUSIBILITY_CHECK_OK)
{
// Nothing to do here, everything's okay
}
elseif($plausibility_check[0] == FORMFIELDS_PLAUSIBILITY_CHECK_ERROR)
{
unset($plausibility_check[0]);
$error = $plausibility_check[1];
unset($plausibility_check[1]);
$targetname = implode(' ', $plausibility_check);
standard_error($error, $targetname);
}
elseif($plausibility_check[0] == FORMFIELDS_PLAUSIBILITY_CHECK_QUESTION)
{
unset($plausibility_check[0]);
$question = $plausibility_check[1];
unset($plausibility_check[1]);
$targetname = implode(' ', $plausibility_check);
if(!isset($input[$question]))
{
if(is_array($url_params) && isset($url_params['filename']))
{
$filename = $url_params['filename'];
unset($url_params['filename']);
}
else
{
$filename = '';
}
ask_yesno($question, $filename, array_merge($url_params, $submitted_fields, array($question => $question)), $targetname);
}
}
else
{
standard_error('plausibilitychecknotunderstood');
}
}
}
}
}
}
foreach($form['groups'] as $groupname => $groupdetails)
{
if(validateFieldDefinition($groupdetails))
{
// Save fields
foreach($groupdetails['fields'] as $fieldname => $fielddetails)
{
if(isset($changed_fields[$fieldname]))
{
if(($saved_field = saveFormField($fieldname, $fielddetails, manipulateFormFieldData($fieldname, $fielddetails, $changed_fields[$fieldname]))) !== false)
{
$saved_fields = array_merge($saved_fields, $saved_field);
}
else
{
standard_error('errorwhensaving', $fieldname);
}
}
}
}
}
// Save form
return saveForm($form, $saved_fields);
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.returnField.php 2735 2009-11-06 09:52:59Z flo $
*/
function returnField($fieldname, $fielddata, $newfieldvalue)
{
return array($fieldname => $newfieldvalue);
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.saveForm.php 2724 2009-06-07 14:18:02Z flo $
*/
function saveForm($fielddata, $newfieldvalue)
{
$returnvalue = '';
if(is_array($fielddata) && isset($fielddata['save_method']) && $fielddata['save_method'] != '' && function_exists($fielddata['save_method']))
{
$returnvalue = call_user_func($fielddata['save_method'], $fielddata, $newfieldvalue);
}
elseif(is_array($fielddata) && !isset($fielddata['save_method']))
{
$returnvalue = true;
}
else
{
$returnvalue = false;
}
return $returnvalue;
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.saveFormField.php 2724 2009-06-07 14:18:02Z flo $
*/
function saveFormField($fieldname, $fielddata, $newfieldvalue)
{
$returnvalue = '';
if(is_array($fielddata) && isset($fielddata['save_method']) && $fielddata['save_method'] != '' && function_exists($fielddata['save_method']))
{
$returnvalue = call_user_func($fielddata['save_method'], $fieldname, $fielddata, $newfieldvalue);
}
elseif(is_array($fielddata) && !isset($fielddata['save_method']))
{
$returnvalue = array();
}
else
{
$returnvalue = false;
}
return $returnvalue;
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.validateFieldDefinition.php 2724 2009-06-07 14:18:02Z flo $
*/
function validateFieldDefinition($field)
{
$returnvalue = false;
if(is_array($field) && !empty($field) && isset($field['fields']) && is_array($field['fields']) && !empty($field['fields']))
{
$returnvalue = true;
}
return $returnvalue;
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.validateFormDefinition.php 2724 2009-06-07 14:18:02Z flo $
*/
function validateFormDefinition($form)
{
$returnvalue = false;
if(is_array($form) && !empty($form) && isset($form['groups']) && is_array($form['groups']) && !empty($form['groups']))
{
$returnvalue = true;
}
return $returnvalue;
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.validateFormField.php 2724 2009-06-07 14:18:02Z flo $
*/
function validateFormField($fieldname, $fielddata, $newfieldvalue)
{
$returnvalue = '';
if(is_array($fielddata) && isset($fielddata['type']) && $fielddata['type'] != '' && function_exists('validateFormField' . ucfirst($fielddata['type'])))
{
$returnvalue = call_user_func('validateFormField' . ucfirst($fielddata['type']), $fieldname, $fielddata, $newfieldvalue);
}
else
{
$returnvalue = 'validation method not found';
}
return $returnvalue;
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldOutputHidden.php 2733 2009-11-06 09:32:00Z flo $
*/
function getFormFieldOutputHidden($fieldname, $fielddata)
{
$returnvalue = '<input type="hidden" name="' . $fieldname . '" value="' . htmlentities($fielddata['value']) . '" />';
if(isset($fielddata['label']) && $fielddata['label'] != '')
{
$label = $fielddata['label'];
$value = htmlentities($fielddata['value']);
eval("\$returnvalue .= \"" . getTemplate("formfields/hidden", true) . "\";");
}
return $returnvalue;
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.validateFormFieldHidden.php 2733 2009-11-06 09:32:00Z flo $
*/
function validateFormFieldHidden($fieldname, $fielddata, $newfieldvalue)
{
if($newfieldvalue === $fielddata['value'])
{
return true;
}
else
{
// TODO: Throw some error that actually makes sense - false would just throw unknown error
return false;
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldDataInt.php 2724 2009-06-07 14:18:02Z flo $
*/
function getFormFieldDataInt($fieldname, $fielddata, $input)
{
if(isset($input[$fieldname]))
{
$newfieldvalue = (int)$input[$fieldname];
}
else
{
$newfieldvalue = (int)$fielddata['default'];
}
return $newfieldvalue;
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldOutputInt.php 2724 2009-06-07 14:18:02Z flo $
*/
function getFormFieldOutputInt($fieldname, $fielddata)
{
return getFormFieldOutputString($fieldname, $fielddata);
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.validateFormFieldInt.php 2724 2009-06-07 14:18:02Z flo $
*/
function validateFormFieldInt($fieldname, $fielddata, $newfieldvalue)
{
if(isset($fielddata['int_min']) && (int)$newfieldvalue < (int)$fielddata['int_min'])
{
return('intvaluetoolow');
}
if(isset($fielddata['int_max']) && (int)$newfieldvalue > (int)$fielddata['int_max'])
{
return('intvaluetoohigh');
}
return true;
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldOutputLabel.php 2724 2009-06-07 14:18:02Z flo $
*/
function getFormFieldOutputLabel($fieldname, $fielddata)
{
$label = $fielddata['label'];
eval("\$returnvalue = \"" . getTemplate("formfields/label", true) . "\";");
return $returnvalue;
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.validateFormFieldLabel.php 2733 2009-11-06 09:32:00Z flo $
*/
function validateFormFieldLabel($fieldname, $fielddata, $newfieldvalue)
{
// Return false, in case we happen to have that field in our $input array, so someone doesn't get the chance to save crap to our database
// TODO: Throw some error that actually makes sense - false would just throw unknown error
return false;
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldDataOption.php 2724 2009-06-07 14:18:02Z flo $
*/
function getFormFieldDataOption($fieldname, $fielddata, $input)
{
if(isset($input[$fieldname]))
{
$newfieldvalue = $input[$fieldname];
}
else
{
$newfieldvalue = $fielddata['default'];
}
if(is_array($newfieldvalue))
{
$newfieldvalue = implode(',', $newfieldvalue);
}
return $newfieldvalue;
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldOutputOption.php 2724 2009-06-07 14:18:02Z flo $
*/
function getFormFieldOutputOption($fieldname, $fielddata)
{
$returnvalue = '';
if(isset($fielddata['option_options']) && is_array($fielddata['option_options']) && !empty($fielddata['option_options']))
{
if(isset($fielddata['option_mode']) && $fielddata['option_mode'] == 'multiple')
{
$multiple = true;
$fielddata['value'] = explode(',', $fielddata['value']);
}
else
{
$multiple = false;
}
$label = $fielddata['label'];
$options_array = $fielddata['option_options'];
$options = '';
foreach($options_array as $value => $title)
{
$options .= makeoption($title, $value, $fielddata['value']);
}
eval("\$returnvalue = \"" . getTemplate("formfields/option", true) . "\";");
}
return $returnvalue;
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.prefetchFormFieldDataOption.php 2724 2009-06-07 14:18:02Z flo $
*/
function prefetchFormFieldDataOption($fieldname, $fielddata)
{
$returnvalue = array();
if((!isset($fielddata['option_options']) || !is_array($fielddata['option_options']) || empty($fielddata['option_options'])) && (isset($fielddata['option_options_method']) && function_exists($fielddata['option_options_method'])))
{
$returnvalue['options'] = call_user_func($fielddata['option_options_method']);
}
return $returnvalue;
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.validateFormFieldOption.php 2724 2009-06-07 14:18:02Z flo $
*/
function validateFormFieldOption($fieldname, $fielddata, $newfieldvalue)
{
$returnvalue = true;
if(isset($fielddata['option_mode']) && $fielddata['option_mode'] == 'multiple')
{
$options = explode(',', $newfieldvalue);
foreach($options as $option)
{
$returnvalue = ($returnvalue && isset($fielddata['option_options'][$option]));
}
}
else
{
$returnvalue = isset($fielddata['option_options'][$newfieldvalue]);
}
if($returnvalue === true)
{
return true;
}
else
{
return 'not in option';
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldOutputString.php 2724 2009-06-07 14:18:02Z flo $
*/
function getFormFieldOutputString($fieldname, $fielddata)
{
$label = $fielddata['label'];
$value = htmlentities($fielddata['value']);
eval("\$returnvalue = \"" . getTemplate("formfields/string", true) . "\";");
return $returnvalue;
}

View File

@@ -0,0 +1,99 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.validateFormFieldString.php 2724 2009-06-07 14:18:02Z flo $
*/
function validateFormFieldString($fieldname, $fielddata, $newfieldvalue)
{
if(isset($fielddata['string_delimiter']) && $fielddata['string_delimiter'] != '')
{
$newfieldvalues = explode($fielddata['string_delimiter'], $newfieldvalue);
unset($fielddata['string_delimiter']);
$returnvalue = true;
foreach($newfieldvalues as $single_newfieldvalue)
{
$single_returnvalue = validateFormFieldString($fieldname, $fielddata, $single_newfieldvalue);
if($single_returnvalue !== true)
{
$returnvalue = $single_returnvalue;
break;
}
}
}
else
{
$returnvalue = false;
if(isset($fielddata['string_type']) && $fielddata['string_type'] == 'mail')
{
$returnvalue = (filter_var($newfieldvalue, FILTER_VALIDATE_EMAIL) == $newfieldvalue);
}
elseif(isset($fielddata['string_type']) && $fielddata['string_type'] == 'url')
{
$returnvalue = validateUrl($newfieldvalue);
}
elseif(isset($fielddata['string_type']) && $fielddata['string_type'] == 'dir')
{
$returnvalue = ($newfieldvalue == makeCorrectDir($newfieldvalue));
}
elseif(isset($fielddata['string_type']) && $fielddata['string_type'] == 'file')
{
$returnvalue = ($newfieldvalue == makeCorrectFile($newfieldvalue));
}
elseif(isset($fielddata['string_type']) && $fielddata['string_type'] == 'filedir')
{
$returnvalue = (($newfieldvalue == makeCorrectDir($newfieldvalue)) || ($newfieldvalue == makeCorrectFile($newfieldvalue)));
}
elseif(preg_match('/^[^\r\n\t\f\0]*$/D', $newfieldvalue))
{
$returnvalue = true;
}
if(isset($fielddata['string_regexp']) && $fielddata['string_regexp'] != '')
{
if(preg_match($fielddata['string_regexp'], $newfieldvalue))
{
$returnvalue = true;
}
else
{
$returnvalue = false;
}
}
if(isset($fielddata['string_emptyallowed']) && $fielddata['string_emptyallowed'] === true && $newfieldvalue === '')
{
$returnvalue = true;
}
elseif(isset($fielddata['string_emptyallowed']) && $fielddata['string_emptyallowed'] === false && $newfieldvalue === '')
{
$returnvalue = 'stringmustntbeempty';
}
}
if($returnvalue === true)
{
return true;
}
elseif($returnvalue === false)
{
return 'stringformaterror';
}
else
{
return $returnvalue;
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getFormFieldOutputText.php 2724 2009-06-07 14:18:02Z flo $
*/
function getFormFieldOutputText($fieldname, $fielddata)
{
$label = $fielddata['label'];
$value = htmlentities($fielddata['value']);
eval("\$returnvalue = \"" . getTemplate("formfields/text", true) . "\";");
return $returnvalue;
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.validateFormFieldText.php 2724 2009-06-07 14:18:02Z flo $
*/
function validateFormFieldText($fieldname, $fielddata, $newfieldvalue)
{
$returnvalue = 'stringformaterror';
if(preg_match('/^[^\0]*$/', $newfieldvalue))
{
$returnvalue = true;
}
return $returnvalue;
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: constant.logger.php 2724 2009-06-07 14:18:02Z flo $
*/
if(!defined('USR_ACTION'))
define('USR_ACTION', '10');
if(!defined('RES_ACTION'))
define('RES_ACTION', '20');
if(!defined('ADM_ACTION'))
define('ADM_ACTION', '30');
if(!defined('CRON_ACTION'))
define('CRON_ACTION', '40');
if(!defined('LOG_ERROR'))
define('LOG_ERROR', '99');

View File

@@ -0,0 +1,65 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.ask_yesno.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Prints Question on screen
*
* @param string The question
* @param string File which will be called with POST if user clicks yes
* @param array Values which will be given to $yesfile. Format: array(variable1=>value1, variable2=>value2, variable3=>value3)
* @param string Name of the target eg Domain or eMail address etc.
* @author Florian Lippert <flo@syscp.org>
*/
function ask_yesno($text, $yesfile, $params = array(), $targetname = '')
{
global $userinfo, $db, $s, $header, $footer, $lng;
/*
// For compatibility reasons (if $params contains a string like "field1=value1;field2=value2") this will convert it into a usable array
if(!is_array($params))
{
$params_tmp=explode(';',$params);
unset($params);
$params=array();
while(list(,$param_tmp)=each($params_tmp))
{
$param_tmp=explode('=',$param_tmp);
$params[$param_tmp[0]]=$param_tmp[1];
}
}
*/
$hiddenparams = '';
if(is_array($params))
{
foreach($params as $field => $value)
{
$hiddenparams.= '<input type="hidden" name="' . htmlspecialchars($field) . '" value="' . htmlspecialchars($value) . '" />' . "\n";
}
}
if(isset($lng['question'][$text]))
{
$text = $lng['question'][$text];
}
$text = strtr($text, array('%s' => $targetname));
eval("echo \"" . getTemplate('misc/question_yesno', '1') . "\";");
exit;
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.buildNavigation.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Build Navigation Sidebar
* @param array navigation data
* @param array userinfo the userinfo of the user
* @return string the content of the navigation bar
*
* @author Florian Lippert <flo@syscp.org>
*/
function buildNavigation($navigation, $userinfo)
{
$returnvalue = '';
foreach($navigation as $box)
{
if((!isset($box['show_element']) || $box['show_element'] === true) &&
(!isset($box['required_resources']) || $box['required_resources'] == '' || (isset($userinfo[$box['required_resources']]) && ((int)$userinfo[$box['required_resources']] > 0 || $userinfo[$box['required_resources']] == '-1'))))
{
$navigation_links = '';
foreach($box['elements'] as $element_id => $element)
{
if((!isset($element['show_element']) || $element['show_element'] === true) &&
(!isset($element['required_resources']) || $element['required_resources'] == '' || (isset($userinfo[$element['required_resources']]) && ((int)$userinfo[$element['required_resources']] > 0 || $userinfo[$element['required_resources']] == '-1'))))
{
if(isset($element['url']) && trim($element['url']) != '')
{
// append sid only to local
if(!preg_match('/^https?\:\/\//', $element['url'])
&& (isset($userinfo['hash']) && $userinfo['hash'] != ''))
{
// generate sid with ? oder &
if(strpos($element['url'], '?') !== false)
{
$element['url'].= '&s=' . $userinfo['hash'];
}
else
{
$element['url'].= '?s=' . $userinfo['hash'];
}
}
$target = '';
if(isset($element['new_window']) && $element['new_window'] == true)
{
$target = ' target="_blank"';
}
$completeLink = '<a href="' . htmlspecialchars($element['url']) . '"' . $target . ' class="menu">' . $element['label'] . '</a>';
}
else
{
$completeLink = $element['label'];
}
eval("\$navigation_links .= \"" . getTemplate("navigation_link", 1) . "\";");
}
}
if($navigation_links != '')
{
if(isset($box['url']) && trim($box['url']) != '')
{
// append sid only to local
if(!preg_match('/^https?\:\/\//', $box['url'])
&& (isset($userinfo['hash']) && $userinfo['hash'] != ''))
{
// generate sid with ? oder &
if(strpos($box['url'], '?') !== false)
{
$box['url'].= '&s=' . $userinfo['hash'];
}
else
{
$box['url'].= '?s=' . $userinfo['hash'];
}
}
$target = '';
if(isset($box['new_window']) && $box['new_window'] == true)
{
$target = ' target="_blank"';
}
$completeLink = '<a href="' . htmlspecialchars($box['url']) . '"' . $target . ' class="menu">' . $box['label'] . '</a>';
}
else
{
$completeLink = $box['label'];
}
eval("\$returnvalue .= \"" . getTemplate("navigation_element", 1) . "\";");
}
}
}
return $returnvalue;
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getCorrectFullUserDetails.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Returns full style user details "Name, Firstname | Company"
*
* @param array An array with keys firstname, name and company
* @return string The full details
*
* @author Florian Lippert <flo@syscp.org>
*/
function getCorrectFullUserDetails($userinfo)
{
$returnval = '';
if(isset($userinfo['firstname']) && isset($userinfo['name']) && isset($userinfo['company']))
{
if($userinfo['company'] == '')
{
$returnval = $userinfo['name'] . ', ' . $userinfo['firstname'];
}
else
{
if($userinfo['name'] != ''
&& $userinfo['firstname'] != '')
{
$returnval = $userinfo['name'] . ', ' . $userinfo['firstname'] . ' | ' . $userinfo['company'];
}
else
{
$returnval = $userinfo['company'];
}
}
}
return $returnval;
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getCorrectUserSalutation.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Returns correct user salutation, either "Firstname Name" or "Company"
*
* @param array An array with keys firstname, name and company
* @return string The correct salutation
*
* @author Florian Lippert <flo@syscp.org>
*/
function getCorrectUserSalutation($userinfo)
{
$returnval = '';
if(isset($userinfo['firstname']) && isset($userinfo['name']) && isset($userinfo['company']))
{
// Always prefer firstname name
if($userinfo['company'] != '' && $userinfo['name'] == '' && $userinfo['firstname'] == '')
{
$returnval = $userinfo['company'];
}
else
{
$returnval = $userinfo['firstname'] . ' ' . $userinfo['name'];
}
}
return $returnval;
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getTemplate.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Get template from filesystem
*
* @param string Templatename
* @param string noarea If area should be used to get template
* @return string The Template
* @author Florian Lippert <flo@syscp.org>
*/
function getTemplate($template, $noarea = 0)
{
global $templatecache;
if($noarea != 1)
{
$template = AREA . '/' . $template;
}
if(!isset($templatecache[$template]))
{
$filename = './templates/' . $template . '.tpl';
if(file_exists($filename)
&& is_readable($filename))
{
$templatefile = addcslashes(file_get_contents($filename), '"\\');
// loop through template more than once in case we have an "if"-statement in another one
while(preg_match('/<if[ \t]*(.*)>(.*)(<\/if>|<else>(.*)<\/if>)/Uis', $templatefile))
{
$templatefile = preg_replace('/<if[ \t]*(.*)>(.*)(<\/if>|<else>(.*)<\/if>)/Uis', '".( ($1) ? ("$2") : ("$4") )."', $templatefile);
}
}
else
{
$templatefile = 'TEMPLATE NOT FOUND: ' . $filename;
}
$templatecache[$template] = $templatefile;
}
return $templatecache[$template];
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.makecheckbox.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Return HTML Code for a checkbox
*
* @param string The fieldname
* @param string The captions
* @param string The Value which will be returned
* @param bool Add a <br /> at the end of the checkbox
* @param string Values which will be selected by default
* @param bool Whether the title may contain html or not
* @param bool Whether the value may contain html or not
* @return string HTML Code
* @author Michael Kaufmann <mkaufmann@nutime.de>
*/
function makecheckbox($name, $title, $value, $break = false, $selvalue = NULL, $title_trusted = false, $value_trusted = false)
{
if($selvalue !== NULL
&& $value == $selvalue)
{
$checked = 'checked="checked"';
}
else
{
$checked = '';
}
if(!$title_trusted)
{
$title = htmlspecialchars($title);
}
if(!$value_trusted)
{
$value = htmlspecialchars($value);
}
$checkbox = '<input type="checkbox" name="' . $name . '" value="' . $value . '" ' . $checked . ' />&nbsp;' . $title;
if($break)
{
$checkbox.= '<br />';
}
return $checkbox;
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.makeoption.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Return HTML Code for an option within a <select>
*
* @param string The caption
* @param string The Value which will be returned
* @param string Values which will be selected by default.
* @param bool Whether the title may contain html or not
* @param bool Whether the value may contain html or not
* @return string HTML Code
* @author Florian Lippert <flo@syscp.org>
*/
function makeoption($title, $value, $selvalue = NULL, $title_trusted = false, $value_trusted = false)
{
if($selvalue !== NULL
&& ((is_array($selvalue) && in_array($value, $selvalue)) || $value == $selvalue))
{
$selected = 'selected="selected"';
}
else
{
$selected = '';
}
if(!$title_trusted)
{
$title = htmlspecialchars($title);
}
if(!$value_trusted)
{
$value = htmlspecialchars($value);
}
$option = '<option value="' . $value . '" ' . $selected . ' >' . $title . '</option>';
return $option;
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.makeyesno.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Returns HTML Code for two radio buttons with two choices: yes and no
*
* @param string Name of HTML-Variable
* @param string Value which will be returned if user chooses yes
* @param string Value which will be returned if user chooses no
* @param string Value which is chosen by default
* @return string HTML Code
* @author Florian Lippert <flo@syscp.org>
*/
function makeyesno($name, $yesvalue, $novalue = '', $yesselected = '')
{
global $lng;
return '<select class="dropdown_noborder" name="' . $name . '"><option value="' . $yesvalue . '"' . ($yesselected ? ' selected="selected"' : '') . '>' . $lng['panel']['yes'] . '</option><option value="' . $novalue . '"' . ($yesselected ? '' : ' selected="selected"') . '>' . $lng['panel']['no'] . '</option></select>';
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.redirectTo.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Sends an header ( 'Location ...' ) to the browser.
*
* @param string Destination
* @param array Get-Variables
* @param boolean if the target we are creating for a redirect
* should be a relative or an absolute url
*
* @return boolean false if params is not an array
*
* @author Florian Lippert <flo@syscp.org>
* @author Martin Burchert <eremit@syscp.org>
*
* @changes martin@2005-01-29
* - added isRelative parameter
* - speed up the url generation
* - fixed bug #91
*/
function redirectTo($destination, $get_variables = array(), $isRelative = false)
{
$params = array();
if(is_array($get_variables))
{
foreach($get_variables as $key => $value)
{
$params[] = urlencode($key) . '=' . urlencode($value);
}
$params = '?' . implode($params, '&');
if($isRelative)
{
$protocol = '';
$host = '';
$path = './';
}
else
{
if(isset($_SERVER['HTTPS'])
&& strtolower($_SERVER['HTTPS']) == 'on')
{
$protocol = 'https://';
}
else
{
$protocol = 'http://';
}
$host = $_SERVER['HTTP_HOST'];
if(dirname($_SERVER['PHP_SELF']) == '/')
{
$path = '/';
}
else
{
$path = dirname($_SERVER['PHP_SELF']) . '/';
}
}
header('Location: ' . $protocol . $host . $path . $destination . $params);
exit;
}
elseif($get_variables == null)
{
header('Location: ' . $destination);
exit;
}
return false;
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.standard_error.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Prints one ore more errormessages on screen
*
* @param array Errormessages
* @param string A %s in the errormessage will be replaced by this string.
* @author Florian Lippert <flo@syscp.org>
* @author Ron Brand <ron.brand@web.de>
*/
function standard_error($errors = '', $replacer = '')
{
global $db, $userinfo, $s, $header, $footer, $lng;
$replacer = htmlentities($replacer);
if(!is_array($errors))
{
$errors = array(
$errors
);
}
$error = '';
foreach($errors as $single_error)
{
if(isset($lng['error'][$single_error]))
{
$single_error = $lng['error'][$single_error];
$single_error = strtr($single_error, array('%s' => $replacer));
}
else
{
$error = 'Unknown Error (' . $single_error . '): ' . $replacer;
break;
}
if(empty($error))
{
$error = $single_error;
}
else
{
$error.= ' ' . $single_error;
}
}
eval("echo \"" . getTemplate('misc/error', '1') . "\";");
exit;
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.standard_success.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Prints one ore more errormessages on screen
*
* @param array Errormessages
* @param string A %s in the errormessage will be replaced by this string.
* @author Florian Lippert <flo@syscp.org>
*/
function standard_success($success_message = '', $replacer = '', $params = array())
{
global $s, $header, $footer, $lng;
if(isset($lng['success'][$success_message]))
{
$success_message = strtr($lng['success'][$success_message], array('%s' => htmlentities($replacer)));
}
if(is_array($params) && isset($params['filename']))
{
$redirect_url = $params['filename'] . '?s=' . $s;
unset($params['filename']);
foreach($params as $varname => $value)
{
if($value != '')
{
$redirect_url .= '&amp;' . $varname . '=' . $value;
}
}
}
else
{
$redirect_url = '';
}
eval("echo \"" . getTemplate('misc/success', '1') . "\";");
exit;
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.array_merge_prefix.php 2724 2009-06-07 14:18:02Z flo $
*/
function array_merge_prefix($array1, $key_prefix, $array2)
{
if(is_array($array1) && is_array($array2))
{
if($key_prefix != '')
{
foreach($array2 as $key => $value)
{
$array1[$key_prefix . '_' . $key] = $value;
unset($array2[$key]);
}
unset($array2);
return $array1;
}
else
{
return array_merge($array1, $array2);
}
}
else
{
return $array1;
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.array_trim.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Returns Array, whose elements have been checked whether thay are empty or not
*
* @param array The array to trim
* @return array The trim'med array
* @author Florian Lippert <flo@syscp.org>
*/
function array_trim($source)
{
$returnval = array();
if(is_array($source))
{
while(list($var, $val) = each($source))
{
if($val != ' '
&& $val != '')$returnval[$var] = $val;
}
}
else
{
$returnval = $source;
}
return $returnval;
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.doubleval_ressource.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Returns a double of the given value which isn't negative.
* Returns -1 if the given value was -1.
*
* @param any The value
* @return double The positive value
* @author Florian Lippert <flo@syscp.org>
*/
function doubleval_ressource($the_value)
{
$the_value = doubleval($the_value);
if($the_value < 0
&& $the_value != '-1')
{
$the_value*= - 1;
}
return $the_value;
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.html_entity_decode_array.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Wrapper around html_entity_decode to handle arrays, with the advantage that you
* can select which fields should be handled by htmlentities and with advantage,
* that you can eliminate all html entities by setting complete=true
*
* @param array The subject array
* @param string The fields which should be checked for, separated by spaces
* @param bool Select true to use html_entity_decode_complete instead of html_entity_decode
* @param int See php documentation about this
* @param string See php documentation about this
* @return array The array with html_entity_decode'd strings
* @author Florian Lippert <flo@syscp.org>
*/
function html_entity_decode_array($subject, $fields = '', $complete = false, $quote_style = ENT_COMPAT, $charset = 'ISO-8859-1')
{
if(is_array($subject))
{
if(!is_array($fields))
{
$fields = array_trim(explode(' ', $fields));
}
foreach($subject as $field => $value)
{
if((!is_array($fields) || empty($fields))
|| (is_array($fields) && !empty($fields) && in_array($field, $fields)))
{
/**
* Just call ourselve to manage multi-dimensional arrays
*/
$subject[$field] = html_entity_decode_array($subject[$field], $fields, $complete, $quote_style, $charset);
}
}
}
else
{
if($complete == true)
{
$subject = html_entity_decode_complete($subject, $quote_style, $charset);
}
else
{
$subject = html_entity_decode($subject, $quote_style, $charset);
}
}
return $subject;
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.html_entity_decode_complete.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Calls html_entity_decode in a loop until the result doesn't differ from original anymore
*
* @param string The string in which the html entities should be eliminated.
* @return string The cleaned string
* @author Florian Lippert <flo@syscp.org>
*/
function html_entity_decode_complete($string)
{
while($string != html_entity_decode($string))
{
$string = html_entity_decode($string);
}
return $string;
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.htmlentities_array.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Wrapper around htmlentities to handle arrays, with the advantage that you
* can select which fields should be handled by htmlentities
*
* @param array The subject array
* @param string The fields which should be checked for, separated by spaces
* @param int See php documentation about this
* @param string See php documentation about this
* @return array The array with htmlentitie'd strings
* @author Florian Lippert <flo@syscp.org>
*/
function htmlentities_array($subject, $fields = '', $quote_style = ENT_COMPAT, $charset = 'ISO-8859-1')
{
if(is_array($subject))
{
if(!is_array($fields))
{
$fields = array_trim(explode(' ', $fields));
}
foreach($subject as $field => $value)
{
if((!is_array($fields) || empty($fields))
|| (is_array($fields) && !empty($fields) && in_array($field, $fields)))
{
/**
* Just call ourselve to manage multi-dimensional arrays
*/
$subject[$field] = htmlentities_array($subject[$field], $fields, $quote_style, $charset);
}
}
}
else
{
$subject = htmlentities($subject, $quote_style, $charset);
}
return $subject;
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.intval_ressource.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Returns an integer of the given value which isn't negative.
* Returns -1 if the given value was -1.
*
* @param any The value
* @return int The positive value
* @author Florian Lippert <flo@syscp.org>
*/
function intval_ressource($the_value)
{
$the_value = intval($the_value);
if($the_value < 0
&& $the_value != '-1')
{
$the_value*= - 1;
}
return $the_value;
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.replace_variables.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Replaces all occurences of variables defined in the second argument
* in the first argument with their values.
*
* @param string The string that should be searched for variables
* @param array The array containing the variables with their values
* @return string The submitted string with the variables replaced.
* @author Michael Duergner
*/
function replace_variables($text, $vars)
{
$pattern = "/\{([a-zA-Z0-9\-_]+)\}/";
// --- martin @ 08.08.2005 -------------------------------------------------------
// fixing usage of uninitialised variable
$matches = array();
// -------------------------------------------------------------------------------
if(count($vars) > 0
&& preg_match_all($pattern, $text, $matches))
{
for ($i = 0;$i < count($matches[1]);$i++)
{
$current = $matches[1][$i];
if(isset($vars[$current]))
{
$var = $vars[$current];
$text = str_replace("{" . $current . "}", $var, $text);
}
}
}
$text = str_replace('\n', "\n", $text);
return $text;
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.str_replace_array.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Replaces Strings in an array, with the advantage that you
* can select which fields should be str_replace'd
*
* @param mixed String or array of strings to search for
* @param mixed String or array to replace with
* @param array The subject array
* @param string The fields which should be checked for, separated by spaces
* @return array The str_replace'd array
* @author Florian Lippert <flo@syscp.org>
*/
function str_replace_array($search, $replace, $subject, $fields = '')
{
if(is_array($subject))
{
$fields = array_trim(explode(' ', $fields));
foreach($subject as $field => $value)
{
if((!is_array($fields) || empty($fields))
|| (is_array($fields) && !empty($fields) && in_array($field, $fields)))
{
$subject[$field] = str_replace($search, $replace, $subject[$field]);
}
}
}
else
{
$subject = str_replace($search, $replace, $subject);
}
return $subject;
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.stripslashes_array.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Wrapper around stripslashes to handle arrays, with the advantage that you
* can select which fields should be handled by htmlentities and with advantage,
* that you can eliminate all slashes by setting complete=true
*
* @param array The subject array
* @param int See php documentation about this
* @param string See php documentation about this
* @param string The fields which should be checked for, separated by spaces
* @param bool Select true to use stripslashes_complete instead of stripslashes
* @return array The array with stripslashe'd strings
* @author Florian Lippert <flo@syscp.org>
*/
function stripslashes_array($subject, $fields = '', $complete = false)
{
if(is_array($subject))
{
if(!is_array($fields))
{
$fields = array_trim(explode(' ', $fields));
}
foreach($subject as $field => $value)
{
if((!is_array($fields) || empty($fields))
|| (is_array($fields) && !empty($fields) && in_array($field, $fields)))
{
/**
* Just call ourselve to manage multi-dimensional arrays
*/
$subject[$field] = stripslashes_array($subject[$field], $fields, $complete);
}
}
}
else
{
if($complete == true)
{
$subject = stripslashes_complete($subject);
}
else
{
$subject = stripslashes($subject);
}
}
return $subject;
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.stripslashes_complete.php 2724 2009-06-07 14:18:02Z flo $
*/
/**
* Calls stripslashes in a loop until the result doesn't differ from original anymore
*
* @param string The string in which the slashes should be eliminated.
* @return string The cleaned string
* @author Florian Lippert <flo@syscp.org>
*/
function stripslashes_complete($string)
{
while($string != stripslashes($string))
{
$string = stripslashes($string);
}
return $string;
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* This file is part of the SysCP project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.syscp.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org>
* @license GPLv2 http://files.syscp.org/misc/COPYING.txt
* @package Functions
* @version $Id: function.getSetting.php 2724 2009-06-07 14:18:02Z flo $
*/
function getSetting($settinggroup, $varname)
{
global $settings;
if(isset($settings[$settinggroup]) && is_array($settings[$settinggroup]) && isset($settings[$settinggroup][$varname]))
{
return $settings[$settinggroup][$varname];
}
else
{
return false;
}
}

Some files were not shown because too many files have changed in this diff Show More