diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f8f61d0..edb456d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ -image: ofalk/centos7-python36 +image: docker.io/ofalk/fedora28-python3 before_script: - - virtualenv -p python3.6 /tmp/.virtualenv + - virtualenv-3 -p python3 /tmp/.virtualenv - source /tmp/.virtualenv/bin/activate - pip install Pillow - pip install -r requirements.txt diff --git a/README.md b/README.md index e2ea9a9..20995ca 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,25 @@ +ivatar / libravatar +=================== + +Pipeline and coverage status +============================ + [![pipeline status](https://git.linux-kernel.at/oliver/ivatar/badges/master/pipeline.svg)](https://git.linux-kernel.at/oliver/ivatar/commits/master) [![coverage report](https://git.linux-kernel.at/oliver/ivatar/badges/master/coverage.svg)](http://git.linux-kernel.at/oliver/ivatar/commits/master) +Reports / code documentation +============================ + - [Coverage HTML report](http://oliver.git.linux-kernel.at/ivatar) - [Code documentation (autogenerated, pycco)](http://oliver.git.linux-kernel.at/ivatar/pycco/) + +Authors and contributors +======================== + +Lead developer/Owner: Oliver Falk (aka ofalk or falko) - https://git.linux-kernel.at/oliver +Operations: Michal Novotny (aka clime) +QA: Tristan Le Guern (aka tleguern) +Frontend developer: Niklas Poslovski (aka nipos) +Organisation/Meeting moderation: Lars Kruse (aka sumpfralle) + +Initial developer: François Marier - https://fmarier.org/ diff --git a/config.py b/config.py index bdadc3c..71207dc 100644 --- a/config.py +++ b/config.py @@ -187,3 +187,7 @@ CACHES = { ], } } + +# This is 5 minutes caching for generated/resized images, +# so the sites don't hit ivatar so much +CACHE_IMAGES_MAX_AGE = 5 * 60 diff --git a/ivatar/ivataraccount/templates/upload_photo.html b/ivatar/ivataraccount/templates/upload_photo.html index 4eb3e7b..19177b5 100644 --- a/ivatar/ivataraccount/templates/upload_photo.html +++ b/ivatar/ivataraccount/templates/upload_photo.html @@ -28,13 +28,13 @@
- +
- +
diff --git a/ivatar/ivataraccount/views.py b/ivatar/ivataraccount/views.py index 40c3d0b..62ac7c9 100644 --- a/ivatar/ivataraccount/views.py +++ b/ivatar/ivataraccount/views.py @@ -816,12 +816,16 @@ class UploadLibravatarExportView(SuccessMessageMixin, FormView): def form_valid(self, form): data = self.request.FILES['export_file'] - items = libravatar_read_gzdata(data.read()) - # DEBUG print(items) - return render(self.request, 'choose_libravatar_export.html', { - 'emails': items['emails'], - 'photos': items['photos'], - }) + try: + items = libravatar_read_gzdata(data.read()) + # DEBUG print(items) + return render(self.request, 'choose_libravatar_export.html', { + 'emails': items['emails'], + 'photos': items['photos'], + }) + except Exception as e: + messages.error(self.request, _('Unable to parse file: %s' % e)) + return HttpResponseRedirect(reverse_lazy('upload_export')) @method_decorator(login_required, name='dispatch') @@ -914,7 +918,7 @@ class PasswordResetView(PasswordResetViewOriginal): try: confirmed_email = ConfirmedEmail.objects.get(email=request.POST['email']) confirmed_email.user.email = confirmed_email.email - if not confirmed_email.user.password: + if not confirmed_email.user.password or confirmed_email.user.password == '!': random_pass = User.objects.make_random_password() confirmed_email.user.set_pasword(random_pass) confirmed_email.user.save() diff --git a/ivatar/static/css/clime.css b/ivatar/static/css/clime.css new file mode 100644 index 0000000..b067de9 --- /dev/null +++ b/ivatar/static/css/clime.css @@ -0,0 +1 @@ +body{font-family:'Source Sans Pro',Helvetica,Arial,sans-serif;color:#525252}.btn{border-bottom-width:3px;box-sizing:border-box;font-family:'Montserrat',sans-serif;text-transform:uppercase;background:#ff4400;overflow:hidden;position:relative;-webkit-transition:all .3s;-moz-transition:all .3s;-ms-transition:all .3s;transition:all .3s}.btn.btn-default{color:#ff6933;border-color:#ff6933;background:none}.btn.btn-primary{border-color:#b33000}.btn:hover,.btn:active,.btn:focus{background:none;border-color:#cc3600;color:#cc3600}.btn:hover:after,.btn:active:after,.btn:focus:after{top:50%}.btn:after{content:'';position:absolute;z-index:-1;width:150%;height:200%;top:-190%;left:50%;background:#ff8f66;-webkit-transform:translateX(-50%) translateY(-50%) skew(0, 5deg);-moz-transform:translateX(-50%) translateY(-50%) skew(0, 5deg);-ms-transform:translateX(-50%) translateY(-50%) skew(0, 5deg);transform:translateX(-50%) translateY(-50%) skew(0, 5deg);-webkit-transition:all .5s ease-out;-moz-transition:all .5s ease-out;-ms-transition:all .5s ease-out;transition:all .5s ease-out}.btn.btn-block:after{height:250%;width:200%;-webkit-transform:translateX(-50%) translateY(-50%) skew(0, 2deg);-moz-transform:translateX(-50%) translateY(-50%) skew(0, 2deg);-ms-transform:translateX(-50%) translateY(-50%) skew(0, 2deg);transform:translateX(-50%) translateY(-50%) skew(0, 2deg)}.hero{background-color:#ff4400;color:#fff;padding:90px 0 40px}.hero h1{font-weight:600;font-size:6em;color:rgba(255,255,255,0.5)}.hero h2{font-weight:200;font-size:30px;margin-bottom:30px}.hero small{color:rgba(0,0,0,0.4)}.hero .btn{display:inline-block}.hero .btn.btn-default{color:#ff9670;border-color:#ff9670;background:none}.hero .btn.btn-primary{border-color:#fff}.hero .btn:hover,.hero .btn:active,.hero .btn:focus{border-color:#fff;color:#992900}.hero .btn:after{background:rgba(255,255,255,0.5)}.hero .container{position:relative;z-index:10}.social{background-color:#ff4400;padding:30px 0 140px}.social ul{list-style:none;padding:0;margin:0}.social ul li{float:left;margin-right:15px;width:100px}.clipper,.clipper-footer{background-color:#fff;height:110px;width:100%;position:relative;top:-40px;-webkit-transform:skew(0, 2deg);-moz-transform:skew(0, 2deg);-ms-transform:skew(0, 2deg);transform:skew(0, 2deg);pointer-events:none;z-index:1}.clipper-footer{top:0}section.content{position:relative;top:-100px;margin-bottom:-100px;z-index:10}section.content h1,section.content h2,section.content h3,section.content h4,section.content h5,section.content h6{color:#cc3600}section.content h2{font-weight:200;font-size:40px}section.content section{margin-bottom:20px;margin-top:20px}section.content .container>hr{-webkit-transform:skew(0, 2deg);-moz-transform:skew(0, 2deg);-ms-transform:skew(0, 2deg);transform:skew(0, 2deg);margin-top:80px;margin-bottom:40px}footer{background-color:#dddddd;color:#888888;padding:100px 0 40px;margin-top:-40px}footer .pull-left{margin-right:20px}footer .logo{float:left;display:inline-block;margin-right:5px;margin-top:-8px}footer .logo .circle{stroke:#888888;stroke-width:7;fill:none}footer .logo .polygon{fill:#888888}@media (max-width:768px){.hero{padding:50px 0 30px}.hero h1{font-size:4em}.social{padding:30px 0 100px}.btn{margin-bottom:5px}section.content section{margin-bottom:50px}}.color{display:inline-block;border-radius:50%;height:20px;width:20px}.color.blue{background-color:#36b7d7}.color.green{background-color:#3aa850}.color.red{background-color:#f7645e}.color.black{background-color:#525252}.navbar-tortin{border:0;background-color:#ff4400;color:#FFFFFF;border-radius:0}.form-control{border-bottom-width:3px;box-sizing:border-box;font-family:'Montserrat',sans-serif;overflow:hidden;position:relative;-webkit-transition:all .3s;-moz-transition:all .3s;-ms-transition:all .3s;transition:all .3s;border-color:#ff6933;background:none}.form-control:focus{border-color:#cc3600;box-shadow:none}.navbar-tortin .navbar-brand,.navbar-tortin .navbar-text,.navbar-tortin .navbar-nav>li>a,.navbar-tortin .navbar-link,.navbar-tortin .btn-link{color:#FFFFFF}.navbar-tortin .navbar-nav>.active>a,.navbar-tortin .navbar-nav>.active>a:focus,.navbar-tortin .navbar-nav>.active>a:hover,.navbar-tortin .navbar-nav>li>a:focus,.navbar-tortin .navbar-nav>li>a:hover,.navbar-tortin .navbar-link:hover,.navbar-tortin .btn-link:focus,.navbar-tortin .btn-link:hover,.navbar-tortin .navbar-nav>.open>a,.navbar-tortin .navbar-nav>.open>a:focus,.navbar-tortin .navbar-nav>.open>a:hover{background-color:#cc3600}.navbar-tortin .navbar-toggle{border-color:#FFFFFF}.navbar-tortin .navbar-toggle:hover{background-color:#FFFFFF}.navbar-tortin .navbar-toggle .icon-bar{background-color:#FFFFFF}.navbar-tortin .navbar-toggle:hover .icon-bar{background-color:#ff4400}.navbar-tortin .navbar-collapse,.navbar-tortin .navbar-form{border:0}.dropdown-menu{background-color:#ff4400;border:1px solid #cc3600}.dropdown-menu>li>a{color:#FFFFFF}.dropdown-menu>li>a:focus,.dropdown-menu>li>a:hover{background-color:#cc3600;color:#FFFFFF}.checkbox input,.radio input{display:none}.checkbox input+label,.radio input+label{padding-left:0}.checkbox input+label:before,.radio input+label:before{font-family:FontAwesome;display:inline-block;letter-spacing:5px;font-size:20px;color:#ff4400;vertical-align:middle}.checkbox input+label:before{content:"\f0c8"}.checkbox input:checked+label:before{content:"\f14a"}.radio input+label:before{content:"\f10c"}.radio input:checked+label:before{content:"\f192"}.uploadbtn:before{position:absolute;left:0;right:0;text-align:center;content:"Select file";font-family:'Montserrat',sans-serif}.jcrop-holder>div>div:nth-child(1){outline-width:2px;outline-style:solid;outline-color:#ff4400}@media (max-width:767px){.navbar-tortin .navbar-nav .open .dropdown-menu>li>a{color:#FFFFFF}.navbar-tortin .navbar-nav .open .dropdown-menu>li>a:hover{background-color:#cc3600}.navbar-tortin .navbar-nav .open .dropdown-menu>.active>a,.navbar-tortin .navbar-nav .open .dropdown-menu>.active>a:focus,.navbar-tortin .navbar-nav .open .dropdown-menu>.active>a:hover{background-color:#cc3600}}.panel-tortin{border-color:#ff4400;border-bottom-width:3px}.panel-tortin>.panel-heading{color:#fff;background-color:#ff4400;border-color:#ff4400;font-family:'Montserrat',sans-serif}.panel-tortin>.panel-heading+.panel-collapse>.panel-body{border-top-color:#ff4400}.panel-tortin>.panel-heading .badge{color:#ff4400;background-color:#fff}.panel-tortin>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#ff4400}.alert.alert-danger{background-color:#FFFFFF;color:#f7645e;border-color:#f7645e;border-bottom-width:3px;box-sizing:border-box;font-family:'Montserrat',sans-serif;overflow:hidden;position:relative}.input-group-addon{border-bottom-width:3px;box-sizing:border-box;font-family:'Montserrat',sans-serif;overflow:hidden;position:relative;border-color:#ff6933;background:none;width:auto;height:36px}.radio{color:#ff4400}input[type="radio"]:checked+label{font-weight:bold}.btn{border-radius:0 !important}section.content h1,section.content h2,section.content h3,section.content h4,section.content h5,section.content h6{color:#ff4400} \ No newline at end of file diff --git a/ivatar/static/css/clime.less b/ivatar/static/css/clime.less new file mode 100644 index 0000000..9124cf4 --- /dev/null +++ b/ivatar/static/css/clime.less @@ -0,0 +1,10 @@ +@import 'tortin.less'; +@bg-hero:#ff4400; + +.btn { + border-radius: 0px !important; +} + +section.content h1, section.content h2, section.content h3, section.content h4, section.content h5, section.content h6 { + color: #ff4400; +} diff --git a/ivatar/test_views.py b/ivatar/test_views.py index dbed347..cc18515 100644 --- a/ivatar/test_views.py +++ b/ivatar/test_views.py @@ -61,5 +61,8 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods """ Test incorrect digest """ - response = self.client.get('/avatar/%s' % 'x'*65) - self.assertEqual(response.status_code, 200, 'no 200 ok?') + response = self.client.get('/avatar/%s' % 'x'*65, follow=True) + self.assertRedirects( + response=response, + expected_url='/static/img/deadbeef.png', + msg_prefix='Why does an invalid hash not redirect to deadbeef?') diff --git a/ivatar/tools/templates/check.html b/ivatar/tools/templates/check.html index 9e86eb4..9e80266 100644 --- a/ivatar/tools/templates/check.html +++ b/ivatar/tools/templates/check.html @@ -21,7 +21,7 @@
{% if mailurl %} -
+

MD5  

@@ -44,7 +44,7 @@ {% endif %} {% if openidurl %} -
+

SHA256  

diff --git a/ivatar/tools/templates/check_domain.html b/ivatar/tools/templates/check_domain.html index 560779b..be0f8ee 100644 --- a/ivatar/tools/templates/check_domain.html +++ b/ivatar/tools/templates/check_domain.html @@ -34,7 +34,6 @@
- {% if result %}

The following servers will be used for your domain

@@ -44,8 +43,8 @@
{% if result.avatar_server_http %} - -

{{result.avatar_server_http}}

+
+

http://{{result.avatar_server_http}}

{% if result.avatar_server_http_ipv4 %}
{{ result.avatar_server_http_ipv4 }}
@@ -66,8 +65,8 @@
{% if result.avatar_server_https %} - -

{{result.avatar_server_https}}

+
+

https://{{result.avatar_server_https}}

{% if result.avatar_server_https_ipv4 %}
{{ result.avatar_server_https_ipv4 }}
diff --git a/ivatar/tools/urls.py b/ivatar/tools/urls.py index 9605ed4..1a13b43 100644 --- a/ivatar/tools/urls.py +++ b/ivatar/tools/urls.py @@ -8,4 +8,5 @@ from . views import CheckView, CheckDomainView urlpatterns = [ # pylint: disable=invalid-name url('check/', CheckView.as_view(), name='tools_check'), url('check_domain/', CheckDomainView.as_view(), name='tools_check_domain'), + url('check_domain$', CheckDomainView.as_view(), name='tools_check_domain'), ] diff --git a/ivatar/urls.py b/ivatar/urls.py index 1609c9f..7ba926b 100644 --- a/ivatar/urls.py +++ b/ivatar/urls.py @@ -21,13 +21,10 @@ urlpatterns = [ # pylint: disable=invalid-name url( r'avatar/(?P\w{32})', AvatarImageView.as_view(), name='avatar_view'), + url(r'avatar/$', AvatarImageView.as_view(), name='avatar_view'), url( r'avatar/(?P\w*)', - TemplateView.as_view( - template_name='error.html', - extra_context={ - 'errormessage': 'Incorrect digest length', - })), + RedirectView.as_view(url='/static/img/deadbeef.png'), name='invalid_hash'), url( r'gravatarproxy/(?P\w*)', GravatarProxyView.as_view(), name='gravatarproxy'), diff --git a/ivatar/views.py b/ivatar/views.py index 4c3ca58..b8c2743 100644 --- a/ivatar/views.py +++ b/ivatar/views.py @@ -22,6 +22,7 @@ import pagan from robohash import Robohash from ivatar.settings import AVATAR_MAX_SIZE, JPEG_QUALITY, DEFAULT_AVATAR_SIZE +from ivatar.settings import CACHE_IMAGES_MAX_AGE from . ivataraccount.models import ConfirmedEmail, ConfirmedOpenId from . ivataraccount.models import pil_format, file_format @@ -58,6 +59,11 @@ class AvatarImageView(TemplateView): ''' # TODO: Do cache resize images!! Memcached? + def options(self, request, *args, **kwargs): # pylint: disable=too-many-branches,too-many-statements,too-many-locals,too-many-return-statements + response = HttpResponse("", content_type='text/plain') + response['Allow'] = "404 mm mp retro pagan wavatar monsterid robohash identicon" + return response + def get(self, request, *args, **kwargs): # pylint: disable=too-many-branches,too-many-statements,too-many-locals,too-many-return-statements ''' Override get from parent class @@ -142,9 +148,11 @@ class AvatarImageView(TemplateView): data = BytesIO() monsterdata.save(data, 'PNG', quality=JPEG_QUALITY) data.seek(0) - return HttpResponse( + response = HttpResponse( data, content_type='image/png') + response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE + return response if str(default) == 'robohash': roboset = 'any' @@ -155,9 +163,11 @@ class AvatarImageView(TemplateView): data = BytesIO() robohash.img.save(data, format='png') data.seek(0) - return HttpResponse( + response = HttpResponse( data, content_type='image/png') + response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE + return response if str(default) == 'retro': identicon = Identicon.render(kwargs['digest']) @@ -166,9 +176,11 @@ class AvatarImageView(TemplateView): img = img.resize((size, size), Image.ANTIALIAS) img.save(data, 'PNG', quality=JPEG_QUALITY) data.seek(0) - return HttpResponse( + response = HttpResponse( data, content_type='image/png') + response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE + return response if str(default) == 'pagan': paganobj = pagan.Avatar(kwargs['digest']) @@ -176,9 +188,11 @@ class AvatarImageView(TemplateView): img = paganobj.img.resize((size, size), Image.ANTIALIAS) img.save(data, 'PNG', quality=JPEG_QUALITY) data.seek(0) - return HttpResponse( + response = HttpResponse( data, content_type='image/png') + response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE + return response if str(default) == 'identicon': p = Pydenticon5() @@ -188,9 +202,11 @@ class AvatarImageView(TemplateView): data = BytesIO() img.save(data, 'PNG', quality=JPEG_QUALITY) data.seek(0) - return HttpResponse( + response = HttpResponse( data, content_type='image/png') + response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE + return response if str(default) == 'mm' or str(default) == 'mp': # If mm is explicitly given, we need to catch that @@ -226,9 +242,11 @@ class AvatarImageView(TemplateView): obj.save() if imgformat == 'jpg': imgformat = 'jpeg' - return HttpResponse( + response = HttpResponse( data, content_type='image/%s' % imgformat) + response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE + return response class GravatarProxyView(View): ''' @@ -297,9 +315,11 @@ class GravatarProxyView(View): data = BytesIO(gravatarimagedata.read()) img = Image.open(data) data.seek(0) - return HttpResponse( + response = HttpResponse( data.read(), content_type='image/%s' % file_format(img.format)) + response['Cache-Control'] = 'max-age=%i' % CACHE_IMAGES_MAX_AGE + return response except ValueError as exc: print('Value error: %s' % exc) diff --git a/libravatarproxy.py b/libravatarproxy.py new file mode 100755 index 0000000..eb19fc8 --- /dev/null +++ b/libravatarproxy.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +import urllib.request +import sys +import os + +sys.stderr.buffer.write(b'%s' % bytes(os.environ.get("QUERY_STRING", "No Query String in url"), 'utf-8')) + +link = 'https://www.libravatar.org/avatar/%s' % os.environ.get("QUERY_STRING", 'x'*32) +sys.stderr.buffer.write(b'%s' % bytes(link, 'utf-8')) + +data = None +with urllib.request.urlopen(link) as f: + data = f.read() + +for header in f.headers._headers: + if header[0] == 'Content-Type': + sys.stdout.buffer.write(b"%s: %s\n\n" % (bytes(header[0], 'utf-8'), bytes(header[1], 'utf-8'))) + sys.stdout.flush() + break + +sys.stdout.buffer.write(data) diff --git a/requirements.txt b/requirements.txt index d2bdc99..760b3df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,7 +30,7 @@ wheel yapf django-anymail[mailgun] mysqlclient -psycopg2 +psycopg2-binary notsetuptools git+https://github.com/ofalk/monsterid.git git+https://github.com/ofalk/Robohash.git@devel diff --git a/templates/contact.html b/templates/contact.html index af10e2a..5fdbfb5 100644 --- a/templates/contact.html +++ b/templates/contact.html @@ -30,6 +30,10 @@ If you've got a proposal to discuss or prefer to write to us, you can join our < You can also put short notices to our attention on Identica or Twitter. +

Mastodon

+ +Our Mastodon profile is available on https://photog.social/@libravatar. +

Email

Finally, if you need to email us: dev@libravatar.org diff --git a/templates/header.html b/templates/header.html index 5015f04..f197514 100644 --- a/templates/header.html +++ b/templates/header.html @@ -31,6 +31,7 @@ {% endif %} {% endif %} + diff --git a/templates/home.html b/templates/home.html index d517b0e..84ad794 100644 --- a/templates/home.html +++ b/templates/home.html @@ -37,7 +37,7 @@
{% endif %} -{% trans 'Check email' %}  + {% trans 'Check' %} 
@@ -71,6 +71,7 @@ {% trans 'Wiki' %}
{% trans 'Blog' %}

{% trans 'Social media' %}

+Mastodon
Identica
Twitter