Fossil SCM

fossil-scm / src / configure.c
Source Blame History 1157 lines
e06ae9f… drh 1 /*
c19f34c… drh 2 ** Copyright (c) 2008 D. Richard Hipp
e06ae9f… drh 3 **
e06ae9f… drh 4 ** This program is free software; you can redistribute it and/or
c06edd2… drh 5 ** modify it under the terms of the Simplified BSD License (also
c06edd2… drh 6 ** known as the "2-Clause License" or "FreeBSD License".)
1654456… drh 7 **
e06ae9f… drh 8 ** This program is distributed in the hope that it will be useful,
c06edd2… drh 9 ** but without any warranty; without even the implied warranty of
c06edd2… drh 10 ** merchantability or fitness for a particular purpose.
e06ae9f… drh 11 **
e06ae9f… drh 12 ** Author contact information:
e06ae9f… drh 13 ** [email protected]
e06ae9f… drh 14 ** http://www.hwaci.com/drh/
e06ae9f… drh 15 **
e06ae9f… drh 16 *******************************************************************************
e06ae9f… drh 17 **
e06ae9f… drh 18 ** This file contains code used to manage repository configurations.
71fc181… drh 19 **
db0c512… drh 20 ** By "repository configure" we mean the local state of a repository
e06ae9f… drh 21 ** distinct from the versioned files.
e06ae9f… drh 22 */
e06ae9f… drh 23 #include "config.h"
e06ae9f… drh 24 #include "configure.h"
e06ae9f… drh 25 #include <assert.h>
e06ae9f… drh 26
e06ae9f… drh 27 #if INTERFACE
e06ae9f… drh 28 /*
e06ae9f… drh 29 ** Configuration transfers occur in groups. These are the allowed
e06ae9f… drh 30 ** groupings:
e06ae9f… drh 31 */
b87d3b8… drh 32 #define CONFIGSET_CSS 0x000001 /* Style sheet only */
b87d3b8… drh 33 #define CONFIGSET_SKIN 0x000002 /* WWW interface appearance */
b87d3b8… drh 34 #define CONFIGSET_TKT 0x000004 /* Ticket configuration */
b87d3b8… drh 35 #define CONFIGSET_PROJ 0x000008 /* Project name */
b87d3b8… drh 36 #define CONFIGSET_SHUN 0x000010 /* Shun settings */
b87d3b8… drh 37 #define CONFIGSET_USER 0x000020 /* The USER table */
b87d3b8… drh 38 #define CONFIGSET_ADDR 0x000040 /* The CONCEALED table */
b87d3b8… drh 39 #define CONFIGSET_XFER 0x000080 /* Transfer configuration */
3d36a37… drh 40 #define CONFIGSET_ALIAS 0x000100 /* URL Aliases */
7f0c7fc… drh 41 #define CONFIGSET_SCRIBER 0x000200 /* Email subscribers */
f4dc114… drh 42 #define CONFIGSET_IWIKI 0x000400 /* Interwiki codes */
f4dc114… drh 43 #define CONFIGSET_ALL 0x0007ff /* Everything */
1654456… drh 44
1654456… drh 45 #define CONFIGSET_OVERWRITE 0x100000 /* Causes overwrite instead of merge */
52ed681… mistachkin 46
52ed681… mistachkin 47 /*
52ed681… mistachkin 48 ** This mask is used for the common TH1 configuration settings (i.e. those
52ed681… mistachkin 49 ** that are not specific to one particular subsystem, such as the transfer
52ed681… mistachkin 50 ** subsystem).
52ed681… mistachkin 51 */
52ed681… mistachkin 52 #define CONFIGSET_TH1 (CONFIGSET_SKIN|CONFIGSET_TKT|CONFIGSET_XFER)
e06ae9f… drh 53
e06ae9f… drh 54 #endif /* INTERFACE */
e06ae9f… drh 55
e06ae9f… drh 56 /*
e06ae9f… drh 57 ** Names of the configuration sets
e06ae9f… drh 58 */
e06ae9f… drh 59 static struct {
e06ae9f… drh 60 const char *zName; /* Name of the configuration set */
e06ae9f… drh 61 int groupMask; /* Mask for that configuration set */
bf75ea9… drh 62 const char *zHelp; /* What it does */
e06ae9f… drh 63 } aGroupName[] = {
f4dc114… drh 64 { "/email", CONFIGSET_ADDR, "Concealed email addresses in tickets" },
f4dc114… drh 65 { "/project", CONFIGSET_PROJ, "Project name and description" },
7f0c7fc… drh 66 { "/skin", CONFIGSET_SKIN | CONFIGSET_CSS,
f4dc114… drh 67 "Web interface appearance settings" },
f4dc114… drh 68 { "/css", CONFIGSET_CSS, "Style sheet" },
f4dc114… drh 69 { "/shun", CONFIGSET_SHUN, "List of shunned artifacts" },
f4dc114… drh 70 { "/ticket", CONFIGSET_TKT, "Ticket setup", },
f4dc114… drh 71 { "/user", CONFIGSET_USER, "Users and privilege settings" },
f4dc114… drh 72 { "/xfer", CONFIGSET_XFER, "Transfer setup", },
f4dc114… drh 73 { "/alias", CONFIGSET_ALIAS, "URL Aliases", },
f4dc114… drh 74 { "/subscriber", CONFIGSET_SCRIBER, "Email notification subscriber list" },
f4dc114… drh 75 { "/interwiki", CONFIGSET_IWIKI, "Inter-wiki link prefixes" },
f4dc114… drh 76 { "/all", CONFIGSET_ALL, "All of the above" },
e06ae9f… drh 77 };
e06ae9f… drh 78
e06ae9f… drh 79
e06ae9f… drh 80 /*
e06ae9f… drh 81 ** The following is a list of settings that we are willing to
dacc694… jan.nijtmans 82 ** transfer.
bf75ea9… drh 83 **
bf75ea9… drh 84 ** Setting names that begin with an alphabetic characters refer to
bf75ea9… drh 85 ** single entries in the CONFIG table. Setting names that begin with
bf75ea9… drh 86 ** "@" are for special processing.
e06ae9f… drh 87 */
e06ae9f… drh 88 static struct {
e06ae9f… drh 89 const char *zName; /* Name of the configuration parameter */
e06ae9f… drh 90 int groupMask; /* Which config groups is it part of */
28e5628… drh 91 } aConfig[] = {
b87d3b8… drh 92 { "css", CONFIGSET_CSS },
bf75ea9… drh 93 { "header", CONFIGSET_SKIN },
5f22712… drh 94 { "mainmenu", CONFIGSET_SKIN },
bf75ea9… drh 95 { "footer", CONFIGSET_SKIN },
106c090… drh 96 { "details", CONFIGSET_SKIN },
498fc87… drh 97 { "js", CONFIGSET_SKIN },
818a6ad… drh 98 { "default-skin", CONFIGSET_SKIN },
4348111… drh 99 { "logo-mimetype", CONFIGSET_SKIN },
4348111… drh 100 { "logo-image", CONFIGSET_SKIN },
6239845… drh 101 { "background-mimetype", CONFIGSET_SKIN },
6239845… drh 102 { "background-image", CONFIGSET_SKIN },
37262b8… mistachkin 103 { "icon-mimetype", CONFIGSET_SKIN },
37262b8… mistachkin 104 { "icon-image", CONFIGSET_SKIN },
6908832… drh 105 { "timeline-date-format", CONFIGSET_SKIN },
bc8691c… drh 106 { "timeline-default-style", CONFIGSET_SKIN },
6908832… drh 107 { "timeline-dwelltime", CONFIGSET_SKIN },
6908832… drh 108 { "timeline-closetime", CONFIGSET_SKIN },
89388d4… stephan 109 { "timeline-hard-newlines", CONFIGSET_SKIN },
bf75ea9… drh 110 { "timeline-max-comment", CONFIGSET_SKIN },
2c6fa9c… drh 111 { "timeline-plaintext", CONFIGSET_SKIN },
6908832… drh 112 { "timeline-truncate-at-blank", CONFIGSET_SKIN },
4dbd4e3… florian 113 { "timeline-tslink-info", CONFIGSET_SKIN },
6908832… drh 114 { "timeline-utc", CONFIGSET_SKIN },
4bf5cdc… drh 115 { "adunit", CONFIGSET_SKIN },
4bf5cdc… drh 116 { "adunit-omit-if-admin", CONFIGSET_SKIN },
4bf5cdc… drh 117 { "adunit-omit-if-user", CONFIGSET_SKIN },
14c81d9… drh 118 { "default-csp", CONFIGSET_SKIN },
aa5beb8… drh 119 { "sitemap-extra", CONFIGSET_SKIN },
333520a… stephan 120 { "safe-html", CONFIGSET_SKIN },
333520a… stephan 121
ff8ac8d… mistachkin 122 #ifdef FOSSIL_ENABLE_TH1_HOOKS
ff8ac8d… mistachkin 123 { "th1-hooks", CONFIGSET_TH1 },
6239845… drh 124 #endif
ff8ac8d… mistachkin 125 { "th1-uri-regexp", CONFIGSET_TH1 },
6239845… drh 126
6239845… drh 127 { "project-name", CONFIGSET_PROJ },
1239545… drh 128 { "short-project-name", CONFIGSET_PROJ },
6239845… drh 129 { "project-description", CONFIGSET_PROJ },
5098f74… jan.nijtmans 130 { "index-page", CONFIGSET_PROJ },
6239845… drh 131 { "manifest", CONFIGSET_PROJ },
6ef41ee… mistachkin 132 { "binary-glob", CONFIGSET_PROJ },
b7afa97… mistachkin 133 { "clean-glob", CONFIGSET_PROJ },
6239845… drh 134 { "ignore-glob", CONFIGSET_PROJ },
982f9ec… jan.nijtmans 135 { "keep-glob", CONFIGSET_PROJ },
87320cf… andygoth 136 { "crlf-glob", CONFIGSET_PROJ },
6239845… drh 137 { "crnl-glob", CONFIGSET_PROJ },
7d237c4… jan.nijtmans 138 { "encoding-glob", CONFIGSET_PROJ },
6239845… drh 139 { "empty-dirs", CONFIGSET_PROJ },
9a67bab… mistachkin 140 { "dotfiles", CONFIGSET_PROJ },
08e65c2… drh 141 { "parent-project-code", CONFIGSET_PROJ },
08e65c2… drh 142 { "parent-project-name", CONFIGSET_PROJ },
e92133a… drh 143 { "hash-policy", CONFIGSET_PROJ },
2476b81… drh 144 { "comment-format", CONFIGSET_PROJ },
009a243… stephan 145 { "mimetypes", CONFIGSET_PROJ },
44ac944… drh 146 { "forbid-delta-manifests", CONFIGSET_PROJ },
3c941dd… drh 147 { "mv-rm-files", CONFIGSET_PROJ },
4c4c28d… drh 148 { "forum-statuses", CONFIGSET_PROJ },
8cfe7b2… drh 149 { "path-to-tag", CONFIGSET_PROJ },
bf75ea9… drh 150 { "ticket-table", CONFIGSET_TKT },
bf75ea9… drh 151 { "ticket-common", CONFIGSET_TKT },
a905596… drh 152 { "ticket-change", CONFIGSET_TKT },
bf75ea9… drh 153 { "ticket-newpage", CONFIGSET_TKT },
bf75ea9… drh 154 { "ticket-viewpage", CONFIGSET_TKT },
bf75ea9… drh 155 { "ticket-editpage", CONFIGSET_TKT },
023c9fe… jeremy_c 156 { "ticket-reportlist", CONFIGSET_TKT },
bf75ea9… drh 157 { "ticket-report-template", CONFIGSET_TKT },
bf75ea9… drh 158 { "ticket-key-template", CONFIGSET_TKT },
ac3f1f2… drh 159 { "ticket-title-expr", CONFIGSET_TKT },
ac3f1f2… drh 160 { "ticket-closed-expr", CONFIGSET_TKT },
bf75ea9… drh 161 { "@reportfmt", CONFIGSET_TKT },
6239845… drh 162
bf75ea9… drh 163 { "@user", CONFIGSET_USER },
da0d7f7… drh 164 { "user-color-map", CONFIGSET_USER },
6239845… drh 165
6b0b57a… drh 166 { "@concealed", CONFIGSET_ADDR },
6239845… drh 167
bf75ea9… drh 168 { "@shun", CONFIGSET_SHUN },
3d36a37… drh 169
3d36a37… drh 170 { "@alias", CONFIGSET_ALIAS },
22c3354… drh 171
7f0c7fc… drh 172 { "@subscriber", CONFIGSET_SCRIBER },
f4dc114… drh 173
f4dc114… drh 174 { "@interwiki", CONFIGSET_IWIKI },
1311841… jan.nijtmans 175
0b61e3c… drh 176 { "xfer-common-script", CONFIGSET_XFER },
0b61e3c… drh 177 { "xfer-push-script", CONFIGSET_XFER },
1311841… jan.nijtmans 178 { "xfer-commit-script", CONFIGSET_XFER },
1311841… jan.nijtmans 179 { "xfer-ticket-script", CONFIGSET_XFER },
6239845… drh 180
e06ae9f… drh 181 };
28e5628… drh 182 static int iConfig = 0;
28e5628… drh 183
28e5628… drh 184 /*
28e5628… drh 185 ** Return name of first configuration property matching the given mask.
28e5628… drh 186 */
28e5628… drh 187 const char *configure_first_name(int iMask){
28e5628… drh 188 iConfig = 0;
28e5628… drh 189 return configure_next_name(iMask);
28e5628… drh 190 }
28e5628… drh 191 const char *configure_next_name(int iMask){
2ed7c11… drh 192 if( iConfig==0 && (iMask & CONFIGSET_ALL)==CONFIGSET_ALL ){
2ed7c11… drh 193 iConfig = count(aGroupName);
2ed7c11… drh 194 return "/all";
2ed7c11… drh 195 }
2ed7c11… drh 196 while( iConfig<count(aGroupName)-1 ){
2ed7c11… drh 197 if( aGroupName[iConfig].groupMask & iMask ){
2ed7c11… drh 198 return aGroupName[iConfig++].zName;
2ed7c11… drh 199 }else{
2ed7c11… drh 200 iConfig++;
28e5628… drh 201 }
28e5628… drh 202 }
28e5628… drh 203 return 0;
b344d3c… drh 204 }
b344d3c… drh 205
b344d3c… drh 206 /*
75bcb48… mistachkin 207 ** Return a pointer to a string that contains the RHS of an IN operator
75bcb48… mistachkin 208 ** that will select CONFIG table names that are part of the configuration
db0c512… drh 209 ** that matches iMatch.
75bcb48… mistachkin 210 */
75bcb48… mistachkin 211 const char *configure_inop_rhs(int iMask){
75bcb48… mistachkin 212 Blob x;
75bcb48… mistachkin 213 int i;
75bcb48… mistachkin 214 const char *zSep = "";
75bcb48… mistachkin 215
75bcb48… mistachkin 216 blob_zero(&x);
49b0ff1… drh 217 blob_append_sql(&x, "(");
75bcb48… mistachkin 218 for(i=0; i<count(aConfig); i++){
75bcb48… mistachkin 219 if( (aConfig[i].groupMask & iMask)==0 ) continue;
75bcb48… mistachkin 220 if( aConfig[i].zName[0]=='@' ) continue;
49b0ff1… drh 221 blob_append_sql(&x, "%s'%q'", zSep/*safe-for-%s*/, aConfig[i].zName);
75bcb48… mistachkin 222 zSep = ",";
75bcb48… mistachkin 223 }
49b0ff1… drh 224 blob_append_sql(&x, ")");
49b0ff1… drh 225 return blob_sql_text(&x);
75bcb48… mistachkin 226 }
75bcb48… mistachkin 227
75bcb48… mistachkin 228 /*
bf75ea9… drh 229 ** Return the mask for the named configuration parameter if it can be
bf75ea9… drh 230 ** safely exported. Return 0 if the parameter is not safe to export.
71fc181… drh 231 **
22c3354… drh 232 ** "Safe" in the previous paragraph means the permission is granted to
71fc181… drh 233 ** export the property. In other words, the requesting side has presented
71fc181… drh 234 ** login credentials and has sufficient capabilities to access the requested
71fc181… drh 235 ** information.
2ff87d4… stephan 236 **
2ff87d4… stephan 237 ** Settings which are specifically flagged as sensitive will (as of
2ff87d4… stephan 238 ** 2024-10-15) cause this function to return 0, regardless of user
2ff87d4… stephan 239 ** permissions. As an example, if the th1-setup setting were not
2ff87d4… stephan 240 ** sensitive then a malicious repo admin could set that to include
2ff87d4… stephan 241 ** arbitrary TCL code and affect users who configure fossil with the
2ff87d4… stephan 242 ** --with-tcl flag.
e06ae9f… drh 243 */
e06ae9f… drh 244 int configure_is_exportable(const char *zName){
e06ae9f… drh 245 int i;
1654456… drh 246 int n = strlen(zName);
2ff87d4… stephan 247 Setting *pSet;
1654456… drh 248 if( n>2 && zName[0]=='\'' && zName[n-1]=='\'' ){
2ff87d4… stephan 249 char * zCpy;
1654456… drh 250 zName++;
1654456… drh 251 n -= 2;
2ff87d4… stephan 252 zCpy = fossil_strndup(zName, (ssize_t)n);
2ff87d4… stephan 253 pSet = db_find_setting(zCpy, 0);
2ff87d4… stephan 254 fossil_free(zCpy);
2ff87d4… stephan 255 }else{
2ff87d4… stephan 256 pSet = db_find_setting(zName, 0);
2ff87d4… stephan 257 }
2ff87d4… stephan 258 if( pSet && pSet->sensitive ){
2ff87d4… stephan 259 /* https://fossil-scm.org/forum/forumpost/6179500deadf6ec7 */
2ff87d4… stephan 260 return 0;
1654456… drh 261 }
28e5628… drh 262 for(i=0; i<count(aConfig); i++){
52cb240… drh 263 if( strncmp(zName, aConfig[i].zName, n)==0 && aConfig[i].zName[n]==0 ){
bf75ea9… drh 264 int m = aConfig[i].groupMask;
b344d3c… drh 265 if( !g.perm.Admin ){
7f0c7fc… drh 266 m &= ~(CONFIGSET_USER|CONFIGSET_SCRIBER);
6b0b57a… drh 267 }
b344d3c… drh 268 if( !g.perm.RdAddr ){
6b0b57a… drh 269 m &= ~CONFIGSET_ADDR;
bf75ea9… drh 270 }
bf75ea9… drh 271 return m;
28e5628… drh 272 }
6b0b57a… drh 273 }
b2b4af1… drh 274 if( strncmp(zName, "walias:/", 8)==0 ){
b2b4af1… drh 275 return CONFIGSET_ALIAS;
f4dc114… drh 276 }
f4dc114… drh 277 if( strncmp(zName, "interwiki:", 10)==0 ){
f4dc114… drh 278 return CONFIGSET_IWIKI;
4c666cc… drh 279 }
e06ae9f… drh 280 return 0;
bf75ea9… drh 281 }
bf75ea9… drh 282
bf75ea9… drh 283 /*
4c666cc… drh 284 ** A mask of all configuration tables that have been reset already.
1654456… drh 285 */
1654456… drh 286 static int configHasBeenReset = 0;
0047370… joel 287
0047370… joel 288 /*
0047370… joel 289 ** Mask of modified configuration sets
0047370… joel 290 */
0047370… joel 291 static int rebuildMask = 0;
0047370… joel 292
0047370… joel 293 /*
0047370… joel 294 ** Rebuild auxiliary tables as required by configuration changes.
0047370… joel 295 */
0047370… joel 296 void configure_rebuild(void){
0047370… joel 297 if( rebuildMask & CONFIGSET_TKT ){
0047370… joel 298 ticket_rebuild();
0047370… joel 299 }
0047370… joel 300 rebuildMask = 0;
1654456… drh 301 }
1654456… drh 302
1654456… drh 303 /*
1654456… drh 304 ** Return true if z[] is not a "safe" SQL token. A safe token is one of:
1654456… drh 305 **
1654456… drh 306 ** * A string literal
1654456… drh 307 ** * A blob literal
1654456… drh 308 ** * An integer literal (no floating point)
1654456… drh 309 ** * NULL
1654456… drh 310 */
1654456… drh 311 static int safeSql(const char *z){
1654456… drh 312 int i;
1654456… drh 313 if( z==0 || z[0]==0 ) return 0;
1654456… drh 314 if( (z[0]=='x' || z[0]=='X') && z[1]=='\'' ) z++;
1654456… drh 315 if( z[0]=='\'' ){
1654456… drh 316 for(i=1; z[i]; i++){
1654456… drh 317 if( z[i]=='\'' ){
1654456… drh 318 i++;
1654456… drh 319 if( z[i]=='\'' ){ continue; }
1654456… drh 320 return z[i]==0;
1654456… drh 321 }
1654456… drh 322 }
1654456… drh 323 return 0;
1654456… drh 324 }else{
1654456… drh 325 char c;
1654456… drh 326 for(i=0; (c = z[i])!=0; i++){
1654456… drh 327 if( !fossil_isalnum(c) ) return 0;
1654456… drh 328 }
1654456… drh 329 }
1654456… drh 330 return 1;
1654456… drh 331 }
1654456… drh 332
1654456… drh 333 /*
1654456… drh 334 ** Return true if z[] consists of nothing but digits
1654456… drh 335 */
1654456… drh 336 static int safeInt(const char *z){
1654456… drh 337 int i;
1654456… drh 338 if( z==0 || z[0]==0 ) return 0;
1654456… drh 339 for(i=0; fossil_isdigit(z[i]); i++){}
1654456… drh 340 return z[i]==0;
b44d4a8… drh 341 }
b44d4a8… drh 342
b44d4a8… drh 343 /*
b44d4a8… drh 344 ** Process a single "config" card received from the other side of a
b44d4a8… drh 345 ** sync session.
b44d4a8… drh 346 **
b44d4a8… drh 347 ** Mask consists of one or more CONFIGSET_* values ORed together, to
b44d4a8… drh 348 ** designate what types of configuration we are allowed to receive.
71fc181… drh 349 **
71fc181… drh 350 ** NEW FORMAT:
71fc181… drh 351 **
22c3354… drh 352 ** zName is one of:
22c3354… drh 353 **
22c3354… drh 354 ** "/config", "/user", "/shun", "/reportfmt", "/concealed",
f5eb03f… drh 355 ** "/subscriber",
22c3354… drh 356 **
71fc181… drh 357 ** zName indicates the table that holds the configuration information being
71fc181… drh 358 ** transferred. pContent is a string that consist of alternating Fossil
71fc181… drh 359 ** and SQL tokens. The First token is a timestamp in seconds since 1970.
71fc181… drh 360 ** The second token is a primary key for the table identified by zName. If
71fc181… drh 361 ** The entry with the corresponding primary key exists and has a more recent
71fc181… drh 362 ** mtime, then nothing happens. If the entry does not exist or if it has
dacc694… jan.nijtmans 363 ** an older mtime, then the content described by subsequent token pairs is
71fc181… drh 364 ** inserted. The first element of each token pair is a column name and
71fc181… drh 365 ** the second is its value.
71fc181… drh 366 **
71fc181… drh 367 ** In overview, we have:
71fc181… drh 368 **
71fc181… drh 369 ** NAME CONTENT
71fc181… drh 370 ** ------- -----------------------------------------------------------
71fc181… drh 371 ** /config $MTIME $NAME value $VALUE
71fc181… drh 372 ** /user $MTIME $LOGIN pw $VALUE cap $VALUE info $VALUE photo $VALUE
71fc181… drh 373 ** /shun $MTIME $UUID scom $VALUE
fcf17b2… drh 374 ** /reportfmt $MTIME $TITLE owner $VALUE cols $VALUE sqlcode $VALUE jx $JSON
71fc181… drh 375 ** /concealed $MTIME $HASH content $VALUE
7e87699… drh 376 ** /subscriber $SMTIME $SEMAIL suname $V ...
15b0110… stephan 377 **
15b0110… stephan 378 ** NAME-specific notes:
15b0110… stephan 379 **
15b0110… stephan 380 ** - /reportftm's $MTIME is in Julian, not the Unix epoch.
1654456… drh 381 */
1654456… drh 382 void configure_receive(const char *zName, Blob *pContent, int groupMask){
e2bdc10… danield 383 int checkMask; /* Masks for which we must first check existence of tables */
22c3354… drh 384
7f0c7fc… drh 385 checkMask = CONFIGSET_SCRIBER;
1654456… drh 386 if( zName[0]=='/' ){
1654456… drh 387 /* The new format */
9040de4… drh 388 char *azToken[24];
1654456… drh 389 int nToken = 0;
1654456… drh 390 int ii, jj;
1654456… drh 391 int thisMask;
1654456… drh 392 Blob name, value, sql;
1654456… drh 393 static const struct receiveType {
22c3354… drh 394 const char *zName; /* Configuration key for this table */
22c3354… drh 395 const char *zPrimKey; /* Primary key column */
22c3354… drh 396 int nField; /* Number of data fields */
9040de4… drh 397 const char *azField[6]; /* Names of the data fields */
1654456… drh 398 } aType[] = {
fcf17b2… drh 399 { "/config", "name", 1, { "value", 0,0,0,0,0 } },
fcf17b2… drh 400 { "@user", "login", 5, { "pw","cap","info","photo","jx",0} },
fcf17b2… drh 401 { "@shun", "uuid", 1, { "scom", 0,0,0,0,0} },
fcf17b2… drh 402 { "@reportfmt", "title", 4, { "owner","cols","sqlcode","jx",0,0}},
fcf17b2… drh 403 { "@concealed", "hash", 1, { "content", 0,0,0,0,0 } },
9040de4… drh 404 { "@subscriber","semail",6,
fcf17b2… drh 405 { "suname","sdigest","sdonotcall","ssub","sctime","smip"} },
1654456… drh 406 };
9040de4… drh 407
9040de4… drh 408 /* Locate the receiveType in aType[ii] */
1654456… drh 409 for(ii=0; ii<count(aType); ii++){
1654456… drh 410 if( fossil_strcmp(&aType[ii].zName[1],&zName[1])==0 ) break;
1654456… drh 411 }
1654456… drh 412 if( ii>=count(aType) ) return;
9040de4… drh 413
1654456… drh 414 while( blob_token(pContent, &name) && blob_sqltoken(pContent, &value) ){
1654456… drh 415 char *z = blob_terminate(&name);
1654456… drh 416 if( !safeSql(z) ) return;
1654456… drh 417 if( nToken>0 ){
1654456… drh 418 for(jj=0; jj<aType[ii].nField; jj++){
1654456… drh 419 if( fossil_strcmp(aType[ii].azField[jj], z)==0 ) break;
1654456… drh 420 }
1654456… drh 421 if( jj>=aType[ii].nField ) continue;
1654456… drh 422 }else{
1654456… drh 423 if( !safeInt(z) ) return;
1654456… drh 424 }
1654456… drh 425 azToken[nToken++] = z;
1654456… drh 426 azToken[nToken++] = z = blob_terminate(&value);
1654456… drh 427 if( !safeSql(z) ) return;
9040de4… drh 428 if( nToken>=count(azToken)-1 ) break;
1654456… drh 429 }
1654456… drh 430 if( nToken<2 ) return;
1654456… drh 431 if( aType[ii].zName[0]=='/' ){
1654456… drh 432 thisMask = configure_is_exportable(azToken[1]);
2ff87d4… stephan 433 if( 0==thisMask ){
2ff87d4… stephan 434 fossil_warning("Skipping non-exportable setting: %s = %s",
2ff87d4… stephan 435 azToken[1], nToken>3 ? azToken[3] : "?");
2ff87d4… stephan 436 /* Will be skipped below */
2ff87d4… stephan 437 }
1654456… drh 438 }else{
1654456… drh 439 thisMask = configure_is_exportable(aType[ii].zName);
1654456… drh 440 }
1654456… drh 441 if( (thisMask & groupMask)==0 ) return;
22c3354… drh 442 if( (thisMask & checkMask)!=0 ){
7f0c7fc… drh 443 if( (thisMask & CONFIGSET_SCRIBER)!=0 ){
fc5c7d2… drh 444 alert_schema(1);
22c3354… drh 445 }
22c3354… drh 446 checkMask &= ~thisMask;
22c3354… drh 447 }
dacc694… jan.nijtmans 448
1654456… drh 449 blob_zero(&sql);
1654456… drh 450 if( groupMask & CONFIGSET_OVERWRITE ){
1654456… drh 451 if( (thisMask & configHasBeenReset)==0 && aType[ii].zName[0]!='/' ){
49b0ff1… drh 452 db_multi_exec("DELETE FROM \"%w\"", &aType[ii].zName[1]);
1654456… drh 453 configHasBeenReset |= thisMask;
1654456… drh 454 }
49b0ff1… drh 455 blob_append_sql(&sql, "REPLACE INTO ");
49b0ff1… drh 456 }else{
49b0ff1… drh 457 blob_append_sql(&sql, "INSERT OR IGNORE INTO ");
49b0ff1… drh 458 }
9040de4… drh 459 blob_append_sql(&sql, "\"%w\"(\"%w\",mtime",
9040de4… drh 460 &zName[1], aType[ii].zPrimKey);
140ed0f… drh 461 if( fossil_stricmp(zName,"/subscriber")==0 ) alert_schema(0);
49b0ff1… drh 462 for(jj=2; jj<nToken; jj+=2){
49b0ff1… drh 463 blob_append_sql(&sql, ",\"%w\"", azToken[jj]);
49b0ff1… drh 464 }
0b6d3ea… drh 465 blob_append_sql(&sql,") VALUES(%s,%s",
0b6d3ea… drh 466 azToken[1] /*safe-for-%s*/, azToken[0]/*safe-for-%s*/);
49b0ff1… drh 467 for(jj=2; jj<nToken; jj+=2){
49b0ff1… drh 468 blob_append_sql(&sql, ",%s", azToken[jj+1] /*safe-for-%s*/);
49b0ff1… drh 469 }
f741baa… drh 470 db_protect_only(PROTECT_SENSITIVE);
fcf17b2… drh 471
fcf17b2… drh 472 /* Make sure tables have the "jx" column */
fcf17b2… drh 473 if( strcmp(&zName[1],"user")==0 ){
fcf17b2… drh 474 user_update_user_table();
fcf17b2… drh 475 }else if( strcmp(&zName[1],"reportfmt")==0 ){
fcf17b2… drh 476 report_update_reportfmt_table();
fcf17b2… drh 477 }
fcf17b2… drh 478
49b0ff1… drh 479 db_multi_exec("%s)", blob_sql_text(&sql));
fcf17b2… drh 480
1654456… drh 481 if( db_changes()==0 ){
1654456… drh 482 blob_reset(&sql);
9040de4… drh 483 blob_append_sql(&sql, "UPDATE \"%w\" SET mtime=%s",
9040de4… drh 484 &zName[1], azToken[0]/*safe-for-%s*/);
49b0ff1… drh 485 for(jj=2; jj<nToken; jj+=2){
49b0ff1… drh 486 blob_append_sql(&sql, ", \"%w\"=%s",
49b0ff1… drh 487 azToken[jj], azToken[jj+1]/*safe-for-%s*/);
49b0ff1… drh 488 }
9040de4… drh 489 blob_append_sql(&sql, " WHERE \"%w\"=%s AND mtime<%s",
49b0ff1… drh 490 aType[ii].zPrimKey, azToken[1]/*safe-for-%s*/,
9040de4… drh 491 azToken[0]/*safe-for-%s*/);
49b0ff1… drh 492 db_multi_exec("%s", blob_sql_text(&sql));
49b0ff1… drh 493 }
f741baa… drh 494 db_protect_pop();
1654456… drh 495 blob_reset(&sql);
0047370… joel 496 rebuildMask |= thisMask;
1654456… drh 497 }
1654456… drh 498 }
1654456… drh 499
1654456… drh 500 /*
1654456… drh 501 ** Process a file full of "config" cards.
1654456… drh 502 */
1654456… drh 503 void configure_receive_all(Blob *pIn, int groupMask){
1654456… drh 504 Blob line;
1654456… drh 505 int nToken;
1654456… drh 506 int size;
1654456… drh 507 Blob aToken[4];
1654456… drh 508
1654456… drh 509 configHasBeenReset = 0;
1654456… drh 510 while( blob_line(pIn, &line) ){
1654456… drh 511 if( blob_buffer(&line)[0]=='#' ) continue;
1654456… drh 512 nToken = blob_tokenize(&line, aToken, count(aToken));
1654456… drh 513 if( blob_eq(&aToken[0],"config")
1654456… drh 514 && nToken==3
1654456… drh 515 && blob_is_int(&aToken[2], &size)
1654456… drh 516 ){
1654456… drh 517 const char *zName = blob_str(&aToken[1]);
1654456… drh 518 Blob content;
1654456… drh 519 blob_zero(&content);
1654456… drh 520 blob_extract(pIn, size, &content);
b344d3c… drh 521 g.perm.Admin = g.perm.RdAddr = 1;
1654456… drh 522 configure_receive(zName, &content, groupMask);
1654456… drh 523 blob_reset(&content);
1654456… drh 524 blob_seek(pIn, 1, BLOB_SEEK_CUR);
1654456… drh 525 }
b44d4a8… drh 526 }
b44d4a8… drh 527 }
dacc694… jan.nijtmans 528
b44d4a8… drh 529
b44d4a8… drh 530 /*
1654456… drh 531 ** Send "config" cards using the new format for all elements of a group
1654456… drh 532 ** that have recently changed.
1654456… drh 533 **
1654456… drh 534 ** Output goes into pOut. The groupMask identifies the group(s) to be sent.
1654456… drh 535 ** Send only entries whose timestamp is later than or equal to iStart.
1654456… drh 536 **
1654456… drh 537 ** Return the number of cards sent.
bf75ea9… drh 538 */
1654456… drh 539 int configure_send_group(
1654456… drh 540 Blob *pOut, /* Write output here */
1654456… drh 541 int groupMask, /* Mask of groups to be send */
1654456… drh 542 sqlite3_int64 iStart /* Only write values changed since this time */
1654456… drh 543 ){
1654456… drh 544 Stmt q;
1654456… drh 545 Blob rec;
1654456… drh 546 int ii;
1654456… drh 547 int nCard = 0;
1654456… drh 548
1654456… drh 549 blob_zero(&rec);
1654456… drh 550 if( groupMask & CONFIGSET_SHUN ){
1654456… drh 551 db_prepare(&q, "SELECT mtime, quote(uuid), quote(scom) FROM shun"
1654456… drh 552 " WHERE mtime>=%lld", iStart);
1654456… drh 553 while( db_step(&q)==SQLITE_ROW ){
1654456… drh 554 blob_appendf(&rec,"%s %s scom %s",
1654456… drh 555 db_column_text(&q, 0),
1654456… drh 556 db_column_text(&q, 1),
1654456… drh 557 db_column_text(&q, 2)
1654456… drh 558 );
1654456… drh 559 blob_appendf(pOut, "config /shun %d\n%s\n",
1654456… drh 560 blob_size(&rec), blob_str(&rec));
1654456… drh 561 nCard++;
1654456… drh 562 blob_reset(&rec);
1654456… drh 563 }
1654456… drh 564 db_finalize(&q);
1654456… drh 565 }
1654456… drh 566 if( groupMask & CONFIGSET_USER ){
fcf17b2… drh 567 if( db_table_has_column("repository","user","jx") ){
fcf17b2… drh 568 db_prepare(&q, "SELECT mtime, quote(login), quote(pw), quote(cap),"
fcf17b2… drh 569 " quote(info), quote(photo), quote(jx) FROM user"
fcf17b2… drh 570 " WHERE mtime>=%lld", iStart);
fcf17b2… drh 571 }else{
fcf17b2… drh 572 db_prepare(&q, "SELECT mtime, quote(login), quote(pw), quote(cap),"
fcf17b2… drh 573 " quote(info), quote(photo), 'NULL' FROM user"
fcf17b2… drh 574 " WHERE mtime>=%lld", iStart);
fcf17b2… drh 575 }
1654456… drh 576 while( db_step(&q)==SQLITE_ROW ){
fcf17b2… drh 577 const char *z;
fcf17b2… drh 578 blob_appendf(&rec,"%s %s", db_column_text(&q,0), db_column_text(&q,1));
fcf17b2… drh 579 z = db_column_text(&q,2);
fcf17b2… drh 580 if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," pw %s", z);
fcf17b2… drh 581 z = db_column_text(&q,3);
fcf17b2… drh 582 if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," cap %s", z);
fcf17b2… drh 583 z = db_column_text(&q,4);
fcf17b2… drh 584 if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," info %s", z);
fcf17b2… drh 585 z = db_column_text(&q,5);
fcf17b2… drh 586 if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," photo %s", z);
fcf17b2… drh 587 z = db_column_text(&q,6);
fcf17b2… drh 588 if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," jx %s", z);
1654456… drh 589 blob_appendf(pOut, "config /user %d\n%s\n",
1654456… drh 590 blob_size(&rec), blob_str(&rec));
1654456… drh 591 nCard++;
1654456… drh 592 blob_reset(&rec);
1654456… drh 593 }
1654456… drh 594 db_finalize(&q);
1654456… drh 595 }
1654456… drh 596 if( groupMask & CONFIGSET_TKT ){
fcf17b2… drh 597 if( db_table_has_column("repository","reportfmt","jx") ){
fcf17b2… drh 598 db_prepare(&q, "SELECT mtime, quote(title), quote(owner), quote(cols),"
fcf17b2… drh 599 " quote(sqlcode), quote(jx) FROM reportfmt"
fcf17b2… drh 600 " WHERE mtime>=%lld", iStart);
fcf17b2… drh 601 }else{
fcf17b2… drh 602 db_prepare(&q, "SELECT mtime, quote(title), quote(owner), quote(cols),"
fcf17b2… drh 603 " quote(sqlcode), 'NULL' FROM reportfmt"
fcf17b2… drh 604 " WHERE mtime>=%lld", iStart);
fcf17b2… drh 605 }
1654456… drh 606 while( db_step(&q)==SQLITE_ROW ){
fcf17b2… drh 607 const char *z;
fcf17b2… drh 608 blob_appendf(&rec,"%s %s", db_column_text(&q,0), db_column_text(&q,1));
fcf17b2… drh 609 z = db_column_text(&q,2);
fcf17b2… drh 610 if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," owner %s", z);
fcf17b2… drh 611 z = db_column_text(&q,3);
fcf17b2… drh 612 if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," cols %s", z);
fcf17b2… drh 613 z = db_column_text(&q,4);
fcf17b2… drh 614 if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," sqlcode %s", z);
fcf17b2… drh 615 z = db_column_text(&q,5);
fcf17b2… drh 616 if( strcmp(z,"NULL")!=0 ) blob_appendf(&rec," jx %s", z);
1654456… drh 617 blob_appendf(pOut, "config /reportfmt %d\n%s\n",
1654456… drh 618 blob_size(&rec), blob_str(&rec));
1654456… drh 619 nCard++;
1654456… drh 620 blob_reset(&rec);
1654456… drh 621 }
1654456… drh 622 db_finalize(&q);
1654456… drh 623 }
1654456… drh 624 if( groupMask & CONFIGSET_ADDR ){
1654456… drh 625 db_prepare(&q, "SELECT mtime, quote(hash), quote(content) FROM concealed"
1654456… drh 626 " WHERE mtime>=%lld", iStart);
1654456… drh 627 while( db_step(&q)==SQLITE_ROW ){
1654456… drh 628 blob_appendf(&rec,"%s %s content %s",
1654456… drh 629 db_column_text(&q, 0),
1654456… drh 630 db_column_text(&q, 1),
1654456… drh 631 db_column_text(&q, 2)
1654456… drh 632 );
1654456… drh 633 blob_appendf(pOut, "config /concealed %d\n%s\n",
1654456… drh 634 blob_size(&rec), blob_str(&rec));
1654456… drh 635 nCard++;
1654456… drh 636 blob_reset(&rec);
1654456… drh 637 }
1654456… drh 638 db_finalize(&q);
1654456… drh 639 }
3d36a37… drh 640 if( groupMask & CONFIGSET_ALIAS ){
3d36a37… drh 641 db_prepare(&q, "SELECT mtime, quote(name), quote(value) FROM config"
3d36a37… drh 642 " WHERE name GLOB 'walias:/*' AND mtime>=%lld", iStart);
f4dc114… drh 643 while( db_step(&q)==SQLITE_ROW ){
f4dc114… drh 644 blob_appendf(&rec,"%s %s value %s",
f4dc114… drh 645 db_column_text(&q, 0),
f4dc114… drh 646 db_column_text(&q, 1),
f4dc114… drh 647 db_column_text(&q, 2)
f4dc114… drh 648 );
f4dc114… drh 649 blob_appendf(pOut, "config /config %d\n%s\n",
f4dc114… drh 650 blob_size(&rec), blob_str(&rec));
f4dc114… drh 651 nCard++;
f4dc114… drh 652 blob_reset(&rec);
f4dc114… drh 653 }
f4dc114… drh 654 db_finalize(&q);
f4dc114… drh 655 }
f4dc114… drh 656 if( groupMask & CONFIGSET_IWIKI ){
f4dc114… drh 657 db_prepare(&q, "SELECT mtime, quote(name), quote(value) FROM config"
f4dc114… drh 658 " WHERE name GLOB 'interwiki:*' AND mtime>=%lld", iStart);
7f0c7fc… drh 659 while( db_step(&q)==SQLITE_ROW ){
7f0c7fc… drh 660 blob_appendf(&rec,"%s %s value %s",
7f0c7fc… drh 661 db_column_text(&q, 0),
7f0c7fc… drh 662 db_column_text(&q, 1),
7f0c7fc… drh 663 db_column_text(&q, 2)
7f0c7fc… drh 664 );
7f0c7fc… drh 665 blob_appendf(pOut, "config /config %d\n%s\n",
7f0c7fc… drh 666 blob_size(&rec), blob_str(&rec));
7f0c7fc… drh 667 nCard++;
7f0c7fc… drh 668 blob_reset(&rec);
7f0c7fc… drh 669 }
7f0c7fc… drh 670 db_finalize(&q);
7f0c7fc… drh 671 }
7f0c7fc… drh 672 if( (groupMask & CONFIGSET_SCRIBER)!=0
22c3354… drh 673 && db_table_exists("repository","subscriber")
22c3354… drh 674 ){
9040de4… drh 675 db_prepare(&q, "SELECT mtime, quote(semail),"
9040de4… drh 676 " quote(suname), quote(sdigest),"
9040de4… drh 677 " quote(sdonotcall), quote(ssub),"
4e699c2… drh 678 " quote(sctime), quote(smip)"
22c3354… drh 679 " FROM subscriber WHERE sverified"
9040de4… drh 680 " AND mtime>=%lld", iStart);
22c3354… drh 681 while( db_step(&q)==SQLITE_ROW ){
7e87699… drh 682 blob_appendf(&rec,
9040de4… drh 683 "%lld %s suname %s sdigest %s sdonotcall %s ssub %s"
9040de4… drh 684 " sctime %s smip %s",
9040de4… drh 685 db_column_int64(&q, 0), /* mtime */
22c3354… drh 686 db_column_text(&q, 1), /* semail (PK) */
22c3354… drh 687 db_column_text(&q, 2), /* suname */
22c3354… drh 688 db_column_text(&q, 3), /* sdigest */
22c3354… drh 689 db_column_text(&q, 4), /* sdonotcall */
7e87699… drh 690 db_column_text(&q, 5), /* ssub */
9040de4… drh 691 db_column_text(&q, 6), /* sctime */
9040de4… drh 692 db_column_text(&q, 7) /* smip */
22c3354… drh 693 );
22c3354… drh 694 blob_appendf(pOut, "config /subscriber %d\n%s\n",
22c3354… drh 695 blob_size(&rec), blob_str(&rec));
22c3354… drh 696 nCard++;
22c3354… drh 697 blob_reset(&rec);
22c3354… drh 698 }
22c3354… drh 699 db_finalize(&q);
22c3354… drh 700 }
1654456… drh 701 db_prepare(&q, "SELECT mtime, quote(name), quote(value) FROM config"
1654456… drh 702 " WHERE name=:name AND mtime>=%lld", iStart);
1654456… drh 703 for(ii=0; ii<count(aConfig); ii++){
1654456… drh 704 if( (aConfig[ii].groupMask & groupMask)!=0 && aConfig[ii].zName[0]!='@' ){
2ff87d4… stephan 705 const Setting * pSet = db_find_setting(aConfig[ii].zName, 0);
2ff87d4… stephan 706 if( pSet && pSet->sensitive ){
2ff87d4… stephan 707 /* https://fossil-scm.org/forum/forumpost/6179500deadf6ec7 */
2ff87d4… stephan 708 continue;
2ff87d4… stephan 709 }
1654456… drh 710 db_bind_text(&q, ":name", aConfig[ii].zName);
1654456… drh 711 while( db_step(&q)==SQLITE_ROW ){
1654456… drh 712 blob_appendf(&rec,"%s %s value %s",
1654456… drh 713 db_column_text(&q, 0),
1654456… drh 714 db_column_text(&q, 1),
1654456… drh 715 db_column_text(&q, 2)
1654456… drh 716 );
1654456… drh 717 blob_appendf(pOut, "config /config %d\n%s\n",
1654456… drh 718 blob_size(&rec), blob_str(&rec));
1654456… drh 719 nCard++;
1654456… drh 720 blob_reset(&rec);
1654456… drh 721 }
1654456… drh 722 db_reset(&q);
1654456… drh 723 }
1654456… drh 724 }
1654456… drh 725 db_finalize(&q);
1654456… drh 726 return nCard;
e06ae9f… drh 727 }
e06ae9f… drh 728
e06ae9f… drh 729 /*
e06ae9f… drh 730 ** Identify a configuration group by name. Return its mask.
e06ae9f… drh 731 ** Throw an error if no match.
e06ae9f… drh 732 */
1654456… drh 733 int configure_name_to_mask(const char *z, int notFoundIsFatal){
e06ae9f… drh 734 int i;
e06ae9f… drh 735 int n = strlen(z);
e06ae9f… drh 736 for(i=0; i<count(aGroupName); i++){
1654456… drh 737 if( strncmp(z, &aGroupName[i].zName[1], n)==0 ){
e06ae9f… drh 738 return aGroupName[i].groupMask;
e06ae9f… drh 739 }
e06ae9f… drh 740 }
1654456… drh 741 if( notFoundIsFatal ){
d8ec765… drh 742 fossil_print("Available configuration areas:\n");
1654456… drh 743 for(i=0; i<count(aGroupName); i++){
f5eb03f… drh 744 fossil_print(" %-13s %s\n",
f5eb03f… drh 745 &aGroupName[i].zName[1], aGroupName[i].zHelp);
1654456… drh 746 }
1654456… drh 747 fossil_fatal("no such configuration area: \"%s\"", z);
bf75ea9… drh 748 }
e06ae9f… drh 749 return 0;
bf75ea9… drh 750 }
bf75ea9… drh 751
bf75ea9… drh 752 /*
bf75ea9… drh 753 ** Write SQL text into file zFilename that will restore the configuration
bf75ea9… drh 754 ** area identified by mask to its current state from any other state.
bf75ea9… drh 755 */
bf75ea9… drh 756 static void export_config(
1654456… drh 757 int groupMask, /* Mask indicating which configuration to export */
bf75ea9… drh 758 const char *zMask, /* Name of the configuration */
1654456… drh 759 sqlite3_int64 iStart, /* Start date */
bf75ea9… drh 760 const char *zFilename /* Write into this file */
bf75ea9… drh 761 ){
bf75ea9… drh 762 Blob out;
bf75ea9… drh 763 blob_zero(&out);
dacc694… jan.nijtmans 764 blob_appendf(&out,
1654456… drh 765 "# The \"%s\" configuration exported from\n"
1654456… drh 766 "# repository \"%s\"\n"
1654456… drh 767 "# on %s\n",
bf75ea9… drh 768 zMask, g.zRepositoryName,
bf75ea9… drh 769 db_text(0, "SELECT datetime('now')")
bf75ea9… drh 770 );
1654456… drh 771 configure_send_group(&out, groupMask, iStart);
bf75ea9… drh 772 blob_write_to_file(&out, zFilename);
bf75ea9… drh 773 blob_reset(&out);
28e5628… drh 774 }
28e5628… drh 775
e06ae9f… drh 776
e06ae9f… drh 777 /*
841772c… drh 778 ** COMMAND: configuration*
2210be1… drh 779 **
2210be1… drh 780 ** Usage: %fossil configuration METHOD ... ?OPTIONS?
2210be1… drh 781 **
6cb0fc2… wyoung 782 ** Where METHOD is one of: export import merge pull push reset.
db0c512… drh 783 **
e58c76a… drh 784 ** > fossil configuration export AREA FILENAME
db0c512… drh 785 **
db0c512… drh 786 ** Write to FILENAME exported configuration information for AREA.
62411f3… drh 787 ** AREA can be one of:
62411f3… drh 788 **
79b1cd4… drh 789 ** all email interwiki project shun skin
79b1cd4… drh 790 ** ticket user alias subscriber
db0c512… drh 791 **
e58c76a… drh 792 ** > fossil configuration import FILENAME
e06ae9f… drh 793 **
e06ae9f… drh 794 ** Read a configuration from FILENAME, overwriting the current
bf75ea9… drh 795 ** configuration.
bf75ea9… drh 796 **
e58c76a… drh 797 ** > fossil configuration merge FILENAME
bf75ea9… drh 798 **
bf75ea9… drh 799 ** Read a configuration from FILENAME and merge its values into
bf75ea9… drh 800 ** the current configuration. Existing values take priority over
bf75ea9… drh 801 ** values read from FILENAME.
e06ae9f… drh 802 **
e58c76a… drh 803 ** > fossil configuration pull AREA ?URL?
e06ae9f… drh 804 **
e06ae9f… drh 805 ** Pull and install the configuration from a different server
bf75ea9… drh 806 ** identified by URL. If no URL is specified, then the default
2ed7c11… drh 807 ** server is used. Use the --overwrite flag to completely
2ed7c11… drh 808 ** replace local settings with content received from URL.
6b0b57a… drh 809 **
e58c76a… drh 810 ** > fossil configuration push AREA ?URL?
6b0b57a… drh 811 **
6b0b57a… drh 812 ** Push the local configuration into the remote server identified
6b0b57a… drh 813 ** by URL. Admin privilege is required on the remote server for
1654456… drh 814 ** this to work. When the same record exists both locally and on
1654456… drh 815 ** the remote end, the one that was most recently changed wins.
e06ae9f… drh 816 **
e58c76a… drh 817 ** > fossil configuration reset AREA
e06ae9f… drh 818 **
e06ae9f… drh 819 ** Restore the configuration to the default. AREA as above.
bf75ea9… drh 820 **
e58c76a… drh 821 ** > fossil configuration sync AREA ?URL?
1654456… drh 822 **
1654456… drh 823 ** Synchronize configuration changes in the local repository with
dacc694… jan.nijtmans 824 ** the remote repository at URL.
2210be1… drh 825 **
2210be1… drh 826 ** Options:
6d4cd32… mgagnon 827 ** --proxy PROXY Use PROXY as http proxy during sync operation
6d4cd32… mgagnon 828 ** (used by pull, push and sync subcommands)
6cb0fc2… wyoung 829 ** -R|--repository REPO Affect repository REPO with changes
2210be1… drh 830 **
c965636… drh 831 ** See also: [[settings]], [[unset]]
e06ae9f… drh 832 */
28e5628… drh 833 void configuration_cmd(void){
e06ae9f… drh 834 int n;
e06ae9f… drh 835 const char *zMethod;
d3b14a8… drh 836 db_find_and_open_repository(0, 0);
b06cd63… mistachkin 837 db_open_config(0, 0);
e06ae9f… drh 838 if( g.argc<3 ){
d3b14a8… drh 839 usage("SUBCOMMAND ...");
e06ae9f… drh 840 }
e06ae9f… drh 841 zMethod = g.argv[2];
e06ae9f… drh 842 n = strlen(zMethod);
e06ae9f… drh 843 if( strncmp(zMethod, "export", n)==0 ){
e06ae9f… drh 844 int mask;
1654456… drh 845 const char *zSince = find_option("since",0,1);
1654456… drh 846 sqlite3_int64 iStart;
e06ae9f… drh 847 if( g.argc!=5 ){
e06ae9f… drh 848 usage("export AREA FILENAME");
e06ae9f… drh 849 }
1654456… drh 850 mask = configure_name_to_mask(g.argv[3], 1);
1654456… drh 851 if( zSince ){
1654456… drh 852 iStart = db_multi_exec(
1654456… drh 853 "SELECT coalesce(strftime('%%s',%Q),strftime('%%s','now',%Q))+0",
1654456… drh 854 zSince, zSince
1654456… drh 855 );
1654456… drh 856 }else{
1654456… drh 857 iStart = 0;
1654456… drh 858 }
1654456… drh 859 export_config(mask, g.argv[3], iStart, g.argv[4]);
28e5628… drh 860 }else
dacc694… jan.nijtmans 861 if( strncmp(zMethod, "import", n)==0
bf75ea9… drh 862 || strncmp(zMethod, "merge", n)==0 ){
28e5628… drh 863 Blob in;
1654456… drh 864 int groupMask;
bf75ea9… drh 865 if( g.argc!=4 ) usage(mprintf("%s FILENAME",zMethod));
1772357… drh 866 blob_read_from_file(&in, g.argv[3], ExtFILE);
e1962ef… drh 867 db_begin_transaction();
1654456… drh 868 if( zMethod[0]=='i' ){
1654456… drh 869 groupMask = CONFIGSET_ALL | CONFIGSET_OVERWRITE;
1654456… drh 870 }else{
1654456… drh 871 groupMask = CONFIGSET_ALL;
1654456… drh 872 }
db8c5a9… stephan 873 db_unprotect(PROTECT_USER);
1654456… drh 874 configure_receive_all(&in, groupMask);
8ad6aa5… stephan 875 db_protect_pop();
28e5628… drh 876 db_end_transaction(0);
28e5628… drh 877 }else
1654456… drh 878 if( strncmp(zMethod, "pull", n)==0
1654456… drh 879 || strncmp(zMethod, "push", n)==0
1654456… drh 880 || strncmp(zMethod, "sync", n)==0
1654456… drh 881 ){
28e5628… drh 882 int mask;
6d6740d… drh 883 const char *zServer = 0;
1654456… drh 884 int overwriteFlag = 0;
6d6740d… drh 885
1654456… drh 886 if( strncmp(zMethod,"pull",n)==0 ){
1654456… drh 887 overwriteFlag = find_option("overwrite",0,0)!=0;
1654456… drh 888 }
28e5628… drh 889 url_proxy_options();
bf75ea9… drh 890 if( g.argc!=4 && g.argc!=5 ){
69fe423… drh 891 usage(mprintf("%s AREA ?URL?", zMethod));
bf75ea9… drh 892 }
1654456… drh 893 mask = configure_name_to_mask(g.argv[3], 1);
bf75ea9… drh 894 if( g.argc==5 ){
bf75ea9… drh 895 zServer = g.argv[4];
6d6740d… drh 896 }
661ea33… drh 897 url_parse(zServer, URL_PROMPT_PW|URL_USE_CONFIG);
5fdad9b… drh 898 if( g.url.protocol==0 ) fossil_fatal("no server URL specified");
1a9fe88… drh 899 user_select();
1a9fe88… drh 900 url_enable_proxy("via proxy: ");
5a942d1… andybradford 901 g.zHttpAuth = get_httpauth();
1654456… drh 902 if( overwriteFlag ) mask |= CONFIGSET_OVERWRITE;
1a9fe88… drh 903 if( strncmp(zMethod, "push", n)==0 ){
0cd5589… drh 904 client_sync(0,0,(unsigned)mask,0,0);
1654456… drh 905 }else if( strncmp(zMethod, "pull", n)==0 ){
7384cf5… stephan 906 if( overwriteFlag ) db_unprotect(PROTECT_USER);
0cd5589… drh 907 client_sync(0,(unsigned)mask,0,0,0);
7384cf5… stephan 908 if( overwriteFlag ) db_protect_pop();
1a9fe88… drh 909 }else{
0cd5589… drh 910 client_sync(0,(unsigned)mask,(unsigned)mask,0,0);
6b0b57a… drh 911 }
e06ae9f… drh 912 }else
e06ae9f… drh 913 if( strncmp(zMethod, "reset", n)==0 ){
28e5628… drh 914 int mask, i;
bf75ea9… drh 915 char *zBackup;
28e5628… drh 916 if( g.argc!=4 ) usage("reset AREA");
1654456… drh 917 mask = configure_name_to_mask(g.argv[3], 1);
dacc694… jan.nijtmans 918 zBackup = db_text(0,
bf75ea9… drh 919 "SELECT strftime('config-backup-%%Y%%m%%d%%H%%M%%f','now')");
e1962ef… drh 920 db_begin_transaction();
1654456… drh 921 export_config(mask, g.argv[3], 0, zBackup);
28e5628… drh 922 for(i=0; i<count(aConfig); i++){
bf75ea9… drh 923 const char *zName = aConfig[i].zName;
28e5628… drh 924 if( (aConfig[i].groupMask & mask)==0 ) continue;
bf75ea9… drh 925 if( zName[0]!='@' ){
f741baa… drh 926 db_unprotect(PROTECT_CONFIG);
bf75ea9… drh 927 db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
f741baa… drh 928 db_protect_pop();
31c52c7… drh 929 }else if( fossil_strcmp(zName,"@user")==0 ){
f741baa… drh 930 db_unprotect(PROTECT_USER);
bf75ea9… drh 931 db_multi_exec("DELETE FROM user");
f741baa… drh 932 db_protect_pop();
14c19fb… drh 933 db_create_default_users(0, 0);
31c52c7… drh 934 }else if( fossil_strcmp(zName,"@concealed")==0 ){
6b0b57a… drh 935 db_multi_exec("DELETE FROM concealed");
31c52c7… drh 936 }else if( fossil_strcmp(zName,"@shun")==0 ){
6b0b57a… drh 937 db_multi_exec("DELETE FROM shun");
9040de4… drh 938 }else if( fossil_strcmp(zName,"@subscriber")==0 ){
22c3354… drh 939 if( db_table_exists("repository","subscriber") ){
22c3354… drh 940 db_multi_exec("DELETE FROM subscriber");
22c3354… drh 941 }
22c3354… drh 942 }else if( fossil_strcmp(zName,"@forum")==0 ){
22c3354… drh 943 if( db_table_exists("repository","forumpost") ){
22c3354… drh 944 db_multi_exec("DELETE FROM forumpost");
22c3354… drh 945 db_multi_exec("DELETE FROM forumthread");
22c3354… drh 946 }
31c52c7… drh 947 }else if( fossil_strcmp(zName,"@reportfmt")==0 ){
f2b6459… stephan 948 db_multi_exec("DELETE FROM reportfmt");
49b0ff1… drh 949 assert( strchr(zRepositorySchemaDefaultReports,'%')==0 );
49b0ff1… drh 950 db_multi_exec(zRepositorySchemaDefaultReports /*works-like:""*/);
bf75ea9… drh 951 }
28e5628… drh 952 }
28e5628… drh 953 db_end_transaction(0);
d8ec765… drh 954 fossil_print("Configuration reset to factory defaults.\n");
dacc694… jan.nijtmans 955 fossil_print("To recover, use: %s %s import %s\n",
dacc694… jan.nijtmans 956 g.argv[0], g.argv[1], zBackup);
0047370… joel 957 rebuildMask |= mask;
e06ae9f… drh 958 }else
e06ae9f… drh 959 {
6b0b57a… drh 960 fossil_fatal("METHOD should be one of:"
6b0b57a… drh 961 " export import merge pull push reset");
6b0b57a… drh 962 }
0047370… joel 963 configure_rebuild();
1e21dac… drh 964 }
1e21dac… drh 965
1e21dac… drh 966
1e21dac… drh 967 /*
1e21dac… drh 968 ** COMMAND: test-var-list
1e21dac… drh 969 **
1e21dac… drh 970 ** Usage: %fossil test-var-list ?PATTERN? ?--unset? ?--mtime?
1e21dac… drh 971 **
1e21dac… drh 972 ** Show the content of the CONFIG table in a repository. If PATTERN is
1e21dac… drh 973 ** specified, then only show the entries that match that glob pattern.
1e21dac… drh 974 ** Last modification time is shown if the --mtime option is present.
1e21dac… drh 975 **
1e21dac… drh 976 ** If the --unset option is included, then entries are deleted rather than
1e21dac… drh 977 ** being displayed. WARNING! This cannot be undone. Be sure you know what
1e21dac… drh 978 ** you are doing! The --unset option only works if there is a PATTERN.
1e21dac… drh 979 ** Probably you should run the command once without --unset to make sure
1e21dac… drh 980 ** you know exactly what is being deleted.
1e21dac… drh 981 **
1e21dac… drh 982 ** If not in an open check-out, use the -R REPO option to specify a
1e21dac… drh 983 ** a repository.
1e21dac… drh 984 */
1e21dac… drh 985 void test_var_list_cmd(void){
1e21dac… drh 986 Stmt q;
1e21dac… drh 987 int i, j;
1e21dac… drh 988 const char *zPattern = 0;
1e21dac… drh 989 int doUnset;
1e21dac… drh 990 int showMtime;
1e21dac… drh 991 Blob sql;
1e21dac… drh 992 Blob ans;
1e21dac… drh 993 unsigned char zTrans[1000];
1e21dac… drh 994
1e21dac… drh 995 doUnset = find_option("unset",0,0)!=0;
1e21dac… drh 996 showMtime = find_option("mtime",0,0)!=0;
1e21dac… drh 997 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
1e21dac… drh 998 verify_all_options();
1e21dac… drh 999 if( g.argc>=3 ){
1e21dac… drh 1000 zPattern = g.argv[2];
1e21dac… drh 1001 }
1e21dac… drh 1002 blob_init(&sql,0,0);
1e21dac… drh 1003 blob_appendf(&sql, "SELECT name, value, datetime(mtime,'unixepoch')"
1e21dac… drh 1004 " FROM config");
1e21dac… drh 1005 if( zPattern ){
1e21dac… drh 1006 blob_appendf(&sql, " WHERE name GLOB %Q", zPattern);
1e21dac… drh 1007 }
1e21dac… drh 1008 if( showMtime ){
1e21dac… drh 1009 blob_appendf(&sql, " ORDER BY mtime, name");
1e21dac… drh 1010 }else{
1e21dac… drh 1011 blob_appendf(&sql, " ORDER BY name");
1e21dac… drh 1012 }
1e21dac… drh 1013 db_prepare(&q, "%s", blob_str(&sql)/*safe-for-%s*/);
1e21dac… drh 1014 blob_reset(&sql);
1e21dac… drh 1015 #define MX_VAL 40
1e21dac… drh 1016 #define MX_NM 28
1e21dac… drh 1017 #define MX_LONGNM 60
1e21dac… drh 1018 while( db_step(&q)==SQLITE_ROW ){
1e21dac… drh 1019 const char *zName = db_column_text(&q,0);
1e21dac… drh 1020 int nName = db_column_bytes(&q,0);
1e21dac… drh 1021 const char *zValue = db_column_text(&q,1);
1e21dac… drh 1022 int szValue = db_column_bytes(&q,1);
1e21dac… drh 1023 const char *zMTime = db_column_text(&q,2);
1e21dac… drh 1024 for(i=j=0; j<MX_VAL && zValue[i]; i++){
1e21dac… drh 1025 unsigned char c = (unsigned char)zValue[i];
1e21dac… drh 1026 if( c>=' ' && c<='~' ){
1e21dac… drh 1027 zTrans[j++] = c;
1e21dac… drh 1028 }else{
1e21dac… drh 1029 zTrans[j++] = '\\';
1e21dac… drh 1030 if( c=='\n' ){
1e21dac… drh 1031 zTrans[j++] = 'n';
1e21dac… drh 1032 }else if( c=='\r' ){
1e21dac… drh 1033 zTrans[j++] = 'r';
1e21dac… drh 1034 }else if( c=='\t' ){
1e21dac… drh 1035 zTrans[j++] = 't';
5098f74… jan.nijtmans 1036 }else{
1e21dac… drh 1037 zTrans[j++] = '0' + ((c>>6)&7);
1e21dac… drh 1038 zTrans[j++] = '0' + ((c>>3)&7);
1e21dac… drh 1039 zTrans[j++] = '0' + (c&7);
1e21dac… drh 1040 }
1e21dac… drh 1041 }
1e21dac… drh 1042 }
1e21dac… drh 1043 zTrans[j] = 0;
1e21dac… drh 1044 if( i<szValue ){
1e21dac… drh 1045 sqlite3_snprintf(sizeof(zTrans)-j, (char*)zTrans+j, "...+%d", szValue-i);
1e21dac… drh 1046 j += (int)strlen((char*)zTrans+j);
1e21dac… drh 1047 }
1e21dac… drh 1048 if( showMtime ){
1e21dac… drh 1049 fossil_print("%s:%*s%s\n", zName, 58-nName, "", zMTime);
1e21dac… drh 1050 }else if( nName<MX_NM-2 ){
1e21dac… drh 1051 fossil_print("%s:%*s%s\n", zName, MX_NM-1-nName, "", zTrans);
1e21dac… drh 1052 }else if( nName<MX_LONGNM-2 && j<10 ){
1e21dac… drh 1053 fossil_print("%s:%*s%s\n", zName, MX_LONGNM-1-nName, "", zTrans);
1e21dac… drh 1054 }else{
1e21dac… drh 1055 fossil_print("%s:\n%*s%s\n", zName, MX_NM, "", zTrans);
1e21dac… drh 1056 }
1e21dac… drh 1057 }
1e21dac… drh 1058 db_finalize(&q);
1e21dac… drh 1059 if( zPattern && doUnset ){
1e21dac… drh 1060 prompt_user("Delete all of the above? (y/N)? ", &ans);
1e21dac… drh 1061 if( blob_str(&ans)[0]=='y' || blob_str(&ans)[0]=='Y' ){
1e21dac… drh 1062 db_multi_exec("DELETE FROM config WHERE name GLOB %Q", zPattern);
1e21dac… drh 1063 }
1e21dac… drh 1064 blob_reset(&ans);
1e21dac… drh 1065 }
1e21dac… drh 1066 }
1e21dac… drh 1067
1e21dac… drh 1068 /*
1e21dac… drh 1069 ** COMMAND: test-var-get
1e21dac… drh 1070 **
1e21dac… drh 1071 ** Usage: %fossil test-var-get VAR ?FILE?
1e21dac… drh 1072 **
5098f74… jan.nijtmans 1073 ** Write the text of the VAR variable into FILE. If FILE is "-"
1e21dac… drh 1074 ** or is omitted then output goes to standard output. VAR can be a
1e21dac… drh 1075 ** GLOB pattern.
1e21dac… drh 1076 **
1e21dac… drh 1077 ** If not in an open check-out, use the -R REPO option to specify a
1e21dac… drh 1078 ** a repository.
1e21dac… drh 1079 */
1e21dac… drh 1080 void test_var_get_cmd(void){
1e21dac… drh 1081 const char *zVar;
1e21dac… drh 1082 const char *zFile;
1e21dac… drh 1083 int n;
1e21dac… drh 1084 Blob x;
1e21dac… drh 1085 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
1e21dac… drh 1086 verify_all_options();
1e21dac… drh 1087 if( g.argc<3 ){
1e21dac… drh 1088 usage("VAR ?FILE?");
1e21dac… drh 1089 }
1e21dac… drh 1090 zVar = g.argv[2];
1e21dac… drh 1091 zFile = g.argc>=4 ? g.argv[3] : "-";
1e21dac… drh 1092 n = db_int(0, "SELECT count(*) FROM config WHERE name GLOB %Q", zVar);
1e21dac… drh 1093 if( n==0 ){
1e21dac… drh 1094 fossil_fatal("no match for %Q", zVar);
1e21dac… drh 1095 }
1e21dac… drh 1096 if( n>1 ){
1e21dac… drh 1097 fossil_fatal("multiple matches: %s",
1e21dac… drh 1098 db_text(0, "SELECT group_concat(quote(name),', ') FROM ("
1e21dac… drh 1099 " SELECT name FROM config WHERE name GLOB %Q ORDER BY 1)",
1e21dac… drh 1100 zVar));
1e21dac… drh 1101 }
1e21dac… drh 1102 blob_init(&x,0,0);
1e21dac… drh 1103 db_blob(&x, "SELECT value FROM config WHERE name GLOB %Q", zVar);
1e21dac… drh 1104 blob_write_to_file(&x, zFile);
1e21dac… drh 1105 }
1e21dac… drh 1106
1e21dac… drh 1107 /*
1e21dac… drh 1108 ** COMMAND: test-var-set
1e21dac… drh 1109 **
1e21dac… drh 1110 ** Usage: %fossil test-var-set VAR ?VALUE? ?--file FILE?
1e21dac… drh 1111 **
1e21dac… drh 1112 ** Store VALUE or the content of FILE (exactly one of which must be
1e21dac… drh 1113 ** supplied) into variable VAR. Use a FILE of "-" to read from
1e21dac… drh 1114 ** standard input.
1e21dac… drh 1115 **
1e21dac… drh 1116 ** WARNING: changing the value of a variable can interfere with the
1e21dac… drh 1117 ** operation of Fossil. Be sure you know what you are doing.
1e21dac… drh 1118 **
1e21dac… drh 1119 ** Use "--blob FILE" instead of "--file FILE" to load a binary blob
1e21dac… drh 1120 ** such as a GIF.
1e21dac… drh 1121 */
1e21dac… drh 1122 void test_var_set_cmd(void){
1e21dac… drh 1123 const char *zVar;
1e21dac… drh 1124 const char *zFile;
1e21dac… drh 1125 const char *zBlob;
1e21dac… drh 1126 Blob x;
1e21dac… drh 1127 Stmt ins;
1e21dac… drh 1128 zFile = find_option("file",0,1);
1e21dac… drh 1129 zBlob = find_option("blob",0,1);
1e21dac… drh 1130 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
1e21dac… drh 1131 verify_all_options();
1e21dac… drh 1132 if( g.argc<3 || (zFile==0 && zBlob==0 && g.argc<4) ){
1e21dac… drh 1133 usage("VAR ?VALUE? ?--file FILE?");
1e21dac… drh 1134 }
1e21dac… drh 1135 zVar = g.argv[2];
1e21dac… drh 1136 if( zFile ){
1e21dac… drh 1137 if( zBlob ) fossil_fatal("cannot do both --file or --blob");
1772357… drh 1138 blob_read_from_file(&x, zFile, ExtFILE);
1e21dac… drh 1139 }else if( zBlob ){
1772357… drh 1140 blob_read_from_file(&x, zBlob, ExtFILE);
1e21dac… drh 1141 }else{
1e21dac… drh 1142 blob_init(&x,g.argv[3],-1);
1e21dac… drh 1143 }
f741baa… drh 1144 db_unprotect(PROTECT_CONFIG);
1e21dac… drh 1145 db_prepare(&ins,
1e21dac… drh 1146 "REPLACE INTO config(name,value,mtime)"
1e21dac… drh 1147 "VALUES(%Q,:val,now())", zVar);
1e21dac… drh 1148 if( zBlob ){
1e21dac… drh 1149 db_bind_blob(&ins, ":val", &x);
1e21dac… drh 1150 }else{
1e21dac… drh 1151 db_bind_text(&ins, ":val", blob_str(&x));
1e21dac… drh 1152 }
1e21dac… drh 1153 db_step(&ins);
1e21dac… drh 1154 db_finalize(&ins);
f741baa… drh 1155 db_protect_pop();
1e21dac… drh 1156 blob_reset(&x);
e06ae9f… drh 1157 }

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button