Browse Source

Token between controllers and email fetcher in config

Guénaël Muller 7 years ago
parent
commit
e0dd766c17

+ 2 - 0
tracim/development.ini.base View File

221
 email.reply.imap.user = your_imap_user
221
 email.reply.imap.user = your_imap_user
222
 email.reply.imap.password = your_imap_password
222
 email.reply.imap.password = your_imap_password
223
 email.reply.imap.folder = INBOX
223
 email.reply.imap.folder = INBOX
224
+# Token for communication between mail fetcher and tracim controller
225
+email.reply.token = mysecuretoken
224
 # Delay in seconds between each check
226
 # Delay in seconds between each check
225
 email.reply.delay = 60
227
 email.reply.delay = 60
226
 
228
 

+ 3 - 0
tracim/tracim/config/app_cfg.py View File

376
         self.EMAIL_REPLY_DELAY = int(tg.config.get(
376
         self.EMAIL_REPLY_DELAY = int(tg.config.get(
377
             'email.reply.delay',
377
             'email.reply.delay',
378
         ))
378
         ))
379
+        self.EMAIL_REPLY_TOKEN = tg.config.get(
380
+            'email.reply.token',
381
+        )
379
 
382
 
380
         self.TRACKER_JS_PATH = tg.config.get(
383
         self.TRACKER_JS_PATH = tg.config.get(
381
             'js_tracker_path',
384
             'js_tracker_path',

+ 5 - 3
tracim/tracim/controllers/events.py View File

7
 from tracim.lib.user import UserApi
7
 from tracim.lib.user import UserApi
8
 from tracim.model.data import ContentType
8
 from tracim.model.data import ContentType
9
 
9
 
10
-VALID_TOKEN_VALUE="djkflhqsfhyqsdb fq"
11
-
12
 class EventsRestController(RestController):
10
 class EventsRestController(RestController):
13
 
11
 
14
 
12
 
15
     @tg.expose('json')
13
     @tg.expose('json')
16
     def post(self):
14
     def post(self):
17
         json = request.json_body
15
         json = request.json_body
18
-        if 'token' in json and json['token'] == VALID_TOKEN_VALUE:
16
+
17
+        from tracim.config.app_cfg import CFG
18
+        cfg = CFG.get_instance()
19
+
20
+        if 'token' in json and json['token'] == cfg.EMAIL_REPLY_TOKEN:
19
             if 'user_mail' not in json or 'content_id' not in json:
21
             if 'user_mail' not in json or 'content_id' not in json:
20
                 return {'status': 'error',
22
                 return {'status': 'error',
21
                         'error': 'bad json',}
23
                         'error': 'bad json',}

+ 1 - 0
tracim/tracim/lib/daemons.py View File

175
             delay=cfg.EMAIL_REPLY_DELAY,
175
             delay=cfg.EMAIL_REPLY_DELAY,
176
             # FIXME - G.M - 2017-11-15 - proper tracim url formatting
176
             # FIXME - G.M - 2017-11-15 - proper tracim url formatting
177
             endpoint=cfg.WEBSITE_BASE_URL + "/events",
177
             endpoint=cfg.WEBSITE_BASE_URL + "/events",
178
+            token=cfg.EMAIL_REPLY_TOKEN,
178
         )
179
         )
179
         self._fetcher.run()
180
         self._fetcher.run()
180
 
181
 

+ 4 - 3
tracim/tracim/lib/email_fetcher.py View File

17
 from email_reply_parser import EmailReplyParser
17
 from email_reply_parser import EmailReplyParser
18
 
18
 
19
 from tracim.lib.base import logger
19
 from tracim.lib.base import logger
20
-from tracim.controllers.events import VALID_TOKEN_VALUE
21
 
20
 
22
 TRACIM_SPECIAL_KEY_HEADER = "X-Tracim-Key"
21
 TRACIM_SPECIAL_KEY_HEADER = "X-Tracim-Key"
23
 BS_HTML_BODY_PARSE_CONFIG = {
22
 BS_HTML_BODY_PARSE_CONFIG = {
168
 
167
 
169
     def __init__(self,
168
     def __init__(self,
170
                  host: str, port: str, user: str, password: str, folder: str,
169
                  host: str, port: str, user: str, password: str, folder: str,
171
-                 delay: int, endpoint: str) \
170
+                 delay: int, endpoint: str, token:str) \
172
             -> None:
171
             -> None:
173
         """
172
         """
174
         Fetch mail from a mailbox folder through IMAP and add their content to
173
         Fetch mail from a mailbox folder through IMAP and add their content to
181
         :param folder: mail folder where new mail are fetched
180
         :param folder: mail folder where new mail are fetched
182
         :param delay: seconds to wait before fetching new mail again
181
         :param delay: seconds to wait before fetching new mail again
183
         :param endpoint: tracim http endpoint where decoded mail are send.
182
         :param endpoint: tracim http endpoint where decoded mail are send.
183
+        :param token: token to authenticate http connexion
184
         """
184
         """
185
         self._connection = None
185
         self._connection = None
186
         self._mails = []
186
         self._mails = []
191
         self.folder = folder
191
         self.folder = folder
192
         self.delay = delay
192
         self.delay = delay
193
         self.endpoint = endpoint
193
         self.endpoint = endpoint
194
+        self.token = token
194
 
195
 
195
         self._is_active = True
196
         self._is_active = True
196
 
197
 
260
         unsended_mail = []
261
         unsended_mail = []
261
         while self._mails:
262
         while self._mails:
262
             mail = self._mails.pop()
263
             mail = self._mails.pop()
263
-            msg = {"token": VALID_TOKEN_VALUE,
264
+            msg = {"token": self.token,
264
                    "user_mail": mail.get_from_address(),
265
                    "user_mail": mail.get_from_address(),
265
                    "content_id": mail.get_key(),
266
                    "content_id": mail.get_key(),
266
                    "payload": {
267
                    "payload": {