Skip to content

Instantly share code, notes, and snippets.

@pjaudiomv
Created February 21, 2021 05:14
Show Gist options
  • Save pjaudiomv/5f8dedb1f2c9c22dc1425052aabd7ea6 to your computer and use it in GitHub Desktop.
Save pjaudiomv/5f8dedb1f2c9c22dc1425052aabd7ea6 to your computer and use it in GitHub Desktop.
Get All Emails from BMLT Server (Requires Authentication)
<?php
$root_server = "https://my.root-server.org/main_server";
$bmlt_login_id = "";
$bmlt_login_password = "";
$login = get("$root_server/local_server/server_admin/json.php?c_comdef_admin_login=$bmlt_login_id&c_comdef_admin_password=$bmlt_login_password&admin_action=login");
$meetings = json_decode(get("$root_server/client_interface/json/?switcher=GetSearchResults&data_field_key=contact_email_1,contact_email_2,email_contact"), true);
$service_bodies = json_decode(get("$root_server/client_interface/json/?switcher=GetServiceBodies"), true);
$service_body_emails = array();
$meeting_emails = array();
foreach ($meetings as $meeting) {
if (isset($meeting["contact_email_1"]) && $meeting["contact_email_1"] != "") {
$contact_email_1 = explode("#@-@#", $meeting["contact_email_1"]);
$meeting_emails[] .= $contact_email_1[2];
}
if (isset($meeting["contact_email_2"]) && $meeting["contact_email_2"] != "") {
$contact_email_2 = explode("#@-@#", $meeting["contact_email_2"]);
$meeting_emails[] .= $contact_email_2[2];
}
if (isset($meeting["email_contact"]) && $meeting["email_contact"] != "") {
$email_contact = explode("#@-@#", $meeting["email_contact"]);
$meeting_emails[] .= $email_contact[2];
}
}
foreach ($service_bodies as $service_body) {
if (isset($service_body["contact_email"]) && $service_body["contact_email"] != "") {
$service_body_emails[] .= $service_body["contact_email"];
}
}
asort($meeting_emails);
asort($service_body_emails);
$meeting_emails = array_unique($meeting_emails);
$service_body_emails = array_unique($service_body_emails);
echo pretty() . "Meeting Emails" . pretty() . "\n";
foreach ($meeting_emails as $m) {
echo $m . "\n";
}
echo pretty() . "Service Body Emails" . pretty() . "\n";
foreach ($service_body_emails as $s) {
echo $s . "\n";
}
echo pretty();
function pretty()
{
return "\n" . str_repeat("-=", 20) . "\n";
}
function get($url)
{
#error_log($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'master_cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'master_cookie.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) +bmltform');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$errorno = curl_errno($ch);
curl_close($ch);
if ($errorno > 0) {
throw new Exception(curl_strerror($errorno));
}
return $data;
}
@pjaudiomv
Copy link
Author

pjaudiomv commented Feb 21, 2021

this would get all user emails from db

$servername = "";
$username = "";
$password = "";
$dbName = "";
try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbName", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); }
$gtu = $conn->prepare('SELECT * FROM `na_comdef_users` WHERE `user_level_tinyint` = 2');
$gtu->execute();
$result = $gtu->fetchAll();
foreach ($result as $users) {
    if (!empty($users['email_address_string'])) {
        if ($users['email_address_string'] != "Enter An Email Address") {
            echo $users['email_address_string'] . "\n";
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment