author | Lars Hjemli <hjemli@gmail.com> | 2007-02-03 14:02:55 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-02-04 20:47:46 (UTC) |
commit | ce1c7336e5b3e3ebe8f8c9029c405aedec98c208 (patch) (unidiff) | |
tree | b51a59a9552b32519cf694c0f5dc68c5a739069c | |
parent | ebd7b0fbc378e9beca0b275c5cd9150c930bde56 (diff) | |
download | cgit-ce1c7336e5b3e3ebe8f8c9029c405aedec98c208.zip cgit-ce1c7336e5b3e3ebe8f8c9029c405aedec98c208.tar.gz cgit-ce1c7336e5b3e3ebe8f8c9029c405aedec98c208.tar.bz2 |
Read repo-info from /etc/cgitrc
This makes cgit read all repo-info from the configfile, instead of scanning for
possible git-dirs below a common root path. This is primarily done to get
better security (separate physical path from logical repo-name).
In /etc/cgitrc each repo is registered with the following keys:
repo.url
repo.name
repo.path
repo.desc
repo.owner
Note:
*Required keys are repo.url and repo.path, all others are optional
*Each occurrence of repo.url starts a new repository registration
*Default value for repo.name is taken from repo.url
*The value of repo.url cannot contain characters with special meaning for
urls (i.e. one of /?%&), while repo.name can contain anything.
Example:
repo.url=cgit-pub
repo.name=cgit/public
repo.path=/pub/git/cgit
repo.desc=My public cgit repo
repo.owner=Lars Hjemli
repo.url=cgit-priv
repo.name=cgit/private
repo.path=/home/larsh/src/cgit/.git
repo.desc=My private cgit repo
repo.owner=Lars Hjemli
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 64 | ||||
-rw-r--r-- | cgit.h | 18 | ||||
-rw-r--r-- | cgitrc | 13 | ||||
-rw-r--r-- | shared.c | 41 | ||||
-rw-r--r-- | ui-repolist.c | 39 |
5 files changed, 120 insertions, 55 deletions
@@ -1,61 +1,92 @@ | |||
1 | /* cgit.c: cgi for the git scm | 1 | /* cgit.c: cgi for the git scm |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | const char cgit_version[] = CGIT_VERSION; | 11 | const char cgit_version[] = CGIT_VERSION; |
12 | 12 | ||
13 | static void cgit_prepare_cache(struct cacheitem *item) | 13 | |
14 | static struct repoinfo *cgit_get_repoinfo(char *url) | ||
15 | { | ||
16 | int i; | ||
17 | struct repoinfo *repo; | ||
18 | |||
19 | for (i=0; i<cgit_repolist.count; i++) { | ||
20 | repo = &cgit_repolist.repos[i]; | ||
21 | if (!strcmp(repo->url, url)) | ||
22 | return repo; | ||
23 | } | ||
24 | return NULL; | ||
25 | } | ||
26 | |||
27 | |||
28 | static int cgit_prepare_cache(struct cacheitem *item) | ||
14 | { | 29 | { |
15 | if (!cgit_query_repo) { | 30 | if (!cgit_query_repo) { |
16 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); | 31 | item->name = xstrdup(fmt("%s/index.html", cgit_cache_root)); |
17 | item->ttl = cgit_cache_root_ttl; | 32 | item->ttl = cgit_cache_root_ttl; |
18 | } else if (!cgit_query_page) { | 33 | return 1; |
34 | } | ||
35 | cgit_repo = cgit_get_repoinfo(cgit_query_repo); | ||
36 | if (!cgit_repo) { | ||
37 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | ||
38 | cgit_print_docstart(title, item); | ||
39 | cgit_print_pageheader(title, 0); | ||
40 | cgit_print_error(fmt("Unknown repo: %s", cgit_query_repo)); | ||
41 | cgit_print_docend(); | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | if (!cgit_query_page) { | ||
19 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, | 46 | item->name = xstrdup(fmt("%s/%s/index.html", cgit_cache_root, |
20 | cgit_query_repo)); | 47 | cgit_repo->url)); |
21 | item->ttl = cgit_cache_repo_ttl; | 48 | item->ttl = cgit_cache_repo_ttl; |
22 | } else { | 49 | } else { |
23 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, | 50 | item->name = xstrdup(fmt("%s/%s/%s/%s.html", cgit_cache_root, |
24 | cgit_query_repo, cgit_query_page, | 51 | cgit_repo->url, cgit_query_page, |
25 | cache_safe_filename(cgit_querystring))); | 52 | cache_safe_filename(cgit_querystring))); |
26 | if (cgit_query_has_symref) | 53 | if (cgit_query_has_symref) |
27 | item->ttl = cgit_cache_dynamic_ttl; | 54 | item->ttl = cgit_cache_dynamic_ttl; |
28 | else if (cgit_query_has_sha1) | 55 | else if (cgit_query_has_sha1) |
29 | item->ttl = cgit_cache_static_ttl; | 56 | item->ttl = cgit_cache_static_ttl; |
30 | else | 57 | else |
31 | item->ttl = cgit_cache_repo_ttl; | 58 | item->ttl = cgit_cache_repo_ttl; |
32 | } | 59 | } |
60 | return 1; | ||
33 | } | 61 | } |
34 | 62 | ||
35 | static void cgit_print_repo_page(struct cacheitem *item) | 63 | static void cgit_print_repo_page(struct cacheitem *item) |
36 | { | 64 | { |
37 | if (chdir(fmt("%s/%s", cgit_root, cgit_query_repo)) || | 65 | char *title; |
38 | cgit_read_config("info/cgit", cgit_repo_config_cb)) { | 66 | int show_search; |
39 | char *title = fmt("%s - %s", cgit_root_title, "Bad request"); | 67 | |
68 | if (chdir(cgit_repo->path)) { | ||
69 | title = fmt("%s - %s", cgit_root_title, "Bad request"); | ||
40 | cgit_print_docstart(title, item); | 70 | cgit_print_docstart(title, item); |
41 | cgit_print_pageheader(title, 0); | 71 | cgit_print_pageheader(title, 0); |
42 | cgit_print_error(fmt("Unable to scan repository: %s", | 72 | cgit_print_error(fmt("Unable to scan repository: %s", |
43 | strerror(errno))); | 73 | strerror(errno))); |
44 | cgit_print_docend(); | 74 | cgit_print_docend(); |
45 | return; | 75 | return; |
46 | } | 76 | } |
47 | setenv("GIT_DIR", fmt("%s/%s", cgit_root, cgit_query_repo), 1); | 77 | |
48 | char *title = fmt("%s - %s", cgit_repo_name, cgit_repo_desc); | 78 | title = fmt("%s - %s", cgit_repo->name, cgit_repo->desc); |
49 | int show_search = 0; | 79 | show_search = 0; |
80 | setenv("GIT_DIR", cgit_repo->path, 1); | ||
50 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) | 81 | if (cgit_query_page && !strcmp(cgit_query_page, "log")) |
51 | show_search = 1; | 82 | show_search = 1; |
52 | cgit_print_docstart(title, item); | 83 | cgit_print_docstart(title, item); |
53 | cgit_print_pageheader(title, show_search); | 84 | cgit_print_pageheader(title, show_search); |
54 | if (!cgit_query_page) { | 85 | if (!cgit_query_page) { |
55 | cgit_print_summary(); | 86 | cgit_print_summary(); |
56 | } else if (!strcmp(cgit_query_page, "log")) { | 87 | } else if (!strcmp(cgit_query_page, "log")) { |
57 | cgit_print_log(cgit_query_head, cgit_query_ofs, 100, cgit_query_search); | 88 | cgit_print_log(cgit_query_head, cgit_query_ofs, 100, cgit_query_search); |
58 | } else if (!strcmp(cgit_query_page, "tree")) { | 89 | } else if (!strcmp(cgit_query_page, "tree")) { |
59 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 90 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
60 | } else if (!strcmp(cgit_query_page, "commit")) { | 91 | } else if (!strcmp(cgit_query_page, "commit")) { |
61 | cgit_print_commit(cgit_query_sha1); | 92 | cgit_print_commit(cgit_query_sha1); |
@@ -122,27 +153,24 @@ static void cgit_print_cache(struct cacheitem *item) | |||
122 | 153 | ||
123 | while((i=read(fd, buf, sizeof(buf))) > 0) | 154 | while((i=read(fd, buf, sizeof(buf))) > 0) |
124 | write(STDOUT_FILENO, buf, i); | 155 | write(STDOUT_FILENO, buf, i); |
125 | 156 | ||
126 | close(fd); | 157 | close(fd); |
127 | } | 158 | } |
128 | 159 | ||
129 | static void cgit_parse_args(int argc, const char **argv) | 160 | static void cgit_parse_args(int argc, const char **argv) |
130 | { | 161 | { |
131 | int i; | 162 | int i; |
132 | 163 | ||
133 | for (i = 1; i < argc; i++) { | 164 | for (i = 1; i < argc; i++) { |
134 | if (!strncmp(argv[i], "--root=", 7)) { | ||
135 | cgit_root = xstrdup(argv[i]+7); | ||
136 | } | ||
137 | if (!strncmp(argv[i], "--cache=", 8)) { | 165 | if (!strncmp(argv[i], "--cache=", 8)) { |
138 | cgit_cache_root = xstrdup(argv[i]+8); | 166 | cgit_cache_root = xstrdup(argv[i]+8); |
139 | } | 167 | } |
140 | if (!strcmp(argv[i], "--nocache")) { | 168 | if (!strcmp(argv[i], "--nocache")) { |
141 | cgit_nocache = 1; | 169 | cgit_nocache = 1; |
142 | } | 170 | } |
143 | if (!strncmp(argv[i], "--query=", 8)) { | 171 | if (!strncmp(argv[i], "--query=", 8)) { |
144 | cgit_querystring = xstrdup(argv[i]+8); | 172 | cgit_querystring = xstrdup(argv[i]+8); |
145 | } | 173 | } |
146 | if (!strncmp(argv[i], "--repo=", 7)) { | 174 | if (!strncmp(argv[i], "--repo=", 7)) { |
147 | cgit_query_repo = xstrdup(argv[i]+7); | 175 | cgit_query_repo = xstrdup(argv[i]+7); |
148 | } | 176 | } |
@@ -158,28 +186,34 @@ static void cgit_parse_args(int argc, const char **argv) | |||
158 | cgit_query_has_sha1 = 1; | 186 | cgit_query_has_sha1 = 1; |
159 | } | 187 | } |
160 | if (!strncmp(argv[i], "--ofs=", 6)) { | 188 | if (!strncmp(argv[i], "--ofs=", 6)) { |
161 | cgit_query_ofs = atoi(argv[i]+6); | 189 | cgit_query_ofs = atoi(argv[i]+6); |
162 | } | 190 | } |
163 | } | 191 | } |
164 | } | 192 | } |
165 | 193 | ||
166 | int main(int argc, const char **argv) | 194 | int main(int argc, const char **argv) |
167 | { | 195 | { |
168 | struct cacheitem item; | 196 | struct cacheitem item; |
169 | 197 | ||
198 | htmlfd = STDOUT_FILENO; | ||
199 | item.st.st_mtime = time(NULL); | ||
200 | cgit_repolist.length = 0; | ||
201 | cgit_repolist.count = 0; | ||
202 | cgit_repolist.repos = NULL; | ||
203 | |||
170 | cgit_read_config("/etc/cgitrc", cgit_global_config_cb); | 204 | cgit_read_config("/etc/cgitrc", cgit_global_config_cb); |
171 | if (getenv("QUERY_STRING")) | 205 | if (getenv("QUERY_STRING")) |
172 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); | 206 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); |
173 | cgit_parse_args(argc, argv); | 207 | cgit_parse_args(argc, argv); |
174 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); | 208 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); |
175 | 209 | if (!cgit_prepare_cache(&item)) | |
176 | cgit_prepare_cache(&item); | 210 | return 0; |
177 | if (cgit_nocache) { | 211 | if (cgit_nocache) { |
178 | item.fd = STDOUT_FILENO; | 212 | item.fd = STDOUT_FILENO; |
179 | cgit_fill_cache(&item); | 213 | cgit_fill_cache(&item); |
180 | } else { | 214 | } else { |
181 | cgit_check_cache(&item); | 215 | cgit_check_cache(&item); |
182 | cgit_print_cache(&item); | 216 | cgit_print_cache(&item); |
183 | } | 217 | } |
184 | return 0; | 218 | return 0; |
185 | } | 219 | } |
@@ -6,46 +6,62 @@ | |||
6 | #include <ctype.h> | 6 | #include <ctype.h> |
7 | #include <sched.h> | 7 | #include <sched.h> |
8 | 8 | ||
9 | typedef void (*configfn)(const char *name, const char *value); | 9 | typedef void (*configfn)(const char *name, const char *value); |
10 | 10 | ||
11 | struct cacheitem { | 11 | struct cacheitem { |
12 | char *name; | 12 | char *name; |
13 | struct stat st; | 13 | struct stat st; |
14 | int ttl; | 14 | int ttl; |
15 | int fd; | 15 | int fd; |
16 | }; | 16 | }; |
17 | 17 | ||
18 | struct repoinfo { | ||
19 | char *url; | ||
20 | char *name; | ||
21 | char *path; | ||
22 | char *desc; | ||
23 | char *owner; | ||
24 | }; | ||
25 | |||
26 | struct repolist { | ||
27 | int length; | ||
28 | int count; | ||
29 | struct repoinfo *repos; | ||
30 | }; | ||
31 | |||
18 | struct commitinfo { | 32 | struct commitinfo { |
19 | struct commit *commit; | 33 | struct commit *commit; |
20 | char *author; | 34 | char *author; |
21 | char *author_email; | 35 | char *author_email; |
22 | unsigned long author_date; | 36 | unsigned long author_date; |
23 | char *committer; | 37 | char *committer; |
24 | char *committer_email; | 38 | char *committer_email; |
25 | unsigned long committer_date; | 39 | unsigned long committer_date; |
26 | char *subject; | 40 | char *subject; |
27 | char *msg; | 41 | char *msg; |
28 | }; | 42 | }; |
29 | 43 | ||
30 | struct taginfo { | 44 | struct taginfo { |
31 | char *tagger; | 45 | char *tagger; |
32 | char *tagger_email; | 46 | char *tagger_email; |
33 | int tagger_date; | 47 | int tagger_date; |
34 | char *msg; | 48 | char *msg; |
35 | }; | 49 | }; |
36 | 50 | ||
37 | extern const char cgit_version[]; | 51 | extern const char cgit_version[]; |
38 | 52 | ||
39 | extern char *cgit_root; | 53 | extern struct repolist cgit_repolist; |
54 | extern struct repoinfo *cgit_repo; | ||
55 | |||
40 | extern char *cgit_root_title; | 56 | extern char *cgit_root_title; |
41 | extern char *cgit_css; | 57 | extern char *cgit_css; |
42 | extern char *cgit_logo; | 58 | extern char *cgit_logo; |
43 | extern char *cgit_logo_link; | 59 | extern char *cgit_logo_link; |
44 | extern char *cgit_virtual_root; | 60 | extern char *cgit_virtual_root; |
45 | extern char *cgit_cache_root; | 61 | extern char *cgit_cache_root; |
46 | 62 | ||
47 | extern int cgit_nocache; | 63 | extern int cgit_nocache; |
48 | extern int cgit_max_lock_attempts; | 64 | extern int cgit_max_lock_attempts; |
49 | extern int cgit_cache_root_ttl; | 65 | extern int cgit_cache_root_ttl; |
50 | extern int cgit_cache_repo_ttl; | 66 | extern int cgit_cache_repo_ttl; |
51 | extern int cgit_cache_dynamic_ttl; | 67 | extern int cgit_cache_dynamic_ttl; |
@@ -1,21 +1,17 @@ | |||
1 | ## | 1 | ## |
2 | ## cgitrc: template for /etc/cgitrc | 2 | ## cgitrc: template for /etc/cgitrc |
3 | ## | 3 | ## |
4 | 4 | ||
5 | 5 | ||
6 | ## root folder for git repos | ||
7 | #root=/usr/src/git | ||
8 | |||
9 | |||
10 | ## base for virtual urls. If specified, rewrite rules must be added to | 6 | ## base for virtual urls. If specified, rewrite rules must be added to |
11 | ## httpd.conf. Possible rules for /git/ when cgit.cgi is accessed as /cgit.cgi: | 7 | ## httpd.conf. Possible rules for /git/ when cgit.cgi is accessed as /cgit.cgi: |
12 | ## | 8 | ## |
13 | ## RewriteRule ^/git/$ /cgit.cgi [L,QSA] | 9 | ## RewriteRule ^/git/$ /cgit.cgi [L,QSA] |
14 | ## RewriteRule ^/git/([^/]+)/$ /cgit.cgi?r=$1 [L,QSA] | 10 | ## RewriteRule ^/git/([^/]+)/$ /cgit.cgi?r=$1 [L,QSA] |
15 | ## RewriteRule ^/git/([^/]+)/([^/]+)/$ /cgit.cgi?r=$1&p=$2 [L,QSA] | 11 | ## RewriteRule ^/git/([^/]+)/([^/]+)/$ /cgit.cgi?r=$1&p=$2 [L,QSA] |
16 | ## | 12 | ## |
17 | #virtual-root=/git | 13 | #virtual-root=/git |
18 | 14 | ||
19 | 15 | ||
20 | ## page title for the root page (repo listing) | 16 | ## page title for the root page (repo listing) |
21 | #root-title=Git repository browser | 17 | #root-title=Git repository browser |
@@ -52,12 +48,21 @@ | |||
52 | 48 | ||
53 | ## ttl for root page (repo listing) | 49 | ## ttl for root page (repo listing) |
54 | #cache-root-ttl=5 | 50 | #cache-root-ttl=5 |
55 | 51 | ||
56 | ## ttl for repo summary page | 52 | ## ttl for repo summary page |
57 | #cache-repo-ttl=5 | 53 | #cache-repo-ttl=5 |
58 | 54 | ||
59 | ## ttl for other dynamic pages | 55 | ## ttl for other dynamic pages |
60 | #cache-dynamic-ttl=5 | 56 | #cache-dynamic-ttl=5 |
61 | 57 | ||
62 | ## ttl for static pages (addressed by SHA-1) | 58 | ## ttl for static pages (addressed by SHA-1) |
63 | #cache-static-ttl=-1 | 59 | #cache-static-ttl=-1 |
60 | |||
61 | |||
62 | |||
63 | ## Example repository entry | ||
64 | #repo.url=cgit | ||
65 | #repo.name=cgit | ||
66 | #repo.desc=the caching cgi for git | ||
67 | #repo.path=/pub/git/cgit | ||
68 | #repo.owner=Lars Hjemli | ||
@@ -1,23 +1,25 @@ | |||
1 | /* shared.c: global vars + some callback functions | 1 | /* shared.c: global vars + some callback functions |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | char *cgit_root = "/usr/src/git"; | 11 | struct repolist cgit_repolist; |
12 | struct repoinfo *cgit_repo; | ||
13 | |||
12 | char *cgit_root_title = "Git repository browser"; | 14 | char *cgit_root_title = "Git repository browser"; |
13 | char *cgit_css = "/cgit.css"; | 15 | char *cgit_css = "/cgit.css"; |
14 | char *cgit_logo = "/git-logo.png"; | 16 | char *cgit_logo = "/git-logo.png"; |
15 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | 17 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; |
16 | char *cgit_virtual_root = NULL; | 18 | char *cgit_virtual_root = NULL; |
17 | 19 | ||
18 | char *cgit_cache_root = "/var/cache/cgit"; | 20 | char *cgit_cache_root = "/var/cache/cgit"; |
19 | 21 | ||
20 | int cgit_nocache = 0; | 22 | int cgit_nocache = 0; |
21 | int cgit_max_lock_attempts = 5; | 23 | int cgit_max_lock_attempts = 5; |
22 | int cgit_cache_root_ttl = 5; | 24 | int cgit_cache_root_ttl = 5; |
23 | int cgit_cache_repo_ttl = 5; | 25 | int cgit_cache_repo_ttl = 5; |
@@ -37,52 +39,83 @@ int cgit_query_has_sha1 = 0; | |||
37 | char *cgit_querystring = NULL; | 39 | char *cgit_querystring = NULL; |
38 | char *cgit_query_repo = NULL; | 40 | char *cgit_query_repo = NULL; |
39 | char *cgit_query_page = NULL; | 41 | char *cgit_query_page = NULL; |
40 | char *cgit_query_head = NULL; | 42 | char *cgit_query_head = NULL; |
41 | char *cgit_query_search = NULL; | 43 | char *cgit_query_search = NULL; |
42 | char *cgit_query_sha1 = NULL; | 44 | char *cgit_query_sha1 = NULL; |
43 | char *cgit_query_sha2 = NULL; | 45 | char *cgit_query_sha2 = NULL; |
44 | char *cgit_query_path = NULL; | 46 | char *cgit_query_path = NULL; |
45 | int cgit_query_ofs = 0; | 47 | int cgit_query_ofs = 0; |
46 | 48 | ||
47 | int htmlfd = 0; | 49 | int htmlfd = 0; |
48 | 50 | ||
51 | struct repoinfo *add_repo(const char *url) | ||
52 | { | ||
53 | struct repoinfo *ret; | ||
54 | |||
55 | if (++cgit_repolist.count > cgit_repolist.length) { | ||
56 | if (cgit_repolist.length == 0) | ||
57 | cgit_repolist.length = 8; | ||
58 | else | ||
59 | cgit_repolist.length *= 2; | ||
60 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | ||
61 | cgit_repolist.length * | ||
62 | sizeof(struct repoinfo)); | ||
63 | } | ||
64 | |||
65 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | ||
66 | ret->url = xstrdup(url); | ||
67 | ret->name = ret->url; | ||
68 | ret->path = NULL; | ||
69 | ret->desc = NULL; | ||
70 | ret->owner = NULL; | ||
71 | return ret; | ||
72 | } | ||
73 | |||
49 | void cgit_global_config_cb(const char *name, const char *value) | 74 | void cgit_global_config_cb(const char *name, const char *value) |
50 | { | 75 | { |
51 | if (!strcmp(name, "root")) | 76 | if (!strcmp(name, "root-title")) |
52 | cgit_root = xstrdup(value); | ||
53 | else if (!strcmp(name, "root-title")) | ||
54 | cgit_root_title = xstrdup(value); | 77 | cgit_root_title = xstrdup(value); |
55 | else if (!strcmp(name, "css")) | 78 | else if (!strcmp(name, "css")) |
56 | cgit_css = xstrdup(value); | 79 | cgit_css = xstrdup(value); |
57 | else if (!strcmp(name, "logo")) | 80 | else if (!strcmp(name, "logo")) |
58 | cgit_logo = xstrdup(value); | 81 | cgit_logo = xstrdup(value); |
59 | else if (!strcmp(name, "logo-link")) | 82 | else if (!strcmp(name, "logo-link")) |
60 | cgit_logo_link = xstrdup(value); | 83 | cgit_logo_link = xstrdup(value); |
61 | else if (!strcmp(name, "virtual-root")) | 84 | else if (!strcmp(name, "virtual-root")) |
62 | cgit_virtual_root = xstrdup(value); | 85 | cgit_virtual_root = xstrdup(value); |
63 | else if (!strcmp(name, "nocache")) | 86 | else if (!strcmp(name, "nocache")) |
64 | cgit_nocache = atoi(value); | 87 | cgit_nocache = atoi(value); |
65 | else if (!strcmp(name, "cache-root")) | 88 | else if (!strcmp(name, "cache-root")) |
66 | cgit_cache_root = xstrdup(value); | 89 | cgit_cache_root = xstrdup(value); |
67 | else if (!strcmp(name, "cache-root-ttl")) | 90 | else if (!strcmp(name, "cache-root-ttl")) |
68 | cgit_cache_root_ttl = atoi(value); | 91 | cgit_cache_root_ttl = atoi(value); |
69 | else if (!strcmp(name, "cache-repo-ttl")) | 92 | else if (!strcmp(name, "cache-repo-ttl")) |
70 | cgit_cache_repo_ttl = atoi(value); | 93 | cgit_cache_repo_ttl = atoi(value); |
71 | else if (!strcmp(name, "cache-static-ttl")) | 94 | else if (!strcmp(name, "cache-static-ttl")) |
72 | cgit_cache_static_ttl = atoi(value); | 95 | cgit_cache_static_ttl = atoi(value); |
73 | else if (!strcmp(name, "cache-dynamic-ttl")) | 96 | else if (!strcmp(name, "cache-dynamic-ttl")) |
74 | cgit_cache_dynamic_ttl = atoi(value); | 97 | cgit_cache_dynamic_ttl = atoi(value); |
75 | else if (!strcmp(name, "max-message-length")) | 98 | else if (!strcmp(name, "max-message-length")) |
76 | cgit_max_msg_len = atoi(value); | 99 | cgit_max_msg_len = atoi(value); |
100 | else if (!strcmp(name, "repo.url")) | ||
101 | cgit_repo = add_repo(value); | ||
102 | else if (!strcmp(name, "repo.name")) | ||
103 | cgit_repo->name = xstrdup(value); | ||
104 | else if (cgit_repo && !strcmp(name, "repo.path")) | ||
105 | cgit_repo->path = xstrdup(value); | ||
106 | else if (cgit_repo && !strcmp(name, "repo.desc")) | ||
107 | cgit_repo->desc = xstrdup(value); | ||
108 | else if (cgit_repo && !strcmp(name, "repo.owner")) | ||
109 | cgit_repo->owner = xstrdup(value); | ||
77 | } | 110 | } |
78 | 111 | ||
79 | void cgit_repo_config_cb(const char *name, const char *value) | 112 | void cgit_repo_config_cb(const char *name, const char *value) |
80 | { | 113 | { |
81 | if (!strcmp(name, "name")) | 114 | if (!strcmp(name, "name")) |
82 | cgit_repo_name = xstrdup(value); | 115 | cgit_repo_name = xstrdup(value); |
83 | else if (!strcmp(name, "desc")) | 116 | else if (!strcmp(name, "desc")) |
84 | cgit_repo_desc = xstrdup(value); | 117 | cgit_repo_desc = xstrdup(value); |
85 | else if (!strcmp(name, "owner")) | 118 | else if (!strcmp(name, "owner")) |
86 | cgit_repo_owner = xstrdup(value); | 119 | cgit_repo_owner = xstrdup(value); |
87 | } | 120 | } |
88 | 121 | ||
diff --git a/ui-repolist.c b/ui-repolist.c index bd4af59..011ec95 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -1,63 +1,40 @@ | |||
1 | /* ui-repolist.c: functions for generating the repolist page | 1 | /* ui-repolist.c: functions for generating the repolist page |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | void cgit_print_repolist(struct cacheitem *item) | 11 | void cgit_print_repolist(struct cacheitem *item) |
12 | { | 12 | { |
13 | DIR *d; | 13 | struct repoinfo *repo; |
14 | struct dirent *de; | 14 | int i; |
15 | struct stat st; | ||
16 | char *name; | ||
17 | 15 | ||
18 | chdir(cgit_root); | ||
19 | cgit_print_docstart(cgit_root_title, item); | 16 | cgit_print_docstart(cgit_root_title, item); |
20 | cgit_print_pageheader(cgit_root_title, 0); | 17 | cgit_print_pageheader(cgit_root_title, 0); |
21 | 18 | ||
22 | if (!(d = opendir("."))) { | ||
23 | cgit_print_error(fmt("Unable to scan repository directory: %s", | ||
24 | strerror(errno))); | ||
25 | cgit_print_docend(); | ||
26 | return; | ||
27 | } | ||
28 | |||
29 | html("<h2>Repositories</h2>\n"); | 19 | html("<h2>Repositories</h2>\n"); |
30 | html("<table class='list nowrap'>"); | 20 | html("<table class='list nowrap'>"); |
31 | html("<tr class='nohover'>" | 21 | html("<tr class='nohover'>" |
32 | "<th class='left'>Name</th>" | 22 | "<th class='left'>Name</th>" |
33 | "<th class='left'>Description</th>" | 23 | "<th class='left'>Description</th>" |
34 | "<th class='left'>Owner</th></tr>\n"); | 24 | "<th class='left'>Owner</th></tr>\n"); |
35 | while ((de = readdir(d)) != NULL) { | ||
36 | if (de->d_name[0] == '.') | ||
37 | continue; | ||
38 | if (stat(de->d_name, &st) < 0) | ||
39 | continue; | ||
40 | if (!S_ISDIR(st.st_mode)) | ||
41 | continue; | ||
42 | |||
43 | cgit_repo_name = cgit_repo_desc = cgit_repo_owner = NULL; | ||
44 | name = fmt("%s/info/cgit", de->d_name); | ||
45 | if (cgit_read_config(name, cgit_repo_config_cb)) | ||
46 | continue; | ||
47 | 25 | ||
26 | for (i=0; i<cgit_repolist.count; i++) { | ||
27 | repo = &cgit_repolist.repos[i]; | ||
48 | html("<tr><td>"); | 28 | html("<tr><td>"); |
49 | html_link_open(cgit_repourl(de->d_name), NULL, NULL); | 29 | html_link_open(cgit_repourl(repo->url), NULL, NULL); |
50 | html_txt(cgit_repo_name); | 30 | html_txt(repo->name); |
51 | html_link_close(); | 31 | html_link_close(); |
52 | html("</td><td>"); | 32 | html("</td><td>"); |
53 | html_txt(cgit_repo_desc); | 33 | html_txt(repo->desc); |
54 | html("</td><td>"); | 34 | html("</td><td>"); |
55 | html_txt(cgit_repo_owner); | 35 | html_txt(repo->owner); |
56 | html("</td></tr>\n"); | 36 | html("</td></tr>\n"); |
57 | } | 37 | } |
58 | closedir(d); | ||
59 | html("</table>"); | 38 | html("</table>"); |
60 | cgit_print_docend(); | 39 | cgit_print_docend(); |
61 | } | 40 | } |
62 | |||
63 | |||