sep-urls.gawk 5.97 KB
Newer Older
1 2 3
#! /usr/bin/gawk -f
#
# Copyright (c) 2000-2006 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25
#
# sep-urls - Separate out the setup and teardown URL's.
# 
26 27 28 29
#   Input is in two parts, concatenated: 
#     . An ordered list of .php3 filenames, with interspersed action lines.
#       - PHP filename lines have a / at the front to anchor them for
#         uniqueness.
30
#       - Comment lines are prefixed by a "#".
31
#       - Action lines are prefixed by a "!" or "-".  See urls-to-wget.gawk
32
#         for further descriptions.
33
#       - Leading whitespace on lines is removed, so actions can be indented.
34 35 36 37 38
#
#     . Then the URL's to be separated out and ordered according to the list.
#
#   Output is the subset of URL's corresponding to the file list, in order,
#   with action lines added.  Meant to be fed to urls-to-wget.gawk .
Russ Fish's avatar
Russ Fish committed
39 40
#
#   A -v SYSADMIN= awk arg specifies the administrator login name to use.
41
#
Russ Fish's avatar
Russ Fish committed
42
 
43 44 45
# Remove leading whitespace on lines.
{$1 = $1;}

Russ Fish's avatar
Russ Fish committed
46
# Just a slash and filename, so not a URL.
47
# Remember its name and output order.
Russ Fish's avatar
Russ Fish committed
48 49
/^[/]/ { names[++nfiles] = name = substr($0,2); order[name] = nfiles; next; }

50 51
# Action lines start with an exclamation point or dash.  Just pass through.
/^!/ { urls[++nfiles ",1"] = $0; next; }
52 53
# Concatenate (possibly multiple) inverse actions.
/^-/ { inverse[name] = (inv=inverse[name]) (length(inv)?"\n":"") $0; next; }
Russ Fish's avatar
Russ Fish committed
54

55 56
# Ignore comments and blank lines.
/^#/ || /^[ \t]*$/ { next; }
57 58 59 60 61

# Common code to register a URL for a file into the urls array.
function fn_url(fn, url) {
    # Maybe many URL's per filename when probing, so append a count subscript.
    if ( o = order[fn] ) urls[o "," (nn = ++n_urls[o])] = url;
Russ Fish's avatar
Russ Fish committed
62
    ##printf "file %s, order %s/%s, url %s\n", fn, o, nn, url;
Russ Fish's avatar
Russ Fish committed
63
}
64 65 66

# Stash the desired URL's, indexed by their output order.
{
67 68 69
    # XXX Bash the proj, group, user, exp ids to leave activation objs alone.
    # The setup and teardown sequences use a "3" suffix for their objects.
    $0 = gensub("(test(proj|group|exp|img|osid|imgid))[12]?", "\\13", "g", $0);
Russ Fish's avatar
Russ Fish committed
70
    $0 = gensub("(testuse?r)[12]?", "testusr3", "g", $0);
71
    $0 = gensub("(TestUser)[12]?", "TestUser3", "g", $0);
Russ Fish's avatar
Russ Fish committed
72 73
    $0 = gensub("(pid\\]?=)testbed", "\\1testproj3", "g", $0);

74
    # XXX The testexp3 index comes from the DB at runtime.  (May be newly made.)
Russ Fish's avatar
Russ Fish committed
75 76
    # In the setup/teardown scripts, we put it in a shell variable named "$expidx".
    # In the show script actions, we use the activation object made in the makefile.
77 78 79 80 81 82 83 84 85
    $0 = gensub("(experiment=)[0-9]+", "\\1$expidx", "g", $0);

    # XXX Ditto the testusr3 index, "$usridx".
    $0 = gensub("(user=)[0-9]+", "\\1$usridx", "g", $0);
    # Also in trust and approval strings, e.g. U503$$trust
    $0 = gensub("U[0-9][0-9]*[$][$]", "U$usridx\"'$$'\"", "g", $0);
    # add_ and change_ specs in editgroup_form.
    $0 = gensub("(add_|change_)[0-9][0-9]*=", "\\1$usridx=", "g", $0);

86
    # Extract the filename: Remove args suffix after php tail, then path prefix.
87
    fn = gensub(".*/", "", 1, gensub("(php3*).*", "\\1", 1, $0));
88 89 90 91 92 93 94 95

    # XXX A bunch of per-page special cases.  (Grumble.)
    #
    # Probe the login page separately; it messes up admin mode from the makefile now.
    if ( fn == "login.php3" ) {
	next;
    }
    # Now user e-mail addresses must be unique, as well as login names.
Russ Fish's avatar
Russ Fish committed
96
    else if ( fn == "joinproject.php3" || fn == "moduserinfo.php3" ) {
97
	sub( "\\[usr_email\\]=" SYSADMIN "@", "[usr_email]=testusr3@");
Russ Fish's avatar
Russ Fish committed
98 99 100 101
	if ( fn == "moduserinfo.php3" ) {
            # And the password must actually be changed, if specified.
	    $0 = gensub("(\\[password[12]\\])=[^&]*", "\\1=NeW_pAsS", "g", $0);
	}
102 103 104
    }
    # Approval field name for approveuser contains user name, postpone is default.
    # Can't substitute in input_values.list because the field name isn't known.
Russ Fish's avatar
Russ Fish committed
105
    else if ( fn == "approveuser.php3" ) {
106 107
	sub("=postpone", "=approve");
    }
108
    # Don't swap in testexp3 as it is created, unlike testexp1.
Russ Fish's avatar
Russ Fish committed
109
    else if ( fn == "beginexp_html.php3" ) {
110 111
	sub("$", "\\&formfields[exp_preload]=Yep");
    }
Russ Fish's avatar
Russ Fish committed
112 113 114 115 116 117 118 119 120 121 122 123
    # Confirm newimageid_ez and loadimage.
    else if (fn == "newimageid_ez.php3" || fn == "loadimage.php3" ) {
	sub("$", "\\&confirmed=Confirm");
    }
    # Suffix the imagename so newimageid doesn't step on newimageid_ez.
    else if (fn == "newimageid.php3" ) {
	gsub("img3", "img3a");
    }
    # This looks like a bug: link url's should use target_project, not pid.
    else if ( fn == "deleteuser.php3") {  
	sub("&pid=", "\\&target_project=");
    }
124 125 126 127
    # It's a pain to reallocate nodes; just cancel freenode instead of confirming.
    else if ( fn == "freenode.php3") {  
	sub("confirmed=Confirm", "canceled=Cancel");
    }
128

129 130 131 132 133 134 135
    # REALLY REALLY confirm freezeuser, deleteuser, and deleteproject.
    if ( fn == "freezeuser.php3" || fn == "deleteuser.php3" \
	 || fn == "deleteproject.php3") {
	sub("confirmed=Confirm", "confirmed=Confirm\\&confirmed_twice=Confirm");
    }

    fn_url(fn, $0);
136 137
}

Russ Fish's avatar
Russ Fish committed
138 139
# Dump the ones seen, in order, with action lines interspersed.
# Complain about the ones not seen.
140 141
END{
    for ( i = 1; i <= nfiles; i++ )
142 143 144 145 146 147 148
	if ( length(urls[i ",1"]) )
	    for ( n = 1; length( url = urls[i "," n] ); n++ ) {
		print url;
		# Append "inverse action" lines.
		inv = inverse[names[i]];
		if ( length(inv) ) print inv;
	    }
Russ Fish's avatar
Russ Fish committed
149
	else if ( names[i] != "login.php3" ) # Login is handled specially.
150
		print "*** Missing:", i, names[i] > "/dev/stderr"
151
}