2 # (c) Petr Baudis <pasky@suse.cz>
13 use POSIX
qw(strftime);
16 <script type="text/javascript">
18 function adduseritem(elem)
20 var inp = document.createElement('input');
23 var li = document.createElement('li');
24 li.appendChild(document.createTextNode('Add user: '));
26 elem.parentNode.insertBefore(li, elem);
31 my $gcgi = Girocco
::CGI
->new('Project Settings', undef, $script);
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";
42 if (!Girocco
::Project
::does_exist
($name,1) && !Girocco
::Project
::valid_name
($name)) {
43 print "<p>Invalid project name. Go away, sorcerer.</p>\n";
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";
52 if (my $romsg=check_readonly
(1)) {
53 print "<p>$romsg</p>\n";
57 my $proj = Girocco
::Project
->load($name);
59 print "<p>not found project $name, that's really weird!</p>\n";
63 $escname =~ s/[+]/%2B/g;
65 my $tzoffset = $cgi->param('tzoffset') || 0;
66 $tzoffset =~ /^[-+]?\d{1,5}$/ or $tzoffset = 0;
67 $tzoffset = 0 + $tzoffset;
68 $tzoffset >= -43200 && $tzoffset <= 43200 or $tzoffset = 0;
72 defined($es) or $es = time();
74 my $str = strftime
("%Y-%m-%d %H:%M:%S ", (gmtime($es))[0..5], -1, -1, -1);
76 my $moff = int(abs($tzoffset) / 60);
77 $str .= sprintf("%s%02d%02d",
78 ($tzoffset >= 0 ?
"+" : "-"),
80 $moff - 60 * int($moff / 60));
87 my $y0 = $cgi->param('y0') || '';
88 my $tok = $cgi->param('token') || '';
90 if (($y0 eq 'Update' || $y0 eq 'View All' || $y0 eq 'Restart Mirroring') && $cgi->request_method eq 'POST') {{
91 my $ts = "<span class=\"timestamp\">" . format_epoch_ts
() . "</span>";
92 $gcgi->err_prelude("<p class=\"failed\">Project update failed at $ts.</p>\n") unless $y0 eq 'View All';
93 # Check for token validity
94 if (!check_timed_token
($tok, "projedit", $proj->{name
}, $Girocco::Config
::project_edit_timeout
)) {
95 $gcgi->err("Session has timed out or is invalid, please try again.");
97 # submitted, let's see
98 my $fillok = $proj->cgi_fill($gcgi, 1);
99 my $authok = $proj->authenticate($gcgi);
100 $authok and $protok = 1;
101 $y0 eq 'View All' and last;
102 if (!$gcgi->err_check && $authok) {
103 $proj->update or last;
104 print "<p class=\"updated\">Project successfully updated at $ts.</p>\n";
105 if ($proj->{clone_failed
}) {
107 print "<p>Please <a href=\"@{[url_path($Girocco::Config::webadmurl)]}".
108 "/mirrorproj.cgi?name=$escname\">pass onwards</a>.</p>\n";
109 print "<script language=\"javascript\">document.location=".
110 "'@{[url_path($Girocco::Config::webadmurl)]}/mirrorproj.cgi?name=$escname'</script>\n";
116 # $proj may be insane now but that's actually good for us since we'll let the
117 # user fix the invalid values he or she entered
118 my %h = $proj->form_defaults;
121 <p>Here you may adjust the settings of project $h{name}. Go wild.
123 if ($proj->{mirror
}) {
125 Since this is a mirrored project, you may opt to remove it from the site as well.
126 Just <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname">remove it</a>.</p>
129 if ($proj->is_empty) {
131 Since this is an empty project, you may opt to remove it from the site as well.
132 Just <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname">remove it</a>.</p>
137 <a href="@{[url_path($Girocco::Config::webadmurl)]}/delproj.cgi?name=$escname">request an authorization code</a> in order
138 to remove this project from the site.</p>
142 <p>Use the <b>+</b> button to enable access for more than a single user at a time.</p>
146 my $button_label = $proj->{clone_failed
} ?
'Restart Mirroring' : 'Update';
147 my $showstatusopt = $proj->{mirror
} && !$proj->{clone_failed
} && !$proj->{clone_in_progress
};
148 my $statuschecked = $proj->{statusupdates
} ?
'checked="checked"' : '';
149 my $tokauth = get_token_field
("projedit", $h{name
}, $Girocco::Config
::project_edit_timeout
);
150 $tokauth and $tokauth = "\n".$tokauth;
153 <form method="post" action="@{[url_path($Girocco::Config::webadmurl)]}/editproj.cgi">$tokauth
154 <input type="hidden" name="tzoffset" value="0" />
156 <tr><td class="formlabel">Project name:</td><td class="formdata"><a
157 href="@{[url_path($Girocco::Config::gitweburl)]}/$h{name}.git">$h{name}</a>.git
158 <input type="hidden" name="name" value="$h{name}" /></td></tr>
160 if ($Girocco::Config
::project_passwords
) {
162 $protok || !%{$Girocco::Config
::protect_fields
} or
163 $vab = '  <input type="submit" name="y0" value="View All" />';
165 <tr><td class="formlabel"><strong>Admin password:</strong></td><td>
166 <input type="password" name="cpwd" /> <sup class="sup"><span><a
167 href="@{[url_path($Girocco::Config::webadmurl)]}/pwproj.cgi?name=$escname"
168 class="ctxaction">(forgot password?)</a></span></sup>$vab</td></tr>
169 <tr><td class="formlabel">New admin password (twice):<br />
170 <em>(leave empty to keep it the same)</em></td><td>
171 <input type="password" name="pwd" /><br /><input type="password" name="pwd2" /><br />
175 if ($Girocco::Config
::project_owners
eq 'email') {
177 <tr><td class="formlabel">E-mail contact:</td><td><input type="text" name="email" value="$h{email}" /></td></tr>
181 if ($proj->{mirror
}) {
182 print "<tr><td class=\"formlabel\">Repository URL:</td><td><input type=\"text\" name=\"url\" value=\"$h{url}\" /></td></tr>\n";
183 print '<tr><td class="formlabel">Mirror refs:</td><td class="formdatatd">'.
184 '<label title="Unchecking this will mirror the entire refs namespace which is usually unnecessary. '.
185 'Non-git sources always mirror the entire refs namespace regardless of this setting.">'.
186 '<input type="checkbox" name="cleanmirror" value="1" '.($h{'cleanmirror'} ?
'checked="checked" ' : '').
187 'style="vertical-align:middle" /><span style="vertical-align:middle; margin-left:0.5ex">'.
188 'Only mirror <code>refs/heads/*</code>, <code>refs/tags/*</code> and <code>refs/notes/*</code></span></label></td></tr>'."\n"
189 if grep(/cleanmirror/, @Girocco::Config
::project_fields
);
192 <tr><td class="formlabel" style="vertical-align:middle">Users:</td><td>
195 $Girocco::Config
::manage_users
and print "<p>Only <a href=\"".
196 "@{[url_path($Girocco::Config::webadmurl)]}/reguser.cgi\">registered users</a> may push.</p>";
197 if ($Girocco::Config
::mob
and not grep { $_ eq $Girocco::Config
::mob
} @
{$h{users
}}) {
198 print "<p><em>(Please consider adding the <tt>$Girocco::Config::mob</tt> user.\n";
199 print "<sup class=\"sup\"><span><a href=\"@{[url_path($Girocco::Config::htmlurl)]}/mob.html\">(learn more)</a></span></sup>)\n";
202 foreach my $user (@
{$h{users
}}) {
204 $mlm = " <sup class=\"sup\"><span><a href=\"@{[url_path($Girocco::Config::htmlurl)]}/mob.html\">(learn more)</a></span></sup>"
205 if $Girocco::Config
::mob
&& $user eq $Girocco::Config
::mob
;
206 print "<li><input type=\"checkbox\" name=\"user\" value=\"$user\" checked=\"1\" /> $user$mlm</li>\n";
209 <li>Add user: <input type="text" name="user" /></li>
210 <button type="button" onclick="adduseritem(this)"><b>+</b></button>
216 print '<tr><td class="formlabel">Default branch:</td><td class="formdatatd"><select size="1" name="HEAD">';
217 for ($proj->get_heads) {
218 my $selected = $proj->{HEAD
} eq $_ ?
' selected="selected"' : '';
219 print "<option$selected>".Girocco
::CGI
::html_esc
($_)."</option>";
221 print '</select></td></tr>
224 print '<tr><td class="formlabel">Tags (select to delete):</td><td>';
225 print '<select size="6" name="tags" multiple="multiple">';
226 for ($proj->get_ctag_names) {
227 print '<option>'.Girocco
::CGI
::html_esc
($_).'</option>';
229 print '</select></td></tr>
233 $gcgi->print_form_fields($Girocco::Project
::metadata_fields
,
234 $protok?
{}:$Girocco::Config
::protect_fields
,
235 \
%h, @Girocco::Config
::project_fields
);
236 print <<EOT if $showstatusopt;
237 <tr><td class="formlabel">Enable status update emails:</td>
238 <td class="formdatatd"
239 ><input type="hidden" name="setstatusupdates" value="1"
240 /><input type="checkbox" name="statusupdates" value="1" $statuschecked /></td></tr>
243 <tr><td class="formlabel"></td><td><input type="submit" name="y0" value="$button_label" /></td></tr>
246 <script type="text/javascript">
249 var tzoffset = (new Date).getTimezoneOffset() * -60;
250 var form0 = document.forms[0];
251 if (form0 && form0.tzoffset) {
252 form0.tzoffset.value = tzoffset;