Fix: bad security access

Fix: add entity in facture_rec and constraint with fk_soc
Fix: uniformize code
This commit is contained in:
Regis Houssin 2009-11-19 11:25:08 +00:00
parent 02ece7082c
commit d6e0912f6c
10 changed files with 130 additions and 90 deletions

View File

@ -2988,7 +2988,6 @@ CREATE TABLE `llx_facture_rec` (
`last_gen` varchar(7) default NULL,
PRIMARY KEY (`rowid`),
UNIQUE KEY `idx_facture_rec_uk_titre` (`titre`),
KEY `idx_facture_rec_fksoc` (`fk_soc`),
KEY `idx_facture_rec_fk_soc` (`fk_soc`),
KEY `idx_facture_rec_fk_user_author` (`fk_user_author`),
KEY `idx_facture_rec_fk_projet` (`fk_projet`),

View File

@ -4961,7 +4961,7 @@
<INDEXCOLUMN idColumn="1916" LengthParam="0" />
</INDEXCOLUMNS>
</INDEX>
<INDEX ID="1933" IndexName="idx_facture_rec_fksoc" IndexKind="1" FKRefDef_Obj_id="-1">
<INDEX ID="1933" IndexName="idx_facture_rec_fk_soc" IndexKind="1" FKRefDef_Obj_id="-1">
<INDEXCOLUMNS>
<INDEXCOLUMN idColumn="1918" LengthParam="0" />
</INDEXCOLUMNS>

View File

@ -21,11 +21,11 @@
*/
/**
\file htdocs/categories/categorie.php
\ingroup category
\brief Page de l'onglet categories
\version $Id$
*/
* \file htdocs/categories/categorie.php
* \ingroup category
* \brief Page de l'onglet categories
* \version $Id$
*/
require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php");
@ -57,8 +57,8 @@ if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user,$objecttype,$objectid,$dbtablename,'','',$fieldid);
/*
* Actions
*/
* Actions
*/
//Suppression d'un objet d'une categorie
if ($_REQUEST["removecat"])
@ -113,8 +113,8 @@ if (isset($_REQUEST["catMere"]) && $_REQUEST["catMere"]>=0)
/*
* View
*/
* View
*/
$html = new Form($db);
@ -136,7 +136,7 @@ if ($_GET["socid"])
llxHeader("","",$langs->trans("Category"));
/*
/*
* Affichage onglets
*/
$head = societe_prepare_head($soc);
@ -203,7 +203,7 @@ if ($_GET["socid"])
}
else if ($_GET["id"] || $_GET["ref"])
{
/*
/*
* Fiche categorie de produit
*/
require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php");
@ -262,9 +262,9 @@ else if ($_GET["id"] || $_GET["ref"])
}
/*
* Fonction Barre d'actions
*/
/**
* Fonction Barre d'actions
*/
function formCategory($db,$object,$type,$typeid)
{
global $user,$langs,$html,$bc;

View File

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -31,7 +32,7 @@ require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
/**
* \class FactureRec
* \brief Classe de gestion des factures recurrentes/Mod<EFBFBD>les
* \brief Classe de gestion des factures recurrentes/Modeles
*/
class FactureRec extends Facture
{
@ -43,8 +44,10 @@ class FactureRec extends Facture
var $id ;
var $socid; // Id client
var $client; // Objet societe client (<28> charger par fetch_client)
//! Id customer
var $socid;
//! Customer object (charging by fetch_client)
var $client;
var $number;
var $author;
@ -61,7 +64,7 @@ class FactureRec extends Facture
/**
* \brief Initialisation de la class
* \brief Initialisation de la classe
*/
function FactureRec($DB, $facid=0)
{
@ -75,7 +78,7 @@ class FactureRec extends Facture
*/
function create($user)
{
global $langs;
global $conf, $langs;
$error=0;
@ -99,11 +102,32 @@ class FactureRec extends Facture
// On positionne en mode brouillon la facture
$this->brouillon = 1;
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (titre, fk_soc, datec, amount, remise, note, fk_user_author,fk_projet, fk_cond_reglement, fk_mode_reglement) ";
$sql.= " VALUES ('$this->titre', '$facsrc->socid', ".$this->db->idate(mktime()).", '$facsrc->amount', '$facsrc->remise', '".addslashes($this->note)."','$user->id',";
$sql.= " ".($facsrc->projetid?"'".$facsrc->projetid."'":"null").", ";
$sql.= " '".$facsrc->cond_reglement_id."',";
$sql.= " '".$facsrc->mode_reglement_id."')";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (";
$sql.= "titre";
$sql.= ", fk_soc";
$sql.= ", entity";
$sql.= ", datec";
$sql.= ", amount";
$sql.= ", remise";
$sql.= ", note";
$sql.= ", fk_user_author";
$sql.= ", fk_projet";
$sql.= ", fk_cond_reglement";
$sql.= ", fk_mode_reglement";
$sql.= ") VALUES (";
$sql.= "'".$this->titre."'";
$sql.= ", '".$facsrc->socid."'";
$sql.= ", ".$conf->entity;
$sql.= ", ".$this->db->idate(mktime());
$sql.= ", '".$facsrc->amount."'";
$sql.= ", '".$facsrc->remise."'";
$sql.= ", '".addslashes($this->note)."'";
$sql.= ", '".$user->id."'";
$sql.= ", ".($facsrc->projetid?"'".$facsrc->projetid."'":"null");
$sql.= ", '".$facsrc->cond_reglement_id."'";
$sql.= ", '".$facsrc->mode_reglement_id."'";
$sql.= ")";
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec");
@ -158,12 +182,12 @@ class FactureRec extends Facture
/**
* \brief Recupere l'objet facture et ses lignes de factures
* \param rowid id de la facture a recuperer
* \param societe_id id de societe
* \param socid id de societe
* \return int >0 si ok, <0 si ko
*/
function fetch($rowid, $societe_id=0)
function fetch($rowid, $socid=0)
{
dol_syslog("Facture::Fetch rowid=".$rowid.", societe_id=".$societe_id, LOG_DEBUG);
dol_syslog("Facture::Fetch rowid=".$rowid.", societe_id=".$socid, LOG_DEBUG);
$sql = 'SELECT f.titre,f.fk_soc,f.amount,f.tva,f.total,f.total_ttc,f.remise_percent,f.remise_absolue,f.remise';
$sql.= ','.$this->db->pdate('f.date_lim_reglement').' as dlr';
@ -177,10 +201,8 @@ class FactureRec extends Facture
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'co_fa as cf ON cf.fk_facture = f.rowid';
$sql.= ' WHERE f.rowid='.$rowid;
if ($societe_id > 0)
{
$sql.= ' AND f.fk_soc = '.$societe_id;
}
if ($socid > 0) $sql.= ' AND f.fk_soc = '.$socid;
$result = $this->db->query($sql);
if ($result)
@ -426,19 +448,34 @@ class FactureRec extends Facture
$product_type=$product->type;
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (fk_facture,description,price,qty,tva_taux, fk_product, product_type, remise_percent, subprice, remise, total_ht, total_tva, total_ttc)";
$sql .= " VALUES ('".$facid."', '".addslashes($desc)."'";
$sql .= ",".price2num($price);
$sql .= ",".price2num($qty);
$sql .= ",".price2num($txtva);
$sql .= ",".($fk_product?"'".$fk_product."'":"null");
$sql .= ",".$product_type;
$sql .= ",'".price2num($remise_percent)."'";
$sql .= ",'".price2num($pu_ht)."'";
$sql .= ",'".price2num($remise)."'";
$sql .= ",'".price2num($total_ht)."'";
$sql .= ",'".price2num($total_tva)."'";
$sql .= ",'".price2num($total_ttc)."') ;";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (";
$sql.= "fk_facture";
$sql.= ", description";
$sql.= ", price";
$sql.= ", qty";
$sql.= ", tva_taux";
$sql.= ", fk_product";
$sql.= ", product_type";
$sql.= ", remise_percent";
$sql.= ", subprice";
$sql.= ", remise";
$sql.= ", total_ht";
$sql.= ", total_tva";
$sql.= ", total_ttc";
$sql.= ") VALUES (";
$sql.= "'".$facid."'";
$sql.= ", '".addslashes($desc)."'";
$sql.= ", ".price2num($price);
$sql.= ", ".price2num($qty);
$sql.= ", ".price2num($txtva);
$sql.= ", ".($fk_product?"'".$fk_product."'":"null");
$sql.= ", ".$product_type;
$sql.= ", '".price2num($remise_percent)."'";
$sql.= ", '".price2num($pu_ht)."'";
$sql.= ", '".price2num($remise)."'";
$sql.= ", '".price2num($total_ht)."'";
$sql.= ", '".price2num($total_tva)."'";
$sql.= ", '".price2num($total_ttc)."') ;";
dol_syslog("FactureRec::addline sql=".$sql, LOG_DEBUG);
if ($this->db->query( $sql))

View File

@ -21,7 +21,7 @@
/**
* \file htdocs/compta/facture/fiche-rec.php
* \ingroup facture
* \brief Page d'affichage d'une facture r<EFBFBD>current
* \brief Page d'affichage d'une facture recurrente
* \version $Id$
*/
@ -30,14 +30,14 @@ require_once("./facture-rec.class.php");
require_once(DOL_DOCUMENT_ROOT."/project.class.php");
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
if (!$user->rights->facture->lire)
accessforbidden();
// Security check
$facid=isset($_GET["facid"])?$_GET["facid"]:$_POST["facid"];
$action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'facture', $facid,'facture_rec');
$objecttype = 'facture_rec';
if ($action == "create" || $action == "add") $objecttype = '';
$result = restrictedArea($user, 'facture', $facid, $objecttype);
if ($page == -1)
{
@ -95,11 +95,9 @@ llxHeader('',$langs->trans("RepeatableInvoices"),'ch-facture.html#s-fac-facture-
$html = new Form($db);
/*********************************************************************
*
* Mode creation
*
************************************************************************/
/*
* Create mode
*/
if ($_GET["action"] == 'create')
{
print_fiche_titre($langs->trans("CreateRepeatableInvoice"));
@ -167,7 +165,7 @@ if ($_GET["action"] == 'create')
}
/*
* Lines de factures
* Invoice lines
*/
print '<table class="noborder" width="100%">';
print '<tr><td colspan="3">';
@ -327,12 +325,10 @@ if ($_GET["action"] == 'create')
}
}
else
/* *************************************************************************** */
/* */
/* */
/* */
/* *************************************************************************** */
{
/*
* View mode
*/
if ($facid > 0)
{
@ -485,13 +481,12 @@ else
{
print $langs->trans("ErrorRecordNotFound");
}
} else {
/***************************************************************************
* *
* Mode Liste *
* *
* *
***************************************************************************/
}
else
{
/*
* List mode
*/
if ($user->rights->facture->lire)
{

View File

@ -19,7 +19,7 @@
/**
\file htdocs/compta/paiement_charge.php
\ingroup compta
\brief Page de création d'un paiement d'une charge
\brief Page de creation d'un paiement d'une charge
\version $Id$
*/
@ -31,7 +31,7 @@ $langs->load("bills");
$chid=isset($_GET["id"])?$_GET["id"]:$_POST["id"];
// Sécurité accés client
// Securite acces client
if ($user->societe_id > 0)
{
$action = '';
@ -110,12 +110,12 @@ if ($_POST["action"] == 'add_paiement')
$acc = new Account($db, $_POST["accountid"]);
$bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, -abs($total), $paiement->num_paiement, '', $user);
// Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi le paiement qui a généré l'écriture bancaire
// Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi le paiement qui a g<EFBFBD>n<EFBFBD>r<EFBFBD> l'<27>criture bancaire
if ($bank_line_id > 0)
{
$paiement->update_fk_bank($bank_line_id);
// Mise a jour liens (pour chaque charge concernée par le paiement)
// Mise a jour liens (pour chaque charge concern<EFBFBD>e par le paiement)
foreach ($paiement->amounts as $key => $value)
{
$acc->add_url_line($bank_line_id, $chid, DOL_URL_ROOT.'/compta/sociales/charges.php?id=', '(socialcontribution)','sc');
@ -129,13 +129,13 @@ if ($_POST["action"] == 'add_paiement')
}
else {
$db->rollback();
$mesg = "Echec de la création entrée compte: ".$db->error();
$mesg = "Echec de la cr<EFBFBD>ation entr<74>e compte: ".$db->error();
}
}
else
{
$db->rollback();
$mesg = "Echec de la création du paiement: paiement_id=$paiement_id ".$db->error();
$mesg = "Echec de la cr<EFBFBD>ation du paiement: paiement_id=$paiement_id ".$db->error();
}
}
@ -229,7 +229,7 @@ if ($_GET["action"] == 'create')
print "<td><input name=\"num_paiement\" type=\"text\"></td></tr>\n";
/*
* Autres charges impayées
* Autres charges impay<EFBFBD>es
*/
$num = 1;
$i = 0;

View File

@ -1981,10 +1981,10 @@ class Facture extends CommonObject
$sql.= ' AND type < 2';
if ($option == 'validated') $sql.= ' AND fk_statut = 1';
// PROTECTION BAD DATA
// Au cas ou base corrompue et qu'il y a une facture de remplacement valid<EFBFBD>e
// et une autre non, on donne priorit<EFBFBD> <20> la valid<69>e.
// Ne devrait pas arriver (sauf si acc<EFBFBD>s concurrentiel et que 2 personnes
// ont cr<EFBFBD><EFBFBD> en meme temps une facture de remplacement pour la meme facture)
// Au cas ou base corrompue et qu'il y a une facture de remplacement validee
// et une autre non, on donne priorite a la validee.
// Ne devrait pas arriver (sauf si acces concurrentiel et que 2 personnes
// ont cree en meme temps une facture de remplacement pour la meme facture)
$sql.= ' ORDER BY fk_statut DESC';
$resql=$this->db->query($sql);
@ -2009,7 +2009,7 @@ class Facture extends CommonObject
}
/**
* \brief Retourne le libell<EFBFBD> du type de facture
* \brief Retourne le libelle du type de facture
* \return string Libelle
*/
function getLibType()
@ -2024,8 +2024,8 @@ class Facture extends CommonObject
/**
* \brief Retourne le libell<EFBFBD> du statut d'une facture (brouillon, valid<EFBFBD>e, abandonn<EFBFBD>e, pay<EFBFBD>e)
* \param mode 0=libell<EFBFBD> long, 1=libell<EFBFBD> court, 2=Picto + Libell<EFBFBD> court, 3=Picto, 4=Picto + Libell<EFBFBD> lon
* \brief Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
* \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle lon
* \param alreadypaid 0=Not payment already done, 1=Some payments already done
* \return string Libelle
*/
@ -2035,13 +2035,13 @@ class Facture extends CommonObject
}
/**
* \brief Renvoi le libell<EFBFBD> d'un statut donn<EFBFBD>
* \brief Renvoi le libelle d'un statut donne
* \param paye Etat paye
* \param statut Id statut
* \param mode 0=libell<EFBFBD> long, 1=libell<EFBFBD> court, 2=Picto + Libell<EFBFBD> court, 3=Picto, 4=Picto + Libell<EFBFBD> long, 5=Libell<EFBFBD> court + Pict
* \param alreadypaid Montant deja pay<EFBFBD>
* \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Pict
* \param alreadypaid Montant deja paye
* \param type Type facture
* \return string Libell<EFBFBD> du statut
* \return string Libelle du statut
*/
function LibStatut($paye,$statut,$mode=0,$alreadypaid=-1,$type=0)
{

View File

@ -136,6 +136,7 @@ ALTER TABLE llx_projet ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER ref;
ALTER TABLE llx_adherent ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid;
ALTER TABLE llx_adherent_type ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid;
ALTER TABLE llx_adherent_options_label ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER name;
ALTER TABLE llx_facture_rec ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER fk_soc;
ALTER TABLE llx_rights_def DROP PRIMARY KEY;
ALTER TABLE llx_dolibarr_modules DROP PRIMARY KEY;
@ -169,6 +170,7 @@ ALTER TABLE llx_projet DROP INDEX ref;
ALTER TABLE llx_boxes_def DROP INDEX uk_boxes_def;
ALTER TABLE llx_adherent DROP INDEX uk_adherent_login;
ALTER TABLE llx_adherent_type DROP INDEX uk_adherent_type_libelle;
ALTER TABLE llx_facture_rec DROP INDEX idx_facture_rec_uk_titre;
ALTER TABLE llx_rights_def ADD PRIMARY KEY pk_rights_def (id, entity);
ALTER TABLE llx_dolibarr_modules ADD PRIMARY KEY pk_dolibarr_modules (numero, entity);
@ -201,11 +203,14 @@ ALTER TABLE llx_boxes_def ADD UNIQUE INDEX uk_boxes_def (file, entity);
ALTER TABLE llx_adherent ADD UNIQUE INDEX uk_adherent_login (login, entity);
ALTER TABLE llx_adherent_type ADD UNIQUE INDEX uk_adherent_type_libelle (libelle, entity);
ALTER TABLE llx_adherent_options_label ADD UNIQUE INDEX uk_adherent_options_label_name (name, entity);
ALTER TABLE llx_facture_rec ADD UNIQUE INDEX idx_facture_rec_uk_titre (titre, entity);
ALTER TABLE llx_projet ADD INDEX idx_projet_fk_soc (fk_soc);
-- V4.1 update llx_projet set fk_soc=null where fk_soc is not null and fk_soc not in (select rowid from llx_societe);
ALTER TABLE llx_projet ADD CONSTRAINT fk_projet_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
ALTER TABLE llx_facture_rec ADD CONSTRAINT fk_facture_rec_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
UPDATE llx_const SET entity=0 WHERE name='MAIN_MODULE_USER' AND entity=1;
UPDATE llx_const SET entity=0 WHERE name='MAIN_POPUP_CALENDAR' AND entity=1;

View File

@ -1,6 +1,7 @@
-- ============================================================================
-- Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -20,11 +21,12 @@
-- ============================================================================
ALTER TABLE llx_facture_rec ADD UNIQUE INDEX idx_facture_rec_uk_titre (titre, entity);
ALTER TABLE llx_facture_rec ADD INDEX idx_facture_rec_fk_soc (fk_soc);
ALTER TABLE llx_facture_rec ADD INDEX idx_facture_rec_fk_user_author (fk_user_author);
ALTER TABLE llx_facture_rec ADD INDEX idx_facture_rec_fk_projet (fk_projet);
ALTER TABLE llx_facture_rec ADD CONSTRAINT fk_facture_rec_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
ALTER TABLE llx_facture_rec ADD CONSTRAINT fk_facture_rec_fk_user_author FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid);
ALTER TABLE llx_facture_rec ADD CONSTRAINT fk_facture_rec_fk_projet FOREIGN KEY (fk_projet) REFERENCES llx_projet (rowid);
ALTER TABLE llx_facture_rec ADD UNIQUE INDEX idx_facture_rec_uk_titre (titre);

View File

@ -1,6 +1,7 @@
-- ===========================================================================
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -23,6 +24,7 @@ create table llx_facture_rec
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
titre varchar(50) NOT NULL,
entity integer DEFAULT 1 NOT NULL, -- multi company id
fk_soc integer NOT NULL,
datec datetime, -- date de creation
@ -35,9 +37,9 @@ create table llx_facture_rec
total_ttc real DEFAULT 0,
fk_user_author integer, -- createur
fk_projet integer, -- projet auquel est associ<EFBFBD> la facture
fk_projet integer, -- projet auquel est associe la facture
fk_cond_reglement integer DEFAULT 0, -- condition de reglement
fk_mode_reglement integer DEFAULT 0, -- mode de reglement (Virement, Pr<EFBFBD>l<EFBFBD>vement)
fk_mode_reglement integer DEFAULT 0, -- mode de reglement (Virement, Prelevement)
date_lim_reglement date, -- date limite de reglement
note text,