diff --git a/src/master/bugreporter.py b/src/master/bugreporter.py new file mode 100644 index 0000000..de1c1c0 --- /dev/null +++ b/src/master/bugreporter.py @@ -0,0 +1,53 @@ +from master.settings import settings +import smtplib +from utils.log import logger +from utils import env +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart +from email.header import Header +from datetime import datetime +import json + +def send_bug_mail(username, bugmessage): + #admin_email_address = env.getenv('ADMIN_EMAIL_ADDRESS') + nulladdr = ['\'\'', '\"\"', ''] + email_from_address = settings.get('EMAIL_FROM_ADDRESS') + admin_email_address = settings.get('ADMIN_EMAIL_ADDRESS') + logger.info("receive bug from %s: %s" % (username, bugmessage)) + if (email_from_address in nulladdr or admin_email_address in nulladdr): + return {'success': 'false'} + #text = 'Dear '+ username + ':\n' + ' Your account in docklet has been activated' + text = '

Dear '+ 'admin' + ':

' + text += '''

      A bug has been report by %s.

+
+   %s   +
+

      Please check it !

+

+

Docklet Team, SEI, PKU

+ ''' % (username, bugmessage) + text += '

'+ str(datetime.utcnow()) + '

' + text += '' + subject = 'A bug of Docklet has been reported' + if admin_email_address[0] == '"': + admins_addr = admin_email_address[1:-1].split(" ") + else: + admins_addr = admin_email_address.split(" ") + alladdr="" + for addr in admins_addr: + alladdr = alladdr+addr+", " + alladdr=alladdr[:-2] + msg = MIMEMultipart() + textmsg = MIMEText(text,'html','utf-8') + msg['Subject'] = Header(subject, 'utf-8') + msg['From'] = email_from_address + msg['To'] = alladdr + msg.attach(textmsg) + s = smtplib.SMTP() + s.connect() + try: + s.sendmail(email_from_address, admins_addr, msg.as_string()) + except Exception as e: + logger.error(e) + s.close() + return {'success':'true'} diff --git a/user/user.py b/user/user.py index 9a38c7f..522aa93 100755 --- a/user/user.py +++ b/user/user.py @@ -34,6 +34,7 @@ from utils.model import User,db from httplib2 import Http from urllib.parse import urlencode from master.settings import settings +from master.bugreporter import send_bug_mail external_login = env.getenv('EXTERNAL_LOGIN') if(external_login == 'TRUE'): @@ -472,6 +473,13 @@ def query_self_notifications_infos(cur_user, user, form): result = G_notificationmgr.query_self_notifications_infos(cur_user=cur_user, form=form) return json.dumps(result) +@app.route("/bug/report/", methods=['POST']) +@login_required +def report_bug(cur_user, user, form): + logger.info("handle request: bug/report") + result = send_bug_mail(user, form.get("bugmessage", None)) + return json.dumps(result) + @app.route("/billing/beans/", methods=['POST']) @auth_key_required def billing_beans(): diff --git a/web/templates/addCluster.html b/web/templates/addCluster.html index 8d24c24..1a7b8ca 100644 --- a/web/templates/addCluster.html +++ b/web/templates/addCluster.html @@ -81,7 +81,7 @@ {{image['name']}} private {{user}} - {{image['description']}} + {{image['description']}}
{% endfor %} @@ -91,7 +91,7 @@ {{image['name']}} public {{p_user}} - {{image['description']}} + {{image['description']}}
{% endfor %} diff --git a/web/templates/base_AdminLTE.html b/web/templates/base_AdminLTE.html index ae6ff14..8e6d747 100644 --- a/web/templates/base_AdminLTE.html +++ b/web/templates/base_AdminLTE.html @@ -109,6 +109,23 @@ +
  • Help
  • @@ -220,10 +237,10 @@ diff --git a/web/templates/home.template b/web/templates/home.template index f064358..8e6ccf7 100755 --- a/web/templates/home.template +++ b/web/templates/home.template @@ -38,12 +38,12 @@
    - Docklet Cloud OS + Docklet Cloud OS
    diff --git a/web/templates/opsuccess.html b/web/templates/opsuccess.html index f2bbc84..4783ae0 100644 --- a/web/templates/opsuccess.html +++ b/web/templates/opsuccess.html @@ -19,6 +19,9 @@

    SUCCESS



    +
    {{message}}
    +
    +
    Click Here Back To The Workspace {% endblock %} diff --git a/web/web.py b/web/web.py index db5bf77..ceab7f4 100755 --- a/web/web.py +++ b/web/web.py @@ -36,6 +36,7 @@ from webViews.admin import * from webViews.monitor import * from webViews.beansapplication import * from webViews.cloud import * +from webViews.reportbug import * from webViews.authenticate.auth import login_required, administration_required,activated_required from webViews.authenticate.register import registerView from webViews.authenticate.login import loginView, logoutView @@ -112,13 +113,18 @@ def dashboard(): @app.route("/document/", methods=['GET']) def redirect_dochome(): - return redirect("http://unias.github.io/docklet/userguide") + return redirect("https://unias.github.io/docklet/userguide/") @app.route("/config/", methods=['GET']) @login_required def config(): return configView.as_view() +@app.route("/bug/report/", methods=['POST']) +@login_required +def reportBug(): + reportBugView.bugmessage = request.form['bugmessage'] + return reportBugView.as_view() @app.route("/workspace/create/", methods=['GET']) #@activated_required @@ -601,7 +607,6 @@ def adminpage(): def updatesettings(): return updatesettingsView.as_view() - @app.route('/index/', methods=['GET']) def jupyter_control(): return redirect('/dashboard/') diff --git a/web/webViews/dockletrequest.py b/web/webViews/dockletrequest.py index 8a48790..1d6084d 100644 --- a/web/webViews/dockletrequest.py +++ b/web/webViews/dockletrequest.py @@ -38,7 +38,8 @@ class dockletRequest(): 'user', 'beans', 'notification', - 'settings' + 'settings', + 'bug' } if ":" not in endpoint: endpoint = "http://"+endpoint+":"+master_port diff --git a/web/webViews/reportbug.py b/web/webViews/reportbug.py new file mode 100644 index 0000000..02669d7 --- /dev/null +++ b/web/webViews/reportbug.py @@ -0,0 +1,16 @@ +from flask import session,render_template,request,redirect +from webViews.view import normalView +from webViews.dockletrequest import dockletRequest + + +class reportBugView(normalView): + template_path = "opsuccess.html" + + @classmethod + def get(self): + dockletRequest.post("/bug/report/", {'bugmessage': self.bugmessage}) + return self.render(self.template_path, message="Thank You!") + + @classmethod + def post(self): + return self.get()