logon.cpp

00001 /*********************************************************************** 00002 * * 00003 * ViTooKi * 00004 * * 00005 * title: Logon.cpp * 00006 * * 00007 * * 00008 * * 00009 * ITEC institute of the University of Klagenfurt (Austria) * 00010 * http://www.itec.uni-klu.ac.at * 00011 * * 00012 * * 00013 * For more information visit the ViTooKi homepage: * 00014 * http://ViTooKi.sourceforge.net * 00015 * vitooki-user@lists.sourceforge.net * 00016 * vitooki-devel@lists.sourceforge.net * 00017 * * 00018 * This file is part of ViTooKi, a free video toolkit. * 00019 * ViTooKi is free software; you can redistribute it and/or * 00020 * modify it under the terms of the GNU General Public License * 00021 * as published by the Free Software Foundation; either version 2 * 00022 * of the License, or (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the Free Software * 00031 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * 00032 * MA 02111-1307, USA. * 00033 * * 00034 ***********************************************************************/ 00035 00036 /*********************************************************************** 00037 * * 00038 * REVISION HISTORY: * 00039 * * 00040 * * 00041 * * 00042 ***********************************************************************/ 00043 00044 /*********************************************************************** 00045 * Video Session Migration System, 2004 * 00046 * Author: Klaus Schoeffmann * 00047 ************************************************************************/ 00048 00049 00050 #include "logon.hpp" 00051 00052 00053 /***********************************************************************/ 00054 int main (void) 00055 { 00056 //read all users into memory 00057 UserList *ul = new UserList(); 00058 ul->readUsersFromFile(Globals::getConfigFilePath()); 00059 00060 //read all profiles from file 00061 //(and add each profile to the corresponding user) 00062 ProfileList *profl = new ProfileList(); 00063 profl->readProfilesFromFile(Globals::getConfigFilePath(), ul); 00064 00065 //read form data 00066 string formdata; 00067 cin >> formdata; 00068 CGIParser *cgiparser = new CGIParser(formdata); 00069 uint userId = atoi(cgiparser->getFieldValue("userid").c_str()); 00070 uint profileId = atoi(cgiparser->getFieldValue("proid").c_str()); 00071 char *pass = semifunc::newStrCpy((char*)cgiparser->getFieldValue("password").c_str()); 00072 uint linktype = atoi(cgiparser->getFieldValue("linktype").c_str()); 00073 uint pageSize = atoi(cgiparser->getFieldValue("pagesize").c_str()); 00074 if (pageSize == 0) pageSize = 1; 00075 bool showActiveSessions = true, showClosedSessions = false; 00076 if (cgiparser->getFieldValue("showAS") != "on") showActiveSessions = false; 00077 if (cgiparser->getFieldValue("showCS") == "on") showClosedSessions = true; 00078 bool fakeRtspServer = false; 00079 if (cgiparser->getFieldValue("proxysupported") != "on") fakeRtspServer = true; 00080 00081 //output HTML header and the SeMi menu 00082 cout << html::getHTMLHeader(); 00083 cout << html::getMenu("logon.cgi", pageSize); 00084 html::createPageSizeForm(cgiparser->createOpenForm("frmPageSize", "logon.cgi", "post", ""), pageSize); 00085 00086 //username, profile and password must be specified! 00087 if (userId == 0 || profileId == 0 || pass == NULL || strcmp(pass,"") == 0) 00088 { 00089 cout << html::error("You must specify username, profile and password!"); 00090 exit(1); 00091 } 00092 00093 //check if user exists 00094 User *u = ul->getUserById(userId); 00095 if (u == NULL) 00096 { 00097 cout << html::error("User was not found!") << endl; 00098 exit(1); 00099 } 00100 00101 //check password 00102 if (strcmp(u->getPassword(), pass) != 0) 00103 { 00104 cout << html::error("Wrong password!") << endl; 00105 exit(1); 00106 } 00107 else 00108 { 00109 00110 // cout << "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" << endl; 00111 // cout << "<tr><td width=\"50%\" align=\"center\">"; 00112 00113 00114 //************generate selectbox for profile...************ 00115 cout << "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" << endl; 00116 cout << "<tr><td valign=\"top\">Profile:</td>" << endl; 00117 cout << "<td>"; 00118 cout << cgiparser->createOpenForm("frmProfSel", "logon.cgi", "post", "proid"); 00119 cout << "<select size=\"1\" id=\"proid\"" 00120 << " name=\"proid\" class=\"darkblueborder\"" 00121 << " onChange=\"document.forms['frmProfSel'].submit();\">" << endl; 00122 //output all profiles for chosen user 00123 vector<Profile*> profiles = ul->getUserById(userId)->getProfiles(); 00124 vector<Profile*>::const_iterator piter = profiles.begin(); 00125 for (;piter != profiles.end(); piter++) 00126 { 00127 Profile *profile = *piter; 00128 cout << "<option "; 00129 if (profile->getProfileId() == profileId) cout << " selected "; 00130 cout << " value=\"" << profile->getProfileId() << "\">"; 00131 cout << profile->getProfileName(); 00132 cout << "</option>" << endl; 00133 } 00134 cout << "</select></form></td></tr>"; 00135 00136 00137 //************generate selectbox for link-type selection************ 00138 cout << "<tr><td valign=\"top\">Links as:</td>" << endl; 00139 cout << "<td>"; 00140 cout << cgiparser->createOpenForm("frmLinktypeSel", "logon.cgi", "post", "linktype"); 00141 cout << "<select name=\"linktype\" size=\"1\"" 00142 << " onChange=\"document.forms['frmLinktypeSel'].submit();\">" << endl; 00143 00144 cout << "<option "; 00145 if (linktype == LINK_RTSP) cout << " selected "; 00146 cout << "value=\"" << LINK_RTSP << "\">RTSP-URIs</option>" << endl; 00147 00148 cout << "<option "; 00149 if (linktype == LINK_QTE) cout << " selected "; 00150 cout << "value=\"" << LINK_QTE << "\">Embedded QT</option>" << endl; 00151 00152 cout << "<option "; 00153 if (linktype == LINK_SDP) cout << " selected "; 00154 cout << "value=\"" << LINK_SDP << "\">SDP files</option>" << endl; 00155 00156 cout << "</select>" << endl; 00157 cout << "</form>" << endl; 00158 00159 cout << "</td></tr></table>"; 00160 00161 00162 00163 //************read movies************ 00164 MovieList *ml = new MovieList(profl->getProfileById(profileId)); 00165 cout << "<!-- reading movies from " << Globals::getMoviesFileName() << " -->" << endl; 00166 ml->readMoviesFromFile( Globals::getMoviesFileName() ); 00167 00168 00169 //************read active sessions************ 00170 SessionList *sl = new SessionList(Globals::getProxyComHost(), 00171 Globals::getProxyComPort(), profl->getProfileById(profileId)); 00172 sl->retrieveSessions(); 00173 00174 00175 //************generate a list of active session and all videos************ 00176 cout << "<table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\">" << endl; 00177 cout << "<tr><td colspan=\"2\" align=\"center\"" << ml->getDescription() << "</td></tr>" << endl; 00178 00179 //list all active sessions 00180 sl->writeHTMLRepresentation(cgiparser, showActiveSessions, showClosedSessions, fakeRtspServer); 00181 //list all available movies 00182 cout << ml->getHTMLRepresentation(Globals::getRelativeImagesFilePath(), cgiparser, fakeRtspServer); 00183 00184 cout << "</table>\n"; 00185 } 00186 00187 cout << html::getHTMLFooter(cgiparser->createRefreshForm("logon.cgi", "post")); 00188 00189 delete cgiparser; 00190 delete ul; 00191 delete profl; 00192 return 0; 00193 }