diff --git a/admin/admin.php b/admin/admin.php
index 2d39a58..df20f33 100644
--- a/admin/admin.php
+++ b/admin/admin.php
@@ -1,4 +1,5 @@
=========================== */
-?>
-isAdmin()) {
diff --git a/admin/ajax.php b/admin/ajax.php
index 5c40177..bf10975 100644
--- a/admin/ajax.php
+++ b/admin/ajax.php
@@ -1,4 +1,5 @@
closeSession();
-session_start();
-$user = new user();
-$conf = new configuration();
-$user->closeSession()
?>
@@ -52,7 +48,7 @@ $user->closeSession()
@@ -241,8 +234,8 @@ if ($user->isAdmin()) {
$body = ($isEdition) ? stripslashes($post["description"]) : "";
$url = ($isEdition) ? $post["url"] : "";
-
- switch (isset($_GET["new"]) && $_GET["new"]) {
+ if (!isset($_GET['new'])) $_GET['new'] = 'default';
+ switch ($_GET["new"]) {
case "post":
$input = array("{type}", "{date}", "{id_user}", "{editTitle}", "{editBody}");
$output = array("1", $date, $_SESSION['user_id'], $title, $body);
diff --git a/admin/options.php b/admin/options.php
index 9b0ff01..fecfed7 100644
--- a/admin/options.php
+++ b/admin/options.php
@@ -1,4 +1,5 @@
isAdmin()) {
diff --git a/admin/settings.php b/admin/settings.php
index b567bd4..24ff0c1 100644
--- a/admin/settings.php
+++ b/admin/settings.php
@@ -1,4 +1,5 @@
=========================== */
-?>
-isAdmin()) {
diff --git a/admin/user.php b/admin/user.php
index e7ccb28..d4b94cf 100644
--- a/admin/user.php
+++ b/admin/user.php
@@ -1,5 +1,5 @@
=========================== */
-?>
-
.
Copyright (c) 2005 Nico Kaiser
diff --git a/classes/imgsize.php b/classes/imgsize.php
index 2963914..0e0ffa7 100644
--- a/classes/imgsize.php
+++ b/classes/imgsize.php
@@ -1,4 +1,5 @@
errors_d[1]="The login field cannot be empty";
+ $this->errors_d[2]="The password field cannot be empty";
+ $this->errors_d[3]="Password does not match the confirm password";
+ $this->errors_d[4]="The e-mail field cannot be empty";
+ $this->errors_d[5]="The installation URL field cannot be empty";
+ $this->errors_d[6]="Error establishing a database connection";
+ $this->errors_d[7]="Please add a hostname for the database server";
+ $this->errors_d[8]="Please name the database";
+ }
+
+ function run() {
+
+ if (empty($this->data)) false;
+
+ if (!$this->create_config()) return false;
+
+ $this->create_db();
+
+ if (!$this->install_db()) return false;
+
+ return true;
+ }
+
+ function create_db(){
+
+ $link = mysql_connect($this->data['db_host'], $this->data['db_login'], $this->data['db_password']);
+ if (!$link) {
+ die('Could not connect: ' . mysql_error());
+ }
+
+ $sql = 'CREATE DATABASE ' . $this->data['db_name'];
+ if (!mysql_query($sql, $link)) {
+ $link = mysql_close($link);
+ return false;
+ }
+
+ return true;
+ }
+
+ function install_db(){
+ require('config.php');
+ $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
+ $sqlStr = array();
+
+ $sqlStr[] = "CREATE TABLE `".Table_prefix."data` (
+ `id_post` int(11) NOT NULL auto_increment,
+ `title` text NULL,
+ `url` varchar(250) default NULL,
+ `description` text NULL,
+ `type` tinyint(4) NOT NULL default '1',
+ `date` datetime NOT NULL,
+ `id_user` int(10) NOT NULL,
+ PRIMARY KEY (`id_post`)
+ ) ENGINE = MYISAM ;";
+
+ $sqlStr[] = "CREATE TABLE `".Table_prefix."users` (
+ `id_user` int(10) unsigned NOT NULL auto_increment,
+ `name` varchar(100) default NULL,
+ `login` varchar(100) NOT NULL default '',
+ `password` varchar(64) NOT NULL default '',
+ `email` varchar(100) default NULL,
+ `website` varchar(150) default NULL,
+ `about` text,
+ PRIMARY KEY (`id_user`)
+ ) ENGINE = MYISAM;";
+
+ $sqlStr[] = "CREATE TABLE `".Table_prefix."config` (
+ `posts_limit` int(3) NOT NULL,
+ `title` varchar(250) NOT NULL,
+ `description` text NOT NULL,
+ `lang` varchar(10) NOT NULL,
+ `template` varchar(100) NOT NULL,
+ `url_installation` varchar(250) NOT NULL,
+ PRIMARY KEY (`title`)
+ ) ENGINE = MYISAM ;";
+
+
+
+ $sqlStr[] = "CREATE TABLE `".Table_prefix."options` (
+ `name` varchar(100) NOT NULL,
+ `val` varchar(255) NOT NULL,
+ PRIMARY KEY (`name`)
+ ) ENGINE = MYISAM ;";
+
+
+ $sqlStr[] = "CREATE TABLE `".Table_prefix."comments` (
+ `id_comment` int(11) NOT NULL auto_increment,
+ `id_post` int(11) NOT NULL,
+ `username` varchar(50) NOT NULL,
+ `email` varchar(100) NOT NULL,
+ `web` varchar(250) default NULL,
+ `content` text NOT NULL,
+ `ip_user` varchar(50) NOT NULL,
+ `comment_date` datetime NOT NULL,
+ `spam` tinyint(4) NOT NULL,
+ PRIMARY KEY (`id_comment`)
+ ) ENGINE = MYISAM ;";
+
+ $sqlStr[] = "INSERT INTO `".Table_prefix."config` VALUES (". $this->data['posts_limit'] .", '".$this->data['title']."', '".$this->data['description']."', '".$this->data['lang']."', '".$this->data['template']."', '".$this->data['url_installation']."');";
+ $sqlStr[] = "INSERT INTO `".Table_prefix."users` VALUES ('', '', '".$this->data['login']."', '".md5($this->data['password'])."', '".$this->data['email']."', '".$this->data['website']."', '".$this->data['about']."');";
+ $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('url_friendly', '1');";
+ $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('rich_text', '0');";
+ $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('allow_comments', '0');";
+ $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('offset_city', '".$this->data['offset_city']."');";
+ $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('offset_time', '".$this->data['offset_time']."');";
+
+ foreach($sqlStr as $key => $query){
+ if(!$db->ejecutarConsulta($query)){
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ function inerrors($n) {
+ if ( strpos($this->errors,$n)===false) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ function mostrarerror($n) {
+ if ($this->inerrors($n)) {
+ return ''.$this->errors_d[$n].'';
+ } else {
+ return "";
+ }
+ }
+
+ function is_gelato_installed(){
+ if (!$this->check_for_config()){
+ return false;
+ } else {/*
+ if (!$this->is_db_installed()){
+ return false;
+ }
+ */
+ }
+
+ return true;
+ }
+ /*
+ function is_db_installed(){
+
+ global $db;
+
+ if (function_exists($db->ejecutarConsulta)){
+ $sqlStr = "SELECT * FROM `".Table_prefix."config`";
+ if($db->ejecutarConsulta($sqlStr)) {
+ return ($db->contarRegistros() > 0);
+ }
+ } else {
+ false;
+ }
+
+ }
+ */
+ function check_for_config(){
+ if(!file_exists('config.php')) return false;
+ if(!defined('DB_Server')) return false;
+ if(!defined('DB_name')) return false;
+ if(!defined('DB_User')) return false;
+ if(!defined('DB_Password')) return false;
+
+ return true;
+ }
+
+ function create_config(){
+ $config = fopen("config.php", 'w+');
+ $contents = '
+
+ =========================== */
+
+define(\'DB_Server\', \''. $this->data['db_host'] . '\');
+define(\'DB_name\', \''. $this->data['db_name'] . '\');
+define(\'DB_User\', \''. $this->data['db_login'] . '\');
+define(\'DB_Password\', \''. $this->data['db_password'] . '\');
+define(\'Table_prefix\', \'gel_\');
+define(\'Absolute_Path\', dirname(__FILE__).DIRECTORY_SEPARATOR);
+
+?>';
+
+ if (fwrite($config, $contents) === FALSE) {
+ $this->errors = "Could not write config file to directory";
+ return false;
+ }
+ fclose($config);
+ return true;
+ }
+
+ function check_form(){
+
+ $action="";
+
+ if (isset($this->data['action'])){
+ $action=$this->data['action'];
+ }
+
+ if (!$this->is_gelato_installed()){
+
+ $this->showForm = true;
+
+
+ if ($action=="config") {
+
+ $sep_err="";
+ $this->errors = false;
+
+ if (!$this->data['login'] || !$this->data['db_login']) {
+ $this->errors =$this->errors.$sep_err."1";
+ $sep_err="|";
+ }
+ if (!$this->data['password'] || !$this->data['db_password']) {
+ $this->errors=$this->errors.$sep_err."2";
+ $sep_err="|";
+ }
+ if (!$this->data['email']) {
+ $this->errors=$this->errors.$sep_err."4";
+ $sep_err="|";
+ }
+ if (!$this->data['url_installation'] ) {
+ $this->errors=$this->errors.$sep_err."5";
+ $sep_err="|";
+ }
+ if (!$this->data['db_host'] ) {
+ $this->errors=$this->errors.$sep_err."7";
+ $sep_err="|";
+ }
+ if (!$this->data['db_name'] ) {
+ $this->errors=$this->errors.$sep_err."8";
+ $sep_err="|";
+ }
+ if ($this->data['password']!=$_POST['password2'] || $_POST['db_password']!=$_POST['db_password2'] ) {
+ $this->errors=$this->errors.$sep_err."3";
+ $sep_err="|";
+ }
+ $off_r= split("," , $this->data['time_offsets']);
+ $this->data['offset_time'] = $off_r[0];
+ $this->data['offset_city'] = $off_r[1];
+ unset($this->data['time_offsets']);
+
+ if (!$this->errors) {
+
+ if ($this->run($this->data)) {
+ $this->showForm=false;
+ } else {
+ $this->errors=$this->errors.$sep_err."6";
+ $sep_err="|";
+ $this->showForm=true;
+ }
+ } else {
+ $this->showForm=true;
+ }
+ }
+ }
+ }
+}
+?>
\ No newline at end of file
diff --git a/classes/lang.functions.php b/classes/lang.functions.php
index d7d214b..c64c49a 100644
--- a/classes/lang.functions.php
+++ b/classes/lang.functions.php
@@ -1,4 +1,5 @@
.
diff --git a/classes/templates.class.php b/classes/templates.class.php
index c6c0aad..b6d1682 100644
--- a/classes/templates.class.php
+++ b/classes/templates.class.php
@@ -1,4 +1,6 @@
cookie_life = 60*24*3600;
+ $this->cookieTime = time();
$this->conf = new configuration();
}
function isAdmin() {
- if(isset($_COOKIE["gelato_cookie"]) && $_COOKIE["gelato_cookie"] && $_COOKIE["gelato_cookie"]!="") {
- $galleta = explode(",",$_COOKIE["gelato_cookie"]);
- if ($this->validateUser($galleta[1],$galleta[2])) {
- $_SESSION["user_id"]=$galleta[0];
- $_SESSION["user_login"]=$galleta[1];
- } else {
- $_SESSION["user_id"]="";
- $_SESSION["user_login"]="";
- unset($_SESSION["user_id"]);
- unset($_SESSION["user_login"]);
- }
- }
- if (isset($_SESSION["user_id"]) && isset($_SESSION["user_login"])) {
+
+ if ((!empty($_SESSION["user_id"]) && !empty($_SESSION["user_login"])) && (isset($_SESSION['authenticated']) && $_SESSION['authenticated']==true)) {
return true;
}
+
+ if(isset($_COOKIE["PHPSESSID"]) && $_COOKIE["PHPSESSID"]!="") {
+ if ((!empty($_SESSION["user_id"]) && !empty($_SESSION["user_login"])) && (isset($_SESSION['authenticated']) && $_SESSION['authenticated']==true)) {
+ return true;
+ }
+ }
+
return false;
+
}
- function validateUser($user="", $password="") {
- if ($this->ejecutarConsulta("SELECT id_user, login, password FROM ".$this->conf->tablePrefix."users WHERE login='".sql_escape($user)."' AND password='".$password."'")) {
+ function validateUser($username="", $password="") {
+
+ if ($this->ejecutarConsulta("SELECT id_user, login, password FROM ".$this->conf->tablePrefix."users WHERE login='".sql_escape($username)."' AND password='".$password."'")) {
if ($this->contarRegistros()>0) {
$register=$this->obtenerRegistro();
$_SESSION['user_id']=$register["id_user"];
$_SESSION['user_login']=$register["login"];
+ $_SESSION['authenticated'] = true;
if (isset($_POST["save_pass"])) {
- $cookie_life = 60*24*3600;
- setcookie("gelato_cookie",$register["id_user"].",".$register["login"].",".$register["password"],time()+$cookie_life);
- }
+ $this->persist = true;
+ setcookie("PHPSESSID",session_id(),$this->cookieTime+$this->cookie_life);
+ }
return true;
} else {
return false;
@@ -59,18 +65,9 @@ class user extends Conexion_Mysql {
}
}
- function closeSession() {
- $_SESSION = array();
- $_COOKIE["gelato_cookie"]="";
- setcookie("gelato_cookie","",time()-3600,'/','',0);
- setcookie("gelato_cookie","",0);
- unset($_COOKIE["gelato_cookie"]);
- unset($_COOKIE[session_name()]);
- if (session_destroy()) {
- return true;
- } else {
- return false;
- }
+ function closeSession() {
+ if (!$this->persist) session_destroy();
+ return true;
}
function userExist($user="") {
@@ -82,6 +79,10 @@ class user extends Conexion_Mysql {
}
}
}
+
+ function isAuthenticated(){
+ return $this->isAdmin();
+ }
function addUser($fieldsArray) {
if ($this->ejecutarConsulta("SELECT id_user FROM ".$this->conf->tablePrefix."users WHERE login='".$fieldsArray['login']."'")) {
diff --git a/comments.php b/comments.php
index f75acee..f13543c 100644
--- a/comments.php
+++ b/comments.php
@@ -1,4 +1,5 @@
diff --git a/index.php b/index.php
index cec60c3..b291fc1 100644
--- a/index.php
+++ b/index.php
@@ -1,5 +1,6 @@
template);
// My approach to MVC
-
- $configFile = dirname(__FILE__).DIRECTORY_SEPARATOR."config.php";
-
- if (!file_exists($configFile)) {
- $mensaje = "
- Error reading configuration file
- There doesn't seem to be a config.php file. I need this before we can get started.
- This either means that you did not rename the config-sample.php file to config.php.
";
- die($mensaje);
- } else {
- require(dirname(__FILE__).DIRECTORY_SEPARATOR."config.php");
- }
-
- include("classes/configuration.class.php");
- include("classes/textile.class.php");
- include("classes/gelato.class.php");
- include("classes/templates.class.php");
- include("classes/pagination.class.php");
- include("classes/user.class.php");
- include("classes/comments.class.php");
-
- $user = new user();
- $conf = new configuration();
- $tumble = new gelato();
- $template = new plantillas($conf->template);
+
if(isset($_SERVER['PATH_INFO'])) $param_url = explode("/",$_SERVER['PATH_INFO']);
@@ -78,7 +61,7 @@
$template->cargarPlantilla($input, $output, "template_header");
$template->mostrarPlantilla();
- if ($user->isAdmin()) {
+ if ($user->isAuthenticated()) {
$input = array("{User}", "{URL_Tumble}");
$output = array($_SESSION["user_login"], $conf->urlGelato);
diff --git a/install.php b/install.php
index b368fb1..b0b2690 100644
--- a/install.php
+++ b/install.php
@@ -1,4 +1,5 @@
=========================== */
-?>
-Error reading configuration file
- There doesn't seem to be a config.php file. I need this before we can get started.
- This either means that you did not rename the config-sample.php file to config.php.
";
- die($mensaje);
-} else {
- require(dirname(__FILE__).DIRECTORY_SEPARATOR."config.php");
- $showForm = true;
-}
-
-include("classes/functions.php");
+include('classes/functions.php');
+include('classes/install.class.php');
-$errors_d=array();
-$errors_d[1]="The login field cannot be empty";
-$errors_d[2]="The password field cannot be empty";
-$errors_d[3]="Password does not match the confirm password";
-$errors_d[4]="The e-mail field cannot be empty";
-$errors_d[5]="The installation URL field cannot be empty";
-$errors_d[6]="Error establishing a database connection";
-
-$action="";
-$errors="";
-
-if (isset($_POST['action'])){
- $action=$_POST['action'];
-}
-
-if ($action=="config" && !is_db_installed()) {
-
- $sep_err="";
-
- if (!$_POST['login']) {
- $errors=$errors.$sep_err."1";
- $sep_err="|";
- }
- if (!$_POST['password']) {
- $errors=$errors.$sep_err."2";
- $sep_err="|";
- }
- if (!$_POST['email']) {
- $errors=$errors.$sep_err."4";
- $sep_err="|";
- }
- if (!$_POST['url_installation']) {
- $errors=$errors.$sep_err."5";
- $sep_err="|";
- }
- if ($_POST['password']!=$_POST['password2']) {
- $errors=$errors.$sep_err."3";
- $sep_err="|";
- }
- $off_r= split("," , $_POST['time_offsets']);
- $_POST['offset_time'] = $off_r[0];
- $_POST['offset_city'] = $off_r[1];
- unset($_POST['time_offsets']);
-
- if (!$errors) {
- if (install_db($_POST['login'], $_POST['password'], $_POST['email'], $_POST['title'], $_POST['description'], $_POST['url_installation'], $_POST['posts_limit'], $_POST['lang'], $_POST['template'], $_POST['website'], $_POST['about'], $_POST['offset_city'], $_POST['offset_time'])) {
- $showForm=false;
- } else {
- $errors=$errors.$sep_err."6";
- $sep_err="|";
- $showForm=true;
- }
- } else {
- $showForm=true;
- }
-}
-
-
- $showForm = (!is_db_installed());
+$install = new Install();
+$install->data = $_POST;
+$install->check_form();
?>
@@ -110,7 +42,7 @@ if ($action=="config" && !is_db_installed()) {
showForm) {
?>
@@ -122,17 +54,32 @@ if ($action=="config" && !is_db_installed()) {