/*
Bacula® - The Network Backup Solution
- Copyright (C) 2007-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2007-2008 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.
+ License as published by the Free Software Foundation and included
+ 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
*
*/
-//#include <QAbstractEventDispatcher>
#include "bat.h"
#include "console.h"
#include "restore.h"
m_cursor = new QTextCursor(m_textEdit->document());
mainWin->actionConnect->setIcon(QIcon(":images/disconnected.png"));
- /* Check for messages every 5 seconds */
- m_timer = new QTimer(this);
- QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(poll_messages()));
- startTimer();
+ m_timer = NULL;
+ m_contextActions.append(actionStatusDir);
+ m_contextActions.append(actionConsoleHelp);
+ m_contextActions.append(actionRequestMessages);
+ m_contextActions.append(actionConsoleReload);
+ connect(actionStatusDir, SIGNAL(triggered()), this, SLOT(status_dir()));
+ connect(actionConsoleHelp, SIGNAL(triggered()), this, SLOT(consoleHelp()));
+ connect(actionConsoleReload, SIGNAL(triggered()), this, SLOT(consoleReload()));
+ connect(actionRequestMessages, SIGNAL(triggered()), this, SLOT(messages()));
}
Console::~Console()
void Console::startTimer()
{
+ m_timer = new QTimer(this);
+ QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(poll_messages()));
m_timer->start(mainWin->m_checkMessagesInterval*1000);
}
+void Console::stopTimer()
+{
+ if (m_timer) {
+ QWidget::disconnect(m_timer, SIGNAL(timeout()), this, SLOT(poll_messages()));
+ m_timer->stop();
+ delete m_timer;
+ m_timer = NULL;
+ }
+}
+
void Console::poll_messages()
{
m_messages_pending = true;
void Console::terminate()
{
if (m_sock) {
+ notify(false);
+ delete m_notifier;
+ m_notifier = NULL;
+ stopTimer();
m_sock->close();
m_sock = NULL;
}
- m_timer->stop();
}
/*
- * Connect to Director. If there are more than one, put up
- * a modal dialog so that the user chooses one.
+ * Connect to Director.
*/
-void Console::connect()
+void Console::connect_dir()
{
- JCR jcr;
+ JCR *jcr = new JCR;
utime_t heart_beat;
char buf[1024];
+ CONRES *cons;
+
+ buf[0] = 0;
m_textEdit = textEdit; /* our console screen */
if (!m_dir) {
mainWin->set_status("No Director found.");
- return;
+ goto bail_out;
}
if (m_sock) {
mainWin->set_status("Already connected.");
- return;
+ goto bail_out;
}
- memset(&jcr, 0, sizeof(jcr));
+ memset(jcr, 0, sizeof(JCR));
mainWin->set_statusf(_("Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport);
display_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport);
LockRes();
/* If cons==NULL, default console will be used */
- CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, NULL);
+ cons = (CONRES *)GetNextRes(R_CONSOLE, NULL);
UnlockRes();
/* Initialize Console TLS context once */
if (!cons->tls_ctx) {
display_textf(_("Failed to initialize TLS context for Console \"%s\".\n"),
m_dir->name());
- return;
+ goto bail_out;
}
}
display_textf(_("Failed to initialize TLS context for Director \"%s\".\n"),
m_dir->name());
mainWin->set_status("Connection failed");
- return;
+ goto bail_out;
}
}
NULL, m_dir->DIRport, 0);
if (m_sock == NULL) {
mainWin->set_status("Connection failed");
- return;
+ goto bail_out;
} else {
/* Update page selector to green to indicate that Console is connected */
mainWin->actionConnect->setIcon(QIcon(":images/connected.png"));
item->setForeground(0, greenBrush);
}
- jcr.dir_bsock = m_sock;
+ jcr->dir_bsock = m_sock;
- if (!authenticate_director(&jcr, m_dir, cons, buf, sizeof(buf))) {
+ if (!authenticate_director(jcr, m_dir, cons, buf, sizeof(buf))) {
display_text(buf);
- return;
+ goto bail_out;
}
+
if (buf[0]) {
display_text(buf);
}
displayToPrompt();
beginNewCommand();
+ job_list.clear();
+ client_list.clear();
+ fileset_list.clear();
+ fileset_list.clear();
+ messages_list.clear();
+ pool_list.clear();
+ storage_list.clear();
+ type_list.clear();
+ level_list.clear();
dir_cmd(".jobs", job_list);
dir_cmd(".clients", client_list);
dir_cmd(".filesets", fileset_list);
dir_cmd(".levels", level_list);
mainWin->set_status(_("Connected"));
+ startTimer(); /* start message timer */
+
+bail_out:
+ delete jcr;
return;
}
*/
bool Console::sql_cmd(const char *query, QStringList &results)
{
- if (!is_connectedGui())
- return false;
int stat;
POOL_MEM cmd(PM_MESSAGE);
+ if (!is_connectedGui()) {
+ return false;
+ }
+
notify(false);
pm_strcpy(cmd, ".sql query=\"");
}
}
-#ifdef xxx
- bsnprintf(cmd, sizeof(cmd), "job=%s pool=%s client=%s storage=%s where=%s\n"
- "level=%s type=%s fileset=%s catalog=%s enabled=%d\n",
- job_defs.job_name.toUtf8().data(), job_defs.pool_name.toUtf8().data(),
- job_defs.client_name.toUtf8().data(),
- job_defs.pool_name.toUtf8().data(), job_defs.messages_name.toUtf8().data(),
- job_defs.store_name.toUtf8().data(),
- job_defs.where.toUtf8().data(), job_defs.level.toUtf8().data(),
- job_defs.type.toUtf8().data(), job_defs.fileset_name.toUtf8().data(),
- job_defs.catalog_name.toUtf8().data(), job_defs.enabled);
-#endif
-
notify(true);
return true;
int Console::write(const char *msg)
{
+ if (!m_sock) {
+ return -1;
+ }
m_sock->msglen = pm_strcpy(m_sock->msg, msg);
m_at_prompt = false;
m_at_main_prompt = false;
if (mainWin->m_commDebug) Pmsg1(000, "send: %s\n", msg);
return m_sock->send();
+
}
/*
void Console::beginNewCommand()
{
for (int i=0; i < 3; i++) {
- write(".\n");
+ write(".");
while (read() > 0) {
if (mainWin->m_displayAll) display_text(msg());
}
m_messages_pending = false;
}
}
+ m_sock->msg[0] = 0;
stat = m_sock->recv();
if (stat >= 0) {
+ if (mainWin->m_commDebug) Pmsg1(000, "got: %s\n", m_sock->msg);
if (m_at_prompt) {
display_text("\n");
m_at_prompt = false;
m_at_main_prompt = false;
}
- if (mainWin->m_commDebug) Pmsg1(000, "got: %s", m_sock->msg);
}
switch (m_sock->msglen) {
- case BNET_MSGS_PENDING:
- if (mainWin->m_commDebug) Pmsg0(000, "MSGS PENDING\n");
- write_dir(".messages");
- displayToPrompt();
- m_messages_pending = false;
+ case BNET_MSGS_PENDING :
+ if (m_notifier->isEnabled()) {
+ if (mainWin->m_commDebug) Pmsg0(000, "MSGS PENDING\n");
+ write_dir(".messages");
+ displayToPrompt();
+ m_messages_pending = false;
+ }
+ m_messages_pending = true;
continue;
case BNET_CMD_OK:
if (mainWin->m_commDebug) Pmsg0(000, "CMD OK\n");
m_at_prompt = false;
m_at_main_prompt = false;
+ mainWin->set_status(_("Command completed ..."));
continue;
case BNET_CMD_BEGIN:
if (mainWin->m_commDebug) Pmsg0(000, "CMD BEGIN\n");
m_at_prompt = false;
m_at_main_prompt = false;
+ mainWin->set_status(_("Processing command ..."));
continue;
case BNET_MAIN_PROMPT:
if (mainWin->m_commDebug) Pmsg0(000, "MAIN PROMPT\n");
if (mainWin->m_commDebug) Pmsg0(000, "START SELECT\n");
new selectDialog(this);
break;
+ case BNET_YESNO:
+ if (mainWin->m_commDebug) Pmsg0(000, "YESNO\n");
+ new yesnoPopUp(this);
+ break;
case BNET_RUN_CMD:
if (mainWin->m_commDebug) Pmsg0(000, "RUN CMD\n");
new runCmdPage();
break;
+ case BNET_START_RTREE:
+ if (mainWin->m_commDebug) Pmsg0(000, "START RTREE CMD\n");
+ new restorePage();
+ break;
+ case BNET_END_RTREE:
+ if (mainWin->m_commDebug) Pmsg0(000, "END RTREE CMD\n");
+ break;
case BNET_ERROR_MSG:
if (mainWin->m_commDebug) Pmsg0(000, "ERROR MSG\n");
m_sock->recv(); /* get the message */
}
if (is_bnet_stop(m_sock)) { /* error or term request */
if (mainWin->m_commDebug) Pmsg0(000, "BNET STOP\n");
+ stopTimer();
m_sock->close();
m_sock = NULL;
mainWin->actionConnect->setIcon(QIcon(":images/disconnected.png"));
return true;
} else {
QString message("Director ");
- message += " is curerntly disconnected\n Please reconnect!!";
- QMessageBox::warning(this, tr("Bat"),
+ message += " is currently disconnected\n Please reconnect!!";
+ QMessageBox::warning(this, "Bat",
tr(message.toUtf8().data()), QMessageBox::Ok );
return false;
}
if (!is_connected()) {
QString message("Director ");
message += m_dir->name();
- message += " is curerntly disconnected\n Please reconnect!!";
- QMessageBox::warning(this, tr("Bat"),
+ message += " is currently disconnected\n Please reconnect!!";
+ QMessageBox::warning(this, "Bat",
tr(message.toUtf8().data()), QMessageBox::Ok );
return false;
} else if (!m_at_main_prompt){
QString message("Director ");
message += m_dir->name();
- message += " is curerntly busy\n Please complete restore or other "
-" operation !! This is a limitation that will be resolved before a beta"
-" release. This is currently an alpha release.";
- QMessageBox::warning(this, tr("Bat"),
+ message += " is currently busy\n Please complete restore or other "
+ " operation !! This is a limitation that will be resolved before a beta"
+ " release. This is currently an alpha release.";
+ QMessageBox::warning(this, "Bat",
tr(message.toUtf8().data()), QMessageBox::Ok );
return false;
} else if (!m_at_prompt){
QString message("Director ");
message += m_dir->name();
- message += " is curerntly not at a prompt\n Please try again!!";
- QMessageBox::warning(this, tr("Bat"),
+ message += " is currently not at a prompt\n Please try again!!";
+ QMessageBox::warning(this, "Bat",
tr(message.toUtf8().data()), QMessageBox::Ok );
return false;
} else {
*/
static int tls_pem_callback(char *buf, int size, const void *userdata)
{
+ (void)size;
+ (void)userdata;
#ifdef HAVE_TLS
const char *prompt = (const char *)userdata;
# if defined(HAVE_WIN32)
return 0;
#endif
}
+
+/* Slot for responding to page selectors status help command */
+void Console::consoleHelp()
+{
+ QString cmd("help");
+ consoleCommand(cmd);
+}
+
+/* Slot for responding to page selectors reload bacula-dir.conf */
+void Console::consoleReload()
+{
+ QString cmd("reload");
+ consoleCommand(cmd);
+}
+
+/* Function to get a list of volumes */
+void Console::getVolumeList(QStringList &volumeList)
+{
+ QString query("SELECT VolumeName AS Media FROM Media ORDER BY Media");
+ if (mainWin->m_sqlDebug) {
+ Pmsg1(000, "Query cmd : %s\n",query.toUtf8().data());
+ }
+ QStringList results;
+ if (sql_cmd(query, results)) {
+ QString field;
+ QStringList fieldlist;
+ /* Iterate through the lines of results. */
+ foreach (QString resultline, results) {
+ fieldlist = resultline.split("\t");
+ volumeList.append(fieldlist[0]);
+ } /* foreach resultline */
+ } /* if results from query */
+}
+
+/* Function to get a list of volumes */
+void Console::getStatusList(QStringList &statusLongList)
+{
+ QString statusQuery("SELECT JobStatusLong FROM Status");
+ if (mainWin->m_sqlDebug) {
+ Pmsg1(000, "Query cmd : %s\n",statusQuery.toUtf8().data());
+ }
+ QStringList statusResults;
+ if (sql_cmd(statusQuery, statusResults)) {
+ QString field;
+ QStringList fieldlist;
+ /* Iterate through the lines of results. */
+ foreach (QString resultline, statusResults) {
+ fieldlist = resultline.split("\t");
+ statusLongList.append(fieldlist[0]);
+ } /* foreach resultline */
+ } /* if results from statusquery */
+}