Ir para conteúdo
  • Cadastre-se

Suspender Acesso Ao Google Apps


Posts Recomendados

<p>Uma hook pra trabalhar isso a partir de um custom-field ou produto mesmo pra identificar quem tem o gapps, e fazer de maneira autom&aacute;tica seria interessante.</p>

<p>&nbsp;</p>

<p>O frank tinha um m&oacute;dulo que trocava os mx de gapps para local direto da &aacute;rea do cliente. Talvez seja &uacute;til pra adaptar neste caso. Algu&eacute;m se habilita?</p>

<p>&nbsp;</p>

<p><a data-ipb="nomediaparse" href="https://code.google.com/p/franksworld/downloads/detail?name=googleapps-2.0.zip&amp;can=2&amp;q">https://code.google.com/p/franksworld/downloads/detail?name=googleapps-2.0.zip&amp;can=2&amp;q</a></p>

<p>&nbsp;</p>

<p>Hooks Products que seriam utilizadas:</p>

<p><span style="font-family:inherit;font-style:inherit;font-weight:inherit;margin:0px;"><strong>AfterModuleSuspend</strong>&nbsp;</span></p>

<p><span style="font-family:inherit;font-style:inherit;font-weight:inherit;margin:0px;"><strong>PreModuleUnsuspend</strong>&nbsp;</span></p>

<pre class="_prettyXprint">

function googleapps_show($vars) {

global $smarty;

$lang_arr = $smarty-&gt;get_template_vars('LANG');

$module = $vars['modulename'];

$cpuser = $vars['username'];

$srv_host = $vars['serverip'];

$srv_user = $vars['serverusername'];

$srv_pass = $vars['serverpassword'];

$srv_hash = $vars['serveraccesshash'];

$srv_secure = $vars['serversecure'];

$status = $vars['rawstatus'];

if (($module != 'cpanel') || ($status != 'active')) {

$isvalid = 0;

} else {

$isvalid = 1;

}

if ($isvalid) {

// Setup API connection

$xmlapi = new xmlapi($srv_host);

if ($srv_secure) {

$srv_port = 2087;

} else {

$srv_port = 2086;

}

if (!$srv_hash) {

$xmlapi-&gt;password_auth($srv_user, $srv_pass);

} else {

$xmlapi-&gt;hash_auth($srv_user, preg_replace(&quot;'(\r|\n)'&quot;,&quot;&quot;, $srv_hash));

}

$xmlapi-&gt;set_port($srv_port);

$accounts = array();

$accounts[] = $cpuser;

$domains = ga_getUserDomains($xmlapi, $cpuser);

// Check if reseller

$reseller = $xmlapi-&gt;resellerstats($cpuser);

if (isset($reseller-&gt;result-&gt;accts)) {

// This is a reseller

foreach ($reseller-&gt;result-&gt;accts as $key =&gt; $val) {

if ($val-&gt;user != $cpuser) {

$accounts[] = (string)$val-&gt;user;

}

}

}

// handle event to populate domain select

if (isset($_REQUEST['domlookup'])) {

$curcpuser = $_REQUEST['user'];

$res = ga_getUserDomains($xmlapi, $curcpuser);

print json_encode($res);

exit(1);

}

// handle event to change mode between local and google

if (isset($_REQUEST['googleit'])) {

$errorcount = 0;

$config = $_REQUEST['config'];

$cur_cpuser = $_REQUEST['user'];

$cur_domain = $_REQUEST['domain'];

$cur_domain_dot = $cur_domain.&quot;.&quot;;

$doms_for_user = ga_getUserDomains($xmlapi, $cur_cpuser);

// check if user actually owns domain, and user

if ((in_array($cur_domain, $doms_for_user)) &amp;&amp; (in_array($cur_cpuser, $accounts))) {

$rmRec = array();

$zdata = $xmlapi-&gt;dumpzone($cur_domain);

// step through zone records and find MX, google CNAMEs, mail. CNAME, and SPF record

foreach($zdata-&gt;result-&gt;record as $key =&gt; $val) {

if ($val-&gt;type == 'MX') {

$rmRec[] = array(

'line' =&gt; (string)$val-&gt;Line,

'name' =&gt; (string)$val-&gt;exchange);

} elseif (($val-&gt;type == 'CNAME') &amp;&amp; (($val-&gt;name == 'mail.'.$cur_domain_dot) ||

($val-&gt;name == 'calendar.'.$cur_domain_dot) ||

($val-&gt;name == 'start.'.$cur_domain_dot) ||

($val-&gt;name == 'sites.'.$cur_domain_dot) ||

($val-&gt;name == 'docs.'.$cur_domain_dot))) {

$rmRec[] = array(

'line' =&gt; (string)$val-&gt;Line,

'name' =&gt; (string)$val-&gt;name);

} elseif (($val-&gt;type == 'TXT') &amp;&amp; (preg_match('/v=spf/', (string)$val-&gt;txtdata))) {

$rmRec[] = array(

'line' =&gt; (string)$val-&gt;Line,

'name' =&gt; (string)$val-&gt;name);

}

}

// we must reverse sort them so the line numbers do not when they are removed

rsort($rmRec);

$gmail_smtp = array(

'aspmx.l.google.com' =&gt; '0', 'alt1.aspmx.l.google.com' =&gt; '10',

'alt2.aspmx.l.google.com' =&gt; '10', 'aspmx2.googlemail.com' =&gt; '20',

'aspmx3.googlemail.com' =&gt; '20', 'aspmx4.googlemail.com' =&gt; '20',

'aspmx5.googlemail.com' =&gt; '20');

$ghshost = &quot;ghs.google.com&quot;;

$cnlist = array(&quot;calendar&quot;, &quot;start&quot;, &quot;sites&quot;, &quot;docs&quot;);

// delete lines in zone file found in previous statements

foreach ($rmRec as $del) {

$rmline = $del['line'];

$rmname = $del['name'];

$rmdata = $xmlapi-&gt;removezonerecord($cur_domain, $rmline);

if ($rmdata-&gt;result-&gt;status == 0) {

$errorcount++;

$error .= &quot;Removal of $rmname failed. -- &quot;.$rmdata-&gt;result-&gt;statusmsg.&quot;&lt;br /&gt;&quot;;

}

}

$mxname = &quot;mail.$cur_domain.&quot;;

if ($config == 'google') {

$cname = $ghshost;

} else {

$cname = $cur_domain;

}

$cnameArr = array('name'=&gt;$mxname, 'type'=&gt;'CNAME', 'cname'=&gt;$cname);

// Add main &quot;mail.&quot; CNAME record back as google or local

$cnamedata = $xmlapi-&gt;addzonerecord($cur_domain, $cnameArr);

if ($cnamedata-&gt;result-&gt;status == 0) {

$errorcount++;

$error .= &quot;Failed to add $mxname. -- &quot;.$cnamedata-&gt;result-&gt;statusmsg.&quot;&lt;br /&gt;&quot;;

}

if ($config == 'google') {

// Add google specific CNAME's

foreach ($cnlist as $cur_cname) {

$cn = $cur_cname.'.'.$cur_domain.'.';

$addArr = array('name' =&gt; $cn, 'type'=&gt;'CNAME', 'cname'=&gt;$ghshost);

$adddata = $xmlapi-&gt;addzonerecord($cur_domain, $addArr);

if ($adddata-&gt;result-&gt;status == 0) {

$errorcount++;

$error .= &quot;Failed to add $cn -- &quot;.$adddata-&gt;result-&gt;statusmsg.&quot;&lt;br /&gt;&quot;;

}

}

// Add google SPF

$txtdata = '&quot;v=spf1 include:'.$cur_domain.' include:_spf.google.com ~all&quot;';

$spfArr = array('name'=&gt;$cur_domain_dot, 'type'=&gt;'TXT', 'txtdata'=&gt;$txtdata);

$spfdata = $xmlapi-&gt;addzonerecord($cur_domain, $spfArr);

if ($spfdata-&gt;result-&gt;status == 0) {

$errorcount++;

$error .= &quot;Failed to add SPF record -- &quot;.$spfdata-&gt;result-&gt;statusmsg.&quot;&lt;br /&gt;&quot;;

}

}

if ($config == 'google') {

$mx = $gmail_smtp;

} else {

$mx = array($cur_domain =&gt; 0);

}

// Add MX records

foreach ($mx as $key =&gt; $val) {

$exchange = $key;

$pref = $val;

$addArr = array('name'=&gt;$cur_domain_dot, 'type'=&gt;'MX', 'exchange'=&gt;$exchange, 'preference'=&gt;$pref);

$adddata = $xmlapi-&gt;addzonerecord($cur_domain, $addArr);

if ($adddata-&gt;result-&gt;status == 0) {

$errorcount++;

$error .= &quot;Failed to add $exchange MX record -- &quot;.$adddata-&gt;result-&gt;statusmsg.&quot;&lt;br /&gt;&quot;;

}

}

if ($config == 'google') {

$mxcheck = 'remote';

} else {

$mxcheck = 'local';

}

// Set mxcheck to local or remote

$sdataArr = array('domain'=&gt;$cur_domain, 'mxcheck'=&gt;$mxcheck);

$sdata = $xmlapi-&gt;api2_query($cpuser, 'Email', 'setalwaysaccept', $sdataArr);

if ($sdata-&gt;data-&gt;status == 0) {

$errorcount++;

$error .= &quot;Could not set MX accept status to $mxcheck -- &quot;.$sdata-&gt;data-&gt;statusmsg.&quot;&lt;br /&gt;&quot;;

}

if (!$errorcount) {

$fullmsg = $lang_arr['googleapps_noerror'].'&lt;br /&gt;';

} else {

$fullmsg = $lang_arr['googleapps_error'].'&lt;br /&gt;';

}

} else {

$fullmsg = $lang_arr['googleapps_error'].'&lt;br /&gt;';

$error .= $lang_arr['googleapps_notowned'].'&lt;br /&gt;';

}

$resultsArr = array(

'msg' =&gt; $fullmsg,

'error' =&gt; $error);

print json_encode($resultsArr);

exit(1);

}

}

$smarty-&gt;assign('googleapps_isvalid', $isvalid);

$smarty-&gt;assign('googleapps_domains', $domains);

$smarty-&gt;assign('googleapps_users', $accounts);

}

</pre>

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
  • Quem Está Navegando   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.
×
×
  • Criar Novo...

Informação Importante

Concorda com os nossos termos?