shlib.sh: add -i option to tee command
[girocco/readme.git] / cgi / editproj.cgi
blob3f41849b5a4ec096a56e39d6fd716fe25f8149e6
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib ".";
9 use Girocco::CGI;
10 use Girocco::Config;
11 use Girocco::Project;
12 use Girocco::Util;
13 use POSIX qw(strftime);
15 my $script = <<'EOT';
16 <script type="text/javascript">
17 // <![CDATA[
18 function adduseritem(elem)
20 var inp = document.createElement('input');
21 inp.type = 'text';
22 inp.name = 'user';
23 var li = document.createElement('li');
24 li.appendChild(document.createTextNode('Add user: '));
25 li.appendChild(inp);
26 elem.parentNode.insertBefore(li, elem);
28 // ]]>
29 </script>
30 EOT
31 my $gcgi = Girocco::CGI->new('Project Settings', undef, $script);
32 my $cgi = $gcgi->cgi;
34 my $name = $cgi->param('name');
35 $name =~ s#\.git$## if $name; #
37 unless (defined $name) {
38 print "<p>I need the project name as an argument now.</p>\n";
39 exit;
42 if (!Girocco::Project::does_exist($name,1) && !Girocco::Project::valid_name($name)) {
43 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
44 exit;
47 if (!Girocco::Project::does_exist($name,1)) {
48 print "<p>Sorry but the project $name does not exist. Now, how did you <em>get</em> here?!</p>\n";
49 exit;
52 my $proj = Girocco::Project->load($name);
53 if (!$proj) {
54 print "<p>not found project $name, that's really weird!</p>\n";
55 exit;
57 my $escname = $name;
58 $escname =~ s/[+]/%2B/g;
60 my $y0 = $cgi->param('y0') || '';
61 if (($y0 eq 'Update' || $y0 eq 'Restart Mirroring') && $cgi->request_method eq 'POST') {
62 # submitted, let's see
63 my $utc = strftime('%Y-%m-%d %H:%M:%S UTC', (gmtime(time()))[0..5], -1, -1, -1);
64 my $ts = "<span class=\"timestamp\">$utc</span>";
65 $gcgi->err_prelude("<p class=\"failed\">Project update failed at $ts.</p>\n");
66 if ($proj->cgi_fill($gcgi) and $proj->authenticate($gcgi) and $proj->update) {
67 print "<p class=\"updated\">Project successfully updated at $ts.</p>\n";
68 if ($proj->{clone_failed}) {
69 $proj->clone;
70 print "<p>Please <a href=\"@{[url_path($Girocco::Config::webadmurl)]}".
71 "/mirrorproj.cgi?name=$escname\">pass onwards</a>.</p>\n";
72 print "<script language=\"javascript\">document.location=".
73 "'@{[url_path($Girocco::Config::webadmurl)]}/mirrorproj.cgi?name=$escname'</script>\n";
74 exit;
79 # $proj may be insane now but that's actually good for us since we'll let the
80 # user fix the invalid values he or she entered
81 my %h = $proj->form_defaults;
83 print <<EOT;
84 <p>Here you may adjust the settings of project $h{name}. Go wild.
85 EOT
86 if ($proj->{mirror}) {
87 print <<EOT;
88 Since this is a mirrored project, you may opt to remove it from the site as well.
89 Just <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname">remove it</a>.</p>
90 EOT
91 } else {
92 if ($proj->is_empty) {
93 print <<EOT;
94 Since this is an empty project, you may opt to remove it from the site as well.
95 Just <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname">remove it</a>.</p>
96 EOT
97 } else {
98 print <<EOT;
99 You may
100 <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname">request an authorization code</a> in order
101 to remove this project from the site.</p>
104 print <<EOT;
105 <p>Use the <b>+</b> button to enable access for more than a single user at a time.</p>
109 my $button_label = $proj->{clone_failed} ? 'Restart Mirroring' : 'Update';
110 my $showstatusopt = $proj->{mirror} && !$proj->{clone_failed} && !$proj->{clone_in_progress};
111 my $statuschecked = $proj->{statusupdates} ? 'checked="checked"' : '';
113 print <<EOT;
114 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/editproj.cgi">
115 <table class="form">
116 <tr><td class="formlabel">Project name:</td><td class="formdata"><a
117 href="@{[url_path($Girocco::Config::gitweburl)]}/$h{name}.git">$h{name}</a>.git
118 <input type="hidden" name="name" value="$h{name}" /></td></tr>
120 if ($Girocco::Config::project_passwords) {
121 print <<EOT;
122 <tr><td class="formlabel"><strong>Admin password:</strong></td><td>
123 <input type="password" name="cpwd" /> <sup><a
124 href="@{[url_path($Girocco::Config::webadmurl)]}/pwproj.cgi?name=$escname"
125 class="ctxaction">(forgot password?)</a></sup></td></tr>
126 <tr><td class="formlabel">New admin password (twice):<br />
127 <em>(leave empty to keep it the same)</em></td><td>
128 <input type="password" name="pwd" /><br /><input type="password" name="pwd2" /><br />
129 </td></tr>
132 if ($Girocco::Config::project_owners eq 'email') {
133 print <<EOT;
134 <tr><td class="formlabel">E-mail contact:</td><td><input type="text" name="email" value="$h{email}" /></td></tr>
138 if ($proj->{mirror}) {
139 print "<tr><td class=\"formlabel\">Repository URL:</td><td><input type=\"text\" name=\"url\" value=\"$h{url}\" /></td></tr>\n";
140 } else {
141 print <<EOT;
142 <tr><td class="formlabel" style="vertical-align:middle">Users:</td><td>
143 <ul>
145 $Girocco::Config::manage_users and print "<p>Only <a href=\"".
146 "@{[url_path($Girocco::Config::webadmurl)]}/reguser.cgi\">registered users</a> may push.</p>";
147 if ($Girocco::Config::mob and not grep { $_ eq $Girocco::Config::mob } @{$h{users}}) {
148 print "<p><em>(Please consider adding the <tt>$Girocco::Config::mob</tt> user.\n";
149 print "<sup><a href=\"@{[url_path($Girocco::Config::htmlurl)]}/mob.html\">(learn more)</a></sup>)\n";
150 print "</em></p>\n";
152 foreach my $user (@{$h{users}}) {
153 my $mlm = '';
154 $mlm = " <sup><a href=\"@{[url_path($Girocco::Config::htmlurl)]}/mob.html\">(learn more)</a></sup>"
155 if $Girocco::Config::mob && $user eq $Girocco::Config::mob;
156 print "<li><input type=\"checkbox\" name=\"user\" value=\"$user\" checked=\"1\" /> $user$mlm</li>\n";
158 print <<EOT;
159 <li>Add user: <input type="text" name="user" /></li>
160 <button type="button" onclick="adduseritem(this)"><b>+</b></button>
161 </ul>
162 </td></tr>
166 print '<tr><td class="formlabel">Default branch:</td><td><select size="1" name="HEAD">';
167 for ($proj->get_heads) {
168 my $selected = $proj->{HEAD} eq $_ ? ' selected="selected"' : '';
169 print "<option$selected>".Girocco::CGI::html_esc($_)."</option>";
171 print '</select></td></tr>
174 print '<tr><td class="formlabel">Tags (select to delete):</td><td>';
175 print '<select size="6" name="tags" multiple="multiple">';
176 for ($proj->get_ctag_names) {
177 print '<option>'.Girocco::CGI::html_esc($_).'</option>';
179 print '</select></td></tr>
183 $gcgi->print_form_fields($Girocco::Project::metadata_fields, \%h, @Girocco::Config::project_fields);
184 print <<EOT if $showstatusopt;
185 <tr><td class="formlabel">Enable status update emails:</td>
186 <td class="formdatatd"
187 ><input type="hidden" name="setstatusupdates" value="1"
188 /><input type="checkbox" name="statusupdates" value="1" $statuschecked /></td></tr>
190 print <<EOT;
191 <tr><td class="formlabel"></td><td><input type="submit" name="y0" value="$button_label" /></td></tr>
192 </table>
193 </form>