1#!/usr/local/bin/perl 2# save_user.cgi 3# Save, create or delete a MON user 4 5require './mon-lib.pl'; 6&ReadParse(); 7&error_setup($text{'user_err'}); 8@users = &list_users(); 9$user = $users[$in{'index'}] if ($in{'index'} ne ''); 10 11if ($in{'delete'}) { 12 # Just delete the user 13 &delete_user($user); 14 } 15else { 16 # Validate inputs 17 $in{'user'} =~ /^[^:\s]+$/ || &error($text{'user_euser'}); 18 if ($in{'new'} || $in{'user'} ne $user->{'user'}) { 19 local ($same) = grep { $_->{'user'} eq $in{'user'} } @users; 20 $same && &error($text{'user_esame'}); 21 } 22 23 # Create or update the user 24 $salt = substr(time(), -2); 25 $user->{'user'} = $in{'user'}; 26 if (!$in{'pass_def'}) { 27 $user->{'pass'} = &unix_crypt($in{'pass'}, $salt); 28 } 29 if ($in{'new'}) { 30 &create_user($user); 31 } 32 else { 33 &modify_user($user); 34 } 35 } 36 37&redirect("list_users.cgi"); 38 39