Fossil

Check-in [cb34f1a8ac]
Login

Check-in [cb34f1a8ac]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Initial changes to support HOST: prefixes on the REPOSITORY argument of the "fossil ui" command.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | remote-ui
Files: files | file ages | folders
SHA3-256: cb34f1a8ac57ea78b397a70d3cdadfb562b1cabd056265aba714a64b151607d4
User & Date: drh 2021-06-30 19:14:57.467
Context
2021-06-30
20:15
Improvements to "fossil ui HOST:PATH". ... (check-in: cff1f785e1 user: drh tags: remote-ui)
19:14
Initial changes to support HOST: prefixes on the REPOSITORY argument of the "fossil ui" command. ... (check-in: cb34f1a8ac user: drh tags: remote-ui)
17:39
Add the new file_skip_userhost() function that will find an skip over a "USER@HOST:" prefix on a filename, if it exists. Use this to extract the USER@HOST prefix from names in the "fossil patch push/pull" commands. ... (check-in: 89a8588853 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/alerts.c.
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
      x[2] = "0123456789ABCDEF"[c&0xf];
      blob_append(pOut, x, 3);
      iCol += 3;
    }
  }
}

#if defined(_WIN32) || defined(WIN32)
# undef popen
# define popen _popen
# undef pclose
# define pclose _pclose
#endif

#if INTERFACE
/*
** An instance of the following object is used to send emails.
*/
struct AlertSender {
  sqlite3 *db;               /* Database emails are sent to */
  sqlite3_stmt *pStmt;       /* Stmt to insert into the database */







<
<
<
<
<
<
<







395
396
397
398
399
400
401







402
403
404
405
406
407
408
      x[2] = "0123456789ABCDEF"[c&0xf];
      blob_append(pOut, x, 3);
      iCol += 3;
    }
  }
}








#if INTERFACE
/*
** An instance of the following object is used to send emails.
*/
struct AlertSender {
  sqlite3 *db;               /* Database emails are sent to */
  sqlite3_stmt *pStmt;       /* Stmt to insert into the database */
Changes to src/config.h.
64
65
66
67
68
69
70






71
72
73
74
75
76
77
#if defined( __MINGW32__) ||  defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
#  if defined(__DMC__)  || defined(_MSC_VER) || defined(__POCC__)
     typedef int socklen_t;
#  endif
#  ifndef _WIN32
#    define _WIN32
#  endif






#else
# include <sys/types.h>
# include <signal.h>
# include <pwd.h>
#endif

/*







>
>
>
>
>
>







64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#if defined( __MINGW32__) ||  defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__)
#  if defined(__DMC__)  || defined(_MSC_VER) || defined(__POCC__)
     typedef int socklen_t;
#  endif
#  ifndef _WIN32
#    define _WIN32
#  endif
# include <io.h>
# include <fcntl.h>
# undef popen
# define popen _popen
# undef pclose
# define pclose _pclose
#else
# include <sys/types.h>
# include <signal.h>
# include <pwd.h>
#endif

/*
Changes to src/export.c.
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
struct mark_t {
  char *name;       /* Name of the mark.  Also starts with ":" */
  int rid;          /* Corresponding object in the BLOB table */
  char uuid[65];    /* The GIT hash name for this object */
};
#endif

#if defined(_WIN32) || defined(WIN32)
# undef popen
# define popen _popen
# undef pclose
# define pclose _pclose
#endif

/*
** Output a "committer" record for the given user.
** NOTE: the given user name may be an email itself.
*/
static void print_person(const char *zUser){
  static Stmt q;
  const char *zContact;







<
<
<
<
<
<
<







36
37
38
39
40
41
42







43
44
45
46
47
48
49
struct mark_t {
  char *name;       /* Name of the mark.  Also starts with ":" */
  int rid;          /* Corresponding object in the BLOB table */
  char uuid[65];    /* The GIT hash name for this object */
};
#endif








/*
** Output a "committer" record for the given user.
** NOTE: the given user name may be an email itself.
*/
static void print_person(const char *zUser){
  static Stmt q;
  const char *zContact;
Changes to src/extcgi.c.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
** same login system as the main repository, and appear to be
** an integrated part of the repository.
*/
#include "config.h"
#include "extcgi.h"
#include <assert.h>

#if defined(_WIN32) || defined(WIN32)
# undef popen
# define popen _popen
# undef pclose
# define pclose _pclose
#endif

/*
** These are the environment variables that should be set for CGI
** extension programs:
*/
static const char *azCgiEnv[] = {
   "AUTH_TYPE",
   "AUTH_CONTENT",







<
<
<
<
<
<
<







28
29
30
31
32
33
34







35
36
37
38
39
40
41
** same login system as the main repository, and appear to be
** an integrated part of the repository.
*/
#include "config.h"
#include "extcgi.h"
#include <assert.h>








/*
** These are the environment variables that should be set for CGI
** extension programs:
*/
static const char *azCgiEnv[] = {
   "AUTH_TYPE",
   "AUTH_CONTENT",
Changes to src/http_transport.c.
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  return 0;
}

/*
** Default SSH command
*/
#if 0 /* was: defined(_WIN32).  Windows generally has ssh now. */
static const char zDefaultSshCmd[] = "plink -ssh -T";
#else
static const char zDefaultSshCmd[] = "ssh -e none -T";
#endif

/*
** Initialize a Blob to the name of the configured SSH command.
*/
void transport_ssh_command(Blob *p){
  char *zSsh;        /* The base SSH command */







|

|







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  return 0;
}

/*
** Default SSH command
*/
#if 0 /* was: defined(_WIN32).  Windows generally has ssh now. */
static const char zDefaultSshCmd[] = "plink -ssh";
#else
static const char zDefaultSshCmd[] = "ssh -e none";
#endif

/*
** Initialize a Blob to the name of the configured SSH command.
*/
void transport_ssh_command(Blob *p){
  char *zSsh;        /* The base SSH command */
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
  char *zHost;       /* The host name to contact */

  socket_ssh_resolve_addr(pUrlData);
  transport_ssh_command(&zCmd);
  if( pUrlData->port!=pUrlData->dfltPort && pUrlData->port ){
    blob_appendf(&zCmd, " -p %d", pUrlData->port);
  }
  blob_appendf(&zCmd, " --");  /* End of switches */
  if( pUrlData->user && pUrlData->user[0] ){
    zHost = mprintf("%s@%s", pUrlData->user, pUrlData->name);
    blob_append_escaped_arg(&zCmd, zHost, 0);
    fossil_free(zHost);
  }else{
    blob_append_escaped_arg(&zCmd, pUrlData->name, 0);
  }







|







120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
  char *zHost;       /* The host name to contact */

  socket_ssh_resolve_addr(pUrlData);
  transport_ssh_command(&zCmd);
  if( pUrlData->port!=pUrlData->dfltPort && pUrlData->port ){
    blob_appendf(&zCmd, " -p %d", pUrlData->port);
  }
  blob_appendf(&zCmd, " -T --");  /* End of switches */
  if( pUrlData->user && pUrlData->user[0] ){
    zHost = mprintf("%s@%s", pUrlData->user, pUrlData->name);
    blob_append_escaped_arg(&zCmd, zHost, 0);
    fossil_free(zHost);
  }else{
    blob_append_escaped_arg(&zCmd, pUrlData->name, 0);
  }
Changes to src/main.c.
2814
2815
2816
2817
2818
2819
2820
2821

2822





2823
2824
2825
2826
2827
2828
2829
2830
** "*.fossil*" will be served as static content.  With the "ui" command,
** the REPOSITORY can only be a directory if the --notfound option is
** also present.
**
** If the REPOSITORY is a directory name which is the root of a
** checkout, it will chdir to that directory and, unless overridden by
** the --page option, select the current checkout version in the
** timeline by default.

**





** For the special case REPOSITORY name of "/", the list global configuration
** database is consulted for a list of all known repositories.  The --repolist
** option is implied by this special case.  See also the "fossil all ui"
** command.
**
** By default, the "ui" command provides full administrative access without
** having to log in.  This can be disabled by turning off the "localauth"
** setting.  Automatic login for the "server" command is available if the







|
>

>
>
>
>
>
|







2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
** "*.fossil*" will be served as static content.  With the "ui" command,
** the REPOSITORY can only be a directory if the --notfound option is
** also present.
**
** If the REPOSITORY is a directory name which is the root of a
** checkout, it will chdir to that directory and, unless overridden by
** the --page option, select the current checkout version in the
** timeline by default.  This only works for the "fossil ui" command,
** not the "fossil server" command.
**
** If the REPOSITORY argument has a "HOST:" or "USER@HOST:" prefix, then
** the command is run on the remote host specified and the results are
** tunneled back to the localhost via SSH.  This feature only works for
** the "fossil ui" command, not the "fossil server" command.
**
** For the special case REPOSITORY name of "/", the global configuration
** database is consulted for a list of all known repositories.  The --repolist
** option is implied by this special case.  See also the "fossil all ui"
** command.
**
** By default, the "ui" command provides full administrative access without
** having to log in.  This can be disabled by turning off the "localauth"
** setting.  Automatic login for the "server" command is available if the
2890
2891
2892
2893
2894
2895
2896


2897
2898
2899
2900
2901
2902
2903
  int allowRepoList;         /* List repositories on URL "/" */
  const char *zAltBase;      /* Argument to the --baseurl option */
  const char *zFileGlob;     /* Static content must match this */
  char *zIpAddr = 0;         /* Bind to this IP address */
  int fCreate = 0;           /* The --create flag */
  const char *zInitPage = 0; /* Start on this page.  --page option */
  int findServerArg = 2;     /* argv index for find_server_repository() */



#if defined(_WIN32)
  const char *zStopperFile;    /* Name of file used to terminate server */
  zStopperFile = find_option("stopper", 0, 1);
#endif

  if( g.zErrlog==0 ){







>
>







2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
  int allowRepoList;         /* List repositories on URL "/" */
  const char *zAltBase;      /* Argument to the --baseurl option */
  const char *zFileGlob;     /* Static content must match this */
  char *zIpAddr = 0;         /* Bind to this IP address */
  int fCreate = 0;           /* The --create flag */
  const char *zInitPage = 0; /* Start on this page.  --page option */
  int findServerArg = 2;     /* argv index for find_server_repository() */
  char *zRemote = 0;         /* Remote host on which to run "fossil ui" */
  

#if defined(_WIN32)
  const char *zStopperFile;    /* Name of file used to terminate server */
  zStopperFile = find_option("stopper", 0, 1);
#endif

  if( g.zErrlog==0 ){
2971
2972
2973
2974
2975
2976
2977












2978
2979
2980
2981
2982

2983

2984
2985
2986
2987
2988
2989
2990
      }
      findServerArg = 99;
      fCreate = 0;
      g.argv[2] = 0;
      --g.argc;
    }
  }












  if( isUiCmd ){
    flags |= HTTP_SERVER_LOCALHOST|HTTP_SERVER_REPOLIST;
    g.useLocalauth = 1;
    allowRepoList = 1;
  }

  find_server_repository(findServerArg, fCreate);

  if( zInitPage==0 ){
    if( isUiCmd && g.localOpen ){
      zInitPage = "timeline?c=current";
    }else{
      zInitPage = "";
    }
  }







>
>
>
>
>
>
>
>
>
>
>
>





>
|
>







2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
      }
      findServerArg = 99;
      fCreate = 0;
      g.argv[2] = 0;
      --g.argc;
    }
  }
  if( isUiCmd && 3==g.argc
   && (zRemote = (char*)file_skip_userhost(g.argv[2]))!=0
  ){
    const char *zRepoTail = file_skip_userhost(g.argv[2]);
    unsigned x;
    int n;
    sqlite3_randomness(2,&x);
    zPort = mprintf("%d", 8100+(x%32000));
    n = (int)(zRepoTail - g.argv[2]) - 1;
    zRemote = mprintf("%.*s", n, g.argv[2]);
    g.argv[2] = (char*)zRepoTail;
  }
  if( isUiCmd ){
    flags |= HTTP_SERVER_LOCALHOST|HTTP_SERVER_REPOLIST;
    g.useLocalauth = 1;
    allowRepoList = 1;
  }
  if( !zRemote ){
    find_server_repository(findServerArg, fCreate);
  }
  if( zInitPage==0 ){
    if( isUiCmd && g.localOpen ){
      zInitPage = "timeline?c=current";
    }else{
      zInitPage = "";
    }
  }
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011

3012
3013
3014
3015
3016
3017

3018



3019
3020


























3021
3022
3023






3024
3025
3026
3027
3028
3029
3030
      }
    }
    iPort = mxPort = atoi(zPort);
  }else{
    iPort = db_get_int("http-port", 8080);
    mxPort = iPort+100;
  }
#if !defined(_WIN32)
  /* Unix implementation */
  if( isUiCmd ){

    zBrowser = fossil_web_browser();
    if( zIpAddr==0 ){
      zBrowserCmd = mprintf("%s \"http://localhost:%%d/%s\" &",
                            zBrowser, zInitPage);
    }else if( strchr(zIpAddr,':') ){
      zBrowserCmd = mprintf("%s \"http://[%s]:%%d/%s\" &",

                            zBrowser, zIpAddr, zInitPage);



    }else{
      zBrowserCmd = mprintf("%s \"http://%s:%%d/%s\" &",


























                            zBrowser, zIpAddr, zInitPage);
    }
  }






  if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
  if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
  db_close(1);
  if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
    fossil_fatal("unable to listen on TCP socket %d", iPort);
  }
  /* For the parent process, the cgi_http_server() command above never







<
<

>


|
<

|
>
|
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
>







3024
3025
3026
3027
3028
3029
3030


3031
3032
3033
3034
3035

3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
      }
    }
    iPort = mxPort = atoi(zPort);
  }else{
    iPort = db_get_int("http-port", 8080);
    mxPort = iPort+100;
  }


  if( isUiCmd ){
    char *zBrowserArg;
    zBrowser = fossil_web_browser();
    if( zIpAddr==0 ){
      zBrowserArg = mprintf("http://localhost:%%d/%s", zInitPage);

    }else if( strchr(zIpAddr,':') ){
      zBrowserArg = mprintf("http://[%s]:%%d/%s", zIpAddr, zInitPage);
    }else{
      zBrowserArg = mprintf("http://%s:%%d/%s", zIpAddr, zInitPage);
    }
#ifdef _WIN32
    zBrowserCmd = mprintf("%s %s &", zBrowser, zBrowserArg);
#else
    zBrowserCmd = mprintf("%s %!$ &", zBrowser, zBrowserArg);
#endif
    fossil_free(zBrowserArg);
  }
  if( zRemote && zBrowserCmd ){
    FILE *sshIn;
    Blob ssh;
    char zLine[1000];
    blob_init(&ssh, 0, 0);
    transport_ssh_command(&ssh);
    blob_appendf(&ssh, 
       " -t -L127.0.0.1:%d:127.0.0.1:%d -- %!$"
       " fossil server --nossl --port %d %!$",
       iPort, iPort, zRemote, iPort, g.argv[2]);
    fossil_print("%s\n", blob_str(&ssh));
    sshIn = popen(blob_str(&ssh), "r");
    if( sshIn==0 ){
      fossil_fatal("unable to %s", blob_str(&ssh));
    }
    while( fgets(zLine, sizeof(zLine), sshIn) ){
      fossil_print("%s", zLine);
      fflush(stdout);
      if( zBrowserCmd ){
        char *zCmd = mprintf(zBrowserCmd/*works-like:"%d"*/,iPort);
        fossil_system(zCmd);
        fossil_free(zCmd);
        fossil_free(zBrowserCmd);
        zBrowserCmd = 0;
      }
    }
    pclose(sshIn);
    fossil_free(zBrowserCmd);
    return;
  }
#if !defined(_WIN32)
  /* Unix implementation */
  if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
  if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
  db_close(1);
  if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
    fossil_fatal("unable to listen on TCP socket %d", iPort);
  }
  /* For the parent process, the cgi_http_server() command above never
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
  process_one_web_page(zNotFound, glob_create(zFileGlob), allowRepoList);
  if( g.fAnyTrace ){
    fprintf(stderr, "/***** Webpage finished in subprocess %d *****/\n",
            getpid());
  }
#else
  /* Win32 implementation */
  if( isUiCmd ){
    zBrowser = fossil_web_browser();
    if( zIpAddr==0 ){
      zBrowserCmd = mprintf("%s http://localhost:%%d/%s &",
                            zBrowser, zInitPage);
    }else if( strchr(zIpAddr,':') ){
      zBrowserCmd = mprintf("%s http://[%s]:%%d/%s &",
                            zBrowser, zIpAddr, zInitPage);
    }else{
      zBrowserCmd = mprintf("%s http://%s:%%d/%s &",
                            zBrowser, zIpAddr, zInitPage);
    }
  }
  if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
  if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
  db_close(1);
  if( allowRepoList ){
    flags |= HTTP_SERVER_REPOLIST;
  }
  if( win32_http_service(iPort, zAltBase, zNotFound, zFileGlob, flags) ){







<
<
<
<
<
<
<
<
<
<
<
<
<







3123
3124
3125
3126
3127
3128
3129













3130
3131
3132
3133
3134
3135
3136
  process_one_web_page(zNotFound, glob_create(zFileGlob), allowRepoList);
  if( g.fAnyTrace ){
    fprintf(stderr, "/***** Webpage finished in subprocess %d *****/\n",
            getpid());
  }
#else
  /* Win32 implementation */













  if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
  if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
  db_close(1);
  if( allowRepoList ){
    flags |= HTTP_SERVER_REPOLIST;
  }
  if( win32_http_service(iPort, zAltBase, zNotFound, zFileGlob, flags) ){
Changes to src/patch.c.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
**
** This file contains code used to implement the "diff" command
*/
#include "config.h"
#include "patch.h"
#include <assert.h>

/*
** Additional windows configuration for popen */
#if defined(_WIN32)
#  include <io.h>
#  include <fcntl.h>
#  undef popen
#  define popen _popen
#  undef pclose
#  define pclose _pclose
#endif

/*
** Try to compute the name of the computer on which this process
** is running.
*/
char *fossil_hostname(void){
  FILE *in;
  char zBuf[200];







<
<
<
<
<
<
<
<
<
<
<







17
18
19
20
21
22
23











24
25
26
27
28
29
30
**
** This file contains code used to implement the "diff" command
*/
#include "config.h"
#include "patch.h"
#include <assert.h>












/*
** Try to compute the name of the computer on which this process
** is running.
*/
char *fossil_hostname(void){
  FILE *in;
  char zBuf[200];
677
678
679
680
681
682
683

684
685
686
687
688
689
690
    blob_init(&cmd, 0, 0);
    blob_append_escaped_arg(&cmd, g.nameOfExe, 1);
    blob_appendf(&cmd, " patch %s%s %$ -", zRemoteCmd, zForce, zDir);
  }else{
    Blob remote;
    *(char*)(zDir-1) = 0;
    transport_ssh_command(&cmd);

    blob_append_escaped_arg(&cmd, zRemote, 0);
    blob_init(&remote, 0, 0);
    blob_appendf(&remote, "fossil patch %s%s --dir64 %z -", 
                 zRemoteCmd, zForce, encode64(zDir, -1));
    blob_append_escaped_arg(&cmd, blob_str(&remote), 0);
    blob_reset(&remote);
  }







>







666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
    blob_init(&cmd, 0, 0);
    blob_append_escaped_arg(&cmd, g.nameOfExe, 1);
    blob_appendf(&cmd, " patch %s%s %$ -", zRemoteCmd, zForce, zDir);
  }else{
    Blob remote;
    *(char*)(zDir-1) = 0;
    transport_ssh_command(&cmd);
    blob_appendf(&cmd, " -T");
    blob_append_escaped_arg(&cmd, zRemote, 0);
    blob_init(&remote, 0, 0);
    blob_appendf(&remote, "fossil patch %s%s --dir64 %z -", 
                 zRemoteCmd, zForce, encode64(zDir, -1));
    blob_append_escaped_arg(&cmd, blob_str(&remote), 0);
    blob_reset(&remote);
  }
Changes to src/user.c.
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
void freepass(){
  if( !zPwdBuffer ) return;
  assert( nPwdBuffer>0 );
  fossil_secure_free_page(zPwdBuffer, nPwdBuffer);
}
#endif

#if defined(_WIN32) || defined(WIN32)
# include <io.h>
# include <fcntl.h>
# undef popen
# define popen _popen
# undef pclose
# define pclose _pclose
#endif

/*
** Scramble substitution matrix:
*/
static char aSubst[256];

/*
** Descramble the password







<
<
<
<
<
<
<
<
<







110
111
112
113
114
115
116









117
118
119
120
121
122
123
void freepass(){
  if( !zPwdBuffer ) return;
  assert( nPwdBuffer>0 );
  fossil_secure_free_page(zPwdBuffer, nPwdBuffer);
}
#endif










/*
** Scramble substitution matrix:
*/
static char aSubst[256];

/*
** Descramble the password