-
Notifications
You must be signed in to change notification settings - Fork 103
Add account info page and change up colors #902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4845d2e
e876b6a
2fd3dbb
ae9319e
a7ebad5
cd66b00
7cd1b48
4ff1f01
bc2618f
59cf0a7
9aa5a3a
9b54506
37036bf
1a860a0
472cc12
ca9e13f
4540e54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| from django import forms | ||
| from django.http import HttpRequest | ||
| from django.http import HttpResponse | ||
| from django.shortcuts import render | ||
| from ocflib.printing.quota import get_connection | ||
| from ocflib.printing.quota import get_quota | ||
| from ocflib.vhost.application import get_app_vhosts | ||
| from ocflib.vhost.mail import vhosts_for_user | ||
| from ocflib.vhost.web import get_vhosts | ||
| from paramiko import AuthenticationException | ||
| from paramiko import SSHClient | ||
| from paramiko.hostkeys import HostKeyEntry | ||
|
|
||
| from ocfweb.auth import login_required | ||
| from ocfweb.component.forms import Form | ||
| from ocfweb.component.session import logged_in_user | ||
|
|
||
|
|
||
| @login_required | ||
| def account_info(request: HttpRequest) -> HttpResponse: | ||
| user = logged_in_user(request) | ||
| with get_connection() as c: | ||
| paper_quota = get_quota(c, user) | ||
| bytes_used = None | ||
| bytes_total = None | ||
| error = '' | ||
| if request.method == 'POST': | ||
| form = PasswordForm(request.POST) | ||
| if form.is_valid(): | ||
| password = form.cleaned_data['password'] | ||
| ssh = SSHClient() | ||
| host_keys = ssh.get_host_keys() | ||
| entry_ed25519 = HostKeyEntry.from_line( | ||
| 'ssh.ocf.berkeley.edu ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPm+RlDujsxQyxFTEOCTeImSBDvr63cL8Kg+rNrH6NK8', # noqa | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this in two different files
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wdym
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its in here and commands |
||
| ) | ||
| entry_rsa = HostKeyEntry.from_line( | ||
| 'ssh.ocf.berkeley.edu ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqMkHVVoMl8md25iky7e2Xe3ARaC4H1PbIpv5Y+xT4KOT17gGvFSmfjGyW9P8ZTyqxq560iWdyELIn7efaGPbkUo9retcnT6WLmuh9nRIYwb6w7BGEEvlblBmH27Fkgt7JQ6+1sr5teuABfIMg22WTQAeDQe1jg0XsPu36OjbC7HjA3BXsiNBpxKDolYIXWzOD+r9FxZLP0lawh8dl//O5FW4ha1IbHklq2i9Mgl79wAH3jxf66kQJTvLmalKnQ0Dbp2+vYGGhIjVFXlGSzKsHAVhuVD6TBXZbxWOYoXanS7CC43MrEtBYYnc6zMn/k/rH0V+WeRhuzTnr/OZGJbBBw==', # noqa | ||
| ) | ||
| host_keys.add( | ||
| 'ssh.ocf.berkeley.edu', | ||
| 'ssh-ed25519', | ||
| entry_ed25519.key, | ||
| ) | ||
| host_keys.add( | ||
| 'ssh.ocf.berkeley.edu', | ||
| 'ssh-rsa', | ||
| entry_rsa.key, | ||
| ) | ||
|
|
||
| try: | ||
| ssh.connect( | ||
| 'ssh.ocf.berkeley.edu', | ||
| username=user, | ||
| password=password, | ||
| ) | ||
| except AuthenticationException: | ||
| error = 'Authentication failed. Did you type the wrong password?' | ||
|
|
||
| if not error: | ||
| quota_command = "/run/current-system/sw/bin/quota 2>/dev/null | awk 'NR==3 {print $2, $3}'" | ||
| _, ssh_stdout, _ = ssh.exec_command(quota_command, get_pty=False) | ||
| sizes = ssh_stdout.read().decode().split() | ||
| if len(sizes) == 2: | ||
| bytes_used, bytes_total = (int(size) * 1024 for size in sizes) | ||
| else: | ||
| error = 'Unable to get quota information from the server. Please try again later.' | ||
| else: | ||
| form = PasswordForm() | ||
|
|
||
| return render( | ||
| request, | ||
| 'account/info/index.html', { | ||
| 'title': 'My Account', | ||
| 'form': form, | ||
| 'error': error, | ||
| 'paper_quota': paper_quota, | ||
| 'bytes_used': bytes_used, | ||
| 'bytes_total': bytes_total, | ||
| 'vhosts': [ | ||
| {'host': host, 'aliases': val['aliases']} | ||
| for host, val in get_vhosts().items() | ||
| if val['username'] == user | ||
| ], | ||
| 'vhosts_app': [ | ||
| {'host': host, 'aliases': val['aliases']} | ||
| for host, val in get_app_vhosts().items() | ||
| if val['username'] == user | ||
| ], | ||
| 'vhosts_mail': vhosts_for_user(user), | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| class PasswordForm(Form): | ||
| password = forms.CharField( | ||
| widget=forms.PasswordInput, | ||
| label='', | ||
| min_length=8, | ||
| max_length=256, | ||
| ) | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| {% extends "base.html" %} | ||
| {% load bootstrap %} | ||
|
|
||
| {% block content %} | ||
| <div class="row"> | ||
| <div class="col-md-8 ocf-content-block"> | ||
| <p>You are logged in as <strong>{{user}}</strong>, which is {{ user_is_group|yesno:"a group,an individual" }} account.</p> | ||
| {% if user_is_group %} | ||
| <p>Group accounts can't print. Sorry!</p> | ||
| {% else %} | ||
| <p>You currently have:</p> | ||
| <ul> | ||
| <li><span class="semibold">{{paper_quota.daily}} sides</span> of paper left for printing today</li> | ||
| <li><span class="semibold">{{paper_quota.semesterly}} sides</span> left for the semester</li> | ||
| <li><span class="semibold">{{paper_quota.color}} sides</span> left for color printing this semester</li> | ||
| </ul> | ||
| {% endif %} | ||
| {% if bytes_used is None %} | ||
| <p>Please re-enter your OCF password to check your personal storage.</p> | ||
| <form action="{% url 'account_info' %}" method="post" class="form-mini"> | ||
| {% csrf_token %} | ||
| {{form | bootstrap}} | ||
| <input class="btn btn-primary" type="submit" value="Submit" /> | ||
| </form> | ||
| {% if error %} | ||
| <p><strong>{{ error }}</strong></p> | ||
| {% endif %} | ||
| {% else %} | ||
| <p>You have used <span class="semibold">{{ bytes_used|filesizeformat }}</span> out of {{ bytes_total|filesizeformat }} available in disk storage on the OCF servers.</p> | ||
| {% endif %} | ||
| {% if user_is_group or vhosts or vhosts_app or vhosts_mail %} | ||
| {% if vhosts %} | ||
| <p>Your account has web virtual hosting at:</p> | ||
| <ul> | ||
| {% for vhost in vhosts %} | ||
| <li><code>{{vhost.host}}</code>{% if vhost.aliases %} with alias{{ vhost.aliases|pluralize:"es" }} {% for vhost_alias in vhost.aliases %} <code>{{vhost_alias}}</code>{% endfor %}{% endif %}</li> | ||
| {% endfor %} | ||
| </ul> | ||
| {% else %} | ||
| <p>Your account is not yet set up for <a href="{{docs_url}}/user-docs/services/vhost/">web virtual hosting</a>.</p> | ||
| {% endif %} | ||
| {% if vhosts_app %} | ||
| <p>Your account has web application hosting at:</p> | ||
| <ul> | ||
| {% for vhost_app in vhosts_app %} | ||
| <li><code>{{vhost_app.host}}</code>{% if vhost_app.aliases %} with alias{{ vhost_app.aliases|pluralize:"es" }} {% for vhost_app_alias in vhost_app.aliases %} <code>{{vhost_app_alias}}</code>{% endfor %}{% endif %}</li> | ||
| {% endfor %} | ||
| </ul> | ||
| {% else %} | ||
| <p>Your account is not yet set up for web application hosting.</p> | ||
| {% endif %} | ||
| {% if vhosts_mail %} | ||
| <p>Your account has mail virtual hosting at:</p> | ||
| <ul> | ||
| {% for vhost_mail in vhosts_mail %} | ||
| <li><code>{{vhost_mail.domain}}</code></li> | ||
| {% endfor %} | ||
| </ul> | ||
| {% else %} | ||
| <p>Your account is not yet set up for mail virtual hosting.</p> | ||
| {% endif %} | ||
| {% else %} | ||
| <p>Only group, faculty, and staff accounts are eligible for virtual hosting. Sorry!</p> | ||
| {% endif %} | ||
| <p>You can also check this information via <a href="{{docs_url}}/user-docs/services/shell/">SSH</a> by running <code>paper view {{user}}</code>, <code>quota -vs</code>, and <code>check {{user}}</code>. SSH, including our <a href="https://ssh.ocf.berkeley.edu">web terminal</a>, gives further access to actions such as editing web space files.</p> | ||
| <p>For our policies on printing, file storage, and virtual hosting, refer to the relevant documentation:</p> | ||
| <ul> | ||
| <li><a href="{{docs_url}}/user-docs/services/lab/printing/">Printing</a></li> | ||
| <li><a href="{{docs_url}}/user-docs/services/shell/#disk-quotas">Disk storage</a></li> | ||
| <li><a href="{{docs_url}}/user-docs/services/vhost/">Virtual hosting</a></li> | ||
| </ul> | ||
| <p>Out of pages? Here's a <a href="{{docs_url}}/user-docs/services/lab/printing/#out-of-pages">suggested list</a> of other places to print on and around campus.</p> | ||
| </div> | ||
| </div> | ||
| {% endblock %} |
Uh oh!
There was an error while loading. Please reload this page.