<?php
/*
OsShare v1 ,
Coded By P.Karthikeyan. , Paimpozhil B. , SaravanaKumar M.S.
*/
class InstallerController extends Controller {
var $name = 'Installer';
var $helpers = array('Html', 'Form' );
var $layout = false;
function beforeFilter()
{
if(file_exists(WWW_ROOT . DS . "files" . DS . "install.lock"))
{
$this->redirect(array('controller'=>'pages','action'=>'index'));
exit();
}
}
function index()
{
//Checking Folder & File Permission
$this->set('dbwritable',$this->is__writable(CONFIGS . "database.php")?'Pass':'Failed');
$this->set('dbfilepath',CONFIGS . "database.php" );
$this->set('tmpwritable',$this->is__writable(TMP)?'Pass':'Failed' );
$this->set('tmppath',TMP );
$this->set('fileswritable',$this->is__writable(WWW_ROOT . "files" . DS)?'Pass':'Failed' );
$this->set('filespath',WWW_ROOT . "files" . DS );
$this->set('iscallable',is_callable("system")?'Pass':'Failed' );
}
function index2()
{
if(isset($_POST['button']))
{
$this->set('dbfilepath',CONFIGS . "database.php" );
//print_r($_POST);
$host = $_POST['host'];
$port = $_POST['port'];
$db = $_POST['db'];
$user = $_POST['user'];
$pass = $_POST['pass'];
/////////////////////////////////////////////////////
//////////////////database.php////////////////////////
$content = "<?php
/**
* In this file you set up your database connection details.
*
* @package cake
* @subpackage cake.config
*/
/**
* Database configuration class.
* You can specify multiple configurations for production, development and testing.
*
* driver => The name of a supported driver; valid options are as follows:
* mysql - MySQL 4 & 5,
* mysqli - MySQL 4 & 5 Improved Interface (PHP5 only),
* sqlite - SQLite (PHP5 only),
* postgres - PostgreSQL 7 and higher,
* mssql - Microsoft SQL Server 2000 and higher,
* db2 - IBM DB2, Cloudscape, and Apache Derby (http://php.net/ibm-db2)
* oracle - Oracle 8 and higher
* adodb-[drivername] - ADOdb interface wrapper (see below),
* pear-[drivername] - PEAR::DB wrapper
*
* You can add custom database drivers (or override existing drivers) by adding the
* appropriate file to app/models/datasources/dbo. Drivers should be named 'dbo_x.php',
* where 'x' is the name of the database.
*
* persistent => true / false
* Determines whether or not the database should use a persistent connection
*
* connect =>
* ADOdb set the connect to one of these
* (http://phplens.com/adodb/supported.databases.html) and
* append it '|p' for persistent connection. (mssql|p for example, or just mssql for not persistent)
* For all other databases, this setting is deprecated.
*
* host =>
* the host you connect to the database
* To add a port number use 'port' => #
*
* prefix =>
* Uses the given prefix for all the tables in this database. This setting can be overridden
* on a per-table basis with the Model::"."$"."tablePrefix property.
*
*/
class DATABASE_CONFIG {
var "."$"."default"." = array(
'driver' => 'mysql',
'persistent' => false,
'host' => '".$host."',
'port' => '".$port."',
'login' => '".$user."',
'password' => '".$pass."',
'database' => '".$db."',
'schema' => '',
'prefix' => '',
'encoding' => ''
);
}
?>";
//Over-Writing the database.php file.
$fp = fopen(CONFIGS . "database.php",'w');
fwrite($fp,$content);
fclose($fp);
//Checking the database.php file's default values are correct or not.
/* uses('model' . DS . 'connection_manager');
$db = ConnectionManager::getInstance();
$connected = $db->getDataSource('default');
$connected = $db->getDataSource('default');
*/
$ok=false;
if(!empty($port))
$dbhost = $host.":".$port;
else
$dbhost = $host;
//print("here?");
mysql_connect($dbhost,$user,$pass) or die("Go back and check the Database Host,Port, Username & Password: Mysql Server Retuns: ".mysql_error());
//print("crash?");
mysql_select_db($db) or die("Go Back and check the access rights on the databse: Mysql Server Returns: ".mysql_error());
//print("or what?");
$ok=true;
$this->set('dbconnect',($ok)?'Pass':'Failed');
//$this->set('dbconnect',$connected->isConnected()?'Pass':'Failed' );
}
}
function index3()
{
if(isset($_POST['button']))
{
$websitename = $_POST['websitename'];
$websiteurl = $_POST['websiteurl'];
$adminuser = $_POST['adminuser'];
$adminpass = $_POST['adminpassword'];
$adminemail = $_POST['adminemail'];
$this->Installer->execute("UPDATE `sitesettings` SET `AdminEmail`='$adminemail', `SiteName` = '$websitename',`SiteUrl`='$websiteurl' WHERE `id`='1'");
$this->Installer->execute("UPDATE `users` SET `username`='$adminuser' , `password`='$adminpass' WHERE `id`='1'");
$fp = fopen(WWW_ROOT . DS . "files" . DS . "install.lock",'w');
fclose($fp);
}
}
function setup()
{
$installsql = file_get_contents(ROOT . DS . "sql" . DS . "install.sql" );
$sqlsql = file_get_contents(ROOT . DS . "sql" . DS . "sql.sql" );
$router = new Router;
$webpath= str_replace("index.php/","",$router->url('/',true));
$installsql = str_replace("[webpath]",$webpath,$installsql);
$installsql = str_replace("[root]",addslashes(ROOT . DS),$installsql);
$this->executedump($sqlsql);
$this->executedump($installsql);
}
function upgrade()
{
$changessql = file_get_contents(ROOT . DS . "sql" . DS . "changes.sql" );
$this->executedump($changessql);
}
function executedump($str)
{
$slines = explode(";\r\n",$str);
foreach ($slines as $sline)
{
if(strlen($sline)>4)
$this->Installer->execute($sline . ";");
}
}
function is__writable($path) {
//will work in despite of Windows ACLs bug
//NOTE: use a trailing slash for folders!!!
//see http://bugs.php.net/bug.php?id=27609
//see http://bugs.php.net/bug.php?id=30931
if ($path{strlen($path)-1}=='/') // recursively return a temporary file path
return $this->is__writable($path.uniqid(mt_rand()).'.tmp');
else if (is_dir($path))
return $this->is__writable($path.'/'.uniqid(mt_rand()).'.tmp');
// check tmp file for read/write capabilities
$rm = file_exists($path);
$f = @fopen($path, 'a');
if ($f===false)
return false;
fclose($f);
if (!$rm)
unlink($path);
return true;
}
}
?>