void ProviderService::OnCreate() { Var& rVar = m_mSessionStorage["id"]; rVar.tType.eType = DataType::Generic; rVar.sValue = GetSessionId(); m_pDataSource = &DataSourceFactory::Inst().GetDataSource(IService::GetServiceName()); const ProvidersInfoList& rlsProviders = m_pDataSource->GetProviders(); for (ProvidersInfoList::const_iterator itProvider = rlsProviders.begin(); itProvider != rlsProviders.end(); ++itProvider) { const xml::Element& rConfigElem = itProvider->tConfig; const xml::Element* pOnCreate = rConfigElem.FindChildElementByName("oncreate"); if (pOnCreate) { const xml::Element* pScript = pOnCreate->FindChildElementByName("script"); if (!pScript) { pScript = pOnCreate->FindChildElementByName("execute"); } if (pScript) { ScriptExecuter tScriptExecuter(*m_pDataSource, GetProviders()); tScriptExecuter.SetSessionStorage(m_mSessionStorage, m_tSessionStorageMutex); tScriptExecuter.Process(*pScript); } } } }
void Connection::onConnectCompleted(const asio::error_code& err) { UInt32 result = 1; if ( !err ) { result = 0; } EventRawConnected* e = new EventRawConnected; e->idx = GetUniqueId(); e->result = result; e->socketIndex = GetSessionId(); e->key = 0; m_net->Notify( EventPtr( e ) ); if ( !err ) { requestRecv(); } else { // 에러 날 경우 연결 종료도 통보함 onError( err ); } MU2LogSystem( 0, "Connection::Error> [Code: %d]", err.value()); }
void Connection::onError(const asio::error_code& err) { MU2LogSystem( 0, "Connection::onError> %s", err.message().c_str() ); EventDisconnected* e = new EventDisconnected; e->idx = GetUniqueId(); e->socketIndex = GetSessionId(); e->sessionType = 0; m_net->Notify( EventPtr( e ) ); }
bool ESP8266WebServerEx::VerifyCookie(const char* mime) { if ( !hasLogin || strcmp(mime,"text/html")!=0 ) return true; String session = GetSessionId(); long tag = -1; if ( session.length()==32 && g_Session.isValid(session,&tag) ) { if ( tag>0 && tag<10 ) { SetSessionId(session); return true; } } redirect("/"); return false; }
void ESP8266WebServerEx::handleLogin(const char* login, size_t loginLength, const char* homePath) { hasLogin = true; String session = GetSessionId(); long tag = -1; bool validSession = false; if ( session.length()==32 ) validSession = g_Session.isValid(session,&tag); // if everything is OK and user already logged in if ( validSession && tag>=0 && tag<10 ) { redirect(homePath); return; } // if user never login before, just display a form with challenge string long challenge = random(11,0x7fffffff); if ( !hasArg("userid") || !hasArg("hashpw") ) { challengeString = createChallengeString(challenge); SetSessionId(g_Session.Create(challenge)); sendEx(200, "text/html", login, loginLength, &loginForm); return; } // user already provided userId and password String userId = arg("userid"); String hashPw = arg("hashpw"); challengeString = createChallengeString(tag); if ( userId==adminUser ) { if ( checkPassword(adminUser,g_ModuleSettings.GetLoginPassword(true).c_str(),challengeString,hashPw) ) { g_Session.SetTag(session,ADMIN_USER_ID); redirect(homePath); return; } } else if ( userId==normalUser) { if ( checkPassword(normalUser,g_ModuleSettings.GetLoginPassword(false).c_str(),challengeString,hashPw) ) { g_Session.SetTag(session,USER_USER_ID); redirect(homePath); return; } } // show the login form with invalid userid/password here challengeString = createChallengeString(challenge); SetSessionId(g_Session.Create(challenge)); sendEx(200, "text/html", login, loginLength, &loginFormWithError); }
PROC_TYPE CProcessControl::GetProcType( __in BOOL bCurrentProc, __in ULONG ulPid ) { PROC_TYPE ProcType = PROC_TYPE_UNKNOWN; HANDLE hOutPut = INVALID_HANDLE_VALUE; int nSid = -1; __try { hOutPut = GetStdHandle(STD_OUTPUT_HANDLE); if (INVALID_HANDLE_VALUE == hOutPut) { printfPublic("GetStdHandle failed. (%d)", GetLastError()); __leave; } if (hOutPut) ProcType = PROC_TYPE_CONSOLE; else { ProcType = PROC_TYPE_NORMAL; if (!GetSessionId(TRUE, 0, &nSid)) { printfPublic("GetSessionId failed"); __leave; } if (0 == nSid) ProcType = PROC_TYPE_SERVICE; } } __finally { ; } return ProcType; }
void ESP8266WebServerEx::handleLogout() { String session = GetSessionId(); g_Session.Delete(session); redirect("/"); }
long ESP8266WebServerEx::GetTag() { String session = GetSessionId(); return g_Session.GetTag(session); }
void MediaKeySession::GetSessionId(nsString& aSessionId) const { aSessionId = GetSessionId(); }
void CHttpThread::Run() { //char content[1024]; char szSQL[2048]; char szFile[512]; char * svcname; char * urlargv[256]; int argc; unsigned long bindparalen[256]; char sql_in[2048]; int pos; int len; int start_time; int stat_id; int i; int iRet; char sessionid[64]; char errinfo[256]; int svcauthkey; //服务的authkey int authpassed; int loginauthkey; //login的authkey printf("Thread %d is starting...\n",m_id); m_pSvcData = new CServiceData; ConnStatusType pgstatus; char connstr[1024]; sprintf(connstr,"hostaddr=%s dbname=%s port=%d user=%s password=%s", m_dbip,m_dbname,m_dbport,m_dbuser,m_dbpass); m_pq=PQconnectdb(connstr); pgstatus=PQstatus(m_pq); if(pgstatus==CONNECTION_OK) { printf("Thread %d connect database success!\n",m_id); } else { printf("Thread %d connect database fail:%s\n",m_id,PQerrorMessage(m_pq)); return; } m_pSvcData->Load(m_pq); while(!m_bExitFlag) { //m_optval.l_onoff = 1; //m_optval.l_linger = 10; //setsockopt(m_sockfd,SOL_SOCKET,SO_LINGER, (char*)&m_optval,sizeof(m_optval)); m_sockfd=m_Reqque.getq(); printf("thread %d start to process job ...\n",m_id); if(m_sockfd==-1) { break; } //读http请求 iRet=ReadHttpReq(); if(iRet<0) { send(m_sockfd,szReplyBadReq,strlen(szReplyBadReq),0); goto next_flag; } //只处理GET和POST的请求 if(m_HttpHead.m_Method!=ENUM_GET && m_HttpHead.m_Method!=ENUM_POST) { send(m_sockfd,szReplyBadReq,strlen(szReplyBadReq),0); goto next_flag; } if(m_HttpHead.m_ContentLength<0) { printf("Content-length:%d can not less than zero!\n",m_HttpHead.m_ContentLength); send(m_sockfd,szReplyBadReq,strlen(szReplyBadReq),0); goto next_flag; } Url2FileName(m_HttpHead.m_Url,szFile); if(m_HttpHead.m_Method==ENUM_GET) { //是需要登陆验证的网页 if( strstr(szFile,m_session_dir)!=NULL && strcmp(szFile,m_loginhtml)!=0 && strcmp(szFile,m_reloginhtml)!=0) { authpassed=0; iRet=GetSessionId(m_HttpHead.m_Cookie,sessionid); if(iRet==0) //cookie中有session id { loginauthkey=m_session.UpdateSession(sessionid,m_session_timeouts); if(loginauthkey) { authpassed=1; } } } else { authpassed=1; } if(authpassed) { iRet=SendFileData(szFile); } else //没有验证通过,把relogin的html发过去 { iRet=SendFileData(m_reloginhtml); } if(iRet>0) { send(m_sockfd,szReplyBadReq,strlen(szReplyBadReq),0); } goto next_flag; } else //POST请求,都认为是服务请求 { iRet=ParseHttpPara(m_szHttpContent,argc,urlargv); if(iRet<0 || argc<1 ) { ReplyHttpReq("1\tPOST验证请求中的参数不正确!"); goto next_flag; } svcname=urlargv[0]; if(!strcmp(urlargv[0],"httpdbauth")) //登录 { loginauthkey=GetPassAuth(urlargv[1]); if(loginauthkey>0) //找到密码 { iRet=m_session.CreateSession(sessionid,loginauthkey,m_session_timeouts); ReplyHttpReq("0",sessionid); goto next_flag; } else { //密码错误 ReplyHttpReq("1"); goto next_flag; } } authpassed=0; svcauthkey=m_pSvcData->GetSvcAuthKey(svcname); if(svcauthkey ==0 )//为0,不需要验证 { authpassed=1; } else { iRet=GetSessionId(m_HttpHead.m_Cookie,sessionid); if(iRet==0) //获得了sessionid { loginauthkey=m_session.UpdateSession(sessionid,m_session_timeouts); if(svcauthkey & loginauthkey) { authpassed=1; } else { if(loginauthkey) { ReplyHttpReq("1\t没有权限做此操作,请与管理员联系!"); goto next_flag; } } } } if(! authpassed) //没有验证通过 { ReplyHttpReq("9\t没有登陆,或登陆超时,请重新登陆!"); } else { CallService(argc,urlargv); } goto next_flag; } next_flag: shutdown(m_sockfd,SHUT_RDWR); close(m_sockfd); printf("thread %d wait job ...\n",m_id); //pthread_cond_wait(&m_cond,&m_mutex); //等待任务 } //pthread_mutex_unlock(&m_mutex); PQfinish(m_pq); printf("Thread %d is stop.\n",m_id); }