Esempio n. 1
0
int do_login(void * ppage, char * pname, int type)
{
	char *				puser = getCookie("username");
	char *				pid   = getCookie("session_id");
	BROADBAND_ROUTER 	bbr[1];
	char				errmsg[256] = "";
	char *				language = getCookie("lang");

	load_bbr(bbr, errmsg);

	/* chage default language */
	if (!strcmp("ch", language))
		defLangSet(LANG_CH);
	else if (!strcmp("en", language))
		defLangSet(LANG_EN);
	else if (!strcmp("jp", language))
		defLangSet(LANG_JP);

	/* have been login */
	if (!isblankstr(puser) && !isblankstr(pid) &&
		!strcmp(puser, bbr->account.user) && 
		!strcmp(pid, bbr->account.session_id))			
		return FALSE;

	/* just login.csp */
	if (!strcmp(pname, "/login.csp"))
		return FALSE;

	/* redirect to login.csp */
	forward("/login.csp", TRUE);
	return FALSE;
	
	return TRUE;
}	
void CookiesContentsWidget::removeCookies()
{
	const QModelIndexList indexes = m_ui->cookiesView->selectionModel()->selectedIndexes();

	if (indexes.isEmpty())
	{
		return;
	}

	QNetworkCookieJar *cookieJar = NetworkManagerFactory::getCookieJar();
	QList<QNetworkCookie> cookies;

	for (int i = 0; i < indexes.count(); ++i)
	{
		if (!indexes.at(i).isValid())
		{
			continue;
		}

		if (indexes.at(i).data(Qt::UserRole).toString().isEmpty())
		{
			QStandardItem *domainItem = m_model->itemFromIndex(indexes.at(i));

			if (!domainItem)
			{
				continue;
			}

			for (int j = 0; j < domainItem->rowCount(); ++j)
			{
				QStandardItem *cookieItem = domainItem->child(j, 0);

				if (cookieItem)
				{
					cookies.append(getCookie((cookieItem->index())));
				}
			}
		}
		else
		{
			QStandardItem *cookieItem = m_model->itemFromIndex(indexes.at(i));

			if (cookieItem)
			{
				cookies.append(getCookie(cookieItem->index()));
			}
		}
	}

	for (int i = 0; i < cookies.count(); ++i)
	{
		cookieJar->deleteCookie(cookies.at(i));
	}
}
Esempio n. 3
0
 /// Returns a dbo::ptr to the currently logged in user *
 dbo::ptr<User> user() {
     if (_userCache) {
         if (time(NULL) - _cacheTime > _userSessionStore.getTimeout())
             _userCache.reset();
         else
             return _userCache;
     }
     // Check the session thing live .. this will possibly slow things down by locking if another thread is writing
     // but on the plus side it means if one thread los out .. all threads log out
     string cookie = getCookie();
     if (!cookie.empty()) {
         unsigned int userId;
         try {
             userId = _userSessionStore.userId(cookie);
         } catch (invalid_argument e) {
             // If they have an old session cookie, but they're not logged in now .. delete the old cookie
             WApplication::instance()->setCookie(_cookieName, cookie, 0, "", "/", true);
             cookieCache = "";
             return dbo::ptr<User>(); // Empty pointer
         }
         touchSession();
         // Cache and return the result
         dbo::Transaction t(_dbSession);
         _userCache = _dbSession.find<User>().where("id = ?").bind((int)userId);
         _cacheTime = time(NULL); // (now)
         t.commit();
         return _userCache;
     } else {
         return dbo::ptr<User>(); // Empty pointer
     }
 }
void Settings::setCookie(QString value)
{
    if (getCookie() != value) {
        settings.setValue("cookie", value);
        emit cookieChanged();
    }
}
Esempio n. 5
0
    CompareResult compareTo(const State& arg) const
    {
        LOG4CPLUS_TRACE_METHOD(Logger::getInstance("samples.state"), __PRETTY_FUNCTION__);
        if (getCookie() == arg.getCookie())
        {
            LOG4CPLUS_INFO(Logger::getInstance("samples.state"), "EQUAL!");
            return EQUAL;
        }

        if(getCookie() > arg.getCookie()) 
        {
            LOG4CPLUS_INFO(Logger::getInstance("samples.state"), "GREATER!");
            return GREATER;
        }

        LOG4CPLUS_INFO(Logger::getInstance("samples.state"), "LESS!");
        return LESS;
    }
void CookiesContentsWidget::removeDomainCookies()
{
	const QModelIndexList indexes = m_ui->cookiesView->selectionModel()->selectedIndexes();

	if (indexes.isEmpty())
	{
		return;
	}

	QNetworkCookieJar *cookieJar = NetworkManagerFactory::getCookieJar();
	QList<QNetworkCookie> cookies;

	for (int i = 0; i < indexes.count(); ++i)
	{
		QStandardItem *domainItem = ((indexes.at(i).isValid() && indexes.at(i).parent() == m_model->invisibleRootItem()->index()) ? findDomain(indexes.at(i).sibling(indexes.at(i).row(), 0).data(Qt::ToolTipRole).toString()) : m_model->itemFromIndex(indexes.at(i).parent()));

		if (domainItem)
		{
			for (int j = 0; j < domainItem->rowCount(); ++j)
			{
				QStandardItem *cookieItem = domainItem->child(j, 0);

				if (cookieItem)
				{
					const QNetworkCookie cookie = getCookie(cookieItem->index());

					if (!cookies.contains(cookie))
					{
						cookies.append(cookie);
					}
				}
			}
		}
	}

	if (cookies.isEmpty())
	{
		return;
	}

	QMessageBox messageBox;
	messageBox.setWindowTitle(tr("Question"));
	messageBox.setText(tr("You are about to delete %n cookies.", "", cookies.count()));
	messageBox.setInformativeText(tr("Do you want to continue?"));
	messageBox.setIcon(QMessageBox::Question);
	messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
	messageBox.setDefaultButton(QMessageBox::Yes);

	if (messageBox.exec() == QMessageBox::Yes)
	{
		for (int i = 0; i < cookies.count(); ++i)
		{
			cookieJar->deleteCookie(cookies.at(i));
		}
	}
}
Esempio n. 7
0
int main()
{
    Jar j;
    Cookie *c = getCookie(j);
    Jar j2;
    if (c != NULL)
    {
        putCookie(j2,*c);
    }
    return 0;
}
Esempio n. 8
0
 SessionHandle(WObject* parent, dbo::Session& dbSession, const string& cookieName) :
     BaseSessionHandle(parent, cookieName), _userSessionStore(SessionStore::getInstance()), _dbSession(dbSession), _cacheTime(time(NULL))
 {
     // Check if we're already logged in
     const string& cookie = getCookie();
     if (!cookie.empty()) {
         int userId;
         try {
             userId = _userSessionStore.userId(getCookie(), true); // Touch the session as new app/view is openning for it
         } catch (invalid_argument e) {
             // Nobody's logged in right now
             _userCache.reset();
             return;
         }
         // Remember our user object
         dbo::Transaction transaction(_dbSession);
         _userCache = _dbSession.find<User>().where("id = ?").bind((int)userId);
         transaction.commit();
     }
 }
Esempio n. 9
0
t_bool			destroySession(t_request *clientRequest, char*cookieName, char*cookieUser)
{
  t_projects		project;
  t_parameters		*cookieJar;
  t_list		*list;
  char			*sessionID;
  char			*username;
  char			request[1024];

  project = clientRequest->_project;
  cookieJar = clientRequest->_cookieJar;

  printf("\tDeleting existing Session :\n");
  if (!(sessionID = getCookie(clientRequest, cookieName)))
    return FALSE;
  if (!(username = getCookie(clientRequest, cookieUser)))
    return FALSE;
  
  printf("\t\tCookie found '%s' = '%s'\n", cookieName, sessionID);
  printf("\t\tCookie found '%s' = '%s'\n", cookieUser, username);

  setDatabase("dumbo");
  snprintf(request, 1024,
	   "DELETE FROM sessions WHERE "\
	   "username='******' AND project='%d' AND sessionID='%s'; SELECT ROW_COUNT()",
	   username, clientRequest->_project, sessionID);
  setScript(request);
  printf("\t\tGoing delete existing session :\n");
  if ((list = execRequest()))
    {
      list = list->next;
      if (list->content && strncmp(list->content, "0", 1))
	{
	  printf("\tSession Found and deleted.\n");
	  return TRUE;
	}
      destroyList(list, TRUE);
    }
  printf("\tSession NOT Found. No Deletion\n");
  return FALSE;
}
Esempio n. 10
0
static t_list		*addProductToCart(t_list *list, t_socket *client, char *id, char *amount)
{
  char			*old;
  char			*buffer;
  size_t		len;
  size_t		offset;
  char			*declinaison;

  if (!id || !*id || !amount || !*amount)
    return NULL;

  len = strlen(id) + 1 + strlen(amount);

  if (old = getCookie(client->request, CART_COOKIE))
    len += (strlen(old) + 1);

  if ((declinaison = getParameter(client, "colorSelect")))
    len += (strlen(declinaison) + 1);

  if (!(buffer = malloc(len + 1)))
    {
      perror("malloc");
      exit(FAILURE);
    }

  *buffer = '\0';
  offset = 0;
  if (old && *old)
    {
      if (old[strlen(old) - 1] == ' ' || old[strlen(old) - 1] == '\t')
	old[strlen(old) - 1] = '\0';
      snprintf(buffer + offset, strlen(old) + 1 + 1, "%s%c", old, CART_SEPARATOR);
      offset += (strlen(old) + 1);
      printf("1 - Buffer : '%s'\n", buffer);
    }

  snprintf(buffer + offset, strlen(id) + strlen(amount) + 1 + 1, "%s:%s", id, amount);
  offset += (strlen(id) + strlen(amount) + 1);
  printf("2 - Buffer : '%s'\n", buffer);

  if (declinaison && *declinaison)
    {
      snprintf(buffer + offset, strlen(declinaison) + 1 + 1, ":%s", declinaison);
      offset += (strlen(declinaison) + 1);
      printf("3 - Buffer : '%s'\n", buffer);
    }

  buffer[len] = '\0';
  addCookie(client, CART_COOKIE, buffer);
  list = addToList(list, "<b>Article ajouté au panier</b>\n");
  return list;
}
Esempio n. 11
0
t_bool			checkForExistingSession(t_request *clientRequest, char*cookieName, char*cookieUser)
{
  t_projects		project;
  t_parameters		*cookieJar;
  t_list		*list;
  char			*sessionID;
  char			*username;
  char			request[1024];

  project = clientRequest->_project;
  cookieJar = clientRequest->_cookieJar;

  printf("\tChecking for existing Session :\n");
  if (!(sessionID = getCookie(clientRequest, cookieName)))
    return FALSE;
  if (!(username = getCookie(clientRequest, cookieUser)))
    return FALSE;
  
  printf("\t\tCookie found '%s' = '%s'\n", cookieName, sessionID);
  printf("\t\tCookie found '%s' = '%s'\n", cookieUser, username);

  setDatabase("dumbo");
  snprintf(request, 1024,
	   "SELECT sessionID FROM sessions WHERE "\
	   "username='******' AND project='%d' AND sessionID='%s';",
	   username, clientRequest->_project, sessionID);
  setScript(request);
  printf("\t\tGoing to check into database for session :\n");
  if ((list = execRequest()))
    {
      destroyList(list, TRUE);
      printf("\tSession Found.\n");
      return TRUE;
    }
  printf("\tSession NOT Found.\n");
  return FALSE;
}
Esempio n. 12
0
void ServerSktUdp::newData()
{
	QUdpSocket* s = qobject_cast<QUdpSocket*>(sender());
	if (!s) return;

	qint64 bufLen = s->pendingDatagramSize();
	char* buf = TK::createBuffer(bufLen, MAXBUFFER);
	if (!buf) return;

	QHostAddress addr; quint16 port(0);

	qint64 readLen = 0;
	qint64 ioLen = s->readDatagram(buf, bufLen, &addr, &port);

	//while (ioLen > 0)
	//{
		readLen += ioLen;
	//	ioLen = s->readDatagram(buf+readLen, bufLen-readLen, &addr, &port);
	//}

	if (ioLen >= 0)
	{
		Conn* conn = (Conn*)getCookie(TK::ipstr(addr, port, false));
		if (!conn)
		{
			conn = new Conn;
			if (conn)
			{
				conn->key  = TK::ipstr(addr, port, false);
				conn->addr = addr;
				conn->port = port;
				setCookie(conn->key, conn);
			}
		}

		if (conn)
		{
			recordRecv(readLen);

			conn->stamp = QDateTime::currentDateTime();
			dump(buf, readLen, false, conn->key);
		}
	}

	TK::releaseBuffer(buf);
}
Esempio n. 13
0
bool ConsoleCmd::command(const QByteArray &dest, const ClientCmd &cmd)
{
  Q_UNUSED(dest)

  const QString command = cmd.command().toLower();
  if (command == LS("console")) {
    m_plugin->show();
  }
  else if (command == LS("cookie")) {
    if (isTalk(dest, command) && isOnline())
      getCookie(dest);
  }
  else
    return false;

  return true;
}
Esempio n. 14
0
void ServerSktUdp::check()
{
	QStringList list;
	getKeys(list);

	while (!list.isEmpty())
	{
		QString k = list.takeFirst();

		void* c = getCookie(k);

		if (c && (((Conn*)c)->stamp.addSecs(120) < QDateTime::currentDateTime()))
		{
			close(c);
			unsetCookie(k);
		}
	}
}
Esempio n. 15
0
// is this a temporary filter bypass cookie?
bool HTTPHeader::isBypassCookie(String url, const char *magic, const char *clientip)
{
	String cookie(getCookie("GBYPASS"));
	if (!cookie.length()) {
#ifdef DGDEBUG
		std::cout << "No bypass cookie" << std::endl;
#endif
		return false;
	}
	String cookiehash(cookie.subString(0, 32));
	String cookietime(cookie.after(cookiehash.toCharArray()));
	String mymagic(magic);
	mymagic += clientip;
	mymagic += cookietime;
	bool matched = false;
	while(url.contains(".")) {
		String hashed(url.md5(mymagic.toCharArray()));
		if (hashed == cookiehash) {
			matched = true;
			break;
		}
		url = url.after(".");
	}
	if (not matched) {
#ifdef DGDEBUG
		std::cout << "Cookie GBYPASS not match" << std::endl;
#endif
		return false;
	}
	time_t timen = time(NULL);
	time_t timeu = cookietime.toLong();
	if (timeu < timen) {
#ifdef DGDEBUG
		std::cout << "Cookie GBYPASS expired: " << timeu << " " << timen << std::endl;
#endif
		return false;
	}
	return true;
}
Esempio n. 16
0
int verify163Music(const struct redirect_conf *pstRedirectConf, char *url, char *ip, char *other)
{
	char *p_cookie;
	//case3544:
	ST_163MUSIC_CFG* pstC = pstRedirectConf->other;
    char *uri = NULL;
	assert(pstC != NULL);
/*
	//case3544
	p_range = strstr(other,"Range:");
	if(p_range)
		goto fail403;
*/
	if(!getUri(url,&uri))
		goto fail301;

	DEBUG("uri = %s\n",uri);

	int len = getCookie(other,&p_cookie);
	if (0 == len)
	{
		DEBUG("no cookie,goto fail\n");
		goto fail301;
		
	}
	int deny_or_not = 1;
	int i = 0 ;
//	char *uri = strchr(strstr(url,"http://")+7,'/')+1;

	char *cookie = (char *)malloc(len);
	memset(cookie,0,len);
	if(NULL == cookie)
	{
		goto fail301;
	}
	else
	{
		memcpy(cookie,p_cookie,len-1);
    }

	DEBUG("cookie [%s],len[%d]\n",cookie,len);


	for(i=0 ; i < pstC->cookie_count;i++)
	{
	//	if(0 == strcmp(cookie,pstC->cookie_value[i]))
    	if(strstr(cookie,pstC->cookie_value[i]))
		{
			deny_or_not = 0;
			break;
		}
	}

	if(cookie)
	{
		free(cookie);
		cookie = NULL;
	}

	DEBUG("deny or not [%d],replace_url[%s],uri[%s]\n", deny_or_not,pstC->replace_url,uri);

	if(!deny_or_not)
	{
		printf("%s %s %s", url, ip, other);
		DEBUG("OUTPUT: %s %s %s", url, ip, other);
		fflush(stdout);
	}
	else
	{
		printf("301:%s?r=%s %s %s", pstC->replace_url ,uri,ip, other);
		DEBUG("VERIFY FAILED OUTPUT:301:%s?r=%s %s %s", pstC->replace_url, uri, ip, other);
		fflush(stdout);
	}
	return 1;

fail301:
	if(NULL == uri)
	{
		printf("301:%s?r= %s %s", pstC->replace_url ,ip, other);
		DEBUG("VERIFY failed output:301:%s %s %s", pstC->replace_url, ip, other);
	}
	else
	{
		printf("301:%s?r=%s %s %s", pstC->replace_url ,uri,ip, other);
		DEBUG("VERIFY failed output:301:%s?r=%s %s %s", pstC->replace_url,uri, ip, other);
	}
	fflush(stdout);
	return 0;
/*
fail403:
	printf("403:%s %s %s", url, ip, other);
	DEBUG("OUTPUT:403: %s %s %s", url, ip, other);
	fflush(stdout);
	return 0;
*/
}
Esempio n. 17
0
const char *request_cookieName(int i)
{
    Form cookie = getCookie(i);
    if (cookie != NULL) return Form_get(cookie, "NAME");
    else return NULL;
}
Esempio n. 18
0
const char *request_cookieValue(int i)
{
    Form cookie = getCookie(i);
    if (cookie != NULL) return Form_get(cookie, "VALUE");
    else return NULL;
}
Esempio n. 19
0
bool SVT_Fcml::init(const QString &usr, const QString &pwd, int *retErrorIdx, QString *retErrorStr)
{
    endAllSessions();

    if(retErrorIdx)
    {
        *retErrorIdx=0;
    }
    if(retErrorStr)
    {
        *retErrorStr="";
    }
//    mMutex.lock();
//    mSavedAuth.clear();
//    mMutex.unlock();
    //step1 authenticate
    const char *cHead="POST /fcp/authenticate HTTP/1.1\r\n"
                      "Accept-Encoding: identity\r\n"
                      "Content-Length: %1\r\n"
                      "Host: %2\r\n"
                      "Content-Type: application/x-www-form-urlencoded\r\n"
                      "Connection: close\r\n";


    const char *cMode="<authenticate type=\"basic\""
    " username=\"%1\" password=\"%2\"/>";


    QString body=QString(cMode).arg(usr,pwd);
    QString head=QString(cHead).arg(body.size()).arg(mLinkUrl);

    SVT_Https http(mExitFlag);
    const QByteArray & array=http.rawRequest(mLinkUrl
                         ,head+"\r\n"+body);
    getCookie(array,mCookie);
    QDomDocument doc;
    QByteArray abody=SVT_Https::getBody(array);
    doc.setContent(abody,true);
    QDomNode rnode = doc.firstChild();
    if (!rnode.isElement())
        rnode = rnode.nextSibling();
    QDomElement elem = rnode.toElement();
//    qDebug()<<elem.tagName()<<elem.attribute("authenticated");
    if(0==elem.tagName().compare("authenticate"))
    {
        if(0!=elem.attribute("authenticated").compare("true",Qt::CaseInsensitive))
        {
            if(retErrorIdx)
            {
                *retErrorIdx=FE_LOGIN_WRONG_PWD;
            }
            if(retErrorStr)
            {
                *retErrorStr=elem.attribute("description");
            }
            return false;
        }
    }
    else
    {
        if(retErrorIdx)
        {
            *retErrorIdx=FE_INITPROCESS;
        }
        return false;
    }
    //step2 init


    QString sHead1="POST /fcp/init HTTP/1.1\r\n"
                 "Accept-Encoding: identity\r\n"
                 "Content-Length: %1\r\n"
                 "Host: %2\r\n"
                 "Connection: close\r\n"
                 "Content-Type: application/x-www-form-urlencoded\r\n";
    QString sBody1="<init type=\"ui\" fcmb=\"true\"/>";

    sHead1=sHead1.arg(sBody1.size()).arg(mLinkUrl);
    const QByteArray &array1=http.rawRequest(mLinkUrl
                ,appendCookie(sHead1)+"\r\n"+sBody1);
    QByteArray abody1=SVT_Https::getBody(array1);
    QDomDocument doc1;
    doc1.setContent(abody1,true);
    rnode = doc1.firstChild();
    if (!rnode.isElement())
        rnode = rnode.nextSibling();
    elem = rnode.toElement();
//    qDebug()<<elem.tagName()<<elem.hasAttribute("domain")<<elem.hasAttribute("name");
    if ( (0!=elem.tagName().compare("init"))
         ||!elem.hasAttribute("domain")
         ||!elem.hasAttribute("name")
         )
    {
        if(retErrorIdx)
        {
            *retErrorIdx=FE_INITPROCESS;
        }
        return false;
    }
    mDomain=elem.attribute("domain");
    mName=elem.attribute("name");
    return true;

}
Esempio n. 20
0
 /// Logs the user out of all _userSessionStore eventually; this session immediately. 
 void logout() {
     _userCache.reset();
     _userSessionStore.logout(getCookie());
 }
Esempio n. 21
0
 /// Does the actual touching of the session store user session
 void doTouchSession() { _userSessionStore.touch(getCookie()); }