#include <QCryptographicHash>
+/**Calculate a cryptographic HMAC (used by authentication algorithm)*/
class SMHmac
{
public:
return;
}
//open window
- MOverview *mo=new MOverview;
- mw->setParent(mo);
+ MOverview *mo=new MOverview(mw,profiles->itemData(profiles->currentIndex()).toString());
mo->show();
setEnabled(true);
--- /dev/null
+//
+// C++ Implementation: overview
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2007
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "overview.h"
+#include "webrequest.h"
+
+#include <QSettings>
+#include <QCoreApplication>
+
+MOverview::MOverview(MWebRequest*mw,QString pk)
+{
+ req=mw;
+ setAttribute(Qt::WA_DeleteOnClose);
+ setWindowTitle("MagicSmoke: "+QSettings().value("profiles/"+pk+"/name").toString());
+}
+
+void MOverview::closeEvent(QCloseEvent*ce)
+{
+ //make sure session is deleted
+ req->logout();
+ //actually close window
+ QMainWindow::closeEvent(ce);
+}
+
+MOverview::~MOverview()
+{
+ //free requestor
+ req->deleteLater();
+}
#include <QMainWindow>
+class MWebRequest;
+
+/**Main Overview Window*/
class MOverview:public QMainWindow
{
+ public:
+ /**construct the window with web-request/session handler and QSettings-key for current profile*/
+ MOverview(MWebRequest*,QString);
+ ~MOverview();
+ protected:
+ void closeEvent(QCloseEvent*);
+ private:
+ MWebRequest*req;
+ QString profilekey;
};
#endif
mainwindow.cpp \
hmac.cpp \
code39.cpp \
- webrequest.cpp
+ webrequest.cpp \
+ overview.cpp
HEADERS = \
keygen.h \
mainwindow.h \
hmac.h \
- webrequest.h
+ webrequest.h \
+ overview.h
TRANSLATIONS = \
smoke_de.ts \
return true;
}
+void MWebRequest::logout()
+{
+ request("closesession",QByteArray());
+}
+
QString MWebRequest::errorString()
{
return errstr;
#include <QHttp>
#include <QUrl>
+/**abstraction of requests to the web server, handles sessions and all data transfer*/
class MWebRequest:public QObject
{
Q_OBJECT
MWebRequest();
~MWebRequest();
- bool request(QString,QByteArray a=QByteArray());
+ /**generic request method, use the macro functions if possible; this function blocks until the request either succeeds, times out or fails; returns false if the request failed or timed out*/
+ bool request(QString requestName,QByteArray data=QByteArray());
+ /**returns the last error as string*/
QString errorString();
public slots:
+ /**set how long to wait for a web request*/
void setTimeout(int);
+ /**set URL to connect to*/
bool setUrl(QUrl);
+ /**set proxy to be used*/
void setProxy(QString,quint16,QString u=QString(),QString p=QString());
+ /**log in to web server; requires username/password and the local host name as arguments*/
bool login(QString user,QString passwd,QString hostname);
+ /**log out of web server*/
+ void logout();
private slots:
+ /**internal: used by wait loop for web requests*/
void httpFin(int,bool);
signals:
+ /**internal: used by wait loop for web request*/
void requestFinInt();
private:
{
global $ClientAuthAlgo;
switch($ClientAuthAlgo){
- case "md5":return mhash(MHASH_MD5,$cha.$tok);
- case "sha1":return mhash(MHASH_SHA1,$cha.$tok);
- case "sha256":return mhash(MHASH_SHA256,$cha.$tok);
- case "hmac-md5":return mhash(MHASH_MD5,$cha,$tok);
- case "hmac-sha1":return mhash(MHASH_SHA1,$cha,$tok);
- case "hmac-sha256":return mhash(MHASH_SHA256,$cha,$tok);
+ case "md5":return bin2hex(mhash(MHASH_MD5,$cha.$tok));
+ case "sha1":return bin2hex(mhash(MHASH_SHA1,$cha.$tok));
+ case "sha256":return bin2hex(mhash(MHASH_SHA256,$cha.$tok));
+ case "hmac-md5":return bin2hex(mhash(MHASH_MD5,$cha,$tok));
+ case "hmac-sha1":return bin2hex(mhash(MHASH_SHA1,$cha,$tok));
+ case "hmac-sha256":return bin2hex(mhash(MHASH_SHA256,$cha,$tok));
default:trigger_error("Internal error: unknown hash algorithm",E_USER_ERROR);
}
}
$ret.=$k."=";
//append value
if($dbScheme->isIntColumn($table,$k))
- $val.=$this->escapeInt($v);
+ $ret.=$this->escapeInt($v);
else
if($dbScheme->isStringColumn($table,$k))
- $val.=$this->escapeString($v);
+ $ret.=$this->escapeString($v);
else
//don't know how to escape it...
- $val.="NULL";
+ $ret.="NULL";
}
$ret.=" WHERE ".$where;
return $ret;
return $this->user!="";
}
+ protected function xdie($str)
+ {
+ //debug version:
+// print($str);
+ //all versions
+ exit();
+ }
+
public function authenticate()
{
global $db,$REQUESTDATA;
if(count($ures)<1){
header("X-MagicSmoke-Status: Unauthenticated");
deleteSession();
- die("No such user");
+ $this->xdie("No such user");
}
//get allowed hosts
$uhres=$db->select("userhosts","host","uname=".$db->escapeString($username));
if(count($hres)<1){
header("X-MagicSmoke-Status: Unauthenticated");
deleteSession();
- die("unknown host");
+ $this->xdie("unknown host");
}
}else{
//check whether allowed
//host name not in allowed list
header("X-MagicSmoke-Status: Unauthenticated");
deleteSession();
- die("host not allowed");
+ $this->xdie("host not allowed");
}
//check whether exists
if(count($hres)<1){
header("X-MagicSmoke-Status: Unauthenticated");
deleteSession();
- die("No such host");
+ $this->xdie("No such host");
}
}
//compare
if($ua!=$userauth){
header("X-MagicSmoke-Status: Unauthenticated");
deleteSession();
- die("Challenge failed $ua vs $userauth");
+ $this->xdie("user challenge failed");
}
if($needhostauth){
$ha=calcAuth($sres[0]["hchallenge"],$hres[0]["hostkey"]);
if($ha!=$hostauth){
header("X-MagicSmoke-Status: Unauthenticated");
deleteSession();
- die("challenge failed");
+ $this->xdie("host challenge failed");
}
}
//success