#############################################################################
# Makefile for building: bat
-# Generated by qmake (2.01a) (Qt 4.2.1) on: Sun Jan 28 22:55:01 2007
+# Generated by qmake (2.01a) (Qt 4.2.1) on: Mon Jan 29 10:12:52 2007
# Project: bat.pro
# Template: app
# Command: /usr/bin/qmake -unix -o Makefile bat.pro
####### Files
SOURCES = main.cpp \
- authenticate.cpp \
bat_conf.cpp \
mainwin.cpp \
+ console/authenticate.cpp \
console/console.cpp moc_mainwin.cpp \
moc_console.cpp \
qrc_main.cpp
OBJECTS = main.o \
- authenticate.o \
bat_conf.o \
mainwin.o \
+ authenticate.o \
console.o \
moc_mainwin.o \
moc_console.o \
dist:
@$(CHK_DIR_EXISTS) .tmp/bat1.0.0 || $(MKDIR) .tmp/bat1.0.0
- $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/bat1.0.0/ && $(COPY_FILE) --parents mainwin.h bat.h bat_conf.h console/console.h .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.qrc .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.cpp authenticate.cpp bat_conf.cpp mainwin.cpp console/console.cpp .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.ui .tmp/bat1.0.0/ && (cd `dirname .tmp/bat1.0.0` && $(TAR) bat1.0.0.tar bat1.0.0 && $(COMPRESS) bat1.0.0.tar) && $(MOVE) `dirname .tmp/bat1.0.0`/bat1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/bat1.0.0
+ $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/bat1.0.0/ && $(COPY_FILE) --parents mainwin.h bat.h bat_conf.h console/console.h .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.qrc .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.cpp bat_conf.cpp mainwin.cpp console/authenticate.cpp console/console.cpp .tmp/bat1.0.0/ && $(COPY_FILE) --parents main.ui .tmp/bat1.0.0/ && (cd `dirname .tmp/bat1.0.0` && $(TAR) bat1.0.0.tar bat1.0.0 && $(COMPRESS) bat1.0.0.tar) && $(MOVE) `dirname .tmp/bat1.0.0`/bat1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/bat1.0.0
yaccclean:
bat_conf.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
-authenticate.o: authenticate.cpp bat.h \
- mainwin.h \
- ui_main.h \
- bat_conf.h
- $(CXX) -c $(CXXFLAGS) $(INCPATH) -o authenticate.o authenticate.cpp
-
bat_conf.o: bat_conf.cpp bat_conf.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o bat_conf.o bat_conf.cpp
bat_conf.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwin.o mainwin.cpp
+authenticate.o: console/authenticate.cpp bat.h \
+ mainwin.h \
+ ui_main.h \
+ bat_conf.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o authenticate.o console/authenticate.cpp
+
console.o: console/console.cpp bat.h \
mainwin.h \
ui_main.h \
LIBS += -lssl -lcrypto
RESOURCES = main.qrc
-# Input
+# Main directory
FORMS += main.ui
-HEADERS += mainwin.h bat.h bat_conf.h console/console.h
-SOURCES += main.cpp authenticate.cpp bat_conf.cpp
-SOURCES += mainwin.cpp console/console.cpp
+HEADERS += mainwin.h bat.h bat_conf.h
+SOURCES += main.cpp bat_conf.cpp mainwin.cpp
+
+# Console
+HEADERS += console/console.h
+SOURCES += console/authenticate.cpp console/console.cpp
--- /dev/null
+/*
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 2001-2007 Free Software Foundation Europe e.V.
+
+ The main author of Bacula is Kern Sibbald, with contributions from
+ many others, a complete list can be found in the file AUTHORS.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation plus additions
+ that are listed in the file LICENSE.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of John Walker.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
+
+/*
+ *
+ * Bacula UA authentication. Provides authentication with
+ * the Director.
+ *
+ * Kern Sibbald, June MMI adapted to bat, Jan MMVI
+ *
+ * Version $Id$
+ *
+ */
+
+
+#include "bat.h"
+
+
+/* Commands sent to Director */
+static char hello[] = "Hello %s calling\n";
+
+/* Response from Director */
+static char OKhello[] = "1000 OK:";
+
+/* Forward referenced functions */
+
+/*
+ * Authenticate Director
+ */
+bool Console::authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
+{
+ BSOCK *dir = jcr->dir_bsock;
+ int tls_local_need = BNET_TLS_NONE;
+ int tls_remote_need = BNET_TLS_NONE;
+ int compatible = true;
+ char bashed_name[MAX_NAME_LENGTH];
+ char *password;
+
+ /*
+ * Send my name to the Director then do authentication
+ */
+ if (cons) {
+ bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
+ bash_spaces(bashed_name);
+ password = cons->password;
+ } else {
+ bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
+ password = director->password;
+ }
+ /* Timeout Hello after 5 mins */
+ btimer_t *tid = start_bsock_timer(dir, 60 * 5);
+ bnet_fsend(dir, hello, bashed_name);
+
+ /* respond to Dir challenge */
+ if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) ||
+ /* Now challenge dir */
+ !cram_md5_challenge(dir, password, tls_local_need, compatible)) {
+ stop_bsock_timer(tid);
+ printf(_("%s: Director authorization problem.\n"), my_name);
+ set_text(_("Director authorization problem.\n"));
+ set_text(_(
+ "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"));
+ return false;
+ }
+
+ Dmsg1(6, ">dird: %s", dir->msg);
+ if (bnet_recv(dir) <= 0) {
+ stop_bsock_timer(tid);
+ set_textf(_("Bad response to Hello command: ERR=%s\n"),
+ bnet_strerror(dir));
+ printf(_("%s: Bad response to Hello command: ERR=%s\n"),
+ my_name, bnet_strerror(dir));
+ set_text(_("The Director is probably not running.\n"));
+ return false;
+ }
+ stop_bsock_timer(tid);
+ Dmsg1(10, "<dird: %s", dir->msg);
+ if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
+ set_text(_("Director rejected Hello command\n"));
+ return false;
+ } else {
+ set_text(dir->msg);
+ }
+ return true;
+}
Console::Console()
{
+ QFont font;
QTreeWidgetItem *item, *topItem;
QTreeWidget *treeWidget = mainWin->treeWidget;
m_sock = NULL;
m_at_prompt = false;
m_textEdit = mainWin->textEdit; /* our console screen */
+ m_cursor = new QTextCursor(m_textEdit->document());
+
+ /* ***FIXME*** make this configurable */
+ font.setFamily("Courier");
+ font.setFixedPitch(true);
+ font.setPointSize(10);
+ m_textEdit->setFont(font);
/* Just take the first Director */
LockRes();
m_textEdit = mainWin->textEdit; /* our console screen */
if (!m_dir) {
- set_text("No Director to connect to.\n");
+ mainWin->set_status("No Director found.");
return;
}
if (m_sock) {
- set_text("Already connected.\n");
+ mainWin->set_status("Already connected.");
return;
}
memset(&jcr, 0, sizeof(jcr));
- set_statusf(_(" Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport);
+ mainWin->set_statusf(_(" Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport);
set_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport);
/* Give GUI a chance */
m_sock = bnet_connect(NULL, 5, 15, _("Director daemon"), m_dir->address,
NULL, m_dir->DIRport, 0);
if (m_sock == NULL) {
- set_text("Connection failed\n");
+ mainWin->set_status("Connection failed");
return;
}
/* Give GUI a chance */
app->processEvents();
- set_status(_(" Initializing ..."));
+ mainWin->set_status(_(" Initializing ..."));
bnet_fsend(m_sock, "autodisplay on");
* .pools, .storage, .types, .levels, ...
*/
- set_status(_(" Connected"));
- set_text("Connected\n");
-
+ mainWin->set_status(_(" Connected"));
return;
}
#ifdef xxx
va_start(arg_ptr, fmt);
len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
va_end(arg_ptr);
- m_textEdit->append(buf);
-}
-
-void Console::set_text(const char *buf)
-{
- m_textEdit->append(buf);
+ set_text(buf);
}
-void Console::set_statusf(const char *fmt, ...)
+void Console::set_text(const QString buf)
{
- va_list arg_ptr;
- char buf[1000];
- int len;
- va_start(arg_ptr, fmt);
- len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
- va_end(arg_ptr);
- set_status(buf);
+ m_cursor->movePosition(QTextCursor::End);
+ m_cursor->insertText(buf);
+ m_textEdit->moveCursor(QTextCursor::End);
+ m_textEdit->ensureCursorVisible();
}
-void Console::set_status_ready()
-{
- mainWin->statusBar()->showMessage("Ready");
-// ready = true;
-}
-void Console::set_status(const char *buf)
+void Console::set_text(const char *buf)
{
- mainWin->statusBar()->showMessage(buf);
-// set_text(buf);
-// ready = false;
+ m_cursor->movePosition(QTextCursor::End);
+ m_cursor->insertText(buf);
+ m_textEdit->moveCursor(QTextCursor::End);
+ m_textEdit->ensureCursorVisible();
}
{
if (m_sock) {
m_at_prompt = false;
- set_status(_(" Processing command ..."));
+ mainWin->set_status(_(" Processing command ..."));
+ QApplication::setOverrideCursor(Qt::WaitCursor);
m_sock->msglen = strlen(msg);
pm_strcpy(&m_sock->msg, msg);
bnet_send(m_sock);
- }
- if (strcmp(msg, ".quit") == 0 || strcmp(msg, ".exit") == 0) {
- app->closeAllWindows();
+ } else {
+ mainWin->set_status(" Director not connected. Click on connect button.");
}
}
if (is_bnet_stop(m_sock)) { /* error or term request */
bnet_close(m_sock);
m_sock = NULL;
+ m_notifier->setEnabled(false);
+ delete m_notifier;
+ m_notifier = NULL;
+ mainWin->set_status(_(" Director disconnected."));
+ QApplication::restoreOverrideCursor();
return;
}
/* Must be a signal -- either do something or ignore it */
if (m_sock->msglen == BNET_PROMPT) {
m_at_prompt = true;
- set_status(_(" At prompt waiting for input ..."));
+ mainWin->set_status(_(" At prompt waiting for input ..."));
+ QApplication::restoreOverrideCursor();
}
if (m_sock->msglen == BNET_EOD) {
- set_status_ready();
+ mainWin->set_status_ready();
+ QApplication::restoreOverrideCursor();
}
return;
}
public:
Console();
void set_text(const char *buf);
+ void set_text(const QString buf);
void set_textf(const char *fmt, ...);
- void set_statusf(const char *fmt, ...);
- void set_status_ready();
- void set_status(const char *buf);
void write_dir(const char *buf);
+ bool authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons);
+ bool is_connected() { return m_sock != NULL; };
public slots:
void connect();
BSOCK *m_sock;
bool m_at_prompt;
QSocketNotifier *m_notifier;
+ QTextCursor *m_cursor;
};
-extern int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons);
-
#endif /* _CONSOLE_H_ */
#include "bat.h"
-/* Imported functions */
-int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons);
-
/* Forward referenced functions */
void terminate_console(int sig);
static void usage();
<rect>
<x>0</x>
<y>0</y>
- <width>889</width>
+ <width>1038</width>
<height>802</height>
</rect>
</property>
<height>0</height>
</size>
</property>
+ <property name="toolTip" >
+ <string>Selects right panel</string>
+ </property>
<property name="autoFillBackground" >
<bool>true</bool>
</property>
<height>0</height>
</size>
</property>
+ <property name="focusPolicy" >
+ <enum>Qt::NoFocus</enum>
+ </property>
+ <property name="acceptDrops" >
+ <bool>false</bool>
+ </property>
<property name="toolTip" >
<string comment="Console Window" />
</property>
<property name="documentTitle" >
<string comment="Console Window" />
</property>
+ <property name="lineWrapMode" >
+ <enum>QTextEdit::NoWrap</enum>
+ </property>
<property name="readOnly" >
<bool>true</bool>
</property>
<rect>
<x>0</x>
<y>0</y>
- <width>889</width>
+ <width>1038</width>
<height>33</height>
</rect>
</property>
setupUi(this); /* Setup UI defined by main.ui (designer) */
stackedWidget->setCurrentIndex(0);
+ statusBar()->showMessage("Director not connected. Click on connect button.");
+
m_console = new Console();
- /* Dummy message ***FIXME*** remove a bit later */
- textEdit->setPlainText("Hello Baculites\nThis is the main console window.");
lineEdit->setFocus();
-
/* Connect signals to slots */
connect(lineEdit, SIGNAL(returnPressed()), this, SLOT(input_line()));
connect(actionAbout_bat, SIGNAL(triggered()), this, SLOT(about()));
{
QString cmdStr = lineEdit->text(); /* Get the text */
lineEdit->clear(); /* clear the lineEdit box */
- textEdit->append(cmdStr); /* append text on screen */
- m_console->write_dir(cmdStr.toUtf8().data()); /* send to dir */
+ if (m_console->is_connected()) {
+ m_console->set_text(cmdStr + "\n");
+ m_console->write_dir(cmdStr.toUtf8().data()); /* send to dir */
+ } else {
+ set_status("Director not connected. Click on connect button.");
+ }
}
+
+
void MainWin::about()
{
QMessageBox::about(this, tr("About bat"),
" interface to the Director."));
}
-void set_textf(const char *fmt, ...)
-{
- va_list arg_ptr;
- char buf[1000];
- int len;
- va_start(arg_ptr, fmt);
- len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
- va_end(arg_ptr);
- mainWin->textEdit->append(buf);
-}
-
-void set_text(const char *buf)
-{
- mainWin->textEdit->append(buf);
-}
-
-void set_statusf(const char *fmt, ...)
+void MainWin::set_statusf(const char *fmt, ...)
{
va_list arg_ptr;
char buf[1000];
va_start(arg_ptr, fmt);
len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
va_end(arg_ptr);
-// gtk_label_set_text(GTK_LABEL(status1), buf);
+ set_status(buf);
// set_scroll_bar_to_end();
-// ready = false;
}
-void set_status_ready()
+void MainWin::set_status_ready()
{
- mainWin->statusBar()->showMessage("Ready");
-// ready = true;
+ set_status("Ready");
// set_scroll_bar_to_end();
}
-void set_status(const char *buf)
+void MainWin::set_status(const char *buf)
{
- mainWin->statusBar()->showMessage(buf);
+ statusBar()->showMessage(buf);
// ready = false;
}
public:
MainWin(QWidget *parent = 0);
+ void set_statusf(const char *fmt, ...);
+ void set_status_ready();
+ void set_status(const char *buf);
public slots:
void input_line();