From 00f46f30853732597ddc0ea5be519d7acab90d16 Mon Sep 17 00:00:00 2001 From: Kayden Tebau Date: Mon, 6 Nov 2023 11:22:53 -0800 Subject: [PATCH] Detect if users actually have pages --- .gitignore | 1 + lib/unix_dog/Controller/Main.pm | 17 ++++++++++++++++- templates/main/usersList.html.ep | 11 ++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index bacd1e3..42cc429 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ unix_dog.yml +.DS_store diff --git a/lib/unix_dog/Controller/Main.pm b/lib/unix_dog/Controller/Main.pm index 043bf1d..22fd611 100644 --- a/lib/unix_dog/Controller/Main.pm +++ b/lib/unix_dog/Controller/Main.pm @@ -33,6 +33,15 @@ Mojo::IOLoop->recurring(60 => sub { my $acache = Mojo::Cache->new(max_keys => 1); my $filewatcher; +sub is_dir_used($dir) { + return 0 if not -e $dir; + return 0 if not -d $dir; + opendir my $dh, $dir or return 0; + readdir $dh; + readdir $dh; + return 1 if readdir $dh; +} + sub user_pages ($self) { my $config = $self->config; my $connStr = $config->{'ldap'}->{'uri'}; @@ -59,7 +68,13 @@ sub user_pages ($self) { my @sorted = sort {$a->get_value('createTimestamp') cmp $b->get_value('createTimestamp')} $mesg->entries; for (@sorted) { - push @{$users}, $_->get_value('uid'); + my $uid = $_->get_value('uid'); + my $dir = "/home/$uid/public/www"; + my $has_page = is_dir_used($dir); + push @{$users}, { + username => $uid, + has_page => $has_page, + }; } return $users; diff --git a/templates/main/usersList.html.ep b/templates/main/usersList.html.ep index 644b875..915d3a7 100644 --- a/templates/main/usersList.html.ep +++ b/templates/main/usersList.html.ep @@ -4,8 +4,13 @@

Users

Here's a list of all UNIX.dog users and their webpages: