From: Rob H. <for...@us...> - 2002-02-17 20:28:03
|
Update of /cvsroot/sandweb/sandweb/bin In directory usw-pr-cvs1:/tmp/cvs-serv1570 Modified Files: sandweb.cgi Log Message: * we were already checking for cookie auth in the main subroutine; no need to do it in every menu ( removed ). * was able to fix the auth checker in main() so that it is self contained and leaves the subroutine if it fails, instead of nesting the rest of the subroutine. makes main() alot more readable. * reformmatted code ( just a little ) Index: sandweb.cgi =================================================================== RCS file: /cvsroot/sandweb/sandweb/bin/sandweb.cgi,v retrieving revision 1.172 retrieving revision 1.173 diff -U2 -r1.172 -r1.173 --- sandweb.cgi 13 Feb 2002 09:18:26 -0000 1.172 +++ sandweb.cgi 17 Feb 2002 20:27:56 -0000 1.173 @@ -79,6 +79,5 @@ password => $password, ); - } - else { + } else { # if auth cookie exists, this will return it's data my $ck_auth = CGI::cookie('sandweb_auth') || ''; @@ -95,168 +94,175 @@ exit 0; } - # has valid auth cookie - my $repository_selected = CGI::param('repository_selected'); - my $repo_name = CGI::param('repo_name'); - my $repo_server = CGI::param('repo_server'); - my $repo_username = CGI::param('repo_username'); - my $repo_type = CGI::param('repo_type'); - my $repo_connection = CGI::param('repo_connection'); - my $repo_root = CGI::param('repo_root'); - my $new_repository = CGI::param('new_repository'); - my $submit = CGI::param('Submit'); - my $vcs_command = CGI::param('vcs_command'); - my $module_name = CGI::param('module_name'); - - $log->debug("action: $action submit: $submit"); - - ####################################################### - # Process Action parameter to specified menu - ############################# - # - unless ($action) { - # with auth cookie, default is sandbox_menu - sandbox_menu( ck_auth => $ck_auth ); + } else { + # no auth cookie, default login_menu + $log->debug("no authentication cookie found: '$ck_auth'"); + login_menu(); + } + + # has valid auth cookie + my $repository_selected = CGI::param('repository_selected'); + my $repo_name = CGI::param('repo_name'); + my $repo_server = CGI::param('repo_server'); + my $repo_username = CGI::param('repo_username'); + my $repo_type = CGI::param('repo_type'); + my $repo_connection = CGI::param('repo_connection'); + my $repo_root = CGI::param('repo_root'); + my $new_repository = CGI::param('new_repository'); + my $submit = CGI::param('Submit'); + my $vcs_command = CGI::param('vcs_command'); + my $module_name = CGI::param('module_name'); + + $log->debug("action: $action submit: $submit"); + + ####################################################### + # Process Action parameter to specified menu + ############################# + # + unless ($action) { + # with auth cookie, default is sandbox_menu + sandbox_menu( + ck_auth => $ck_auth, + ); + } else { + # User is logged in; load prefs + load_config(1); + $log->debug("loading prefs"); + + if ( $action eq 'debug' ) { + # called test menu + debug_menu( + ck_auth => $ck_auth, + ); } - else { - # User is logged in; load prefs - load_config(1); - $log->debug("loading prefs"); - - if ( $action eq 'debug' ) { - # called test menu - debug_menu( ck_auth => $ck_auth ); - } - elsif ( $action eq 'preferences' ) { - if (! CGI::param('Submit')) { - # call preferences menu - preferences_menu( ck_auth => $ck_auth ); - } - else { - # commit menu data - preferences_commit( ck_auth => $ck_auth,); - } - } - elsif ( $action eq 'logout' ) { - # called logout - logout(); - } - elsif ( $action eq 'sandbox' ) { - # called sandbox viewer - my $location = CGI::param('location'); - unless ($location) { - $location = ""; - } - sandbox_menu( + elsif ( $action eq 'preferences' ) { + if (! CGI::param('Submit')) { + # call preferences menu + preferences_menu( ck_auth => $ck_auth, - location => $location, ); - } - elsif ( $action eq 'browse_module' ) { - # called sandbox viewer - my $location = CGI::param('location'); - unless ($location) { - $location = ""; - } - browse_module_menu( + } else { + # commit menu data + preferences_commit( ck_auth => $ck_auth, - location => $location, ); } - elsif ( $action eq 'browse_file' ) { - # called file manipulator - my @filename = (); - my $file_command; - if ( CGI::param('action_file') ) { - $file_command = CGI::param('action_file'); - } else { - $file_command = CGI::param('file_command'); - } + } + elsif ( $action eq 'logout' ) { + # called logout + logout(); + } + elsif ( $action eq 'sandbox' ) { + # called sandbox viewer + my $location = CGI::param('location'); + unless ($location) { + $location = ""; + } + sandbox_menu( + ck_auth => $ck_auth, + location => $location, + ); + } + elsif ( $action eq 'browse_module' ) { + # called sandbox viewer + my $location = CGI::param('location'); + unless ($location) { + $location = ""; + } + browse_module_menu( + ck_auth => $ck_auth, + location => $location, + ); + } + elsif ( $action eq 'browse_file' ) { + # called file manipulator + my @filename = (); + my $file_command; + if ( CGI::param('action_file') ) { + $file_command = CGI::param('action_file'); + } else { + $file_command = CGI::param('file_command'); + } + @filename = CGI::param('filename'), + browse_file_commit( + ck_auth => $ck_auth, + file_command => $file_command, + filename => \@filename, + location => CGI::param('location'), + ); + } + elsif ( $action eq 'browse_vcs' ) { + # called VCS action + my @filename = (); + if ( CGI::param('filename') ) { @filename = CGI::param('filename'), - browse_file_commit( - ck_auth => $ck_auth, - file_command => $file_command, - filename => \@filename, - location => CGI::param('location'), - ); + } + else { + @filename = ('.'); } - elsif ( $action eq 'browse_vcs' ) { - # called VCS action - my @filename = (); - if ( CGI::param('filename') ) { - @filename = CGI::param('filename'), - } - else { - @filename = ('.'); - } - browse_vcs_commit( + browse_vcs_commit( + ck_auth => $ck_auth, + vcs_command => CGI::param('vcs_command'), + location => CGI::param('location'), + filename => \@filename, + ); + } + elsif ( $action eq 'checkout' ) { + if ($submit) { + # called checkout commit + checkout_commit( ck_auth => $ck_auth, - vcs_command => CGI::param('vcs_command'), - location => CGI::param('location'), - filename => \@filename, + repo_name => $repo_name, + module_name => $module_name, ); - } - elsif ( $action eq 'checkout' ) { - if ($submit) { - # called checkout commit - checkout_commit( - ck_auth => $ck_auth, - repo_name => $repo_name, - module_name => $module_name, - ); - } else { - # called checkout menu - checkout_menu( - ck_auth => $ck_auth, - ); - } - } - elsif ( $action eq 'repository' ) { - if ($submit) { - repository_commit( - ck_auth => $ck_auth, - repository_selected => $repository_selected, - repo_name => $repo_name, - repo_server => $repo_server, - repo_username => $repo_username, - repo_type => $repo_type, - repo_connection => $repo_connection, - repo_root => $repo_root, - new_repository => $new_repository, - ); - } else { - repository_menu( - ck_auth => $ck_auth, - repository_selected => $repository_selected, - repo_name => $repo_name, - repo_server => $repo_server, - repo_username => $repo_username, - repo_type => $repo_type, - repo_connection => $repo_connection, - repo_root => $repo_root, - new_repository => $new_repository, - ); - } } else { - # called an invalid page - my $page = $action; - my $msg = "Invalid page - $page!"; - $log->error("$msg"); - set_error("$msg"); - # load current menu (instead of going to new one) - #no strict 'refs'; - #my $curr_menu = CGI::param('curr_menu'); - #&$curr_menu( ck_auth => $ck_auth); - debug_menu( ck_auth => $ck_auth ); + # called checkout menu + checkout_menu( + ck_auth => $ck_auth, + ); + } + } + elsif ( $action eq 'repository' ) { + if ($submit) { + repository_commit( + ck_auth => $ck_auth, + repository_selected => $repository_selected, + repo_name => $repo_name, + repo_server => $repo_server, + repo_username => $repo_username, + repo_type => $repo_type, + repo_connection => $repo_connection, + repo_root => $repo_root, + new_repository => $new_repository, + ); + } else { + repository_menu( + ck_auth => $ck_auth, + repository_selected => $repository_selected, + repo_name => $repo_name, + repo_server => $repo_server, + repo_username => $repo_username, + repo_type => $repo_type, + repo_connection => $repo_connection, + repo_root => $repo_root, + new_repository => $new_repository, + ); } + } else { + # called an invalid page + my $page = $action; + my $msg = "Invalid page - $page!"; + $log->error("$msg"); + set_error("$msg"); + # load current menu (instead of going to new one) + #no strict 'refs'; + #my $curr_menu = CGI::param('curr_menu'); + #&$curr_menu( ck_auth => $ck_auth); + debug_menu( + ck_auth => $ck_auth, + ); } } - else { - # no auth cookie, default login_menu - $log->debug("no authentication cookie found: '$ck_auth'"); - login_menu(); - } } - exit 0; } @@ -311,8 +317,4 @@ my $ck_auth = $args{'ck_auth'}; - unless ($ck_auth) { - &login_menu(); - exit 0; - } load_config(1); @@ -352,8 +354,4 @@ $log->debug("entering sandbox_menu()"); $log->debug('dump', $user); - unless ($ck_auth) { - &login_menu(); - exit 0; - } load_config(1); @@ -417,8 +415,4 @@ $log->debug("entering browse_module_menu()"); - unless ($ck_auth) { - &login_menu(); - exit 0; - } if (! load_config()) { # no existing user config, forward to prefs menu @@ -508,8 +502,4 @@ my %args = @_; my $ck_auth = $args{'ck_auth'}; - unless ($ck_auth) { - &login_menu(); - exit 0; - } load_config(1); # load prefs and do not log error msg @@ -570,10 +560,4 @@ $log->debug("<pre>" . Dumper(\%args) . "</pre>"); - # check cookie - unless ($ck_auth) { - $log->debug("bad cookie '$ck_auth'\n"); - &login_menu(); - exit 0; - } my $new_string = 'Add a new repository'; @@ -743,8 +727,4 @@ my $ck_auth = $args{'ck_auth'}; - unless ($ck_auth) { - &login_menu(); - exit 0; - } if (! load_config()) { # no existing user config, forward to prefs menu @@ -1057,8 +1037,4 @@ my %args = @_; my $ck_auth = $args{'ck_auth'}; - unless ($ck_auth) { - &login_menu(); - exit 0; - } if (! load_config()) { # no existing user config, forward to prefs menu @@ -1118,8 +1094,5 @@ my $ck_auth = $args{'ck_auth'}; - unless ($ck_auth) { - &login_menu(); - exit 0; - } + if (! load_config()) { # no existing user config, forward to prefs menu @@ -1259,8 +1232,5 @@ my %args = @_; my $ck_auth = $args{'ck_auth'}; - unless ($ck_auth) { - &login_menu(); - exit 0; - } + my $module_name = $args{'module_name'}; my $repo_name = $args{'repo_name'}; @@ -1355,8 +1325,4 @@ my %args = @_; my $ck_auth = $args{'ck_auth'}; - unless ($ck_auth) { - &login_menu(); - exit 0; - } load_config(1); # load prefs and do not log error msg @@ -1403,8 +1369,4 @@ my $repo_root = $args{'repo_root'}; my $new_repository = $args{'new_repository'} ? 1 : 0; - unless ($ck_auth) { - &login_menu(); - exit 0; - } my $new_string = 'Add a new repository'; @@ -1575,8 +1537,4 @@ $log->standard("$username logged on."); my $ck_auth = CGI::cookie( $auth->set_auth_cookie() ); - unless ($ck_auth) { - set_error("unable to set authentication cookie: '$ck_auth'"); - login_menu(); - } if (! load_config()) { # no existing user config, forward to prefs menu |