Ignore:
Timestamp:
06/17/05 16:42:45 (19 years ago)
Author:
Kris Deugau
Message:

/branches/dns

Update branch base with trunk changes from r216:261

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/dns/cgi-bin/admin.cgi

    r214 r262  
    3333}
    3434
    35 if ($authuser !~ /^(kdeugau|jodyh|jipp)$/) {
    36   print "Content-Type: text/html\n\n".
    37         "<html><head><title>Access denied</title></head><body>\n".
    38         'Access to this tool is restricted.  Contact <a href="mailto:kdeugau@vianet.ca">Kris</a> '.
    39         "for more information.</body></html>\n";
    40   exit;
    41 }
    42 
    4335syslog "debug", "$authuser active";
    4436
     
    5345}
    5446initIPDBGlobals($ip_dbh);
     47
     48if ($IPDBacl{$authuser} !~ /A/) {
     49  print "Content-Type: text/html\n\n".
     50        "<html><head><title>Access denied</title></head><body>\n".
     51        'Access to this tool is restricted.  Contact <a href="mailto:kdeugau@vianet.ca">Kris</a> '.
     52        "for more information.</body></html>\n";
     53  exit;
     54}
    5555
    5656my %webvar = parse_post();
     
    9090</form>
    9191<hr><a href="admin.cgi?action=showpools">List IP Pools</a> for manual tweaking and updates
     92<hr><a href="admin.cgi?action=showusers">Manage users</a> (add/remove users;  change
     93internal access controls - note that this does NOT include IP-based limits)
    9294);
    9395} else {
     
    123125    printAndExit("Can't allocate from outside a free block!!\n")
    124126        if !$data[0];
     127  } elsif ($webvar{alloctype} =~ /^(.)i$/) {
     128    $sth = $ip_dbh->prepare("select cidr from allocations where cidr >>='$cidr' and (type like '_d' or type like '_p')");
     129    $sth->execute;
     130    @data = $sth->fetchrow_array;
     131# User deserves errors if user can't be bothered to find the pool and a free IP first.
     132    printAndExit("Can't allocate static IP from outside a pool!!\n")
     133        if !$data[0];
    125134  } else {
    126135    $sth = $ip_dbh->prepare("select cidr from freeblocks where cidr >>='$cidr' and not (routed='n')");
     
    202211      print "Allocation failed!  IPDB::allocateBlock said:\n$msg\n";
    203212      syslog "err", "($authuser) Allocation of '$webvar{cidr}' to '$webvar{custid}' as ".
    204         "'$webvar{type}' failed: '$msg'";
     213        "'$webvar{alloctype}' failed: '$msg'";
    205214    }
    206215  } # done city check
     
    267276    syslog "notice", "$authuser updated pool IP $webvar{ip}";
    268277  }
    269 #  showPool("$data[0]");
    270 #} else {
    271 #  print "webvar{action} check failed: $webvar{action}";
     278} elsif ($webvar{action} eq 'showusers') {
     279  print "Notes:<br>\n".
     280        "<li>Admin users automatically get all other priviledges.\n".
     281        "<hr>Add new user:<form action=admin.cgi method=POST>\n".
     282        "Username: <input name=username><br>\n".
     283        "Password: <input name=password> <input type=checkbox name=preenc>Password is pre-encrypted (MUST be crypt() encrypted)<br>\n".
     284        "<input type=submit value='Add user'><input type=hidden name=action value=newuser></form>\n";
     285
     286  print "<hr>Users with access:\n<table border=1>\n";
     287  print "<tr><td>Username</td><td>Add new</td><td>Change</td>".
     288        "<td>Delete</td><td>Admin user</td></tr>\n".
     289        "<form action=admin.cgi method=POST>\n";
     290  $sth = $ip_dbh->prepare("select username,acl from users order by username");
     291  $sth->execute;
     292  while (my @data = $sth->fetchrow_array) {
     293    print "<form action=admin.cgi method=POST><input type=hidden name=action value=updacl>".
     294        qq(<tr><td>$data[0]<input type=hidden name=username value="$data[0]"></td><td>).
     295    # Now for the fun bit.  We have to pull apart the ACL field and
     296    # output a bunch of checkboxes.
     297        "<input type=checkbox name=add".($data[1] =~ /a/ ? ' checked=y' : '').
     298        "></td><td><input type=checkbox name=change".($data[1] =~ /c/ ? ' checked=y' : '').
     299        "></td><td><input type=checkbox name=del".($data[1] =~ /d/ ? ' checked=y' : '').
     300        "></td><td><input type=checkbox name=admin".($data[1] =~ /A/ ? ' checked=y' : '').
     301        qq(></td><td><input type=submit value="Update"></td></form>\n).
     302        "<form action=admin.cgi method=POST><td><input type=hidden name=action value=deluser>".
     303        "<input type=hidden name=username value=$data[0]>".
     304        qq(<input type=submit value="Delete user"></tr></form>\n);
     305
     306  }
     307  print "</table>\n";
     308} elsif ($webvar{action} eq 'updacl') {
     309  print "Updating ACL for $webvar{username}:<br>\n";
     310  my $acl = 'b';
     311  if ($webvar{admin} eq 'on') {
     312    $acl .= "acdA";
     313  } else {
     314    $acl .= ($webvar{add} eq 'on' ? 'a' : '').
     315        ($webvar{change} eq 'on' ? 'c' : '').
     316        ($webvar{del} eq 'on' ? 'd' : '');
     317  }
     318  print "New ACL: $acl<br>\n";
     319
     320  $sth = $ip_dbh->prepare("update users set acl='$acl' where username='$webvar{username}'");
     321  $sth->execute;
     322  print "OK\n" if !$sth->err;
     323
     324  print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n);
     325
     326} elsif ($webvar{action} eq 'newuser') {
     327  print "Adding user $webvar{username}...\n";
     328  my $cr_pass = ($webvar{preenc} ? $webvar{password} :
     329        crypt $webvar{password}, join('',('.','/',0..9,'A'..'Z','a'..'z')[rand 64, rand 64]));
     330  $sth = $ip_dbh->prepare("insert into users (username,password,acl) values ".
     331        "('$webvar{username}','$cr_pass','b')");
     332  $sth->execute;
     333  if ($sth->err) {
     334    print "<br>Error adding user: ".$sth->errstr;
     335  } else {
     336    print "OK\n";
     337  }
     338
     339  print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n);
     340
     341} elsif ($webvar{action} eq 'deluser') {
     342  print "Deleting user $webvar{username}.<br>\n";
     343  $sth = $ip_dbh->prepare("delete from users where username='$webvar{username}'");
     344  $sth->execute;
     345  print "OK\n" if !$sth->err;
     346
     347  print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n);
     348
     349} elsif ($webvar{action} ne '<NULL>') {
     350  print "webvar{action} check failed: Don't know how to $webvar{action}";
    272351}
    273352
Note: See TracChangeset for help on using the changeset viewer.