Detect if users actually have pages

This commit is contained in:
Citlali del Rey 2023-11-06 11:22:53 -08:00
parent 05baf8a2d1
commit 00f46f3085
Signed by: nullobsi
GPG Key ID: 933A1F44222C2634
3 changed files with 25 additions and 4 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
unix_dog.yml
.DS_store

View File

@ -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;

View File

@ -4,8 +4,13 @@
<h1>Users</h1>
<p>Here's a list of all UNIX.dog users and their webpages:</p>
<ul>
<% foreach my $username (@{$users}) { %>
<li><a href="https://unix.dog/~<%=$username%>/">~<%= $username %></a></li>
<% } %>
% foreach my $user (@{$users}) {
% if ($user->{has_page}) {
<li><a
href="https://unix.dog/~<%=$user->{username}%>/">~<%=$user->{username} %></a></li>
% } else {
<li>~<%= $user->{username} %></li>
% }
% }
</ul>
</article>