diff --git a/ocfweb/main/home.py b/ocfweb/main/home.py
index 070382aee..8de6c9e51 100644
--- a/ocfweb/main/home.py
+++ b/ocfweb/main/home.py
@@ -1,11 +1,16 @@
+import random
from datetime import date
from datetime import timedelta
from operator import attrgetter
+from typing import Mapping
from django.http import HttpRequest
from django.http import HttpResponse
+from django.http import HttpResponseRedirect
+from django.shortcuts import redirect
from django.shortcuts import render
from ocflib.lab.staff_hours import get_staff_hours_soonest_first
+from ocflib.vhost.web import get_vhosts
from ocfweb.api.hours import get_hours_listing
from ocfweb.caching import periodic
@@ -19,6 +24,20 @@ def get_staff_hours() -> str:
return get_staff_hours_soonest_first()[:2]
+def hosted_site_urls(vhosts: Mapping[str, object] | None = None) -> list[str]:
+ if vhosts is None:
+ vhosts = get_vhosts()
+
+ return sorted(
+ f'https://{hostname}/'
+ for hostname in vhosts.keys()
+ )
+
+
+def random_hosted_site(request: HttpRequest) -> HttpResponseRedirect:
+ return redirect(random.choice(hosted_site_urls()))
+
+
def home(request: HttpRequest) -> HttpResponse:
hours_listing = get_hours_listing()
hours = [
diff --git a/ocfweb/main/templates/main/home.html b/ocfweb/main/templates/main/home.html
index 1a914cb3f..7983a797e 100644
--- a/ocfweb/main/templates/main/home.html
+++ b/ocfweb/main/templates/main/home.html
@@ -33,7 +33,7 @@
Welcome to the Open Computing Facility!
OCF volunteers maintain services for the Berkeley community, including:
- A spiffy computer lab in 171 MLK Student Union
- - Web & email hosting for thousands of student groups and individuals
+ - Web & email hosting for thousands of student groups and individuals. Visit a random website!
- Free printing for all UC Berkeley students
- Shell accounts on our powerful on-campus servers
- High-performance computing on our GPU server
diff --git a/ocfweb/urls.py b/ocfweb/urls.py
index 5869b1a29..f2711a9c7 100644
--- a/ocfweb/urls.py
+++ b/ocfweb/urls.py
@@ -16,6 +16,7 @@
from ocfweb.login.urls import urlpatterns as login
from ocfweb.main.favicon import favicon
from ocfweb.main.home import home
+from ocfweb.main.home import random_hosted_site
from ocfweb.main.hosting_logos import hosting_logo
from ocfweb.main.lab import lab
from ocfweb.main.robots import robots_dot_txt
@@ -36,6 +37,7 @@
re_path('', include('django_prometheus.urls')),
re_path(r'^$', home, name='home'),
+ re_path(r'^random-hosted-site$', random_hosted_site),
re_path(r'^robots\.txt$', robots_dot_txt, name='robots.txt'),
re_path(r'^favicon.ico$', favicon, name='favicon'),
re_path(r'^.well-known/security\.txt$', security_dot_txt, name='security.txt'),
diff --git a/tests/main/random_hosted_site_test.py b/tests/main/random_hosted_site_test.py
new file mode 100644
index 000000000..70bb4c677
--- /dev/null
+++ b/tests/main/random_hosted_site_test.py
@@ -0,0 +1,23 @@
+from ocfweb.main.home import hosted_site_urls
+
+
+def test_hosted_site_urls_uses_primary_vhost_names():
+ vhosts = {
+ 'lift.studentorg.berkeley.edu': {
+ 'username': 'lift',
+ 'aliases': [],
+ 'docroot': '/',
+ 'flags': [],
+ },
+ 'bearbites.asuc.org': {
+ 'username': 'bearbites',
+ 'aliases': ['www.bearbites.asuc.org'],
+ 'docroot': '/',
+ 'flags': [],
+ },
+ }
+
+ assert hosted_site_urls(vhosts) == [
+ 'https://bearbites.asuc.org/',
+ 'https://lift.studentorg.berkeley.edu/',
+ ]