{ list($usec, $sec) = explode(' ', microtime()); return (double) $sec + (double) $usec * 100000; } srand(make_seed_recoverpass()); $password = ""; $max = strlen($keychars) - 1; for ($i = 0; $i <= $length; $i++) { $password .= substr($keychars, rand(0, $max), 1); } $currentURI = get_server_URI(); $url = $currentURI . "/user.php"; $text = "Hello,\n\n You have asked to recover your password for CDash.\n\n"; $text .= "Your new password is: " . $password . "\n"; $text .= "Please go to this page to login: "******"{$url}\n"; $text .= "\n\nGenerated by CDash"; if (cdashmail("{$email}", "CDash password recovery", $text, "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")) { $md5pass = md5($password); // If we can send the email we update the database pdo_query("UPDATE " . qid("user") . " SET password='******' WHERE email='{$email}'"); add_last_sql_error("recoverPassword"); $xml .= "<message>A confirmation message has been sent to your inbox.</message>"; } else { $xml .= "<warning>Cannot send recovery email</warning>"; } } } $xml .= "</cdash>"; // Now doing the xslt transition generate_XSLT($xml, "recoverPassword");
/** 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() }
/** function to send email to site maintainers when the update * step fails */ function send_update_email($handler, $projectid) { include 'config/config.php'; include_once 'include/common.php'; require_once 'include/pdo.php'; require_once 'models/build.php'; require_once 'models/project.php'; require_once 'models/buildgroup.php'; $Project = new Project(); $Project->Id = $projectid; $Project->Fill(); // If we shouldn't sent any emails we stop if ($Project->EmailBrokenSubmission == 0) { return; } // If the handler has a buildid (it should), we use it if (isset($handler->BuildId) && $handler->BuildId > 0) { $buildid = $handler->BuildId; } else { // Get the build id $name = $handler->getBuildName(); $stamp = $handler->getBuildStamp(); $sitename = $handler->getSiteName(); $buildid = get_build_id($name, $stamp, $projectid, $sitename); } if ($buildid < 0) { return; } // Check if the group as no email $Build = new Build(); $Build->Id = $buildid; $groupid = $Build->GetGroup(); $BuildGroup = new BuildGroup(); $BuildGroup->SetId($groupid); // If we specified no email we stop here if ($BuildGroup->GetSummaryEmail() == 2) { return; } // Send out update errors to site maintainers $update_errors = check_email_update_errors($buildid); if ($update_errors['errors']) { // Find the site maintainer(s) $sitename = $handler->getSiteName(); $siteid = $handler->getSiteId(); $to_address = ''; $email_addresses = pdo_query('SELECT email FROM ' . qid('user') . ',site2user WHERE ' . qid('user') . ".id=site2user.userid AND site2user.siteid='{$siteid}'"); while ($email_addresses_array = pdo_fetch_array($email_addresses)) { if ($to_address != '') { $to_address .= ', '; } $to_address .= $email_addresses_array['email']; } if ($to_address != '') { $serverURI = get_server_URI(); // In the case of asynchronous submission, the serverURI contains /cdash // we need to remove it if ($CDASH_BASE_URL == '' && $CDASH_ASYNCHRONOUS_SUBMISSION) { $serverURI = substr($serverURI, 0, strrpos($serverURI, '/')); } // Generate the email to send $subject = 'CDash [' . $Project->Name . '] - Update Errors for ' . $sitename; $update_info = pdo_query('SELECT command,status FROM buildupdate AS u,build2update AS b2u WHERE b2u.updateid=u.id AND b2u.buildid=' . qnum($buildid)); $update_array = pdo_fetch_array($update_info); $body = "{$sitename} has encountered errors during the Update step and you have been identified as the maintainer of this site.\n\n"; $body .= "*Update Errors*\n"; $body .= 'Status: ' . $update_array['status'] . ' (' . $serverURI . '/viewUpdate.php?buildid=' . $buildid . ")\n"; if ($CDASH_TESTING_MODE) { add_log($to_address, 'TESTING: EMAIL', LOG_DEBUG); add_log($subject, 'TESTING: EMAILTITLE', LOG_DEBUG); add_log($body, 'TESTING: EMAILBODY', LOG_DEBUG); } else { if (cdashmail("{$to_address}", $subject, $body)) { add_log('email sent to: ' . $to_address, 'sendEmailExpectedBuilds'); return; } else { add_log('cannot send email to: ' . $to_address, 'sendEmailExpectedBuilds'); } } } } }
// Create a new password $keychars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&'; $length = 10; $password = ''; $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. $password .= substr($keychars, random_int(0, $max), 1); } $currentURI = get_server_URI(); $url = $currentURI . '/user.php'; $text = "Hello,\n\n You have asked to recover your password for CDash.\n\n"; $text .= 'Your new password is: ' . $password . "\n"; $text .= 'Please go to this page to login: '******'CDash password recovery', $text)) { $md5pass = md5($password); // If we can send the email we update the database pdo_query('UPDATE ' . qid('user') . " SET password='******' WHERE email='{$email}'"); add_last_sql_error('recoverPassword'); $xml .= '<message>A confirmation message has been sent to your inbox.</message>'; } else { $xml .= '<warning>Cannot send recovery email</warning>'; } } } $xml .= '</cdash>'; // Now doing the xslt transition generate_XSLT($xml, 'recoverPassword');
/** Send an email to the administrator of the project */ function SendEmailToAdmin($subject, $body) { if (!$this->Id) { echo "Project SendEmailToAdmin(): Id not set"; return false; } include 'cdash/config.php'; // Check if we should send emails $project = pdo_query("SELECT emailadministrator,name FROM project WHERE id =" . qnum($this->Id)); if (!$project) { add_last_sql_error("Project SendEmailToAdmin", $this->Id); return false; } $project_array = pdo_fetch_array($project); if ($project_array['emailadministrator'] == 0) { return; } // Find the site maintainers include_once 'models/userproject.php'; include_once 'models/user.php'; $UserProject = new UserProject(); $UserProject->ProjectId = $this->Id; $userids = $UserProject->GetUsers(2); // administrators $email = ""; foreach ($userids as $userid) { $User = new User(); $User->Id = $userid; if ($email != "") { $email .= ", "; } $email .= $User->GetEmail(); } if ($email != "") { $projectname = $project_array['name']; $emailtitle = "CDash [" . $projectname . "] - Administration "; $emailbody = "Object: " . $subject . "\n"; $emailbody .= $body . "\n"; $serverName = $CDASH_SERVER_NAME; if (strlen($serverName) == 0) { $serverName = $_SERVER['SERVER_NAME']; } $emailbody .= "\n-CDash on " . $serverName . "\n"; if (cdashmail("{$email}", $emailtitle, $emailbody, "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, "Project::SendEmailToAdmin"); return; } else { add_log("cannot send email to: " . $email, "Project::SendEmailToAdmin", LOG_ERR, $this->Id); } } // end if email }
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; }
/** Authentication function */ function register() { global $reg; include dirname(__DIR__) . '/config/config.php'; require_once 'include/pdo.php'; if (isset($_GET['key'])) { $key = pdo_real_escape_string($_GET['key']); $sql = 'SELECT * FROM ' . qid('usertemp') . " WHERE registrationkey='{$key}'"; $query = pdo_query($sql); if (pdo_num_rows($query) == 0) { $reg = 'The key is invalid.'; return 0; } $query_array = pdo_fetch_array($query); $email = $query_array['email']; // We copy the data from usertemp to user $user = new User(); $user->Email = $email; $user->Password = $query_array['password']; $user->FirstName = $query_array['firstname']; $user->LastName = $query_array['lastname']; $user->Institution = $query_array['institution']; if ($user->Save()) { pdo_query("DELETE FROM usertemp WHERE email='{$email}'"); return 1; } else { $reg = pdo_error(); return 0; } } elseif (isset($_POST['sent'])) { // arrive from register form $url = $_POST['url']; if ($url != 'catchbot') { $reg = 'Bots are not allowed to obtain CDash accounts!'; return 0; } $email = $_POST['email']; $passwd = $_POST['passwd']; $passwd2 = $_POST['passwd2']; if (!($passwd == $passwd2)) { $reg = 'Passwords do not match!'; return 0; } global $CDASH_MINIMUM_PASSWORD_LENGTH, $CDASH_MINIMUM_PASSWORD_COMPLEXITY, $CDASH_PASSWORD_COMPLEXITY_COUNT; $complexity = getPasswordComplexity($passwd); if ($complexity < $CDASH_MINIMUM_PASSWORD_COMPLEXITY) { if ($CDASH_PASSWORD_COMPLEXITY_COUNT > 1) { $reg = "Your password must contain at least {$CDASH_PASSWORD_COMPLEXITY_COUNT} characters from {$CDASH_MINIMUM_PASSWORD_COMPLEXITY} of the following types: uppercase, lowercase, numbers, and symbols."; } else { $reg = "Your password must contain at least {$CDASH_MINIMUM_PASSWORD_COMPLEXITY} of the following: uppercase, lowercase, numbers, and symbols."; } return 0; } if (strlen($passwd) < $CDASH_MINIMUM_PASSWORD_LENGTH) { $reg = "Your password must be at least {$CDASH_MINIMUM_PASSWORD_LENGTH} characters."; return 0; } $fname = $_POST['fname']; $lname = $_POST['lname']; $institution = $_POST['institution']; if ($email && $passwd && $passwd2 && $fname && $lname && $institution) { $db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}"); pdo_select_db("{$CDASH_DB_NAME}", $db); $passwd = md5($passwd); $email = pdo_real_escape_string($email); $sql = 'SELECT email FROM ' . qid('user') . " WHERE email='{$email}'"; if (pdo_num_rows(pdo_query($sql)) > 0) { $reg = "{$email} is already registered."; return 0; } $sql = 'SELECT email FROM ' . qid('usertemp') . " WHERE email='{$email}'"; if (pdo_num_rows(pdo_query($sql)) > 0) { $reg = "{$email} is already registered. Check your email if you haven't received the link to activate yet."; return 0; } $passwd = pdo_real_escape_string($passwd); $fname = pdo_real_escape_string($fname); $lname = pdo_real_escape_string($lname); $institution = pdo_real_escape_string($institution); if ($CDASH_REGISTRATION_EMAIL_VERIFY) { $keychars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $length = 40; $key = ''; $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. $key .= substr($keychars, random_int(0, $max), 1); } $date = date(FMT_DATETIME); $sql = 'INSERT INTO ' . qid('usertemp') . " (email,password,firstname,lastname,institution,registrationkey,registrationdate)\n VALUES ('{$email}','{$passwd}','{$fname}','{$lname}','{$institution}','{$key}','{$date}')"; } else { $user = new User(); $user->Email = $email; $user->Password = $passwd; $user->FirstName = $fname; $user->LastName = $lname; $user->Institution = $institution; $user->Save(); } if (pdo_query($sql)) { if ($CDASH_REGISTRATION_EMAIL_VERIFY) { $currentURI = get_server_URI(); // Send the email $emailtitle = 'Welcome to CDash!'; $emailbody = 'Hello ' . $fname . ",\n\n"; $emailbody .= "Welcome to CDash! In order to validate your registration please follow this link: \n"; $emailbody .= $currentURI . '/register.php?key=' . $key . "\n"; $serverName = $CDASH_SERVER_NAME; if (strlen($serverName) == 0) { $serverName = $_SERVER['SERVER_NAME']; } $emailbody .= "\n-CDash on " . $serverName . "\n"; if (cdashmail("{$email}", $emailtitle, $emailbody)) { add_log('email sent to: ' . $email, 'Registration'); } else { add_log('cannot send email to: ' . $email, 'Registration', LOG_ERR); } $reg = "A confirmation email has been sent. Check your email (including your spam folder) to confirm your registration!\n"; $reg .= 'You need to activate your account within 24 hours.'; return 0; } return 1; } else { $reg = pdo_error(); return 0; } } else { $reg = 'Please fill in all of the required fields'; return 0; } } return 0; }
/** Send an email to the administrator of the project */ public function SendEmailToAdmin($subject, $body) { if (!$this->Id) { echo 'Project SendEmailToAdmin(): Id not set'; return false; } include 'config/config.php'; // Check if we should send emails $project = pdo_query('SELECT emailadministrator,name FROM project WHERE id =' . qnum($this->Id)); if (!$project) { add_last_sql_error('Project SendEmailToAdmin', $this->Id); return false; } $project_array = pdo_fetch_array($project); if ($project_array['emailadministrator'] == 0) { return; } // Find the site maintainers $UserProject = new UserProject(); $UserProject->ProjectId = $this->Id; $userids = $UserProject->GetUsers(2); // administrators $email = ''; foreach ($userids as $userid) { $User = new User(); $User->Id = $userid; if ($email != '') { $email .= ', '; } $email .= $User->GetEmail(); } if ($email != '') { $projectname = $project_array['name']; $emailtitle = 'CDash [' . $projectname . '] - Administration '; $emailbody = 'Object: ' . $subject . "\n"; $emailbody .= $body . "\n"; $serverName = $CDASH_SERVER_NAME; if (strlen($serverName) == 0) { $serverName = $_SERVER['SERVER_NAME']; } $emailbody .= "\n-CDash on " . $serverName . "\n"; if (cdashmail("{$email}", $emailtitle, $emailbody)) { add_log('email sent to: ' . $email, 'Project::SendEmailToAdmin'); return; } else { add_log('cannot send email to: ' . $email, 'Project::SendEmailToAdmin', LOG_ERR, $this->Id); } } }
$messagePlainText .= $file['path'] . " (" . round($file['percent'], 2) . "%)\n"; } $messagePlainText .= "Details on the submission can be found at "; $messagePlainText .= get_server_URI(); $messagePlainText .= "\n\n"; $serverName = $CDASH_SERVER_NAME; if (strlen($serverName) == 0) { $serverName = $_SERVER['SERVER_NAME']; } $messagePlainText .= "\n-CDash on " . $serverName . "\n"; // Send the email $title = "CDash [" . $Project->GetName() . "] - Low Coverage"; $User = new User(); $User->Id = $userid; $email = $User->GetEmail(); cdashmail("{$email}", $title, $messagePlainText, "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"); $xml .= add_XML_value("warning", "*The email has been sent successfully."); } else { $xml .= add_XML_value("warning", "*No email sent because the coverage is green."); } } } // end sendEmail // If we change the priority if (isset($_POST['prioritySelection'])) { $CoverageFile2User = new CoverageFile2User(); $CoverageFile2User->ProjectId = $projectid; $CoverageFile2User->FullPath = htmlspecialchars(pdo_real_escape_string($_POST['fullpath'])); $CoverageFile2User->SetPriority(pdo_real_escape_numeric($_POST['prioritySelection'])); } /** We start generating the XML here */
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; }
/** function to send email to site maintainers when the update * step fails */ function send_update_email($handler, $projectid) { include "cdash/config.php"; include_once "cdash/common.php"; require_once "cdash/pdo.php"; require_once "models/build.php"; require_once "models/project.php"; require_once "models/buildgroup.php"; $Project = new Project(); $Project->Id = $projectid; $Project->Fill(); // If we shouldn't sent any emails we stop if ($Project->EmailBrokenSubmission == 0) { return; } // If the handler has a buildid (it should), we use it if (isset($handler->BuildId) && $handler->BuildId > 0) { $buildid = $handler->BuildId; } else { // Get the build id $name = $handler->getBuildName(); $stamp = $handler->getBuildStamp(); $sitename = $handler->getSiteName(); $buildid = get_build_id($name, $stamp, $projectid, $sitename); } if ($buildid < 0) { return; } // Check if the group as no email $Build = new Build(); $Build->Id = $buildid; $groupid = $Build->GetGroup(); $BuildGroup = new BuildGroup(); $BuildGroup->SetId($groupid); // If we specified no email we stop here if ($BuildGroup->GetSummaryEmail() == 2) { return; } // Send out update errors to site maintainers $update_errors = check_email_update_errors($buildid); if ($update_errors['errors']) { // Find the site maintainer(s) $sitename = $handler->getSiteName(); $siteid = $handler->getSiteId(); $to_address = ""; $email_addresses = pdo_query("SELECT email FROM " . qid("user") . ",site2user WHERE " . qid("user") . ".id=site2user.userid AND site2user.siteid='{$siteid}'"); while ($email_addresses_array = pdo_fetch_array($email_addresses)) { if ($to_address != "") { $to_address .= ", "; } $to_address .= $email_addresses_array["email"]; } if ($to_address != "") { $serverURI = get_server_URI(); // In the case of asynchronous submission, the serverURI contains /cdash // we need to remove it if ($CDASH_BASE_URL == '' && $CDASH_ASYNCHRONOUS_SUBMISSION) { $serverURI = substr($serverURI, 0, strrpos($serverURI, "/")); } // Generate the email to send $subject = "CDash [" . $Project->Name . "] - Update Errors for " . $sitename; $update_info = pdo_query("SELECT command,status FROM buildupdate AS u,build2update AS b2u\n WHERE b2u.updateid=u.id AND b2u.buildid=" . qnum($buildid)); $update_array = pdo_fetch_array($update_info); $body = "{$sitename} has encountered errors during the Update step and you have been identified as the maintainer of this site.\n\n"; $body .= "*Update Errors*\n"; $body .= "Status: " . $update_array["status"] . " (" . $serverURI . "/viewUpdate.php?buildid=" . $buildid . ")\n"; $header = "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"; if ($CDASH_TESTING_MODE) { add_log($to_address, "TESTING: EMAIL", LOG_TESTING); add_log($subject, "TESTING: EMAILTITLE", LOG_TESTING); add_log($body, "TESTING: EMAILBODY", LOG_TESTING); } else { if (cdashmail("{$to_address}", $subject, $body, $header)) { add_log("email sent to: " . $to_address, "sendEmailExpectedBuilds"); return; } else { add_log("cannot send email to: " . $to_address, "sendEmailExpectedBuilds"); } } } } }
$messagePlainText .= $file['path'] . ' (' . round($file['percent'], 2) . "%)\n"; } $messagePlainText .= 'Details on the submission can be found at '; $messagePlainText .= get_server_URI(); $messagePlainText .= "\n\n"; $serverName = $CDASH_SERVER_NAME; if (strlen($serverName) == 0) { $serverName = $_SERVER['SERVER_NAME']; } $messagePlainText .= "\n-CDash on " . $serverName . "\n"; // Send the email $title = 'CDash [' . $Project->GetName() . '] - Low Coverage'; $User = new User(); $User->Id = $userid; $email = $User->GetEmail(); cdashmail("{$email}", $title, $messagePlainText); $xml .= add_XML_value('warning', '*The email has been sent successfully.'); } else { $xml .= add_XML_value('warning', '*No email sent because the coverage is green.'); } } } // If we change the priority if (isset($_POST['prioritySelection'])) { $CoverageFile2User = new CoverageFile2User(); $CoverageFile2User->ProjectId = $projectid; $CoverageFile2User->FullPath = htmlspecialchars(pdo_real_escape_string($_POST['fullpath'])); $CoverageFile2User->SetPriority(pdo_real_escape_numeric($_POST['prioritySelection'])); } /* We start generating the XML here */ // Find the recent builds for this project
/** Authentication function */ function register() { global $reg; include "cdash/config.php"; require_once "cdash/pdo.php"; if (isset($_GET["key"])) { $key = pdo_real_escape_string($_GET["key"]); $sql = "SELECT * FROM " . qid("usertemp") . " WHERE registrationkey='{$key}'"; $query = pdo_query($sql); if (pdo_num_rows($query) == 0) { $reg = "The key is invalid."; return 0; } $query_array = pdo_fetch_array($query); $email = $query_array['email']; $passwd = $query_array['password']; $fname = $query_array['firstname']; $lname = $query_array['lastname']; $institution = $query_array['institution']; // We copy the data from usertemp to user $sql = "INSERT INTO " . qid("user") . " (email,password,firstname,lastname,institution)\n VALUES ('{$email}','{$passwd}','{$fname}','{$lname}','{$institution}')"; if (pdo_query($sql)) { pdo_query("DELETE FROM usertemp WHERE email='" . $email . "'"); return 1; } else { $reg = pdo_error(); return 0; } } else { if (isset($_POST["sent"])) { $url = $_POST["url"]; if ($url != "catchbot") { $reg = "Bots are not allowed to obtain CDash accounts!"; return 0; } $email = $_POST["email"]; $passwd = $_POST["passwd"]; $passwd2 = $_POST["passwd2"]; if (!($passwd == $passwd2)) { $reg = "Passwords do not match!"; return 0; } $fname = $_POST["fname"]; $lname = $_POST["lname"]; $institution = $_POST["institution"]; if ($email && $passwd && $passwd2 && $fname && $lname && $institution) { $db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}"); pdo_select_db("{$CDASH_DB_NAME}", $db); $passwd = md5($passwd); $email = pdo_real_escape_string($email); $sql = "SELECT email FROM " . qid("user") . " WHERE email='{$email}'"; if (pdo_num_rows(pdo_query($sql)) > 0) { $reg = "{$email} is already registered."; return 0; } $sql = "SELECT email FROM " . qid("usertemp") . " WHERE email='{$email}'"; if (pdo_num_rows(pdo_query($sql)) > 0) { $reg = "{$email} is already registered. Check your email if you haven't received the link to activate yet."; return 0; } $passwd = pdo_real_escape_string($passwd); $fname = pdo_real_escape_string($fname); $lname = pdo_real_escape_string($lname); $institution = pdo_real_escape_string($institution); if ($CDASH_REGISTRATION_EMAIL_VERIFY) { // Create a key srand(microtime_float()); $keychars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $length = 40; $key = ""; $max = strlen($keychars) - 1; for ($i = 0; $i < $length; $i++) { $key .= substr($keychars, rand(0, $max), 1); } $date = date(FMT_DATETIME); $sql = "INSERT INTO " . qid("usertemp") . " (email,password,firstname,lastname,institution,registrationkey,registrationdate)\n VALUES ('{$email}','{$passwd}','{$fname}','{$lname}','{$institution}','{$key}','{$date}')"; } else { $sql = "INSERT INTO " . qid("user") . " (email,password,firstname,lastname,institution)\n VALUES ('{$email}','{$passwd}','{$fname}','{$lname}','{$institution}')"; } if (pdo_query($sql)) { if ($CDASH_REGISTRATION_EMAIL_VERIFY) { $currentURI = get_server_URI(); // Send the email $emailtitle = "Welcome to CDash!"; $emailbody = "Hello " . $fname . ",\n\n"; $emailbody .= "Welcome to CDash! In order to validate your registration please follow this link: \n"; $emailbody .= $currentURI . "/register.php?key=" . $key . "\n"; $serverName = $CDASH_SERVER_NAME; if (strlen($serverName) == 0) { $serverName = $_SERVER['SERVER_NAME']; } $emailbody .= "\n-CDash on " . $serverName . "\n"; if (cdashmail("{$email}", $emailtitle, $emailbody, "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, "Registration"); } else { add_log("cannot send email to: " . $email, "Registration", LOG_ERR); } $reg = "A confirmation email has been sent. Check your email (including your spam folder) to confirm your registration!\n"; $reg .= "You need to activate your account within 24 hours."; return 0; } return 1; } else { $reg = pdo_error(); return 0; } } else { $reg = "Please fill in all of the required fields"; return 0; } } } // end register return 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'); } } } }