summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-11-11 20:23:35 +0100
committerDenys Vlasenko <dvlasenk@redhat.com>2010-11-11 20:23:35 +0100
commitec5ff039f0dccb6b945056d6d7f5bcc848abba82 (patch)
tree3275753bcf4c134ba6a8abfdb2c29dd824ee94cb /src/plugins
parent301341a339b05615003c66472af18906cad5ca81 (diff)
downloadabrt-ec5ff039f0dccb6b945056d6d7f5bcc848abba82.tar.gz
abrt-ec5ff039f0dccb6b945056d6d7f5bcc848abba82.tar.xz
abrt-ec5ff039f0dccb6b945056d6d7f5bcc848abba82.zip
add "new style" abrt-action-upload plugin
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Makefile.am28
-rw-r--r--src/plugins/Upload.conf9
-rw-r--r--src/plugins/Upload.glade185
-rw-r--r--src/plugins/abrt-action-upload.cpp303
4 files changed, 525 insertions, 0 deletions
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 9eef1149..5fbdd349 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -22,6 +22,7 @@ dist_pluginslib_DATA = \
Bugzilla.glade \
RHTSupport.glade \
ReportUploader.glade \
+ Upload.glade \
KerneloopsReporter.glade
pluginsconfdir = $(PLUGINS_CONF_DIR)
@@ -33,6 +34,7 @@ dist_pluginsconf_DATA = \
Kerneloops.conf \
Bugzilla.conf \
RHTSupport.conf \
+ Upload.conf \
ReportUploader.conf \
FileTransfer.conf \
Python.conf \
@@ -120,6 +122,7 @@ libexec_PROGRAMS = \
abrt-action-bugzilla \
abrt-action-rhtsupport \
abrt-action-kerneloops \
+ abrt-action-upload \
abrt-action-print
abrt_action_analyze_c_SOURCES = \
@@ -243,6 +246,31 @@ abrt_action_rhtsupport_LDADD = \
../../lib/utils/libABRTdUtils.la \
../../lib/utils/libABRTUtils.la
+abrt_action_upload_SOURCES = \
+ abrt-action-upload.cpp
+abrt_action_upload_CPPFLAGS = \
+ -I$(srcdir)/../../inc \
+ -I$(srcdir)/../../lib/utils \
+ -DBIN_DIR=\"$(bindir)\" \
+ -DVAR_RUN=\"$(VAR_RUN)\" \
+ -DCONF_DIR=\"$(CONF_DIR)\" \
+ -DLOCALSTATEDIR='"$(localstatedir)"' \
+ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \
+ -DDEBUG_INFO_DIR=\"$(DEBUG_INFO_DIR)\" \
+ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \
+ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \
+ $(GLIB_CFLAGS) \
+ $(CURL_CFLAGS) \
+ -D_GNU_SOURCE \
+ -Wall -Werror
+abrt_action_upload_LDFLAGS = -ltar
+# Needs libABRTdUtils only for LoadPluginSettings
+abrt_action_upload_LDADD = \
+ $(GLIB_LIBS) \
+ $(CURL_LIBS) \
+ ../../lib/utils/libABRTdUtils.la \
+ ../../lib/utils/libABRTUtils.la
+
abrt_action_kerneloops_SOURCES = \
abrt-action-kerneloops.cpp
abrt_action_kerneloops_CPPFLAGS = \
diff --git a/src/plugins/Upload.conf b/src/plugins/Upload.conf
new file mode 100644
index 00000000..696a7bd4
--- /dev/null
+++ b/src/plugins/Upload.conf
@@ -0,0 +1,9 @@
+# Description: Packs crash data into .tar.gz file and uploads it via FTP/SCP/etc
+
+# URL to upload the files to.
+# supported: ftp, ftps, http, https, scp, sftp, tftp, file
+# for example: ftp://user:password@server.name/directory
+# or: scp://user:password@server.name:port/directory etc.
+# for testing: file:///tmp/test_directory
+# If empty, the prepared archive is stored in /var/run/abrt/
+URL =
diff --git a/src/plugins/Upload.glade b/src/plugins/Upload.glade
new file mode 100644
index 00000000..4aa03204
--- /dev/null
+++ b/src/plugins/Upload.glade
@@ -0,0 +1,185 @@
+<?xml version="1.0"?>
+<interface>
+ <requires lib="gtk+" version="2.14"/>
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkDialog" id="PluginDialog">
+ <property name="border_width">5</property>
+ <property name="resizable">False</property>
+ <property name="modal">True</property>
+ <property name="window_position">center-on-parent</property>
+ <property name="icon_name">abrt</property>
+ <property name="type_hint">normal</property>
+ <property name="has_separator">False</property>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="dialog-vbox">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkFrame" id="frame1">
+ <property name="visible">True</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">none</property>
+ <child>
+ <object class="GtkAlignment" id="alignment1">
+ <property name="visible">True</property>
+ <property name="top_padding">6</property>
+ <property name="left_padding">12</property>
+ <child>
+ <object class="GtkTable" id="table1">
+ <property name="visible">True</property>
+ <property name="n_rows">6</property>
+ <property name="n_columns">2</property>
+ <property name="column_spacing">12</property>
+ <property name="row_spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">URL:</property>
+ </object>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="conf_URL">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">&#x25CF;</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label6">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Retry count:</property>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="conf_RetryCount">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">&#x25CF;</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label7">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Retry delay:</property>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="conf_RetryDelay">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">&#x25CF;</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="conf_Encrypt">
+ <property name="label" translatable="yes">Use encryption</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="right_attach">2</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">6</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="label">
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">&lt;b&gt;Upload plugin configuration&lt;/b&gt;</property>
+ <property name="use_markup">True</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox" id="dialog-action_area1">
+ <property name="visible">True</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="button2">
+ <property name="label">gtk-cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="bApply">
+ <property name="label">gtk-apply</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-6">button2</action-widget>
+ <action-widget response="-10">bApply</action-widget>
+ </action-widgets>
+ </object>
+ <object class="GtkAction" id="action1"/>
+</interface>
diff --git a/src/plugins/abrt-action-upload.cpp b/src/plugins/abrt-action-upload.cpp
new file mode 100644
index 00000000..d2acd0f7
--- /dev/null
+++ b/src/plugins/abrt-action-upload.cpp
@@ -0,0 +1,303 @@
+/*
+ Copyright (C) 2010 ABRT team
+ Copyright (C) 2010 RedHat Inc
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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.
+*/
+
+#include <libtar.h>
+#include <curl/curl.h>
+#include "abrtlib.h"
+#include "parse_options.h"
+#include "crash_types.h"
+#include "abrt_exception.h"
+
+#include "plugin.h" /* LoadPluginSettings */
+
+
+#define PROGNAME "abrt-action-upload"
+
+//TODO: use this for better logging
+#if 0
+/* "read local data from a file" callback */
+static size_t fread_with_reporting(void *ptr, size_t size, size_t nmemb, void *userdata)
+{
+ static time_t last_t; // hack
+
+ FILE *fp = (FILE*)userdata;
+ time_t t = time(NULL);
+
+ // Report current file position every 16 seconds
+ if (!(t & 0xf) && last_t != t)
+ {
+ last_t = t;
+ off_t cur_pos = ftello(fp);
+ fseeko(fp, 0, SEEK_END);
+ off_t sz = ftello(fp);
+ fseeko(fp, cur_pos, SEEK_SET);
+ log(_("Uploaded: %llu of %llu kbytes"),
+ (unsigned long long)cur_pos / 1024,
+ (unsigned long long)sz / 1024);
+ }
+
+ return fread(ptr, size, nmemb, fp);
+}
+#endif
+
+static int send_file(const char *url, const char *filename)
+{
+ FILE *fp = fopen(filename, "r");
+ if (!fp)
+ {
+ perror_msg("Can't open '%s'", filename);
+ return 1;
+ }
+
+ log(_("Sending %s to %s"), filename, url);
+
+ struct stat stbuf;
+ fstat(fileno(fp), &stbuf); /* never fails */
+ char *whole_url = concat_path_file(url, strrchr(filename, '/') ? : filename);
+
+ CURL *curl = curl_easy_init();
+ if (!curl)
+ {
+ error_msg_and_die("Can't create curl handle");
+ }
+ /* Buffer[CURL_ERROR_SIZE] curl stores human readable error messages in.
+ * This may be more helpful than just return code from curl_easy_perform.
+ * curl will need it until curl_easy_cleanup. */
+ char curl_err_msg[CURL_ERROR_SIZE];
+ curl_err_msg[0] = '\0';
+ curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_msg);
+ /* enable uploading */
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+ /* specify target */
+ curl_easy_setopt(curl, CURLOPT_URL, whole_url);
+ /* FILE handle: passed to the default callback, it will fread() it */
+ curl_easy_setopt(curl, CURLOPT_READDATA, fp);
+ curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)stbuf.st_size);
+
+ /* everything is done here; result 0 means success */
+ CURLcode result = curl_easy_perform(curl);
+ free(whole_url);
+ fclose(fp);
+ if (result != 0)
+ error_msg("Error while uploading: '%s'", curl_easy_strerror(result));
+ else
+ /* This ends up a "reporting status message" in abrtd */
+ log(_("Successfully sent %s to %s"), filename, url);
+
+ curl_easy_cleanup(curl);
+
+ return result;
+}
+
+static int create_and_upload_archive(
+ const char *dump_dir_name,
+ const map_plugin_settings_t& settings)
+{
+ int result = 0;
+
+ pid_t child;
+ TAR* tar = NULL;
+ const char* errmsg = NULL;
+ char* tempfile = NULL;
+
+ struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
+ if (!dd)
+ exit(1); /* error msg is already logged by dd_opendir */
+
+ /* Gzipping e.g. 0.5gig coredump takes a while. Let client know what we are doing */
+ log(_("Compressing data"));
+
+//TODO:
+//Encrypt = yes
+//ArchiveType = .tar.bz2
+//ExcludeFiles = foo,bar*,b*z
+ char* env;
+ map_plugin_settings_t::const_iterator end = settings.end();
+ map_plugin_settings_t::const_iterator it;
+
+ env = getenv("Upload_URL");
+ it = settings.find("URL");
+ const char *url = (env ? env : (it == end ? NULL : it->second.c_str()));
+
+ /* Create a child gzip which will compress the data */
+ /* SELinux guys are not happy with /tmp, using /var/run/abrt */
+ tempfile = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%lu-%lu.tar.gz", (long)getpid(), (long)time(NULL));
+ int pipe_from_parent_to_child[2];
+ xpipe(pipe_from_parent_to_child);
+ child = fork();
+ if (child == 0)
+ {
+ /* child */
+ close(pipe_from_parent_to_child[1]);
+ xmove_fd(pipe_from_parent_to_child[0], 0);
+ xmove_fd(xopen3(tempfile, O_WRONLY | O_CREAT | O_EXCL, 0600), 1);
+ execlp("gzip", "gzip", NULL);
+ perror_msg_and_die("can't execute '%s'", "gzip");
+ }
+ close(pipe_from_parent_to_child[0]);
+
+ /* Create tar writer object */
+ if (tar_fdopen(&tar, pipe_from_parent_to_child[1], tempfile,
+ /*fileops:(standard)*/ NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU) != 0)
+ {
+ errmsg = "Can't create temporary file in "LOCALSTATEDIR"/run/abrt";
+ goto ret;
+ }
+
+ /* Write data to the tarball */
+ {
+ dd_init_next_file(dd);
+ char *short_name, *full_name;
+ while (dd_get_next_file(dd, &short_name, &full_name))
+ {
+ if (strcmp(short_name, CD_COUNT) == 0) goto next;
+ if (strcmp(short_name, CD_DUMPDIR) == 0) goto next;
+ if (strcmp(short_name, CD_INFORMALL) == 0) goto next;
+ if (strcmp(short_name, CD_REPORTED) == 0) goto next;
+ if (strcmp(short_name, CD_MESSAGE) == 0) goto next; // plugin's status message (if we already reported it yesterday)
+ if (strcmp(short_name, FILENAME_DESCRIPTION) == 0) goto next; // package description
+ // dd_get_next_file guarantees this:
+ //struct stat stbuf;
+ //if (stat(full_name, &stbuf) != 0)
+ // || !S_ISREG(stbuf.st_mode)
+ //) {
+ // goto next;
+ //}
+ if (tar_append_file(tar, full_name, short_name) != 0)
+ {
+ errmsg = "Can't create temporary file in "LOCALSTATEDIR"/run/abrt";
+ free(short_name);
+ free(full_name);
+ goto ret;
+ }
+ next:
+ free(short_name);
+ free(full_name);
+ }
+ }
+ dd_close(dd);
+ dd = NULL;
+
+ /* Close tar writer... */
+ if (tar_append_eof(tar) != 0 || tar_close(tar) != 0)
+ {
+ errmsg = "Can't create temporary file in "LOCALSTATEDIR"/run/abrt";
+ goto ret;
+ }
+ tar = NULL;
+ /* ...and check that gzip child finished successfully */
+ int status;
+ waitpid(child, &status, 0);
+ child = -1;
+ if (status != 0)
+ {
+ /* We assume the error was out-of-disk-space or out-of-quota */
+ errmsg = "Can't create temporary file in "LOCALSTATEDIR"/run/abrt";
+ goto ret;
+ }
+
+ /* Upload the tarball */
+ if (url && url[0])
+ {
+ result = send_file(url, tempfile);
+ /* cleanup code will delete tempfile */
+ }
+ else
+ {
+ log(_("Archive is created: '%s'"), tempfile);
+ free(tempfile);
+ tempfile = NULL;
+ }
+
+ ret:
+ dd_close(dd);
+ if (tar)
+ tar_close(tar);
+ /* close(pipe_from_parent_to_child[1]); - tar_close() does it itself */
+ if (child > 0)
+ waitpid(child, NULL, 0);
+ if (tempfile)
+ {
+ unlink(tempfile);
+ free(tempfile);
+ }
+ if (errmsg)
+ error_msg_and_die("%s", errmsg);
+
+ return result;
+}
+
+int main(int argc, char **argv)
+{
+ char *env_verbose = getenv("ABRT_VERBOSE");
+ if (env_verbose)
+ g_verbose = atoi(env_verbose);
+
+ const char *dump_dir_name = ".";
+ const char *conf_file = NULL;
+ const char *url = NULL;
+
+ const char *program_usage = _(
+ PROGNAME" [-v] -d DIR [-c CONFFILE] [-u URL]\n"
+ "\n"
+ "Upload compressed tarball of crash dump"
+ );
+ enum {
+ OPT_v = 1 << 0,
+ OPT_d = 1 << 1,
+ OPT_c = 1 << 2,
+ OPT_u = 1 << 3,
+ };
+ /* Keep enum above and order of options below in sync! */
+ struct options program_options[] = {
+ OPT__VERBOSE(&g_verbose),
+ OPT_STRING('d', NULL, &dump_dir_name, "DIR" , _("Crash dump directory")),
+ OPT_STRING('c', NULL, &conf_file , "CONFFILE", _("Config file")),
+ OPT_STRING('u', NULL, &url , "URL" , _("Base URL to upload to")),
+ OPT_END()
+ };
+
+ /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage);
+
+ putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose));
+ //msg_prefix = PROGNAME;
+ //if (optflags & OPT_s)
+ //{
+ // openlog(msg_prefix, 0, LOG_DAEMON);
+ // logmode = LOGMODE_SYSLOG;
+ //}
+
+ map_plugin_settings_t settings;
+ if (url)
+ settings["URL"] = url;
+ if (conf_file)
+ LoadPluginSettings(conf_file, settings);
+
+ int result = 0;
+ try
+ {
+ result = create_and_upload_archive(dump_dir_name, settings);
+ }
+ catch (CABRTException& e)
+ {
+ error_msg_and_die("%s", e.what());
+ }
+
+ return result;
+}