diff options
| author | 2011-05-27 22:52:24 +0200 | |
|---|---|---|
| committer | 2011-05-27 22:52:24 +0200 | |
| commit | 3254a85595dd27a96862d8d7b932c03ade166f95 (patch) | |
| tree | 969bd75d09550da32792c2537e8d6e9f0101386e | |
| parent | fixes last commit (diff) | |
| download | pyload-3254a85595dd27a96862d8d7b932c03ade166f95.tar.xz | |
change password in webif
| -rw-r--r-- | module/database/UserDatabase.py | 6 | ||||
| -rw-r--r-- | module/network/HTTPDownload.py | 8 | ||||
| -rw-r--r-- | module/plugins/hoster/FilesonicCom.py | 11 | ||||
| -rw-r--r-- | module/plugins/hoster/RealdebridCom.py | 20 | ||||
| -rw-r--r-- | module/web/json_app.py | 10 | ||||
| -rw-r--r-- | module/web/templates/default/admin.html | 224 | ||||
| -rw-r--r-- | module/web/templates/default/settings.html | 2 | ||||
| -rwxr-xr-x | pyLoadCore.py | 4 | 
8 files changed, 213 insertions, 72 deletions
| diff --git a/module/database/UserDatabase.py b/module/database/UserDatabase.py index 11bdbabc0..0e3011593 100644 --- a/module/database/UserDatabase.py +++ b/module/database/UserDatabase.py @@ -71,9 +71,9 @@ class UserMethods():      @style.queue -    def changePw(db, user, oldpw, newpw): +    def changePassword(db, user, oldpw, newpw): -        db.c.execute('SELECT id, name, password, role, permission, template FROM "users" WHERE name=?', (user, )) +        db.c.execute('SELECT id, name, password FROM users WHERE name=?', (user, ))          r = db.c.fetchone()          if not r:              return False @@ -118,10 +118,8 @@ class UserMethods():          return user -          @style.queue      def removeUser(db, user):          db.c.execute('DELETE FROM users WHERE name=?', (user, )) -      DatabaseBackend.registerSub(UserMethods) diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py index 40e2e69e1..603fea7a8 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -124,6 +124,14 @@ class HTTPDownload():          try:              self._download(chunks, resume) +        except pycurl.error, e: +            #code 33 - no resume +            code = e.args[0] +            if code == 33: +                # try again without resume +                return self._download(chunks, False) +            else: +                raise e          finally:              self.close() diff --git a/module/plugins/hoster/FilesonicCom.py b/module/plugins/hoster/FilesonicCom.py index 8862c84e0..6aabcc277 100644 --- a/module/plugins/hoster/FilesonicCom.py +++ b/module/plugins/hoster/FilesonicCom.py @@ -62,8 +62,8 @@ class FilesonicCom(Hoster):      CAPTCHA_TYPE1_PATTERN = r'Recaptcha.create\("(.*?)",'
      CAPTCHA_TYPE2_PATTERN = r'id="recaptcha_image"><img style="display: block;" src="(.+)image?c=(.+?)"'
 -    def init(self): -        if self.account: +    def init(self):
 +        if self.account:
              self.premium = self.account.getAccountInfo(self.user)["premium"]
          if not self.premium:
              self.chunkLimit = 1
 @@ -94,8 +94,11 @@ class FilesonicCom(Hoster):                  self.offline()
              if item["is_password_protected"] != 0:
                  self.fail("This file is password protected")
 -            if item["is_premium_only"] != 0 and not self.premium:
 -                self.fail("need premium account for file")
 +
 +            # ignored this check due to false api information
 +            #if item["is_premium_only"] != 0 and not self.premium:
 +            #    self.fail("need premium account for file")
 +
              self.pyfile.name=item["filename"]
              # Fix the url and resolve the domain to the correct regional variation
 diff --git a/module/plugins/hoster/RealdebridCom.py b/module/plugins/hoster/RealdebridCom.py index d86259c4c..47bd5e4db 100644 --- a/module/plugins/hoster/RealdebridCom.py +++ b/module/plugins/hoster/RealdebridCom.py @@ -3,6 +3,8 @@  import re
  from urllib import quote, unquote
 +from random import randrange
 +
  from module.plugins.Hoster import Hoster
  class RealdebridCom(Hoster):
 @@ -16,7 +18,13 @@ class RealdebridCom(Hoster):      __author_mail__ = ("naibaf_11@yahoo.de")
      def getFilename(self, url):
 -        return unquote(url.rsplit("/", 1)[1])
 +        try:
 +            name = unquote(url.rsplit("/", 1)[1])
 +        except IndexError:
 +            name = "Unknown_Filename..."
 +        if name.endswith("..."): #incomplete filename, append random stuff
 +            name += "%s.tmp" % randrange(100,999)
 +        return name
      def setup(self):
          self.chunkLimit = 3
 @@ -57,12 +65,10 @@ class RealdebridCom(Hoster):          self.log.debug("Real-Debrid: New URL: %s" % new_url)
 -        try:
 -            if pyfile.name.startswith("http") or pyfile.name.startswith("Unknown"):
 -                #only use when name wasnt already set
 -                pyfile.name = self.getFilename(new_url)
 -        except IndexError:
 -            pyfile.name = "Unknown_Filename.ext"
 +
 +        if pyfile.name.startswith("http") or pyfile.name.startswith("Unknown"):
 +            #only use when name wasnt already set
 +            pyfile.name = self.getFilename(new_url)
          self.download(new_url, disposition=True)
 diff --git a/module/web/json_app.py b/module/web/json_app.py index 738f5ac63..39cd81f5f 100644 --- a/module/web/json_app.py +++ b/module/web/json_app.py @@ -415,6 +415,16 @@ def update_accounts():              deleted.append((plugin,user))              PYLOAD.remove_account(plugin, user) +@route("/json/change_password", method="POST") +def change_password(): + +    user = request.POST["user_login"] +    oldpw = request.POST["login_current_password"] +    newpw = request.POST["login_new_password"] + +    if not PYLOAD.change_password(user, oldpw, newpw): +        print "Wrong password" +        return HTTPError()  @route("/json/filemanager/rename", method="POST")  @login_required('filemanager') diff --git a/module/web/templates/default/admin.html b/module/web/templates/default/admin.html index 365e9b7bc..7b9a8b32d 100644 --- a/module/web/templates/default/admin.html +++ b/module/web/templates/default/admin.html @@ -1,64 +1,178 @@  {% extends 'default/base.html' %} +{% block head %} +    <script type="text/javascript"> + +        var password_dialog; + +        function show_password_dialog() { +            bg_show(); +            $("password_box").setStyle('display', 'block'); +            password_dialog.start('opacity', 1) +        } + +        function hide_password_dialog() { +            bg_hide(); +            password_dialog.start('opacity', 0).chain(function() { +                $('password_box').setStyle('display', 'none'); +            }); +        } + +        window.addEvent("domready", function() { + +            password_dialog = new Fx.Tween($("password_box")); + +            $("login_password_reset").addEvent("click", hide_password_dialog); +            $("login_password_button").addEvent("click", function(e) { + +                var current = $("login_current_password").get("value"); +                var newpw = $("login_new_password").get("value"); +                var newpw2 = $("login_new_password2").get("value"); + +                if (newpw == newpw2) { +                    var form = $("password_form"); + +                    form.set("send", { +                                onSuccess: function(data) { +                                    notify.alert("Success", { +                                            'className': 'success' +                                        }); +                                }, +                                onFailure: function(data) { +                                    notify.alert("Error", { +                                            'className': 'error' +                                        }); +                    }}); + +                    form.send(); + +                    hide_password_dialog(); +                } else { +                    alert("{{_("Passwords did not match.")}}"); +                } +                e.stop(); +            }); + +            $$(".change_password").each(function(item) { +                var id = item.get("id"); +                var user = id.split("|")[1]; +                $("user_login").set("value", user); + +                item.addEvent("click", function(e) { +                    show_password_dialog(); +                }); +            }); +        }); +    </script> +{% endblock %} + +  {% block title %}{{ _("Administrate User") }} - {{ super() }} {% endblock %}  {% block subtitle %}{{ _("Administrate User") }}{% endblock %}  {% block content %} -{{ _("Note: You can only change permissions for webinterface.") }} -{{ _("To add user or change passwords use:") }} <b>python pyLoadCore.py -u</b><br> -{{ _("Important: Admin user have always all permissions! Only Admin user can use other clients like CLI and GUI.") }} - -<form action="" method="POST"> -<table class="settable wide"> -    <thead style="font-size: 11px"> -    <th> -        {{ _("Name") }} -    </th> -    <th> -        {{ _("Admin") }} -    </th> -    <th> -        {{ _("Add downloads") }} -    </th> -    <th> -        {{ _("Delete downloads") }} -    </th> -    <th> -        {{ _("Change server status") }} -    </th> -    <th> -        {{ _("See queue/collector") }} -    </th> -    <th> -        {{ _("Download from webinterface") }} -    </th> -    <th> -        {{ _("Change settings") }} -    </th> -    <th> -        {{ _("Filemanager") }} -    </th> -    </thead> - -{% for name, data in users.iteritems() %} -    <tr> -        <td>{{name}}</td> -        <td><input name="{{ name }}|admin" type="checkbox" {% if data.perms.admin %} checked="True" {% endif %}"></td> -        <td><input name="{{ name }}|add" type="checkbox" {% if data.perms.add %} checked="True" {% endif %}"></td> -        <td><input name="{{ name }}|delete" type="checkbox" {% if data.perms.delete %} checked="True" {% endif %}"></td> -        <td><input name="{{ name }}|status" type="checkbox" {% if data.perms.status %} checked="True" {% endif %}"></td> -        <td><input name="{{ name }}|see_downloads" type="checkbox" {% if data.perms.see_downloads %} checked="True" {% endif %}"></td> -        <td><input name="{{ name }}|download" type="checkbox" {% if data.perms.download %} checked="True" {% endif %}"></td> -        <td><input name="{{ name }}|settings" type="checkbox" {% if data.perms.settings %} checked="True" {% endif %}"></td> -	<td><input name="{{ name }}|filemanager" type="checkbox" {% if data.perms.filemanager %} checked="True" {% endif %}"></td> -    </tr> -{% endfor %} - - -</table> - -<button class="styled_button" type="submit">{{ _("Submit") }}</button> -</form> +    {{ _("Note: You can only change permissions for webinterface.") }} +    {{ _("To add user or change passwords use:") }} <b>python pyLoadCore.py -u</b><br> +    {{ _("Important: Admin user have always all permissions! Only Admin user can use other clients like CLI and GUI.") }} + +    <form action="" method="POST"> +        <table class="settable wide"> +            <thead style="font-size: 11px"> +            <th> +                {{ _("Name") }} +            </th> +            <th> +                {{ _("Change Password") }} +            </th> +            <th> +                {{ _("Admin") }} +            </th> +            <th> +                {{ _("Add downloads") }} +            </th> +            <th> +                {{ _("Delete downloads") }} +            </th> +            <th> +                {{ _("Change server status") }} +            </th> +            <th> +                {{ _("See queue/collector") }} +            </th> +            <th> +                {{ _("Download from webinterface") }} +            </th> +            <th> +                {{ _("Change settings") }} +            </th> +            <th> +                {{ _("Filemanager") }} +            </th> +            </thead> + +            {% for name, data in users.iteritems ( ) %} +                <tr> +                    <td>{{ name }}</td> +                    <td><a class="change_password" href="#" id="change_pw|{{name}}">{{ _("change") }}</a></td> +                    <td><input name="{{ name }}|admin" type="checkbox" {% if data.perms.admin %} +                               checked="True" {% endif %}"></td> +                    <td><input name="{{ name }}|add" type="checkbox" {% if data.perms.add %} checked="True" {% endif %} +                        "></td> +                    <td><input name="{{ name }}|delete" type="checkbox" {% if data.perms.delete %} +                               checked="True" {% endif %}"></td> +                    <td><input name="{{ name }}|status" type="checkbox" {% if data.perms.status %} +                               checked="True" {% endif %}"></td> +                    <td><input name="{{ name }}|see_downloads" type="checkbox" {% if data.perms.see_downloads %} +                               checked="True" {% endif %}"></td> +                    <td><input name="{{ name }}|download" type="checkbox" {% if data.perms.download %} +                               checked="True" {% endif %}"></td> +                    <td><input name="{{ name }}|settings" type="checkbox" {% if data.perms.settings %} +                               checked="True" {% endif %}"></td> +                    <td><input name="{{ name }}|filemanager" type="checkbox" {% if data.perms.filemanager %} +                               checked="True" {% endif %}"></td> +                </tr> +            {% endfor %} + + +        </table> + +        <button class="styled_button" type="submit">{{ _("Submit") }}</button> +    </form> + + +    <div id="password_box" class="myform window_box" style="z-index: 2"> +        <form id="password_form" action="/json/change_password" method="POST" enctype="multipart/form-data"> +            <h1>{{ _("Change Password") }}</h1> + +            <p>{{ _("Enter your current and desired Password.") }}</p> +            <label for="user_login">{{ _("User") }} +                <span class="small">{{ _("Your username.") }}</span> +            </label> +            <input id="user_login" name="user_login" type="text" size="20"/> + +            <label for="login_current_password">{{ _("Current password") }} +                <span class="small">{{ _("The password for this account.") }}</span> +            </label> +            <input id="login_current_password" name="login_current_password" type="password" size="20"/> + +            <label for="login_new_password">{{ _("New password") }} +                <span class="small">{{ _("The new password.") }}</span> +            </label> +            <input id="login_new_password" name="login_new_password" type="password" size="20"/> + +            <label for="login_new_password2">{{ _("New password (repeat)") }} +                <span class="small">{{ _("Please repeat the new password.") }}</span> +            </label> +            <input id="login_new_password2" name="login_new_password2" type="password" size="20"/> + + +            <button id="login_password_button" type="submit">{{ _("Submit") }}</button> +            <button id="login_password_reset" style="margin-left: 0" type="reset">{{ _("Reset") }}</button> +            <div class="spacer"></div> + +        </form> + +    </div>  {% endblock %}
\ No newline at end of file diff --git a/module/web/templates/default/settings.html b/module/web/templates/default/settings.html index 4c8f0d63e..a74fe4261 100644 --- a/module/web/templates/default/settings.html +++ b/module/web/templates/default/settings.html @@ -215,7 +215,7 @@  <input id="account_login" name="account_login" type="text" size="20" />  <label for="account_password">{{_("Password")}} -<span class="small">The password for this account.</span> +<span class="small">{{_("The password for this account.")}}</span>  </label>  <input id="account_password" name="account_password" type="password" size="20" /> diff --git a/pyLoadCore.py b/pyLoadCore.py index d9f795026..593fb046e 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -859,10 +859,12 @@ class ServerMethods():          return self.core.db.getAllUserData()      def set_user_permission(self, user, permission, role): -          self.core.db.setPermission(user, permission)          self.core.db.setRole(user, role) +    def change_password(self, user, oldpw, newpw): +        return self.core.db.changePassword(user, oldpw, newpw) +  def deamon():      try: | 
