diff --git a/roundcube/class/m_roundcube.php b/roundcube/class/m_roundcube.php index 97b09e58..53b86b50 100644 --- a/roundcube/class/m_roundcube.php +++ b/roundcube/class/m_roundcube.php @@ -40,16 +40,21 @@ class m_roundcube { // Search for the domain where the panel is hosted, then search for a webmail in it. $i=2; $domain=""; - do { // for each domain part (search panel.alternc.org then alternc.org then org, if the current panel is at www.panel.alternc.org) - list($host,$dompart)=explode(".",$_SERVER["HTTP_HOST"],$i); - // We search for a 'roundcube' subdomain in that domain - $db->query("SELECT * FROM sub_domaines s WHERE s.domaine='".addslashes($dompart)."' AND s.type='roundcube';"); - if ($db->next_record()) { - $domain=$db->Record; - return "http://".$domain["sub"].(($domain["sub"])?".":"").$domain["domaine"]; - } - $i++; - } while (strpos($dompart,'.')!==false); + if (!empty($_SERVER["HTTP_HOST"])) { + do { // for each domain part (search panel.alternc.org then alternc.org then org, if the current panel is at www.panel.alternc.org) + $expl=explode(".",$_SERVER["HTTP_HOST"],$i); + if (count($expl)>=2) { + list($host,$dompart)=$expl; + // We search for a 'squirrelmail' subdomain in that domain + $db->query("SELECT * FROM sub_domaines s WHERE s.domaine='".addslashes($dompart)."' AND s.type='roundcube';"); + if ($db->next_record()) { + $domain=$db->Record; + return "http://".$domain["sub"].(($domain["sub"])?".":"").$domain["domaine"]; + } + } + $i++; + } while (strpos($dompart,'.')!==false); + } // not found: search for a webmail in the admin user account $db->query("SELECT * FROM sub_domaines s WHERE s.compte=2000 AND s.type='roundcube';"); diff --git a/squirrelmail/class/m_squirrelmail.php b/squirrelmail/class/m_squirrelmail.php index 82add3db..7897af22 100644 --- a/squirrelmail/class/m_squirrelmail.php +++ b/squirrelmail/class/m_squirrelmail.php @@ -40,17 +40,22 @@ class m_squirrelmail { // Search for the domain where the panel is hosted, then search for a webmail in it. $i=2; $domain=""; - do { // for each domain part (search panel.alternc.org then alternc.org then org, if the current panel is at www.panel.alternc.org) - list($host,$dompart)=explode(".",$_SERVER["HTTP_HOST"],$i); - // We search for a 'squirrelmail' subdomain in that domain - $db->query("SELECT * FROM sub_domaines s WHERE s.domaine='".addslashes($dompart)."' AND s.type='squirrelmail';"); - if ($db->next_record()) { - $domain=$db->Record; - return "http://".$domain["sub"].(($domain["sub"])?".":"").$domain["domaine"]; - } - $i++; - } while (strpos($dompart,'.')!==false); - + if (!empty($_SERVER["HTTP_HOST"])) { + do { // for each domain part (search panel.alternc.org then alternc.org then org, if the current panel is at www.panel.alternc.org) + $expl=explode(".",$_SERVER["HTTP_HOST"],$i); + if (count($expl)>=2) { + list($host,$dompart)=$expl; + // We search for a 'squirrelmail' subdomain in that domain + $db->query("SELECT * FROM sub_domaines s WHERE s.domaine='".addslashes($dompart)."' AND s.type='squirrelmail';"); + if ($db->next_record()) { + $domain=$db->Record; + return "http://".$domain["sub"].(($domain["sub"])?".":"").$domain["domaine"]; + } + } + $i++; + } while (strpos($dompart,'.')!==false); + } + // not found: search for a webmail in the admin user account $db->query("SELECT * FROM sub_domaines s WHERE s.compte=2000 AND s.type='squirrelmail';"); if ($db->next_record()) {