Mise en place d'un systeme de bannissement SQL des fora.
authorthomas.deniau@polytechnique.org <thomas.deniau@polytechnique.org>
Mon, 17 Mar 2008 13:23:53 +0000 (14:23 +0100)
committerthomas.deniau@polytechnique.org <x2005deniau@mx1.polytechnique.org>
Tue, 18 Mar 2008 13:12:54 +0000 (14:12 +0100)
Ce systeme a trois composantes :
- Consultation d'une base SQL par inn dans le nnrpd_access.pl
- Manipulation de la base de données via plat/al
- Webservice integre a plat/al pour avoir les permissions d'un utilisateur (utilise par le BR pour bannir les utilisateurs des groupes de xorg.* feedes sur
Frankiz)

Ce commit realise le deuxieme item. La base SQL est creee par le script d'upgrade correspondant.

On peut modifier cette base
- Sur une nouvelle page admin/forums
- Sur le "edit" de chaque utilisateur.

A noter : la modification de PLTableEditor pour pouvoir editer correctement des IPs stockees comme des entiers (avec INET_ATON() dans MySQL), a condition que
le champ COMMENT des colonnes en question soit 'ip_address'.

ChangeLog
classes/pltableeditor.php
modules/admin.php
modules/banana.php
templates/admin/index.tpl
templates/admin/utilisateurs.tpl
templates/payment/retour_paypal.tpl
upgrade/0.9.16/08_forums.sql [new file with mode: 0644]

index 21cbede..0313ea2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,9 @@ New:
     * Lists:
         - Unsure mails are moderated                                       -FRU
 
+    * Forums:
+       - Ban system                                                       -THD
+       
 Bug/Wish:
 
     * Emails:
@@ -1166,6 +1169,7 @@ ACRONYMS:
     * OG : Olivier Guillaumin               <olivier.guillaumin@m4x.org>
     * PIK: Fabien Laborde       (pika)      <fabien.laborde@m4x.org>
     * SHK: Jeremy Lainé         (Sharky)    <jeremy.laine@m4x.org>
+    * THD: Thomas Deniau        (Totom)     <thomas.deniau@m4x.org>
     * VP : Vincent Palatin                  <vincent.palatin@m4x.org>
     * XdX: Alexandre Hô         (XandreX)   <alexandre.ho@m4x.org>
     * VZA: Vincent Zanotti      (vinZ2)     <vincent.zanotti@m4x.org>
index 7637238..7cfc2e8 100644 (file)
@@ -63,7 +63,7 @@ class PLTableEditor
         $this->sortfield = $idfield;
         $this->idfield_editable = $editid;
         $this->whereclause = '1';
-        $r = XDB::iterator("SHOW COLUMNS FROM $table");
+        $r = XDB::iterator("SHOW FULL COLUMNS FROM $table");
         $this->vars = array();
         while ($a = $r->next()) {
             // desc will be the title of the column
@@ -97,6 +97,9 @@ class PLTableEditor
             elseif (substr($a['Type'],0,10) == 'timestamp(' || $a['Type'] == 'datetime') {
                 $a['Type'] = 'timestamp';
             }
+            elseif ($a['Comment'] == 'ip_address') {
+                $a['Type']='ip_address';
+            }
 
             $this->vars[$a['Field']] = $a;
         }
@@ -133,6 +136,10 @@ class PLTableEditor
                 $date =& $entry[$field];
                 $date = preg_replace('/([0-9]{4})-?([0-9]{2})-?([0-9]{2})/', '\3/\2/\1', $date);
             }
+            if ($descr['Type'] == 'ip_address') {
+                $ip = & $entry[$field];
+                $ip = long2ip($ip);
+            }
         }
         return $entry;
     }
@@ -197,7 +204,7 @@ class PLTableEditor
                     $page->trig($this->delete_message);
                 } else {
                     $page->trig("L'entrée ".$id." a été supprimée.");
-                }                      
+                }
             } else {
                 $page->trig("Impossible de supprimer l'entrée.");
             }
@@ -254,6 +261,9 @@ class PLTableEditor
                     elseif ($descr['Type'] == 'date') {
                         $val = preg_replace('/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})/', '\3-\2-\1', $val);
                     }
+                    elseif ($descr['Type'] == 'ip_address') {
+                        $val = ip2long($val);
+                    }
                     $val = "'".addslashes($val)."'";
                 } else {
                     $cancel = true;
@@ -272,7 +282,7 @@ class PLTableEditor
                     $id = XDB::insertId();
                 }
             } else
-                $page->trig("Impossible de mette à jour.");
+                $page->trig("Impossible de mettre à jour.");
             if (!$this->auto_return) {
                 return $this->apply($page, 'edit', $id);
             }
index 01878a7..af011ea 100644 (file)
@@ -612,6 +612,21 @@ class AdminModule extends PLModule
                         $mailer->assign("deletion", true);
                         $mailer->send();
                         break;
+
+                    case "b_edit":
+                        XDB::execute("DELETE FROM forums.innd WHERE uid = {?}", $mr['user_id']);
+                        if (Env::v('write_perm') != "" || Env::v('read_perm') != ""  || Env::v('commentaire') != "" ) {
+                          XDB::execute("INSERT INTO forums.innd
+                                                SET ipmin = '0',
+                                                    ipmax = '4294967295',
+                                                    write_perm = {?},
+                                                    read_perm = {?},
+                                                    comment = {?},
+                                                    priority = '200',
+                                                    uid = {?}",
+                                       Env::v('write_perm'), Env::v('read_perm'), Env::v('comment'), $mr['user_id']);
+                        }
+                        break;
                 }
             }
 
@@ -640,6 +655,13 @@ class AdminModule extends PLModule
             }
 
             $page->assign('mr',$mr);
+
+            // Bans forums
+            $res = XDB::query("SELECT  write_perm, read_perm, comment
+                                 FROM  forums.innd
+                                WHERE  uid = {?}", $mr['user_id']);
+            $bans = $res->fetchOneAssoc();
+            $page->assign('bans', $bans);
         }
     }
 
@@ -921,6 +943,7 @@ class AdminModule extends PLModule
         $table_editor->describe('ext','extension du screenshot',false);
         $table_editor->apply($page, $action, $id);
     }
+
     function handler_postfix_blacklist(&$page, $action = 'list', $id = null) {
         $page->assign('xorg_title','Polytechnique.org - Administration - Postfix : Blacklist');
         $page->assign('title', 'Blacklist de postfix');
index c23749d..ad09a9b 100644 (file)
@@ -28,6 +28,7 @@ class BananaModule extends PLModule
 //            'banana/profile'      => $this->make_hook('profile', AUTH_MDP),
 //            'banana/subscribe'    => $this->make_hook('subscription', AUTH_COOKIE),
             'banana/rss'          => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS),
+            'admin/forums'   => $this->make_hook('forums_bans', AUTH_MDP, 'admin'),
         );
     }
 
@@ -146,6 +147,21 @@ class BananaModule extends PLModule
         exit;
     }
 
+    function handler_forums_bans(&$page, $action = 'list', $id = null)
+    {
+        $page->assign('xorg_title','Polytechnique.org - Administration - Bannissements des forums');
+        $page->assign('title', 'Gestion des mises au ban');
+        $table_editor = new PLTableEditor('admin/forums','forums.innd','id_innd');
+        $table_editor->describe('ipmin','min plage IP',true);
+        $table_editor->describe('ipmax','max plage IP',true);
+        $table_editor->describe('uid','utilisateur',true);
+        $table_editor->describe('write_perm','perm. poster',true);
+        $table_editor->describe('read_perm','perm. lire',true);
+        $table_editor->describe('priority','priorite',true);
+        $table_editor->describe('comment','commentaire',true);
+        $table_editor->apply($page, $action, $id);
+    }
+
     static function run_banana(&$page, $params = null)
     {
         $page->changeTpl('banana/index.tpl');
index 3e56fad..fe4dd82 100644 (file)
       <a href="survey/admin">Gestion des sondages</a>
     </td>
   </tr>
+  <tr class="pair">
+    <td>
+      <strong>Forums&nbsp;:</strong>&nbsp;&nbsp;
+      <a href="admin/forums">Gestion des mises au ban</a>
+    </td>
+  </tr>
 </table>
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index 38a0d5a..33859af 100644 (file)
@@ -70,7 +70,7 @@
 {if $mr}
 
 <p class="smaller">
-Derniére connexion le <strong>{$lastlogin|date_format:"%d %B %Y, %T"}</strong>
+Dernière connexion le <strong>{$lastlogin|date_format:"%d %B %Y, %T"}</strong>
 depuis <strong>{$host}</strong>
 </p>
 
@@ -103,6 +103,15 @@ function clean_fwd(fwd) {
   document.forms.fwds.clean_fwd.value = fwd;
   document.forms.fwds.submit();
 }
+function ban_write()
+{
+    document.forms.bans.write_perm.value = "!xorg.*";
+}
+function ban_read()
+{
+    document.forms.bans.read_perm.value = "!xorg.*";
+}
+
 // ]]>
 </script>
 {/literal}
@@ -211,7 +220,7 @@ function clean_fwd(fwd) {
         <input type="text" name="promoN" size="4" maxlength="4" value="{$mr.promo}" />
       </td>
     </tr>
-    <tr class "impair">
+    <tr class="impair">
       <td class="titre">
         Surveillance
       </td>
@@ -307,6 +316,53 @@ Pour ceci changer ses permissions en 'disabled'.
   </table>
 </form>
 
+<form id="bans" method="post" action="admin/user">
+  <table cellspacing="0" cellpadding="2" class="tinybicol">
+    <tr>
+      <th colspan="4">
+        Permissions sur les forums
+      </th>
+    </tr>
+    <tr class="impair">
+      <td class="titre">
+        Poster :
+      </td>
+      <td>
+        <input type="text" name="write_perm" size="40" maxlength="255" value="{$bans.write_perm}" />
+      </td>
+      <td class="action">
+        <a href="javascript:ban_write()">Bannir</a>
+      </td>
+    </tr>
+    <tr class="pair">
+      <td class="titre">
+        Lire :
+      </td>
+      <td>
+        <input type="text" name="read_perm" size="40" maxlength="255" value="{$bans.read_perm}" />
+      </td>
+      <td class="action">
+        <a href="javascript:ban_read()">Bannir</a>
+      </td>
+    </tr>
+    <tr class="impair">
+      <td class="titre">
+        Commentaire
+      </td>
+      <td>
+        <input type="text" name="comment" size="40" maxlength="255" value="{$bans.comment}" />
+      </td>
+      <td/>
+    </tr>
+    <tr class="center">
+      <td colspan="3">
+        <input type="hidden" name="user_id" value="{$mr.user_id}" />
+        <input type="submit" name="b_edit" value="Modifier" />
+      </td>
+    </tr>
+  </table>
+</form>
+
 <p>
 <strong>* à ne modifier qu'avec l'accord express de l'utilisateur !!!</strong>
 </p>
index 666ca23..40df8fe 100644 (file)
@@ -21,7 +21,7 @@
 {**************************************************************************}
 
 
-<h1>Télépaiments</h1>
+<h1>Télépaiements</h1>
 
 {if $erreur}
 <p>Aucun paiement n'a été effectué.</p>
diff --git a/upgrade/0.9.16/08_forums.sql b/upgrade/0.9.16/08_forums.sql
new file mode 100644 (file)
index 0000000..f208a2a
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE TABLE `forums.innd` (
+  `id_innd` int(10) unsigned NOT NULL auto_increment,
+  `ipmin` int(10) unsigned default '0' COMMENT 'ip_address',
+  `ipmax` int(10) unsigned default '4294967295' COMMENT 'ip_address',
+  `uid` smallint(5) unsigned default NULL,
+  `read_perm` varchar(100) default '!*',
+  `write_perm` varchar(100) default '!*',
+  `priority` tinyint(1) unsigned default '255',
+  `comment` text,
+  PRIMARY KEY  (`id_innd`)
+) DEFAULT CHARSET=utf8;
+
+INSERT INTO `forums.innd` VALUES (1,0,4294967295,NULL,'xorg.*,!xorg.prive.*','xorg.*,!xorg.prive.*,!xorg.pa.emploi',0,'par defaut pour tous');