function send_error_email($userid, $emailaddress, $sendEmail, $errors, $Build, $Project, $prefix = 'none') { include 'config/config.php'; $emailtext = array(); $emailtext['nerror'] = 0; if ($userid != 0) { // For registered users, tune the error array based on user preferences // to make sure he doesn't get emails that are unwanted/unnecessary $UserProject = new UserProject(); $UserProject->UserId = $userid; $UserProject->ProjectId = $Project->Id; $useremailcategory = $UserProject->GetEmailCategory(); } // Check if an email has been sent already for this user foreach ($errors as $errorkey => $nerrors) { if ($nerrors == 0 || $errorkey == 'errors') { continue; } $stop = false; if ($userid != 0) { // If the user doesn't want to get the email switch ($errorkey) { case 'update_errors': if (!check_email_category('update', $useremailcategory)) { $stop = true; } break; case 'configure_errors': if (!check_email_category('configure', $useremailcategory)) { $stop = true; } break; case 'build_errors': if (!check_email_category('error', $useremailcategory)) { $stop = true; } break; case 'build_warnings': if (!check_email_category('warning', $useremailcategory)) { $stop = true; } break; case 'test_errors': if (!check_email_category('test', $useremailcategory)) { $stop = true; } break; case 'dynamicanalysis_errors': if (!check_email_category('dynamicanalysis', $useremailcategory)) { $stop = true; } break; } } else { // For committers, only send emails when the errorkey starts with the // prefix associated with the current handler calling us. // (So stop if the errorkey does not begin with the prefix...) // This minimizes sending out possibly near-duplicate emails to the // same committers... // if (0 !== strpos($errorkey, $prefix)) { $stop = true; } } if ($stop) { continue; } if (0 == $userid || !check_email_sent($userid, $Build->Id, $errorkey)) { $emailtext['summary'][$errorkey] = get_email_summary($Build->Id, $errors, $errorkey, $Project->EmailMaxItems, $Project->EmailMaxChars, $Project->TestTimeMaxStatus, $Project->EmailTestTimingChanged); $emailtext['category'][$errorkey] = $nerrors; $emailtext['nerror'] = 1; } } // Send the email if ($emailtext['nerror'] == 1) { if ($userid != 0) { send_email_to_user($userid, $emailtext, $Build, $Project); if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/sendemail.php')) { $sendEmail->UserId = $userid; $sendEmail->Text = $emailtext; $sendEmail->SendToUser(); } } else { send_email_to_address($emailaddress, $emailtext, $Build, $Project); // // Do we still need a "$sendEmail->" call here even if // there is no UserId...? // } } }
@($emailcategory_dynamicanalysis = $_POST["emailcategory_dynamicanalysis"]); $EmailCategory = $emailcategory_update + $emailcategory_configure + $emailcategory_warning + $emailcategory_error + $emailcategory_test + $emailcategory_dynamicanalysis; if (pdo_num_rows($user2project) > 0) { pdo_query("UPDATE user2project SET role='{$Role}',emailtype='{$EmailType}',\n emailcategory='{$EmailCategory}'.\n emailmissingsites='{$EmailMissingSites}',\n emailsuccess='{$EmailSuccess}'\n WHERE userid='{$userid}' AND projectid='{$projectid}'"); // Update the repository credential $UserProject = new UserProject(); $UserProject->ProjectId = $projectid; $UserProject->UserId = $userid; $UserProject->UpdateCredentials($Credentials); if ($Role == 0) { // Remove the claim sites for this project if they are only part of this project pdo_query("DELETE FROM site2user WHERE userid='{$userid}'\n AND siteid NOT IN\n (SELECT build.siteid FROM build,user2project as up WHERE\n up.projectid = build.projectid AND up.userid='{$userid}' AND up.role>0\n GROUP BY build.siteid)"); } } else { pdo_query("INSERT INTO user2project (role,userid,projectid,emailtype,emailcategory,emailsuccess,\n emailmissingsites)\n VALUES ('{$Role}','{$userid}','{$projectid}','{$EmailType}','{$EmailCategory}',\n '{$EmailSuccess}','{$EmailMissingSites}')"); $UserProject = new UserProject(); $UserProject->ProjectId = $projectid; $UserProject->UserId = $userid; foreach ($Credentials as $credential) { $UserProject->AddCredential($credential); } } header('location: user.php?note=subscribedtoproject'); } } } // XML // Show the current credentials for the user $query = pdo_query("SELECT credential,projectid FROM user2repository WHERE userid='" . $userid . "'\n AND (projectid='" . $projectid . "' OR projectid=0)"); $credential_num = 0; while ($credential_array = pdo_fetch_array($query)) {
/** 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 }
/** 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 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; }
add_last_sql_error('editUser.php'); } } $xml .= '<user>'; $user = pdo_query('SELECT * FROM ' . qid('user') . " WHERE id='{$userid}'"); $user_array = pdo_fetch_array($user); $xml .= add_XML_value('id', $userid); $xml .= add_XML_value('firstname', $user_array['firstname']); $xml .= add_XML_value('lastname', $user_array['lastname']); $xml .= add_XML_value('email', $user_array['email']); $xml .= add_XML_value('institution', $user_array['institution']); // Update the credentials @($updatecredentials = $_POST['updatecredentials']); if ($updatecredentials) { $credentials = $_POST['credentials']; $UserProject = new UserProject(); $UserProject->ProjectId = 0; $UserProject->UserId = $userid; $credentials[] = $user_array['email']; $UserProject->UpdateCredentials($credentials); } // List the credentials // First the email one (which cannot be changed) $credential = pdo_query("SELECT credential FROM user2repository WHERE userid='{$userid}'\n AND projectid=0 AND credential='" . $user_array['email'] . "'"); if (pdo_num_rows($credential) == 0) { $xml .= add_XML_value('credential_0', 'Not found (you should really add it)'); } else { $xml .= add_XML_value('credential_0', $user_array['email']); } $credential = pdo_query("SELECT credential FROM user2repository WHERE userid='{$userid}'\n AND projectid=0 AND credential!='" . $user_array['email'] . "'"); $credential_num = 1;
/** 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); } } }
$User = new User(); $User->Id = $authorid; $xml .= add_XML_value("name", $User->GetName()); $xml .= add_XML_value("id", $authorid); $xml .= "</author>"; } $priority = $CoverageFile2User->GetPriority(); if ($priority > 0) { $xml .= add_XML_value("priority", $priority); } $xml .= "</file>"; } } // end count(buildids) // List all the users of the project $UserProject = new UserProject(); $UserProject->ProjectId = $Project->Id; $userIds = $UserProject->GetUsers(); foreach ($userIds as $userid) { $User = new User(); $User->Id = $userid; $xml .= "<user>"; $xml .= add_XML_value("id", $userid); $xml .= add_XML_value("name", $User->GetName()); $xml .= "</user>"; } $xml .= "</project>"; } $xml .= "</cdash>"; // Now doing the xslt transition generate_XSLT($xml, "manageCoverage");
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; }
} if (!isset($_GET['projectid']) && !isset($_GET['scheduleid'])) { echo 'Projectid or Schedule id not set'; return; } if (isset($_GET['projectid'])) { $projectid = pdo_real_escape_numeric($_GET['projectid']); } else { $scheduleid = pdo_real_escape_numeric($_GET['scheduleid']); $ClientJobSchedule = new ClientJobSchedule(); $ClientJobSchedule->Id = $scheduleid; $projectid = $ClientJobSchedule->GetProjectId(); } if (!$User->IsAdmin()) { // Make sure user has project admin privileges to use this page $UserProject = new UserProject(); $UserProject->ProjectId = $projectid; $projectAdmins = $UserProject->GetUsers(2); //get project admin users if (!in_array($userid, $projectAdmins)) { echo 'You are not a project administrator!'; return; } } $xml = begin_XML_for_XSLT(); $xml .= add_XML_value('manageclient', $CDASH_MANAGE_CLIENTS); $db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}"); pdo_select_db("{$CDASH_DB_NAME}", $db); $xml .= add_XML_value('title', 'CDash - Schedule Build'); $xml .= add_XML_value('menutitle', 'CDash'); $xml .= add_XML_value('menusubtitle', 'Schedule Build');
/** endElement function */ public function endElement($parser, $name) { parent::endElement($parser, $name); global $CDASH_DELETE_OLD_SUBPROJECTS; if (!$this->ProjectNameMatches) { return; } if ($name == 'PROJECT') { foreach ($this->SubProjects as $subproject) { if ($CDASH_DELETE_OLD_SUBPROJECTS) { // Remove dependencies that do not exist anymore, // but only for those relationships where both sides // are present in $this->SubProjects. // $dependencyids = $subproject->GetDependencies(); $removeids = array_diff($dependencyids, $this->Dependencies[$subproject->GetId()]); foreach ($removeids as $removeid) { if (array_key_exists($removeid, $this->SubProjects)) { $subproject->RemoveDependency($removeid); } else { $dep = pdo_get_field_value("SELECT name FROM subproject WHERE id='{$removeid}'", 'name', "{$removeid}"); add_log("Not removing dependency {$dep}({$removeid}) from " . $subproject->GetName() . 'because it is not a SubProject element in this Project.xml file', 'ProjectHandler:endElement', LOG_WARNING, $this->projectid); } } } // Add dependencies that were queued up as we processed the DEPENDENCY // elements: // foreach ($this->Dependencies[$subproject->GetId()] as $addid) { if (array_key_exists($addid, $this->SubProjects)) { $subproject->AddDependency($addid); } else { add_log('impossible condition: should NEVER see this: unknown DEPENDENCY clause should prevent this case', 'ProjectHandler:endElement', LOG_WARNING, $this->projectid); } } } if ($CDASH_DELETE_OLD_SUBPROJECTS) { // Delete old subprojects that weren't included in this file. $previousSubProjectIds = $this->Project->GetSubProjects(); foreach ($previousSubProjectIds as $previousId) { $found = false; foreach ($this->SubProjects as $subproject) { if ($subproject->GetId() == $previousId) { $found = true; break; } } if (!$found) { $subProjectToRemove = new SubProject(); $subProjectToRemove->SetId($previousId); $subProjectToRemove->Delete(); add_log("Deleted " . $subProjectToRemove->GetName() . " because it was not mentioned in Project.xml", 'ProjectHandler:endElement', LOG_WARNING, $this->projectid); } } } } elseif ($name == 'SUBPROJECT') { // Insert the SubProject. $this->SubProject->Save(); // Insert the label. $Label = new Label(); $Label->Text = $this->SubProject->GetName(); $Label->Insert(); $this->SubProjects[$this->SubProject->GetId()] = $this->SubProject; // Handle dependencies here too. $this->Dependencies[$this->SubProject->GetId()] = array(); foreach ($this->CurrentDependencies as $dependencyid) { $added = false; if ($dependencyid !== false && is_numeric($dependencyid)) { if (array_key_exists($dependencyid, $this->SubProjects)) { $this->Dependencies[$this->SubProject->GetId()][] = $dependencyid; $added = true; } } if (!$added) { add_log('Project.xml DEPENDENCY of ' . $this->SubProject->GetName() . ' not mentioned earlier in file.', 'ProjectHandler:endElement', LOG_WARNING, $this->projectid); } } // Check if the user is in the database. $User = new User(); $posat = strpos($this->Email, '@'); if ($posat !== false) { $User->FirstName = substr($this->Email, 0, $posat); $User->LastName = substr($this->Email, $posat + 1); } else { $User->FirstName = $this->Email; $User->LastName = $this->Email; } $User->Email = $this->Email; $User->Password = md5($this->Email); $User->Admin = 0; $userid = $User->GetIdFromEmail($this->Email); if (!$userid) { $User->Save(); $userid = $User->Id; } // Insert into the UserProject $UserProject = new UserProject(); $UserProject->EmailType = 3; // any build $UserProject->EmailCategory = 54; // everything except warnings $UserProject->UserId = $userid; $UserProject->ProjectId = $this->projectid; $UserProject->Save(); // Insert the labels for this user $LabelEmail = new LabelEmail(); $LabelEmail->UserId = $userid; $LabelEmail->ProjectId = $this->projectid; $Label = new Label(); $Label->SetText($this->SubProject->GetName()); $labelid = $Label->GetIdFromText(); if (!empty($labelid)) { $LabelEmail->LabelId = $labelid; $LabelEmail->Insert(); } } }
/** startElement function */ public function startElement($parser, $name, $attributes) { parent::startElement($parser, $name, $attributes); // Check that the project name matches if ($name == 'PROJECT') { if (get_project_id($attributes['NAME']) != $this->projectid) { add_log("Wrong project name: " . $attributes['NAME'], "ProjectHandler::startElement", LOG_ERR, $this->projectid); $this->ProjectNameMatches = false; } } if (!$this->ProjectNameMatches) { return; } if ($name == 'PROJECT') { $this->SubProjects = array(); $this->Dependencies = array(); } else { if ($name == 'SUBPROJECT') { $this->SubProject = new SubProject(); $this->SubProject->SetProjectId($this->projectid); $this->SubProject->SetName($attributes['NAME']); if (array_key_exists("GROUP", $attributes)) { $this->SubProject->SetGroup($attributes['GROUP']); } $this->SubProject->Save(); // Insert the label $Label = new Label(); $Label->Text = $this->SubProject->GetName(); $Label->Insert(); $this->SubProjects[$this->SubProject->GetId()] = $this->SubProject; $this->Dependencies[$this->SubProject->GetId()] = array(); } else { if ($name == 'DEPENDENCY') { // A DEPENDENCY is expected to be: // // - another subproject that already exists (from a previous element in // this submission) // $dependentProject = new SubProject(); $dependentProject->SetName($attributes['NAME']); $dependentProject->SetProjectId($this->projectid); // The subproject's Id is automatically loaded once its name & projectid // are set. $dependencyid = $dependentProject->GetId(); $added = false; if ($dependencyid !== false && is_numeric($dependencyid)) { if (array_key_exists($dependencyid, $this->SubProjects)) { $this->Dependencies[$this->SubProject->GetId()][] = $dependencyid; $added = true; } } if (!$added) { add_log("Project.xml DEPENDENCY of " . $this->SubProject->GetName() . " not mentioned earlier in file: " . $attributes['NAME'], "ProjectHandler:startElement", LOG_WARNING, $this->projectid); } } else { if ($name == 'EMAIL') { $email = $attributes['ADDRESS']; // Check if the user is in the database $User = new User(); $posat = strpos($email, '@'); if ($posat !== false) { $User->FirstName = substr($email, 0, $posat); $User->LastName = substr($email, $posat + 1); } else { $User->FirstName = $email; $User->LastName = $email; } $User->Email = $email; $User->Password = md5($email); $User->Admin = 0; $userid = $User->GetIdFromEmail($email); if (!$userid) { $User->Save(); $userid = $User->Id; } // Insert into the UserProject $UserProject = new UserProject(); $UserProject->EmailType = 3; // any build $UserProject->EmailCategory = 54; // everything except warnings $UserProject->UserId = $userid; $UserProject->ProjectId = $this->projectid; $UserProject->Save(); // Insert the labels for this user $LabelEmail = new LabelEmail(); $LabelEmail->UserId = $userid; $LabelEmail->ProjectId = $this->projectid; $Label = new Label(); $Label->SetText($this->SubProject->GetName()); $labelid = $Label->GetIdFromText(); if (!empty($labelid)) { $LabelEmail->LabelId = $labelid; $LabelEmail->Insert(); } } } } } }
/** 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'); } } } }