PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/install.php

https://bitbucket.org/themattreid/kontrollbase
PHP | 189 lines | 145 code | 31 blank | 13 comment | 39 complexity | bb5c201c27bec1fcb6aeeef9ec8399a4 MD5 | raw file
  1<?php
  2  /**
  3   * Kontrollbase
  4   *
  5   * An open source MySQL monitoring and analytics application
  6   * ID: $Id: install.php 326 2011-04-25 21:04:18Z themattreid $
  7   * @package Kontrollbase
  8   * @author Matt Reid
  9   * @copyright Copyright (c) 2009 Matt Reid, Kontrollbase LLC
 10   * @license http://kontrollsoft.com/kontrollbase/userguide/general-LICENSE.php
 11   * @link http://kontrollbase.com
 12   */
 13
 14function head_d($nroot,$syspath,$w_logs,$w_includes,$w_config) {
 15  $d_logs = "$syspath/system/logs";
 16  $d_includes = "$syspath/includes";
 17  $d_config = "$syspath/system/application/config";
 18
 19
 20  if($w_logs == 1) { $w_logs = '<img src="includes/images/delete-icon.png" width="11" height="11">'; } 
 21  else { $w_logs = '<img src="includes/images/check-red.png" width="16" height="20">'; }
 22  if($w_includes == 1) { $w_includes = '<img src="includes/images/delete-icon.png" width="11" height="11">'; } 
 23  else { $w_includes = '<img src="includes/images/check-red.png" width="16" height="20">'; }
 24  if($w_config == 1) { $w_config = '<img src="includes/images/delete-icon.png" width="11" height="11">'; } 
 25  else { $w_config = '<img src="includes/images/check-red.png" width="16" height="20">'; }
 26
 27  print<<<HEAD
 28    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 29    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
 30    
 31    <head>
 32    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 33    <title>Kontrollbase 2.0.1 - MySQL Monitoring</title>
 34    
 35    <link rel="stylesheet" type="text/css" href="$nroot/includes/style.css" />
 36    <link rel="stylesheet" type="text/css" media="all" href="$nroot/userguide/css/userguide-nofluff.css" />
 37    <link rel="stylesheet" type="text/css" href="$nroot/includes/extjs/layout/layout-browser.css">
 38    <link rel="stylesheet" type="text/css" href="$nroot/includes/extjs/resources/css/ext-all.css" />
 39    <link rel="stylesheet" type="text/css" href="$nroot/includes/extjs/resources/css/xtheme-slate.css" />
 40    
 41    <script type="text/javascript" src="$nroot/includes/extjs/adapter/ext/ext-base.js"></script>
 42    <script type="text/javascript" src="$nroot/includes/extjs/ext-all-debug.js"></script>
 43    
 44    <script type='text/javascript'>                                                                                                                                                                                                           
 45    Ext.onReady(function(){                                                                                                                                       Ext.Msg.alert('Installation Failure.', '<table><tr><td colspan="2">Directory Check:</td></td></tr><tr><td align="left">$d_logs</td><td align="center">$w_logs</td></tr><tr><td align="left">$d_includes</td><td align="center">$w_includes</td></tr><tr><td align="left">$d_config</td><td align="center">$w_config</td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td colspan="2">Directories must be writeable by the webserver user and group</td></tr><tr><td colspan="2">ie: $> chown -R apache:apache includes</td></tr><tr><td colspan="2">ie: $> chown -R apache:apache system/logs</td></tr><tr><td colspan="2">ie: $> chown -R apache:apache system/application/config</td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td colspan="2">Run the proper commands, then refresh this screen to continue.</td></tr></table>', function(btn, text){
 46                                  if (btn == 'ok'){
 47                                    var redirect = '$nroot/install.php';
 48                                    window.location = redirect;
 49                                  }
 50                                })});
 51  </script>
 52      </head>
 53      <body>
 54      
 55HEAD;
 56}
 57
 58function head_m($nroot,$syspath,$install_sc,$install_sd) {
 59  $sysconfig="system/application/config/config.php";
 60  $sysdatabase="system/application/config/database.php";
 61  if($install_sc == 1) { $install_sc = '<img src="includes/images/delete-icon.png" width="11" height="11">';  } 
 62  else { $install_sc = '<img src="includes/images/check-red.png" width="16" height="20">'; }
 63  if($install_sd == 1) { $install_sd = '<img src="includes/images/delete-icon.png" width="11" height="11">';  } 
 64  else { $install_sd = '<img src="includes/images/check-red.png" width="16" height="20">'; }
 65
 66  print<<<HEAD
 67    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 68    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
 69    
 70    <head>
 71    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 72    <title>Kontrollbase 2.0.1 - MySQL Monitoring</title>
 73    
 74    <link rel="stylesheet" type="text/css" href="$nroot/includes/style.css" />
 75    <link rel="stylesheet" type="text/css" media="all" href="$nroot/userguide/css/userguide-nofluff.css" />
 76    <link rel="stylesheet" type="text/css" href="$nroot/includes/extjs/layout/layout-browser.css">
 77    <link rel="stylesheet" type="text/css" href="$nroot/includes/extjs/resources/css/ext-all.css" />
 78    <link rel="stylesheet" type="text/css" href="$nroot/includes/extjs/resources/css/xtheme-slate.css" />
 79    
 80    <script type="text/javascript" src="$nroot/includes/extjs/adapter/ext/ext-base.js"></script>
 81    <script type="text/javascript" src="$nroot/includes/extjs/ext-all-debug.js"></script>
 82    
 83    <script type='text/javascript'>                                                                                                                                                                                                           
 84    Ext.onReady(function(){                                                                                                                                                                                                                   
 85		  Ext.Msg.alert('Installation Failure.', '<table><tr><td colspan="2">Config files check</td></tr><tr><td>$sysconfig</td><td>$install_sc</td></tr><tr><td>$sysdatabase</td><td>$install_sd</td></tr><tr><td colspan="2">Remove the config files to continue.</td></tr></table>', function(btn, text){
 86				  if (btn == 'ok'){
 87				    var redirect = '$nroot/install.php';
 88				    window.location = redirect;
 89				  }
 90				})});
 91  </script>
 92      </head>
 93      <body>
 94      
 95HEAD;
 96}
 97
 98function head_i($nroot,$syspath,$d_logs,$d_includes,$d_config) {
 99  $len = ((strlen($syspath)) + 1) ;
100  $d_logs = substr($d_logs,$len);
101  $d_includes = substr($d_includes,$len);
102  $d_config = substr($d_config,$len);
103  print<<<HEAD
104    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
105    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
106    
107    <head>
108    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
109    <title>Kontrollbase 2.0.1 - MySQL Monitoring</title>
110    
111    <link rel="stylesheet" type="text/css" href="$nroot/includes/style.css" />
112    <link rel="stylesheet" type="text/css" media="all" href="$nroot/userguide/css/userguide-nofluff.css" />
113    <link rel="stylesheet" type="text/css" href="$nroot/includes/extjs/layout/layout-browser.css">
114    <link rel="stylesheet" type="text/css" href="$nroot/includes/extjs/resources/css/ext-all.css" />
115    <link rel="stylesheet" type="text/css" href="$nroot/includes/extjs/resources/css/xtheme-slate.css" />
116    
117    <script type="text/javascript" src="$nroot/includes/extjs/adapter/ext/ext-base.js"></script>
118    <script type="text/javascript" src="$nroot/includes/extjs/ext-all-debug.js"></script>
119    
120    <script type='text/javascript'>                                                                                                                                                                                                           
121    Ext.onReady(function(){                                                                                                                                                                                                                   
122		  Ext.Msg.alert('The Kontrollbase Installer', '<table><tr><td align="left">Config File Check</td><td align="center"><img src="includes/images/check-red.png" width="16" height="20"></td></tr><tr><td align="left">Directory $d_logs:</td><td align="center"><img src="includes/images/check-red.png" width="16" height="20"></td></tr><tr><td align="left">Directory $d_includes:</td><td align="center"><img src="includes/images/check-red.png" width="16" height="20"></td></tr><tr><td align="left">Directory $d_config:</td><td align="center"><img src="includes/images/check-red.png" width="16" height="20"></td></tr></table>', function(btn, text){
123				  if (btn == 'ok'){
124				    var redirect = '$nroot/install/overview.php';
125				    window.location = redirect;
126				  }
127				})});
128  </script>
129      </head>
130      <body>
131      
132HEAD;
133}
134
135function dir_writeable($file) {
136  if(is_writable($file)) {
137    return 0;
138  }
139  else {
140    return 1;
141  }
142}
143
144function check_install() {
145  $nroot = $_SERVER['PHP_SELF'];
146  $server = $_SERVER['SERVER_NAME'];
147  $nroot = rtrim($nroot, "/install.php");
148
149  $syspath = $_SERVER['SCRIPT_FILENAME'];
150  $syspath = rtrim($syspath, ".php");
151  $syspath = rtrim($syspath, "/install");
152
153  $sysconfig="$syspath/system/application/config/config.php";
154  $sysdatabase="$syspath/system/application/config/database.php";
155  //  $d_cache = "$syspath/system/cache"; // might want to be checking this too...
156  $d_logs = "$syspath/system/logs";
157  $d_includes = "$syspath/includes";
158  $d_config = "$syspath/system/application/config";
159  
160  //check to see if config files exist
161  $install_sc = exists($sysconfig);
162  $install_sd = exists($sysdatabase);
163  $w_logs = dir_writeable($d_logs);
164  $w_includes = dir_writeable($d_includes);
165  $w_config = dir_writeable($d_config);
166
167  if(($install_sc == 0) && ($install_sd == 0) && ($w_logs == 0) && ($w_includes == 0) && ($w_config == 0)) {
168    head_i($nroot,$syspath,$d_logs,$d_includes,$d_config);
169  }
170  elseif(($install_sc == 1) || ($install_sd == 1)) {
171    head_m($nroot,$syspath,$install_sc,$install_sd);
172  }
173  else {
174    head_d($nroot,$syspath,$w_logs,$w_includes,$w_config);
175  }
176}
177
178function exists($file) {
179  if (file_exists($file)) {
180    return 1;
181  } 
182  else {
183    return 0;
184  }
185}
186
187check_install();
188
189?>