|
1
|
/* |
|
2
|
** Copyright (c) 2007 D. Richard Hipp |
|
3
|
** |
|
4
|
** This program is free software; you can redistribute it and/or |
|
5
|
** modify it under the terms of the Simplified BSD License (also |
|
6
|
** known as the "2-Clause License" or "FreeBSD License".) |
|
7
|
|
|
8
|
** This program is distributed in the hope that it will be useful, |
|
9
|
** but without any warranty; without even the implied warranty of |
|
10
|
** merchantability or fitness for a particular purpose. |
|
11
|
** |
|
12
|
** Author contact information: |
|
13
|
** [email protected] |
|
14
|
** http://www.hwaci.com/drh/ |
|
15
|
** |
|
16
|
******************************************************************************* |
|
17
|
** |
|
18
|
** This file contains code to implement the transfer configuration |
|
19
|
** setup screens. |
|
20
|
*/ |
|
21
|
#include "config.h" |
|
22
|
#include "xfersetup.h" |
|
23
|
#include <assert.h> |
|
24
|
|
|
25
|
/* |
|
26
|
** WEBPAGE: xfersetup |
|
27
|
** Main sub-menu for configuring the transfer system. |
|
28
|
*/ |
|
29
|
void xfersetup_page(void){ |
|
30
|
login_check_credentials(); |
|
31
|
if( !g.perm.Setup ){ |
|
32
|
login_needed(0); |
|
33
|
return; |
|
34
|
} |
|
35
|
|
|
36
|
style_header("Transfer Setup"); |
|
37
|
|
|
38
|
@ <table class="xfersetup"> |
|
39
|
setup_menu_entry("Common", "xfersetup_com", |
|
40
|
"Common TH1 code run before all transfer request processing."); |
|
41
|
setup_menu_entry("Push", "xfersetup_push", |
|
42
|
"Specific TH1 code to run after \"push\" transfer requests."); |
|
43
|
setup_menu_entry("Commit", "xfersetup_commit", |
|
44
|
"Specific TH1 code to run after processing a commit."); |
|
45
|
setup_menu_entry("Ticket", "xfersetup_ticket", |
|
46
|
"Specific TH1 code to run after processing a ticket change."); |
|
47
|
@ </table> |
|
48
|
|
|
49
|
url_parse(0, URL_USE_CONFIG); |
|
50
|
if( g.url.protocol ){ |
|
51
|
unsigned syncFlags; |
|
52
|
const char *zButton; |
|
53
|
char *zWarning; |
|
54
|
|
|
55
|
if( db_get_boolean("dont-push", 0) ){ |
|
56
|
syncFlags = SYNC_PULL; |
|
57
|
zButton = "Pull"; |
|
58
|
zWarning = 0; |
|
59
|
}else{ |
|
60
|
syncFlags = SYNC_PUSH | SYNC_PULL; |
|
61
|
zButton = "Synchronize"; |
|
62
|
zWarning = mprintf("WARNING: Pushing to \"%s\" is enabled.", |
|
63
|
g.url.canonical); |
|
64
|
} |
|
65
|
@ <p>Press the <strong>%h(zButton)</strong> button below to |
|
66
|
@ synchronize with the <em>%h(g.url.canonical)</em> repository now.<br> |
|
67
|
@ This may be useful when testing the various transfer scripts.</p> |
|
68
|
@ <p>You can use the <code>http -async</code> command in your scripts, but |
|
69
|
@ make sure the <code>th1-uri-regexp</code> setting is set first.</p> |
|
70
|
if( zWarning ){ |
|
71
|
@ |
|
72
|
@ <big><b>%h(zWarning)</b></big> |
|
73
|
free(zWarning); |
|
74
|
} |
|
75
|
@ |
|
76
|
@ <form method="post" action="%R/%s(g.zPath)"><div> |
|
77
|
login_insert_csrf_secret(); |
|
78
|
@ <input type="submit" name="sync" value="%h(zButton)"> |
|
79
|
@ </div></form> |
|
80
|
@ |
|
81
|
if( P("sync") ){ |
|
82
|
user_select(); |
|
83
|
url_enable_proxy(0); |
|
84
|
@ <pre class="xfersetup"> |
|
85
|
client_sync(syncFlags, 0, 0, 0, 0); |
|
86
|
@ </pre> |
|
87
|
} |
|
88
|
} |
|
89
|
|
|
90
|
style_finish_page(); |
|
91
|
} |
|
92
|
|
|
93
|
/* |
|
94
|
** Common implementation for the transfer setup editor pages. |
|
95
|
*/ |
|
96
|
static void xfersetup_generic( |
|
97
|
const char *zTitle, /* Page title */ |
|
98
|
const char *zDbField, /* Configuration field being edited */ |
|
99
|
const char *zDfltValue, /* Default text value */ |
|
100
|
const char *zDesc, /* Description of this field */ |
|
101
|
char *(*xText)(const char*), /* Validity test or NULL */ |
|
102
|
void (*xRebuild)(void), /* Run after successful update */ |
|
103
|
int height /* Height of the edit box */ |
|
104
|
){ |
|
105
|
const char *z; |
|
106
|
int isSubmit; |
|
107
|
|
|
108
|
login_check_credentials(); |
|
109
|
if( !g.perm.Setup ){ |
|
110
|
login_needed(0); |
|
111
|
return; |
|
112
|
} |
|
113
|
if( P("setup") ){ |
|
114
|
cgi_redirect("xfersetup"); |
|
115
|
} |
|
116
|
isSubmit = P("submit")!=0; |
|
117
|
z = P("x"); |
|
118
|
if( z==0 ){ |
|
119
|
z = db_get(zDbField, zDfltValue); |
|
120
|
} |
|
121
|
style_set_current_feature("xfersetup"); |
|
122
|
style_header("Edit %h", zTitle); |
|
123
|
if( P("clear")!=0 && cgi_csrf_safe(2) ){ |
|
124
|
db_unset(zDbField/*works-like:"x"*/, 0); |
|
125
|
if( xRebuild ) xRebuild(); |
|
126
|
z = zDfltValue; |
|
127
|
}else if( isSubmit && cgi_csrf_safe(2) ){ |
|
128
|
char *zErr = 0; |
|
129
|
if( xText && (zErr = xText(z))!=0 ){ |
|
130
|
@ <p class="xfersetupError">ERROR: %h(zErr)</p> |
|
131
|
}else{ |
|
132
|
db_set(zDbField/*works-like:"x"*/, z, 0); |
|
133
|
if( xRebuild ) xRebuild(); |
|
134
|
cgi_redirect("xfersetup"); |
|
135
|
} |
|
136
|
} |
|
137
|
@ <form action="%R/%s(g.zPath)" method="post"><div> |
|
138
|
login_insert_csrf_secret(); |
|
139
|
@ <p>%s(zDesc)</p> |
|
140
|
@ <textarea name="x" rows="%d(height)" cols="80">%h(z)</textarea> |
|
141
|
@ <p> |
|
142
|
@ <input type="submit" name="submit" value="Apply Changes"> |
|
143
|
@ <input type="submit" name="clear" value="Revert To Default"> |
|
144
|
@ <input type="submit" name="setup" value="Cancel"> |
|
145
|
@ </p> |
|
146
|
@ </div></form> |
|
147
|
if ( zDfltValue ){ |
|
148
|
@ <hr> |
|
149
|
@ <h2>Default %s(zTitle)</h2> |
|
150
|
@ <blockquote><pre> |
|
151
|
@ %h(zDfltValue) |
|
152
|
@ </pre></blockquote> |
|
153
|
} |
|
154
|
style_finish_page(); |
|
155
|
} |
|
156
|
|
|
157
|
static const char *zDefaultXferCommon = 0; |
|
158
|
|
|
159
|
/* |
|
160
|
** WEBPAGE: xfersetup_com |
|
161
|
** View or edit the TH1 script that runs prior to receiving a |
|
162
|
** transfer. |
|
163
|
*/ |
|
164
|
void xfersetup_com_page(void){ |
|
165
|
static const char zDesc[] = |
|
166
|
@ Enter TH1 script that initializes variables prior to running |
|
167
|
@ any of the transfer request scripts. |
|
168
|
; |
|
169
|
xfersetup_generic( |
|
170
|
"Transfer Common Script", |
|
171
|
"xfer-common-script", |
|
172
|
zDefaultXferCommon, |
|
173
|
zDesc, |
|
174
|
0, |
|
175
|
0, |
|
176
|
30 |
|
177
|
); |
|
178
|
} |
|
179
|
|
|
180
|
static const char *zDefaultXferPush = 0; |
|
181
|
|
|
182
|
/* |
|
183
|
** WEBPAGE: xfersetup_push |
|
184
|
** View or edit the TH1 script that runs after receiving a "push". |
|
185
|
*/ |
|
186
|
void xfersetup_push_page(void){ |
|
187
|
static const char zDesc[] = |
|
188
|
@ Enter TH1 script that runs after processing <strong>push</strong> |
|
189
|
@ transfer requests. |
|
190
|
; |
|
191
|
xfersetup_generic( |
|
192
|
"Transfer Push Script", |
|
193
|
"xfer-push-script", |
|
194
|
zDefaultXferPush, |
|
195
|
zDesc, |
|
196
|
0, |
|
197
|
0, |
|
198
|
30 |
|
199
|
); |
|
200
|
} |
|
201
|
|
|
202
|
static const char *zDefaultXferCommit = 0; |
|
203
|
|
|
204
|
/* |
|
205
|
** WEBPAGE: xfersetup_commit |
|
206
|
** View or edit the TH1 script that runs when a transfer commit |
|
207
|
** is processed. |
|
208
|
*/ |
|
209
|
void xfersetup_commit_page(void){ |
|
210
|
static const char zDesc[] = |
|
211
|
@ Enter TH1 script that runs when a commit is processed. |
|
212
|
; |
|
213
|
xfersetup_generic( |
|
214
|
"Transfer Commit Script", |
|
215
|
"xfer-commit-script", |
|
216
|
zDefaultXferCommit, |
|
217
|
zDesc, |
|
218
|
0, |
|
219
|
0, |
|
220
|
30 |
|
221
|
); |
|
222
|
} |
|
223
|
|
|
224
|
static const char *zDefaultXferTicket = 0; |
|
225
|
|
|
226
|
/* |
|
227
|
** WEBPAGE: xfersetup_ticket |
|
228
|
** View or edit the TH1 script that runs when a ticket change artifact |
|
229
|
** is processed during a transfer. |
|
230
|
*/ |
|
231
|
void xfersetup_ticket_page(void){ |
|
232
|
static const char zDesc[] = |
|
233
|
@ Enter TH1 script that runs when a ticket change is processed. |
|
234
|
; |
|
235
|
xfersetup_generic( |
|
236
|
"Transfer Ticket Script", |
|
237
|
"xfer-ticket-script", |
|
238
|
zDefaultXferTicket, |
|
239
|
zDesc, |
|
240
|
0, |
|
241
|
0, |
|
242
|
30 |
|
243
|
); |
|
244
|
} |
|
245
|
|