Commit ccbf1497 authored by Till Brehm's avatar Till Brehm

- Added templating library to installer.

- Added function to detect the apache version to installer.
- Added support for apache 2.4 to vhots templates for ispconfig vhost and apps vhost in installer.
parent b846a278
......@@ -645,10 +645,12 @@ class installer_dist extends installer_base {
$vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
$vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
// copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apache_ispconfig.conf.master', 'tpl/apache_ispconfig.conf.master');
$tpl = new tpl('apache_ispconfig.conf.master');
$tpl->setVar('apache_version',getapacheversion());
$records = $this->db->queryAllRecords('SELECT * FROM '.$conf['mysql']['master_database'].'.server_ip WHERE server_id = '.$conf['server_id']." AND virtualhost = 'y'");
$ip_addresses = array();
if(is_array($records) && count($records) > 0) {
foreach($records as $rec) {
if($rec['ip_type'] == 'IPv6') {
......@@ -661,15 +663,15 @@ class installer_dist extends installer_base {
foreach($ports as $port) {
$port = intval($port);
if($port > 0 && $port < 65536 && $ip_address != '') {
$content .= 'NameVirtualHost '.$ip_address.":".$port."\n";
$ip_addresses[] = array('ip_address' => $ip_address, 'port' => $port);
}
}
}
}
}
$content .= "\n";
wf($vhost_conf_dir.'/ispconfig.conf', $content);
wf($vhost_conf_dir.'/ispconfig.conf', $tpl->grab());
unset($tpl);
if(!@is_link($vhost_conf_enabled_dir."/000-ispconfig.conf")) {
exec("ln -s ".$vhost_conf_dir."/ispconfig.conf ".$vhost_conf_enabled_dir."/000-ispconfig.conf");
......@@ -1033,28 +1035,30 @@ class installer_dist extends installer_base {
// Dont just copy over the virtualhost template but add some custom settings
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apache_ispconfig.vhost.master', "tpl/apache_ispconfig.vhost.master");
$content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
$tpl = new tpl('apache_ispconfig.vhost.master');
$tpl->setVar('vhost_port',$conf['apache']['vhost_port']);
// comment out the listen directive if port is 80 or 443
if($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) {
$content = str_replace('{vhost_port_listen}', '#', $content);
$tpl->setVar('vhost_port_listen','#');
} else {
$content = str_replace('{vhost_port_listen}', '', $content);
$tpl->setVar('vhost_port_listen','');
}
if(is_file('/usr/local/ispconfig/interface/ssl/ispserver.crt') && is_file('/usr/local/ispconfig/interface/ssl/ispserver.key')) {
$content = str_replace('{ssl_comment}', '', $content);
if(is_file($install_dir.'/interface/ssl/ispserver.crt') && is_file($install_dir.'/interface/ssl/ispserver.key')) {
$tpl->setVar('ssl_comment','');
} else {
$content = str_replace('{ssl_comment}', '#', $content);
$tpl->setVar('ssl_comment','#');
}
if(is_file($install_dir.'/interface/ssl/ispserver.crt') && is_file($install_dir.'/interface/ssl/ispserver.key') && is_file($install_dir.'/interface/ssl/ispserver.bundle')) {
$content = str_replace('{ssl_bundle_comment}', '', $content);
$tpl->setVar('ssl_bundle_comment','');
} else {
$content = str_replace('{ssl_bundle_comment}', '#', $content);
$tpl->setVar('ssl_bundle_comment','#');
}
$tpl->setVar('apache_version',getapacheversion());
wf("$vhost_conf_dir/ispconfig.vhost", $content);
wf($vhost_conf_dir.'/ispconfig.vhost', $tpl->grab());
//copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
//* and create the symlink
......
......@@ -495,6 +495,7 @@ class installer extends installer_base
//* Copy the ISPConfig configuration include
/*
$content = $this->get_template_file('apache_ispconfig.conf', true);
$records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
......@@ -507,6 +508,35 @@ class installer extends installer_base
}
$this->write_config_file($conf['apache']['vhost_conf_dir'].'/000-ispconfig.conf', $content);
*/
$tpl = new tpl('apache_ispconfig.conf.master');
$tpl->setVar('apache_version',getapacheversion());
$records = $this->db->queryAllRecords('SELECT * FROM '.$conf['mysql']['master_database'].'.server_ip WHERE server_id = '.$conf['server_id']." AND virtualhost = 'y'");
$ip_addresses = array();
if(is_array($records) && count($records) > 0) {
foreach($records as $rec) {
if($rec['ip_type'] == 'IPv6') {
$ip_address = '['.$rec['ip_address'].']';
} else {
$ip_address = $rec['ip_address'];
}
$ports = explode(',', $rec['virtualhost_port']);
if(is_array($ports)) {
foreach($ports as $port) {
$port = intval($port);
if($port > 0 && $port < 65536 && $ip_address != '') {
$ip_addresses[] = array('ip_address' => $ip_address, 'port' => $port);
}
}
}
}
}
wf($conf['apache']['vhost_conf_dir'].'/000-ispconfig.conf', $tpl->grab());
unset($tpl);
//* Gentoo by default does not include .vhost files. Add include line to config file.
$content = rf($conf['apache']['config_file']);
......
......@@ -660,10 +660,12 @@ class installer_dist extends installer_base {
$vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
$vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
//copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apache_ispconfig.conf.master', 'tpl/apache_ispconfig.conf.master');
$tpl = new tpl('apache_ispconfig.conf.master');
$tpl->setVar('apache_version',getapacheversion());
$records = $this->db->queryAllRecords('SELECT * FROM '.$conf['mysql']['master_database'].'.server_ip WHERE server_id = '.$conf['server_id']." AND virtualhost = 'y'");
$ip_addresses = array();
if(is_array($records) && count($records) > 0) {
foreach($records as $rec) {
if($rec['ip_type'] == 'IPv6') {
......@@ -676,15 +678,15 @@ class installer_dist extends installer_base {
foreach($ports as $port) {
$port = intval($port);
if($port > 0 && $port < 65536 && $ip_address != '') {
$content .= 'NameVirtualHost '.$ip_address.":".$port."\n";
$ip_addresses[] = array('ip_address' => $ip_address, 'port' => $port);
}
}
}
}
}
$content .= "\n";
wf($vhost_conf_dir.'/ispconfig.conf', $content);
wf($vhost_conf_dir.'/ispconfig.conf', $tpl->grab());
unset($tpl);
if(!@is_link($vhost_conf_enabled_dir."/000-ispconfig.conf")) {
exec("ln -s ".$vhost_conf_dir."/ispconfig.conf ".$vhost_conf_enabled_dir."/000-ispconfig.conf");
......@@ -1089,31 +1091,30 @@ class installer_dist extends installer_base {
// Dont just copy over the virtualhost template but add some custom settings
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apache_ispconfig.vhost.master', "tpl/apache_ispconfig.vhost.master");
$content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
$tpl = new tpl('apache_ispconfig.vhost.master');
$tpl->setVar('vhost_port',$conf['apache']['vhost_port']);
// comment out the listen directive if port is 80 or 443
if($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) {
$content = str_replace('{vhost_port_listen}', '#', $content);
$tpl->setVar('vhost_port_listen','#');
} else {
$content = str_replace('{vhost_port_listen}', '', $content);
$tpl->setVar('vhost_port_listen','');
}
if(is_file('/usr/local/ispconfig/interface/ssl/ispserver.crt') && is_file('/usr/local/ispconfig/interface/ssl/ispserver.key')) {
$content = str_replace('{ssl_comment}', '', $content);
if(is_file($install_dir.'/interface/ssl/ispserver.crt') && is_file($install_dir.'/interface/ssl/ispserver.key')) {
$tpl->setVar('ssl_comment','');
} else {
$content = str_replace('{ssl_comment}', '#', $content);
$tpl->setVar('ssl_comment','#');
}
if(is_file($install_dir.'/interface/ssl/ispserver.crt') && is_file($install_dir.'/interface/ssl/ispserver.key') && is_file($install_dir.'/interface/ssl/ispserver.bundle')) {
$content = str_replace('{ssl_bundle_comment}', '', $content);
$tpl->setVar('ssl_bundle_comment','');
} else {
$content = str_replace('{ssl_bundle_comment}', '#', $content);
$tpl->setVar('ssl_bundle_comment','#');
}
$tpl->setVar('apache_version',getapacheversion());
$content = str_replace('/var/www/', '/srv/www/', $content);
wf("$vhost_conf_dir/ispconfig.vhost", $content);
wf($vhost_conf_dir.'/ispconfig.vhost', $tpl->grab());
//if(!is_file('/srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter')) {
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apache_ispconfig_fcgi_starter.master', 'tpl/apache_ispconfig_fcgi_starter.master');
......
......@@ -65,6 +65,9 @@ if(realpath(dirname(__FILE__)) != $cur_dir) {
define('ISPC_LOG_FILE', '/var/log/ispconfig_install.log');
define('ISPC_INSTALL_ROOT', realpath(dirname(__FILE__).'/../'));
//** Include the templating lib
require_once 'lib/classes/tpl.inc.php';
//** Check for existing installation
/*if(is_dir("/usr/local/ispconfig")) {
die('We will stop here. There is already a ISPConfig installation, use the update script to update this installation.');
......
<?php
/**
* vlibTemplate is a class used to seperate PHP and HTML.
* For instructions on how to use vlibTemplate, see the
* vlibTemplate.html file, located in the 'docs' directory.
*
* @since 07/03/2002
* @author Kelvin Jones <kelvin@kelvinjones.co.uk>
* @package vLIB
* @access public
* @see vlibTemplate.html
*/
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002 Active Fish Group |
// +----------------------------------------------------------------------+
// | Authors: Kelvin Jones <kelvin@kelvinjones.co.uk> |
// +----------------------------------------------------------------------+
//
// $Id: class.tpl.inc.php,v 1.1 2003/07/08 12:31:10 platinum Exp $
//** check and avoid multiple loading of class
if (!defined('vlibTemplateClassLoaded')) {
define('vlibTemplateClassLoaded', 1);
include_once ISPC_INSTALL_ROOT.'/install/lib/classes/tpl_error.inc.php';
include_once ISPC_INSTALL_ROOT.'/install/lib/classes/tpl_ini.inc.php';
class tpl{
/*-----------------------------------------------------------------------------\
| ATTENTION |
| Do not touch the following variables. vlibTemplate will not work otherwise. |
\-----------------------------------------------------------------------------*/
private $OPTIONS = array(
'MAX_INCLUDES' => 10,
'TEMPLATE_DIR' => null,
'GLOBAL_VARS' => null,
'GLOBAL_CONTEXT_VARS' => null,
'LOOP_CONTEXT_VARS' => null,
'SET_LOOP_VAR' => null,
'DEFAULT_ESCAPE' => null,
'STRICT' => null,
'CASELESS' => null,
'UNKNOWNS' => null,
'TIME_PARSE' => null,
'ENABLE_PHPINCLUDE' => null,
'INCLUDE_PATHS' => array(),
'CACHE_DIRECTORY' => null,
'CACHE_LIFETIME' => null,
'CACHE_EXTENSION' => null
);
/** open and close tags used for escaping */
private $ESCAPE_TAGS = array(
'html' => array('open' => 'htmlspecialchars(' , 'close'=> ', ENT_QUOTES)'),
'url' => array('open' => 'urlencode(' , 'close'=> ')'),
'rawurl' => array('open' => 'rawurlencode(' , 'close'=> ')'),
'sq' => array('open' => 'addcslashes(' , 'close'=> ", \"'\")"),
'dq' => array('open' => 'addcslashes(' , 'close'=> ", '\"')"),
'1' => array('open' => 'htmlspecialchars(' , 'close'=> ', ENT_QUOTES)'),
'0' => array('open' => '' , 'close'=> ''),
'none' => array('open' => '' , 'close'=> ''),
'hex' => array('open' => '$this->_escape_hex(' , 'close'=> ', false)'),
'hexentity' => array('open' => '$this->_escape_hex(' , 'close'=> ', true)')
);
/** open and close tags used for formatting */
private $FORMAT_TAGS = array(
'strtoupper' => array('open' => 'strtoupper(', 'close'=> ')'),
'uc' => array('open' => 'strtoupper(', 'close'=> ')'),
'strtolower' => array('open' => 'strtolower(', 'close'=> ')'),
'lc' => array('open' => 'strtolower(', 'close'=> ')'),
'ucfirst' => array('open' => 'ucfirst(', 'close'=> ')'),
'lcucfirst' => array('open' => 'ucfirst(strtolower(', 'close'=> '))'),
'ucwords' => array('open' => 'ucwords(', 'close'=> ')'),
'lcucwords' => array('open' => 'ucwords(strtolower(', 'close'=> '))')
);
/** operators allowed when using extended TMPL_IF syntax */
private $allowed_if_ops = array('==', '!=', '<>', '<', '>', '<=', '>=');
/** dbs allowed by vlibTemplate::setDbLoop(). */
private $allowed_loop_dbs = array('MYSQL', 'POSTGRESQL', 'INFORMIX', 'INTERBASE', 'INGRES',
'MSSQL', 'MSQL', 'OCI8', 'ORACLE', 'OVRIMOS', 'SYBASE');
/** root directory of vlibTemplate automagically filled in */
private $VLIBTEMPLATE_ROOT = null;
/** contains current directory used when doing recursive include */
private $_currentincludedir = array();
/** current depth of includes */
private $_includedepth = 0;
/** full path to tmpl file */
private $_tmplfilename = null;
/** file data before it's parsed */
private $_tmplfile = null;
/** parsed version of file, ready for eval()ing */
private $_tmplfilep = null;
/** eval()ed version ready for printing or whatever */
private $_tmploutput = null;
/** array for variables to be kept */
private $_vars = array();
/** array where loop variables are kept */
private $_arrvars = array();
/** array which holds the current namespace during parse */
private $_namespace = array();
/** variable is set to true once the template is parsed, to save re-parsing everything */
private $_parsed = false;
/** array holds all unknowns vars */
private $_unknowns = array();
/** microtime when template parsing began */
private $_firstparsetime = null;
/** total time taken to parse template */
private $_totalparsetime = null;
/** name of current loop being passed in */
private $_currloopname = null;
/** rows with the above loop */
private $_currloop = array();
/** define vars to avoid warnings */
private $_debug = null;
private $_cache = null;
/** array which holds the dynamic Includes */
private $_dyninclude = array();
/*-----------------------------------------------------------------------------\
| public functions |
\-----------------------------------------------------------------------------*/
/**
* Usually called by the class constructor.
* Stores the filename in $this->_tmplfilename.
* Raises an error if the template file is not found.
* @param string $tmplfile full path to template file
* @return boolean true
* @access public
*/
public function newTemplate($tmplfile)
{
if (!$tfile = $this->_fileSearch($tmplfile)){
vlibTemplateError::raiseError('VT_ERROR_NOFILE', KILL, $tmplfile);
}
//* make sure that any parsing vars are cleared for the new template
$this->_tmplfile = null;
$this->_tmplfilep = null;
$this->_tmploutput = null;
$this->_parsed = false;
$this->_unknowns = array();
$this->_firstparsetime = null;
$this->_totalparsetime = null;
//* reset debug module
if ($this->_debug){
$this->_debugReset();
}
$this->_tmplfilename = $tfile;
return true;
}
/**
* Sets variables to be used by the template
* If $k is an array, then it will treat it as an associative array
* using the keys as variable names and the values as variable values.
* @param mixed $k key to define variable name
* @param mixed $v variable to assign to $k
* @return boolean true/false
* @access public
*/
public function setVar($k, $v = null)
{
if (is_array($k)) {
foreach($k as $key => $value){
$key = ($this->OPTIONS['CASELESS']) ? strtolower(trim($key)) : trim($key);
if (preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $key) && $value !== null ) {
$this->_vars[$key] = $value;
}
}
} else {
if (preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $k) && $v !== null) {
if ($this->OPTIONS['CASELESS']) $k = strtolower($k);
$this->_vars[trim($k)] = $v;
} else {
return false;
}
}
return true;
}
/**
* Sets dynamic includes to be used by the template
* If $k is an array, then it will treat it as an associative array
* using the keys as variable names and the values as variable values.
* @param mixed $k key to define variable name
* @param mixed $v variable to assign to $k
* @return boolean true/false
* @access public
*/
public function setInclude($k, $v = null)
{
if(is_array($k)) {
foreach($k as $key => $val) {
$this->_dyninclude[$key] = $val;
}
} else {
$this->_dyninclude[$k] = $v;
}
return true;
}
/**
* Unsets a variable which has already been set
* Parse in all vars wanted for deletion in seperate parametres
* @param string var name to remove use: vlibTemplate::unsetVar(var[, var..])
* @return boolean true/false returns true unless called with 0 params
* @access public
*/
public function unsetVar()
{
$num_args = func_num_args();
if ($num_args < 1) return false;
for ($i = 0; $i < $num_args; $i++) {
$var = func_get_arg($i);
if ($this->OPTIONS['CASELESS']) $var = strtolower($var);
if (!preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $var)) continue;
unset($this->_vars[$var]);
}
return true;
}
/**
* Gets all vars currently set in global namespace.
* @return array
* @access public
*/
public function getVars()
{
return empty($this->_vars) ? false : $this->_vars;
}
/**
* Gets a single var from the global namespace
* @return var
* @access public
*/
public function getVar($var)
{
if ($this->OPTIONS['CASELESS']) $var = strtolower($var);
return (empty($var) || !isset($this->_vars[$var])) ? false : $this->_vars[$var];
}
/**
* sets the GLOBAL_CONTEXT_VARS
* @return true
* @access public
*/
public function setContextVars()
{
$_phpself = @$GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'];
$_pathinfo = @$GLOBALS['HTTP_SERVER_VARS']['PATH_INFO'];
$_request_uri = @$GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'];
$_qs = @$GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING'];
//* the following fixes bug of $PHP_SELF on Win32 CGI and IIS.
$_self = (!empty($_pathinfo)) ? $_pathinfo : $_phpself;
$_uri = (!empty($_request_uri)) ? $_request_uri : $_self.'?'.$_qs;
$this->setvar('__SELF__', $_self);
$this->setvar('__REQUEST_URI__', $_uri);
return true;
}
/**
* Builds the loop construct for use with <TMPL_LOOP>.
* @param string $k string to define loop name
* @param array $v array to assign to $k
* @return boolean true/false
* @access public
*/
public function setLoop($k, $v)
{
if (is_array($v) && preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $k)) {
$k = ($this->OPTIONS['CASELESS']) ? strtolower(trim($k)) : trim($k);
$this->_arrvars[$k] = array();
if ($this->OPTIONS['SET_LOOP_VAR'] && !empty($v)) $this->setvar($k, 1);
if (($this->_arrvars[$k] = $this->_arrayBuild($v)) == false) {
vlibTemplateError::raiseError('VT_WARNING_INVALID_ARR', WARNING, $k);
} else {
$this->vars['_'.$k.'_num'] = count($v);
}
}
return true;
}
/**
* [** EXPERIMENTAL **]
* Function to create a loop from a Db result resource link.
* @param string $loopname to commit loop. If not set, will use last loopname set using newLoop()
* @param string $result link to a Db result resource
* @param string $db_type, type of db that the result resource belongs to.
* @return boolean true/false
* @access public
*/
public function setDbLoop($loopname, $result, $db_type = 'MYSQL')
{
/*
$db_type = strtoupper($db_type);
if (!in_array($db_type, $this->allowed_loop_dbs)) {
vlibTemplateError::raiseError('VT_WARNING_INVALID_LOOP_DB', WARNING, $db_type);
return false;
}
$loop_arr = array();
// TODO: Are all these necessary as were onyl using mysql and possible postgres ? - pedro
switch ($db_type) {
case 'MYSQL':
if (get_resource_type($result) != 'mysql result') {
vlibTemplateError::raiseError('VT_WARNING_INVALID_RESOURCE', WARNING, $db_type);
return false;
}
while($r = mysql_fetch_assoc($result)) {
$loop_arr[] = $r;
}
break;
case 'POSTGRESQL':