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;
}
}
}
?>