Use webservice instead of mail.
authorValentin Vidic <Valentin.Vidic@CARNet.hr>
Thu, 9 Oct 2014 13:35:03 +0000 (15:35 +0200)
committerValentin Vidic <Valentin.Vidic@CARNet.hr>
Thu, 9 Oct 2014 13:35:03 +0000 (15:35 +0200)
debian/control
debian/install
debian/po/templates.pot
debian/postinst
debian/templates
gpg/pubring.gpg [deleted file]
gpg/secring.gpg [deleted file]
gpg/trustdb.gpg [deleted file]

index 4dedc32..585c07f 100644 (file)
@@ -11,8 +11,8 @@ Vcs-Browser: http://ftp.carnet.hr/carnet-debian/scm/?p=bacula-cn.git;a=summary
 
 Package: bacula-cn
 Architecture: all
-Depends: bacula-fd (>= 5), bacula-console (>= 5), openssl, gnupg,
- debconf (>= 0.5) | debconf-2.0, ${misc:Depends}
+Depends: bacula-fd (>= 5), bacula-console (>= 5), openssl, curl,
+ ca-certificates, debconf (>= 0.5) | debconf-2.0, ${misc:Depends}
 Suggests: mysql-client, postgresql-client-common, mail-transport-agent
 Description: Network backup configuration for CARNet members
  This package install Bacula client daemon and configures it for use
index 8d8a82b..cfc38bb 100644 (file)
@@ -1,3 +1,2 @@
 sysbackup.pem etc/bacula/
-gpg var/lib/bacula-cn/
 db-dump etc/bacula/run-before-job.d/
index 7d4527c..bf4edfc 100644 (file)
@@ -6,9 +6,9 @@
 #, fuzzy
 msgid ""
 msgstr ""
-"Project-Id-Version: PACKAGE VERSION\n"
+"Project-Id-Version: bacula-cn\n"
 "Report-Msgid-Bugs-To: bacula-cn@packages.debian.org\n"
-"POT-Creation-Date: 2011-03-08 14:10+0100\n"
+"POT-Creation-Date: 2014-10-09 15:02+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -83,19 +83,13 @@ msgstr ""
 #: ../templates:4001
 msgid ""
 "Automatsko slanje zahtjeva za pokretanje usluge backupa posluzitelja nije "
-"uspjelo.  Zahtjev je spremljen u datoteci /etc/bacula/bacula-fd.txt"
+"uspjelo."
 msgstr ""
 
 #. Type: error
 #. Description
 #: ../templates:4001
 msgid ""
-"Molimo prekopirajte navedenu datoteku na vas mail posluzitelj i posaljite ju "
-"koristeci sljedecu naredbu:"
-msgstr ""
-
-#. Type: error
-#. Description
-#: ../templates:4001
-msgid "/usr/sbin/sendmail -t < bacula-fd.txt"
+"Provjerite vezu prema posluzitelju https://sysbackup.carnet.hr i ponovo "
+"instalirajte paket."
 msgstr ""
index 68f0916..03b2c5e 100644 (file)
@@ -33,7 +33,7 @@ generate_fd_config() {
         fi
 
         echo Generating $FD_CONFIG
-        CONFIG_CHANGED=1
+        rm -f $REQUEST_FILE
         cat >$FD_CONFIG <<EOF
 #
 # List Directors who are permitted to contact this File daemon
@@ -101,7 +101,7 @@ generate_bconsole_config() {
         fi
 
         echo Generating $BCONSOLE_CONFIG
-        CONFIG_CHANGED=1
+        rm -f $REQUEST_FILE
         cat >$BCONSOLE_CONFIG <<EOF
 #
 # Bacula User Agent (or Console) Configuration File
@@ -151,7 +151,7 @@ generate_cert() {
         umask 077
 
         echo Generating $CERT_FILE
-        CONFIG_CHANGED=1
+        rm -f $REQUEST_FILE
         openssl req -new -newkey rsa:2048 -nodes -keyout $CERT_FILE \
             -subj "/C=HR/ST=Croatia/O=CARNet/OU=sysbackup/CN=$IP" \
             -x509 -extensions usr_cert -days $((365*5)) \
@@ -173,77 +173,28 @@ random_string() {
     head -n 20 /dev/urandom | openssl dgst -sha1 | sed 's/^.* //'
 }
 
-send_mail() {
-    REQUEST_FILE=/etc/bacula/bacula-fd.txt
-    GPG_HOME=/var/lib/bacula-cn/gpg
-
-    BOUNDARY=$( random_string )
-    GPG="gpg --homedir $GPG_HOME --batch --encrypt --armour --recipient rt@tt.carnet.hr --always-trust"
+send_request() {
+    # cleanup gpg files
+    rm -rf /var/lib/bacula-cn
 
-    if [ -z "$CONFIG_CHANGED" ]; then
+    if [ -e $REQUEST_FILE ]; then
         echo Config has not changed, skipping request.
         return
     fi
 
-    umask 022
-    chmod 0700 $GPG_HOME
-    echo Generating request in $REQUEST_FILE
-    rm -f $REQUEST_FILE
-
-    # Header
-    cat > $REQUEST_FILE <<EOF
-From: $CONTACT
-To: sysbackup@carnet.hr
-Subject: Backup za $HOST
-MIME-Version: 1.0
-Content-Type: multipart/mixed; boundary="$BOUNDARY"
-
-This is a message with multiple parts in MIME format.
---$BOUNDARY
-Content-Type: text/plain
-Content-Transfer-Encoding: 7bit
-Content-Disposition: inline
-
-Ime posluzitelja: $HOST
-IP adresa: $IP
-Kontakt adresa: $CONTACT
-EOF
-
-# attachment: disk sizes
-cat >> $REQUEST_FILE <<EOF
---$BOUNDARY
-Content-Type: text/plain
-Content-Transfer-Encoding: 7bit
-Content-Disposition: inline; filename="df.txt.gpg"
-
-EOF
-
-    df -h | $GPG >> $REQUEST_FILE
-
-# attachment: database sizes
-if [ -d /var/lib/mysql -o -d /var/lib/postgresql ]; then
-    cat >> $REQUEST_FILE <<EOF
---$BOUNDARY
-Content-Type: text/plain
-Content-Transfer-Encoding: 7bit
-Content-Disposition: inline; filename="db.txt.gpg"
-
-EOF
-
-    du -sh /var/lib/mysql /var/lib/postgresql 2>/dev/null \
-    | $GPG >> $REQUEST_FILE
-fi
-
-# attachment: client config
-cat >> $REQUEST_FILE <<EOF
---$BOUNDARY
-Content-Type: text/plain
-Content-Transfer-Encoding: 7bit
-Content-Disposition: inline; filename="$HOST-fd.conf.gpg"
+    # report disk sizes
+    DF_FILE=$(mktemp bacula-cn.XXXXXXXXXX)
+    df -h > $DF_FILE
 
-EOF
+    # report database sizes
+    DB_FILE=$(mktemp bacula-cn.XXXXXXXXXX)
+    if [ -d /var/lib/mysql -o -d /var/lib/postgresql ]; then
+        du -sh /var/lib/mysql /var/lib/postgresql >$DB_FILE 2>/dev/null || true
+    fi
 
-    cat <<EOF | $GPG >> $REQUEST_FILE
+    # generate client config
+    FD_FILE=$(mktemp bacula-cn.XXXXXXXXXX)
+    cat >> $FD_FILE <<EOF
 # Requested by $CONTACT on $DATE
 Client {
   Name = $HOST-fd
@@ -275,32 +226,34 @@ Messages {
 }
 EOF
 
-# attachment: client certificate
-cat >> $REQUEST_FILE <<EOF
---$BOUNDARY
-Content-Type: text/plain
-Content-Transfer-Encoding: 7bit
-Content-Disposition: inline; filename="$HOST-fd.pem.gpg"
-
-EOF
-
-    sed -n '/BEGIN CERTIFICATE/,/END CERTIFICATE/p' /etc/bacula/bacula-fd.pem \
-    | $GPG >> $REQUEST_FILE
-
-cat >> $REQUEST_FILE <<EOF
---$BOUNDARY--
-EOF
-
-    # Try to send it
-    if [ -x "`which sendmail 2>/dev/null`" ]; then
-        echo Mailing request from $REQUEST_FILE
-        if sendmail -t -oi -f "$EMAIL" < $REQUEST_FILE; then
-            requestsent=1
-        fi
+    # client certificate
+    PEM_FILE=$(mktemp bacula-cn.XXXXXXXXXX)
+    sed -n '/BEGIN CERTIFICATE/,/END CERTIFICATE/p' \
+        /etc/bacula/bacula-fd.pem > $PEM_FILE
+
+    # send using web service
+    echo Sending sysbackup request.
+    [ -s $DB_FILE ] && DB_PARAM="-F db=@$DB_FILE;filename=db.txt"
+    if curl --fail --silent --show-error \
+         -F "contact=$CONTACT" \
+         -F "host=$HOST" \
+         -F "ip=$IP" \
+         -F "df=@$DF_FILE;filename=df.txt" \
+         $DB_PARAM \
+         -F "fd=@$FD_FILE;filename=$HOST-fd.conf" \
+         -F "pem=@$PEM_FILE;filename=$HOST-fd.pem" \
+         --cacert /etc/ssl/certs/ca-certificates.crt \
+         https://sysbackup.carnet.hr/bacapp.php >/dev/null
+    then
+        touch $REQUEST_FILE
     fi
 
-    if [ -z "$requestsent" ]; then
-        db_input high bacula-cn/mail-failed || true
+    # cleanup
+    rm -f $DF_FILE $DB_FILE $FD_FILE $PEM_FILE
+
+    # report problems
+    if [ ! -e $REQUEST_FILE ]; then
+        db_input high bacula-cn/request-failed || true
         db_go || true
     fi
 }
@@ -322,7 +275,7 @@ load_config() {
 
     DATE=$( date '+%Y-%m-%d' )
 
-    CONFIG_CHANGED=
+    REQUEST_FILE=/etc/bacula/bacula-fd.txt
 }
 
 case "$1" in
@@ -335,7 +288,7 @@ case "$1" in
         generate_bconsole_config
 
         restart_bacula
-        send_mail
+        send_request
 
         db_stop
     ;;
index 07fe9c8..5be901d 100644 (file)
@@ -21,13 +21,11 @@ _Description: Kontakt adresa:
  usluge backupa i za kontakt u slucaju problema. Zbog toga molimo
  da unesete radecu mail adresu.
 
-Template: bacula-cn/mail-failed
+Template: bacula-cn/request-failed
 Type: error
 _Description: Greska prilikom slanja zahtjeva.
  Automatsko slanje zahtjeva za pokretanje usluge backupa posluzitelja
- nije uspjelo.  Zahtjev je spremljen u datoteci /etc/bacula/bacula-fd.txt
+ nije uspjelo.
  .
- Molimo prekopirajte navedenu datoteku na vas mail posluzitelj i
- posaljite ju koristeci sljedecu naredbu:
- .
- /usr/sbin/sendmail -t < bacula-fd.txt
+ Provjerite vezu prema posluzitelju https://sysbackup.carnet.hr i
+ ponovo instalirajte paket.
diff --git a/gpg/pubring.gpg b/gpg/pubring.gpg
deleted file mode 100644 (file)
index 471b4cb..0000000
Binary files a/gpg/pubring.gpg and /dev/null differ
diff --git a/gpg/secring.gpg b/gpg/secring.gpg
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/gpg/trustdb.gpg b/gpg/trustdb.gpg
deleted file mode 100644 (file)
index 1dd5d29..0000000
Binary files a/gpg/trustdb.gpg and /dev/null differ