diff options
| author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-11-11 20:41:18 +0100 |
|---|---|---|
| committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-11-11 20:41:18 +0100 |
| commit | 44d0593bd24d58ee4252a332655475bcf9f83577 (patch) | |
| tree | 05bdf5031a288a4f1e50a75389c5de7d89f3c455 /src/plugins | |
| parent | ec5ff039f0dccb6b945056d6d7f5bcc848abba82 (diff) | |
| download | abrt-44d0593bd24d58ee4252a332655475bcf9f83577.tar.gz abrt-44d0593bd24d58ee4252a332655475bcf9f83577.tar.xz abrt-44d0593bd24d58ee4252a332655475bcf9f83577.zip | |
remove "old-style" FileTransfer and ReportUploader plugins
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/plugins')
| -rw-r--r-- | src/plugins/FileTransfer.conf | 35 | ||||
| -rw-r--r-- | src/plugins/FileTransfer.cpp | 367 | ||||
| -rw-r--r-- | src/plugins/FileTransfer.h | 46 | ||||
| -rw-r--r-- | src/plugins/Makefile.am | 34 | ||||
| -rw-r--r-- | src/plugins/ReportUploader.conf | 23 | ||||
| -rw-r--r-- | src/plugins/ReportUploader.cpp | 517 | ||||
| -rw-r--r-- | src/plugins/ReportUploader.glade | 249 | ||||
| -rw-r--r-- | src/plugins/ReportUploader.h | 55 | ||||
| -rw-r--r-- | src/plugins/abrt-FileTransfer.7 | 72 | ||||
| -rw-r--r-- | src/plugins/abrt-Upload.7 (renamed from src/plugins/abrt-ReportUploader.7) | 0 |
10 files changed, 8 insertions, 1390 deletions
diff --git a/src/plugins/FileTransfer.conf b/src/plugins/FileTransfer.conf deleted file mode 100644 index 111c1c4b..00000000 --- a/src/plugins/FileTransfer.conf +++ /dev/null @@ -1,35 +0,0 @@ -# Configuration of the FileTransfer reporter plugin. -Enabled = yes - -# The plugin is invoked in the abrt.conf file, usually in the -# ActionsAndReporters option and/or the [cron] section. -# There are two modes of invocation: -# -# * Specify FileTransfer(one) in ActionsAndReporters directive. -# Immediately after crash is detected, the plugin transfers -# crash data to the server specified via URL directive in this file. -# -# * Specify FileTransfer(store) in ActionsAndReporters directive -# and add "HH:MM = FileTransfer" line in [cron] section. -# At the time of the crash, the plugin stores a record of it -# in its internal list. When specified time is reached, -# the plugin iterates through its internal list and sends -# every recorded crash to the specified URL. -# After that, the internal list is cleared. - - -# 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 -URL = - -# Archive type, one of .zip, .tar.gz or .tar.bz2 -ArchiveType = .tar.gz - -# How many times we try to upload the file -RetryCount = 3 - -# How long we wait between we retry the upload (in seconds) -RetryDelay = 20 diff --git a/src/plugins/FileTransfer.cpp b/src/plugins/FileTransfer.cpp deleted file mode 100644 index d964bc9d..00000000 --- a/src/plugins/FileTransfer.cpp +++ /dev/null @@ -1,367 +0,0 @@ -/* - FileTransfer.cpp - - Copyright (C) 2009 Daniel Novotny (dnovotny@redhat.com) - Copyright (C) 2009 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. -*/ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif -#include <libtar.h> -#include <bzlib.h> -#include <zlib.h> -#include "abrtlib.h" -#include "abrt_curl.h" -#include "FileTransfer.h" -#include "abrt_exception.h" -#include "comm_layer_inner.h" - -using namespace std; - -#define HBLEN 255 -#define FILETRANSFER_DIRLIST DEBUG_DUMPS_DIR "/FileTransferDirlist.txt" - -CFileTransfer::CFileTransfer() -: - m_sArchiveType(".tar.gz"), - m_nRetryCount(3), - m_nRetryDelay(20) -{ -} - -void CFileTransfer::SendFile(const char *pURL, const char *pFilename) -{ - int len = strlen(pURL); - if (len == 0) - { - error_msg(_("FileTransfer: URL not specified")); - return; - } - - update_client(_("Sending archive %s to %s"), pFilename, pURL); - - char *whole_url = concat_path_file(pURL, strrchr(pFilename, '/') ? : pFilename); - - int count = m_nRetryCount; - while (1) - { - FILE *f = fopen(pFilename, "r"); - if (!f) - { - free(whole_url); - throw CABRTException(EXCEP_PLUGIN, "Can't open archive file '%s'", pFilename); - } - - struct stat buf; - fstat(fileno(f), &buf); /* never fails */ - - CURL *curl = xcurl_easy_init(); - /* 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, f); - curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)buf.st_size); - - /* everything is done here; result 0 means success */ - int result = curl_easy_perform(curl); - - curl_easy_cleanup(curl); - fclose(f); - if (result == 0 || --count <= 0) - break; - /* retry the upload if not succesful, wait a bit before next try */ - sleep(m_nRetryDelay); - } - free(whole_url); -} - -static void create_tar(const char *archive_name, const char *directory) -{ - TAR *tar; - - if (tar_open(&tar, (char *)archive_name, NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU) != 0) - { - return; - } - tar_append_tree(tar, (char *)directory, (char*)"."); - tar_close(tar); -} - -static void create_targz(const char *archive_name, const char *directory) -{ - char *name_without_gz = xstrdup(archive_name); - strrchr(name_without_gz, '.')[0] = '\0'; - - create_tar(name_without_gz, directory); - - int fd = open(name_without_gz, O_RDONLY); - if (fd < 0) - { - remove(name_without_gz); - free(name_without_gz); - return; - } - - gzFile gz = gzopen(archive_name, "w"); - if (gz == NULL) - { - close(fd); - remove(name_without_gz); - free(name_without_gz); - return; - } - - char buf[BUFSIZ]; - ssize_t bytesRead; - while ((bytesRead = full_read(fd, buf, BUFSIZ)) > 0) - { - gzwrite(gz, buf, bytesRead); // TODO: check that return value == bytesRead - } - - gzclose(gz); - close(fd); - remove(name_without_gz); - free(name_without_gz); -} - -static void create_tarbz2(const char * archive_name, const char * directory) -{ - char *name_without_bz2 = xstrdup(archive_name); - strrchr(name_without_bz2, '.')[0] = '\0'; - - create_tar(name_without_bz2, directory); - - int tarFD = open(name_without_bz2, O_RDONLY); - if (tarFD == -1) - { - remove(name_without_bz2); - free(name_without_bz2); - return; - } - FILE *f = fopen(archive_name, "w"); - if (f == NULL) - { - close(tarFD); - remove(name_without_bz2); - free(name_without_bz2); - return; - } - int bzError; - BZFILE *bz = BZ2_bzWriteOpen(&bzError, f, /*BLOCK_MULTIPLIER:*/ 7, 0, 0); - if (bz == NULL) - { - fclose(f); - close(tarFD); - remove(name_without_bz2); - free(name_without_bz2); - return; - } - - char buf[BUFSIZ]; - ssize_t bytesRead; - while ((bytesRead = read(tarFD, buf, BUFSIZ)) > 0) - { - BZ2_bzWrite(&bzError, bz, buf, bytesRead); - } - - BZ2_bzWriteClose(&bzError, bz, 0, NULL, NULL); - fclose(f); - close(tarFD); - remove(name_without_bz2); - free(name_without_bz2); -} - -void CFileTransfer::CreateArchive(const char *pArchiveName, const char *pDir) -{ - if (m_sArchiveType == ".tar") - { - create_tar(pArchiveName, pDir); - } - else if (m_sArchiveType == ".tar.gz") - { - create_targz(pArchiveName, pDir); - } - else if (m_sArchiveType == ".tar.bz2") - { - create_tarbz2(pArchiveName, pDir); - } - else - { - throw CABRTException(EXCEP_PLUGIN, "Unknown/unsupported archive type %s", m_sArchiveType.c_str()); - } -} - -/* Returns the last component of the directory path. - * Careful to not return "" on "/path/path2/", but "path2". - */ -static string DirBase(const char *pStr) -{ - int end = strlen(pStr); - if (end > 1 && pStr[end-1] == '/') - { - end--; - } - int beg = end; - while (beg > 0 && pStr[beg-1] != '/') - { - beg--; - } - return string(pStr + beg, end - beg); -} - -void CFileTransfer::Run(const char *pActionDir, const char *pArgs, int force) -{ - if (strcmp(pArgs, "store") == 0) - { - /* Remember pActiveDir for later sending */ - FILE *dirlist = fopen(FILETRANSFER_DIRLIST, "a"); - if (!dirlist) - { - throw CABRTException(EXCEP_PLUGIN, "Can't open "FILETRANSFER_DIRLIST); - } - fprintf(dirlist, "%s\n", pActionDir); - fclose(dirlist); - VERB3 log("Remembered '%s' for future file transfer", pActionDir); - return; - } - - update_client(_("FileTransfer: Creating a report...")); - - char hostname[HBLEN]; - gethostname(hostname, HBLEN-1); - hostname[HBLEN-1] = '\0'; - - char tmpdir_name[] = "/tmp/abrtuploadXXXXXX"; - /* mkdtemp does mkdir(xxx, 0700), should be safe (is it?) */ - if (mkdtemp(tmpdir_name) == NULL) - { - throw CABRTException(EXCEP_PLUGIN, "Can't mkdir a temporary directory in /tmp"); - } - - if (strcmp(pArgs, "one") == 0) - { - /* Just send one archive */ - string archivename = ssprintf("%s/%s-%s%s", tmpdir_name, hostname, DirBase(pActionDir).c_str(), m_sArchiveType.c_str()); - try - { - CreateArchive(archivename.c_str(), pActionDir); - SendFile(m_sURL.c_str(), archivename.c_str()); - } - catch (CABRTException& e) - { - error_msg(_("Cannot create and send an archive: %s"), e.what()); - } - unlink(archivename.c_str()); - } - else - { - /* Tar up and send all remebered directories */ - FILE *dirlist = fopen(FILETRANSFER_DIRLIST, "r"); - if (!dirlist) - { - /* not an error */ - VERB3 log("No saved crashes to transfer"); - goto del_tmp_dir; - } - - char *dirname; - while ((dirname = xmalloc_fgetline(dirlist)) != NULL) - { - string archivename = ssprintf("%s/%s-%s%s", tmpdir_name, hostname, DirBase(dirname).c_str(), m_sArchiveType.c_str()); - try - { - VERB3 log("Creating archive '%s' of dir '%s'", archivename.c_str(), dirname); - CreateArchive(archivename.c_str(), dirname); - VERB3 log("Sending archive to '%s'", m_sURL.c_str()); - SendFile(m_sURL.c_str(), archivename.c_str()); - } - catch (CABRTException& e) - { - error_msg(_("Cannot create and send an archive: %s"), e.what()); - } - VERB3 log("Deleting archive '%s'", archivename.c_str()); - unlink(archivename.c_str()); - free(dirname); - } - - fclose(dirlist); - /* all the files we're able to send should be sent now, - starting over with clean table */ - unlink(FILETRANSFER_DIRLIST); - } - - del_tmp_dir: - rmdir(tmpdir_name); -} - -void CFileTransfer::SetSettings(const map_plugin_settings_t& pSettings) -{ - m_pSettings = pSettings; - - map_plugin_settings_t::const_iterator end = pSettings.end(); - map_plugin_settings_t::const_iterator it; - it = pSettings.find("URL"); - if (it != end) - { - m_sURL = it->second; - } - - it = pSettings.find("RetryCount"); - if (it != end) - { - m_nRetryCount = xatoi_u(it->second.c_str()); - } - - it = pSettings.find("RetryDelay"); - if (it != end) - { - m_nRetryDelay = xatoi_u(it->second.c_str()); - } - - it = pSettings.find("ArchiveType"); - if (it != end) - { - /* currently supporting .tar, .tar.gz, .tar.bz2 and .zip */ - m_sArchiveType = it->second; - if (m_sArchiveType[0] != '.') - { - m_sArchiveType = "." + m_sArchiveType; - } - } -} - -//ok to delete? -//const map_plugin_settings_t& CFileTransfer::GetSettings() -//{ -// m_pSettings["URL"] = m_sURL; -// m_pSettings["RetryCount"] = to_string(m_nRetryCount); -// m_pSettings["RetryDelay"] = to_string(m_nRetryDelay); -// m_pSettings["ArchiveType"] = m_sArchiveType; -// -// return m_pSettings; -//} - -PLUGIN_INFO(ACTION, - CFileTransfer, - "FileTransfer", - "0.0.6", - _("Sends a report via FTP or SCTP"), - "dnovotny@redhat.com", - "https://fedorahosted.org/abrt/wiki", - ""); diff --git a/src/plugins/FileTransfer.h b/src/plugins/FileTransfer.h deleted file mode 100644 index 17bebf3d..00000000 --- a/src/plugins/FileTransfer.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - FileTransfer.h - header file for the file transfer plugin - - it uploads the file via ftp or sctp - - Copyright (C) 2009 Daniel Novotny (dnovotny@redhat.com) - Copyright (C) 2009 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. -*/ -#ifndef FILETRANSFER_H_ -#define FILETRANSFER_H_ - -#include <string> -#include "plugin.h" -#include "action.h" - -class CFileTransfer : public CAction -{ - private: - std::string m_sURL; - std::string m_sArchiveType; - int m_nRetryCount; - int m_nRetryDelay; - - void CreateArchive(const char *pArchiveName, const char *pDir); - void SendFile(const char *pURL, const char *pFilename); - - public: - CFileTransfer(); - virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual void Run(const char *pActionDir, const char *pArgs, int force); -}; - -#endif /* FILETRANSFER_H_ */ diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 5fbdd349..743c8d1d 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -7,49 +7,43 @@ libexec_SCRIPTS = \ pluginslib_LTLIBRARIES = \ libCCpp.la \ + libPython.la \ libMailx.la \ - libSQLite3.la \ - libKerneloopsScanner.la\ + libKerneloopsScanner.la \ libKerneloops.la \ libSOSreport.la \ - libReportUploader.la \ - libPython.la \ - libFileTransfer.la + libSQLite3.la dist_pluginslib_DATA = \ Logger.glade \ Mailx.glade \ Bugzilla.glade \ RHTSupport.glade \ - ReportUploader.glade \ Upload.glade \ KerneloopsReporter.glade pluginsconfdir = $(PLUGINS_CONF_DIR) dist_pluginsconf_DATA = \ CCpp.conf \ + Python.conf \ Mailx.conf \ - SQLite3.conf \ Logger.conf \ Kerneloops.conf \ Bugzilla.conf \ RHTSupport.conf \ Upload.conf \ - ReportUploader.conf \ - FileTransfer.conf \ - Python.conf \ - SOSreport.conf + SOSreport.conf \ + SQLite3.conf man_MANS = \ - abrt-FileTransfer.7 \ abrt-Bugzilla.7 \ abrt-KerneloopsScanner.7 \ abrt-KerneloopsReporter.7 \ abrt-Logger.7 \ abrt-Mailx.7 \ abrt-plugins.7 \ - abrt-SQLite3.7 \ - abrt-ReportUploader.7 + abrt-Upload.7 \ + abrt-SQLite3.7 EXTRA_DIST = $(man_MANS) abrt-action-install-debuginfo @@ -96,24 +90,12 @@ libSQLite3_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) $(SQLITE3_CFLAGS) -DLOCAL libSOSreport_la_SOURCES = SOSreport.cpp SOSreport.h libSOSreport_la_LDFLAGS = -avoid-version -# ReportUploader -libReportUploader_la_SOURCES = ReportUploader.h ReportUploader.cpp -libReportUploader_la_LDFLAGS = -avoid-version -libReportUploader_la_LIBADD = $(CURL_LIBS) -libReportUploader_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) $(CURL_CFLAGS) -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" - # Python libPython_la_SOURCES = Python.h Python.cpp #libPython_la_LIBADD = $(NSS_LIBS) libPython_la_LDFLAGS = -avoid-version libPython_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) -# FileTrasfer -libFileTransfer_la_SOURCES = FileTransfer.cpp FileTransfer.h -libFileTransfer_la_LDFLAGS = -avoid-version -ltar -lbz2 -lz -libFileTransfer_la_LIBADD = $(CURL_LIBS) -libFileTransfer_la_CPPFLAGS = -I$(INC_PATH) -I$(UTILS_PATH) $(CURL_CFLAGS) -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" - libexec_PROGRAMS = \ abrt-action-analyze-c \ abrt-action-analyze-python \ diff --git a/src/plugins/ReportUploader.conf b/src/plugins/ReportUploader.conf deleted file mode 100644 index 7a7b9133..00000000 --- a/src/plugins/ReportUploader.conf +++ /dev/null @@ -1,23 +0,0 @@ -# Description: Packs crash data into .tar.gz file, optionally uploads it via FTP/SCP/etc - -Enabled = yes - -# Customer = "Example Inc." -# Ticket = IT12345 -# Encrypt = yes -# If set to "no" or commented out, -# compressed ticket data will be copied to /tmp: -# Upload = yes - -# If "Upload = yes", 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 -# URL = - -# How many times we try to upload the file -# RetryCount = 3 - -# How long we wait between we retry the upload (in seconds) -# RetryDelay = 20 diff --git a/src/plugins/ReportUploader.cpp b/src/plugins/ReportUploader.cpp deleted file mode 100644 index 4100e996..00000000 --- a/src/plugins/ReportUploader.cpp +++ /dev/null @@ -1,517 +0,0 @@ -/* - ReportUploader.cpp - - Copyright (C) 2009 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 "abrtlib.h" -#include "abrt_curl.h" -#include "ReportUploader.h" -#include "abrt_exception.h" -#include "comm_layer_inner.h" - -using namespace std; - - -CReportUploader::CReportUploader() : - m_bEncrypt(false), - m_bUpload(false), - m_nRetryCount(3), - m_nRetryDelay(20) -{} - -CReportUploader::~CReportUploader() -{} - - -static void RunCommand(const char *cmd) -{ - int retcode = system(cmd); - if (retcode) - { - throw CABRTException(EXCEP_PLUGIN, "'%s' exited with %d", cmd, retcode); - } -} - -static string ReadCommand(const char *cmd) -{ - FILE* fp = popen(cmd, "r"); - if (!fp) - { - throw CABRTException(EXCEP_PLUGIN, "Error running '%s'", cmd); - } - - string result; - char *buff; - while ((buff = xmalloc_fgetline(fp)) != NULL) - { - result += buff; - free(buff); - } - - int retcode = pclose(fp); - if (retcode) - { - throw CABRTException(EXCEP_PLUGIN, "'%s' exited with %d", cmd, retcode); - } - - return result; -} - -static void WriteCommand(const char *cmd, const char *input) -{ - FILE* fp = popen(cmd, "w"); - if (!fp) - { - throw CABRTException(EXCEP_PLUGIN, "error running '%s'", cmd); - } - - /* Hoping it's not too big to get us forever blocked... */ - fputs(input, fp); - - int retcode = pclose(fp); - if (retcode) - { - throw CABRTException(EXCEP_PLUGIN, "'%s' exited with %d", cmd, retcode); - } -} - -void CReportUploader::SendFile(const char *pURL, const char *pFilename, int retry_count, int retry_delay) -{ - if (pURL[0] == '\0') - { - error_msg(_("FileTransfer: URL not specified")); - return; - } - - update_client(_("Sending archive %s to %s"), pFilename, pURL); - - const char *base = (strrchr(pFilename, '/') ? : pFilename-1) + 1; - char *whole_url = concat_path_file(pURL, base); - int count = retry_count; - int result; - while (1) - { - FILE* f = fopen(pFilename, "r"); - if (!f) - { - free(whole_url); - throw CABRTException(EXCEP_PLUGIN, "Can't open archive file '%s'", pFilename); - } - struct stat buf; - fstat(fileno(f), &buf); /* never fails */ - CURL* curl = xcurl_easy_init(); - /* enable uploading */ - curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); - /* specify target */ - curl_easy_setopt(curl, CURLOPT_URL, whole_url); - curl_easy_setopt(curl, CURLOPT_READDATA, f); - curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)buf.st_size); - /* everything is done here; result 0 means success */ - result = curl_easy_perform(curl); - /* goodbye */ - curl_easy_cleanup(curl); - fclose(f); - if (result != 0) - { - update_client(_("Sending failed, trying again. %s"), curl_easy_strerror((CURLcode)result)); - } - if (result == 0 || --count <= 0) - break; - /* retry the upload if not succesful, wait a bit before next try */ - sleep(retry_delay); - } - free(whole_url); - - if (count <= 0 && result != 0) - { - throw CABRTException(EXCEP_PLUGIN, "Curl can not send a ticket"); - } -} - - -static void write_str_to_file(const char *str, const char *path, const char *fname) -{ - char *ofile_name = concat_path_file(path, fname); - FILE *ofile = fopen(ofile_name, "w"); - if (!ofile) - { - CABRTException e(EXCEP_PLUGIN, "Can't open '%s'", ofile_name); - free(ofile_name); - throw e; - } - free(ofile_name); - fputs(str, ofile); - fclose(ofile); -} - -string CReportUploader::Report(const map_crash_data_t& pCrashData, - const map_plugin_settings_t& pSettings, - const char *pArgs) -{ - string customer_name; - string ticket_name; - string upload_url; - bool do_encrypt; - bool do_upload; - int retry_count; - int retry_delay; - - /* if parse_settings fails it returns an empty map so we need to use defaults */ - map_plugin_settings_t settings = parse_settings(pSettings); - // Get ticket name, customer name, and do_encrypt from config settings - if (!settings.empty()) - { - customer_name = settings["Customer"]; - ticket_name = settings["Ticket"]; - upload_url = settings["URL"]; - do_encrypt = string_to_bool(settings["Encrypt"].c_str()); - do_upload = string_to_bool(settings["Upload"].c_str()); - retry_count = xatoi_u(settings["RetryCount"].c_str()); - retry_delay = xatoi_u(settings["RetryDelay"].c_str()); - } - else - { - customer_name = m_sCustomer; - ticket_name = m_sTicket; - upload_url = m_sURL; - do_encrypt = m_bEncrypt; - do_upload = m_bUpload; - retry_count = m_nRetryCount; - retry_delay = m_nRetryDelay; - } - update_client(_("Creating a ReportUploader report...")); - - bool have_ticket_name = (ticket_name != ""); - if (!have_ticket_name) - { - ticket_name = "ReportUploader-newticket"; - } - - // Format the time to add to the file name - char timebuf[256]; - time_t curtime = time(NULL); - strftime(timebuf, sizeof(timebuf), "-%Y%m%d%H%M%S", gmtime(&curtime)); - - // Create a tmp work directory, and within that - // create the "<ticketname>-yyyymmddhhmmss" directory - // which will be the root of the tarball - string file_name = ticket_name + timebuf; - - char tmpdir_name[] = "/tmp/abrtuploadXXXXXX"; - if (mkdtemp(tmpdir_name) == NULL) - { - throw CABRTException(EXCEP_PLUGIN, "Can't mkdir a temporary directory in /tmp"); - } - - char *tmptar_name = concat_path_file(tmpdir_name, file_name.c_str()); - if (mkdir(tmptar_name, 0700)) - { - CABRTException e(EXCEP_PLUGIN, "Can't mkdir '%s'", tmptar_name); - free(tmptar_name); - throw e; - } - - // Copy each entry into the tarball root. - // Files are simply copied, strings are written to a file - // TODO: some files are totally useless: - // "Reported", "Message" (plugin's output), "DumpDir", - // "Description" (package description) - maybe skip those? - map_crash_data_t::const_iterator it; - for (it = pCrashData.begin(); it != pCrashData.end(); it++) - { - const char *content = it->second[CD_CONTENT].c_str(); - if (it->second[CD_TYPE] == CD_TXT) - { - write_str_to_file(content, tmptar_name, it->first.c_str()); - } - else if (it->second[CD_TYPE] == CD_BIN) - { - char *ofile_name = concat_path_file(tmptar_name, it->first.c_str()); - if (copy_file(content, ofile_name, 0644) < 0) - { - CABRTException e(EXCEP_PLUGIN, - "Can't copy '%s' to '%s'", - content, ofile_name - ); - free(tmptar_name); - free(ofile_name); - throw e; - } - free(ofile_name); - } - } - - // add ticket_name and customer name to tarball - if (have_ticket_name) - { - write_str_to_file(ticket_name.c_str(), tmptar_name, "TICKET"); - } - if (customer_name != "") - { - write_str_to_file(customer_name.c_str(), tmptar_name, "CUSTOMER"); - } - - // Create the compressed tarball - string outfile_basename = file_name + ".tar.gz"; - char *outfile_name = concat_path_file(tmpdir_name, outfile_basename.c_str()); - string cmd = ssprintf("tar -C %s --create --gzip --file=%s %s", tmpdir_name, outfile_name, file_name.c_str()); - RunCommand(cmd.c_str()); - - // encrypt if requested - string key; - if (do_encrypt) - { - key = ReadCommand("openssl rand -base64 48"); - - string infile_name = outfile_name; - outfile_basename += ".aes"; - outfile_name = append_to_malloced_string(outfile_name, ".aes"); - - cmd = ssprintf("openssl aes-128-cbc -in %s -out %s -pass stdin", infile_name.c_str(), outfile_name); - WriteCommand(cmd.c_str(), key.c_str()); - } - - // generate md5sum - cmd = ssprintf("cd %s; md5sum <%s", tmpdir_name, outfile_basename.c_str()); - string md5sum = ReadCommand(cmd.c_str()); - - // upload or cp to /tmp - if (do_upload) - { - // FIXME: SendFile isn't working sometime (scp) - SendFile(upload_url.c_str(), outfile_name, retry_count, retry_delay); - } - else - { - cmd = ssprintf("cp %s /tmp/", outfile_name); - RunCommand(cmd.c_str()); - } - - // generate a reciept telling md5sum and encryption key - // note: do not internationalize these strings! - string msg; - if (have_ticket_name) - { - msg += "Please copy this into ticket: "; - msg += ticket_name; - msg += '\n'; - msg += "========cut here========\n"; - } - else - { - msg += "Please send this to your technical support:\n"; - msg += "========cut here========\n"; - } - if (do_upload) - { - msg += "RHUPLOAD: This report was sent to "; - msg += upload_url; - msg += '\n'; - } - else - { - msg += "RHUPLOAD: This report was copied into /tmp/:\n"; - } - if (have_ticket_name) - { - msg += "TICKET: "; - msg += ticket_name; - msg += '\n'; - } - msg += "FILE: "; - msg += outfile_basename; - msg += "\nMD5SUM: "; - msg += md5sum; - msg += '\n'; - if (do_encrypt) - { - msg += "KEY: aes-128-cbc\n"; - msg += key; - msg += '\n'; - } - msg += "==========end===========\n"; - - // warn the client (why _warn_? it's not an error, maybe update_client?): - //error_msg("%s", msg.c_str()); - - // delete the temporary directory - cmd = ssprintf("rm -rf %s", tmpdir_name); - RunCommand(cmd.c_str()); - - free(tmptar_name); - free(outfile_name); - - return msg; -} - -static bool is_string_safe(const char *str) -{ - const char *p = str; - while (*p) - { - unsigned char c = *p; - if ((c < '0' || c > '9') - && c != '_' - && c != '-' - ) { - c |= 0x20; // tolower - if (c < 'a' || c > 'z') - { - return false; - } - } - // only 0-9, -, _, A-Z, a-z reach this point - p++; - } - return true; -} - -void CReportUploader::SetSettings(const map_plugin_settings_t& pSettings) -{ - m_pSettings = pSettings; - - map_plugin_settings_t::const_iterator end = pSettings.end(); - map_plugin_settings_t::const_iterator it; - it = pSettings.find("Customer"); - if (it != end) - { - m_sCustomer = it->second; - } - // We use m_sTicket as part of filename, - // and we use resulting filename in system("cd %s; ...", filename) etc, - // so we are very paraniod about allowed chars - it = pSettings.find("Ticket"); - if (it != end && is_string_safe(it->second.c_str())) - { - m_sTicket = it->second; - } - it = pSettings.find("URL"); - if (it != end) - { - m_sURL = it->second; - } - it = pSettings.find("Encrypt"); - if (it != end) - { - m_bEncrypt = string_to_bool(it->second.c_str()); - } - it = pSettings.find("Upload"); - if (it != end) - { - m_bUpload = string_to_bool(it->second.c_str()); - } - it = pSettings.find("RetryCount"); - if (it != end) - { - m_nRetryCount = xatoi_u(it->second.c_str()); - } - it = pSettings.find("RetryDelay"); - if (it != end) - { - m_nRetryDelay = xatoi_u(it->second.c_str()); - } -} - -const map_plugin_settings_t& CReportUploader::GetSettings() -{ - m_pSettings["Customer"] = m_sCustomer; - m_pSettings["Ticket"] = m_sTicket; - m_pSettings["URL"] = m_sURL; - m_pSettings["Encrypt"] = m_bEncrypt ? "yes" : "no"; - m_pSettings["Upload"] = m_bUpload ? "yes" : "no"; - m_pSettings["RetryCount"] = to_string(m_nRetryCount); - m_pSettings["RetryDelay"] = to_string(m_nRetryDelay); - - return m_pSettings; -} - -//todo: make static -map_plugin_settings_t CReportUploader::parse_settings(const map_plugin_settings_t& pSettings) -{ - map_plugin_settings_t plugin_settings; - - map_plugin_settings_t::const_iterator end = pSettings.end(); - map_plugin_settings_t::const_iterator it; - - it = pSettings.find("Customer"); - if (it == end) - { - plugin_settings.clear(); - return plugin_settings; - } - plugin_settings["Customer"] = it->second; - - it = pSettings.find("Ticket"); - if (it == end) - { - plugin_settings.clear(); - return plugin_settings; - } - plugin_settings["Ticket"] = it->second; - - it = pSettings.find("URL"); - if (it == end) - { - plugin_settings.clear(); - return plugin_settings; - } - plugin_settings["URL"] = it->second; - - it = pSettings.find("Encrypt"); - if (it == end) - { - plugin_settings.clear(); - return plugin_settings; - } - plugin_settings["Encrypt"] = it->second; - - it = pSettings.find("Upload"); - if (it == end) - { - plugin_settings.clear(); - return plugin_settings; - } - plugin_settings["Upload"] = it->second; - - it = pSettings.find("RetryCount"); - if (it == end) - { - plugin_settings.clear(); - return plugin_settings; - } - plugin_settings["RetryCount"] = it->second; - - it = pSettings.find("RetryDelay"); - if (it == end) - { - plugin_settings.clear(); - return plugin_settings; - } - plugin_settings["RetryDelay"] = it->second; - - VERB1 log("User settings ok, using them instead of defaults"); - return plugin_settings; -} - -PLUGIN_INFO(REPORTER, - CReportUploader, - "ReportUploader", - "0.0.1", - _("Packs crash data into .tar.gz file, optionally uploads it via FTP/SCP/etc"), - "gavin@redhat.com", - "https://fedorahosted.org/abrt/wiki", - PLUGINS_LIB_DIR"/ReportUploader.glade"); diff --git a/src/plugins/ReportUploader.glade b/src/plugins/ReportUploader.glade deleted file mode 100644 index c2bbd470..00000000 --- a/src/plugins/ReportUploader.glade +++ /dev/null @@ -1,249 +0,0 @@ -<?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">7</property> - <property name="n_columns">2</property> - <property name="column_spacing">12</property> - <property name="row_spacing">6</property> - <child> - <object class="GtkLabel" id="label3"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">Customer:</property> - </object> - <packing> - <property name="x_options">GTK_FILL</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label4"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">Ticket:</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="GtkLabel" id="label5"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">URL:</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_Customer"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">●</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - </packing> - </child> - <child> - <object class="GtkEntry" id="conf_Ticket"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">●</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="GtkEntry" id="conf_URL"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">●</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="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">3</property> - <property name="bottom_attach">4</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">●</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">3</property> - <property name="bottom_attach">4</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">4</property> - <property name="bottom_attach">5</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">●</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">4</property> - <property name="bottom_attach">5</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">5</property> - <property name="bottom_attach">6</property> - </packing> - </child> - <child> - <object class="GtkCheckButton" id="conf_Upload"> - <property name="label" translatable="yes">Upload</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">6</property> - <property name="bottom_attach">7</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"><b>Report Uploader plugin configuration</b></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/ReportUploader.h b/src/plugins/ReportUploader.h deleted file mode 100644 index 4ff780b8..00000000 --- a/src/plugins/ReportUploader.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - ReportUploader.h - - Attach a configureable Ticket Number and Customer name to a report. - Create a compressed, optionally encrypted, tarball. - Upload tarball to configureable URL. - - Copyright (C) 2009 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. -*/ -#ifndef REPORTUPLOADER_H_ -#define REPORTUPLAODER_H_ - -#include "plugin.h" -#include "reporter.h" - -class CReportUploader : public CReporter -{ - private: - std::string m_sCustomer; - std::string m_sTicket; - std::string m_sURL; - bool m_bEncrypt; - bool m_bUpload; - int m_nRetryCount; - int m_nRetryDelay; - - void SendFile(const char *pURL, const char *pFilename, int retry_count, int retry_delay); - map_plugin_settings_t parse_settings(const map_plugin_settings_t& pSettings); - - public: - CReportUploader(); - virtual ~CReportUploader(); - virtual const map_plugin_settings_t& GetSettings(); - virtual void SetSettings(const map_plugin_settings_t& pSettings); - - virtual std::string Report(const map_crash_data_t& pCrashData, - const map_plugin_settings_t& pSettings, - const char *pArgs); -}; - -#endif diff --git a/src/plugins/abrt-FileTransfer.7 b/src/plugins/abrt-FileTransfer.7 deleted file mode 100644 index a721dd81..00000000 --- a/src/plugins/abrt-FileTransfer.7 +++ /dev/null @@ -1,72 +0,0 @@ -.TH abrt "7" "1 Jun 2009" "" -.SH NAME -FileTransfer plugin for abrt(8) -.SH DESCRIPTION -.P -.I abrt -is a daemon that watches for application crashes. When a crash occurs, -it collects the crash data and takes action according to -its configuration. This manual page describes the \fIFileTransfer\fP plugin -for \fIabrt\fP. -.P -This plugin is used to transfer the crash report to another -machine using a file transfer protocol. The protocols supported -are FTP, FTPS, HTTP, HTTPS, SCP, SFTP, and TFTP. -.SH INVOCATION -.P -The plugin is invoked in the \fIabrt.conf\fP file, usually in the -\fIActionsAndReporters\fP option and/or the \fI[cron]\fP section. -There are two modes of invocation: -.P -* Specify \fIFileTransfer(one)\fP in ActionsAndReporters directive. -Immediately after crash is detected, the plugin transfers crash data -to the server specified in the \fIFileTransfer.conf\fP configuration file. -.P -* Specify \fIFileTransfer(store)\fP in ActionsAndReporters directive -and add \fIHH:MM = FileTransfer\fP line in [cron] section. -At the time of the crash, -the plugin stores a record of it in its internal list. -When specified time is reached, the plugin iterates through -its internal list and sends every recorded crash to the specified URL. -After that, the internal list is cleared. -.SH CONFIGURATION -The \fIFileTransfer.conf\fP configuration file contains -several entries in the format "Option = Value". The options are: -.SS URL -The URL of the server, where the crash should -be transfered, specifying the protocol, the path, -the user name and the password, for example: -.br -URL = ftp://user:passwd@server.com/path -.SS ArchiveType -The type of the archive in which to pack the crash data. -Currently, \fI.tar\fP, \fI.tar.gz\fP, \fI.tar.bz2\fP and \fI.zip\fP -are supported. The default is \fI.tar.gz\fP -.SS RetryCount -This specifies how many times the plugin will try to resend -the file if the transfer was not succesful. The plugin -waits a while before it retries the transfer: see \fIRetryDelay\fP. -The default is 3 -.SS RetryDelay -If the transfer was not succesful, the plugin will -wait some time before sending the file again. This configuration -option specifies the time in seconds. The default is 20. -.SH EXAMPLES -.P -Typical configuration in \fIabrt.conf\fP. The crash is stored -each time it happens and at midnight, all the crash data -is transferred to a central server. -.P -[common] -.br -ActionsAndReporters = FileTransfer(store) -.br -[cron] -.br -00:00 = FileTransfer -.SH "SEE ALSO" -.IR abrt (8), -.IR abrt.conf (5), -.IR abrt-plugins (7) -.SH AUTHOR -Written by Daniel Novotny <dnovotny@redhat.com>. diff --git a/src/plugins/abrt-ReportUploader.7 b/src/plugins/abrt-Upload.7 index bd91f266..bd91f266 100644 --- a/src/plugins/abrt-ReportUploader.7 +++ b/src/plugins/abrt-Upload.7 |
