This file is indexed.

/usr/share/netdisco/html/admin_user.html is in netdisco-frontend 1.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<h1 class="pagehead">Admin Panel - User Control</h1>
<& SELF:error &>
% if ($cmd eq 'Delete' and !$confirm) {
<& SELF:confirm_del &>
% } elsif ($cmd eq 'Edit' and !$err) {
<& SELF:add_user, action => 'Change' &>
% } else {
<& SELF:list_users &>
<& SELF:add_user &>
%}
<%args>
$cmd   => undef
$user  => undef
$port  => 0
$admin => 0
$ldap  => 0
$confirm => 0
$pw    => undef
$fullname => undef
$note  => undef
</%args>
<%shared>
my ($this_user,$users,%user_hash,$arg_user);
my $odd    = 0;
my $err    = '';
my $userip = $r->connection->remote_ip; 
</%shared>
<%init>
# Enforce secure + admin
$m->comp('admin.html:force_secure_admin');

$this_user = $m->session->{user};
$arg_user = $user;

# Fetch users from db.
$m->comp('SELF:load_users');

# Add 
if ($cmd eq 'Add'){
    $user = lc($user);
    $user =~  s/^\s*//;
    $user =~  s/\s+.*//;
    unless ($user){
        $err .= "Select a user name.\n";
    }
    unless ($pw || $ldap){
        $err .= "Enter a password for this user.\n";
    }
    if (defined $user_hash{$user}) {
        $err .= "There is already a user by that name.\n";
    }
    unless ($err){
        # Add
        my $rv = netdisco::user_add($user,(
                                    'pw' => $pw,
                                    'admin' => $admin eq '1' ? 1 : 0,
                                    'port'  => $port eq  '1' ? 1 : 0,
                                    'ldap'  => $ldap eq  '1' ? 1 : 0,
                                    'fullname' => $fullname,
                                    'note' => $note,
                                ));
        $err = $rv ? "User $user added.\n" : "Could not Add user!\n";

        # Log addition
        insert_or_update('user_log',{},
                {'username'=>$m->session->{user},'event'=>'user_add',
                 'userip'=>$userip,'details'=>"User: $user - $err"});
        
        # Reload hash
        $m->comp('SELF:load_users');
    }
}

if ($cmd eq 'Change'){
    unless (defined $user_hash{$user}){
        $err .= "User $user not found.\n";
    } 
    my %user_change;
    unless ($err){
        # Check for PW
        if (defined $pw and length($pw)){
            $user_change{pw}=$pw;
        }

        # Check for Admin Change
        if ($admin != $user_hash{$user}->{admin}) { 
            $user_change{admin} = $admin;
        }

        # Check for Port Change
        if ($port != $user_hash{$user}->{port_control}) {
            $user_change{port} = $port;
        }
        
        # Check for Ldap Change
        if ($ldap != $user_hash{$user}->{ldap}) {
            $user_change{ldap} = $ldap;
        }

        # Check for Note Change
        if ($note ne $user_hash{$user}->{note}) {
            $user_change{note} = $note;
        }

        # Check for Full Name Change
        if ($fullname ne $user_hash{$user}->{fullname}) {
            $user_change{fullname} = $fullname;
        }

        if (scalar keys %user_change){
            my $rv = netdisco::user_add($user,%user_change);
            $err .= $rv ?
                    "Could not modify user! $rv\n"
                        :
                    "Changed ".join(',',keys %user_change)." for user $user.\n";

            # Log Change
            insert_or_update('user_log',{},
                    {'username'=>$m->session->{user},'event'=>'user_change',
                     'userip'=>$userip,'details'=>"User: $user - $err"});

            $m->comp('SELF:load_users');
        } 

    }

}

if ($cmd eq 'Edit'){
    unless (defined $user_hash{$user}){
        $err .= "User $user not found.\n";
    } 
}

if ($cmd eq 'Delete'){
    unless (defined $user_hash{$user}){
        $err .= "User $user not found.\n";
    } 

    if ($user eq $this_user) {
        $err .= "You cannot delete yourself.\n";
    }

    if (!$err and $confirm){
        my $rv = netdisco::user_del($user);

        if (defined $rv){
            $err .= "Deleted user $user.\n";
        } else {
            $err .= "Could not delete user $user.\n";
        }

        # Log Change
        insert_or_update('user_log',{},
                {'username'=>$m->session->{user},'event'=>'user_del',
                 'userip'=>$userip,'details'=> "User: $user - $err"});

        # Reload hash
        $m->comp('SELF:load_users');
    } 
}
 
</%init>
<%method list_users>
<h2 class="subheader">Existing Users</h2>
<TABLE CLASS="adm-q">
<TR>
    <TH>User</TH>
    <TH>Port<BR>Control</TH>
    <TH>Admin<BR>Control</TH>
    <TH>LDAP</TH>
    <TH>Full Name</TH>
    <TH>Note</TH>
    <TH>Created /<BR>Last Login</TH>
    <TH>&nbsp;</TH>
</TR>
% foreach my $user_entry (sort { $a->{username} cmp $b->{username} } @$users){
%   my $last_on =  $user_entry->{last_on} ?
%                   scalar(localtime($user_entry->{last_on})) 
%                   : 'Never logged in';
%   $odd++;
<TR>
    <TD CLASS="match-<%$odd%2%>"><B><%$user_entry->{username}%></B></TD>
    <TD CLASS="match-<%$odd%2%>"><%$user_entry->{port_control} ? 'Yes' : 'No'%></TD>
    <TD CLASS="match-<%$odd%2%>"><%$user_entry->{admin} ? 'Yes' : 'No'%></TD>
    <TD CLASS="match-<%$odd%2%>"><%$user_entry->{ldap} ? 'Yes' : 'No'%></TD>
    <TD CLASS="match-<%$odd%2%>"><%$user_entry->{fullname} |h%></TD>
    <TD CLASS="match-<%$odd%2%>"><%$user_entry->{note} |h%></TD>
    <TD CLASS="match-<%$odd%2%>"><span class="nobr"><%scalar localtime($user_entry->{creation})%></span><BR>
        <span class="nobr"><%$last_on%></span></TD>
    <TD CLASS="match-<%$odd%2%>">
        <FORM ACTION="<%$r->uri%>" METHOD=POST>
        <DIV>
        <INPUT TYPE="hidden" NAME="user" VALUE="<%$user_entry->{username}|h%>">
        <INPUT TYPE="submit" CLASS="navbutton" NAME="cmd" VALUE="Delete">
        <INPUT TYPE="submit" CLASS="navbutton" NAME="cmd" VALUE="Edit">
        </DIV>
        </FORM>
    </TD>
</TR>
% }
</TABLE>
<%scalar @$users%> Users.
</%method>
<%method add_user>
% my $user = ($action eq 'Change') ? $user_hash{$arg_user} : undef;
<h2 class="subheader"><%$action%> User</h2>
<FORM ACTION="<%$r->uri%>" METHOD=POST>
<DIV>
<INPUT TYPE="HIDDEN" NAME="cmd" VALUE="<%$action%>">
<TABLE CLASS="adm-search">
<TR>
    <TH>Username:</TH>
% if ($action eq 'Add') {
    <TD><INPUT TYPE="text" NAME="user" SIZE="20" MAXLENGTH="50"></TD>
    <TD CLASS="note">Lower case, alphanumeric only.</TD>
% } else {
    <TD><INPUT TYPE="HIDDEN" NAME="user" VALUE="<%$arg_user|h%>"><%$arg_user%></TD>
    <TD CLASS="note">&nbsp;</TD>
% }
</TR>
<TR>
    <TH>Password:</TH>
    <TD><INPUT TYPE="password" NAME="pw" SIZE="20" MAXLENGTH="50"></TD>
    <TD CLASS="note">Case Sensitive.</TD>
</TR>
<TR>
    <TH>LDAP:</TH>
    <TD><INPUT NAME="ldap" TYPE="checkbox" VALUE="1" <%$user->{ldap} ? 'CHECKED' : ''%>></TD>
    <TD CLASS="note">Use LDAP for Login</TD>
</TR>
<TR>
    <TH>Full Name:</TH>
    <TD><INPUT TYPE="text" NAME="fullname" SIZE=35 MAXLENGTH=255 VALUE="<%$user->{fullname} |h%>"></TD>
    <TD CLASS="note">(optional)</TD>
</TR>
<TR>
    <TH>Note:</TH>
    <TD><INPUT TYPE="text" NAME="note" SIZE=35 MAXLENGTH=255 VALUE="<%$user->{note} |h%>"></TD>
    <TD CLASS="note">(optional)</TD>
</TR>
<TR>
    <TH>Port Control:</TH>
    <TD><INPUT NAME="port" TYPE="checkbox" VALUE="1" <%$user->{port_control} ? 'CHECKED' : ''%>></TD>
    <TD CLASS="note">Gives user ability to turn non-uplink ports on and off.</TD>
<TR>
    <TH>Admin:</TH>
    <TD><INPUT NAME="admin" TYPE="checkbox" VALUE="1" <%$user->{admin} ? 'CHECKED' : ''%>></TD>
    <TD CLASS="note">Gives user ability to control device and users.</TD>
</TR>
<TR>
    <TH>&nbsp;</TH>
    <TD COLSPAN=2>
        <INPUT TYPE="submit" CLASS="navbutton" VALUE="<%$action%> User">
% if ($action eq 'Change') {
        <A CLASS="navbutton" HREF="<%$r->uri%>">Don't Change</A>
% }
    </TD>
</TR>
</TABLE>
</DIV>
</FORM>
<%args>
$action => 'Add'
</%args>
</%method>
<%method confirm_del>
<FORM ACTION="<%$r->uri%>" METHOD=POST>
<DIV>
<INPUT TYPE="hidden" NAME="cmd" VALUE="Delete">
<INPUT TYPE="hidden" NAME="user" VALUE="<%$arg_user|h%>"> 
Confirm Deletion of <%$arg_user |h%> : 
<INPUT TYPE="checkbox" NAME="confirm" VALUE="1">
<BR>
<INPUT TYPE="submit" CLASS="navbutton" VALUE="Delete <%$arg_user|h%>">
<A CLASS="navbutton" HREF="<%$r->uri%>">Cancel</A>
</DIV>
</FORM> 
</%method>
<%method load_users>
<%perl>
$users = sql_rows('users',['username','password','extract(epoch from creation) as creation',
                           'extract(epoch from last_on) as last_on','port_control','admin',
                           'note','fullname','ldap']
                 );

%user_hash = map {$_->{username} => $_} @$users;
</%perl>
</%method>
<%method error>
% return unless $err;
<h1 class="pagehead"><%$err%></h1>
</%method>
<%method title>
- Admin Panel - Users \
</%method>
%# $Id: admin_user.html,v 1.10 2007/12/19 06:24:34 maxbaker Exp $
%# vim:syntax=mason