Ejemplo n.º 1
0
/** Send a summary email */
function sendsummaryemail($projectid, $groupid, $errors, $buildid)
{
    include 'config/config.php';
    require_once 'models/userproject.php';
    require_once 'models/user.php';
    require_once 'models/project.php';
    require_once 'models/build.php';
    require_once 'models/site.php';
    $Project = new Project();
    $Project->Id = $projectid;
    $Project->Fill();
    // Check if the email has been sent
    $date = '';
    // now
    list($previousdate, $currentstarttime, $nextdate, $today) = get_dates($date, $Project->NightlyTime);
    $dashboarddate = gmdate(FMT_DATE, $currentstarttime);
    // If we already have it we return
    if (pdo_num_rows(pdo_query("SELECT buildid FROM summaryemail WHERE date='{$dashboarddate}' AND groupid=" . qnum($groupid))) == 1) {
        return;
    }
    // Update the summaryemail table to specify that we have send the email
    // We also delete any previous rows from that groupid
    pdo_query("DELETE FROM summaryemail WHERE groupid={$groupid}");
    pdo_query("INSERT INTO summaryemail (buildid,date,groupid) VALUES ({$buildid},'{$dashboarddate}',{$groupid})");
    add_last_sql_error('sendmail');
    // If the trigger for SVN/CVS diff is not done yet we specify that the asynchronous trigger should
    // send an email
    $dailyupdatequery = pdo_query('SELECT status FROM dailyupdate WHERE projectid=' . qnum($projectid) . " AND date='{$dashboarddate}'");
    add_last_sql_error('sendmail');
    if (pdo_num_rows($dailyupdatequery) == 0) {
        return;
    }
    $dailyupdate_array = pdo_fetch_array($dailyupdatequery);
    $dailyupdate_status = $dailyupdate_array['status'];
    if ($dailyupdate_status == 0) {
        pdo_query("UPDATE dailyupdate SET status='2' WHERE projectid=" . qnum($projectid) . " AND date='{$dashboarddate}'");
        return;
    }
    // Find the current updaters from the night using the dailyupdatefile table
    $summaryEmail = '';
    $query = 'SELECT ' . qid('user') . '.email,up.emailcategory,' . qid('user') . '.id
                          FROM ' . qid('user') . ',user2project AS up,user2repository AS ur,
                           dailyupdate,dailyupdatefile WHERE
                           up.projectid=' . qnum($projectid) . '
                           AND up.userid=' . qid('user') . '.id
                           AND ur.userid=up.userid
                           AND (ur.projectid=0 OR ur.projectid=' . qnum($projectid) . ")\n                           AND ur.credential=dailyupdatefile.author\n                           AND dailyupdatefile.dailyupdateid=dailyupdate.id\n                           AND dailyupdate.date='{$dashboarddate}'\n                           AND dailyupdate.projectid=" . qnum($projectid) . '
                           AND up.emailtype>0
                           ';
    $user = pdo_query($query);
    add_last_sql_error('sendmail');
    // Loop through the users and add them to the email array
    while ($user_array = pdo_fetch_array($user)) {
        // If the user is already in the list we quit
        if (strpos($summaryEmail, $user_array['email']) !== false) {
            continue;
        }
        // If the user doesn't want to receive email
        if (!checkEmailPreferences($user_array['emailcategory'], $errors)) {
            continue;
        }
        // Check if the labels are defined for this user
        if (!checkEmailLabel($projectid, $user_array['id'], $buildid, $user_array['emailcategory'])) {
            continue;
        }
        if ($summaryEmail != '') {
            $summaryEmail .= ', ';
        }
        $summaryEmail .= $user_array['email'];
    }
    // Select the users that are part of this build
    $authors = pdo_query('SELECT author FROM updatefile AS uf,build2update AS b2u
                        WHERE b2u.updateid=uf.updateid AND b2u.buildid=' . qnum($buildid));
    add_last_sql_error('sendmail');
    while ($authors_array = pdo_fetch_array($authors)) {
        $author = $authors_array['author'];
        if ($author == 'Local User') {
            continue;
        }
        $UserProject = new UserProject();
        $UserProject->RepositoryCredential = $author;
        $UserProject->ProjectId = $projectid;
        if (!$UserProject->FillFromRepositoryCredential()) {
            continue;
        }
        // If the user doesn't want to receive email
        if (!checkEmailPreferences($UserProject->EmailCategory, $errors)) {
            continue;
        }
        // Check if the labels are defined for this user
        if (!checkEmailLabel($projectid, $UserProject->UserId, $buildid, $UserProject->EmailCategory)) {
            continue;
        }
        // Find the email
        $User = new User();
        $User->Id = $UserProject->UserId;
        $useremail = $User->GetEmail();
        // If the user is already in the list we quit
        if (strpos($summaryEmail, $useremail) !== false) {
            continue;
        }
        if ($summaryEmail != '') {
            $summaryEmail .= ', ';
        }
        $summaryEmail .= $useremail;
    }
    // In the case of asynchronous submission, the serverURI contains /cdash
    // we need to remove it
    $currentURI = get_server_URI();
    if ($CDASH_BASE_URL == '' && $CDASH_ASYNCHRONOUS_SUBMISSION) {
        $currentURI = substr($currentURI, 0, strrpos($currentURI, '/'));
    }
    // Select the users who want to receive all emails
    $user = pdo_query('SELECT ' . qid('user') . '.email,user2project.emailtype,' . qid('user') . '.id  FROM ' . qid('user') . ',user2project
                     WHERE user2project.projectid=' . qnum($projectid) . '
                     AND user2project.userid=' . qid('user') . '.id AND user2project.emailtype>1');
    add_last_sql_error('sendsummaryemail');
    while ($user_array = pdo_fetch_array($user)) {
        // If the user is already in the list we quit
        if (strpos($summaryEmail, $user_array['email']) !== false) {
            continue;
        }
        // Check if the labels are defined for this user
        if (!checkEmailLabel($projectid, $user_array['id'], $buildid)) {
            continue;
        }
        if ($summaryEmail != '') {
            $summaryEmail .= ', ';
        }
        $summaryEmail .= $user_array['email'];
    }
    // Send the email
    if ($summaryEmail != '') {
        $Build = new Build();
        $Build->FillFromId($buildid);
        $Site = new Site();
        $Site->Id = $Build->SiteId;
        $summaryemail_array = pdo_fetch_array(pdo_query("SELECT name FROM buildgroup WHERE id={$groupid}"));
        add_last_sql_error('sendsummaryemail');
        $title = 'CDash [' . $Project->Name . '] - ' . $summaryemail_array['name'] . ' Failures';
        $messagePlainText = 'The "' . $summaryemail_array['name'] . "\" group has either errors, warnings or test failures.\n";
        $messagePlainText .= 'You have been identified as one of the authors who have checked in changes that are part of this submission ';
        $messagePlainText .= "or you are listed in the default contact list.\n\n";
        $messagePlainText .= 'Site name: ' . $Site->GetName() . "\n";
        $messagePlainText .= 'Build name: ' . $Build->Name . ' (' . $Build->Type . ")\n";
        $messagePlainText .= "To see this dashboard:\n";
        $messagePlainText .= $currentURI;
        $messagePlainText .= '/index.php?project=' . urlencode($Project->Name) . '&date=' . $today;
        $messagePlainText .= "\n\n";
        $messagePlainText .= "Summary of the first build failure:\n";
        // Check if an email has been sent already for this user
        foreach ($errors as $errorkey => $nerrors) {
            $messagePlainText .= get_email_summary($buildid, $errors, $errorkey, $Project->EmailMaxItems, $Project->EmailMaxChars, $Project->TestTimeMaxStatus, $Project->EmailTestTimingChanged);
        }
        $messagePlainText .= "\n\n";
        $serverName = $CDASH_SERVER_NAME;
        if (strlen($serverName) == 0) {
            $serverName = $_SERVER['SERVER_NAME'];
        }
        $messagePlainText .= "\n-CDash on " . $serverName . "\n";
        // If this is the testing
        if ($CDASH_TESTING_MODE) {
            add_log($summaryEmail, 'TESTING: EMAIL', LOG_DEBUG);
            add_log($title, 'TESTING: EMAILTITLE', LOG_DEBUG);
            add_log($messagePlainText, 'TESTING: EMAILBODY', LOG_DEBUG);
        } else {
            // Send the email
            if (cdashmail("{$summaryEmail}", $title, $messagePlainText)) {
                add_log('summary email sent to: ' . $summaryEmail, 'sendemail ' . $Project->Name, LOG_INFO);
                return;
            } else {
                add_log('cannot send summary email to: ' . $summaryEmail, 'sendemail ' . $Project->Name, LOG_ERR);
            }
        }
    }
}
Ejemplo n.º 2
0
/** Send an email to administrator of the project for users who are not registered */
function sendEmailUnregisteredUsers($projectid, $cvsauthors)
{
    include "cdash/config.php";
    require_once "models/userproject.php";
    include_once "cdash/common.php";
    $unregisteredusers = array();
    foreach ($cvsauthors as $author) {
        if ($author == "Local User") {
            continue;
        }
        $UserProject = new UserProject();
        $UserProject->RepositoryCredential = $author;
        $UserProject->ProjectId = $projectid;
        if (!$UserProject->FillFromRepositoryCredential()) {
            $unregisteredusers[] = $author;
        }
    }
    // Send the email if any
    if (count($unregisteredusers) > 0) {
        // Find the project administrators
        $email = "";
        $emails = pdo_query("SELECT email FROM " . qid("user") . ",user2project WHERE " . qid("user") . ".id=user2project.userid\n                         AND user2project.projectid=" . qnum($projectid) . " AND user2project.role='2'");
        while ($emails_array = pdo_fetch_array($emails)) {
            if ($email != "") {
                $email .= ", ";
            }
            $email .= $emails_array["email"];
        }
        // Send the email
        if ($email != "") {
            $projectname = get_project_name($projectid);
            $serverName = $CDASH_SERVER_NAME;
            if (strlen($serverName) == 0) {
                $serverName = $_SERVER['SERVER_NAME'];
            }
            $title = "CDash [" . $projectname . "] - Unregistered users";
            $body = "The following users are checking in code but are not registered for the project " . $projectname . ":\n";
            foreach ($unregisteredusers as $unreg) {
                $body .= "* " . $unreg . "\n";
            }
            $body .= "\n You should register these users to your project. They are currently not receiving any emails from CDash.\n";
            $body .= "\n-CDash on " . $serverName . "\n";
            add_log($title . " : " . $body . " : " . $email, "sendEmailUnregisteredUsers");
            if (cdashmail("{$email}", $title, $body, "From: CDash <" . $CDASH_EMAIL_FROM . ">\nReply-To: " . $CDASH_EMAIL_REPLY . "\nContent-type: text/plain; charset=utf-8\nX-Mailer: PHP/" . phpversion() . "\nMIME-Version: 1.0")) {
                add_log("email sent to: " . $email, "sendEmailUnregisteredUsers");
                return;
            } else {
                add_log("cannot send email to: " . $email, "sendEmailUnregisteredUsers");
            }
        }
    }
    // end count()
}
Ejemplo n.º 3
0
 function register_user($projectid, $email, $firstName, $lastName, $repositoryCredential)
 {
     include dirname(__DIR__) . '/config/config.php';
     $UserProject = new UserProject();
     $UserProject->ProjectId = $projectid;
     // Check if the user is already registered
     $user = pdo_query('SELECT id FROM ' . qid('user') . " WHERE email='{$email}'");
     if (pdo_num_rows($user) > 0) {
         // Check if the user has been registered to the project
         $user_array2 = pdo_fetch_array($user);
         $userid = $user_array2['id'];
         $user = pdo_query("SELECT userid FROM user2project WHERE userid='{$userid}' AND projectid='{$projectid}'");
         if (pdo_num_rows($user) == 0) {
             // not registered
             // We register the user to the project
             pdo_query("INSERT INTO user2project (userid,projectid,role,emailtype)\n                                  VALUES ('{$userid}','{$projectid}','0','1')");
             // We add the credentials if not already added
             $UserProject->UserId = $userid;
             $UserProject->AddCredential($repositoryCredential);
             $UserProject->ProjectId = 0;
             $UserProject->AddCredential($email);
             // Add the email by default
             echo pdo_error();
             return false;
         }
         return '<error>User ' . $email . ' already registered.</error>';
     }
     // already registered
     // Check if the repositoryCredential exists for this project
     $UserProject->RepositoryCredential = $repositoryCredential;
     if ($UserProject->FillFromRepositoryCredential() === true) {
         return '<error>' . $repositoryCredential . ' was already registered for this project under a different email address</error>';
     }
     // Register the user
     // Create a new password
     $keychars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
     $length = 10;
     $pass = '';
     $max = strlen($keychars) - 1;
     for ($i = 0; $i <= $length; $i++) {
         // random_int is available in PHP 7 and the random_compat PHP 5.x
         // polyfill included in the Composer package.json dependencies.
         $pass .= substr($keychars, random_int(0, $max), 1);
     }
     $encrypted = md5($pass);
     pdo_query('INSERT INTO ' . qid('user') . " (email,password,firstname,lastname,institution,admin)\n                 VALUES ('{$email}','{$encrypted}','{$firstName}','{$lastName}','','0')");
     add_last_sql_error('register_user');
     $userid = pdo_insert_id('user');
     // Insert the user into the project
     pdo_query("INSERT INTO user2project (userid,projectid,role,emailtype)\n                                VALUES ('{$userid}','{$projectid}','0','1')");
     add_last_sql_error('register_user');
     // We add the credentials if not already added
     $UserProject->UserId = $userid;
     $UserProject->AddCredential($repositoryCredential);
     $UserProject->ProjectId = 0;
     $UserProject->AddCredential($email);
     // Add the email by default
     $currentURI = get_server_URI();
     $prefix = '';
     if (strlen($firstName) > 0) {
         $prefix = ' ';
     }
     $project = pdo_query("SELECT name FROM project WHERE id='{$projectid}'");
     $project_array = pdo_fetch_array($project);
     $projectname = $project_array['name'];
     // Send the email
     $text = 'Hello' . $prefix . $firstName . ",\n\n";
     $text .= 'You have been registered to CDash because you have CVS/SVN access to the repository for ' . $projectname . "\n";
     $text .= 'To access your CDash account: ' . $currentURI . "/user.php\n";
     $text .= 'Your login is: ' . $email . "\n";
     $text .= 'Your password is: ' . $pass . "\n\n";
     $text .= 'Generated by CDash.';
     if (cdashmail("{$email}", 'CDash - ' . $projectname . ' : Subscription', "{$text}")) {
         echo 'Email sent to: ' . $email . '<br>';
     } else {
         add_log("cannot send email to: {$email}", 'register_user', LOG_ERR);
     }
     return true;
 }
Ejemplo n.º 4
0
 function register_user($projectid, $email, $firstName, $lastName, $repositoryCredential)
 {
     include "cdash/config.php";
     $UserProject = new UserProject();
     $UserProject->ProjectId = $projectid;
     // Check if the user is already registered
     $user = pdo_query("SELECT id FROM " . qid("user") . " WHERE email='{$email}'");
     if (pdo_num_rows($user) > 0) {
         // Check if the user has been registered to the project
         $user_array2 = pdo_fetch_array($user);
         $userid = $user_array2["id"];
         $user = pdo_query("SELECT userid FROM user2project WHERE userid='{$userid}' AND projectid='{$projectid}'");
         if (pdo_num_rows($user) == 0) {
             // We register the user to the project
             pdo_query("INSERT INTO user2project (userid,projectid,role,emailtype)\n                                  VALUES ('{$userid}','{$projectid}','0','1')");
             // We add the credentials if not already added
             $UserProject->UserId = $userid;
             $UserProject->AddCredential($repositoryCredential);
             $UserProject->ProjectId = 0;
             $UserProject->AddCredential($email);
             // Add the email by default
             echo pdo_error();
             return false;
         }
         return "<error>User " . $email . " already registered.</error>";
     }
     // already registered
     // Check if the repositoryCredential exists for this project
     $UserProject->RepositoryCredential = $repositoryCredential;
     if ($UserProject->FillFromRepositoryCredential() === true) {
         return "<error>" . $repositoryCredential . " was already registered for this project under a different email address</error>";
     }
     // Register the user
     // Create a new password
     $keychars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
     $length = 10;
     srand(make_seed_recoverpass());
     $pass = "";
     $max = strlen($keychars) - 1;
     for ($i = 0; $i <= $length; $i++) {
         $pass .= substr($keychars, rand(0, $max), 1);
     }
     $encrypted = md5($pass);
     pdo_query("INSERT INTO " . qid("user") . " (email,password,firstname,lastname,institution,admin)\n                 VALUES ('{$email}','{$encrypted}','{$firstName}','{$lastName}','','0')");
     add_last_sql_error("register_user");
     $userid = pdo_insert_id("user");
     // Insert the user into the project
     pdo_query("INSERT INTO user2project (userid,projectid,role,emailtype)\n                                VALUES ('{$userid}','{$projectid}','0','1')");
     add_last_sql_error("register_user");
     // We add the credentials if not already added
     $UserProject->UserId = $userid;
     $UserProject->AddCredential($repositoryCredential);
     $UserProject->ProjectId = 0;
     $UserProject->AddCredential($email);
     // Add the email by default
     $currentURI = get_server_URI();
     $prefix = "";
     if (strlen($firstName) > 0) {
         $prefix = " ";
     }
     $project = pdo_query("SELECT name FROM project WHERE id='{$projectid}'");
     $project_array = pdo_fetch_array($project);
     $projectname = $project_array['name'];
     // Send the email
     $text = "Hello" . $prefix . $firstName . ",<br><br>";
     $text .= "You have been registered to CDash because you have CVS/SVN access to the repository for " . $projectname . " <br>";
     $text .= "To access your CDash account: " . $currentURI . "/user.php<br>";
     $text .= "Your login is: " . $email . "<br>";
     $text .= "Your password is: " . $pass . "<br>";
     $text .= "<br>Generated by CDash.";
     if (@cdashmail("{$email}", "CDash - " . $projectname . " : Subscription", "{$text}", "From: {$CDASH_EMAILADMIN}\nReply-To: no-reply\nContent-type: text/plain; charset=utf-8\nX-Mailer: PHP/" . phpversion() . "\nMIME-Version: 1.0\nContent-type: text/html; charset=UTF-8")) {
         echo "Email sent to: " . $email . "<br>";
     }
     return true;
 }
Ejemplo n.º 5
0
/** Send an email to administrator of the project for users who are not registered */
function sendEmailUnregisteredUsers($projectid, $cvsauthors)
{
    include 'config/config.php';
    require_once 'models/userproject.php';
    include_once 'include/common.php';
    $unregisteredusers = array();
    foreach ($cvsauthors as $author) {
        if ($author == 'Local User') {
            continue;
        }
        $UserProject = new UserProject();
        $UserProject->RepositoryCredential = $author;
        $UserProject->ProjectId = $projectid;
        if (!$UserProject->FillFromRepositoryCredential()) {
            $unregisteredusers[] = $author;
        }
    }
    // Send the email if any
    if (count($unregisteredusers) > 0) {
        // Find the project administrators
        $email = '';
        $emails = pdo_query('SELECT email FROM ' . qid('user') . ',user2project WHERE ' . qid('user') . '.id=user2project.userid
                         AND user2project.projectid=' . qnum($projectid) . " AND user2project.role='2'");
        while ($emails_array = pdo_fetch_array($emails)) {
            if ($email != '') {
                $email .= ', ';
            }
            $email .= $emails_array['email'];
        }
        // Send the email
        if ($email != '') {
            $projectname = get_project_name($projectid);
            $serverName = $CDASH_SERVER_NAME;
            if (strlen($serverName) == 0) {
                $serverName = $_SERVER['SERVER_NAME'];
            }
            $title = 'CDash [' . $projectname . '] - Unregistered users';
            $body = 'The following users are checking in code but are not registered for the project ' . $projectname . ":\n";
            foreach ($unregisteredusers as $unreg) {
                $body .= '* ' . $unreg . "\n";
            }
            $body .= "\n You should register these users to your project. They are currently not receiving any emails from CDash.\n";
            $body .= "\n-CDash on " . $serverName . "\n";
            add_log($title . ' : ' . $body . ' : ' . $email, 'sendEmailUnregisteredUsers');
            if (cdashmail("{$email}", $title, $body)) {
                add_log('email sent to: ' . $email, 'sendEmailUnregisteredUsers');
                return;
            } else {
                add_log('cannot send email to: ' . $email, 'sendEmailUnregisteredUsers');
            }
        }
    }
}