7
It's a lot dirty!!!
But, it's only an idea...
--------------
just put this in the /etc/aliases file:
Quote:
parser.c file
-------------
Quote:
#include
int main(void)
{
char mycad[1024];
char total[10000];
char *pos;
char XoopUser[1024], XoopPasswd[1024], XoopTitle[1024], XoopMessage[10000], XoopTopic[1024];
printf("Received parameters:\n");
while ( !feof(stdin) )
{
fscanf(stdin,"%[^\n]", mycad );
fgetc(stdin);
if ( strstr ( mycad, "XoopUser:" ) )
{
strcpy (XoopUser, strstr ( mycad, ":" ) + 1);
printf("->XoopUser:%s\n",XoopUser);
}
if ( strstr ( mycad, "XoopPasswd:" ) )
{
strcpy (XoopPasswd, strstr ( mycad, ":" ) + 1);
printf("->XoopPasswd:%s\n",XoopPasswd);
}
if ( strstr ( mycad, "XoopTitle:" ) )
{
strcpy (XoopTitle, strstr ( mycad, ":" ) + 1);
printf("->XoopTitle:%s\n",XoopTitle);
}
if ( strstr ( mycad, "XoopMessage:" ))
{
strcpy (XoopMessage, strstr ( mycad, ":" )+1);
printf("->XoopMessage:%s\n",XoopMessage);
}
if ( strstr ( mycad, "XoopTopic:" ) )
{
strcpy (XoopTopic, strstr ( mycad, ":" ) +1);
printf("->XoopTopic:%s\n",XoopTopic);
}
mycad[0]=0;
}
sprintf( total, "/usr/bin/php4 /usr/share/xoops/post_xoops %s %s %s %s %s", XoopUser, XoopPasswd, XoopTitle,
XoopMessage, XoopTopic, NULL );
printf("Executing %s\n", total);
system ( total );
return 0;
}
-----
Just compile it with gcc parser.c -o parser
Copy it to /bin ( or if your prefer /usr/local/bin and remember to change the path in the aliases file )
and at last... the post_xoops.php file ( it's dirty, dirty dirty... if some hacker from XOOPS could clean it... please!! ). Copy it to /usr/share/xoops/post_xoops
---------------
Quote:
$myargsKikoV=$GLOBALS['argv'];
$HTTP_SERVER_VARS['REQUEST_METHOD'] ='POST';
$HTTP_SERVER_VARS['HTTP_REFERER'] = 'http://your.url.org/modules/news/submit.php';
$nohtml = 1;
include '/path/to/xoops/mainfile.php';
include_once '/path/to/xoops/modules/news/class/class.newsstory.php';
$module_handler =& xoops_gethandler('module');
$xoopsModule =& $module_handler->getByDirname('news');
$nohtml_db = 1;
$xoopsModuleConfig =& $config_handler->getConfigsByCat(0, $xoopsModule->getVar('mid'));
echo "\n";
if (count ($myargsKikoV ) < 5)
{
echo "Usage: php4 ".$myargsKikoV[0]." UserName Password Title Message [Topic]\n";
exit(0);
}
$param_username=$myargsKikoV[1];
$param_password=$myargsKikoV[2];
$param_title=$myargsKikoV[3];
$param_message=$myargsKikoV[4];
if ( count($myargsKikoV) >= 6 )
{
$param_topic=$myargsKikoV[5];
$sql = 'SELECT topic_id FROM '. $xoopsDB->prefix("topics")." WHERE topic_title='".$param_topic."'";
$result = $xoopsDB->query('SELECT topic_id FROM '. $xoopsDB->prefix("topics")." WHERE topic_title='".$param_topic."'");
$topic = array();
$myts =& MyTextSanitizer::getInstance();
while ($myrow = $xoopsDB->fetchArray($result)) {
$topic_id= $myrow['topic_id'];
}
}
$member_handler =& xoops_gethandler('member');
$myts =& MyTextsanitizer::getInstance();
$user =& $member_handler->loginUser(addslashes($myts->stripSlashesGPC($param_username)), addslashes($myts->stripSlashesGPC($param_password)));
if ( ! $user )
{
echo "Login problem\n";
exit(1);
}
$luid=$user->getVar('uid');
$xoopsUser =& $member_handler->getUser($luid);
if ( $xoopsUser ) {
$uid = $xoopsUser->getVar('uid');
if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
$nohtml_db = empty($nohtml) ? 0 : 1;
}
} else {
echo "xoopsModuleConfig:".$xoopsModuleConfig['anonpost'];
if ( $xoopsModuleConfig['anonpost'] == 1 ) {
$uid = 0;
} else {
redirect_header("index.php",3,_NOPERM);
exit();
}
}
$story = new NewsStory();
$story->setTitle($param_title);
$story->setHometext($param_message);
$story->setUid($uid['value']);
$story->setTopicId($topic_id);
$story->setHostname(xoops_getenv('REMOTE_ADDR'));
$story->setNohtml($nohtml_db);
$nosmiley = isset($nosmiley) ? intval($nosmiley) : 0;
$notifypub = isset($notifypub) ? intval($notifypub) : 0;
$story->setNosmiley($nosmiley);
$story->setNotifyPub($notifypub);
$story->setType('user');
if ( $xoopsModuleConfig['autoapprove'] == 1 ) {
$approve = 1;
$story->setApproved($approve);
$story->setPublished(time());
$story->setExpired(0);
$story->setTopicalign('R');
}
$result = $story->store();
?>
How it works?
It's quite simple...
When you send a message to
xoops@your.host.org, it's passed through a filter ( parser.c ) that parse the email seeking the values.
For example:
Quote:
XoopUser:myuser
XoopPasswd:mypasswd
XoopTitle:This.is.my.news.sent.by.email
XoopMessage:Hi!This.is.my.first.NEWS.sent.by.email.
XoopTopic:Xoops
Then, the values are passed as argument to the php file, that call the functions of XOOPS to add a NEWS.
The stream is:
Email (Evolution,KMail,Outlook) -> MailServer -> Parser -> PostXoops -> Xoops
Yes, I know I have to fix the spaces thing... And let the XoopMessage be more than a line. But this is only a first version to know that it's possible... ( I made everything in just two hours.. )
Comments are welcome!
Thx and greeting