3 * Bacula Gnome Tray Monitor
5 * Nicolas Boichat, August MMIV
11 Copyright (C) 2000-2004 Kern Sibbald and John Walker
13 This library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 2.1 of the License, or (at your option) any later version.
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free
25 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #include "tray-monitor.h"
33 #include "eggstatusicon.h"
38 #include "running.xpm"
42 /* Imported functions */
43 int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client);
45 /* Forward referenced functions */
46 static void terminate_console(int sig);
47 void writecmd(const char* command);
49 /* Static variables */
50 static char *configfile = NULL;
51 static BSOCK *FD_sock = NULL;
52 static MONITOR *monitor;
55 /* UI variables and functions */
56 gboolean fd_read(gpointer data);
58 static EggStatusIcon* mTrayIcon;
60 #define CONFIG_FILE "./tray-monitor.conf" /* default configuration file */
65 "Copyright (C) 2000-2004 Kern Sibbald and John Walker\n"
66 "\nVersion: " VERSION " (" BDATE ") %s %s %s\n\n"
67 "Usage: tray-monitor [-s] [-c config_file] [-d debug_level]\n"
68 " -c <file> set configuration file to file\n"
69 " -dnn set debug level to nn\n"
71 " -t test - read configuration and exit\n"
72 " -? print this message.\n"
73 "\n"), HOST_OS, DISTNAME, DISTVER);
76 /*********************************************************************
78 * Main Bacula Tray Monitor -- User Interface Program
81 int main(int argc, char *argv[])
84 bool test_config = false;
89 my_name_is(argc, argv, "tray-monitor");
92 working_directory = "/tmp";
93 args = get_pool_memory(PM_FNAME);
95 while ((ch = getopt(argc, argv, "bc:d:r:st?")) != -1) {
97 case 'c': /* configuration file */
98 if (configfile != NULL) {
101 configfile = bstrdup(optarg);
105 debug_level = atoi(optarg);
106 if (debug_level <= 0) {
129 if (configfile == NULL) {
130 configfile = bstrdup(CONFIG_FILE);
133 parse_config(configfile);
137 foreach_res(filed, R_CLIENT) {
142 Emsg1(M_ERROR_TERM, 0, _("No Client resource defined in %s (or more than one)\n\
143 Without that I don't how to get status from the Client :-(\n"), configfile);
147 terminate_console(0);
152 filed = (CLIENT*)GetNextRes(R_CLIENT, NULL);
155 memset(&jcr, 0, sizeof(jcr));
157 (void)WSA_Init(); /* Initialize Windows sockets */
159 printf(_("Connecting to Client %s:%d\n"), filed->address, filed->FDport);
160 FD_sock = bnet_connect(NULL, 5, 15, "File daemon", filed->address,
161 NULL, filed->FDport, 0);
162 if (FD_sock == NULL) {
163 terminate_console(0);
166 jcr.file_bsock = FD_sock;
169 monitor = (MONITOR*)GetNextRes(R_MONITOR, (RES *)NULL);
172 if (!authenticate_file_daemon(&jcr, monitor, filed)) {
173 fprintf(stderr, "ERR=%s", FD_sock->msg);
174 terminate_console(0);
178 printf("Opened connection with File daemon\n");
182 gtk_init (&argc, &argv);
184 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_xpm_data(xpm_idle);
185 // This should be ideally replaced by a completely libpr0n-based icon rendering.
186 mTrayIcon = egg_status_icon_new_from_pixbuf(pixbuf);
187 /* g_signal_connect(G_OBJECT(mTrayIcon), "activate", G_CALLBACK(TrayIconActivate), this);
188 g_signal_connect(G_OBJECT(mTrayIcon), "popup-menu", G_CALLBACK(TrayIconPopupMenu), this);*/
189 g_object_unref(G_OBJECT(pixbuf));
191 gtk_idle_add( fd_read, NULL );
196 bnet_sig(FD_sock, BNET_TERMINATE); /* send EOF */
200 terminate_console(0);
204 gboolean fd_read(gpointer data) {
208 if ((stat = bnet_recv(FD_sock)) >= 0) {
209 printf(FD_sock->msg);
211 else if (stat == BNET_SIGNAL) {
212 if (FD_sock->msglen == BNET_PROMPT) {
215 else if (FD_sock->msglen == BNET_EOD) {
221 else if (FD_sock->msglen == BNET_HEARTBEAT) {
222 bnet_sig(FD_sock, BNET_HB_RESPONSE);
223 printf("<< Heartbeat signal received, answered. >>");
226 printf("<< Unexpected signal received : %s >>", bnet_sig_to_ascii(FD_sock));
229 else { /* BNET_HARDEOF || BNET_ERROR */
234 if (is_bnet_stop(FD_sock)) {
236 break; /* error or term */
242 /* Cleanup and then exit */
243 static void terminate_console(int sig)
246 static bool already_here = false;
248 if (already_here) { /* avoid recursive temination problems */
252 free_pool_memory(args);
253 (void)WSACleanup(); /* Cleanup Windows sockets */
260 void writecmd(const char* command) {
261 FD_sock->msglen = strlen(command);
262 pm_strcpy(&FD_sock->msg, command);