Skip to content

Instantly share code, notes, and snippets.

@skroczek
Created August 1, 2018 09:05
Show Gist options
  • Select an option

  • Save skroczek/37d2e35a07ce8a90d0a57c5defc49f34 to your computer and use it in GitHub Desktop.

Select an option

Save skroczek/37d2e35a07ce8a90d0a57c5defc49f34 to your computer and use it in GitHub Desktop.

Revisions

  1. skroczek created this gist Aug 1, 2018.
    31 changes: 31 additions & 0 deletions rspamd-learn-ham.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/bin/bash

    function log_error() { echo `date '+%Y-%m-%d %H:%M:%S'` ERROR: $1 >&2; }
    function log() { echo `date '+%Y-%m-%d %H:%M:%S'` INFO: $1; }

    MAIL=$(tee)

    SERVER_LIST="['10.10.115.15', '10.10.115.16']"
    PASSWORD="p455w0rD"

    SERVERS=($(python -c "from random import shuffle; server=${SERVER_LIST}; shuffle(server); print(' '.join(server))"))


    for SERVER in ${SERVERS[@]}; do
    log "Trying to report spam to ${SERVER}"
    RETURN=$(/usr/bin/curl -s --connect-timeout 1 -H "Password: ${PASSWORD}" --data-binary --url "http://${SERVER}:11334/learnham" -d "${MAIL}")
    STATUS=$?
    if [ $STATUS -eq 0 ]; then
    log "Spam reported to ${SERVER}: ${RETURN}"
    exit 0
    else
    if [ $STATUS -eq 28 ]; then
    log_error "Reporting SPAM to ${SERVER} failed: Connection timed out."
    else
    log_error "Reporting SPAM to ${SERVER} failed: CURL exit status ${STATUS}"
    fi
    fi
    done

    log_error "Reporting SPAM failed ${SERVERS[@]}"
    exit 1
    31 changes: 31 additions & 0 deletions rspamd-learn-spam.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/bin/bash

    function log_error() { echo `date '+%Y-%m-%d %H:%M:%S'` ERROR: $1 >&2; }
    function log() { echo `date '+%Y-%m-%d %H:%M:%S'` INFO: $1; }

    MAIL=$(tee)

    SERVER_LIST="['10.10.110.15', '10.10.110.16']"
    PASSWORD="p455w0rD"

    SERVERS=($(python -c "from random import shuffle; server=${SERVER_LIST}; shuffle(server); print(' '.join(server))"))


    for SERVER in ${SERVERS[@]}; do
    log "Trying to report spam to ${SERVER}"
    RETURN=$(/usr/bin/curl -s --connect-timeout 1 -H "Password: ${PASSWORD}" --data-binary --url "http://${SERVER}:11334/learnspam" -d "${MAIL}")
    STATUS=$?
    if [ $STATUS -eq 0 ]; then
    log "Spam reported to ${SERVER}: ${RETURN}"
    exit 0
    else
    if [ $STATUS -eq 28 ]; then
    log_error "Reporting SPAM to ${SERVER} failed: Connection timed out."
    else
    log_error "Reporting SPAM to ${SERVER} failed: CURL exit status ${STATUS}"
    fi
    fi
    done

    log_error "Reporting SPAM failed ${SERVERS[@]}"
    exit 1