Changeset 484
- Timestamp:
- 09/21/10 00:19:32 (14 years ago)
- Location:
- branches/htmlform
- Files:
-
- 7 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/htmlform/cgi-bin/admin.cgi
r483 r484 117 117 $page->param(masterlist => \@masterlist); 118 118 119 #} else { 120 # print '<a href="/ip/cgi-bin/admin.cgi">Back</a> to main<hr>'; 121 } 122 123 124 ## Possible actions. 119 } 120 121 ## Non-default actions. 125 122 elsif ($webvar{action} eq 'alloc') { 126 123 # OK, we know what we're allocating. … … 290 287 291 288 print $html; 289 292 290 } elsif ($webvar{action} eq 'touch') { 293 print "Touching master $webvar{whichmaster}\n"; 291 292 $page->param(master => $webvar{whichmaster}); 294 293 $sth = $ip_dbh->prepare("update masterblocks set mtime=now() where cidr='$webvar{whichmaster}'"); 295 294 $sth->execute; 296 295 if ($sth->err) { 297 print "<p>Error updating modified timestamp on master $webvar{whichmaster}: ".$sth->errstr."\n";296 $page->param(errmsg => $sth->errstr); 298 297 } 299 298 … … 366 365 367 366 } elsif ($webvar{action} eq 'showpools') { 368 print "IP Pools currently allocated:\n". 369 "<table border=1>\n<tr><td>Pool</td><td># of free IPs</td></tr>\n"; 370 $sth = $ip_dbh->prepare("select cidr from allocations where type like '%p' or type like '%d' order by cidr"); 371 $sth->execute; 372 my %poolfree; 373 while (my @data = $sth->fetchrow_array) { 374 $poolfree{$data[0]} = 0; 375 } 376 $sth = $ip_dbh->prepare("select pool,ip from poolips where available='y' order by ip"); 377 $sth->execute; 378 while (my @data = $sth->fetchrow_array) { 379 $poolfree{$data[0]}++; 380 } 381 foreach my $key (keys %poolfree) { 382 print qq(<tr><td><a href="admin.cgi?action=tweakpool&pool=$key">$key</a></td>). 383 "<td>$poolfree{$key}</td></tr>\n"; 384 } 385 print "</table>\n"; 367 368 $sth = $ip_dbh->prepare("select pool, count(*) from poolips where available='y' group by pool order by pool"); 369 $sth->execute; 370 my @poollist; 371 while (my ($pool,$free) = $sth->fetchrow_array) { 372 my %row = ( 373 pool => $pool, 374 free => $free 375 ); 376 push @poollist, \%row; 377 } 378 $page->param(poollist => \@poollist); 379 386 380 } elsif ($webvar{action} eq 'tweakpool') { 387 381 showPool($webvar{pool}); … … 389 383 390 384 $sth = $ip_dbh->prepare("update poolips set custid='$webvar{custid}', ". 391 "city= '$webvar{city}', type='$webvar{type}', available='".385 "city=?, type='$webvar{type}', available='". 392 386 (($webvar{available} eq 'y') ? 'y' : 'n'). 393 "', notes= '$webvar{notes}', description='$webvar{desc}'".387 "', notes=?, description=? ". 394 388 "where ip='$webvar{ip}'"); 395 $sth->execute ;389 $sth->execute($webvar{city},$webvar{notes},$webvar{desc}); 396 390 if ($sth->err) { 397 391 print "Error updating pool IP $webvar{ip}: $@<hr>\n"; … … 404 398 syslog "notice", "$authuser updated pool IP $webvar{ip}"; 405 399 } 400 406 401 } elsif ($webvar{action} eq 'showusers') { 407 print "Notes:<br>\n". 408 "<li>Admin users automatically get all other priviledges.\n". 409 "<li>Everyone has basic read access.\n". 410 "<hr>Add new user:<form action=admin.cgi method=POST>\n". 411 "Username: <input name=username><br>\n". 412 "Password: <input name=password> <input type=checkbox name=preenc>Password is pre-encrypted (MUST be crypt() encrypted)<br>\n". 413 "<input type=submit value='Add user'><input type=hidden name=action value=newuser></form>\n"; 414 415 print "<hr>Users with access:\n<table border=1>\n"; 416 print "<tr><td></td><td align=center colspan=3>General access</td></tr>\n"; 417 print "<tr><td>Username</td><td>Add new</td><td>Change</td>". 418 "<td>Delete</td><td>Systems/Networking</td><td>Admin user</td></tr>\n". 419 "<form action=admin.cgi method=POST>\n"; 402 420 403 $sth = $ip_dbh->prepare("select username,acl from users order by username"); 421 404 $sth->execute; 422 while (my @data = $sth->fetchrow_array) { 423 print "<form action=admin.cgi method=POST><input type=hidden name=action value=updacl>". 424 qq(<tr><td>$data[0]<input type=hidden name=username value="$data[0]"></td><td>). 425 # Now for the fun bit. We have to pull apart the ACL field and 426 # output a bunch of checkboxes. 427 "<input type=checkbox name=add".($data[1] =~ /a/ ? ' checked=y' : ''). 428 "></td><td><input type=checkbox name=change".($data[1] =~ /c/ ? ' checked=y' : ''). 429 "></td><td><input type=checkbox name=del".($data[1] =~ /d/ ? ' checked=y' : ''). 430 "></td><td><input type=checkbox name=sysnet".($data[1] =~ /s/ ? ' checked=y' : ''). 431 "></td><td><input type=checkbox name=admin".($data[1] =~ /A/ ? ' checked=y' : ''). 432 qq(></td><td><input type=submit value="Update"></td></form>\n). 433 "<form action=admin.cgi method=POST><td><input type=hidden name=action value=deluser>". 434 "<input type=hidden name=username value=$data[0]>". 435 qq(<input type=submit value="Delete user"></tr></form>\n); 436 437 } 438 print "</table>\n"; 405 my @userlist; 406 while (my ($username,$acl) = $sth->fetchrow_array) { 407 ##fixme: funky things happening with HTML::Template here; shouldn't need the "logic ? iftrue : iffalse" structure 408 my %row = ( 409 username => $username, 410 can_add => ($acl =~ /a/ ? 1 : 0), 411 can_change => ($acl =~ /c/ ? 1 : 0), 412 can_del => ($acl =~ /d/ ? 1 : 0), 413 sysnet => ($acl =~ /s/ ? 1 : 0), 414 is_admin => ($acl =~ /A/ ? 1 : 0), 415 acl => $acl 416 ); 417 push @userlist, \%row; 418 } 419 $page->param(userlist => \@userlist); 420 439 421 } elsif ($webvar{action} eq 'updacl') { 440 print "Updating ACL for $webvar{username}:<br>\n"; 422 423 $page->param(username => $webvar{username}); 441 424 my $acl = 'b'; 442 425 if ($webvar{admin} eq 'on') { … … 448 431 ($webvar{sysnet} eq 'on' ? 's' : ''); 449 432 } 450 print "New ACL: $acl<br>\n";433 $page->param(acl => $acl); 451 434 452 435 $sth = $ip_dbh->prepare("update users set acl='$acl' where username='$webvar{username}'"); 453 436 $sth->execute; 454 print "OK\n" if !$sth->err; 455 456 print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n); 437 $page->param(errmsg => $sth->errstr) if $sth->err; 457 438 458 439 } elsif ($webvar{action} eq 'newuser') { 459 print "Adding user $webvar{username}...\n"; 440 441 $page->param(username => $webvar{username}); 460 442 my $cr_pass = ($webvar{preenc} ? $webvar{password} : 461 443 crypt $webvar{password}, join('',('.','/',0..9,'A'..'Z','a'..'z')[rand 64, rand 64])); … … 463 445 "('$webvar{username}','$cr_pass','b')"); 464 446 $sth->execute; 465 if ($sth->err) { 466 print "<br>Error adding user: ".$sth->errstr; 467 } else { 468 print "OK\n"; 469 } 470 471 print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n); 447 $page->param(errmsg => $sth->errstr) if $sth->err; 472 448 473 449 } elsif ($webvar{action} eq 'deluser') { 474 print "Deleting user $webvar{username}.<br>\n"; 450 451 $page->param(username => $webvar{username}); 475 452 $sth = $ip_dbh->prepare("delete from users where username='$webvar{username}'"); 476 453 $sth->execute; 477 print "OK\n" if !$sth->err; 478 479 print qq(<hr><a href="admin.cgi?action=showusers">Back</a> to user listing\n); 454 $page->param(errmsg => $sth->errstr) if $sth->err; 480 455 481 456 } elsif ($webvar{action} eq 'emailnotice') {
Note:
See TracChangeset
for help on using the changeset viewer.