bd3864e1e7ec7ee2e2ff687527ce4750e3f83284 chinhli Wed Aug 22 14:35:37 2012 -0700 Bug #8832 Modify hgLogin to use the right arguments depending on the version of mail on the system diff --git src/hg/hgLogin/hgLogin.c src/hg/hgLogin/hgLogin.c index 1507de9..cfb3ed8 100644 --- src/hg/hgLogin/hgLogin.c +++ src/hg/hgLogin/hgLogin.c @@ -25,30 +25,31 @@ char msg[4096] = ""; char *incorrectUsernameOrPassword="The username or password you entered is incorrect."; char *incorrectUsername="The username you entered is incorrect."; /* The excludeVars are not saved to the cart. */ char *excludeVars[] = { "submit", "Submit", "debug", "fixMembers", "update", "hgLogin_password", "hgLogin_password2", "hgLogin_newPassword1", "hgLogin_newPassword2", NULL }; struct cart *cart; /* This holds cgi and other variables between clicks. */ char *database; /* Name of genome database - hg15, mm3, or the like. */ struct hash *oldCart; /* Old cart hash. */ char *errMsg; /* Error message to show user when form data rejected */ char brwName[64]; char brwAddr[256]; char signature[256]; char returnAddr[256]; +char mailFormat[32]; /* ---- Global helper functions ---- */ char *browserName() /* Return the browser name like 'UCSC Genome Browser' */ { if isEmpty(cfgOption(CFG_LOGIN_BROWSER_NAME)) return cloneString("NULL_browserName"); else return cloneString(cfgOption(CFG_LOGIN_BROWSER_NAME)); } char *browserAddr() /* Return the browser address like 'http://genome.ucsc.edu' */ { if isEmpty(cfgOption(CFG_LOGIN_BROWSER_ADDR)) return cloneString("NULL_browserAddr"); @@ -62,30 +63,53 @@ if isEmpty(cfgOption(CFG_LOGIN_MAIL_SIGNATURE)) return cloneString("NULL_mailSignature"); else return cloneString(cfgOption(CFG_LOGIN_MAIL_SIGNATURE)); } char *mailReturnAddr() /* Return the return addr. to be used by outbound mail or NULL. Allocd here. */ { if isEmpty(cfgOption(CFG_LOGIN_MAIL_RETURN_ADDR)) return cloneString("NULL_mailReturnAddr"); else return cloneString(cfgOption(CFG_LOGIN_MAIL_RETURN_ADDR)); } +char *mailOptionFormat() +/* Return the mail option format to be used by mail command */ +{ +if isEmpty(cfgOption(CFG_MAIL_OPTIONFORMAT)) + return cloneString("SENDMAIL"); +else + return cloneString(cfgOption(CFG_MAIL_OPTIONFORMAT)); +} + +int mailItOut(char *toAddr, char *subject, char *msg, char *fromAddr) +/* send mail to toAddr address */ +{ +char cmd[4096]; +if (sameString(mailFormat, "POSTFIX")) + safef(cmd,sizeof(cmd), "echo '%s' | /bin/mail -s \"%s\" -r %s %s", + msg, subject, fromAddr, toAddr); +else + safef(cmd,sizeof(cmd), "echo '%s' | /bin/mail -s \"%s\" %s -- -f%s", + msg, subject, toAddr, fromAddr); +int result = system(cmd); +return result; +} + /* ---- password functions depend on optionally installed openssl lib ---- */ #ifdef USE_SSL #include void cryptWikiWay(char *password, char *salt, char* result) /* encrypt password in mediawiki format - ':B:'.$salt.':'. md5($salt.'-'.md5($password ) */ { int i; unsigned char result1[MD5_DIGEST_LENGTH]; unsigned char result2[MD5_DIGEST_LENGTH]; char firstMD5[MD5_DIGEST_LENGTH*2 + 1]; char secondMD5[MD5_DIGEST_LENGTH*2 + 1]; i = MD5_DIGEST_LENGTH; MD5((unsigned char *)password, strlen(password), result1); @@ -337,35 +361,33 @@ "\n" "

%s

", brwName); hPrintf( "

A confirmation email has been sent to you. \n" "Please click the confirmation link in the email to activate your account.

" "\n" "

Return

", returnURL); cartRemove(cart, "hgLogin_email"); cartRemove(cart, "hgLogin_userName"); } void sendActMailOut(char *email, char *subject, char *msg) /* send mail to email address */ { char *hgLoginHost = wikiLinkHost(); -char cmd[4096]; -safef(cmd,sizeof(cmd), - "echo '%s' | mail -s \"%s\" %s -- -f %s", - msg, subject, email, returnAddr); -int result = system(cmd); +int result; +result = mailItOut(email, subject, msg, returnAddr); + if (result == -1) { hPrintf( "

%s

", brwName); hPrintf( "

" "

" "

Error emailing to: %s

" "Click here to return.
", email ); } else { hPrintf("