Skip to content

Commit

Permalink
Merge branch 'release/2.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
fedelemantuano committed Mar 16, 2019
2 parents 4eb0bbb + 424a33f commit 059a690
Show file tree
Hide file tree
Showing 18 changed files with 534 additions and 25 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@ dist: clean ## builds source and wheel package

install: clean ## install the package to the active Python's site-packages
python setup.py install

debug-iter-topology:
mkdir /tmp/logs/ 2>/dev/null || echo /tmp/logs/ already exist
sparse run \
-n spamscope_debug_iter \
-e debug \
-o topology.max.spout.pending=1 \
-o "topology.sleep.spout.wait.strategy.time.ms=10" \
-o "topology.tick.tuple.freq.secs=10"
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,13 @@ You can use:
* [Ansible](./ansible/README.md): to install and run SpamScope on server

# Topologies
SpamScope comes with three topologies:
SpamScope comes with six topologies:
- [spamscope_debug](./topologies/spamscope_debug.py): the output are JSON files on file system.
- [spamscope_elasticsearch](./topologies/spamscope_elasticsearch.py): the output are stored in Elasticsearch indexes.
- [spamscope_redis](./topologies/spamscope_redis.py): the output are stored in Redis.
- [spamscope_debug_iter](./topologies/spamscope_debug_iter.py): It uses generator to send mails in topology. The output are JSON files on file system.
- [spamscope_elasticsearch_iter](./topologies/spamscope_elasticsearch_iter.py): It uses generator to send mails in topology. The output are stored in Elasticsearch indexes.
- [spamscope_redis_iter](./topologies/spamscope_redis_iter.py): It uses generator to send mails in topology. The output are stored in Redis.

If you want submit SpamScope topology use `spamscope-topology submit` tool. For more details [see SpamScope cli tools](src/cli/README.md):

Expand Down
12 changes: 10 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,21 @@ run SpamScope on server
Topologies
==========

SpamScope comes with three topologies: -
SpamScope comes with six topologies: -
`spamscope_debug <./topologies/spamscope_debug.py>`__: the output are
JSON files on file system. -
`spamscope_elasticsearch <./topologies/spamscope_elasticsearch.py>`__:
the output are stored in Elasticsearch indexes. -
`spamscope_redis <./topologies/spamscope_redis.py>`__: the output are
stored in Redis.
stored in Redis. -
`spamscope_debug_iter <./topologies/spamscope_debug_iter.py>`__: It uses
generator to send mails in topology. The output are JSON files on file
system. -
`spamscope_elasticsearch_iter <./topologies/spamscope_elasticsearch_iter.py>`__:
It uses generator to send mails in topology. The output are stored in
Elasticsearch indexes. -
`spamscope_redis_iter <./topologies/spamscope_redis_iter.py>`__: It uses
generator to send mails in topology. The output are stored in Redis.

If you want submit SpamScope topology use ``spamscope-topology submit``
tool. For more details `see SpamScope cli tools <src/cli/README.md>`__:
Expand Down
44 changes: 44 additions & 0 deletions conf/spamscope.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,50 @@ files-mails:
path_mails: /path/mails2


# Spout file on file system
# Use an iterator. Safe for RAM
iter-files-mails:

# The mails in processing older that fail.after.seconds will be failed
fail.after.seconds: 60

# Post processing
post_processing:

# move or remove mails analyzed, default remove
what: remove

# Where you want move the analyzed mails, default /tmp/moved
where: /tmp/moved

# Where you want move the failed mails, default /tmp/failed
where.failed: /tmp/failed

# Mailboxes
mailboxes:
test:
mail_server: hostname
# Trust string is used to get sender IP address from mail server.
# More details:
# https://github.com/SpamScope/mail-parser/blob/v0.4.6/mailparser/__init__.py#L221
trust_string: "test_trust_string"
files_pattern: "*untroubled*"
path_mails: /path/mails1

# This flag enables Outlook msg parsing for every mails in mailbox
# Default value is false
outlook: false

# List of others headers to get
headers:
- custom_one
- custom_two
test1:
mail_server: hostname
trust_string: "test1_trust_string"
files_pattern: "*"
path_mails: /path/mails2

# Bolts configurations
# Phishing bolt configuration
phishing:
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject spamscope "2.7.0-SNAPSHOT"
(defproject spamscope "2.8.0-SNAPSHOT"
:resource-paths ["_resources"]
:target-path "_build"
:min-lein-version "2.0.0"
Expand Down
4 changes: 2 additions & 2 deletions src/bolts/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import random
import six
from collections import deque
from cPickle import BadPickleGet
from cPickle import PickleError

from streamparse import Stream
import mailparser
Expand Down Expand Up @@ -85,7 +85,7 @@ def load_filters(self):
try:
obj = load_obj(path)
setattr(self, "analyzed_" + i, obj)
except (IOError, EOFError, ValueError, BadPickleGet):
except (IOError, EOFError, ValueError, PickleError):
setattr(self, "analyzed_" + i, deque(
maxlen=getattr(self, "maxlen_" + i)))

Expand Down
10 changes: 8 additions & 2 deletions src/cli/spamscope_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ def get_args():
submit.add_argument(
"-g",
"--topology",
choices=["spamscope_debug", "spamscope_elasticsearch",
"spamscope_redis"],
choices=[
"spamscope_debug_iter",
"spamscope_debug",
"spamscope_elasticsearch_iter",
"spamscope_elasticsearch",
"spamscope_redis_iter",
"spamscope_redis",
],
default="debug",
help="SpamScope topology.",
dest="topology")
Expand Down
8 changes: 5 additions & 3 deletions src/modules/attachments/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,11 @@ def withhashes(cls, attachments=[]):
try:
payload = base64.b64decode(i["payload"])
except TypeError, e:
payload = base64.b64decode(i["payload"] + "===")
i.setdefault("errors", []).append(repr(e))

try:
payload = base64.b64decode(i["payload"] + "===")
i.setdefault("errors", []).append(repr(e))
except TypeError:
continue
else:
payload = i["payload"]

Expand Down
8 changes: 6 additions & 2 deletions src/modules/attachments/thug_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ def generate_json_report():
if m is None:
return

report = json.loads(m(tempfile.gettempdir()))
return report
try:
report = json.loads(m(tempfile.gettempdir()))
except TypeError:
return
else:
return report


class CustomWatchdog(Watchdog):
Expand Down
2 changes: 1 addition & 1 deletion src/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from os.path import join

__version__ = "2.7.0"
__version__ = "2.8.0"
__configuration_path__ = "/etc/spamscope"

__defaults__ = {
Expand Down
13 changes: 13 additions & 0 deletions src/spouts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Overview
In this folder there are all SpamScope `spouts`.

# How add a new spout
These are the steps to add a new `spout` to Spamscope:

- add a new module in [spouts](./) folder. This module should implement a new class that has `AbstractSpout` as base.

- import the new class in [\_\_init\_\_.py](./__init__.py)

- add the new section in [main configuration file](../../conf/spamscope.example.yml). The name of this section will be used in topology file

- add the new spout in [topology](../../topologies)
1 change: 1 addition & 0 deletions src/spouts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
"""

from .files_mails import FilesMailSpout
from .iter_files_mails import IterFilesMailSpout
26 changes: 15 additions & 11 deletions src/spouts/files_mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,21 @@ def next_tuple(self):
self.log("EMITTED - {!r}".format(mail_string))

processing = mail.filename + ".processing"
shutil.move(mail.filename, processing)

self.emit([
processing, # 0
mail.mail_server, # 1
mail.mailbox, # 2
mail.priority, # 3
mail.trust, # 4
mail.mail_type, # 5
mail.headers], # 6
tup_id=mail.filename)

try:
shutil.move(mail.filename, processing)
except IOError:
self.log("ALREADY EMITTED - {!r}".format(mail_string))
else:
self.emit([
processing, # 0
mail.mail_server, # 1
mail.mailbox, # 2
mail.priority, # 3
mail.trust, # 4
mail.mail_type, # 5
mail.headers], # 6
tup_id=mail.filename)

def ack(self, tup_id):
"""Acknowledge tup_id, that is the path_mail. """
Expand Down
Loading

0 comments on commit 059a690

Please sign in to comment.