aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2017-08-05 16:42:21 +0200
committerThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2017-08-05 16:42:21 +0200
commit8d7655c9456d2efcd6f97e2173163a188a0750d7 (patch)
tree6e3da91537765d2a36be5f9ce7aeffa7714a0327
parent3430fec2318d94b0387dafbb294c3112af2c9f72 (diff)
Improved security and message format.
-rwxr-xr-xSilicium/Forum.py11
-rwxr-xr-xSilicium/Topic.py5
-rw-r--r--Utilities/AccountManager.py10
-rwxr-xr-xUtilities/CacheManager.py3
-rw-r--r--Utilities/utils.py32
5 files changed, 52 insertions, 9 deletions
diff --git a/Silicium/Forum.py b/Silicium/Forum.py
index 12f2e3a..6274b95 100755
--- a/Silicium/Forum.py
+++ b/Silicium/Forum.py
@@ -36,8 +36,9 @@ from .Topic import *
from .utils import *
class Forum:
- def __init__(self, forum_id, base = sili_base):
- self.id = forum_id
+ def __init__(self, forum_id, parent = None, base = sili_base):
+ self.parent = parent
+ self.id = forum_id
self.__base = base
self.title = None
self.forums = None
@@ -144,7 +145,7 @@ class Forum:
forums = []
for raw in body.find_all(True, {'class': 'forabg'}):
for el in self.__loadlist(raw):
- forum = Forum(el['forum_id'], base = self.__base)
+ forum = Forum(el['forum_id'], self, base = self.__base)
forum.load(el['title'], el['updater'], el['updated'])
forums.append(forum)
ans['forums'] = forums
@@ -153,7 +154,7 @@ class Forum:
announcements = []
for raw in body.find_all(True, {'class': 'forumbg announcement'}):
for el in self.__loadlist(raw):
- topic = Topic(el['topic_id'], base = self.__base)
+ topic = Topic(el['topic_id'], self, base = self.__base)
topic.load(el['title'], el['poster'], el['posted'],
el['updater'], el['updated'])
announcements.append(topic)
@@ -198,7 +199,7 @@ class Forum:
for raw in body.find_all(True, {'class': 'forumbg'}):
if 'announcement' in raw['class']: continue
for el in self.__loadlist(raw):
- topic = Topic(el['topic_id'], base = self.__base)
+ topic = Topic(el['topic_id'], self, base = self.__base)
topic.load(el['title'], el['poster'], el['posted'],
el['updater'], el['updated'])
topics.append(topic)
diff --git a/Silicium/Topic.py b/Silicium/Topic.py
index 94bfec3..5aaf446 100755
--- a/Silicium/Topic.py
+++ b/Silicium/Topic.py
@@ -26,8 +26,9 @@
from .utils import *
class Topic:
- def __init__(self, topic_id, base = sili_base):
- self.id = topic_id
+ def __init__(self, topic_id, parent = None, base = sili_base):
+ self.parent = parent
+ self.id = topic_id
self.__base = base
self.title = None
self.poster = None
diff --git a/Utilities/AccountManager.py b/Utilities/AccountManager.py
index 51d3dc3..d82c7f8 100644
--- a/Utilities/AccountManager.py
+++ b/Utilities/AccountManager.py
@@ -25,6 +25,8 @@
import os, pickle
from mastodon import Mastodon
+from .utils import *
+
__all__ = ["AccountManager"]
_VER = 'ohmygoditsmickbumhole'
@@ -47,6 +49,7 @@ class AccountManager:
data = {'ver': _VER, 'mastodon-app': self.__mastodon_app,
'mastodon-users': self.__mastodon_users}
pickle.dump(data, open(self.__path, 'wb'))
+ makeprivate(self.__path)
def mastodon_delete_app(self):
if not self.__mastodon_app:
@@ -70,6 +73,7 @@ class AccountManager:
Mastodon.create_app('Silicium.org Bot',
api_base_url = base,
to_file = os.path.join(self.__fold, app_id))
+ makeprivate(os.path.join(self.__fold, app_id))
self.__mastodon_app = (app_id, base)
self.save()
@@ -91,6 +95,7 @@ class AccountManager:
name, password,
to_file = os.path.join(self.__fold, user_id)
)
+ makeprivate(os.path.join(self.__fold, user_id))
self.__mastodon_users[name] = user_id
self.save()
@@ -105,8 +110,9 @@ class AccountManager:
access_token = muser).toot(message)
def post_topic(self, topic):
- msg = "Nouveau topic par {} : {}\n{}".format(topic.poster.name,
- topic.title, topic.link())
+ msg = 'Nouveau topic dans "{}" par {} : "{}"\n{}'.format(\
+ topic.parent.title if topic.parent else "(inconnu)",
+ topic.poster.name, topic.title, topic.link())
self.post(msg)
# End of file.
diff --git a/Utilities/CacheManager.py b/Utilities/CacheManager.py
index d1eaa1d..7ea5fa2 100755
--- a/Utilities/CacheManager.py
+++ b/Utilities/CacheManager.py
@@ -25,6 +25,8 @@
import pickle, datetime
import Silicium
+from .utils import *
+
__all__ = ["CacheManager"]
_VER = 'magick'
@@ -43,6 +45,7 @@ class CacheManager:
def save(self):
data = {'ver': _VER, 'forums': self.forums, 'topics': self.topics}
pickle.dump(data, open(self.__path, 'wb'))
+ makeprivate(self.__path)
def __refresh_forum(self, forum):
try:
diff --git a/Utilities/utils.py b/Utilities/utils.py
new file mode 100644
index 0000000..7b6bd1c
--- /dev/null
+++ b/Utilities/utils.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#******************************************************************************
+# Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
+#
+# 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.
+#******************************************************************************
+""" Small utilities for the big utilities. """
+
+import os as _os
+import stat as _stat
+
+__all__ = ['makeprivate']
+
+def makeprivate(path):
+ try: _os.chmod(path, _stat.S_IRUSR | _stat.S_IWUSR)
+ except: pass
+
+# End of file.