2 /********************************************************************************
3 * install.d/config.inc.php : configuration file
4 * --------------------------
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
14 var $hdecode = array('from','name','organization','subject');
15 var $parse_hdr = array('content-disposition', 'content-transfer-encoding', 'content-type', 'date', 'followup-to', 'from',
16 'message-id', 'newsgroups', 'organization', 'references', 'subject', 'x-face');
17 var $show_hdr = array('from', 'subject', 'newsgroups', 'followup', 'date', 'organization', 'references', 'x-face');
19 /** Favorites MIMEtypes to use, by order for reading multipart messages
21 var $body_mime = array('text/plain', 'text/html', 'text/richtext');
22 /** Indicate wether posting attachment is allowed
24 var $can_attach = true
;
25 /** Maximum allowed file size for attachment
27 var $maxfilesize = 100000;
28 /** Indicate wether x-face should be skinned as specials data or not
30 var $formatxface = true
;
32 /** Regexp for selecting newsgroups to show (if empty, match all newsgroups)
33 * ex : '^xorg\..*' for xorg.*
43 * Should be included in a regexp delimited using ! (eg: "!$url_regexp!i")
44 * If it matches, return 3 main parts :
45 * \\1 and \\3 are delimiters
48 * eg : preg_match("!$url_regexp!i", "[http://www.polytechnique.org]", $matches);
50 * $matches[2] = "http://www.polytechnique.org"
53 var $url_regexp = '(["\[])?((?:https?|ftp|news)://(?:&|,?[a-z@0-9.~%$£µ&i#\-+=_/\?])*)(["\]])?';
56 /** Boundary for multipart messages
58 var $boundary = 'bananaBoundary42';
59 /** Global headers to use for messages
61 var $custom = "Mime-Version: 1.0\nUser-Agent: Banana @VERSION@\n";
62 /** Global headers to use from multipart messages
64 var $custom_mp = "Content-Type: multipart/mixed; boundary=\"bananaBoundary42\"\nContent-Transfer-Encoding: 7bit\n";
65 /** Body type when using plain text
67 var $custom_plain= "Content-Type: text/plain; charset=utf-8\nContent-Transfert-Encoding: 8bit\n";
69 /** News serveur to use
71 var $host = 'news://localhost:119/';
75 var $profile = Array( 'name' => 'Anonymous <anonymouse@example.com>', 'sig' => '', 'org' => '',
76 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array());
78 var $state = Array('group' => null
, 'artid' => null
);
87 $this->_require('NetNNTP');
88 setlocale(LC_ALL
, $this->profile
['locale']);
89 $this->nntp
= new nntp($this->host
);
90 if (!$this->nntp ||
!$this->nntp
->valid
) {
95 function run($class = 'Banana')
99 Banana
::_require('misc');
100 $banana = new $class();
102 if (!$banana->nntp
) {
103 return '<p class="error">'._b_('Impossible de contacter le serveur').'</p>';
106 $group = empty($_GET['group']) ? null
: strtolower($_GET['group']);
107 $artid = empty($_GET['artid']) ? null
: strtolower($_GET['artid']);
108 $partid = !isset($_GET['part']) ?
-1 : $_GET['part'];
109 $banana->state
= Array ('group' => $group, 'artid' => $artid);
111 if (is_null($group)) {
112 if (isset($_GET['subscribe'])) {
113 return $banana->action_listSubs();
114 } elseif (isset($_POST['subscribe'])) {
115 $banana->action_saveSubs();
117 return $banana->action_listGroups();
119 } elseif (is_null($artid)) {
120 if (isset($_POST['action']) && $_POST['action'] == 'new') {
121 return $banana->action_doFup($group, isset($_POST['artid']) ?
intval($_POST['artid']) : -1);
122 } elseif (isset($_GET['action']) && $_GET['action'] == 'new') {
123 return $banana->action_newFup($group);
125 return $banana->action_showThread($group, isset($_GET['first']) ?
intval($_GET['first']) : 1);
129 if (isset($_POST['action']) && $_POST['action']=='cancel') {
130 $res = $banana->action_cancelArticle($group, $artid);
135 if (isset($_GET['action'])) {
136 switch ($_GET['action']) {
138 $res .= $banana->action_showArticle($group, $artid, $partid);
139 if ($banana->post
->checkcancel()) {
140 $form = '<p class="error">'._b_('Voulez-vous vraiment annuler ce message ?').'</p>'
141 . "<form action=\"?group=$group&artid=$artid\" method='post'><p>"
142 . '<input type="hidden" name="action" value="cancel" />'
143 . '<input type="submit" value="Annuler !" />'
150 return $banana->action_newFup($group, $artid);
154 if (isset($_GET['pj'])) {
156 if (isset($_GET['action']) && $_GET['action'] == 'view') {
159 $att = $banana->action_getAttachment($group, $artid, $_GET['pj'], $action);
166 return $res . $banana->action_showArticle($group, $artid, $partid);
170 /**************************************************************************/
172 /**************************************************************************/
174 function action_saveSubs()
179 function action_listGroups()
183 $cuts = displayshortcuts();
184 $res = '<h1>'._b_('Les forums de Banana').'</h1>'.$cuts.$this->groups
->to_html();
185 if (count($this->newgroups
->overview
)) {
186 $res .= '<p>'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'</p>';
187 $res .= $this->newgroups
->to_html();
194 function action_listSubs()
196 $this->_require('groups');
197 $this->groups
= new BananaGroups(BANANA_GROUP_ALL
);
199 $cuts = displayshortcuts();
200 $res = '<h1>'._b_('Abonnements').'</h1>'.$cuts.$this->groups
->to_html(true
).$cuts;
206 function action_showThread($group, $first)
208 if (!$this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews'])) {
209 return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>';
212 if ($first > count($this->spool
->overview
)) {
213 $first = count($this->spool
->overview
);
216 $first = $first - ($first %
$this->tmax
) +
1;
218 $cuts = displayshortcuts($first);
220 $res = '<h1>'.$group.'</h1>'.$cuts;
221 $res .= $this->spool
->to_html($first, $first+
$this->tmax
);
228 function action_showArticle($group, $id, $part)
230 if (!$this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews'])) {
231 return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>';
234 if (!$this->_newPost($id)) {
235 if ($this->nntp
->lasterrorcode
== "423") {
236 $this->spool
->delid($id);
239 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
242 $cuts = displayshortcuts();
243 $res = '<h1>'._b_('Message').'</h1>'.$cuts;
244 $res .= $this->post
->to_html($part);
251 function action_getAttachment($group, $id, $pjid, $action)
253 if (!$this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews'])) {
254 return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>';
257 if (!$this->_newPost($id)) {
258 if ($this->nntp
->lasterrorcode
== "423") {
259 $this->spool
->delid($id);
262 return displayshortcuts().'<p class="error">'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'</p>';
266 if ($this->post
->get_attachment($pjid, $action)) {
269 return displayshortcuts().'<p calss="error">'._b_('Impossible d\'accéder à la pièce jointe.').'</p>';
273 function action_cancelArticle($group, $id)
275 if (!$this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews'])) {
276 return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>';
279 if (!$this->_newPost($id)) {
280 return '<p class="error">'._b_('Impossible de trouver le message à annuler').'</p>';
282 $mid = array_search($id, $this->spool
->ids
);
284 if (!$this->post
->checkcancel()) {
285 return '<p class="error">'._b_('Vous n\'avez pas les permissions pour annuler ce message').'</p>';
287 $msg = 'From: '.$this->profile
['name']."\n"
288 . "Newsgroups: $group\n"
289 . "Subject: cmsg $mid\n"
291 . "Control: cancel $mid\n"
293 . "Message canceled with Banana";
294 if ($this->nntp
->post($msg)) {
295 $this->spool
->delid($id);
297 redirect(Array('group' => $group,
300 return '<p class="error">'._b_('Impossible d\'annuler le message').'</p>';
304 function action_newFup($group, $id = -1)
306 $subject = $body = '';
310 $this->nntp
->group($group);
311 if ($this->_newPost($id)) {
312 $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post
->headers
['subject']);
313 $body = utf8_encode($this->post
->name
." "._b_("a écrit"))." :\n".wrap($this->post
->get_body(), "> ");
314 $target = isset($this->post
->headers
['followup-to']) ?
$this->post
->headers
['followup-to'] : $this->post
->headers
['newsgroups'];
320 $cuts = displayshortcuts();
321 $html = '<h1>'._b_('Nouveau message').'</h1>'.$cuts;
322 $html .= '<form enctype="multipart/form-data" action="?group='.$group.'" method="post" accept-charset="utf-8">';
323 $html .= '<table class="bicol" cellpadding="0" cellspacing="0">';
324 $html .= '<tr><th colspan="2">'._b_('En-têtes').'</th></tr>';
325 $html .= '<tr><td>'._b_('Nom').'</td><td>'.htmlentities($this->profile
['name']).'</td></tr>';
326 $html .= '<tr><td>'._b_('Sujet').'</td><td><input type="text" name="subject" value="'.htmlentities($subject).'" size="60" /></td></tr>';
327 $html .= '<tr><td>'._b_('Forums').'</td><td><input type="text" name="newsgroups" value="'.htmlentities($target).'" size="60" /></td></tr>';
328 $html .= '<tr><td>'._b_('Suivi à').'</td><td><input type="text" name="followup" value="" size="60" /></td></tr>';
329 $html .= '<tr><td>'._b_('Organisation').'</td><td>'.$this->profile
['org'].'</td></tr>';
330 $html .= '<tr><th colspan="2">'._b_('Corps').'</th></tr>';
331 $html .= '<tr><td colspan="2"><textarea name="body" cols="74" rows="16">'
332 . to_entities($body).($this->profile
['sig'] ?
"\n\n-- \n".htmlentities($this->profile
['sig']) : '').'</textarea></td></tr>';
333 if ($this->can_attach
) {
334 $html .= '<tr><th colspan="2">'._b_('Pièce jointe').'</th></tr>';
335 $html .= '<tr><td colspan="2"><input type="hidden" name="MAX_FILE_SIZE" value="'.$this->maxfilesize
.'" />';
336 $html .= '<input type="file" name="newpj" size="40"/></td></tr>';
338 $html .= '<tr><th colspan="2">';
340 $html .= '<input type="hidden" name="artid" value="'.$id.'" />';
342 $html .= '<input type="hidden" name="action" value="new" />';
343 $html .= '<input type="submit" value="Envoyer le message" /></th></tr>';
344 $html .= '</table></form>';
349 function action_doFup($group, $artid = -1)
351 if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name'])
352 && is_utf8($_POST['org']) && is_utf8($_POST['body']) )
354 foreach(array('subject', 'name', 'org', 'body') as $key) {
355 $_POST[$key] = utf8_encode($_POST[$key]);
359 $forums = preg_split('/\s*(,|;)\s*/', $_POST['newsgroups']);
360 $fup = $_POST['followup'];
361 if (sizeof($forums) > 1) {
366 $to = implode(',', $forums);
368 if (!$this->_newSpool($group, $this->profile
['display'], $this->profile
['lastnews'])) {
369 return '<p class="error">'._b_('Impossible charger la liste des messages').'</p>';
372 $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']);
373 $msg = 'From: ' . $this->profile
['name'] . "\n"
374 . "Newsgroups: ". $to . "\n"
375 . "Subject: " . headerEncode($_POST['subject'], 128) . "\n"
376 . (empty($this->profile
['org']) ?
'' : "Organization: {$this->profile['org']}\n")
377 . (empty($fup) ?
'' : 'Followup-To: ' . $fup . "\n");
380 $this->_require('post');
381 $post = new BananaPost($artid);
382 if (!$post ||
!$post->valid
) {
383 return '<p class="error">'._b_('Impossible charger le message d\'origine').'</p>';
385 $refs = ( isset($post->headers
['references']) ?
$post->headers
['references']." " : "" );
386 $msg .= "References: $refs{$post->headers['message-id']}\n";
389 $body_headers = $this->custom_plain
;
390 $body = wrap($body, "");
392 // include attachment in the body
393 $uploaded = $this->_upload('newpj');
394 switch ($uploaded['error']) {
396 $this->custom
= $this->custom_mp
.$this->custom
;
397 $body = $this->_make_part($body_headers, $body);
398 $file_head = 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n"
399 . 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n"
400 . 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n";
401 $body .= $this->_make_part($file_head, $uploaded['data']);
402 $body .= "\n--".$this->boundary
.'--';
405 case UPLOAD_ERR_INI_SIZE
: case UPLOAD_ERR_FORM_SIZE
:
406 return '<p class="error">'._b_('Fichier trop gros pour être envoyé : ')
407 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
409 case UPLOAD_ERR_PARTIAL
:
410 return '<p class="error">'._b_('Erreur lors de l\'upload de ')
411 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
413 case UPLOAD_ERR_NO_FILE
:
414 return '<p class="error">'._b_('Le fichier spécifié n\'existe pas : ')
415 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
417 case UPLOAD_ERR_NO_TMP_DIR
:
418 return '<p class="error">'._b_('Une erreur est survenue sur le serveur lors de l\'upload de ')
419 .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
422 $this->custom
= $body_headers.$this->custom
;
425 // finalise and post the message
426 $msg .= $this->custom
.$this->profile
['customhdr']."\n".$body;
428 if ($this->nntp
->post($msg)) {
429 $dir = Array('group' => $group);
431 $dir['first'] = $artid;
435 return "<p class=\"error\">"._b_('Impossible de poster le message')."</p>".$this->action_showThread($group, $artid);
439 /**************************************************************************/
440 /* Private functions */
441 /**************************************************************************/
443 function _newSpool($group, $disp=0, $since='') {
444 $this->_require('spool');
445 if (!$this->spool ||
$this->spool
->group
!= $group) {
446 $this->spool
= new BananaSpool($group, $disp, $since);
447 if (!$this->spool ||
!$this->spool
->valid
) {
455 function _newPost($id)
457 $this->_require('post');
458 $this->post
= new BananaPost($id);
459 if (!$this->post ||
!$this->post
->valid
) {
468 $this->_require('groups');
469 $this->groups
= new BananaGroups(BANANA_GROUP_SUB
);
470 if ($this->groups
->type
== BANANA_GROUP_SUB
) {
471 $this->newgroups
= new BananaGroups(BANANA_GROUP_NEW
);
475 function _require($file)
477 require_once (dirname(__FILE__
).'/'.$file.'.inc.php');
480 function _upload($file)
482 if ($_FILES[$file]['name'] == "") {
483 return Array( 'error' => -1 );
487 $_FILES[$file]['tmp_name'];
489 // test if upload is ok
490 $file = $_FILES[$file];
491 if ($file['size'] == 0 ||
$file['error'] != 0) {
492 if ($file['error'] == 0) {
498 // adding custum data
499 $mime = rtrim(shell_exec('file -bi '.$file['tmp_name'])); //Because mime_content_type don't work :(
501 if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) {
505 $data = fread(fopen($file['tmp_name'], 'r'), $file['size']);
506 if ($encod == 'base64') {
507 $data = chunk_split(base64_encode($data));
509 $file['name'] = basename($file['name']);
510 $file['type'] = $mime;
511 $file['encoding'] = $encod;
512 $file['data'] = $data;
517 function _make_part($headers, $body)
519 return "\n--".$this->boundary
."\n".$headers."\n".$body;