Add users list
This commit is contained in:
parent
510b0a016e
commit
ab208912e6
|
@ -26,6 +26,8 @@ sub startup ($self) {
|
|||
|
||||
$r->get('/account')->to('Account#account');
|
||||
$r->post('/account')->to('Account#update_account');
|
||||
|
||||
$r->get('/users')->to('Main#user_pages');
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package unix_dog::Controller::Main;
|
||||
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
||||
use Net::LDAPS;
|
||||
|
||||
sub index ($self) {
|
||||
$self->render();
|
||||
|
@ -13,4 +14,46 @@ sub services ($self) {
|
|||
$self->render();
|
||||
}
|
||||
|
||||
|
||||
my $cache = Mojo::Cache->new(max_keys => 1);
|
||||
$cache->set(users => []);
|
||||
Mojo::IOLoop->recurring(60 => sub {
|
||||
$cache->set(users => []);
|
||||
});
|
||||
|
||||
sub user_pages ($self) {
|
||||
my $config = $self->config;
|
||||
my $connStr = $config->{'ldap'}->{'uri'};
|
||||
|
||||
my $users = $cache->get('users');
|
||||
|
||||
if (scalar @{$users} != 0) {
|
||||
$self->stash(users => $users);
|
||||
return $self->render('main/usersList');
|
||||
}
|
||||
|
||||
return Mojo::IOLoop->subprocess->run_p(sub {
|
||||
my $ldap = Net::LDAPS->new($connStr, verify=>'none', version=>3) or die "$@";
|
||||
my $mesg = $ldap->bind();
|
||||
$mesg->code and die $mesg->error;
|
||||
|
||||
$mesg = $ldap->search(
|
||||
base => 'OU=Dogs,DC=unix,DC=dog',
|
||||
filter => '(objectClass=posixAccount)',
|
||||
attrs => ['uid'],
|
||||
);
|
||||
$mesg->code and die $mesg->error;
|
||||
|
||||
for ($mesg->entries) {
|
||||
push @{$users}, $_->get_value('uid');
|
||||
}
|
||||
return $users;
|
||||
|
||||
})->then(sub (@results) {
|
||||
$self->stash(users => (@results));
|
||||
$cache->set(users => (@results));
|
||||
$self->render('main/usersList');
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
<img src="favicon.ico" width="32" height="32" alt="UNIX.dog"/>
|
||||
<h1><a href="/">UNIX.dog</a></h1>
|
||||
<div id="nav">
|
||||
<a href="/users">Users</a>
|
||||
<a href="/account">Account</a>
|
||||
<a href="/services">Services</a>
|
||||
<a href="/register">Register</a>
|
||||
|
|
|
@ -7,6 +7,14 @@
|
|||
hooked into LDAP and use the same username and password you
|
||||
registered with.
|
||||
</p>
|
||||
<section>
|
||||
<h2>SSH</h2>
|
||||
<p>
|
||||
An SSH shell is provided for all registered users. You
|
||||
can use the SSH shell to store files and create your
|
||||
webpage! :)
|
||||
</p>
|
||||
</section>
|
||||
<section>
|
||||
<h2>Akkoma</h2>
|
||||
<p>
|
||||
|
@ -50,9 +58,8 @@
|
|||
<section>
|
||||
<h2>Static webhosting</h2>
|
||||
<p>
|
||||
Files under ~/public are hosted at unix.dog/~username. A list
|
||||
of user websites will be added to a page here soon, but you
|
||||
can still make cool webpages!
|
||||
Files under ~/public are hosted at username.www.unix.dog. A list
|
||||
of user websites can be found <a href="/users">here.</a>
|
||||
</p>
|
||||
</section>
|
||||
</article>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
% title 'UNIX.dog Users';
|
||||
% layout 'default';
|
||||
<article>
|
||||
<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://<%=$username%>.www.unix.dog/">~<%= $username %></a></li>
|
||||
<% } %>
|
||||
</ul>
|
||||
</article>
|
Loading…
Reference in New Issue