# HG changeset patch # User mortenp # Date 1236197309 -39600 # Node ID 9d5846a45086506c0fdd0575e7b2a59dbb6c0752 # Parent 9b32890a008ecb0ec582c11b0193a7498cd21372 Added contrib/web/php-moderation (Thomas Goirand) diff -r 9b32890a008e -r 9d5846a45086 ChangeLog --- a/ChangeLog Thu Mar 05 07:05:19 2009 +1100 +++ b/ChangeLog Thu Mar 05 07:08:29 2009 +1100 @@ -1,3 +1,4 @@ + o Added contrib/web/php-moderation (Thomas Goirand) 1.2.16 o Fixed injection in contrib/web/perl-user (Gerd von Egidy) 1.2.16-RC1 diff -r 9b32890a008e -r 9d5846a45086 contrib/web/php-moderation/build-translations.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/web/php-moderation/build-translations.sh Thu Mar 05 07:08:29 2009 +1100 @@ -0,0 +1,37 @@ +#!/bin/bash +# +# Build script for generating the MLMMJ moderation web interface locales +# + +set -e + +LOCALE_TRANS=fr_FR +WEB_SCRIPT_FILES=mlmmj-moderation.php + +if [ ! -d translations ]; then + echo "Wrong working directory." >&2 + exit 1 +fi + +echo "===> Managing internationalizations and localizations" + +echo "=> Extracting strings from sources" +xgettext $WEB_SCRIPT_FILES -o translations/templates.pot + +echo "=> Merging in every language .po file:" +for i in $LOCALE_TRANS; do + echo -n "$i " + msgmerge -s -U "translations/$i.po" translations/templates.pot +done + +echo "=> Creating l10n folders" +for i in $LOCALE_TRANS; do + mkdir -p "translations/locale/$i/LC_MESSAGES" +done + +echo "=> Creating binary formats of language files:" +for i in $LOCALE_TRANS; do + echo -n $i" " + msgfmt -c -v -o "translations/locale/$i/LC_MESSAGES/messages.mo" \ + "translations/$i.po" +done diff -r 9b32890a008e -r 9d5846a45086 contrib/web/php-moderation/mlmmj-moderation.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/web/php-moderation/mlmmj-moderation.php Thu Mar 05 07:08:29 2009 +1100 @@ -0,0 +1,277 @@ + + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. +*/ + +// These are the configuration variables for your list +$mod_dir = "/some/path/to/your/listname/moderation"; +$list_name = "listname"; +$list_domain = "example.com"; +$delimiter = "+"; +$from_addr = "user@example.com"; + +// Manage accepted language and cookies +$txt_default_lang = "en"; +session_register("lang"); +if(isset($_SESSION["lang"]) && !is_string($_SESSION["lang"])){ + unset($lang); +} +if(isset($_SESSION["lang"])){ + $lang = $_SESSION["lang"]; +} + +// TODO: Add some web stuffs to change the language manually on the web interface... +// ...HERE... +// + +// $lang = "fr_FR"; + +// The following code keeps the lang in sessions, so it can be changed manually above with lang=XX +// and if there's nothing in session yet, then it will parse the language set in the browser +if(isset($lang)){ + $_SESSION["lang"] = $lang; +} +if (!isset($lang)){ + if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) && $_SERVER["HTTP_ACCEPT_LANGUAGE"]) { + $all_languages = strtok($_SERVER["HTTP_ACCEPT_LANGUAGE"],";"); + $langaccept = explode(",", $all_languages); + for ($i = 0; $i < sizeof($langaccept); $i++) { + $tmplang = trim($langaccept[$i]); + $tmplang2 = substr($tmplang,0,2); + if (!isset($lang) && isset($txt_langname[$tmplang]) && $txt_langname[$tmplang]) { + $lang = $tmplang; + }elseif (!isset($lang) && isset($txt_langname[$tmplang2])) { + $lang = $tmplang2; + } + } + } + if (!isset($lang)) { + $lang = $txt_default_lang; + } + $_SESSION["lang"] = $lang; +} +header("Content-type: text/html; charset=UTF-8"); +switch($lang){ +case "fr_FR": +case "fr": + $gettext_lang = "fr_FR.UTF-8"; + break; +default: + $gettext_lang = "en_US.UTF-8"; + break; +} +if(FALSE === putenv("LC_ALL=$gettext_lang")){ + echo "Failed to putenv LC_ALL=$gettext_lang
"; +} +if(FALSE === putenv("LANG=$gettext_lang")){ + echo "Failed to putenv LANG=$gettext_lang
"; +} +if(FALSE === setlocale(LC_ALL, $gettext_lang)){ + echo "Failed to setlocale(LC_ALL,$gettext_lang)
"; +} +$pathname = bindtextdomain("messages", dirname(__FILE__) ."/translations/locale"); +$message_domain = textdomain("messages"); + +// This comes from the Mail_Mime PEAR package, under Debian, you need +// the php-mail-mime package to have this script work. +require_once 'Mail/mimeDecode.php'; + +// Email header parsing +function decodeEmail($input){ + $params['include_bodies'] = true; + $params['decode_bodies'] = true; + $params['decode_headers'] = true; + + $decoder = new Mail_mimeDecode($input); + $structure = $decoder->decode($params); + return $structure; +} + +// Reading of all the messages from the moderation folder +function getMessageList(){ + global $mod_dir; + $all_msg = array(); + // Read all files from the directory. + if (is_dir($mod_dir)) { + if ($dh = opendir($mod_dir)) { + while (($file = readdir($dh)) !== false) { + $full_path = $mod_dir . "/" . $file; + if(filetype($full_path) == "file"){ + if(FALSE === ($input = file_get_contents($full_path))){ + echo ""._("Warning: could not read")." $full_path
"; + }else{ + $struct = decodeEmail($input); + $my_msg = array(); + $my_msg["headers"] = $struct->headers; + $my_msg["body"] = $struct->body; + $my_msg["filename"] = $file; + $all_msg[] = $my_msg; + } + } + } + closedir($dh); + } + } + return $all_msg; +} + +// Printing of the list of messages to be displayed (the big table) +function printAllMessages($all_msg){ + $n = sizeof($all_msg); + $out = "\n"; + $th = " class=\"tableTitle\" "; + $out .= ""._("Date").""._("Subject").""._("From")."\n"; + $out .= ""; + for($i=0;$i<$n;$i++){ + if($i % 2){ + $cls = " class=\"alternatecolorline\" "; + }else{ + $cls = " class=\"alternatecolorline2\" "; + } + $out .= ""; + $out .= ""; + $out .= ""; + if( strlen($all_msg[$i]["headers"]["subject"]) == 0){ + $subject = _("No subject"); + }else{ + $subject = $all_msg[$i]["headers"]["subject"]; + } + $out .= ""; + $out .= ""; + $out .= "\n"; + } + $out .= "
" . "" . "" . htmlspecialchars($all_msg[$i]["headers"]["date"]) . "" . htmlspecialchars($subject) . "" . htmlspecialchars($all_msg[$i]["headers"]["from"]) . "
\n"; + $out .= _("For the selection:")." "; + $out .= ""; + $out .= ""; + return $out; +} + +// Deletion and validation of messages +if( isset($_REQUEST["validate"]) || isset($_REQUEST["delete"])){ + if( !isset($_REQUEST["msg_id"]) ){ + echo ""._("No message selected!")."
"; + }else{ + $n = sizeof($_REQUEST["msg_id"]); + for($i=0;$i<$n;$i++){ + if( !ereg("^([0-9a-f]+)\$",$_REQUEST["msg_id"][$i]) ){ + echo "".("Moderation ID format is wrong: will ignore this one!").""; + continue; + } + $fullpath = $mod_dir . "/" . $_REQUEST["msg_id"][$i]; + if(!file_exists($fullpath)){ + echo ""._("Moderation ID not found in the moderation folder!").""; + continue; + } + // TODO: Check if message is there! + if( isset($_REQUEST["validate"]) ){ +// echo "Validating message ".$_REQUEST["msg_id"][$i]."
"; + $to_addr = $list_name . $delimiter . "moderate-" . $_REQUEST["msg_id"][$i] . "@" . $list_domain; + $headers = "From: ".$from_addr; + mail($to_addr,"MLMMJ Web interface moderation","MLMMJ Web interface moderation",$headers); + }else{ +// echo "Deleting message ".$_REQUEST["msg_id"][$i]."
"; + unlink($mod_dir . "/" . $_REQUEST["msg_id"][$i]); + } + } + } +} + +// A bit of javascript to do the checkboxes inversion. +echo " + + + + + +

MLMMJ "._("moderation web interface")."

+"._("Refresh page").""; + +if( isset($_REQUEST["action"]) && $_REQUEST["action"] == show_message){ + if( !ereg("^([0-9a-f]+)\$",$_REQUEST["msgid"]) ){ + echo ""._("Message ID format is wrong: can't display!").""; + }else{ + $full_path = $mod_dir . "/" . $_REQUEST["msgid"]; + if( !file_exists($full_path) ){ + echo "".("Message does not exists!").""; + }else{ + if(FALSE === ($input = file_get_contents($full_path))){ + echo ""._("Error: could not read")." $full_path
"; + }else{ + $struct = decodeEmail($input); + echo ""._("Back to messages list")."

"; + echo ""._("From:")." " . htmlspecialchars($struct->headers["from"])."
"; + echo ""._("Date:")." " . htmlspecialchars($struct->headers["date"])."
"; + echo ""._("To:")." " . htmlspecialchars($struct->headers["to"])."
"; + echo ""._("Subject:")." " . htmlspecialchars($struct->headers["subject"])."
"; + echo ""._("Message body:")."

" . nl2br(htmlspecialchars($struct->body)); + } + } + } +}else{ + $all_msg = getMessageList(); + echo printAllMessages($all_msg); +} + +echo ' + +'; + +?> \ No newline at end of file diff -r 9b32890a008e -r 9d5846a45086 contrib/web/php-moderation/mlmmj.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/web/php-moderation/mlmmj.css Thu Mar 05 07:08:29 2009 +1100 @@ -0,0 +1,46 @@ +.alternatecolorline2 { + background-color: #E3f9ff; + font-size: 10px; + } + +.alternatecolorline { + background-color: #bcd0d6; + font-size: 10px; + } + +.tableTitle { + text-align: center; + color: #547074; + font-size: 12px; + background-color: #dbe9ed; +} + +.errorMessages { + color: #FF0000; + font-size: 14px; + font-weight: bold; +} + +a:link{color:#105278;text-decoration: none;} +a:visited{color:#105278;text-decoration: none;} +a:hover{color:#000000;text-decoration: underline;} +a:active{color:#000000;text-decoration: none;} + +html{height:100%; margin:4;} +body{height:100%;margin:4; font: 12px Arial, Helvetica, sans-serif; color: #000000;} + +/* Forms fields definitions */ +input,select,textarea { + font-family: arial; + font-size: 12px; + color: #000000; + background-color: #F6F6F2; + border-color: #ECEEE5 #F6F6F2 #F6F6F2 #ECEEE5; +} + +h3 { + text-align: center; + font-size: 20px; +} + +.footer{width:98%; text-align:center; position:absolute; bottom:0; padding:1%; } diff -r 9b32890a008e -r 9d5846a45086 contrib/web/php-moderation/translations/dot.htaccess --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/web/php-moderation/translations/dot.htaccess Thu Mar 05 07:08:29 2009 +1100 @@ -0,0 +1,2 @@ +Order Deny,Allow +Deny from all diff -r 9b32890a008e -r 9d5846a45086 contrib/web/php-moderation/translations/fr_FR.po --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/web/php-moderation/translations/fr_FR.po Thu Mar 05 07:08:29 2009 +1100 @@ -0,0 +1,100 @@ +# MLMMJ moderation web interface templates. +# Copyright (C) 2009 Thomas GOIRAND +# This file is distributed under the same license as MLMMJ package. +# Thomas Goirand , 2009. +# +msgid "" +msgstr "" +"Project-Id-Version: 0.1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-02-08 11:46+0000\n" +"PO-Revision-Date: 2009-02-08 11:15+0000\n" +"Last-Translator: Thomas Goirand \n" +"Language-Team: Thomas Goirand \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: mlmmj-moderation.php:249 +msgid "Back to messages list" +msgstr "Retour a la liste des messages" + +#: mlmmj-moderation.php:144 +msgid "Date" +msgstr "Date" + +#: mlmmj-moderation.php:251 +msgid "Date:" +msgstr "Date :" + +#: mlmmj-moderation.php:167 +msgid "Delete" +msgstr "Effacer" + +#: mlmmj-moderation.php:246 +msgid "Error: could not read" +msgstr "Erreur: impossible de lire" + +#: mlmmj-moderation.php:165 +msgid "For the selection:" +msgstr "Pour la selection :" + +#: mlmmj-moderation.php:144 +msgid "From" +msgstr "De" + +#: mlmmj-moderation.php:250 +msgid "From:" +msgstr "De:" + +#: mlmmj-moderation.php:144 +msgid "Inverse selection" +msgstr "Inverser la selection" + +#: mlmmj-moderation.php:239 +msgid "Message ID format is wrong: can't display!" +msgstr "Le format de l'ID du message est faux: affichage impossible !" + +#: mlmmj-moderation.php:254 +msgid "Message body:" +msgstr "Corp du message :" + +#: mlmmj-moderation.php:184 +msgid "Moderation ID not found in the moderation folder!" +msgstr "ID de moderation non trouve dans le dossier de moderation!" + +#: mlmmj-moderation.php:174 +msgid "No message selected!" +msgstr "Pas de message selectionne !" + +#: mlmmj-moderation.php:156 +msgid "No subject" +msgstr "Pas de sujet" + +#: mlmmj-moderation.php:235 +msgid "Refresh page" +msgstr "Rafraichir la page" + +#: mlmmj-moderation.php:144 +msgid "Subject" +msgstr "Sujet" + +#: mlmmj-moderation.php:253 +msgid "Subject:" +msgstr "Sujet :" + +#: mlmmj-moderation.php:252 +msgid "To:" +msgstr "Pour :" + +#: mlmmj-moderation.php:166 +msgid "Validate" +msgstr "Valider" + +#: mlmmj-moderation.php:122 +msgid "Warning: could not read" +msgstr "Warning : impossible de lire" + +#: mlmmj-moderation.php:234 +msgid "moderation web interface" +msgstr "interface web de moderation"