Facebook
From Botched Giraffe, 5 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 268
  1. <?php
  2. /*
  3. Modulo v1.1
  4. API v2.0
  5. Fleetmailer v84.2
  6. WHMCS v6.x - v7.x
  7. */
  8.  
  9. function whfleet_ConfigOptions() {
  10.         return [
  11.                 "max_sends" => [ // 1
  12.                         "FriendlyName" => "Envios mensuales",
  13.                         "Type" => "text", # Text Box
  14.                         "Size" => "8", # Defines the Field Width
  15.                         "Description" => "0 = ninguno, -1 = ilimitado",
  16.                         "Default" => "0",
  17.                 ],
  18.                 "max_list" => [// 2
  19.                         "FriendlyName" => "Listas",
  20.                         "Type" => "text",
  21.                         "Size" => "8",
  22.                         "Description" => "0 = ilimitado",
  23.                         "Default" => "0",
  24.                 ],
  25.                 "max_susbcribers" => [// 3
  26.                         "FriendlyName" => "Suscriptores",
  27.                         "Type" => "text",
  28.                         "Size" => "8",
  29.                         "Description" => "0 = ilimitado",
  30.                         "Default" => "0",
  31.                 ],
  32.                 "credits" => [// 4
  33.                         "FriendlyName" => "Créditos",
  34.                         "Type" => "text",
  35.                         "Size" => "8",
  36.                         "Description" => "Cantidad de créditos para la carga inicial",
  37.                         "Default" => "0",
  38.                 ],
  39.                 "max_lists_deletions" => [// 5
  40.                         "FriendlyName" => "Eliminado de listas",
  41.                         "Type" => "text",
  42.                         "Size" => "4",
  43.                         "Description" => "Para cuentas de suscriptores. Cuantas listas puede eliminar por período. 0 = ilimitado.",
  44.                         "Default" => "0",
  45.                 ],
  46.                 "allow_api" => [// 6
  47.                         "FriendlyName" => "Permite API",
  48.                         "Type" => "yesno",
  49.                         "Description" => "Permite el uso de API",
  50.                         "Default" => "1",
  51.                 ],
  52.                 "allow_txn" => [// 7
  53.                         "FriendlyName" => "Permite Transaccionales",
  54.                         "Type" => "yesno",
  55.                         "Size" => "8",
  56.                         "Description" => "Permite el uso de emails transaccionales",
  57.                 ],
  58.                 "allow_send" => [// 8
  59.                         "FriendlyName" => "Permite envios",
  60.                         "Type" => "yesno",
  61.                         "Size" => "8",
  62.                         "Description" => "Permite el envío de campañas.",
  63.                 ],
  64.                 "allow_email_templates" => [// 9
  65.                         "FriendlyName" => "Permite plantillas",
  66.                         "Type" => "yesno",
  67.                         "Size" => "8",
  68.                         "Description" => "Permite el uso de plantillas prediseñadas.",
  69.                 ],
  70.                 "trial" => [// 10
  71.                         "FriendlyName" => "Días de prueba",
  72.                         "Type" => "text",
  73.                         "Size" => "4",
  74.                         "Description" => "Pasados los dias la cuenta es eliminada. Cero o blanco para ignorar.",
  75.                         "Default" => "0",
  76.                 ],
  77.                 "is_reseller" => [// 11
  78.                         "FriendlyName" => "Es reseller",
  79.                         "Type" => "yesno",
  80.                         "Description" => "Válido solo para cuentas administrador",
  81.                 ],
  82.                 "fraud_check" => [// 12
  83.                         "FriendlyName" => "Requiere moderacion",
  84.                         "Type" => "yesno",
  85.                         "Description" => "Las campañas podrian ser detenidas si se encuentra alguna palabra sospechosa.",
  86.                 ],
  87.                 "external_id" => [// 13
  88.                         "FriendlyName" => "ID externo",
  89.                         "Type" => "text",
  90.                         "Size" => "10",
  91.                         "Description" => "Puede configurar un identificador unico para cada cuenta.",
  92.                         "Default" => ""
  93.                 ],
  94.                 "verifica_remitente" => [// 14
  95.                         "FriendlyName" => "Valida remitentes",
  96.                         "Type" => "yesno",
  97.                         "Description" => "Debe validar las direcciones de email remitente.",
  98.                         "Default" => "1",
  99.                 ]
  100.         ];
  101. }
  102.  
  103. function whfleet_CreateAccount($params) {
  104.         $post_data = [];
  105.         $post_data['username']=$params['username'];
  106.         $post_data['password']=$params['password'];
  107.         $post_data['name'] = $params['clientsdetails']['firstname'];
  108.         $post_data['lastname'] = $params['clientsdetails']['lastname'];
  109.         $post_data['email'] = $params['clientsdetails']['email'];
  110.         $post_data['max_list'] = $params["configoption2"];
  111.         $post_data['max_sends'] = $params["configoption1"];
  112.         $post_data['credits'] = $params["configoption4"];
  113.         $post_data['max_users'] = 0;
  114.         $post_data["exclude_emlbrand"] = 1;
  115.         $post_data["verifica_remitente"] = 1;
  116.         $post_data['max_susbcribers'] = $params["configoption3"];
  117.         $post_data['allow_delete_lists'] = 1;
  118.         $post_data['max_lists_deletions'] = $params["configoption5"];
  119.         $post_data['allow_email_templates'] = $params["configoption9"];
  120.         $post_data['allow_verifications'] = 1;
  121.         $post_data['allow_txn'] = $params["configoption7"];
  122.         $post_data['allow_api'] = $params["configoption6"];
  123.         $post_data['allow_send'] = $params["configoption8"];
  124.         $post_data['trial'] = $params["configoption10"];
  125.         $post_data['is_reseller'] = $params["configoption11"];
  126.         $post_data['whm_clientid'] = $params["userid"];
  127.         $post_data['fraud_check'] = $params["configoption12"];
  128.         $post_data['external_id'] = $params["configoption13"];
  129.         $post_data['verifica_remitente'] = $params["configoption14"];
  130.  
  131.         if($post_data['is_reseller']) $post_data["max_users"]=1000;
  132.  
  133.         $post_data['company'] = $params['clientsdetails']['companyname'];
  134.         $post_data['address'] = $params["clientsdetails"]["address1"]." ".$params["clientsdetails"]["address1"];
  135.         $post_data['city'] = $params["clientsdetails"]["city"];
  136.         $post_data['region'] = $params["clientsdetails"]["state"];
  137.  
  138.         $module = "/user/create";
  139.  
  140.         return execFleetMailerApi($module, $post_data, $params);
  141. }
  142.  
  143. function whfleet_creditos($params) {
  144.  
  145. }
  146.  
  147. function whfleet_ChangePackage($params) {
  148.         $post_data = [];
  149.         $post_data['username']=$params['username'];
  150.         $post_data['name'] = $params['clientsdetails']['firstname'];
  151.         $post_data['lastname'] = $params['clientsdetails']['lastname'];
  152.         $post_data['email'] = $params[""][""];
  153.         $post_data['max_list'] = $params["configoption2"];
  154.         $post_data['max_sends'] = $params["configoption1"];
  155.         $post_data['credits'] = $params["configoption4"];
  156.         $post_data['max_users'] = 0;
  157.         $post_data["exclude_emlbrand"] = 1;
  158.         $post_data["verifica_remitente"] = 1;
  159.         $post_data['max_susbcribers'] = $params["configoption3"];
  160.         $post_data['allow_delete_lists'] = 1;
  161.         $post_data['max_lists_deletions'] = $params["configoption5"];
  162.         $post_data['allow_email_templates'] = $params["configoption9"];
  163.         $post_data['allow_verifications'] = 1;
  164.         $post_data['allow_txn'] = $params["configoption7"];
  165.         $post_data['allow_api'] = $params["configoption6"];
  166.         $post_data['allow_send'] = $params["configoption8"];
  167.         $post_data['trial'] = $params["configoption10"];
  168.         $post_data['is_reseller'] = $params["configoption11"];
  169.         $post_data['fraud_check'] = $params["configoption12"];
  170.         $post_data['external_id'] = $params["configoption13"];
  171.         $post_data['verifica_remitente'] = $params["configoption14"];
  172.         $post_data['whm_clientid'] = $params["userid"];
  173.  
  174.         if($post_data['is_reseller']) $post_data["max_users"]=1000;
  175.  
  176.         $post_data['company'] = $params['clientsdetails']['companyname'];
  177.         $post_data['address'] = $params["clientsdetails"]["address1"]." ".$params["clientsdetails"]["address1"];
  178.         $post_data['city'] = $params["clientsdetails"]["city"];
  179.         $post_data['region'] = $params["clientsdetails"]["state"];
  180.  
  181.         $module = "/user/edit";
  182.  
  183.         return execFleetMailerApi($module, $post_data, $params);
  184. }
  185.  
  186. function whfleet_TerminateAccount($params) {
  187.         $post_data = [];
  188.         $post_data['username']=$params['username'];
  189.  
  190.         $module = "/user/delete";
  191.  
  192.         return execFleetMailerApi($module, $post_data, $params);
  193. }
  194.  
  195. function whfleet_SuspendAccount($params) {
  196.         $post_data = [];
  197.         $post_data['username']=$params['username'];
  198.         $post_data['status']="suspended";
  199.  
  200.         $module = "/user/changeStatus";
  201.  
  202.         return execFleetMailerApi($module, $post_data, $params);
  203. }
  204.  
  205. function whfleet_UnsuspendAccount($params) {
  206.         $post_data = [];
  207.         $post_data['username']=$params['username'];
  208.         $post_data['status']="active";
  209.  
  210.         $module = "/user/changeStatus";
  211.  
  212.         return execFleetMailerApi($module, $post_data, $params);
  213. }
  214.  
  215. function whfleet_ChangePassword($params) {
  216.         $post_data = [];
  217.         $post_data['username']=$params['username'];
  218.         $post_data['password']=$params['password'];
  219.  
  220.         $module = "/user/password";
  221.  
  222.         return execFleetMailerApi($module, $post_data, $params);
  223. }
  224.  
  225. /**********************************************************************************************/
  226. /**********************************************************************************************/
  227. /**********************************************************************************************/
  228. /**********************************************************************************************/
  229. function whfleet_AdminServicesTabFields($params) {
  230.         $post_data = [];
  231.         $post_data["user_key"] = $params['serveraccesshash'];
  232.         $post_data['username']=$params['username'];
  233.  
  234.         $payload = json_encode($post_data);
  235.         $url = "{$params['serverhttpprefix']}://{$params['serverhostname']}/api/2.0/user/get";
  236.  
  237.         try {
  238.                 $ch = curl_init( $url );
  239.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $payload );
  240.                 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  241.                 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
  242.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
  243.                 $body = curl_exec($ch);
  244.                 curl_close($ch);
  245.         } catch (Exception $e) {
  246.                 return $e;
  247.         }
  248.  
  249.         if($body){
  250.                 $res = json_decode($body, 1);
  251.  
  252.                 file_put_contents("/tmp/_userData_", print_r($res, 1));
  253.  
  254.                 if($res["status"]=="error"){
  255.                         return $res["message"];
  256.                 }
  257.                 if($res["status"]=="success"){
  258.                        
  259.                         $smarty = new Smarty;
  260.                         $smarty->template_dir = realpath(__DIR__."/templates");
  261.                         $smarty->compile_dir = realpath(__DIR__."/../../../templates_c");
  262.                         $smarty->cache_dir = realpath(__DIR__."/../../../templates_c");
  263.  
  264.                         $data['username']=$params['username'];
  265.  
  266.                         $smarty->assign("uData", $res["user_data"]);
  267.                         $smarty->assign("params", $params);
  268.  
  269.                         if(is_array($res["user_data"]["lists_info"])){
  270.                                 $bkl = $invalid = 0;
  271.                                 foreach($res["user_data"]["lists_info"] as $ldata){
  272.                                         $bkl += $ldata["subscribers"]["bkl"];
  273.                                         $invalid += $ldata["subscribers"]["invalid"];
  274.                                 }
  275.                                 $smarty->assign("bkl", $bkl);
  276.                                 $smarty->assign("invalid", $invalid);
  277.                         }
  278.  
  279.                         $output = $smarty->fetch(realpath(__DIR__)."/templates/clientPackage.tpl");
  280.  
  281.                         $fieldsarray = array(
  282.                                 'Informacion de cuenta' => $output
  283.                         );
  284.                        
  285.                         return $fieldsarray;
  286.  
  287.                 }
  288.  
  289.                 return false;
  290.  
  291.         } else {
  292.                 return false;
  293.         }
  294.  
  295. }
  296.  
  297. function whfleet_ClientArea($params) {
  298.         $code = "<a href=\"http://".$params["serverhostname"]."\" target=\"_blank\" style=\"color:#cc0000\">Ingresar</a>";
  299.         return $code;
  300. }
  301.  
  302. function whfleet_AdminLink($params) {
  303.         $code = "<a href=\"http://".$params["serverhostname"]."\" target=\"_blank\" style=\"color:#cc0000\">Ingresar</a>";
  304.         return $code;
  305. }
  306.  
  307.  
  308. function whfleet_LoginLink($params) {
  309.         $code = "<a href=\"http://".$params["serverhostname"]."\" target=\"_blank\" style=\"color:#cc0000\">Ingresar</a>";
  310.         return $code;
  311. }
  312.  
  313. function whfleet_AdminCustomButtonArray() {
  314.                 $buttonarray = array(
  315.  
  316.         );
  317.         return $buttonarray;
  318. }
  319.  
  320. function execFleetMailerApi($module, $post_data, $params) {
  321.         $post_data["user_key"] = $params['serveraccesshash'];
  322.         $payload = json_encode($post_data);
  323.         $url = "{$params['serverhttpprefix']}://{$params['serverhostname']}/api/2.0{$module}";
  324.  
  325.         try {
  326.                 $ch = curl_init( $url );
  327.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $payload );
  328.                 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  329.                 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
  330.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
  331.                 $body = curl_exec($ch);
  332.                 curl_close($ch);
  333.         } catch (Exception $e) {
  334.                 return $e;
  335.         }
  336.  
  337.         if($body){
  338.                 $res = json_decode($body, 1);
  339.  
  340.                 if($res["status"]=="error"){
  341.                         return $res["message"];
  342.                 }
  343.                 if($res["status"]=="success"){
  344.                         return "success";
  345.                 }
  346.  
  347.                 return "La respuesta del servidor no es válida.";
  348.  
  349.         } else {
  350.                 return "No se ha podido acceder al servidor.";
  351.         }
  352.  
  353.  
  354. }
  355.  
  356.  
  357. ?>