Sponsor:

Server and Web Integrator
Link:
Kloxo-MR logo
6.5.0 or 7.0.0
Click for "How to install"
Donation/Sponsorship:
Kloxo-MR is open-source.
Donate and or Sponsorship always welcome.
Click to:
Click Here
Please login or register. 2024-04-27, 12:05:44

Author Topic: fix-qmail-assign.php makes wrong /var/qmail/users/assign value (contains fix)  (Read 3409 times)

0 Members and 1 Guest are viewing this topic.

Offline luckytanuki

  • Junior Member
  • *
  • Posts: 35
  • Karma: +0/-0
    • View Profile
    • Kloxo Next Generation
Hi Mustafa,

I have a fix for a bug in fix-qmail-assign.php .

Yesterday I upgraded  to 7.0.0.b-2016021403 and  had a problem where mail users from one domain where made in the root folder. All other users were ok.

The problem was a incorrect folder setting in /var/qmail/users/assign

The correct path value should be
/home/lxadmin/mail/domains/firstnamesurname.com

But /var/qmail/users/assign had the value
/home/lxadmin/mail/domainssurname.com.au

It was cause by a line in fix-qmail-assign.php

The error occurs when the email name was in the domain name

eg

where $row['pw_name'] = 'firstname'

and

 $row['pw_dir'] = '/home/lxadmin/mail/domains/firstnamesurname.com/firstname'

$n[$row['pw_domain']] = str_replace("/" . $row['pw_name'], '', $row['pw_dir']);

calculates

/home/lxadmin/mail/domainssurname.com.au

as it removes all occurrences of firstname from the path

The fix is to make the string replace only work on the end of $row['pw_dir']

$n[$row['pw_domain']] = preg_replace('/\/' . $row['pw_name'].'$/', '', $row['pw_dir']);

cheers

John

Offline MRatWork

  • Administrator
  • The Elite
  • *****
  • Posts: 15,807
  • Karma: +119/-11
  • Gender: Male
    • View Profile
    • MRatWork Forum
I didn't this issue.

Try update Kloxo-MR 7.0 with 'yum clean all; yum update -y; sh /script/cleanup'. I found trouble with 'cgi mode' for php for KLoxo-MR. So, update will be make sure to use 'fpm mode'.
..:: MRatWork (Mustafa Ramadhan Projects) ::..
-- Server/Web-integrator - Web Hosting (Kloxo-MR READY!) --

Offline luckytanuki

  • Junior Member
  • *
  • Posts: 35
  • Karma: +0/-0
    • View Profile
    • Kloxo Next Generation
Done all that. Problem is still str_replace as it does a global match

This is hard to reproduce as depends on the order of records in the vpopmail table.

For the bug to appear two conditions must be meet.

1. The email name occurs in the domain name eg fred@frednerk.com
2. The email address it the last record for that domain in the vpopmail table

Here is a small proof of concept:
Code: [Select]
<?php
$name
="firstname";
$path="/home/lxadmin/mail/domains/firstnamesurname.com/firstname";

echo 
"source path: ".$path."\n"

//Calculate path with str_replace 
$newpath=str_replace("/" $name''$path);
echo 
"str_replace method: ".$newpath."\n";

//Calculate path with str_replace
$newpath2=preg_replace('/\/' $name.'$/'''$path);
echo 
"preg_replace method: ".$newpath2."\n";
?>

output:
source path: /home/lxadmin/mail/domains/firstnamesurname.com/firstname
str_replace method: /home/lxadmin/mail/domainssurname.com
preg_replace method: /home/lxadmin/mail/domains/firstnamesurname.com

Offline MRatWork

  • Administrator
  • The Elite
  • *****
  • Posts: 15,807
  • Karma: +119/-11
  • Gender: Male
    • View Profile
    • MRatWork Forum
Try change /usr/local/lxlabs/kloxo/bin/fix/fix-qmail-assign.php to:
Code: [Select]
<?php

// by mustafa@bigraf.com for Kloxo-MR

include_once "lib/html/include.php";

resetQmailAssign();

function 
resetQmailAssign($nolog null)
{
$mpath "/home/lxadmin/mail/domains";

$pass slave_get_db_pass();

$con = new mysqli("localhost""root"$pass);

if (!$con) {
die('Could not connect: ' $con->connect_error);
}

$con->select_db("vpopmail");

$result $con->query("SELECT pw_name, pw_domain, pw_dir FROM vpopmail");

if (!isset($result)) { return; }

$n = array();

while ($row $result->fetch_array(MYSQLI_ASSOC)) {
// MR -- need this team to fix issue where prefix account as the same as prefix domain
//       like your@yourdomain.com (the same 'your')
$temp str_replace($mpath "/"''$row['pw_dir']);
$n[$row['pw_domain']] = $mpath "/" str_replace("/" $row['pw_name'], ''$temp);
}

$ua '';
$rh '';
$vd '';

log_cleanup("Reset Qmail Assign for domains (also rcpthosts and virtualdomains)"$nolog);

$bpath "/var/qmail/bin";
$cpath "/var/qmail/control";
$upath "/var/qmail/users";

exec("'rm' -f {$upath}/assign {$cpath}/rcpthosts {$cpath}/morercpthosts* {$cpath}/virtualdomains");

foreach ($n as $k => $v) {
log_cleanup("- assign for '{$k}'"$nolog);

$o fileowner($v);
$ua .= "+{$k}-:{$k}:{$o}:{$o}:{$v}:-::\n";

if (isRpmInstalled('qmail-toaster')) {
// MR -- also fix /home/lxadmin/mail/bin to /home/vpopmail/bin
$d $v "/.qmail-default";
$x file_get_contents($d);
$x str_replace("/home/lxadmin/mail/bin""/home/vpopmail/bin"$x);
}

file_put_contents($d$x);

log_cleanup("- rcpthosts/morercpthosts for '{$k}'"$nolog);
$rh .= "{$k}\n";
}

$ua .= ".";

$con->select_db("kloxo");

$result2 $con->query("SELECT nname FROM mmail WHERE remotelocalflag = 'remote'");

$n2 = array();

while ($row2 $result2->fetch_array(MYSQLI_ASSOC)) {
$n2[$row2['nname']] = '1';
}

foreach ($n as $k => $v) {
foreach ($n2 as $k2 => $v2) {
if ($k === $k2) {
unset($n[$k]);
}
}
}

foreach ($n as $k => $v) {
log_cleanup("- virtualdomains for '{$k}'"$nolog);
$vd .= "{$k}:{$k}\n";
}

exec("echo '{$ua}' > {$upath}/assign");
// MR -- moving list to morercpthosts
// exec("echo '{$rh}' > {$cpath}/rcpthosts");
exec("echo '' > {$cpath}/rcpthosts");
exec("echo '{$rh}' > {$cpath}/morercpthosts; {$bpath}/qmail-newmrh");
exec("echo '{$vd}' > {$cpath}/virtualdomains; {$bpath}/qmail-newu");

$con->close();
}
..:: MRatWork (Mustafa Ramadhan Projects) ::..
-- Server/Web-integrator - Web Hosting (Kloxo-MR READY!) --

Offline luckytanuki

  • Junior Member
  • *
  • Posts: 35
  • Karma: +0/-0
    • View Profile
    • Kloxo Next Generation
Thanks, that looks like it would fix it. Will let you know when I've had a chance to test it,

J

Offline MRatWork

  • Administrator
  • The Elite
  • *****
  • Posts: 15,807
  • Karma: +119/-11
  • Gender: Male
    • View Profile
    • MRatWork Forum
Update your Kloxo-MR 7.0.
..:: MRatWork (Mustafa Ramadhan Projects) ::..
-- Server/Web-integrator - Web Hosting (Kloxo-MR READY!) --

 


Top 10 Social Networking:    Facebook    Twitter    LinkedIn    Pinterest    Google Plus    Tumblr    Instagram    VK    Flickr    Vine

Page created in 0.038 seconds with 18 queries.

web stats analysis