// Copyright 1999 (c) by Perforce Software, Inc. All rights reserved. // // p4wAuthView: // The auth view. // ------------------------------------- // Includes // #include <stdlib.h> #include <string.h> #include <p4wp4.h> #include "p4wStrBuf.h" #include "p4wHtml.h" #include "p4wView.h" #include "p4wAuthView.h" #include "p4wLogoutPane.h" #include "p4wPasswdTestPane.h" // // ------------------------------------- // Constructors and destructor. // p4wAuthView::p4wAuthView(p4wRequest & Request) : p4wView(Request) { } p4wAuthView::~p4wAuthView() { } // ------------------------------------- // Render this view. // void p4wAuthView::Render() { // // See if new enough server to use login -p const StrPtr *server = fRequest.GetProtocol( "server2" ); Error e; fRequest.p4Init( &e ); if( !e.Test() ) { p4wPasswdTestPane dummyCmd( *this, fRequest ); fRequest.p4( "info", 0, 0, &dummyCmd ); fRequest.p4Wait(); server = fRequest.GetProtocol( "server2" ); int protocol; if( server ) protocol = server->Atoi(); // // Satisfy minimal SSL requirement int i = 1; const char *argv[] = { "-y" }; p4wPasswdTestPane dummy( *this, fRequest ); fRequest.p4("trust", i, (const char **)argv, &dummy); fRequest.p4Wait(); fRequest.fSave4Later = 1; p4wLogoutPane LogoutPane( *this, fRequest, "Logout" ); fRequest.p4( "logout", 0, 0, &LogoutPane ); fRequest.p4Wait(); fRequest.fSave4Later = 0; if( protocol > 17 ) // 2004.1 or later? { RenderFancy(); return; } } // // Generate the HTTP header for an authentication failure p4wHtml htm; char *p = fRequest.GetHTTPPort().Text(); p = strchr(p, ':'); htm.authHeader(); htm.contentType( "text/html", p ? 0 : 1 ); htm.setCookie( p ? p+1 : "", fRequest.GetUser().Text(), 1, 1 ); // clear cookie // // Include p4web-style features, like the BASE htm.beginHeader( 0 ); htm.title( "P4Web - Authentication Error" ); htm.base( p4wStrBuf().NormalizeBase( fRequest.GetBase() ).Text(), fRequest.IsHTTPS() ); htm.endHeader( fRequest.GetHTTPPort().Text(), fRequest.IsHTTPS() ); // // Generate the authentication error message htm.beginBody( "#ffffff", "#0000cc", "#0000cc" ); htm.header( "Authentication Error" ); htm.text( "Unauthorized Perforce user or incorrect password." ); // // Include a link to retry entering user & password. // The link is the originally entered url with the // "pw" flag set to indicate a password failure occurred. StrBuf url; StrBufDict args; args.SetVar( "pw", "" ); fRequest.ConstructSafeURL( url, fRequest.GetURL().Text(), fRequest.GetCmd(), &args ); htm.beginLink( url.Text() ); htm.text( "Retry" ); htm.endLink(); htm.text( " login." ); htm.paragraph(); htm.text( "Contact your Perforce administrator if you need further assistance." ); htm.endBody(); // // Write out the page fRequest << htm; } void p4wAuthView::RenderFancy() { // // Generate a normal HTTP header p4wHtml htm(1); p4wURL urlMaker; char *p = fRequest.GetHTTPPort().Text(); p = strchr(p, ':'); htm.httpHeader(200); htm.contentType( "text/html", 0 ); htm.setCookie( p ? p+1 : "", fRequest.GetUser().Text(), 1, 1 ); // clear cookie // // Include p4web-style features, like the CSS & BASE htm.beginHeader( 0 ); if (fRequest.GetCmd() == AC_LOGOUT && strcmp(fRequest.GetUser().Text(), "@")) htm.title( "P4Web - Logout" ); else htm.title( "P4Web - Login" ); htm.styleSheet(&fRequest, 1); htm.base( p4wStrBuf().NormalizeBase( fRequest.GetBase() ).Text(), fRequest.IsHTTPS() ); if (fRequest.GetCmd() == AC_LOGOUT) { htm << "<META http-equiv=\"Refresh\" content=\"60; URL="; if (fRequest.IsHTTPS()) htm << "https://"; else htm << "http://"; htm << fRequest.GetHTTPPort().Text() << "?ac=" << AC_USERPSWD << "\">"; } htm.endHeader( fRequest.GetHTTPPort().Text(), fRequest.IsHTTPS() ); // // Generate the authentication error message htm.beginBody( "#ffffff", "#0000cc", "#0000cc", "0", "0", "0", "0", fRequest.GetJavascriptMode() == 2 ? "onLoad" : 0, fRequest.GetJavascriptMode() == 2 ? "document.execCommand('ClearAuthenticationCache')" : 0); fRequest << htm; htm.Clear(); fRequest.SetScreenChunks(SCRN_LOGO + SCRN_BODY + SCRN_COPYRIGHT); RenderInfo(); htm.beginTable( "0", "100%", "6", 0, "#FFFFFF", "normal" ); htm.beginTRow(); htm.beginCol( ); if (fRequest.GetCmd() == AC_LOGOUT && strcmp(fRequest.GetUser().Text(), "@")) { htm.beginTable( "0", "100%", "0", "0"); htm << fRequest.fLater; fRequest.fLater.Clear(); htm.endTable(); htm.hline(NULL, NULL); htm.text( "To resume using P4Web, log in to the Perforce server" ); } else { htm.beginSpan("title"); htm.text( "Log In:" ); htm.endSpan(); htm.linebreak(); StrBuf grayIcon; urlMaker.ConstructURL( grayIcon, "/grayPixelIcon", AC_ICON, NULL ); htm.icon( grayIcon.Text(), "1", "100%", "", 1, "3", "0" ); const StrPtr *bad = fRequest.GetDynArg("bad"); htm.text( "To start or resume using P4Web, log in to the Perforce server" ); } htm.paragraph(); // // Save the original URL so we can retry it after successful login StrBuf orgurl; orgurl << fRequest.GetURL().Text() << fRequest.GetDynURL().Text(); // // If this URL is processing a POST command, // we have to use the referer as the orgurl char *post = fRequest.GetPostData(); if (post) { const StrPtr *referer = fRequest.GetReferer(); if (referer) { p = strrchr(referer->Text(), '/'); if (p) { #ifdef OS_NT if( fRequest.GetViewMode() == VM_WORKSPACE ) { char *q = p; while (q) { q = strstr(p, "%5C"); if (q) p = q+2; } } #endif orgurl.Set(++p); } } } p = strstr(orgurl.Text(), "&pw"); if (p) { orgurl.SetLength(); strcpy(p, p+3); } p4wURL url; StrBuf actionURL; url.ConstructURL( actionURL, NULL, AC_USERPSWD, NULL, fRequest.GetUnicode() ); htm.beginLogin(actionURL.Text()); htm.beginTRow(); htm.beginCol(); htm << "Client: "; htm.endCol(); htm.beginCol(); const StrPtr *cl = fRequest.GetStateArg( "cl" ); htm.textField("c", cl && cl->Length() ? p4wStrBuf().EscapeHTML(*cl, fRequest.GetUnicode()).Text() : 0, 25, 0,0,0,0, "off"); htm.endCol(); htm.endTRow(); htm.beginTRow(); htm.beginCol(); htm.endCol(); htm.beginCol(); htm.beginSpan("remote"); StrPtr *s; Options *opts = fRequest.GetOpts(); Enviro enviro; if (fRequest.GetBrowseMode()) { if (enviro.Get( "P4CLIENT" )) htm.text( "(Optional)" ); } else if( s = (*opts)[ 'M' ] ) { htm.text( "Leave this field blank if you don't know the client you want to use" ); if (enviro.Get( "P4CLIENT" )) { htm.linebreak(); htm.text( "or you only want to browse the depot." ); } } else if (enviro.Get( "P4CLIENT" )) { htm.text( "Leave this field blank if you want to use the default client." ); } htm.endSpan(); htm.endCol(); htm.endTRow(); htm.beginTRow(); htm.beginCol(); htm << " "; htm.endCol(); htm.endTRow(); htm.endLogin(orgurl.Text()); htm.paragraph(); htm.text("If you need further assistance, see "); StrBuf helpurl; urlMaker.ConstructLocationURL( helpurl, "auth", AC_HELP, NULL, fRequest.GetUnicode() ); htm.beginLink(helpurl.Text()); htm.text("P4Web help"); htm.endLink(); htm.text( " or contact your Perforce administrator." ); htm.endTRow(); htm.beginTRow(); htm.beginCol(0, 0, 0, 0,0,0,0,1); htm.hline(0, 0); htm.beginSpan( "copyright" ); htm << "Copyright 2008 Perforce Software. All rights reserved."; htm.endSpan(); htm.endCol(); htm.endTRow(); htm.endTable(); htm.endCol(); htm.endTRow(); htm.endTable(); htm.endCol(); htm.endTRow(); htm.endTable(); htm.endBody(); // // Write out the page fRequest << htm; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 12234 | Matt Attaway |
Rejigger P4Web project in preparation for official sunsetting The bin directory contains the last official builds of P4Web from the Perforce download site. P4Web is soon to be completely sunsetted; these builds are here for folks who don't want to build their own. To better handle the archived builds the source code has been moved into a separate src directory. |
||
//guest/perforce_software/p4web/Views/p4wAuthView.cpp | |||||
#2 | 10416 | Lester Cheung | Using HTTPS for favicon when option -ss (HTTPS mode) is used. | ||
#1 | 8914 | Matt Attaway | Initial add of the P4Web source code |