Detect if users actually have pages
This commit is contained in:
parent
05baf8a2d1
commit
00f46f3085
|
@ -1 +1,2 @@
|
||||||
unix_dog.yml
|
unix_dog.yml
|
||||||
|
.DS_store
|
||||||
|
|
|
@ -33,6 +33,15 @@ Mojo::IOLoop->recurring(60 => sub {
|
||||||
my $acache = Mojo::Cache->new(max_keys => 1);
|
my $acache = Mojo::Cache->new(max_keys => 1);
|
||||||
my $filewatcher;
|
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) {
|
sub user_pages ($self) {
|
||||||
my $config = $self->config;
|
my $config = $self->config;
|
||||||
my $connStr = $config->{'ldap'}->{'uri'};
|
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;
|
my @sorted = sort {$a->get_value('createTimestamp') cmp $b->get_value('createTimestamp')} $mesg->entries;
|
||||||
|
|
||||||
for (@sorted) {
|
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;
|
return $users;
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,13 @@
|
||||||
<h1>Users</h1>
|
<h1>Users</h1>
|
||||||
<p>Here's a list of all UNIX.dog users and their webpages:</p>
|
<p>Here's a list of all UNIX.dog users and their webpages:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<% foreach my $username (@{$users}) { %>
|
% foreach my $user (@{$users}) {
|
||||||
<li><a href="https://unix.dog/~<%=$username%>/">~<%= $username %></a></li>
|
% if ($user->{has_page}) {
|
||||||
<% } %>
|
<li><a
|
||||||
|
href="https://unix.dog/~<%=$user->{username}%>/">~<%=$user->{username} %></a></li>
|
||||||
|
% } else {
|
||||||
|
<li>~<%= $user->{username} %></li>
|
||||||
|
% }
|
||||||
|
% }
|
||||||
</ul>
|
</ul>
|
||||||
</article>
|
</article>
|
||||||
|
|
Loading…
Reference in New Issue