00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include <exception>
00046 #include <iostream>
00047
00048 #include "cgicc/Cgicc.h"
00049 #include "cgicc/HTTPResponseHeader.h"
00050 #include "cgicc/HTMLClasses.h"
00051
00052 using namespace std;
00053 using namespace cgicc;
00054
00055 int
00056 main(int ,
00057 char ** )
00058 {
00059 try {
00060 Cgicc cgi;
00061 const CgiEnvironment& env = cgi.getEnvironment();
00062 string remoteuser = env.getRemoteUser();
00063 string serversw = env.getServerSoftware();
00064 string clientsw = env.getUserAgent();
00065 string authtype = env.getAuthType();
00066
00067 if(remoteuser.empty()) {
00068 if (serversw.find("Microsoft") != string::npos
00069 && clientsw.find("Win") != string::npos) {
00070
00071
00072
00073
00074
00075
00076
00077 cout << HTTPResponseHeader("HTTP/1.1", 401, "Unauthorized")
00078 .addHeader("WWW-Authenticate", "NTLM")
00079 .addHeader("WWW-Authenticate", "Basic realm=\"cgicc\"");
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 }
00090 else {
00091
00092 cout << HTTPResponseHeader("HTTP/1.1", 401, "Unauthorized")
00093 .addHeader("WWW-Authenticate", "Basic realm=\"cgicc\"");
00094 }
00095
00096
00097
00098
00099 cout << HTMLDoctype(HTMLDoctype::eStrict) << endl;
00100 cout << html().set("lang", "EN").set("dir", "LTR") << endl;
00101
00102 cout << head() << endl;
00103 cout << title("401 Authorization Required") << endl;
00104 cout << head() << endl;
00105
00106 cout << body() << endl;
00107 cout << h1("401 Authorization Required") << endl;
00108 cout << p() << "This server could not verify that you are "
00109 << "authorized to access the document requested. Either you "
00110 << "supplied the wrong credentials (e.g., bad password), or "
00111 << "your browser doesn't understand how to supply the "
00112 << "credentials required." << p();
00113
00114 cout << hr() << endl;
00115 cout << address() << "GNU cgicc \"server\" version " << cgi.getVersion()
00116 << address() << endl;
00117
00118 return 0;
00119 }
00120
00121
00122
00123 cout << HTTPResponseHeader(env.getServerProtocol(), 200 ,"OK")
00124 .addHeader("Content-Type", "text/html");
00125 cout << HTMLDoctype(HTMLDoctype::eStrict) << endl;
00126 cout << html().set("lang", "EN").set("dir", "LTR") << endl;
00127
00128
00129 cout << head() << endl;
00130 cout << title() << "GNU cgicc v" << cgi.getVersion() << title() << endl;
00131 cout << head() << endl;
00132
00133
00134 cout << body() << endl;
00135
00136
00137 cout << "Hello " << env.getRemoteUser()
00138 << " your login was accepted" << br() << endl;
00139 cout << "You were authenticated using authentication scheme : "
00140 << env.getAuthType() << br() << endl;
00141 cout << "Your server software is :" << serversw << br() << endl;
00142 cout << "Your browser software is :" << clientsw << br() << endl;
00143
00144 cout << body() << html();
00145
00146
00147 }
00148
00149 catch(const exception& e) {
00150
00151 }
00152
00153 return 0;
00154 }