tbrehm
2012-04-05 aad3f0eb1e40aff62e888bff45d193ce0838f90c
commit | author | age
6fa2f1 1 <?php
T 2
3 /*
44d2a7 4 Copyright (c) 2007 - 2009, Till Brehm, projektfarm Gmbh
6fa2f1 5 All rights reserved.
T 6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
c53695 31 //* Enable gzip compression for the interface
T 32 ob_start('ob_gzhandler');
33
71ea2a 34 //* Set timezone
2dd674 35 if(isset($conf['timezone']) && $conf['timezone'] != '') date_default_timezone_set($conf['timezone']);
71ea2a 36
c53695 37 //* Set error reporting level when we are not on a developer system
T 38 if(DEVSYSTEM == 0) {
627993 39     @ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_DEPRECATED);
c53695 40 }
T 41
6fa2f1 42 /*
T 43     Application Class
44 */
45 class app {
46
47     private $_language_inc = 0;
48     private $_wb;
49     private $_loaded_classes = array();
50     private $_conf;
51
ae3a8a 52     public function __construct() {
6fa2f1 53         global $conf;
ae3a8a 54
6fa2f1 55         if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS']) || isset($_REQUEST['s']) || isset($_REQUEST['s_old']) || isset($_REQUEST['conf'])) {
T 56             die('Internal Error: var override attempt detected');
57         }
ae3a8a 58
6fa2f1 59         $this->_conf = $conf;
T 60         if($this->_conf['start_db'] == true) {
61             $this->load('db_'.$this->_conf['db_type']);
62             $this->db = new db;
63         }
ae3a8a 64
6fa2f1 65         //* Start the session
T 66         if($this->_conf['start_session'] == true) {
ae81a2 67             
T 68             $this->uses('session');
69             session_set_save_handler(    array($this->session, 'open'),
70                                         array($this->session, 'close'),
71                                         array($this->session, 'read'),
72                                         array($this->session, 'write'),
73                                         array($this->session, 'destroy'),
74                                         array($this->session, 'gc'));
75             
6fa2f1 76             session_start();
ae3a8a 77
6fa2f1 78             //* Initialize session variables
T 79             if(!isset($_SESSION['s']['id']) ) $_SESSION['s']['id'] = session_id();
80             if(empty($_SESSION['s']['theme'])) $_SESSION['s']['theme'] = $conf['theme'];
81             if(empty($_SESSION['s']['language'])) $_SESSION['s']['language'] = $conf['language'];
82         }
ae3a8a 83
5bbfc1 84         $this->uses('auth,plugin,functions');
6fa2f1 85     }
b55e2b 86     
T 87     public function __destruct() {
88         session_write_close();
89         if(isset($this->db)) $this->db->closeConn();
90     }
6fa2f1 91
ae3a8a 92     public function uses($classes) {
V 93         $cl = explode(',', $classes);
6fa2f1 94         if(is_array($cl)) {
ae3a8a 95             foreach($cl as $classname) {
6fa2f1 96                 $classname = trim($classname);
ae3a8a 97                 //* Class is not loaded so load it
V 98                 if(!array_key_exists($classname, $this->_loaded_classes)) {
6fa2f1 99                     include_once(ISPC_CLASS_PATH."/$classname.inc.php");
T 100                     $this->$classname = new $classname();
101                     $this->_loaded_classes[$classname] = true;
102                 }
103             }
104         }
105     }
106
ae3a8a 107     public function load($files) {
6fa2f1 108         $fl = explode(',', $files);
T 109         if(is_array($fl)) {
ae3a8a 110             foreach($fl as $file) {
6fa2f1 111                 $file = trim($file);
T 112                 include_once(ISPC_CLASS_PATH."/$file.inc.php");
113             }
114         }
115     }
116
117     /** Priority values are: 0 = DEBUG, 1 = WARNING,  2 = ERROR */
ae3a8a 118     public function log($msg, $priority = 0) {
da1da4 119         global $conf;
6fa2f1 120         if($priority >= $this->_conf['log_priority']) {
da1da4 121             // $server_id = $conf["server_id"];
T 122             $server_id = 0;
123             $priority = intval($priority);
124             $tstamp = time();
125             $msg = $this->db->quote('[INTERFACE]: '.$msg);
126             $this->db->query("INSERT INTO sys_log (server_id,datalog_id,loglevel,tstamp,message) VALUES ($server_id,0,$priority,$tstamp,'$msg')");
127             /*
6fa2f1 128             if (is_writable($this->_conf['log_file'])) {
T 129                 if (!$fp = fopen ($this->_conf['log_file'], 'a')) {
130                     $this->error('Unable to open logfile.');
131                 }
132                 if (!fwrite($fp, date('d.m.Y-H:i').' - '. $msg."\r\n")) {
133                     $this->error('Unable to write to logfile.');
134                 }
135                 fclose($fp);
136             } else {
137                 $this->error('Unable to write to logfile.');
138             }
da1da4 139             */
ae3a8a 140         }
V 141     }
6fa2f1 142
ae3a8a 143     /** Priority values are: 0 = DEBUG, 1 = WARNING,  2 = ERROR */
V 144     public function error($msg, $next_link = '', $stop = true, $priority = 1) {
6fa2f1 145         //$this->uses("error");
T 146         //$this->error->message($msg, $priority);
ae3a8a 147         if($stop == true) {
903ede 148             /*
V 149              * We always have a error. So it is better not to use any more objects like
150              * the template or so, because we don't know why the error occours (it could be, that
151              * the error occours in one of these objects..)
152              */
153             /*
154              * Use the template inside the user-template - Path. If it is not found, fallback to the
155              * default-template (the "normal" behaviour of all template - files)
156              */
157             if (file_exists(dirname(__FILE__) . '/../web/themes/' . $_SESSION['s']['theme'] . '/templates/error.tpl.htm')) {
158                 $content = file_get_contents(dirname(__FILE__) . '/../web/themes/' . $_SESSION['s']['theme'] . '/templates/error.tpl.htm');
159             } else {
160                 $content = file_get_contents(dirname(__FILE__) . '/../web/themes/default/templates/error.tpl.htm');
161             }
6fa2f1 162             if($next_link != '') $msg .= '<a href="'.$next_link.'">Next</a>';
ae3a8a 163             $content = str_replace('###ERRORMSG###', $msg, $content);
V 164             die($content);
6fa2f1 165         } else {
T 166             echo $msg;
167             if($next_link != '') echo "<a href='$next_link'>Next</a>";
168         }
169     }
170
ae3a8a 171     /** Translates strings in current language */
V 172     public function lng($text) {
c161ea 173         global $conf;
6fa2f1 174         if($this->_language_inc != 1) {
e83dd1 175             $language = (isset($_SESSION['s']['language']))?$_SESSION['s']['language']:$conf['language'];
2eff06 176             //* loading global Wordbook
e83dd1 177             $this->load_language_file('lib/lang/'.$language.'.lng');
2eff06 178             //* Load module wordbook, if it exists
e83dd1 179             if(isset($_SESSION['s']['module']['name'])) {
T 180                 $lng_file = 'web/'.$_SESSION['s']['module']['name'].'/lib/lang/'.$language.'.lng';
1ca823 181                 if(!file_exists(ISPC_ROOT_PATH.'/'.$lng_file)) $lng_file = '/web/'.$_SESSION['s']['module']['name'].'/lib/lang/en.lng';
44d2a7 182                 $this->load_language_file($lng_file);
6fa2f1 183             }
T 184             $this->_language_inc = 1;
ae3a8a 185         }
6fa2f1 186         if(!empty($this->_wb[$text])) {
T 187             $text = $this->_wb[$text];
ef3719 188         } else {
T 189             if($this->_conf['debug_language']) {
190                 $text = '#'.$text.'#';
191             }
6fa2f1 192         }
T 193         return $text;
194     }
ae3a8a 195
44d2a7 196     //** Helper function to load the language files.
T 197     public function load_language_file($filename) {
198         $filename = ISPC_ROOT_PATH.'/'.$filename;
199         if(substr($filename,-4) != '.lng') $this->error('Language file has wrong extension.');
200         if(file_exists($filename)) {
1ca823 201             @include($filename);
44d2a7 202             if(is_array($wb)) {
T 203                 if(is_array($this->_wb)) {
40dd9f 204                     $this->_wb = array_merge($this->_wb,$wb);
44d2a7 205                 } else {
T 206                     $this->_wb = $wb;
207                 }
208             }
209         }
210     }
6fa2f1 211
ae3a8a 212     public function tpl_defaults() {
6fa2f1 213         $this->tpl->setVar('app_title', $this->_conf['app_title']);
b09c9a 214         if(isset($_SESSION['s']['user'])) {
T 215             $this->tpl->setVar('app_version', $this->_conf['app_version']);
216         } else {
217             $this->tpl->setVar('app_version', '');
218         }
6fa2f1 219         $this->tpl->setVar('app_link', $this->_conf['app_link']);
aad3f0 220         /*
ae3a8a 221         if(isset($this->_conf['app_logo']) && $this->_conf['app_logo'] != '' && @is_file($this->_conf['app_logo'])) {
6fa2f1 222             $this->tpl->setVar('app_logo', '<img src="'.$this->_conf['app_logo'].'">');
T 223         } else {
224             $this->tpl->setVar('app_logo', '&nbsp;');
225         }
aad3f0 226         */
T 227         $this->tpl->setVar('app_logo', $this->_conf['logo']);
6fa2f1 228
T 229         $this->tpl->setVar('phpsessid', session_id());
230
231         $this->tpl->setVar('theme', $_SESSION['s']['theme']);
232         $this->tpl->setVar('html_content_encoding', $this->_conf['html_content_encoding']);
233
234         $this->tpl->setVar('delete_confirmation', $this->lng('delete_confirmation'));
ae3a8a 235         //print_r($_SESSION);
6fa2f1 236         if(isset($_SESSION['s']['module']['name'])) {
T 237             $this->tpl->setVar('app_module', $_SESSION['s']['module']['name']);
238         }
239         if(isset($_SESSION['s']['user']) && $_SESSION['s']['user']['typ'] == 'admin') {
240             $this->tpl->setVar('is_admin', 1);
241         }
242         if(isset($_SESSION['s']['user']) && $this->auth->has_clients($_SESSION['s']['user']['userid'])) {
243             $this->tpl->setVar('is_reseller', 1);
244         }
955391 245         /* Show username */
V 246         if(isset($_SESSION['s']['user'])) {
247             $this->tpl->setVar('cpuser', $_SESSION['s']['user']['username']);
911dbe 248             $this->tpl->setVar('logout_txt', $this->lng('logout_txt'));
955391 249         }
ae3a8a 250     }
V 251
6fa2f1 252 } // end class
T 253
254 //** Initialize application (app) object
255 //* possible future =  new app($conf);
256 $app = new app();
257
b09c9a 258 ?>