Răsfoiți Sursa

Make smtp server configuarable

LiteHell 6 ani în urmă
părinte
comite
28b46b9043
5 a modificat fișierele cu 98 adăugiri și 24 ștergeri
  1. 5 0
      app.py
  2. 13 0
      language/en-US.json
  3. 10 3
      language/ko-KR.json
  4. 37 9
      route/setting.py
  5. 33 12
      route/tool/func.py

+ 5 - 0
app.py

@@ -325,6 +325,11 @@ if not curs.fetchall():
     for i in ['naver.com', 'gmail.com', 'daum.net', 'kakao.com']:
         curs.execute(db_change("insert into html_filter (html, kind) values (?, 'email')"), [i])
 
+curs.execute(db_change('select data from other where name = "smtp_server" or name = "smtp_port" or name = "smtp_security"'))
+if not curs.fetchall():
+    for i in [['smtp_server', 'imap.google.com'], ['smtp_port', '587'], ['smtp_security', 'tls']]:
+        curs.execute(db_change("insert into other (name, data) values (?, ?)"), [i[0], i[1]])
+
 conn.commit()
 
 if os.path.exists('custom.py'):

+ 13 - 0
language/en-US.json

@@ -233,7 +233,11 @@
                 "wiki_port" : "Wiki port number",
                 "wiki_secret_key" : "Wiki secret key",
                 "email_required" : "Email required",
+<<<<<<< HEAD
                 "google_imap_required" : "Google IMAP configuration required",
+=======
+                "smtp_setting_required" : "Email SMTP setting required",
+>>>>>>> 2347c8d... Make smtp server configuarable
                 "update_branch" : "Branch to import updates",
                 "slow_edit" : "Continuous edit limit",
                 "requires_approval" : "Requires approval for register",
@@ -253,9 +257,18 @@
                 "edit_help" : "Editing textarea phrase",
             "_comment_2.2.4_" : "Google",
                 "recaptcha" : "reCAPTCHA",
+<<<<<<< HEAD
                 "google_imap" : "Google IMAP",
                 "google_email" : "Google email address",
                 "google_app_password" : "Google APP password",
+=======
+                "smtp_setting" : "Email SMTP setting",
+                "smtp_server" : "SMTP Server address",
+                "smtp_security": "SMTP Connection security",
+                "smtp_port" : "SMTP Server port",
+                "smtp_username" : "SMTP Username",
+                "smtp_password" : "SMTP Password",
+>>>>>>> 2347c8d... Make smtp server configuarable
         "_comment_2.3_" : "List",
             "open_discussion_list" : "Open discussion(s) list",
             "discussion_list" : "Discussion(s) list",

+ 10 - 3
language/ko-KR.json

@@ -18,7 +18,10 @@
     "view_acl": "읽기 ACL",
     "notice": "알림",
     "login": "로그인",
-    "google_imap": "Google IMAP",
+    "smtp_setting": "이메일 SMTP 설정",
+    "smtp_server" : "SMTP 서버 주소",
+    "smtp_security": "SMTP 보안 프로토콜",
+    "smtp_port" : "SMTP 서버 포트",
     "close": "닫기",
     "closed": "닫힘",
     "start": "시작",
@@ -181,9 +184,13 @@
     "text_setting": "문구 설정",
     "document_acl_authority": "문서 ACL 관리 권한",
     "wiki_logo": "위키 로고",
-    "google_imap_required": "Google IMAP 설정 필요",
+    "smtp_setting_required": "이메일 SMTP 설정 필요",
     "adsense_setting": "애드센스 설정",
+<<<<<<< HEAD
     "google_email": "Google 이메일 주소",
+=======
+    "smtp_username": "SMTP 아이디",
+>>>>>>> 2347c8d... Make smtp server configuarable
     "previous": "이전",
     "name_or_ip_or_regex": "사용자 이름 혹은 IP 주소 혹은 정규표현식",
     "editor": "편집자",
@@ -262,7 +269,7 @@
     "count": "기여 횟수",
     "main_head": "메인 <HEAD>",
     "recent_ban": "최근 차단",
-    "google_app_password": "Google 앱 비밀번호",
+    "smtp_password": "SMTP Password",
     "id_filter_list": "ID 필터 목록",
     "other": "기타",
     "edit": "편집",

+ 37 - 9
route/setting.py

@@ -163,9 +163,15 @@ def setting_2(conn, num):
                         <input type="checkbox" name="reg" ''' + check_box_div[0] + '''> ''' + load_lang('no_register') + '''
                         <hr>
                         <input type="checkbox" name="ip_view" ''' + check_box_div[1] + '''> ''' + load_lang('hide_ip') + '''
+<<<<<<< HEAD
                         <hr>
                         <input type="checkbox" name="email_have" ''' + check_box_div[2] + '''> ''' + load_lang('email_required') + ' <a href="/setting/6">(' + load_lang('google_imap_required') + ''')</a>
                         <hr>
+=======
+                        <hr class=\"main_hr\">
+                        <input type="checkbox" name="email_have" ''' + check_box_div[2] + '''> ''' + load_lang('email_required') + ' <a href="/setting/6">(' + load_lang('smtp_setting_required') + ''')</a>
+                        <hr class=\"main_hr\">
+>>>>>>> 2347c8d... Make smtp server configuarable
                         <input type="checkbox" name="requires_approval" ''' + check_box_div[3] + '''> ''' + load_lang('requires_approval') + '''
                         <hr>
                         <span>''' + load_lang('wiki_host') + '''</span>
@@ -456,16 +462,16 @@ def setting_2(conn, num):
         i_list = [
             'recaptcha',
             'sec_re',
-            'g_email',
-            'g_pass'
+            'smtp_server',
+            'smtp_port',
+            'smtp_security',
+            'smtp_email',
+            'smtp_pass'
         ]
 
         if flask.request.method == 'POST':
             for data in i_list:
-                if data == 'g_email':
-                    into_data = re.sub('@.*$', '', flask.request.form.get(data, ''))
-                else:
-                    into_data = flask.request.form.get(data, '')
+                into_data = flask.request.form.get(data, '')
 
                 curs.execute(db_change("update other set data = ? where name = ?"), [into_data, data])
 
@@ -493,6 +499,10 @@ def setting_2(conn, num):
 
             conn.commit()
 
+            security_radios = ''
+            for i in ['tls', 'starttls', 'plain']:
+                security_radios += '<input name="smtp_security" type="radio" value="' + i + '" ' + ('checked' if d_list[4] == i else '') + '>' + i + '<hr class="main_hr">'
+
             return easy_minify(flask.render_template(skin_check(),
                 imp = ['Google', wiki_set(), custom(), other2([0, 0])],
                 data = '''
@@ -506,14 +516,32 @@ def setting_2(conn, num):
                         <hr class=\"main_hr\">
                         <input name="sec_re" value="''' + html.escape(d_list[1]) + '''">
                         <hr class=\"main_hr\">
-                        <h2><a href="https://support.google.com/mail/answer/7126229">''' + load_lang('google_imap') + '</a> (' + load_lang('restart_required') + ''')</h1>
-                        <span>''' + load_lang('google_email') + '''</span>
+                        <h2>''' + load_lang('smtp_setting') + ' (' + load_lang('restart_required') + ''')</h1>
+                        <span>''' + load_lang('smtp_server') + '''</span>
+                        <hr class=\"main_hr\">
+                        <input name="smtp_server" value="''' + html.escape(d_list[2]) + '''">
                         <hr class=\"main_hr\">
+                        <span>''' + load_lang('smtp_port') + '''</span>
+                        <hr class=\"main_hr\">
+                        <input name="smtp_port" value="''' + html.escape(d_list[3]) + '''">
+                        <hr class=\"main_hr\">
+                        <span>''' + load_lang('smtp_security') + '''</span>
+                        <hr class=\"main_hr\">'''
+                        + security_radios +
+                        '''<hr class=\"main_hr\">
+                        <span>''' + load_lang('smtp_username') + '''</span>
+                        <hr class=\"main_hr\">
+<<<<<<< HEAD
                         <input name="g_email" value="''' + html.escape(d_list[2]) + '''">
                         <hr>
                         <span><a href="https://security.google.com/settings/security/apppasswords">''' + load_lang('google_app_password') + '''</a></span>
+=======
+                        <input name="smtp_email" value="''' + html.escape(d_list[5]) + '''">
+                        <hr class=\"main_hr\">
+                        <span>''' + load_lang('smtp_password') + '''</span>
+>>>>>>> 2347c8d... Make smtp server configuarable
                         <hr class=\"main_hr\">
-                        <input type="password" name="g_pass" value="''' + html.escape(d_list[3]) + '''">
+                        <input type="password" name="smtp_pass" value="''' + html.escape(d_list[6]) + '''">
                         <hr class=\"main_hr\">
                         <button id="save" type="submit">''' + load_lang('save') + '''</button>
                     </form>

+ 33 - 12
route/tool/func.py

@@ -72,25 +72,46 @@ def load_conn(data):
     load_conn2(data)
 
 def send_email(who, title, data):
-    smtp = smtplib.SMTP_SSL('smtp.gmail.com', 465)
-
     try:
-        curs.execute(db_change('select name, data from other where name = "g_email" or name = "g_pass"'))
+        curs.execute(db_change('select name, data from other where name = "smtp_email" or name = "smtp_pass" or name = "smtp_server" or name = "smtp_port" or name = "smtp_security"'))
         rep_data = curs.fetchall()
+
+        smtp_email = ''
+        smtp_pass = ''
+        smtp_server = ''
+        smtp_security = ''
+        smtp_port = ''
+        smtp = ''
+
         if rep_data:
-            g_email = ''
-            g_pass = ''
+            smtp_email = ''
+            smtp_pass = ''
             for i in rep_data:
-                if i[0] == 'g_email':
-                    g_email = i[1]
-                else:
-                    g_pass = i[1]
-
-            smtp.login(g_email, g_pass)
+                if i[0] == 'smtp_email':
+                    smtp_email = i[1]
+                elif i[0] == 'smtp_pass':
+                    smtp_pass = i[1]
+                elif i[0] == 'smtp_server':
+                    smtp_server = i[1]
+                elif i[0] == 'smtp_security':
+                    smtp_security = i[1]
+                elif i[0] == 'smtp_port':
+                    smtp_port = i[1]
+            
+            smtp_port = int(smtp_port)
+            if smtp_security == 'plain':
+                smtp = smtplib.SMTP(smtp_server, smtp_port)
+            elif smtp_security == 'starttls':
+                smtp = smtplib.SMTP(smtp_server, smtp_port)
+                smtp.starttls()
+            else: #if smtp_security == 'tls':
+                smtp = smtplib.SMTP_SSL(smtp_server, smtp_port)
+            
+            smtp.login(smtp_email, smtp_pass)
 
         msg = email.mime.text.MIMEText(data)
         msg['Subject'] = title
-        smtp.sendmail(g_email, who, msg.as_string())
+        smtp.sendmail(smtp_email, who, msg.as_string())
 
         smtp.quit()
     except: