List of commits:
Subject Hash Author Date (UTC)
Lots of changes, too hard to split them; sorry about it 77c26d9ce82d452ebdc1b609d71c5e931768805c Catalin(ux) M. BOIE 2021-10-21 06:05:51
Lots of changes to the rg daemons 8b68e3967f650953d368dfb5ca5cdd2927e9c0de Catalin(ux) M. BOIE 2021-10-21 06:05:03
Hooks: Mostly cosmetic 3633af7d937f7c9c7c0c33cdc3ad9897aab8becd Catalin(ux) M. BOIE 2021-10-21 06:04:02
Added RGFS for packages e0573aadcff81694d38ee448326964bddf0c3c13 Catalin(ux) M. BOIE 2021-10-21 06:02:37
Container changes cb3c4a84e2abc3a4b206925b60fdf4524e0379de Catalin(ux) M. BOIE 2021-10-21 06:01:25
Lots of html/css changes bde37682fac058f68806b3342ba043a2f72458ba Catalin(ux) M. BOIE 2021-10-21 06:00:29
Lots of tests updated 40e01f4db4d341d4e2dceb4407ea7d6ff523ac9e Catalin(ux) M. BOIE 2021-10-21 06:00:02
Big changes to add rpm packages repositories 5e07ff440d6ad7f0ef9900a634b2f39f0e7fa1e4 Catalin(ux) M. BOIE 2021-10-21 05:59:26
Cosmetic 02376344f7d7d321d824ab7978de2ad49c007167 Catalin(ux) M. BOIE 2021-05-23 12:57:06
Added FIDO2 support for SSH 04186abe13896ad4f4ea7126691d0a2b1798de1a Catalin(ux) M. BOIE 2021-05-23 12:30:43
ssh: show the id of the key both on web and when connecting ab95ccfa2819d6ac9f427209ee61c75aad8a3661 Catalin(ux) M. BOIE 2021-05-23 10:52:44
Some events are doing some queries, and we need to cover them in transaction, not only the subevents 4768ffec303961971cc0c3732a24e858f47dd381 Catalin(ux) M. BOIE 2020-12-15 07:33:36
Added rate limit for ssh and git connections b667130e6c5721a3d30193863a5defd8bbff50f1 Catalin(ux) M. BOIE 2020-11-30 10:49:27
cosmetic abe44edadda9da7c639b7bd8c9e13e6058555669 Catalin(ux) M. BOIE 2020-11-30 10:21:01
gpg functions and test ecb9e05c99a2b73edfba5014329e362d8c6e9246 Catalin(ux) M. BOIE 2020-11-09 07:38:11
Stats page is not rendered for bots. 29ca3f62ac460b64eb0a10fbb8bdfdf4a1767dc5 Catalin(ux) M. BOIE 2020-10-13 05:48:43
Added rate limit options 60e939a52577a01603f9f386ffaf1a9712f99ab6 Catalin(ux) M. BOIE 2020-10-07 05:02:25
Improved bots list and clean old entries 9da0a014040753734beabfecb298b8956fc25fe3 Catalin(ux) M. BOIE 2020-10-05 06:34:43
builder: use secrets only if available 4fe47afc60435508ad90f62c51d489ac3c20b4d0 Catalin(ux) M. BOIE 2020-08-28 07:29:14
worker: use secrets only if available 5371e918e294a46cc38c765371a1caf7a3083eef Catalin(ux) M. BOIE 2020-08-28 07:28:12
Commit 77c26d9ce82d452ebdc1b609d71c5e931768805c - Lots of changes, too hard to split them; sorry about it
Author: Catalin(ux) M. BOIE
Author date (UTC): 2021-10-21 06:05
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2021-10-21 06:05
Parent(s): 8b68e3967f650953d368dfb5ca5cdd2927e9c0de
Signer:
Signing key:
Signing status: N
Tree: 90c2c1de95d73332753af9d33e4aa443c2ee3d49
File Lines added Lines deleted
TODO 207 172
docker/.gitignore 1 0
inc/admin.inc.php 13 14
inc/admin/admin.php 9 3
inc/admin/mails/mails.php 1 1
inc/admin/plans/plans.php 1 1
inc/admin/users/users.php 4 5
inc/api.inc.php 4 1
inc/apikeys.inc.php 21 19
inc/artifacts.inc.php 21 14
inc/bug.inc.php 40 57
inc/builder.inc.php 54 51
inc/cache.inc.php 9 13
inc/conn.inc.php 15 1
inc/demo.inc.php 36 14
inc/dispatch/dispatch.php 19 9
inc/events.inc.php 51 37
inc/feedback/suggestion.php 2 1
inc/fixes.inc.php 27 12
inc/format.inc.php 8 8
inc/git.inc.php 111 136
inc/gpg.inc.php 35 23
inc/graph.inc.php 7 4
inc/keys.inc.php 44 38
inc/ldap.inc.php 25 24
inc/ldap_core.inc.php 2 2
inc/ldap_sync.inc.php 8 8
inc/log.inc.php 9 2
inc/login/login.php 2 3
inc/mail.inc.php 13 14
inc/mr.inc.php 9 9
inc/prof.inc.php 7 7
inc/ratelimit.inc.php 49 40
inc/repo.inc.php 131 353
inc/repo/repo.php 5 4
inc/rights.inc.php 276 31
inc/sess.inc.php 5 8
inc/sql.inc.php 9 3
inc/ssh.inc.php 39 34
inc/state.inc.php 33 13
inc/stats.inc.php 16 8
inc/struct.inc.php 49 33
inc/token.inc.php 4 4
inc/totp.inc.php 20 16
inc/user.inc.php 269 188
inc/user/confirm.php 1 3
inc/user/forgot.php 4 5
inc/user/home-page.php 12 12
inc/user/keys/keys.php 6 4
inc/user/pass/pass.php 3 3
inc/user/repo-page.php 36 50
inc/user/repo/artifacts/main.php 22 19
inc/user/repo/bug/main.php 11 18
inc/user/repo/bug/search/search.php 2 1
inc/user/repo/bug/show/add_note.php 4 12
inc/user/repo/bug/show/show.php 9 18
inc/user/settings.php 8 3
inc/util.inc.php 338 108
inc/watch.inc.php 9 7
inc/wh/amazon.inc.php 17 17
inc/wh/cloud.inc.php 13 10
inc/wh/core.inc.php 14 12
inc/wh/http.inc.php 21 20
inc/wh/http/matrix.inc.php 12 12
inc/wh/lambda.inc.php 11 9
inc/workers.inc.php 46 23
rocketgit.spec.in 8 1
root/index.php 71 50
samples/nginx.conf 23 72
samples/rocketgit-fs.service 2 2
samples/sshd-akc.conf 5 0
selinux/.gitignore 2 1
techdocs/html_escape.txt 45 0
File TODO changed (mode: 100644) (index b71bd61..ee2da02)
1 == Where I stopped last time ==
2
3 1 == Always == == Always ==
4 2 [ ] Always make sure we link the docs from the Features page. [ ] Always make sure we link the docs from the Features page.
3 [ ] Announce internal users.
5 4
6 5 == After deploy on rocketgit.com == == After deploy on rocketgit.com ==
7 6 [ ] Add to "Corporate friendly": a link to a frustrations page about current software. [ ] Add to "Corporate friendly": a link to a frustrations page about current software.
 
9 8 [ ] Switch worker@com to websocket. [ ] Switch worker@com to websocket.
10 9 [ ] docker [ ] docker
11 10 [ ] old environments are present in the list! At least on dev1. [ ] old environments are present in the list! At least on dev1.
11 Store the last update date (or the worker id) and do not show the
12 old ones.
12 13 [ ] Check if SELinux module is inserted. [ ] Check if SELinux module is inserted.
13 14 [ ] Announce RLUG [ ] Announce RLUG
14 15 [ ] Announce LWN [ ] Announce LWN
15 16 [ ] Announce build jobs users that now is working. [ ] Announce build jobs users that now is working.
17 [ ] Partner with Solo Keys?
16 18 [ ] [ ]
17 19
18 20 == Now == == Now ==
19 [ ] pkg: we need to store how many bytes were sent to the client for accounting purposes.
20 [ ] pkg: we need an api key to identify the user.
21 [ ] rpmdeb.com: 15$ for 5GiB storage + 15GiB bandwidth, 50$ 20+70, 100$ 50+150, 300$ 150+500.
22 [ ] I need to check the logs to see if cache is really refreshed when update_distro_info is called.
23 [ ] Do we need escaping for the link to the repo package?
24 [ ] A bot must not index pkg repos pages (https://rg.embedromix.ro:9003/user/catab/ci1/pkg)!
25 [ ] More changes from 'master' to 'main'.
26 [ ] head_link is not encoded properly (/ -> %2f)!
27 [ ] When clicking rpm URLs, set correct Content-Type.
28 [ ] rocketgit-*-*-ver.noarch.rpm should not be associated with a repo_id!
29 And should not be stored in meta. Or in a separate meta. How to distinguish between
30 them? Different folder? Yes, 'dotrepo'!
31 [ ] In /user/catab/ci1/pkg, I need to show the versions of the packages.
32 Maybe show older versions?
33 [ ] Do not build jobs (web hooks) for unconfirmed e-mails.
34 [ ] What to do with private repos mapping to global repo?
35 Can happen?
36 [ ] Decide what to do with environments. What to choose?
37 I think I should use the enabled ones.
38 Because the admin adding a new worker, with new envs,
39 agrees to add them automatically.
40 [ ] Analyze triggering of subbrepo regenerate
41 rg_wh_build_send_one
42 ||
43 rg_pkg_subrepo_event_regenerate
44 ||
45 rg_pkg_event_generate_dotrepo_rpm
46 pushing triggers the build and adds callback event_callbacks[]=pkg_generate_dotrepo_rpm_callback
47 worker sets status[pkg_subrepo_dirty]
48 builder receives job[status][pkg_subrepo_dirty]
49 rg_builder_done
50 adds event wh_build_job_done ev[status][pkg_subrepo_dirty]
51 calls rg_wh_build_job_done
52 process event_callbacks
53 rg_pkg_event_generate_dotrepo_rpm_callback
54 update distro_info
55 add ev:pkg_subrepo_regenerate
56 rg_pkg_subrepo_event_regenerate [RECURSIVE]
57
58 Another flow:
59 rg_pkg_subrepo_event_edit [only for previous generated dotrepos] [this is triggered because the name changed]
60 sets ev[force_regenerate_dotrepo]
61 ev:pkg_generate_dotrepo_rpm [pkg_repo_uid, env]
62 rg_pkg_event_generate_dotrepo_rpm
63 rg_pkg_prepare_ev_for_dotrepo
64 for every pkg_subrepo_id
65 if (!force_regenerate_dotrepo && sri[distro_info][dotrepo])
66 continue
67 sets callback rg_pkg_event_generate_dotrepo_rpm_callback
68 rg_builder_add
69
70 And we want to call ev:pkg_subrepo_regenerate. Where?
71 But, what about just editing a repo?
72
73 [ ] Use case ci3: no user repo, only mappinng to global.
74 [ ] When a pkg (sub)repo name changes, we need to remove old files.
75 [ ] build_jobs: add another column with the type of build? 'vm', 'docker' etc.?
76 [ ] Add in Admin report how many e-mails are confirmed.
77 [ ] We have graphics for worker. It would be nice to show also the start/end
78 of the jobs, including the id.
79 [ ] Trigger a single build for global repos, not for every subrepo, like it is now.
80 [ ] For public repos, do the pkg repo mapping to global. For private ones, do not.
81 [ ] Add triggered_by to events for debug/status info..
82 [ ] We can stream the build process by ssh, now that we have the channel...
83 [ ] If build job return error, do not update distro_info!
84 [ ] Problems pushing into a repo (ci1)
85 So, when I push, I expect to send a build job also containing dotrepo instructions.
86 Now it is not happening because the dotrepo info is not added.
87 It is added by:
88 - rg_pkg_subrepo_event_regenerate
89 - rg_pkg_event_generate_dotrepo_rpm
90 None are called when building a package!
91
92 [ ] In 'pkg_subrepo_event_regenerate' we have a time race: we do the build and we schedule the
93 'generate_dotrepo'. 'generate_dotrepo' may happen first.
94 We should do it on a callback?
95 [ ] Now, when pushing as a normal user, I am calling createrepo,
96 but we should also create the dotrepo if not available.
97 rg_pkg_subrepo_event_regenerate
98 $ev['pkg_subrepos'][$pkg_subrepo_id] = $sri;
99 rg_builder_add
100 trigger event pkg_generate_dotrepo_rpm
101
102 rg_pkg_subrepo_event_edit
103 rg_pkg_subrepo_info
104 foreach ($di as $env => $info)
105 continue if dotrepo was never generated
106 trigger event pkg_generate_dotrepo_rpm
107
108 [ ] DELETE from events, should be in the same transaction, right? Seems it is not!
109 [ ] 'distros' -> 'envs'?
110 [ ] When we edit a pkg repo, we trigger the rebuild of all dotrepos for all enabled distros.
111 We should not do it! We should do it only when first package is built! We should, see below.
112 Now, subrepo add/edit triggers 'pkg_generate_dotrepo_rpm'. I THINK IT SHOULD NOT. What about the name?!
113 I think it should be triggered for all already built dotrepo envs.
114 Now, rgfs triggers 'pkg_subrepo_event_regenerate' to rebuild pkg repo.
115 It may build a pkg for a distro we do not have a dotrepo done.
116 So, we need to trigger a build of a dotrepo.
117 We need to pass a custom distro list. Maybe we will pass a distro list to override the internal one.
118 Call trace:
119 rgfs[has env] ->
120 -> rg_pkg_subrepo_event_regenerate ->
121 -> pkg_subrepo may need rebuilding (global repo may be empty - first package added) ->
122 -> TODO: if (pkg_subrepo.distro_info[env][dotrepo] == 0) => trigger dotrepo creation ->
123 TODO, we do NOT need to force regeneration.
124 We already pass the 'env', so, use it!
125 pkg_subrepo edit ->
126 -> event 'rg_pkg_subrepo_event_edit' ->
127 -> TODO: for (all already generated dotrepo) trigger 'pkg_generate_dotrepo_rpm'
128 TODO: we need to force the regeneration of existing dotrepos.
129 TODO: remove old name?
130
131 IT IS possible that pkg_generate_dotrepo_rpm is already looking for distro_info
132 and we do not have to do it in rg_pkg_subrepo_event_edit? I am checking...
133 It uses rg_distros_enabled.
134 Should we pass a parameter to signal the forcing?
135
136 TODO: rg_pkg_subrepo_event_edit - regenerate all dotrepo for all already-generated-dotrepo envs.
137 Seems now pkg_generate_dotrepo_rpm is called, but is not clear what 'env'!
138 [ ] Switch for rg_distros to a table (distro,major,arch) to be able to store if
139 a dotrepo exists? No, because this info is per subrepo!
140 Do not forget that dotrepo is for rpms only!
141 There is some value to allow a user to restrict the (sub)repo
142 to a subset of distros?
143 We can do it also in the json.
144 What about a user repo? I think this is triggered by an event. Check.
145 We should trigger also for the global repos, to always have them.
146 Where should I trigger and what function?
147 There are two orthogonal things: distro-major-arch and pkg_subrepos.
148 When we enable a distro-major-arch, we need to trigger the build of dotrepo, only for global.
149 We should not trigger for all user pkg repos - are too many.
150 When we add a pkg_repo, we need to trigger dotrepo for all distro-major-arch.
151 Can't we wait till the first package is built?
152 WHERE IS THE IMPACT? Where do we show the list of dotrepo links?
153 Per repo ("Packages" menu). Maybe it would be wise to filter there first the list
154 based on info whether a package is present in that repo?
155 Seems it is the only page where I do this, so, no need for now
156 to build dotrepo if we do not have at least one package.
157 If we will have a dotrepo page where we list all global repos,
158 we can still check if we have a dotrepo for that repo.
159 I think I should do not worry about this now.
160 Let's filter the dotrepo page first, and then we will see from there.
161 [ ] distros: should a user restrict more what distros should be active? Per user/repo?
162 I think this is already done from webhook.
163 [ ] pkg repo: what about private repositories? We should not expose the packages!
164 [ ] When we enable an architecture, should we trigger a rebuild of the dotrepo packages?
165 Maybe we should just wait for the first package.
166 But, I think the dotrepo is still not built.
167 Maybe we should add an event to check that.
168 [ ] I need to report top 20 from the 'elap' time pov.
169 [ ] Add to pkg meta, when createrepo took place. Worker?
170 [ ] 'ui' is ambigous; migrate to 'page_ui', 'login_ui', 'repo_ui' etc.
171 [ ] rgfs configuration is hardcoded! We need an entry in Admin's 'Settings'.
172 [ ] worker: we prefix packages with 'job_username' which is incorrect!
173 It should be repo_username!
174 [ ] Move "Packages" settings to 'Admin' section. Now is Settings (of Admin).
175 [ ] We should not allow any uid to edit pkg subrepos! Check also pkg repos.
176 [ ] pkg.list should be removed! Should we use full paths to not copy it?
177 [ ] pkg repo link for public user pkg repo seems to not contain /username/! Should it?
178 https://rg.embedromix.ro:9003/user/catab/ci1/pkg (not logged in)
179 Problem: we are showing links to dotrepo which do not exist!
180 We must know if a dotrepo was built.
181 [ ] We should not pass to the worker pkg_repos/subrepos/maps which are not needed (from a security pov).
182 Now, we are doing filtering in the worker.
183 We need to prepare a list of pkg_repos in rg_pkg_event_generate_rpm
184 which should trigger the rebuilding of the repos.
185 [ ] When we call rg_pkg_event_generate_dotrepo_rpm, what about the old files
186 (using old name of the pkg_repo)?
21 [ ] Add an island on "Features" page about packages!
187 22 [ ] [ ]
188 23
189 24 == hook update == hook update
 
218 53 Seems we are cloning the namespace, before knowing if the user can push! Seems we are cloning the namespace, before knowing if the user can push!
219 54
220 55 == FOR OTHER RELEASE == == FOR OTHER RELEASE ==
56 [ ] Offer RGFS for all user content.
57 [ ] "Me" and "My repositories" pages seems to do the same thing!
58 [ ] Do the regular expression pkg repo mapping is checked?
59 [ ] 'repo map' is not used anymore, right?
60 [ ] pkg_repos: add stats for users.
61 [ ] When showing pkg repos, show the number of packages and size.
62 [ ] pkg_repos: 'Type: global' can be removed if we show only the global repos.
63 [ ] Tutorials: it is not centered. If I try to set 'margin: auto' on
64 'demo_container', the title is also centered.
65 [ ] pkg_repos: I have demos/TODO where I think we can generate rpms from
66 Pyton. Integrate it.
67 [ ] Move "Packages" settings to 'Admin' section. Now is Settings (of Admin).
68 Why? Because we are talking about global repos.
69 What about the user? I need to think more, but seems OK how it is now.
70 [ ] Settings -> Workers -> List
71 When browser loses focus, the space between the table and
72 the button becomes grey. If I focus the windows, it switches to another
73 gray.
74 [ ] hints: must "stick" to the bottom part of the div.
75 [ ] We should not allow any uid to edit pkg subrepos! Check also pkg repos.
76 Add test.
77 [ ] pkg_repo: hisnt: dnf repository-packages <repo_name> list
78 (list all packages of a repo)
79 [ ] For dotrepo, we may want to add 'Group: System Environment/Base'.
80 [ ] How much is the rpm key expiration?
81 [ ] pkg: when I am installing a repo, it asks me to confirm the key! Is it normal? Yes.
82 [ ] 'user_http_git' should not appear in logs if is not the case.
83 [ ] Add (http_)error_code to 'conns' table.
84 [ ] We should warn the user when creates a public repo but a private repo?
85 [ ] worker: we prefix packages with 'job_username' which is incorrect!
86 It should be repo_username! Still true?
87 [ ] pkg: Teach user ow to download debug packages and source packages.
88 [ ] rgfs configuration is hardcoded! We need an entry in Admin's 'Settings'.
89 By default should be the https host and port.
90 [ ] Add to pkg meta, when createrepo took place. Worker?
91 [ ] We show how to install the package. We need to show all details, as in
92 'Details about all versions', including download button!
93 [ ] pkg: add a test for rights.
94 [ ] Using only @@ESCAPE_SHELL_ARG@@ can have security issues (without HTML_SPECIAL:)?
95 [ ] Add a hint explaining why we have a 'Download' button in the packages page
96 for a private repo, instead of a "dnf link" like on a pub repo.
97 [ ] When creating public repos, do the pkg repo mapping to global.
98 I think that without more info about the branching strategy, we cannot do it.
99 We may consider it as unstable.
100 For private ones, do not.
101 [ ] When we enable an architecture, should we trigger a rebuild of the dotrepo packages?
102 Maybe we should just wait for the first package.
103 But, I think the dotrepo is still not built.
104 Maybe we should add an event to check that.
105 [ ] We may need to replace more instances of URL_ENCODE with HTML_SPECIAL.
106 [ ] When we call rg_pkg_event_generate_dotrepo_rpm, what about the old files
107 (using old name of the pkg_repo)?
108 [ ] If build job return error, do not update distro_info!
109 Seems I do not signal if the subtasks finish with success.
110 [ ] In 'pkg_subrepo_event_regenerate' we have a time race: we do the build and we schedule the
111 'generate_dotrepo'. 'generate_dotrepo' may happen first.
112 We should do it on a callback?
113 [ ] Use-case ci3: no user repo, only mapping to global.
114 [ ] When a pkg (sub)repo name changes, we need to remove old files.
115 Maybe we should not allow renaming? Hm.
116 [ ] Trigger a single build for global repos, not for every subrepo, like it is now.
117 [ ] The match in 'meta' should be done by repo_id and not by strcmp.
118 [ ] 'howto' may be stored in distro_info, next to 'distro_pkg_type'?
119 [ ] Why do I have things in 'pkg_repos/1/1/fedora/34/x86_64/os/+pending/catab'?
120 [ ] repo pkg: hash password?
121 [ ] Do we need escaping for the link to the repo package?
122 [ ] head_link is not encoded properly (/ -> %2f)!
123 [ ] rocketgit-*-*-ver.noarch.rpm should NOT be associated with a repo_id!
124 And should not be stored in meta. Or in a separate meta.
125 How to distinguish between them? Different folder? Yes, 'dotrepo'!
126 [ ] BETWEEK PKG REPO AND PKG SUBREPO THERE IS '-', NO '+'. I think is solved.
127 [ ] Can I send 404 when a resource does not exists and stil render the current page?
128 [ ] Add a configurable timeout to rgfs connection.
129 [ ] I can try to install rpms in a chroot.
130 [ ] Should we add a link to "Settings" submenu in the "page" page.
131 See for example having a settings link for "Packages" page.
132 [ ] Allow API calls over websocket connection.
133 [ ] /user/USER/REPO/pkg: show different the 'pending' packages?
134 [ ] We need to build ETag based on RG version and utime (at least).
135 [ ] artifacts: we should use etag and compression!
136 Probably we need to redo a lot of stuff in that area.
137 [ ] Notify users (with build hooks) when a new build environment is added.
138 [ ] Allow users to add/remove extra repositories hosted on rocketgit.
139 What about packages which run the srcipts as root?
140 Maybe by not running the installation scripts at all?
141 [ ] Add hints about 'nlink' in pkg and artifacts pages.
142 [ ] Show on the repo page to which repo(s) it is mapped.
143 [ ] communicate the name of the app to the cache daemon and use that name.
144 [ ] race: when inserting into partition tables, we need to use 'itime'
145 not 'now'.
146 [ ] pkg: we should try do identify the .spec file AFTER 'configure' run.
147 Think about projects which generate the .spec file (mine included).
148 [ ] pkg: we should document that .spec dependencies will be extracted
149 from that file and there is no need to specify them in the hook..
150 [ ] worker: do not build rgfs if is not needed!
151 [ ] If no mappings are added, shouldn't we add the global ones by default?
152 [ ] Switch for rg_distros to a table (distro,major,arch) to be able to store if
153 a dotrepo exists? No, because this info is per subrepo!
154 Do not forget that dotrepo is for rpms only!
155 There is some value to allow a user to restrict the (sub)repo
156 to a subset of distros?
157 We can do it also in the json.
158 What about a user repo? I think this is triggered by an event. Check.
159 We should trigger also for the global repos, to always have them.
160 Where should I trigger and what function?
161 There are two orthogonal things: distro-major-arch and pkg_subrepos.
162 When we enable a distro-major-arch, we need to trigger the build of dotrepo, only for global.
163 We should not trigger for all user pkg repos - are too many.
164 When we add a pkg_repo, we need to trigger dotrepo for all distro-major-arch.
165 Can't we wait till the first package is built?
166 WHERE IS THE IMPACT? Where do we show the list of dotrepo links?
167 Per repo ("Packages" menu). Maybe it would be wise to filter there first the list
168 based on info whether a package is present in that repo?
169 Seems it is the only page where I do this, so, no need for now
170 to build dotrepo if we do not have at least one package.
171 If we will have a dotrepo page where we list all global repos,
172 we can still check if we have a dotrepo for that repo.
173 I think I should do not worry about this now.
174 Let's filter the dotrepo page first, and then we will see from there.
175 [ ] distros: should a user restrict more what distros should be active?
176 Per user/repo? I think this is already done from webhook.
177 [ ] rights: we should test if at least one right is granted before allowing
178 access to grants tables? Do we need a "See rights" right?
179 Where is this needed?!
180 [ ] rights
181 What about 'A' (Admin) rights for a repo? It includes Grant/Revoke?
182 [ ] 'distros' -> 'envs'?
183 [ ] Add triggered_by to events for debug/status info.
184 [ ] Allow admin to set how many time must pass (after confirmation of e-mail)
185 before allowing users to execute expensive stuff (webhooks).
186 [ ] Allow API call over Websocket.
187 [ ] Allow independent debug settings. For example for worker/builder.
188 [ ] Add an option to trust X-Forwarded-For.
189 What about multiple headers?
190 [ ] Allow user to delete packages. Policy?
191 [ ] In /user/catab/ci1/pkg, should we allow download of old versions?
192 [ ] pkg: add test for a user which access granted to a repo if it can access
193 the repo pkg page.
194 [ ] pkg: what happens if a repo is switched from public to private and the reverse?
195 [ ] What to do with private repos mapping to global repo?
196 Can happen?
197 [ ] Granting/revoking rights should notify the user involved.
198 [ ] artifacts: docs: 'see' page: add a screenshot with the artifacts page.
199 [ ] environments
200 The problem: we filter the environment when a worker connects
201 to the builder. But we want to allow custom environments
202 defined by the user. How to achieve that?
203 Maybe we should start investigating what happens when a
204 worker connects.
205 Probably we need a separate table to keep this information.
206 And obsolete environments after a while and when the same workes
207 does not probide it anymore.
208 Then, we need to migrate from the 'state' to this table.
209 [ ] Allow artifacts to be stored in S3. Should be easy.
210 [ ] "Me" page: shot the date of the last push.
211 [ ] hint: pkg: how to list packages installed from rocketgit.
212 [ ] I need to report top 20 from the 'elap' time pov.
213 [ ] We can stream the build process by ssh to a waiting user, now that we have the channel...
214 [ ] We have graphics for worker. It would be nice to show also the start/end
215 of the jobs, including the id.
216 [ ] Add in Admin report how many e-mails are confirmed.
217 [ ] build_jobs: add another column with the type of build? 'vm', 'docker' etc.?
218 [ ] More changes from 'master' to 'main'.
219 [ ] Audit log for granting/revoking rights?
220 [ ] rights: repo: be very clear what "Access repo" means!
221 [ ] events: seems I am starting a transaction and then calling curl!
222 And I am doing an UPDATE right before ROLLBACK! Stupid!
223 [ ] DELETE from events, should be in the same transaction, right? Seems it is not!
224 [ ] Invalidate e-mail confirmation if user changes the e-mail.
225 [ ] Tranforms all 'ui_*' passed as parameters to use rg_ui_* inside.
226 [ ] rg_user_rename seems to not be used!
227 [ ] 'mail/user/rename' is used but is missing.
228 [ ] Try to move the call to rg_ip into the called functions.
229 [ ] We may get ui_login in stats_insert from rg_ui_login, and not passed.
230 [ ] When connecting by ssh, show also the name of the key (not yet added),
231 not only the id.
232 [ ] Allow users to upload/generates GPG keys and sign the artifacts/other
233 things.
234 [ ] Add possibility to reject pushes with non-signed commits.
235 [ ] Add a feature to copy rights from a user to another.
236 [ ] Send in daily report the size of the tables/indexes.
237 [ ] rights: Maybe we should not show "All" when all (current) rights
238 are granted?
239 [ ] htt: allow a user to download/upload a certificate, so http can act
240 as ssh regarding authentication?
241 [ ] conn: should we also store the http code or the command exit code?
242 [ ] pkg: allow user to manually remove packages.
243 [ ] pkg: allow a user to subscribe to an external pkg repo and manually approve
244 the flowing of the packages into his.
245 [ ] pkg: we need to store how many bytes were sent to the client for accounting purposes.
246 [ ] rpmdeb.com: 15$ for 5GiB storage + 15GiB transfer, 50$ 20+70, 100$ 50+150, 300$ 150+500.
247 [ ] pkg: when showing the head, show also the commit message?
248 [ ] Sometow give access to private repositories to other users.
249 Notify them when they got access.
250 [ ] build: how to remove old environments? Aadd a button for admin to delete
251 it and mark it as deleted to not how up in the list, even if a
252 worker is still using it?
221 253 [ ] fido2: a user/org/admin must be able to disable 'no touch' or 'no pin' keys. [ ] fido2: a user/org/admin must be able to disable 'no touch' or 'no pin' keys.
222 254 By not setting "no-touch" or by setting "verify-required". By not setting "no-touch" or by setting "verify-required".
223 255 [ ] ssh: admin must be able to disale completely !fido2 keys. [ ] ssh: admin must be able to disale completely !fido2 keys.
 
... ... Seems we are cloning the namespace, before knowing if the user can push!
232 264 [ ] Pushing ci1 should map to priv1/stab (25/9). It builds rpms but the repo is not shown. [ ] Pushing ci1 should map to priv1/stab (25/9). It builds rpms but the repo is not shown.
233 265 Probaly because is private. Check logs. Probaly because is private. Check logs.
234 266 [ ] conn: split bytes into in/out. [ ] conn: split bytes into in/out.
235 [ ] Get rid of $rg_distros.
267 [ ] Get rid of $rg_distros, rg_distros_enabled and rg_distros_enable.
268 I think is more "use enabled distros" instead of "removing $rg_distros".
269 Where are they used?
270 rg_state_get returns all envs, including the disabled ones.
236 271 [ ] Store also the number of bytes deleivered in 'conns'. It will be used [ ] Store also the number of bytes deleivered in 'conns'. It will be used
237 272 for charging. Done. Graphics are ok because of the -1? for charging. Done. Graphics are ok because of the -1?
238 273 [ ] Pay attention to history (switching from public to private) when recording [ ] Pay attention to history (switching from public to private) when recording
 
... ... But, we have a problem with the expiration time!
2483 2518 [ ] Use an 'indent' string per repo and (optionally) enforce it. [ ] Use an 'indent' string per repo and (optionally) enforce it.
2484 2519 [ ] Should we use a more restrictive umask? [ ] Should we use a more restrictive umask?
2485 2520 [ ] In some places we have rg_event_add and then COMMIT. The event processing [ ] In some places we have rg_event_add and then COMMIT. The event processing
2486 loop may loose the last transaction. :(
2521 loop may lose the last transaction. :(
2487 2522 [ ] Remove rg_repo_rights_*. Seems we cannot because we test if [ ] Remove rg_repo_rights_*. Seems we cannot because we test if
2488 2523 ri.uid == login_ui.uid, that we cannot do in rg_rights_get. ri.uid == login_ui.uid, that we cannot do in rg_rights_get.
2489 2524 Maybe if we pass the owner of a resource to rg_rights_get. Maybe if we pass the owner of a resource to rg_rights_get.
File docker/.gitignore changed (mode: 100644) (index c418961..657dac5)
... ... Dockerfile-postgresql
2 2 Dockerfile-rocketgit-alpine Dockerfile-rocketgit-alpine
3 3 Dockerfile-rocketgit Dockerfile-rocketgit
4 4 Dockerfile-rocketgit-dev Dockerfile-rocketgit-dev
5 *.ok
File inc/admin.inc.php changed (mode: 100644) (index 1c1aaeb..adcc33d)
... ... function rg_admin_invite_one($db, $event)
34 34 $header = rg_template("mail/common.head.txt", $rg, FALSE /*xss*/); $header = rg_template("mail/common.head.txt", $rg, FALSE /*xss*/);
35 35 $header = trim($header); $header = trim($header);
36 36 $header .= "\nFrom: $admin_name <" . $rg_admin_email . ">"; $header .= "\nFrom: $admin_name <" . $rg_admin_email . ">";
37 rg_log_ml("DEBUG: header=$header");
37 rg_log_debug('header=' . $header);
38 38 $body = str_replace('{NAME}', $event['name'], $event['body']); $body = str_replace('{NAME}', $event['name'], $event['body']);
39 39
40 40 $r = mail($event['email'], $subject, $body, $header, $r = mail($event['email'], $subject, $body, $header,
 
... ... function rg_admin_invite($db, $event)
53 53 { {
54 54 $ret = array(); $ret = array();
55 55
56 rg_log_ml("DEBUG: event[list]=" . print_r($event['list'], TRUE));
56 rg_log_debug('event[list]=' . print_r($event['list'], TRUE));
57 57 foreach ($event['list'] as $line) { foreach ($event['list'] as $line) {
58 58 $line = trim($line); $line = trim($line);
59 59 if (empty($line)) if (empty($line))
 
... ... function rg_admin_mails_users_one($db, $ev)
91 91 $header = rg_template('mail/common.head.txt', $rg, FALSE /*xss*/); $header = rg_template('mail/common.head.txt', $rg, FALSE /*xss*/);
92 92 $header = trim($header); $header = trim($header);
93 93 $header .= "\n" . 'From: ' . $admin_name . ' <' . $rg_admin_email . '>'; $header .= "\n" . 'From: ' . $admin_name . ' <' . $rg_admin_email . '>';
94 rg_log_ml('DEBUG: header=' . $header);
94 rg_log_debug('header=' . $header);
95 95
96 96 $r = mail($ev['email'], $subject, $ev['body'], $header, $r = mail($ev['email'], $subject, $ev['body'], $header,
97 97 '-f ' . $rg_admin_email); '-f ' . $rg_admin_email);
 
... ... function rg_admin_mails_users_high_level($db, $rg)
296 296 $ev = array( $ev = array(
297 297 'category' => 'admin_mails_users', 'category' => 'admin_mails_users',
298 298 'prio' => 50, 'prio' => 50,
299 'ui' => $rg['login_ui'],
300 299 'f' => $f); 'f' => $f);
301 300 $r = rg_event_add($db, $ev); $r = rg_event_add($db, $ev);
302 301 if ($r !== TRUE) { if ($r !== TRUE) {
 
... ... function rg_admin_mails_invites_high_level($db, $rg)
356 355 if (empty($_FILES['inv::file']['tmp_name'])) if (empty($_FILES['inv::file']['tmp_name']))
357 356 break; break;
358 357
359 rg_log_ml("DEBUG: we have a file uploaded: " . print_r($_FILES, TRUE));
358 rg_log_debug('we have a file uploaded: ' . print_r($_FILES, TRUE));
360 359 if ($_FILES['inv::file']['error'] !== UPLOAD_ERR_OK) { if ($_FILES['inv::file']['error'] !== UPLOAD_ERR_OK) {
361 360 $errmsg[] = "error in upload (1); try again"; $errmsg[] = "error in upload (1); try again";
362 361 break; break;
 
... ... function rg_admin_mails_invites_high_level($db, $rg)
420 419
421 420 $event = array( $event = array(
422 421 'category' => 'admin_invite', 'category' => 'admin_invite',
423 'prio' => 50,
424 'ui' => $rg['login_ui']);
422 'prio' => 50
423 );
425 424 $event = array_merge($event, $inv); $event = array_merge($event, $inv);
426 425 $event['list'] = $list; $event['list'] = $list;
427 426 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
 
... ... function rg_init($db, $rg)
483 482 $rg['init']['pass2'] = rg_var_str('init::pass2'); $rg['init']['pass2'] = rg_var_str('init::pass2');
484 483 $rg['init']['session_time'] = rg_var_uint('init::session_time'); $rg['init']['session_time'] = rg_var_uint('init::session_time');
485 484 $rg['init']['confirmed'] = time(); /* = no need to confirm */ $rg['init']['confirmed'] = time(); /* = no need to confirm */
486 $rg['init']['last_ip'] = $rg['ip'];
485 $rg['init']['last_ip'] = rg_ip();
487 486
488 487 if (!rg_valid_referer()) { if (!rg_valid_referer()) {
489 488 $errmsg[] = "invalid referer; try again"; $errmsg[] = "invalid referer; try again";
 
... ... function rg_admin_report_conns($db, $from, $to)
558 557 break; break;
559 558 } }
560 559
561 $url = rg_base_url();
560 $url = rg_base_url($db, '', '');
562 561 $x = explode('://', $url, 2); $x = explode('://', $url, 2);
563 562 $url = $x[1]; $url = $x[1];
564 563
 
... ... function rg_admin_report1($db, $rg)
738 737
739 738 $body = ''; $body = '';
740 739
741 $site = rg_base_url();
740 $site = rg_base_url($db, '', '');
742 741 $y_start = gmmktime(0, 0, 0, gmdate("m"), gmdate("d") - 1); $y_start = gmmktime(0, 0, 0, gmdate("m"), gmdate("d") - 1);
743 742 $y_end = gmmktime(0, 0, 0, gmdate("m"), gmdate("d")) - 1; $y_end = gmmktime(0, 0, 0, gmdate("m"), gmdate("d")) - 1;
744 743
 
... ... function rg_admin_report1($db, $rg)
856 855 $body .= 'Average elap: ' . $conns['avg_elap'] . 'ms' . "\n\n"; $body .= 'Average elap: ' . $conns['avg_elap'] . 'ms' . "\n\n";
857 856 unset($conns['avg_elap']); unset($conns['avg_elap']);
858 857
859 //rg_log_ml('DEBUG: conns: ' . print_r($conns, TRUE));
858 //rg_log_debug('conns: ' . print_r($conns, TRUE));
860 859 foreach ($conns as $t => $i) { foreach ($conns as $t => $i) {
861 860 $body .= 'Top for \'' . $t . '\':' . "\n"; $body .= 'Top for \'' . $t . '\':' . "\n";
862 861 foreach ($i as $k => $v) { foreach ($i as $k => $v) {
 
... ... function rg_admin_report1($db, $rg)
882 881 return FALSE; return FALSE;
883 882 $body .= $r; $body .= $r;
884 883
885 $rg['ui']['ignore_confirmed'] = 1;
886 $rg['ui']['email'] = $rg_admin_email;
884 $rg['ui_login']['ignore_confirmed'] = 1;
885 $rg['ui_login']['email'] = $rg_admin_email;
887 886 $rg['mail'] = array(); $rg['mail'] = array();
888 887 $rg['mail']['subject'] = 'RocketGit report' $rg['mail']['subject'] = 'RocketGit report'
889 888 . ' [' . $g['users']['yesterday'] . 'u]' . ' [' . $g['users']['yesterday'] . 'u]'
 
... ... function rg_admin_settings_ssh($db, $rg)
1115 1114 $ev = array( $ev = array(
1116 1115 'category' => 'rg_keys_event_regen', 'category' => 'rg_keys_event_regen',
1117 1116 'prio' => 10, 'prio' => 10,
1118 'ui' => array('uid' => $rg['login_ui']['uid'])
1117 'source' => 'admin_settings_ssh'
1119 1118 ); );
1120 1119 $r = rg_event_add($db, $ev); $r = rg_event_add($db, $ev);
1121 1120 if ($r !== TRUE) { if ($r !== TRUE) {
File inc/admin/admin.php changed (mode: 100644) (index 2879403..5ff1bc2)
1 1 <?php <?php
2 rg_log("FILE: /inc/admin/admin");
2 require_once(__DIR__ . '/distros.inc.php');
3 3
4 4 $_admin = ''; $_admin = '';
5 5
6 if ($rg['login_ui']['is_admin'] != 1) {
7 $_admin .= rg_template("access_denied.html", $rg, TRUE /* xss */);
6 $ui_login = rg_ui_login();
7 if ($ui_login['is_admin'] != 1) {
8 rg_log_debug('User is not admin');
9 $_admin .= rg_template('access_denied.html', $rg, TRUE /*xss*/);
8 10 return; return;
9 11 } }
10 12
 
... ... case 'workers':
43 45 $_admin_body = rg_worker_high_level($db, $rg, $paras); $_admin_body = rg_worker_high_level($db, $rg, $paras);
44 46 break; break;
45 47
48 case 'distros':
49 $_admin_body = rg_admin_distros($db, $rg, $paras);
50 break;
51
46 52 case 'mails': case 'mails':
47 53 include(__DIR__ . '/mails/mails.php'); include(__DIR__ . '/mails/mails.php');
48 54 $_admin_body = $_admin_mails; $_admin_body = $_admin_mails;
File inc/admin/mails/mails.php changed (mode: 100644) (index d92078d..954787c)
2 2 $_admin_mails = ''; $_admin_mails = '';
3 3
4 4 $_op = empty($paras) ? 'users' : array_shift($paras); $_op = empty($paras) ? 'users' : array_shift($paras);
5 rg_log('DEBUG: _op=' . $_op . ' sparas=' . rg_array2string($paras));
5 rg_log_debug('_op=' . $_op . ' sparas=' . rg_array2string($paras));
6 6
7 7 $rg['admin_mails_menu'][$_op] = 1; $rg['admin_mails_menu'][$_op] = 1;
8 8 $rg['HTML:menu_level2'] = rg_template('admin/mails/menu.html', $rg, TRUE /*xss*/); $rg['HTML:menu_level2'] = rg_template('admin/mails/menu.html', $rg, TRUE /*xss*/);
File inc/admin/plans/plans.php changed (mode: 100644) (index 58ece96..e1c9938)
2 2 $_admin_plans = ''; $_admin_plans = '';
3 3
4 4 $_op = empty($paras) ? "list" : array_shift($paras); $_op = empty($paras) ? "list" : array_shift($paras);
5 rg_log("DEBUG: _op=$_op sparas=" . rg_array2string($paras));
5 rg_log_debug('_op=$_op sparas=' . rg_array2string($paras));
6 6
7 7 $rg['admin_plans_menu'][$_op] = 1; $rg['admin_plans_menu'][$_op] = 1;
8 8 $rg['HTML:menu_level2'] = rg_template("admin/plans/menu.html", $rg, TRUE /*xss*/); $rg['HTML:menu_level2'] = rg_template("admin/plans/menu.html", $rg, TRUE /*xss*/);
File inc/admin/users/users.php changed (mode: 100644) (index 7e27640..c1fb051)
... ... case 'edit': // edit
22 22 break; break;
23 23
24 24 case 'suspend': case 'suspend':
25 if (!rg_user_suspend($db, $rg, $target_ui, 1))
25 if (!rg_user_suspend($db, $target_ui, 1))
26 26 $_admin_users .= rg_template("admin/users/bad_suspend.html", $rg, TRUE /* xss */); $_admin_users .= rg_template("admin/users/bad_suspend.html", $rg, TRUE /* xss */);
27 27 break; break;
28 28
29 29 case 'unsuspend': case 'unsuspend':
30 if (!rg_user_suspend($db, $rg, $target_ui, 0))
30 if (!rg_user_suspend($db, $target_ui, 0))
31 31 $_admin_users .= rg_template("admin/users/bad_unsuspend.html", $rg, TRUE /* xss */); $_admin_users .= rg_template("admin/users/bad_unsuspend.html", $rg, TRUE /* xss */);
32 32 break; break;
33 33
34 34 case 'make_admin': case 'make_admin':
35 if (!rg_user_make_admin($db, $rg, $target_ui, 1))
35 if (!rg_user_make_admin($db, $target_ui, 1))
36 36 $_admin_users .= rg_template("admin/users/bad_admin.html", $rg, TRUE /* xss */); $_admin_users .= rg_template("admin/users/bad_admin.html", $rg, TRUE /* xss */);
37 37 break; break;
38 38
39 39 case 'remove_admin': case 'remove_admin':
40 if (!rg_user_make_admin($db, $rg, $target_ui, 0))
40 if (!rg_user_make_admin($db, $target_ui, 0))
41 41 $_admin_users .= rg_template("admin/users/bad_unadmin.html", $rg, TRUE /* xss */); $_admin_users .= rg_template("admin/users/bad_unadmin.html", $rg, TRUE /* xss */);
42 42 break; break;
43 43
 
... ... case 'remove':
50 50 if ($_show_list == 1) if ($_show_list == 1)
51 51 $_admin_users .= rg_user_list($db); $_admin_users .= rg_user_list($db);
52 52
53 ?>
File inc/api.inc.php changed (mode: 100644) (index f3317d6..1018a5b)
... ... function rg_api($db, &$a, $json)
32 32 // Needed for logging // Needed for logging
33 33 rg_stats_conns_set('cmd', $json['cmd']); rg_stats_conns_set('cmd', $json['cmd']);
34 34
35 $ui_login = rg_ui_login();
36
35 37 if (isset($json['user'])) { if (isset($json['user'])) {
36 38 $a['target_ui'] = rg_user_info($db, 0, $json['user'], ''); $a['target_ui'] = rg_user_info($db, 0, $json['user'], '');
37 39 } else if (isset($json['uid'])) { } else if (isset($json['uid'])) {
38 40 $a['target_ui'] = rg_user_info($db, $json['uid'], '', ''); $a['target_ui'] = rg_user_info($db, $json['uid'], '', '');
39 41 } else { } else {
40 $a['target_ui'] = $a['login_ui'];
42 $a['target_ui'] = $ui_login;
41 43 } }
42 44
45 rg_stats_conns_set('login_uid', $ui_login['uid']);
43 46 rg_stats_conns_set('uid', $a['target_ui']['uid']); rg_stats_conns_set('uid', $a['target_ui']['uid']);
44 47
45 48 if (strncmp($json['cmd'], 'user', 4) == 0) { if (strncmp($json['cmd'], 'user', 4) == 0) {
File inc/apikeys.inc.php changed (mode: 100644) (index c32c871..993ce08)
... ... function rg_ak_event_notify_user($db, $event)
85 85 } }
86 86
87 87 /* /*
88 * Remove api keys from database for user 'ui'
88 * Remove api keys from database for user 'ui_login'
89 89 */ */
90 function rg_ak_remove($db, $ui, $list)
90 function rg_ak_remove($db, $ui_login, $list)
91 91 { {
92 92 rg_prof_start('ak_remove'); rg_prof_start('ak_remove');
93 93 rg_log_enter('ak_remove: list=' . rg_array2string($list)); rg_log_enter('ak_remove: list=' . rg_array2string($list));
 
... ... function rg_ak_remove($db, $ui, $list)
98 98 foreach ($list as $key_id => $junk) foreach ($list as $key_id => $junk)
99 99 $my_list[] = sprintf('%u', $key_id); $my_list[] = sprintf('%u', $key_id);
100 100
101 $params = array('uid' => $ui['uid']);
101 $params = array('uid' => $ui_login['uid']);
102 102 $sql_list = implode(', ', $my_list); $sql_list = implode(', ', $my_list);
103 103 $sql = 'DELETE FROM apikeys' $sql = 'DELETE FROM apikeys'
104 104 . ' WHERE uid = @@uid@@' . ' WHERE uid = @@uid@@'
 
... ... function rg_ak_remove($db, $ui, $list)
113 113 $event = array( $event = array(
114 114 'category' => 'ak_event_del', 'category' => 'ak_event_del',
115 115 'prio' => 50, 'prio' => 50,
116 'ui' => $ui,
116 'ui_login' => $ui_login,
117 117 'keys' => implode(',', $my_list)); 'keys' => implode(',', $my_list));
118 118 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
119 119 if ($r !== TRUE) { if ($r !== TRUE) {
 
... ... function rg_ak_remove($db, $ui, $list)
122 122 break; break;
123 123 } }
124 124
125 $key = 'user' . '::' . $ui['uid'] . '::' . 'apikeys'
125 $key = 'user' . '::' . $ui_login['uid'] . '::' . 'apikeys'
126 126 . '::' . 'list'; . '::' . 'list';
127 127 foreach ($my_list as $_key_id) foreach ($my_list as $_key_id)
128 128 rg_cache_unset($key . '::' . $_key_id, rg_cache_unset($key . '::' . $_key_id,
 
... ... function rg_ak_remove($db, $ui, $list)
142 142 * Adds an apikey * Adds an apikey
143 143 * Returns the key_id of the key. * Returns the key_id of the key.
144 144 */ */
145 function rg_ak_add($db, $ui, $key, $name)
145 function rg_ak_add($db, $ui_login, $key, $name)
146 146 { {
147 147 rg_prof_start('ak_add'); rg_prof_start('ak_add');
148 148 rg_log_enter('ak_add: key=' . $key . ' name=' . $name); rg_log_enter('ak_add: key=' . $key . ' name=' . $name);
 
... ... function rg_ak_add($db, $ui, $key, $name)
161 161
162 162 $params = array( $params = array(
163 163 'itime' => $itime, 'itime' => $itime,
164 'uid' => $ui['uid'],
164 'uid' => $ui_login['uid'],
165 165 'key' => $key, 'key' => $key,
166 166 'name' => $name, 'name' => $name,
167 167 'count' => 0, 'count' => 0,
 
... ... function rg_ak_add($db, $ui, $key, $name)
184 184 $event = array( $event = array(
185 185 'category' => 'ak_event_new', 'category' => 'ak_event_new',
186 186 'prio' => 50, 'prio' => 50,
187 'ui' => $ui,
187 'ui_login' => $ui_login,
188 188 'key' => $key, 'key' => $key,
189 189 'name' => $name, 'name' => $name,
190 190 'key_id' => $key_id); 'key_id' => $key_id);
 
... ... function rg_ak_add($db, $ui, $key, $name)
202 202 } }
203 203 $do_rollback = 0; $do_rollback = 0;
204 204
205 $_key = 'user' . '::' . $ui['uid'] . '::'
205 $_key = 'user' . '::' . $ui_login['uid'] . '::'
206 206 . 'apikeys' . '::' . 'list' . '::' . $key_id; . 'apikeys' . '::' . 'list' . '::' . $key_id;
207 207 rg_cache_merge($_key, $params, RG_SOCKET_NO_WAIT); rg_cache_merge($_key, $params, RG_SOCKET_NO_WAIT);
208 208
 
... ... function rg_ak_add($db, $ui, $key, $name)
223 223 /* /*
224 224 * Update first_use, last_use, last_ip and count * Update first_use, last_use, last_ip and count
225 225 */ */
226 function rg_ak_update_use($db, $uid, $key_id, $ip, $cmd)
226 function rg_ak_update_use($db, $uid, $key_id, $cmd)
227 227 { {
228 228 rg_prof_start('ak_update_use'); rg_prof_start('ak_update_use');
229 229 rg_log_enter('ak_update_use: uid=' . $uid . ' key_id=' . $key_id rg_log_enter('ak_update_use: uid=' . $uid . ' key_id=' . $key_id
230 . ', ip=' . $ip . ', cmd=' . $cmd);
230 . ' cmd=' . $cmd);
231 231
232 232 $ret = FALSE; $ret = FALSE;
233 233 while (1) { while (1) {
 
... ... function rg_ak_update_use($db, $uid, $key_id, $ip, $cmd)
245 245
246 246 // We will not update the field if is too soon // We will not update the field if is too soon
247 247 if (isset($c['last_use']) if (isset($c['last_use'])
248 && (strcmp($ip, $c['last_ip']) == 0)
248 && (strcmp(rg_ip(), $c['last_ip']) == 0)
249 249 && (strcmp($cmd, $c['last_cmd']) == 0) && (strcmp($cmd, $c['last_cmd']) == 0)
250 250 && ($now - $c['last_use'] < 60)) && ($now - $c['last_use'] < 60))
251 251 $update_last_use = FALSE; $update_last_use = FALSE;
 
... ... function rg_ak_update_use($db, $uid, $key_id, $ip, $cmd)
254 254 $params = array( $params = array(
255 255 'now' => $now, 'now' => $now,
256 256 'key_id' => $key_id, 'key_id' => $key_id,
257 'last_ip' => $ip,
257 'last_ip' => rg_ip(),
258 258 'last_cmd' => $cmd); 'last_cmd' => $cmd);
259 259
260 260 if ($update_first_use) { if ($update_first_use) {
 
... ... function rg_ak_update_use($db, $uid, $key_id, $ip, $cmd)
287 287
288 288 $a = array( $a = array(
289 289 'last_use' => $now, 'last_use' => $now,
290 'last_ip' => $ip,
290 'last_ip' => rg_ip(),
291 291 'last_cmd' => $cmd); 'last_cmd' => $cmd);
292 292 rg_cache_merge($key, $a, RG_SOCKET_NO_WAIT); rg_cache_merge($key, $a, RG_SOCKET_NO_WAIT);
293 293 } }
 
... ... function rg_ak_list($db, $uid)
340 340 while (1) { while (1) {
341 341 $key = 'user' . '::' . $uid . '::' . 'apikeys'; $key = 'user' . '::' . $uid . '::' . 'apikeys';
342 342 $c = rg_cache_get($key); $c = rg_cache_get($key);
343 //rg_log_ml('DEBUG: cache: ' . print_r($c, TRUE));
343 //rg_log_debug('cache: ' . print_r($c, TRUE));
344 344 if (($c !== FALSE) && isset($c['LOADED'])) { if (($c !== FALSE) && isset($c['LOADED'])) {
345 345 $ret = $c['list']; $ret = $c['list'];
346 346
 
... ... function rg_ak_list_high_level($db, $rg, $paras)
442 442 $errmsg = array(); $errmsg = array();
443 443 $rg['HTML:status'] = ''; $rg['HTML:status'] = '';
444 444
445 $ui_login = rg_ui_login();
445 446 $doit = rg_var_uint('doit'); $doit = rg_var_uint('doit');
446 447 while ($doit == 1) { while ($doit == 1) {
447 448 if (!rg_valid_referer()) { if (!rg_valid_referer()) {
 
... ... function rg_ak_list_high_level($db, $rg, $paras)
455 456 } }
456 457
457 458 $list = rg_var_str('key_delete_ids'); $list = rg_var_str('key_delete_ids');
458 $r = rg_ak_remove($db, $rg['login_ui'], $list);
459 $r = rg_ak_remove($db, $ui_login, $list);
459 460 if ($r !== TRUE) { if ($r !== TRUE) {
460 461 $errmsg[] = 'cannot delete: ' . rg_ak_error(); $errmsg[] = 'cannot delete: ' . rg_ak_error();
461 462 break; break;
 
... ... function rg_ak_list_high_level($db, $rg, $paras)
467 468 break; break;
468 469 } }
469 470
470 $r = rg_ak_list($db, $rg['login_ui']['uid']);
471 $r = rg_ak_list($db, $ui_login['uid']);
471 472 if ($r === FALSE) { if ($r === FALSE) {
472 473 $rg['errmsg'] = rg_ak_error(); $rg['errmsg'] = rg_ak_error();
473 474 $ret .= rg_template('user/settings/apikeys/list_err.html', $ret .= rg_template('user/settings/apikeys/list_err.html',
 
... ... function rg_ak_add_high_level($db, $rg, $paras)
498 499 $rg['ak']['name'] = ''; $rg['ak']['name'] = '';
499 500 $rg['ak']['key'] = rg_id(32);; $rg['ak']['key'] = rg_id(32);;
500 501
502 $ui_login = rg_ui_login();
501 503 $doit = rg_var_uint('doit'); $doit = rg_var_uint('doit');
502 rg_log('DEBUG: doit=' . $doit);
504 rg_log_debug('doit=' . $doit);
503 505 while ($doit == 1) { while ($doit == 1) {
504 506 $rg['ak']['name'] = trim(rg_var_str('ak::name')); $rg['ak']['name'] = trim(rg_var_str('ak::name'));
505 507 $rg['ak']['key'] = trim(rg_var_str('ak::key')); $rg['ak']['key'] = trim(rg_var_str('ak::key'));
 
... ... function rg_ak_add_high_level($db, $rg, $paras)
519 521 break; break;
520 522 } }
521 523
522 $r = rg_ak_add($db, $rg['login_ui'], $rg['ak']['key'],
524 $r = rg_ak_add($db, $ui_login, $rg['ak']['key'],
523 525 $rg['ak']['name']); $rg['ak']['name']);
524 526 if ($r === FALSE) { if ($r === FALSE) {
525 527 $errmsg[] = rg_ak_error(); $errmsg[] = rg_ak_error();
File inc/artifacts.inc.php changed (mode: 100644) (index 89853c6..9e1be5d)
... ... function rg_artifacts_error()
19 19 */ */
20 20 function rg_artifacts_load_file($uid, $repo_id, $path) function rg_artifacts_load_file($uid, $repo_id, $path)
21 21 { {
22 rg_log_enter('artifacts_load_one: path=' . $path);
22 rg_log_enter('artifacts_load_file: path=' . $path);
23 23
24 24 $ret = FALSE; $ret = FALSE;
25 while (1) {
25 do {
26 26 if (strstr($path, '..')) { if (strstr($path, '..')) {
27 27 rg_artifacts_set_error('invalid path'); rg_artifacts_set_error('invalid path');
28 28 break; break;
 
... ... function rg_artifacts_load_file($uid, $repo_id, $path)
30 30
31 31 $apath = rg_repo_artifacts_path_by_id($uid, $repo_id); $apath = rg_repo_artifacts_path_by_id($uid, $repo_id);
32 32 $fpath = $apath . '/' . $path; $fpath = $apath . '/' . $path;
33 $s = @stat($fpath);
34 if ($s === FALSE) {
35 rg_artifacts_set_error('cannot stat path');
36 break;
37 }
38
33 39 $ret = @rg_unserialize(file_get_contents($fpath . '.rg.meta')); $ret = @rg_unserialize(file_get_contents($fpath . '.rg.meta'));
34 40 if ($ret === FALSE) { if ($ret === FALSE) {
35 rg_log('DEBUG: cannot load metadata from ' . $fpath . '.rg.data');
36 $ret = array();
41 rg_artifacts_set_error('cannot load metadata from'
42 . ' ' . $fpath . '.rg.data');
43 break;
37 44 } }
38 rg_log_ml('DEBUG: data loaded from .rg.meta: ' . print_r($ret, TRUE));
45 rg_log_debug('data loaded from .rg.meta: ' . print_r($ret, TRUE));
46
47 $ret['nlink'] = $s['nlink'];
48 $ret['size'] = $s['size'];
39 49
40 50 $ret['full_path'] = $fpath; $ret['full_path'] = $fpath;
41 51 $ret['path'] = dirname($path); $ret['path'] = dirname($path);
 
... ... function rg_artifacts_load_file($uid, $repo_id, $path)
48 58 if (!isset($ret['content_type'])) if (!isset($ret['content_type']))
49 59 $ret['content_type'] = rg_content_type_by_ext($ret['file']); $ret['content_type'] = rg_content_type_by_ext($ret['file']);
50 60
51 rg_log_ml('ret: ' . print_r($ret, TRUE));
52 break;
53 }
61 rg_log_debug('ret: ' . print_r($ret, TRUE));
62 } while (0);
54 63
55 64 rg_log_exit(); rg_log_exit();
56 65 return $ret; return $ret;
 
... ... function rg_artifacts_load_file($uid, $repo_id, $path)
61 70 */ */
62 71 function rg_artifacts_load($uid, $repo_id, $dir) function rg_artifacts_load($uid, $repo_id, $dir)
63 72 { {
64 rg_log_enter('artifacts_load');
73 rg_log_enter('artifacts_load repo_id=' . $repo_id . ' dir=' . $dir);
65 74
66 75 $ret = FALSE; $ret = FALSE;
67 while (1) {
76 do {
68 77 if (strstr($dir, '..')) { if (strstr($dir, '..')) {
69 78 rg_artifacts_set_error('invalid dir'); rg_artifacts_set_error('invalid dir');
70 79 break; break;
 
... ... function rg_artifacts_load($uid, $repo_id, $dir)
95 104 continue; continue;
96 105 } }
97 106
107 // it is a dir
98 108 $a = array(); $a = array();
99 109 $a['content_type'] = 'n/a'; $a['content_type'] = 'n/a';
100 110 $a['size'] = 'n/a'; $a['size'] = 'n/a';
 
... ... function rg_artifacts_load($uid, $repo_id, $dir)
107 117 $a['size_nice'] = 'n/a'; $a['size_nice'] = 'n/a';
108 118 $ret[] = $a; $ret[] = $a;
109 119 } }
110
111 rg_log_ml('ret: ' . print_r($ret, TRUE));
112 break;
113 }
120 } while (0);
114 121
115 122 rg_log_exit(); rg_log_exit();
116 123 return $ret; return $ret;
File inc/bug.inc.php changed (mode: 100644) (index 5aebf52..c7b7bc1)
... ... rg_event_register_functions($rg_bug_functions);
52 52 */ */
53 53 function rg_bug_event_add_one($db, $event) function rg_bug_event_add_one($db, $event)
54 54 { {
55 rg_log_enter("DEBUG: bug_event_add_one event=" . rg_array2string($event));
55 rg_log_enter('bug_event_add_one event=' . rg_array2string($event));
56 56
57 57 $ret = FALSE; $ret = FALSE;
58 58 while (1) { while (1) {
 
... ... function rg_bug_event_add_all($db, $event)
80 80 $x = $event; $x = $event;
81 81 $x['category'] = 'bug_event_add_one'; $x['category'] = 'bug_event_add_one';
82 82 $x['prio'] = 100; $x['prio'] = 100;
83 $x['ui'] = array();
84 83
85 84 // We will sent notifications to all watchers of a repo // We will sent notifications to all watchers of a repo
86 85 $r = rg_watch_load_by_obj_id($db, "repo", $event['ri']['repo_id'], 0); $r = rg_watch_load_by_obj_id($db, "repo", $event['ri']['repo_id'], 0);
 
... ... function rg_bug_event_add_all($db, $event)
89 88 $full = rg_user_list_to_full_info($db, $r); $full = rg_user_list_to_full_info($db, $r);
90 89 if ($full === FALSE) if ($full === FALSE)
91 90 return FALSE; return FALSE;
92 foreach ($full as $uid => $ui) {
93 $x['ui'] = $ui;
91 foreach ($full as $uid => $ui_login) {
92 $x['ui_login'] = $ui_login;
94 93 $ret[$uid] = $x; $ret[$uid] = $x;
95 94 } }
96 95
 
... ... function rg_bug_event_add_all($db, $event)
102 101 $full = rg_user_list_to_full_info($db, $r); $full = rg_user_list_to_full_info($db, $r);
103 102 if ($full === FALSE) if ($full === FALSE)
104 103 return FALSE; return FALSE;
105 foreach ($full as $uid => $ui) {
106 $x['ui'] = $ui;
104 foreach ($full as $uid => $ui_login) {
105 $x['ui_login'] = $ui_login;
107 106 $ret[$uid] = $x; $ret[$uid] = $x;
108 107 } }
109 108
 
... ... function rg_bug_event_add_all($db, $event)
114 113 /* /*
115 114 * Notify one user when a note is added to a bug * Notify one user when a note is added to a bug
116 115 */ */
117 function rg_bug_event_note_add_one($db, $event)
116 function rg_bug_event_note_add_one($db, $ev)
118 117 { {
119 rg_log_enter("DEBUG: bug_event_note_add_one event=" . rg_array2string($event));
118 rg_log_enter('bug_event_note_add_one event=' . rg_array2string($ev));
120 119
121 120 $ret = FALSE; $ret = FALSE;
122 121 while (1) { while (1) {
123 // lookup user email
124 $ui = rg_user_info($db, $event['ui']['uid'], '', '');
125 if ($ui['exists'] != 1) {
126 rg_internal_error("User does not exists!");
127 break;
128 }
129
130 $event['ui']['email'] = $ui['email'];
131 $r = rg_mail_template("mail/user/repo/bug/new_note", $event);
122 $r = rg_mail_template('mail/user/repo/bug/new_note', $ev);
132 123 if ($r === FALSE) if ($r === FALSE)
133 124 break; break;
134 125
 
... ... function rg_bug_event_note_add_all($db, $event)
151 142 $x = $event; $x = $event;
152 143 $x['category'] = 'bug_event_note_add_one'; $x['category'] = 'bug_event_note_add_one';
153 144 $x['prio'] = 100; $x['prio'] = 100;
154 $x['ui'] = array();
145 $x['ui_login'] = array();
155 146
156 147 // Now, build the list of users that will receive notification // Now, build the list of users that will receive notification
157 148 $r = rg_watch_load_by_obj_id($db, 'bug', $event['ri']['repo_id'], $r = rg_watch_load_by_obj_id($db, 'bug', $event['ri']['repo_id'],
 
... ... function rg_bug_event_note_add_all($db, $event)
162 153 if ($full === FALSE) if ($full === FALSE)
163 154 return FALSE; return FALSE;
164 155 foreach ($full as $uid => $ui) { foreach ($full as $uid => $ui) {
165 $x['ui'] = $ui;
156 $x['ui_login'] = $ui;
166 157 $ret[] = $x; $ret[] = $x;
167 158 } }
168 159
169 rg_log_ml("DEBUG: ret: " . print_r($ret, TRUE));
160 rg_log_debug('ret: ' . print_r($ret, TRUE));
170 161 rg_prof_end("bug_event_note_add_all"); rg_prof_end("bug_event_note_add_all");
171 162 return $ret; return $ret;
172 163 } }
 
... ... function rg_bug_vars_defaults($rg)
220 211 $ret['body'] = $rg['ri']['template']; $ret['body'] = $rg['ri']['template'];
221 212 $ret['state'] = 1; $ret['state'] = 1;
222 213 $ret['labels'] = ''; $ret['labels'] = '';
223 $ret['assigned_to'] = $rg['page_ui']['username'];
214 $ui_page = rg_ui_page();
215 $ret['assigned_to'] = $ui_page['username'];
224 216
225 217 return $ret; return $ret;
226 218 } }
 
... ... function rg_bug_info($db, $repo_id, $bug_id)
347 339 * Add/edit a bug * Add/edit a bug
348 340 * If bug_id > 0 - edit, else add * If bug_id > 0 - edit, else add
349 341 */ */
350 function rg_bug_edit($db, $login_ui, $ri, $data)
342 function rg_bug_edit($db, $ui_login, $ri, $data)
351 343 { {
352 344 rg_prof_start("bug_edit"); rg_prof_start("bug_edit");
353 345 rg_log_enter("bug_edit: data: " . rg_array2string($data)); rg_log_enter("bug_edit: data: " . rg_array2string($data));
 
... ... function rg_bug_edit($db, $login_ui, $ri, $data)
355 347 $data['labels'] = isset($data['labels']) ? $data['labels'] : ""; $data['labels'] = isset($data['labels']) ? $data['labels'] : "";
356 348
357 349 $now = time(); $now = time();
358 $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : "";
359 350
360 351 $ret = FALSE; $ret = FALSE;
361 352 $rollback = 0; $rollback = 0;
 
... ... function rg_bug_edit($db, $login_ui, $ri, $data)
408 399
409 400 $data['itime'] = $now; $data['itime'] = $now;
410 401 $data['utime'] = $now; $data['utime'] = $now;
411 $data['ip'] = $ip;
402 $data['ip'] = rg_ip();
412 403 $data['repo_id'] = $ri['repo_id']; $data['repo_id'] = $ri['repo_id'];
413 $data['uid'] = $login_ui['uid'];
404 $data['uid'] = $ui_login['uid'];
414 405 if ($add == 1) { if ($add == 1) {
415 406 $data['deleted'] = 0; $data['deleted'] = 0;
416 407 $sql = "INSERT INTO bugs (bug_id, itime, utime, repo_id" $sql = "INSERT INTO bugs (bug_id, itime, utime, repo_id"
 
... ... function rg_bug_edit($db, $login_ui, $ri, $data)
437 428
438 429 // Add reporter and assignee to the watch list // Add reporter and assignee to the watch list
439 430 if ($add == 1) { if ($add == 1) {
440 $r = rg_watch_add($db, 'bug', $login_ui['uid'],
431 $r = rg_watch_add($db, 'bug', $ui_login['uid'],
441 432 $ri['repo_id'], $data['bug_id']); $ri['repo_id'], $data['bug_id']);
442 433 if ($r === FALSE) { if ($r === FALSE) {
443 434 rg_bug_set_error("cannot add to watch list" rg_bug_set_error("cannot add to watch list"
 
... ... function rg_bug_edit($db, $login_ui, $ri, $data)
460 451 $event = array( $event = array(
461 452 'category' => 'bug_event_add_all', 'category' => 'bug_event_add_all',
462 453 'prio' => 200, 'prio' => 200,
463 'ui' => $login_ui,
454 'ui_login' => $ui_login,
464 455 'ri' => array( 'ri' => array(
465 456 'repo_id' => $ri['repo_id'], 'repo_id' => $ri['repo_id'],
466 457 'name' => $ri['name']), 'name' => $ri['name']),
467 458 'bug' => array( 'bug' => array(
468 'who_added' => $login_ui['uid'],
469 'who_added_text' => $login_ui['username'],
470 'url' => rg_base_url()
471 . rg_re_bugpage($login_ui, $ri['name'], $data['bug_id']),
459 'who_added' => $ui_login['uid'],
460 'who_added_text' => $ui_login['username'],
461 'url' => rg_base_url($db, '', '')
462 . rg_re_bugpage($ui_login, $ri['name'], $data['bug_id']),
472 463 'assigned_to_text' => $assigned_to_text, 'assigned_to_text' => $assigned_to_text,
473 464 'state_text' => rg_bug_state($data['state']))); 'state_text' => rg_bug_state($data['state'])));
474 465 $event = rg_array_merge($event, 'bug', $data); $event = rg_array_merge($event, 'bug', $data);
 
... ... function rg_bug_list_query($db, $sql, $params)
583 574 break; break;
584 575 } }
585 576
586 rg_log("DEBUG: list_query return " . rg_array2string($ret));
577 rg_log_debug('list_query return ' . rg_array2string($ret));
587 578 rg_log_exit(); rg_log_exit();
588 579 rg_prof_end("bug_list_query"); rg_prof_end("bug_list_query");
589 580 return $ret; return $ret;
 
... ... function rg_bug_search_save($db, $repo_id, $uid, $q)
752 743
753 744 // We will not overwrite somebody else's search // We will not overwrite somebody else's search
754 745 // TODO: race? // TODO: race?
755 rg_log("DEBUG: old: " . rg_array2string($old));
746 rg_log_debug('old: ' . rg_array2string($old));
756 747 $params = array("repo_id" => $repo_id, $params = array("repo_id" => $repo_id,
757 748 "uid" => $uid, "uid" => $uid,
758 749 "name" => $name, "name" => $name,
 
... ... function rg_bug_note_add($db, $repo_id, $bug_id, $login_uid, $data)
938 929 $ret = FALSE; $ret = FALSE;
939 930 while (1) { while (1) {
940 931 $itime = time(); $itime = time();
941 $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : "?";
942 932
943 933 $params = array("repo_id" => $repo_id, $params = array("repo_id" => $repo_id,
944 934 "bug_id" => $bug_id, "bug_id" => $bug_id,
945 935 "itime" => $itime, "itime" => $itime,
946 936 "uid" => $login_uid, "uid" => $login_uid,
947 "ip" => $ip,
937 'ip' => rg_ip(),
948 938 "note" => $data['note']); "note" => $data['note']);
949 939 $sql = "INSERT INTO bug_notes (repo_id, bug_id, itime, uid, ip" $sql = "INSERT INTO bug_notes (repo_id, bug_id, itime, uid, ip"
950 940 . ", note)" . ", note)"
 
... ... function rg_bug_note_add($db, $repo_id, $bug_id, $login_uid, $data)
958 948 rg_sql_free_result($res); rg_sql_free_result($res);
959 949
960 950 $_ri = rg_repo_info($db, $repo_id, 0, ""); $_ri = rg_repo_info($db, $repo_id, 0, "");
961 rg_log_ml("DEBUG: _ri: " . print_r($_ri, TRUE));
951 rg_log_debug('_ri: ' . print_r($_ri, TRUE));
962 952 if ($_ri['exists'] != 1) { if ($_ri['exists'] != 1) {
963 953 rg_bug_set_error("cannot lookup repo" rg_bug_set_error("cannot lookup repo"
964 954 . " (" . rg_repo_error() . ")"); . " (" . rg_repo_error() . ")");
 
... ... function rg_bug_note_add($db, $repo_id, $bug_id, $login_uid, $data)
979 969 $event = array( $event = array(
980 970 'category' => 'bug_event_note_add_all', 'category' => 'bug_event_note_add_all',
981 971 'prio' => 200, 'prio' => 200,
982 'ui' => $_ui,
972 'ui_login' => $_ui,
983 973 'bug' => array( 'bug' => array(
984 974 'bug_id' => $bug_id, 'bug_id' => $bug_id,
985 975 'title' => $_bi['title'], 'title' => $_bi['title'],
986 'url' => rg_base_url()
976 'url' => rg_base_url($db, '', '')
987 977 . rg_re_bugpage($_ui, $_ri['name'], $bug_id) . rg_re_bugpage($_ui, $_ri['name'], $bug_id)
988 978 ), ),
989 979 'ri' => array( 'ri' => array(
 
... ... function rg_bug_label_string2array($s)
1074 1064 $ret = array(); $ret = array();
1075 1065
1076 1066 $s = preg_replace('/[\r\n\t ]/u', ',', $s); $s = preg_replace('/[\r\n\t ]/u', ',', $s);
1077 rg_log("DEBUG: s=[$s]");
1067 rg_log_debug('s=[' . $s . ']');
1078 1068 $list = explode(",", $s); $list = explode(",", $s);
1079 rg_log("DEBUG: list: " . rg_array2string($list));
1069 rg_log_debug('list: ' . rg_array2string($list));
1080 1070 if (empty($list)) if (empty($list))
1081 1071 return array(); return array();
1082 1072
 
... ... function rg_bug_label_insert($db, $repo_id, $bug_id, $labels)
1159 1149 $ret = FALSE; $ret = FALSE;
1160 1150 while (1) { while (1) {
1161 1151 $labels = rg_bug_label_string2array($labels); $labels = rg_bug_label_string2array($labels);
1162 rg_log("DEBUG: labels: " . rg_array2string($labels));
1152 rg_log_debug('labels: ' . rg_array2string($labels));
1163 1153 if (empty($labels)) { if (empty($labels)) {
1164 1154 $ret = TRUE; $ret = TRUE;
1165 1155 break; break;
1166 1156 } }
1167 1157
1168 1158 $existing = rg_bug_label_get($db, $repo_id, $bug_id); $existing = rg_bug_label_get($db, $repo_id, $bug_id);
1169 rg_log("DEBUG: existing: " . rg_array2string($existing));
1159 rg_log_debug('existing: ' . rg_array2string($existing));
1170 1160 if ($existing === FALSE) if ($existing === FALSE)
1171 1161 break; break;
1172 1162
1173 1163 $diff = rg_bug_label_diff($labels, $existing); $diff = rg_bug_label_diff($labels, $existing);
1174 rg_log("DEBUG: diff: " . rg_array2string($diff));
1164 rg_log_debug('diff: ' . rg_array2string($diff));
1175 1165 if (empty($diff)) { if (empty($diff)) {
1176 1166 $ret = TRUE; $ret = TRUE;
1177 1167 break; break;
 
... ... function rg_bug_label_html($db, $labels)
1230 1220 function rg_bug_edit_high_level($db, &$rg) function rg_bug_edit_high_level($db, &$rg)
1231 1221 { {
1232 1222 rg_log_enter("rg_bug_edit_high_level"); rg_log_enter("rg_bug_edit_high_level");
1233 rg_log_ml("DEBUG: rg: " . print_r($rg, TRUE));
1223 rg_log_debug('rg: ' . print_r($rg, TRUE));
1234 1224
1235 1225 $ret = ""; $ret = "";
1236 1226
1237 1227 $errmsg = array(); $errmsg = array();
1238 1228 $show_form = FALSE; $show_form = FALSE;
1239 1229 while (1) { while (1) {
1240 $x = array();
1241 $x['obj_id'] = $rg['ri']['repo_id'];
1242 $x['type'] = 'repo';
1243 $x['owner'] = $rg['ri']['uid'];
1244 $x['uid'] = $rg['login_ui']['uid'];
1245 $x['username'] = $rg['login_ui']['username'];
1246 $x['needed_rights'] = 'B';
1247 $x['ip'] = $rg['ip'];
1248 $x['misc'] = '';
1249 if (rg_rights_allow($db, $x) !== TRUE) {
1230 $obj_id = $rg['ri']['repo_id'];
1231 if (rg_rights_allow2($db, 'repo', $obj_id, 'B', '') !== TRUE) {
1250 1232 $ret .= rg_template("repo/bug/deny_edit.html", $rg, TRUE /* xss */); $ret .= rg_template("repo/bug/deny_edit.html", $rg, TRUE /* xss */);
1251 1233 break; break;
1252 1234 } }
 
... ... function rg_bug_edit_high_level($db, &$rg)
1271 1253 break; break;
1272 1254 } }
1273 1255
1274 $bug_id = rg_bug_edit($db, $rg['login_ui'], $rg['ri'],
1275 $rg['bug']);
1256 $ui_login = rg_ui_login();
1257 $bug_id = rg_bug_edit($db, $ui_login, $rg['ri'], $rg['bug']);
1276 1258 if ($bug_id === FALSE) { if ($bug_id === FALSE) {
1277 1259 $errmsg[] = rg_bug_error(); $errmsg[] = rg_bug_error();
1278 1260 break; break;
1279 1261 } }
1280 1262 $rg['bug']['bug_id'] = $bug_id; $rg['bug']['bug_id'] = $bug_id;
1281 1263
1282 $url = rg_re_bugpage($rg['page_ui'], $rg['ri']['name'], $bug_id);
1264 $ui_page = rg_ui_page();
1265 $url = rg_re_bugpage($ui_page, $rg['ri']['name'], $bug_id);
1283 1266 rg_redirect($url); rg_redirect($url);
1284 1267
1285 1268 $show_form = FALSE; $show_form = FALSE;
File inc/builder.inc.php changed (mode: 100644) (index 865fa79..6c170da)
... ... function rg_builder_load_jobs($db, $where, $order, $limit)
47 47 /* /*
48 48 * Add a build job in queue * Add a build job in queue
49 49 */ */
50 function rg_builder_add($db, $repo_id, $d)
50 function rg_builder_add($db, $repo_id, $prio, $d)
51 51 { {
52 rg_log_ml('builder_add: ' . print_r($d, TRUE));
52 //rg_log_ml('builder_add: ' . print_r($d, TRUE));
53 53
54 54 $ret = array('ok' => 0); $ret = array('ok' => 0);
55 55 while (1) { while (1) {
56 56 $params = array( $params = array(
57 57 'repo_id' => $repo_id, 'repo_id' => $repo_id,
58 'prio' => 10, // TODO
58 'prio' => $prio,
59 59 'itime' => time(), 'itime' => time(),
60 60 'request' => rg_serialize($d), 'request' => rg_serialize($d),
61 61 'done' => 0, 'done' => 0,
 
... ... function rg_builder_vm_list()
102 102 function rg_builder_done($db, $job, $s) function rg_builder_done($db, $job, $s)
103 103 { {
104 104 rg_log_enter('builder_done'); rg_log_enter('builder_done');
105 //rg_log_ml('DEBUG: builder_done: job: ' . print_r($job, TRUE));
106 //rg_log_ml('DEBUG: builder_done: status: ' . print_r($s, TRUE));
105 //rg_log_debug('builder_done: job: ' . print_r($job, TRUE));
106 //rg_log_debug('builder_done: status: ' . print_r($s, TRUE));
107 107
108 108 // old way // old way
109 109 $req = isset($job['request']) ? $job['request'] : $job; $req = isset($job['request']) ? $job['request'] : $job;
 
... ... function rg_builder_done($db, $job, $s)
112 112
113 113 $ret = FALSE; $ret = FALSE;
114 114 $rollback = FALSE; $rollback = FALSE;
115 while (1) {
115 do {
116 116 $res = rg_sql_begin($db); $res = rg_sql_begin($db);
117 117 if ($res === FALSE) if ($res === FALSE)
118 118 break; break;
119
120 119 $rollback = TRUE; $rollback = TRUE;
121 120
122 121 $labels = $s['labels']; $labels = $s['labels'];
123 122
124 123 // Some cosmetic stuff // Some cosmetic stuff
125 124 $env = $req['env']; $env = $req['env'];
126 $labels[] = 'worker_elap/' . ($s['done'] - $s['start']) . 's';
125 // TODO: sometimes, done is not present
126 if (isset($s['done']))
127 $labels[] = 'worker_elap/' . ($s['done'] - $s['start']) . 's';
127 128 $labels[] = 'wait_time/' . ($job['worker_sent'] - $job['itime']) . 's'; $labels[] = 'wait_time/' . ($job['worker_sent'] - $job['itime']) . 's';
128 129 $labels[] = 'date/' . gmdate('Y-m-d', $job['itime']); $labels[] = 'date/' . gmdate('Y-m-d', $job['itime']);
129 130 $labels[] = 'time/' . gmdate('H:i', $job['itime']); $labels[] = 'time/' . gmdate('H:i', $job['itime']);
130 131
131 // add labels to the commit
132 $params = array(
133 'repo_id' => $job['repo_id'],
134 'head' => $req['head'],
135 'type' => 'build',
136 'misc' => $env,
137 'labels' => rg_serialize($labels),
138 'itime' => time()
139 );
140 $sql = 'DELETE FROM commit_labels'
141 . ' WHERE repo_id = @@repo_id@@'
142 . ' AND type = @@type@@'
143 . ' AND misc = @@misc@@'
144 . ' AND head = @@head@@';
145 $res = rg_sql_query_params($db, $sql, $params);
146 if ($res === FALSE)
147 break;
148 rg_sql_free_result($res);
149
150 $sql = 'INSERT INTO commit_labels (repo_id, head, type, misc'
151 . ', labels, itime)'
152 . ' VALUES (@@repo_id@@, @@head@@, @@type@@'
153 . ', @@misc@@, @@labels@@, @@itime@@)';
154 $res = rg_sql_query_params($db, $sql, $params);
155 if ($res === FALSE)
156 break;
157 rg_sql_free_result($res);
158 rg_cache_unset('repo_commit_labels' . '::' . $job['repo_id']
159 . '::' . $req['head'], RG_SOCKET_NO_WAIT);
132 if (!empty($req['head'])) {
133 // add labels to the commit
134 $params = array(
135 'repo_id' => $job['repo_id'],
136 'head' => $req['head'],
137 'type' => 'build',
138 'misc' => $env,
139 'labels' => rg_serialize($labels),
140 'itime' => time()
141 );
142 $sql = 'DELETE FROM commit_labels'
143 . ' WHERE repo_id = @@repo_id@@'
144 . ' AND type = @@type@@'
145 . ' AND misc = @@misc@@'
146 . ' AND head = @@head@@';
147 $res = rg_sql_query_params($db, $sql, $params);
148 if ($res === FALSE)
149 break;
150 rg_sql_free_result($res);
151
152 $sql = 'INSERT INTO commit_labels (repo_id, head, type, misc'
153 . ', labels, itime)'
154 . ' VALUES (@@repo_id@@, @@head@@, @@type@@'
155 . ', @@misc@@, @@labels@@, @@itime@@)';
156 $res = rg_sql_query_params($db, $sql, $params);
157 if ($res === FALSE)
158 break;
159 rg_sql_free_result($res);
160 rg_cache_unset('repo_commit_labels' . '::' . $job['repo_id']
161 . '::' . $req['head'], RG_SOCKET_NO_WAIT);
162 }
160 163
161 164 $params = array( $params = array(
162 165 'id' => $job['id'], 'id' => $job['id'],
 
... ... function rg_builder_done($db, $job, $s)
174 177 $ev = array( $ev = array(
175 178 'category' => 'wh_build_job_done', 'category' => 'wh_build_job_done',
176 179 'prio' => 100, 'prio' => 100,
177 'ui' => array('uid' => $req['uid']),
180 'uid' => $req['uid'],
178 181 'job' => $job, 'job' => $job,
179 182 'status' => $s 'status' => $s
180 183 ); );
 
... ... function rg_builder_done($db, $job, $s)
188 191 $res = rg_sql_commit($db); $res = rg_sql_commit($db);
189 192 if ($res === FALSE) if ($res === FALSE)
190 193 break; break;
191
192 194 $rollback = FALSE; $rollback = FALSE;
193 195
194 $key = 'wh' . '::' . $req['uid'] . '::' . 'list'
195 . '::' . $req['hook_id'];
196 unset($params['id']);
197 rg_cache_merge($key, $params, RG_SOCKET_NO_WAIT);
196 if (!empty($req['hook_id'])) {
197 $key = 'wh' . '::' . $req['uid'] . '::' . 'list'
198 . '::' . $req['hook_id'];
199 unset($params['id']);
200 rg_cache_merge($key, $params, RG_SOCKET_NO_WAIT);
201 }
198 202
199 203 rg_event_signal_daemon('', 0); rg_event_signal_daemon('', 0);
200 204
201 205 $ret = TRUE; $ret = TRUE;
202 break;
203 }
204
206 } while (0);
205 207 if ($rollback) if ($rollback)
206 208 rg_sql_rollback($db); rg_sql_rollback($db);
207 209
 
... ... function rg_builder_done($db, $job, $s)
214 216 */ */
215 217 function rg_builder_nice_status(&$a) function rg_builder_nice_status(&$a)
216 218 { {
217 rg_log_ml('DEBUG: nice_status: a: ' . print_r($a, TRUE));
219 rg_log_debug('nice_status: a: ' . print_r($a, TRUE));
218 220 $a['start_nice'] = gmdate('Y-m-d H:i', intval($a['start'])); $a['start_nice'] = gmdate('Y-m-d H:i', intval($a['start']));
219 221 $a['net_ok_nice'] = gmdate('Y-m-d H:i', intval($a['net_ok'])); $a['net_ok_nice'] = gmdate('Y-m-d H:i', intval($a['net_ok']));
220 222 $a['pkgs_ok_nice'] = gmdate('Y-m-d H:i', intval($a['pkgs_ok'])); $a['pkgs_ok_nice'] = gmdate('Y-m-d H:i', intval($a['pkgs_ok']));
 
... ... function rg_builder_nice_status(&$a)
253 255 */ */
254 256 function rg_builder_cosmetic($db, &$row) function rg_builder_cosmetic($db, &$row)
255 257 { {
256 rg_log_ml('DEBUG: builder_cosmetic: ' . print_r($row, TRUE));
258 rg_log_debug('builder_cosmetic: ' . print_r($row, TRUE));
257 259
258 260 if (isset($row['itime'])) if (isset($row['itime']))
259 261 $row['itime_nice'] = gmdate('Y-m-d H:i', $row['itime']); $row['itime_nice'] = gmdate('Y-m-d H:i', $row['itime']);
 
... ... function rg_builder_list_high_level($db, $rg, $op, $paras)
291 293 $errmsg = array(); $errmsg = array();
292 294 $rg['HTML:status'] = ''; $rg['HTML:status'] = '';
293 295
294 if ($rg['login_ui']['is_admin'] == 1)
296 $ui_login = rg_ui_login();
297 if ($ui_login['is_admin'] == 1)
295 298 $where = '1 = 1'; $where = '1 = 1';
296 299 else else
297 300 $where = 'repo_id IN (SELECT repo_id FROM repos' $where = 'repo_id IN (SELECT repo_id FROM repos'
298 . ' WHERE uid = ' . $rg['login_ui']['uid'] . ')';
301 . ' WHERE uid = ' . $ui_login['uid'] . ')';
299 302
300 303 if (strcmp($op, 'queue') == 0) if (strcmp($op, 'queue') == 0)
301 304 $where .= ' AND done = 0'; $where .= ' AND done = 0';
 
... ... function rg_builder_list_high_level($db, $rg, $op, $paras)
327 330 $d[] = $i; $d[] = $i;
328 331 } }
329 332
330 rg_log_ml('DEBUG: d: ' . print_r($d, TRUE));
333 rg_log_debug('d: ' . print_r($d, TRUE));
331 334 return rg_template_table('builder/queue', $d, $rg); return rg_template_table('builder/queue', $d, $rg);
332 335 } }
333 336
File inc/cache.inc.php changed (mode: 100644) (index e2e4d75..6c7e591)
... ... function rg_cache_core_unset($ns_var)
215 215 } }
216 216
217 217 if (isset($tree[$var])) { if (isset($tree[$var])) {
218 if ($rg_cache_debug)
219 rg_log('cache_core_unset(' . $ns_var . ')');
220 218 unset($tree[$var]); unset($tree[$var]);
221 219 return TRUE; return TRUE;
222 220 } }
 
... ... function rg_cache_send($cmd, $para, $flags)
416 414 $id = intval($t[1]); $id = intval($t[1]);
417 415 if ($id < $rg_cache_count) { if ($id < $rg_cache_count) {
418 416 if ($rg_cache_debug) if ($rg_cache_debug)
419 rg_log('DEBUG: id: ' . $id . ' < ' . $rg_cache_count);
417 rg_log_debug('id: ' . $id . ' < ' . $rg_cache_count);
420 418 continue; continue;
421 419 } }
422 420 //if ($rg_cache_debug) //if ($rg_cache_debug)
423 // rg_log('DEBUG: id: ' . $id . ' == ' . $rg_cache_count);
421 // rg_log_debug('id: ' . $id . ' == ' . $rg_cache_count);
424 422
425 423 if (strcmp($status, 'OK') != 0) { if (strcmp($status, 'OK') != 0) {
426 //rg_log('DEBUG: not an OK answer: ' . $status);
424 //rg_log_debug('not an OK answer: ' . $status);
427 425 return FALSE; return FALSE;
428 426 } }
429 427
 
... ... function rg_cache_get($ns_var)
446 444 rg_prof_start('cache_get'); rg_prof_start('cache_get');
447 445
448 446 $ret = FALSE; $ret = FALSE;
449 while (1) {
447 do {
450 448 $k = rg_cache_prepare_key($ns_var); $k = rg_cache_prepare_key($ns_var);
451 449 $ret = rg_cache_core_get($k); $ret = rg_cache_core_get($k);
452 450 if ($ret !== FALSE) if ($ret !== FALSE)
 
... ... function rg_cache_get($ns_var)
464 462 break; break;
465 463 } }
466 464
467 rg_cache_core_set($ns_var, $ret);
468 break;
469 }
465 if ($rg_cache_debug)
466 rg_log('cache_get[' . $ns_var . '] returns: '
467 . ($ret === FALSE ? 'FALSE' : rg_array2string($ret)));
470 468
471 if ($rg_cache_debug)
472 rg_log('cache_get[' . $ns_var . '] returns: '
473 . ($ret === FALSE ? 'FALSE' : rg_array2string($ret)));
469 rg_cache_core_set($ns_var, $ret);
470 } while (0);
474 471
475 472 rg_prof_end('cache_get'); rg_prof_end('cache_get');
476 473 return $ret; return $ret;
 
... ... function rg_cache_sleep()
618 615 return TRUE; return TRUE;
619 616 } }
620 617
621 ?>
File inc/conn.inc.php changed (mode: 100644) (index 0a75cda..4ac2d5b)
... ... function rg_conn_shutdown($key, $what)
26 26 if (!is_resource($rg_conns[$key]['socket'])) if (!is_resource($rg_conns[$key]['socket']))
27 27 return; return;
28 28
29 if (($what == 0) || ($what == 2))
30 $rg_conns[$key]['shutdow_read'] = 1;
31
32 if (($what == 1) || ($what == 2))
33 $rg_conns[$key]['shutdow_write'] = 1;
34
29 35 @socket_shutdown($rg_conns[$key]['socket'], $what); @socket_shutdown($rg_conns[$key]['socket'], $what);
30 36 rg_log($key . ': shutdown ' . $what); rg_log($key . ': shutdown ' . $what);
31 37 } }
 
... ... function rg_conn_enq($key, $buf)
105 111 global $rg_events; global $rg_events;
106 112
107 113 $s = &$rg_conns[$key]; $s = &$rg_conns[$key];
114
115 if ($s['shutdown_write'] == 1) {
116 rg_log($key . ': cannot enq because we called shutdown(write)');
117 return;
118 }
108 119 $s['send'] .= $buf; $s['send'] .= $buf;
109 120 $rg_events['w'][$key] = $s['socket']; $rg_events['w'][$key] = $s['socket'];
110 121 } }
 
... ... function rg_conn_send($key)
136 147 if (empty($s['send'])) if (empty($s['send']))
137 148 unset($rg_events['w'][$key]); unset($rg_events['w'][$key]);
138 149
150 $s['bytes_sent'] += $r;
151
139 152 return $r; return $r;
140 153 } }
141 154
 
... ... function rg_conn_recv($key)
169 182 return; return;
170 183 } }
171 184
172 $r = @socket_recv($s['socket'], $buf, 4096, 0);
185 $r = @socket_recv($s['socket'], $buf, 16 * 4096, 0);
173 186 if ($r === FALSE) { if ($r === FALSE) {
174 187 rg_log($key . ': cannot receive: ' rg_log($key . ': cannot receive: '
175 188 . socket_strerror(socket_last_error())); . socket_strerror(socket_last_error()));
 
... ... function rg_conn_recv($key)
189 202
190 203 $used = $s['func_data']($key, $s['recv']); $used = $s['func_data']($key, $s['recv']);
191 204 $s['recv'] = substr($s['recv'], $used); $s['recv'] = substr($s['recv'], $used);
205 $s['bytes_recv'] += $r;
192 206 return; return;
193 207 } }
194 208
File inc/demo.inc.php changed (mode: 100644) (index f86d76e..12a421e)
... ... function rg_demo_list()
15 15 if ($r === FALSE) if ($r === FALSE)
16 16 return $ret; return $ret;
17 17
18 rg_log_ml('DEBUG: list: ' . print_r($r, TRUE));
18 rg_log_debug('list: ' . print_r($r, TRUE));
19 19
20 20 return $ret; return $ret;
21 21 } }
 
... ... function rg_demo_load($name)
48 48 return $ret; return $ret;
49 49 } }
50 50
51 rg_log_ml('DEBUG: demo dir: ' . print_r($r, TRUE));
51 rg_log_debug('demo dir: ' . print_r($r, TRUE));
52 52
53 53 return $r; return $r;
54 54 } }
 
... ... function rg_demo($rg, $paras)
97 97 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
98 98 } }
99 99
100 rg_log_ml('DEBUG: pi: ' . print_r($pi, TRUE));
100 rg_log_debug('pi: ' . print_r($pi, TRUE));
101 101 foreach ($pi as $k => $v) foreach ($pi as $k => $v)
102 102 $rg['demo'][$k] = $v; $rg['demo'][$k] = $v;
103 103
 
... ... function rg_demo($rg, $paras)
129 129 $rg_demos = array( $rg_demos = array(
130 130 'ci-1' => array( 'ci-1' => array(
131 131 array( array(
132 'page' => '0',
133 132 'prev' => '', 'prev' => '',
133 'page' => '0',
134 134 'next' => 'about' 'next' => 'about'
135 135 ), ),
136 136 array( array(
137 'page' => 'about',
138 137 'prev' => '0', 'prev' => '0',
138 'page' => 'about',
139 139 'next' => 'add_hook' 'next' => 'add_hook'
140 140 ), ),
141 141 array( array(
142 'page' => 'add_hook',
143 142 'prev' => 'about', 'prev' => 'about',
143 'page' => 'add_hook',
144 144 'next' => 'trigger' 'next' => 'trigger'
145 145 ), ),
146 146 array( array(
147 'page' => 'trigger',
148 147 'prev' => 'add_hook', 'prev' => 'add_hook',
148 'page' => 'trigger',
149 149 'next' => 'python1' 'next' => 'python1'
150 150 ), ),
151 151 array( array(
152 'page' => 'python1',
153 152 'prev' => 'trigger', 'prev' => 'trigger',
153 'page' => 'python1',
154 154 'next' => '' 'next' => ''
155 155 ) )
156 156 ), ),
157 157 'config' => array( 'config' => array(
158 158 array( array(
159 'page' => '0',
160 159 'prev' => '', 'prev' => '',
160 'page' => '0',
161 161 'next' => 'openssh' 'next' => 'openssh'
162 162 ), ),
163 163 array( array(
164 'page' => 'openssh',
165 164 'prev' => '0', 'prev' => '0',
165 'page' => 'openssh',
166 166 'next' => '' 'next' => ''
167 167 ) )
168 168 ), ),
169 169 'artifacts' => array( 'artifacts' => array(
170 170 array( array(
171 'page' => '0',
172 171 'prev' => '', 'prev' => '',
172 'page' => '0',
173 173 'next' => 'define' 'next' => 'define'
174 174 ), ),
175 175 array( array(
176 'page' => 'define',
177 176 'prev' => '0', 'prev' => '0',
177 'page' => 'define',
178 178 'next' => 'see' 'next' => 'see'
179 179 ), ),
180 180 array( array(
181 'page' => 'see',
182 181 'prev' => 'define', 'prev' => 'define',
182 'page' => 'see',
183 'next' => 'rights'
184 ),
185 array(
186 'prev' => 'see',
187 'page' => 'rights',
183 188 'next' => 'blendergraph' 'next' => 'blendergraph'
184 189 ), ),
185 190 array( array(
191 'prev' => 'rights',
186 192 'page' => 'blendergraph', 'page' => 'blendergraph',
187 'prev' => 'see',
193 'next' => ''
194 )
195 ),
196 'packages' => array(
197 array(
198 'prev' => '',
199 'page' => '0',
200 'next' => 'create'
201 ),
202 array(
203 'prev' => '0',
204 'page' => 'create',
205 'next' => 'global'
206 ),
207 array(
208 'prev' => 'create',
209 'page' => 'global',
188 210 'next' => '' 'next' => ''
189 211 ) )
190 212 ) )
File inc/dispatch/dispatch.php changed (mode: 100644) (index 394cbaf..e9e8396)
1 1 <?php <?php
2 2 $rg['menu'][$_op] = 1; $rg['menu'][$_op] = 1;
3 3
4 $ui_login = rg_ui_login();
5
4 6 $rg['url_up'] = $rg['url']; $rg['url_up'] = $rg['url'];
5 7 $rg['url'] .= '/' . rawurlencode($_op); $rg['url'] .= '/' . rawurlencode($_op);
6 8 switch ($_op) { switch ($_op) {
 
... ... case 'logout':
14 16 rg_log("Invalid referer"); rg_log("Invalid referer");
15 17
16 18 // Session expired // Session expired
17 if ($rg['login_ui']['uid'] == 0) {
19 if ($ui_login['uid'] == 0) {
18 20 $body .= rg_template("user/logout.html", $rg, TRUE /*xss*/); $body .= rg_template("user/logout.html", $rg, TRUE /*xss*/);
19 21 break; break;
20 22 } }
 
... ... case 'logout':
22 24 if (!rg_token_valid($db, $rg, 'logout', TRUE)) if (!rg_token_valid($db, $rg, 'logout', TRUE))
23 25 break; break;
24 26
25 rg_user_set_last_seen($db, $rg['login_ui']['uid'], time(), $rg['ip']);
27 rg_user_set_last_seen($db, $ui_login['uid'], time(), rg_ip());
26 28
27 if (rg_sess_destroy($db, $rg['sid'], $rg['login_ui'])) {
28 $body .= rg_template("user/logout.html", $rg, TRUE /* xss */);
29 if (rg_sess_destroy($db, $rg['sid'])) {
30 $body .= rg_template('user/logout.html', $rg, TRUE /*xss*/);
29 31 } else { } else {
30 $body .= rg_template("user/logout_err.html", $rg, TRUE /* xss */);
32 $body .= rg_template('user/logout_err.html', $rg, TRUE /*xss*/);
31 33 } }
32 34 break; break;
33 35
 
... ... case 'suggestion':
73 75 break; break;
74 76
75 77 case 'settings': case 'settings':
78 rg_ui_page_set(rg_ui_login());
76 79 include(__DIR__ . '/../user/settings.php'); include(__DIR__ . '/../user/settings.php');
80 rg_ui_page_reset();
77 81 $body .= $_settings; $body .= $_settings;
78 82 break; break;
79 83
 
... ... case 'doc':
142 146 break; break;
143 147
144 148 case 'ask_email_conf': case 'ask_email_conf':
145 $r = rg_user_ask_for_email_confirmation($db, $rg['login_ui']['uid']);
149 $r = rg_user_ask_for_email_confirmation($db, $ui_login);
146 150 if ($r === TRUE) if ($r === TRUE)
147 151 $body .= rg_template('user/email_conf.html', $rg, TRUE /*xss*/); $body .= rg_template('user/email_conf.html', $rg, TRUE /*xss*/);
148 152 else else
149 153 $body .= rg_template('user/email_conf_error.html', $rg, TRUE /*xss*/); $body .= rg_template('user/email_conf_error.html', $rg, TRUE /*xss*/);
150 154 break; break;
151 155
156 case 'pkg_repos': // Link from the footer; show global repos
157 $body .= rg_template('pkg_repos/welcome_begin.html', $rg, TRUE /*xss*/);
158 $body .= rg_packages_repo_page($db, $rg);
159 $body .= rg_template('pkg_repos/welcome_end.html', $rg, TRUE /*xss*/);
160 break;
161
152 162 default: // can be the main page or user page or repo page default: // can be the main page or user page or repo page
153 rg_log("DEBUG:paras=" . rg_array2string($paras));
163 rg_log_debug('paras=' . rg_array2string($paras));
154 164 $type = empty($paras) ? "" : $paras[0]; $type = empty($paras) ? "" : $paras[0];
155 rg_log("DEBUG: type=[$type]");
165 rg_log_debug('type=[' . $type . ']');
156 166 if (strcmp($type, "user") == 0) { if (strcmp($type, "user") == 0) {
157 167 array_shift($paras); array_shift($paras);
158 168 $user = empty($paras) ? "" : array_shift($paras); $user = empty($paras) ? "" : array_shift($paras);
 
... ... default: // can be the main page or user page or repo page
167 177 } }
168 178
169 179 if (!empty($user)) { if (!empty($user)) {
170 rg_log("DEBUG: user=[$user] repo=[$repo]");
180 rg_log_debug('user=[' . $user . '] repo=[' . $repo . ']');
171 181 if (empty($repo)) { if (empty($repo)) {
172 182 include(__DIR__ . '/../user/home-page.php'); include(__DIR__ . '/../user/home-page.php');
173 183 $body .= $_home; $body .= $_home;
File inc/events.inc.php changed (mode: 100644) (index 9b6e6fc..80e12db)
... ... function rg_event_signal_daemon($ev_id, $timeout)
53 53 { {
54 54 global $rg_event_socket; global $rg_event_socket;
55 55
56 if (empty($rg_event_socket)) {
57 rg_log('DEBUG: rg_event_socket is not defined!');
58 return TRUE;
59 }
56 rg_prof_start('event_signal_daemon');
57 rg_log_enter('event_signal_daemon: event_id=[' . $ev_id . ']');
60 58
61 if ($timeout === NULL)
62 $s_timeout = "forever";
63 else if ($timeout === 0)
64 $s_timeout = "no_wait";
65 else
66 $s_timeout = $timeout . "ms";
59 $ret = FALSE;
60 do {
61 if (empty($rg_event_socket)) {
62 rg_log_debug('rg_event_socket is not defined!');
63 break;
64 }
67 65
68 rg_prof_start("event_signal_daemon");
69 rg_log_enter("event_signal_daemon: event_id=[$ev_id] timeout=$s_timeout");
66 if ($timeout === NULL)
67 $s_timeout = "forever";
68 else if ($timeout === 0)
69 $s_timeout = "no_wait";
70 else
71 $s_timeout = $timeout . "ms";
70 72
71 if (empty($ev_id))
72 $buf = "W\n";
73 else
74 $buf = "NOTIFY " . $ev_id . "\n";
73 if (empty($ev_id))
74 $buf = 'W' . "\n";
75 else
76 $buf = 'NOTIFY ' . $ev_id . "\n";
75 77
76 $flags = 0;
77 if ($timeout === 0)
78 $flags |= RG_SOCKET_NO_WAIT;
78 $flags = 0;
79 if ($timeout === 0)
80 $flags |= RG_SOCKET_NO_WAIT;
79 81
80 $r = rg_socket($rg_event_socket, $buf, $timeout, 1, $flags);
82 $ret = rg_socket($rg_event_socket, $buf, $timeout, 1, $flags);
83 } while (0);
81 84
82 85 rg_log_exit(); rg_log_exit();
83 return $r;
86 return $ret;
84 87 } }
85 88
86 89 /* /*
87 90 * Inserts an event * Inserts an event
88 91 * This function is called from all over the place to generate events * This function is called from all over the place to generate events
89 92 */ */
90 function rg_event_add($db, $event)
93 function rg_event_add($db, $ev)
91 94 { {
92 rg_prof_start("event_add");
93 rg_log_enter("event_add: event=" . rg_array2string($event));
95 global $rg_log_sid;
96
97 rg_prof_start('event_add');
98 rg_log_enter('event_add category=' . $ev['category']);
99 //rg_log_debug('ev: ' . print_r($ev, TRUE));
100
101 if (!isset($ev['ui_login']))
102 $ev['ui_login'] = rg_ui_login();
94 103
95 if (!isset($event['ip']))
96 $event['ip'] = rg_var_str('REMOTE_ADDR');
104 if (!isset($ev['ip']))
105 $ev['ip'] = rg_ip();
97 106
98 $event['debug'] = rg_state_get($db, 'debug');
107 if (!isset($ev['log_sid']))
108 $ev['log_sid'] = $rg_log_sid;
109
110 $ev['debug'] = rg_debug();
99 111
100 112 $ret = FALSE; $ret = FALSE;
101 113 while (1) { while (1) {
102 114 $now = time(); $now = time();
103 $prio = $event['prio']; unset($event['prio']);
115 $prio = $ev['prio']; unset($ev['prio']);
104 116 $params = array("now" => $now, $params = array("now" => $now,
105 117 "prio" => $prio, "prio" => $prio,
106 "data" => rg_serialize($event));
118 "data" => rg_serialize($ev));
107 119 $sql = "INSERT INTO events (itime, prio, data)" $sql = "INSERT INTO events (itime, prio, data)"
108 120 . " VALUES (@@now@@, @@prio@@, @@data@@)"; . " VALUES (@@now@@, @@prio@@, @@data@@)";
109 121 $res = rg_sql_query_params($db, $sql, $params); $res = rg_sql_query_params($db, $sql, $params);
 
... ... function rg_event_process($db, $ev_id, $event)
136 148 $ret = FALSE; $ret = FALSE;
137 149 $rollback = FALSE; $rollback = FALSE;
138 150 do { do {
151 rg_debug_set($event['debug']);
152
153 if (isset($event['ui_login']))
154 rg_ui_login_set($event['ui_login']);
155
139 156 $category = $event['category']; $category = $event['category'];
140 157 unset($event['category']); unset($event['category']);
141 158
 
... ... function rg_event_process($db, $ev_id, $event)
163 180 break; break;
164 181 } }
165 182
166 if (empty($evs)) {
167 $ret = TRUE;
168 break;
169 }
170
171 $r = TRUE;
183 $err = FALSE;
172 184 foreach ($evs as $index => $ev) { foreach ($evs as $index => $ev) {
173 185 $r = rg_event_add($db, $ev); $r = rg_event_add($db, $ev);
174 if ($r !== TRUE)
186 if ($r !== TRUE) {
187 $err = TRUE;
175 188 break; break;
189 }
176 190 } }
177 if ($r !== TRUE)
191 if ($err)
178 192 break; break;
179 193
180 194 $r = rg_sql_commit($db); $r = rg_sql_commit($db);
File inc/feedback/suggestion.php changed (mode: 100644) (index ea08caf..23f5a0c)
... ... while (1) {
27 27 break; break;
28 28 } }
29 29
30 $r = rg_user_suggestion($db, $rg['login_ui']['uid'], $suggestion);
30 $ui_login = rg_ui_login();
31 $r = rg_user_suggestion($db, $ui_login['uid'], $suggestion);
31 32 if ($r === FALSE) { if ($r === FALSE) {
32 33 $errmsg[] = "could not add suggestion (" . rg_user_error() . ")!"; $errmsg[] = "could not add suggestion (" . rg_user_error() . ")!";
33 34 break; break;
File inc/fixes.inc.php changed (mode: 100644) (index 7ebf4c0..48d7100)
... ... $rg_fixes[11] = array(
49 49 $rg_fixes[12] = array( $rg_fixes[12] = array(
50 50 'functions' => 'rg_fixes_remove_cr' 'functions' => 'rg_fixes_remove_cr'
51 51 ); );
52 $rg_fixes[13] = array(
53 'functions' => 'rg_fixes_add_global_pkg_repo'
54 );
52 55
53 56 // This must be the last line // This must be the last line
54 57 $rg_fixes_ver = count($rg_fixes); $rg_fixes_ver = count($rg_fixes);
 
... ... function rg_fixes_remove_cr($db)
810 813 return $ret; return $ret;
811 814 } }
812 815
816 function rg_fixes_add_global_pkg_repo($db)
817 {
818 rg_log_enter('fixes_add_global_pkg_repo');
819
820 $ret = FALSE;
821 do {
822 $r = rg_pkg_repo_add_global($db);
823 if ($r === FALSE)
824 break;
825
826 $r = rg_pkg_subrepo_add_global($db);
827 if ($r === FALSE)
828 break;
829
830 $ret = TRUE;
831 } while (0);
832 rg_log_exit();
833 return $ret;
834 }
835
813 836
814 837
815 838 /* /*
 
... ... function rg_fixes_needed($db)
872 895 if ($old === FALSE) if ($old === FALSE)
873 896 break; break;
874 897
875 rg_log("DEBUG: old=$old new=$rg_fixes_ver");
898 rg_log_debug('old=' . $old . ' new=' . $rg_fixes_ver);
876 899 if ($old == $rg_fixes_ver) { if ($old == $rg_fixes_ver) {
877 900 // fixes are up to date // fixes are up to date
878 901 $ret = 0; $ret = 0;
 
... ... function rg_fixes_update($db)
898 921 rg_log_enter("fixes_update"); rg_log_enter("fixes_update");
899 922
900 923 $ret = FALSE; $ret = FALSE;
901 while (1) {
924 do {
902 925 $old = rg_state_get_uint($db, "fixes_version"); $old = rg_state_get_uint($db, "fixes_version");
903 926 if ($old === FALSE) if ($old === FALSE)
904 927 break; break;
 
... ... function rg_fixes_update($db)
908 931 break; break;
909 932 } }
910 933
911 // If we cannot lock, return error
912 if (rg_lock("fixes.lock", 0) === FALSE)
913 break;
914
915 934 $r = rg_fixes_run($db, $old); $r = rg_fixes_run($db, $old);
916 rg_unlock("fixes.lock");
917 if ($r !== TRUE) {
918 rg_internal_error("Cannot apply fixes.");
935 if ($r !== TRUE)
919 936 break; break;
920 }
921 937
922 938 $ret = TRUE; $ret = TRUE;
923 break;
924 }
939 } while (0);
925 940
926 941 rg_log_exit(); rg_log_exit();
927 942 return $ret; return $ret;
File inc/format.inc.php changed (mode: 100644) (index a069c20..7eb899e)
... ... function rg_format_markdown($a)
73 73 $table_started = FALSE; $table_started = FALSE;
74 74 $f = explode("\n", $a); unset($a); $f = explode("\n", $a); unset($a);
75 75 foreach ($f as $i => $line) { foreach ($f as $i => $line) {
76 rg_log('DEBUG: line=' . $line);
76 rg_log_debug('line=' . $line);
77 77
78 78 if (preg_match('/^=+$/u', $line) === 1) { if (preg_match('/^=+$/u', $line) === 1) {
79 79 rg_log('Found a h1 with = sign'); rg_log('Found a h1 with = sign');
 
... ... function rg_format_markdown($a)
98 98 if (($r === FALSE) || !isset($r[1])) if (($r === FALSE) || !isset($r[1]))
99 99 break; break;
100 100
101 rg_log_ml('DEBUG: found a table row: ' . print_r($r, TRUE));
101 rg_log_debug('found a table row: ' . print_r($r, TRUE));
102 102 if ($table_started !== TRUE) { if ($table_started !== TRUE) {
103 rg_log('DEBUG: But table was not started.');
103 rg_log_debug('But table was not started.');
104 104 if ($j == 0) { if ($j == 0) {
105 rg_log('DEBUG: this is first line; ship');
105 rg_log_debug('this is first line; ship');
106 106 break; break;
107 107 } }
108 rg_log('DEBUG: Check previous line [' . $ret[$j - 1] . '] to contain \s|\s');
108 rg_log_debug('Check previous line [' . $ret[$j - 1] . '] to contain \s|\s');
109 109 $r2 = preg_split($p = '/\s*\|\s*/u', $ret[$j - 1]); $r2 = preg_split($p = '/\s*\|\s*/u', $ret[$j - 1]);
110 110 if (($r2 === FALSE) || !isset($r2[1])) if (($r2 === FALSE) || !isset($r2[1]))
111 111 break; break;
112 112
113 rg_log_ml('DEBUG: header match: ' . print_r($r2, TRUE));
113 rg_log_debug('header match: ' . print_r($r2, TRUE));
114 114 rg_log(' DEBUG: Found a table in the previous line!'); rg_log(' DEBUG: Found a table in the previous line!');
115 115 $ret[$j - 1] = '<table>'; $ret[$j - 1] = '<table>';
116 116 $ret[$j++] = '<tr><th>' $ret[$j++] = '<tr><th>'
 
... ... function rg_format_markdown($a)
130 130 continue; continue;
131 131
132 132 if ($table_started) { if ($table_started) {
133 rg_log('DEBUG: we have a normal line but table is in progress; stop table');
133 rg_log_debug('we have a normal line but table is in progress; stop table');
134 134 $ret[$j++] = '</table>'; $ret[$j++] = '</table>';
135 135 $table_started = FALSE; $table_started = FALSE;
136 136 } }
 
... ... function rg_format_markdown($a)
138 138 $ret[$j++] = $line; $ret[$j++] = $line;
139 139 } }
140 140 if ($table_started) { if ($table_started) {
141 rg_log('DEBUG: we have a normal line but table is in progress; stop table');
141 rg_log_debug('we have a normal line but table is in progress; stop table');
142 142 $ret[$j++] = '</table>'; $ret[$j++] = '</table>';
143 143 $table_started = FALSE; $table_started = FALSE;
144 144 } }
File inc/git.inc.php changed (mode: 100644) (index 5a05fbd..d437487)
... ... function rg_git_repo_is_empty($repo_path)
65 65 if (empty($scan)) if (empty($scan))
66 66 return 1; return 1;
67 67
68 rg_log_ml('DEBUG: scan: ' . print_r($scan, TRUE));
68 rg_log_debug('scan: ' . print_r($scan, TRUE));
69 69 return 0; return 0;
70 70 } }
71 71
 
... ... function rg_git_from_to($from, $to)
229 229 global $rg_git_empty; global $rg_git_empty;
230 230
231 231 if (empty($from) && empty($to)) { if (empty($from) && empty($to)) {
232 rg_log('DEBUG: from/to empty');
232 rg_log_debug('from/to empty');
233 233 $from_to = ''; $from_to = '';
234 234 } else if (empty($from)) { } else if (empty($from)) {
235 rg_log('DEBUG: from empty');
235 rg_log_debug('from empty');
236 236 $from_to = $to; $from_to = $to;
237 237 } else if (strcmp($from, $rg_git_zero) == 0) { } else if (strcmp($from, $rg_git_zero) == 0) {
238 rg_log('DEBUG: from zero');
238 rg_log_debug('from zero');
239 239 $from_to = $rg_git_empty . '..' . $to; $from_to = $rg_git_empty . '..' . $to;
240 240 } else if (empty($to)) { } else if (empty($to)) {
241 rg_log('DEBUG: to empty');
241 rg_log_debug('to empty');
242 242 $from_to = $from; $from_to = $from;
243 243 } else { } else {
244 244 $from_to = $from . '..' . $to; $from_to = $from . '..' . $to;
 
... ... function rg_git_load_ref($repo_path, $ref)
612 612 } }
613 613
614 614 $ret = trim($r); $ret = trim($r);
615 rg_log('DEBUG: git_load_ref[' . $ref . ']=' . $ret);
615 rg_log_debug('git_load_ref[' . $ref . ']=' . $ret);
616 616 return $ret; return $ret;
617 617 } }
618 618
 
... ... function rg_git_ls_tree($repo_path, $tree, $path)
830 830 if (empty($line)) if (empty($line))
831 831 break; break;
832 832
833 //rg_log('DEBUG: processing line [' . $line . ']');
833 //rg_log_debug('processing line [' . $line . ']');
834 834 $_y = array(); $_y = array();
835 835 $_t = explode("\t", $line); $_t = explode("\t", $line);
836 836 unset($line); // manually free data unset($line); // manually free data
 
... ... function rg_git_ls_tree($repo_path, $tree, $path)
855 855
856 856 // We are forced to use print_r instead of array2string because // We are forced to use print_r instead of array2string because
857 857 // it may be a multilevel array. // it may be a multilevel array.
858 //rg_log_ml("DEBUG: ls-tree: " . print_r($ret, TRUE));
858 //rg_log_debug('ls-tree: ' . print_r($ret, TRUE));
859 859
860 860 rg_log_exit(); rg_log_exit();
861 861 rg_prof_end("git_ls_tree"); rg_prof_end("git_ls_tree");
 
... ... function rg_git_parse_file_name(&$s)
897 897
898 898 /* From now on, $quoted is TRUE */ /* From now on, $quoted is TRUE */
899 899 if (empty($s)) { if (empty($s)) {
900 rg_log('DEBUG: ret=' . $ret);
900 rg_log_debug('ret=' . $ret);
901 901 rg_git_set_error('unterminated quoted file name'); rg_git_set_error('unterminated quoted file name');
902 902 $ret = FALSE; $ret = FALSE;
903 903 break; break;
 
... ... function rg_git_parse_file_name(&$s)
912 912 } }
913 913
914 914 /* Decoding '\xxx' strings */ /* Decoding '\xxx' strings */
915 //rg_log('DEBUG: s: ' . $s);
915 //rg_log_debug('s: ' . $s);
916 916 if ($rest >= 3) { if ($rest >= 3) {
917 917 $all_digits = TRUE; $all_digits = TRUE;
918 918 $nr = 0; $f = 64; $nr = 0; $f = 64;
 
... ... function rg_git_split_diff_file_names($s)
976 976 } }
977 977
978 978 if ($rg_git_debug > 90) if ($rg_git_debug > 90)
979 rg_log_ml('DEBUG: git_split_diff_file_names: ret: '
979 rg_log_debug('git_split_diff_file_names: ret: '
980 980 . print_r($ret, TRUE)); . print_r($ret, TRUE));
981 981 rg_log_exit(); rg_log_exit();
982 982 return $ret; return $ret;
 
... ... function rg_git_diff2array($diff, &$out)
995 995 rg_prof_start("git_diff2array"); rg_prof_start("git_diff2array");
996 996 rg_log_enter('git_diff2array'); rg_log_enter('git_diff2array');
997 997 if ($rg_git_debug > 90) { if ($rg_git_debug > 90) {
998 rg_log_ml("DEBUG: git_diff2array: diff: " . $diff);
999 rg_log_ml("DEBUG: git_diff2array: out: " . print_r($out, TRUE));
998 rg_log_debug('git_diff2array: diff: ' . $diff);
999 rg_log_debug('git_diff2array: out: ' . print_r($out, TRUE));
1000 1000 } }
1001 1001
1002 1002 $ret = TRUE; $ret = TRUE;
1003 1003 $lines = explode("\n", $diff); $lines = explode("\n", $diff);
1004 1004 //if ($rg_git_debug > 90) { //if ($rg_git_debug > 90) {
1005 // rg_log_ml("DEBUG: lines: " . print_r($lines, TRUE));
1005 // rg_log_debug('lines: ' . print_r($lines, TRUE));
1006 1006 foreach ($lines as $line) { foreach ($lines as $line) {
1007 1007 if ($rg_git_debug > 90) if ($rg_git_debug > 90)
1008 rg_log("DEBUG: line=$line");
1008 rg_log_debug('line=' . $line);
1009 1009
1010 1010 // format: diff --git a/a b/a // format: diff --git a/a b/a
1011 1011 if (strncmp($line, "diff --git ", 11) == 0) { if (strncmp($line, "diff --git ", 11) == 0) {
 
... ... function rg_git_diff2array($diff, &$out)
1029 1029
1030 1030 $file = $a['file']; $file = $a['file'];
1031 1031 if (!isset($out[$file])) { if (!isset($out[$file])) {
1032 rg_log_ml('DEBUG: out: ' . print_r($out, TRUE));
1033 rg_log('DEBUG: line=' . $line);
1032 rg_log_debug('out: ' . print_r($out, TRUE));
1033 rg_log_debug('line=' . $line);
1034 1034 rg_git_set_error('internal error'); rg_git_set_error('internal error');
1035 1035 rg_internal_error('we have a diff for a' rg_internal_error('we have a diff for a'
1036 1036 . ' non-existing file (' . $file . ')'); . ' non-existing file (' . $file . ')');
 
... ... function rg_git_diff2array($diff, &$out)
1114 1114 // parse line "@@ -14,6 +14,8 @@ function..." // parse line "@@ -14,6 +14,8 @@ function..."
1115 1115 // @@ from_file_range to_file_range @@ ... // @@ from_file_range to_file_range @@ ...
1116 1116 if (strncmp($line, "@@", 2) == 0) { if (strncmp($line, "@@", 2) == 0) {
1117 //rg_log("DEBUG: chunks: $line");
1117 //rg_log_debug('chunks: ' . $line);
1118 1118
1119 1119 $_t = explode(" ", $line, 5); $_t = explode(" ", $line, 5);
1120 1120 if (count($_t) < 4) { if (count($_t) < 4) {
1121 rg_log_ml('DEBUG: diff: ' . print_r($diff, TRUE));
1121 rg_log_debug('diff: ' . print_r($diff, TRUE));
1122 1122 rg_internal_error("invalid line [$line]: count < 4"); rg_internal_error("invalid line [$line]: count < 4");
1123 1123 $ret = FALSE; $ret = FALSE;
1124 1124 break; break;
 
... ... function rg_git_log_has_merges($repo_path, $from, $to)
1208 1208 break; break;
1209 1209 } }
1210 1210
1211 $rg_git_debug && rg_log('a:' . print_r($a, TRUE));
1211 $rg_git_debug && rg_log('a:' . rg_array2string($a));
1212 1212 if (empty($a['data'])) { if (empty($a['data'])) {
1213 1213 $ret = 0; $ret = 0;
1214 1214 break; break;
 
... ... function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files,
1321 1321 $ret = array(); $ret = array();
1322 1322 foreach ($blocks as $junk => $block) { foreach ($blocks as $junk => $block) {
1323 1323 if ($rg_git_debug > 90) if ($rg_git_debug > 90)
1324 rg_log_ml('DEBUG: block: ' . print_r($block, TRUE));
1324 rg_log_debug('block: ' . print_r($block, TRUE));
1325 1325
1326 1326 $y = array("vars" => array(), "files" => array()); $y = array("vars" => array(), "files" => array());
1327 1327
 
... ... function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files,
1332 1332 $parts = explode($sep_end, $block, 2); $parts = explode($sep_end, $block, 2);
1333 1333 unset($block); // manually free memory unset($block); // manually free memory
1334 1334 if ($rg_git_debug > 90) if ($rg_git_debug > 90)
1335 rg_log_ml('DEBUG: parts: ' . print_r($parts, TRUE));
1335 rg_log_debug('parts: ' . print_r($parts, TRUE));
1336 1336
1337 1337 // vars // vars
1338 1338 $y['vars']['lines_add'] = 0; $y['vars']['lines_add'] = 0;
 
... ... function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files,
1347 1347 } else if (empty($_t[0])) { } else if (empty($_t[0])) {
1348 1348 // do nothing // do nothing
1349 1349 } else { } else {
1350 //rg_log("DEBUG: Var [" . $_t[0] . "] has no value!");
1350 //rg_log_debug('Var [' . $_t[0] . '] has no value!');
1351 1351 } }
1352 1352 } }
1353 1353 // Some additions // Some additions
 
... ... function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files,
1367 1367 // numstat [+ diff separated by \0\0] // numstat [+ diff separated by \0\0]
1368 1368 $n_d = explode("\0\0", $parts[1]); $n_d = explode("\0\0", $parts[1]);
1369 1369 unset($parts[1]); // manually free data unset($parts[1]); // manually free data
1370 //rg_log_ml('DEBUG: n_d: ' . print_r($n_d, TRUE));
1370 //rg_log_debug('n_d: ' . print_r($n_d, TRUE));
1371 1371
1372 1372 // numstat // numstat
1373 1373 $numstat = explode("\0", trim($n_d[0])); $numstat = explode("\0", trim($n_d[0]));
1374 //rg_log_ml('DEBUG: numstat: ' . print_r($numstat, TRUE));
1374 //rg_log_debug('numstat: ' . print_r($numstat, TRUE));
1375 1375 $tc = count($numstat); $tc = count($numstat);
1376 1376 while ($tc > 0) { while ($tc > 0) {
1377 1377 $a = explode("\t", array_shift($numstat), 3); $tc--; $a = explode("\t", array_shift($numstat), 3); $tc--;
1378 //rg_log_ml('DEBUG: a: ' . print_r($a, TRUE));
1378 //rg_log_debug('a: ' . print_r($a, TRUE));
1379 1379
1380 1380 // We may have an empty commit // We may have an empty commit
1381 1381 if (count($a) == 1) if (count($a) == 1)
 
... ... function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files,
1414 1414 $y['files'][$f]['changes'] = $changes; $y['files'][$f]['changes'] = $changes;
1415 1415
1416 1416 // We will mark over sized diffs for later use // We will mark over sized diffs for later use
1417 //rg_log('DEBUG: File [' . $f . '] '
1417 //rg_log_debug('File [' . $f . '] '
1418 1418 // . $changes . ' changes'); // . $changes . ' changes');
1419 1419 $y['files'][$f]['oversize_diff'] = $y['files'][$f]['oversize_diff'] =
1420 1420 ($changes > $patch_limit) ? 1 : 0; ($changes > $patch_limit) ? 1 : 0;
 
... ... function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files,
1423 1423 $y['vars']['lines_add'] += $y['files'][$f]['lines_add']; $y['vars']['lines_add'] += $y['files'][$f]['lines_add'];
1424 1424 $y['vars']['lines_del'] += $y['files'][$f]['lines_del']; $y['vars']['lines_del'] += $y['files'][$f]['lines_del'];
1425 1425 } }
1426 //rg_log_ml('DEBUG: files: ' . print_r($y['files'], TRUE));
1426 //rg_log_debug('files: ' . print_r($y['files'], TRUE));
1427 1427
1428 1428 if ($also_patch === FALSE) { if ($also_patch === FALSE) {
1429 1429 $ret[] = $y; $ret[] = $y;
 
... ... function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files,
1443 1443 break; break;
1444 1444 } }
1445 1445
1446 //rg_log_ml('DEBUG: diff2array: ' . print_r($y['files'], TRUE));
1447 //rg_log_ml('DEBUG: y: ' . print_r($y, TRUE));
1446 //rg_log_debug('diff2array: ' . print_r($y['files'], TRUE));
1447 //rg_log_debug('y: ' . print_r($y, TRUE));
1448 1448 $ret[] = $y; $ret[] = $y;
1449 1449 } }
1450 1450 break; break;
1451 1451 } }
1452 1452
1453 1453 if ($rg_git_debug > 90) if ($rg_git_debug > 90)
1454 rg_log_ml('DEBUG: simple: ret: ' . print_r($ret, TRUE));
1454 rg_log_debug('simple: ret: ' . print_r($ret, TRUE));
1455 1455
1456 1456 rg_log_exit(); rg_log_exit();
1457 1457 rg_prof_end('git_log_simple'); rg_prof_end('git_log_simple');
 
... ... function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files,
1460 1460
1461 1461 /* /*
1462 1462 * Works on git_log (without patch) output to detect big diffs. * Works on git_log (without patch) output to detect big diffs.
1463 * Returns an array with all the info needed to prepare a 'git log'.
1464 * Will return an empty array if normal log should be called.
1463 * Returns an array with all the info needed to prepare a new 'git log'.
1464 * Will return an empty array if normal log can be called.
1465 * It returns contiguous ranges of good commits and separate bad commits, with what files are good.
1465 1466 */ */
1466 function rg_git_log_detect_big_diff($stat, $from)
1467 function rg_git_log_detect_big_diff($stat)
1467 1468 { {
1468 rg_log_enter('git_log_detect_big_diff from=' . $from);
1469 global $rg_git_debug;
1469 1470
1470 //rg_log_ml('DEBUG: stat: ' . print_r($stat, TRUE));
1471 rg_log_enter('git_log_detect_big_diff');
1471 1472
1472 $ret = array();
1473 $pos = 0;
1474 $last_was_good = 2; // 2 = not good or bad
1475 $ret[0] = array('from' => $from);
1473 if ($rg_git_debug > 90)
1474 rg_log_debug('input(stat): ' . print_r($stat, TRUE));
1476 1475
1476 $ret = array();
1477 1477 $at_least_one_bad = FALSE; $at_least_one_bad = FALSE;
1478 1478 foreach ($stat as $junk => $per_commit) { foreach ($stat as $junk => $per_commit) {
1479 1479 $hash = $per_commit['vars']['sha1']; $hash = $per_commit['vars']['sha1'];
1480 1480
1481 1481 $good_files = array(); $good_files = array();
1482 $we_have_bad_files = FALSE;
1482 $cur = 'good';
1483 1483 foreach ($per_commit['files'] as $fname => $i) { foreach ($per_commit['files'] as $fname => $i) {
1484 1484 if ($i['oversize_diff']) { if ($i['oversize_diff']) {
1485 $we_have_bad_files = TRUE;
1485 $cur = 'bad';
1486 1486 $at_least_one_bad = TRUE; $at_least_one_bad = TRUE;
1487 1487 } else { } else {
1488 1488 $good_files[] = $fname; $good_files[] = $fname;
1489 1489 } }
1490 1490 } }
1491 if ($we_have_bad_files === FALSE)
1492 $good_files = array(); // = all
1493 1491
1494 //rg_log_enter('DEBUG: hash ' . $hash);
1495 //rg_log('DEBUG: we_have_bad_files='
1496 // . ($we_have_bad_files ? 'TRUE' : 'FALSE'));
1497 //rg_log('DEBUG: last_was_good=' . $last_was_good);
1498 //rg_log_ml('DEBUG: good_files: ' . print_r($good_files, TRUE));
1499
1500 if ($we_have_bad_files) {
1501 if ($last_was_good < 2) {
1502 rg_log('last_was_good == 0/1');
1503 $ret[$pos]['from'] = $hash;
1504 $ret[$pos]['from_to'] = rg_git_from_to($ret[$pos]['from'], $ret[$pos]['to']);
1505 $pos++;
1506 }
1507
1508 $ret[$pos] = array(
1509 'type' => 'bad',
1510 'from' => '', // we do not need it
1511 'to' => $hash,
1512 'good_files' => $good_files
1513 );
1514 $ret[$pos]['from_to'] = rg_git_from_to($ret[$pos]['from'], $ret[$pos]['to']);
1515 $last_was_good = 0;
1492 if (empty($ret)) {
1493 $pos = 0;
1516 1494 } else { } else {
1517 // we have no bad files
1518 if ($last_was_good == 1) {
1519 rg_log('last_was_good == 1; do nothing');
1520 } else {
1521 if ($last_was_good == 0) {
1522 rg_log('last_was_good == 0');
1523 $ret[$pos]['from'] = $hash;
1524 $ret[$pos]['from_to'] = rg_git_from_to($ret[$pos]['from'], $ret[$pos]['to']);
1525 $pos++;
1526 } else {
1527 rg_log('last_was_good == 2');
1528 }
1495 $last = $ret[$pos]['type'];
1529 1496
1530 $ret[$pos]['type'] = 'good';
1531 $ret[$pos]['to'] = $hash;
1497 if ($rg_git_debug > 90)
1498 rg_log_debug('pos=' . $pos . ' last=' . $last
1499 . ' cur=' . $cur . ' hash='
1500 . substr($ret[$pos]['hash'], 0, 6)
1501 . ' range=' . $ret[$pos]['range']);
1502
1503 if (strcmp($cur, 'good') == 0) {
1504 $ret[$pos]['range']++;
1505 $ret[$pos]['hash'] = $hash;
1506 continue;
1532 1507 } }
1533 $last_was_good = 1;
1508
1509 $pos++;
1534 1510 } }
1535 //rg_log_exit();
1536 }
1537 1511
1538 // We may not had the chance to set 'from'
1539 if (!isset($ret[$pos]['from'])) {
1540 $ret[$pos]['from'] = $from;
1541 $ret[$pos]['from_to'] = rg_git_from_to($ret[$pos]['from'], $ret[$pos]['to']);
1512 $ret[$pos] = array(
1513 'hash' => $hash,
1514 'range' => 1,
1515 'type' => $cur
1516 );
1517
1518 if (strcmp($cur, 'bad') == 0)
1519 $ret[$pos]['good_files'] = $good_files;
1542 1520 } }
1543 //rg_log_ml('DEBUG final (after detect big diff): ' . print_r($ret, TRUE));
1544 1521
1545 1522 // No need to parse the array // No need to parse the array
1546 1523 if ($at_least_one_bad === FALSE) { if ($at_least_one_bad === FALSE) {
1547 rg_log('DEBUG: No big diff detected.');
1524 rg_log_debug('No big diff detected => return empty array');
1548 1525 $ret = array(); $ret = array();
1549 1526 } }
1550 1527
1551 rg_log('DEBUG: Big diff detected.');
1552 1528 rg_log_exit(); rg_log_exit();
1553 1529 return $ret; return $ret;
1554 1530 } }
 
... ... function rg_git_log($repo_path, $max, $from, $to, $also_patch, $patch_limit)
1573 1549 $stat = rg_git_log_simple($repo_path, $max, $from, $to, $stat = rg_git_log_simple($repo_path, $max, $from, $to,
1574 1550 FALSE /*also_patch*/, $good_files, $patch_limit); FALSE /*also_patch*/, $good_files, $patch_limit);
1575 1551 if ($stat === FALSE) { if ($stat === FALSE) {
1576 rg_log('DEBUG: git_log_simple returned FALSE');
1552 rg_log_debug('git_log_simple returned FALSE');
1577 1553 break; break;
1578 1554 } }
1579 1555
 
... ... function rg_git_log($repo_path, $max, $from, $to, $also_patch, $patch_limit)
1585 1561 } }
1586 1562
1587 1563 if ($rg_git_debug > 90) if ($rg_git_debug > 90)
1588 rg_log_ml('DEBUG: stat: ' . print_r($stat, TRUE));
1589 if (empty($from)) {
1590 $from = $stat[0]['vars']['sha1'];
1591 if ($rg_git_debug > 50)
1592 rg_log('DEBUG: overwriting from with ' . $from);
1593 }
1564 rg_log_debug('log_simple returned: stat: ' . print_r($stat, TRUE));
1594 1565
1595 $r = rg_git_log_detect_big_diff($stat, $from);
1566 $r = rg_git_log_detect_big_diff($stat);
1596 1567 if (empty($r)) { // = no big diff if (empty($r)) { // = no big diff
1568 rg_log_debug('No big diff, call git_log_simple and return');
1597 1569 $good_files = array(); // = all $good_files = array(); // = all
1598 1570 $ret = rg_git_log_simple($repo_path, $max, $from, $to, $ret = rg_git_log_simple($repo_path, $max, $from, $to,
1599 1571 $also_patch, $good_files, $patch_limit); $also_patch, $good_files, $patch_limit);
1600 1572 break; break;
1601 1573 } }
1602 1574
1603 foreach ($r as $i) {
1604 rg_log_ml('DEBUG: Generating log for ' . print_r($i, TRUE));
1575 //if ($rg_git_debug > 90)
1576 // rg_log_debug('git_log_detect_big_diff returned ' . count($r) . ' entries');
1577 foreach ($r as $index => $i) {
1578 if ($rg_git_debug > 90)
1579 rg_log_debug('Generating log for index '
1580 . $index . ': ' . print_r($i, TRUE));
1605 1581
1606 1582 if (strcmp($i['type'], 'good') == 0) if (strcmp($i['type'], 'good') == 0)
1607 1583 $_files = array(); $_files = array();
 
... ... function rg_git_log($repo_path, $max, $from, $to, $also_patch, $patch_limit)
1610 1586 else else
1611 1587 continue; continue;
1612 1588
1613 $x = rg_git_log_simple($repo_path, $max,
1614 $i['from'], $i['to'], $also_patch, $_files,
1589 // TODO: do we signal in web that a patch is big?
1590 // TODO: it is not really ok to call 'git log' n times! How to optimize this?
1591 // TODO: maybe join togheter a continuous range of good commits.
1592 // TODO: it is true that this is called only if there are oversized commits.
1593 $x = rg_git_log_simple($repo_path, $i['range'],
1594 '' /*from*/, $i['hash'], $also_patch, $_files,
1615 1595 $patch_limit); $patch_limit);
1616 1596 if ($x === FALSE) { if ($x === FALSE) {
1617 1597 $stat = FALSE; $stat = FALSE;
1618 1598 break; break;
1619 1599 } }
1620 //rg_log_ml('DEBUG: x: ' . print_r($x, TRUE));
1600 //rg_log_debug('x: ' . print_r($x, TRUE));
1621 1601
1622 1602 // Overwrite $stat with the latest info // Overwrite $stat with the latest info
1623 1603 foreach ($x as $hash => $per_hash) { foreach ($x as $hash => $per_hash) {
 
... ... function rg_git_diff($id, $a, $template_file)
1768 1748 global $rg_git_debug; global $rg_git_debug;
1769 1749
1770 1750 rg_prof_start("git_diff"); rg_prof_start("git_diff");
1771 rg_log("DEBUG: git_diff: id=$id a: " . rg_array2string($a));
1751 rg_log_debug('git_diff: id=' . $id . ' a: ' . rg_array2string($a));
1772 1752
1773 1753 $id = rg_xss_safe($id); $id = rg_xss_safe($id);
1774 1754
 
... ... function rg_git_diff($id, $a, $template_file)
1780 1760 // for each file changed // for each file changed
1781 1761 foreach ($a as $fileindex => $finfo) { foreach ($a as $fileindex => $finfo) {
1782 1762 if ($rg_git_debug > 90) if ($rg_git_debug > 90)
1783 rg_log_ml("DEBUG: finfo: " . print_r($finfo, TRUE));
1763 rg_log_debug('finfo: ' . print_r($finfo, TRUE));
1784 1764
1785 1765 $v = rg_visible_string($finfo['file']); $v = rg_visible_string($finfo['file']);
1786 1766 $f = rg_xss_safe($v); $f = rg_xss_safe($v);
 
... ... function rg_git_diff($id, $a, $template_file)
1827 1807
1828 1808 $empty_line = ""; $empty_line = "";
1829 1809 foreach ($finfo['chunks'] as $chunk => $ci) { foreach ($finfo['chunks'] as $chunk => $ci) {
1830 //rg_log_ml("DEBUG: ci: " . print_r($ci, TRUE));
1810 //rg_log_debug('ci: ' . print_r($ci, TRUE));
1831 1811 $ret .= $empty_line; $ret .= $empty_line;
1832 1812 $empty_line = "<tr style=\"border: 1px\"><td colspan=\"4\">&nbsp;</td></tr>\n"; $empty_line = "<tr style=\"border: 1px\"><td colspan=\"4\">&nbsp;</td></tr>\n";
1833 1813 if (!empty($ci['section'])) { if (!empty($ci['section'])) {
 
... ... function rg_git_update_tag($db, $a)
1926 1906 $x['obj_id'] = $a['repo_id']; $x['obj_id'] = $a['repo_id'];
1927 1907 $x['type'] = 'repo_refs'; $x['type'] = 'repo_refs';
1928 1908 $x['owner'] = $a['repo_uid']; $x['owner'] = $a['repo_uid'];
1929 $x['uid'] = $a['login_uid'];
1930 $x['username'] = $a['ui']['username'];
1931 $x['needed_rights'] = '';
1932 $x['ip'] = $a['ip'];
1933 1909 $x['misc'] = $a['refname']; $x['misc'] = $a['refname'];
1934 1910
1935 $history = array('ri' => array(), 'ui' => array());
1911 $history = array('ri' => array(), 'ui_login' => array());
1936 1912 $history['ri']['repo_id'] = $a['repo_id']; $history['ri']['repo_id'] = $a['repo_id'];
1937 $history['ui']['uid'] = $a['login_uid'];
1913 $history['ui_login']['uid'] = $a['login_uid'];
1938 1914
1939 1915 if (strcmp($a['new_rev_type'], "tag") == 0) { // Annotated if (strcmp($a['new_rev_type'], "tag") == 0) { // Annotated
1940 1916 if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create if (strcmp($a['old_rev'], $rg_git_zero) == 0) { // create
 
... ... function rg_git_update_tag($db, $a)
2001 1977 // Not clear when we do not have a namespace. // Not clear when we do not have a namespace.
2002 1978 if (!empty($a['namespace'])) { if (!empty($a['namespace'])) {
2003 1979 // Update the main ref (not a namespace) // Update the main ref (not a namespace)
2004 $reason = $a['ui']['username'] . ' pushed tag ' . $a['refname'];
1980 $reason = $a['ui_login']['username'] . ' pushed tag ' . $a['refname'];
2005 1981 $r = rg_git_update_ref($a['repo_path'], $a['refname'], $r = rg_git_update_ref($a['repo_path'], $a['refname'],
2006 1982 $a['old_rev'], $a['new_rev'], $reason); $a['old_rev'], $a['new_rev'], $reason);
2007 1983 if ($r !== TRUE) { if ($r !== TRUE) {
 
... ... function rg_git_update_branch($db, $a)
2031 2007 $_x['obj_id'] = $a['repo_id']; $_x['obj_id'] = $a['repo_id'];
2032 2008 $_x['type'] = 'repo_refs'; $_x['type'] = 'repo_refs';
2033 2009 $_x['owner'] = $a['repo_uid']; $_x['owner'] = $a['repo_uid'];
2034 $_x['uid'] = $a['login_uid'];
2035 $_x['username'] = $a['ui']['username'];
2036 $_x['needed_rights'] = '';
2037 $_x['ip'] = $a['ip'];
2038 2010 $_x['misc'] = $a['refname']; $_x['misc'] = $a['refname'];
2039 2011
2040 $history = array('ri' => array(), 'ui' => array());
2012 $history = array('ri' => array(), 'ui_login' => array());
2041 2013 $history['ri']['repo_id'] = $a['repo_id']; $history['ri']['repo_id'] = $a['repo_id'];
2042 $history['ui']['uid'] = $a['login_uid'];
2014 $history['ui_login']['uid'] = $a['login_uid'];
2043 2015
2044 2016 if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete if (strcmp($a['new_rev'], $rg_git_zero) == 0) { // delete
2045 2017 $x = $_x; $x = $_x;
 
... ... function rg_git_update_branch($db, $a)
2079 2051 } }
2080 2052
2081 2053 if (strcmp($merge_base, $a['old_rev']) != 0) { if (strcmp($merge_base, $a['old_rev']) != 0) {
2082 rg_log('DEBUG: merge_base=' . $merge_base);
2083 rg_log('DEBUG: merge_base != old_rev [' . $a['old_rev'] . ']');
2054 rg_log_debug('merge_base=' . $merge_base);
2055 rg_log_debug('merge_base != old_rev [' . $a['old_rev'] . ']');
2084 2056 rg_git_fatal($a['refname'] rg_git_fatal($a['refname']
2085 2057 . "\nYou have no rights to do a non fast-forward push;" . "\nYou have no rights to do a non fast-forward push;"
2086 2058 . " Do a merge or re-base before pushing."); . " Do a merge or re-base before pushing.");
 
... ... function rg_git_update_branch($db, $a)
2114 2086 . "\n" . $w); . "\n" . $w);
2115 2087 } }
2116 2088
2117 rg_log_enter('DEBUG: Checking repo_path rights');
2089 rg_log_enter('Checking repo_path rights');
2118 2090 $r = rg_git_files($a['old_rev'], $a['new_rev']); $r = rg_git_files($a['old_rev'], $a['new_rev']);
2119 2091 if ($r === FALSE) if ($r === FALSE)
2120 2092 rg_git_fatal($a['refname'] . "\nInternal error, try again later\n"); rg_git_fatal($a['refname'] . "\nInternal error, try again later\n");
 
... ... function rg_git_update_branch($db, $a)
2177 2149 $ev['prio'] = 50; $ev['prio'] = 50;
2178 2150 $ev['ri'] = array( $ev['ri'] = array(
2179 2151 'repo_id' => $a['repo_id'], 'repo_id' => $a['repo_id'],
2152 'repo_uid' => $a['repo_uid'],
2180 2153 'name' => $a['repo_name'], 'name' => $a['repo_name'],
2181 'url' => rg_base_url() . $a['login_url']
2154 'repo_username' => $a['repo_username'],
2155 'url' => rg_base_url($db, '', '') . $a['login_url']
2182 2156 . '/' . rawurlencode($a['repo_name']) . '/' . rawurlencode($a['repo_name'])
2183 2157 ); );
2184 2158 unset($ev['repo_id']); unset($ev['repo_name']); unset($ev['repo_id']); unset($ev['repo_name']);
 
... ... function rg_git_branches_and_tags($refs, $base_url, $current_ref)
2260 2234 $current = ltrim($current_ref, '/'); $current = ltrim($current_ref, '/');
2261 2235 if (empty($current)) if (empty($current))
2262 2236 $current = 'branch/master'; $current = 'branch/master';
2263 //rg_log("DEBUG: current=[$current]");
2237 //rg_log_debug('DEBUG: current=' . $current);
2264 2238
2265 2239 $_l = array(); $_l = array();
2266 2240 foreach ($refs as $o => $list) { foreach ($refs as $o => $list) {
 
... ... function rg_git_branches_and_tags($refs, $base_url, $current_ref)
2271 2245 // TODO: escape ','! // TODO: escape ','!
2272 2246 $ename = str_replace('/', ',', $name); $ename = str_replace('/', ',', $name);
2273 2247 $name = rg_xss_safe($name); $name = rg_xss_safe($name);
2274 rg_log("DEBUG: compare with [" . $o . "/" . $ename . "]");
2248 rg_log_debug('compare with [' . $o . '/' . $ename . ']');
2275 2249 if (strcmp($current, $o . "/" . $ename) == 0) { if (strcmp($current, $o . "/" . $ename) == 0) {
2276 2250 $add_s = "<b>"; $add_s = "<b>";
2277 2251 $add_e = "</b>"; $add_e = "</b>";
 
... ... function rg_git_branches_and_tags($refs, $base_url, $current_ref)
2295 2269 $ret['HTML:branches_and_tags'] .= "</div>\n"; $ret['HTML:branches_and_tags'] .= "</div>\n";
2296 2270 } }
2297 2271
2298 //rg_log("DEBUG: rg_git_branches_and_tags: ret:" . rg_array2string($ret));
2272 //rg_log_debug('rg_git_branches_and_tags: ret:' . rg_array2string($ret));
2299 2273
2300 2274 rg_log_exit(); rg_log_exit();
2301 2275 return $ret; return $ret;
 
... ... function rg_git_parse_ref(&$paras)
2326 2300 } else if (strcmp($paras[0], 'commit') == 0) { } else if (strcmp($paras[0], 'commit') == 0) {
2327 2301 $ret['ref_type'] = 'commit'; $ret['ref_type'] = 'commit';
2328 2302 $ret['ref_path'] = $paras[1]; $ret['ref_path'] = $paras[1];
2303 $ret['ref_val'] = $paras[1]; // TODO: don't know why this is needed. accessing /source/log/commit needs this
2304 $ret['ref_url'] = 'commit/' . rawurlencode($paras[1]); // TODO: same as above
2329 2305 return $ret; return $ret;
2330 2306 } else { } else {
2331 2307 return $ret; return $ret;
 
... ... function rg_git_diff_tree($tree1, $tree2)
2381 2357 break; break;
2382 2358 } }
2383 2359
2384 //rg_log("DEBUG: diff-tree: " . rg_array2string($ret));
2360 //rg_log_debug('diff-tree: ' . rg_array2string($ret));
2385 2361
2386 2362 rg_log_exit(); rg_log_exit();
2387 2363 rg_prof_end("git_diff_tree"); rg_prof_end("git_diff_tree");
 
... ... function rg_git_log2listing($log, $rg, $commit_table)
2445 2421 } }
2446 2422
2447 2423 foreach ($log as $junk => &$i) { foreach ($log as $junk => &$i) {
2448 //rg_log_ml('DEBUG: i=' . print_r($i, TRUE));
2424 //rg_log_debug('i=' . print_r($i, TRUE));
2449 2425
2450 2426 // Some info about commit // Some info about commit
2451 2427 if (!empty($i['vars']['body'])) if (!empty($i['vars']['body']))
 
... ... function rg_git_log2listing($log, $rg, $commit_table)
2477 2453 $i['HTML:x_stats'] = $r; $i['HTML:x_stats'] = $r;
2478 2454
2479 2455 // diff // diff
2480 //rg_log_ml("DEBUG: i[files]=" . print_r($i['files'], TRUE));
2456 //rg_log_debug('i[files]=' . print_r($i['files'], TRUE));
2481 2457 $r = rg_git_diff($i['vars']['sha1'], $i['files'], $r = rg_git_diff($i['vars']['sha1'], $i['files'],
2482 2458 'repo/diff.html'); 'repo/diff.html');
2483 2459 if ($r === FALSE) if ($r === FALSE)
 
... ... function rg_git_merge_tree($repo_path, $base, $a, $b)
2600 2576 $ret = trim($a['data']); $ret = trim($a['data']);
2601 2577 rg_cache_set($key, $ret, RG_SOCKET_NO_WAIT); rg_cache_set($key, $ret, RG_SOCKET_NO_WAIT);
2602 2578 } }
2603 rg_log_ml('DEBUG: merge-tree: ' . $ret);
2579 rg_log_debug('merge-tree: ' . $ret);
2604 2580 break; break;
2605 2581 } }
2606 2582
 
... ... function rg_git_merge($repo_path, $ref_name, $new, $ff, $msg)
2692 2668 $mb = rg_git_merge_base($repo_path, $ref_name_tmp, $new); $mb = rg_git_merge_base($repo_path, $ref_name_tmp, $new);
2693 2669 if ($mb === FALSE) if ($mb === FALSE)
2694 2670 break; break;
2695 rg_log('DEBUG: merge-base=' . $mb);
2671 rg_log_debug('merge-base=' . $mb);
2696 2672
2697 2673 $cur = rg_git_load_ref($repo_path, $ref_name_tmp); $cur = rg_git_load_ref($repo_path, $ref_name_tmp);
2698 2674 if ($cur === FALSE) if ($cur === FALSE)
2699 2675 break; break;
2700 rg_log('DEBUG: ref_name points to ' . $cur);
2676 rg_log_debug('ref_name points to ' . $cur);
2701 2677
2702 2678 // If repo was empty, we are forced to do a ff // If repo was empty, we are forced to do a ff
2703 2679 if (strcmp($mb, $rg_git_empty) == 0) { if (strcmp($mb, $rg_git_empty) == 0) {
2704 rg_log('DEBUG: merge base is empty, allow fast-forward.');
2680 rg_log_debug('merge base is empty, allow fast-forward.');
2705 2681 $ff = 1; $ff = 1;
2706 2682 } }
2707 2683
2708 2684 if (($ff == 1) && (strcmp($mb, $cur) == 0)) { if (($ff == 1) && (strcmp($mb, $cur) == 0)) {
2709 rg_log('DEBUG: we can do a fast forward...');
2685 rg_log_debug('we can do a fast forward...');
2710 2686 $commit = $new; $commit = $new;
2711 2687 } else { } else {
2712 rg_log('DEBUG: we must not do a fast forward.');
2688 rg_log_debug('we must not do a fast forward');
2713 2689 $e_mb = escapeshellarg($mb); $e_mb = escapeshellarg($mb);
2714 2690 $e_ref_name_tmp = escapeshellarg($ref_name_tmp); $e_ref_name_tmp = escapeshellarg($ref_name_tmp);
2715 2691 $e_new = escapeshellarg($new); $e_new = escapeshellarg($new);
 
... ... function rg_git_band_3($s)
2856 2832 echo rg_git_pack("\x03" . $s); echo rg_git_pack("\x03" . $s);
2857 2833 } }
2858 2834
2859 ?>
File inc/gpg.inc.php changed (mode: 100644) (index 5a7d4fe..a860723)
... ... function rg_gpg_key_gen($user_id)
20 20 { {
21 21 $ret = array('ok' => 0); $ret = array('ok' => 0);
22 22 do { do {
23 $r = rg_lock('gpg_keyring.lock', RG_LOCK_BLOCK);
24 if ($r === FALSE) {
25 $ret['errmsg'] = 'cannot lock';
26 break;
27 }
28
29 $kr = rg_tmp_path('gpg_keyring');
23 // TODO: hd - how to clean it? Take care of on current access! Lock?
24 $hd = rg_tmp_path('gpg', 0);
25 $ehd = escapeshellarg($hd);
26 $kr = rg_tmp_path('gpg-kr-' . rg_id(16), 120);
30 27 $ekr = escapeshellarg($kr); $ekr = escapeshellarg($kr);
31 28 $euser_id = escapeshellarg($user_id); $euser_id = escapeshellarg($user_id);
32 29
30 if (!is_dir($hd)) {
31 $r = @mkdir($hd, 0700);
32 if ($r === FALSE) {
33 $ret['errmsg'] = 'cannot create gpg homedir [' . $hd . ']: '
34 . rg_php_err();
35 break;
36 }
37 }
38
39 $base = 'gpg2'
40 . ' --no-options'
41 . ' --lock-never'
42 . ' --keyring ' . $ekr
43 . ' --no-default-keyring'
44 . ' --homedir ' . $ehd;
45
33 46 $a = array( $a = array(
34 47 'cmds' => array( 'cmds' => array(
35 48 'cmd1' => array( 'cmd1' => array(
36 'cmd' => 'gpg2'
37 . ' --keyring ' . $ekr
49 'cmd' => $base
38 50 . ' --passphrase \'\'' . ' --passphrase \'\''
39 . ' --no-default-keyring'
40 51 . ' --batch' . ' --batch'
41 52 . ' --quick-generate-key' . ' --quick-generate-key'
42 53 . ' ' . $euser_id . ' ' . $euser_id
 
... ... function rg_gpg_key_gen($user_id)
46 57 ); );
47 58 $r = rg_exec2($a); $r = rg_exec2($a);
48 59 if (($r['ok'] != 1) || ($r['cmds']['cmd1']['exitcode'] != 0)) { if (($r['ok'] != 1) || ($r['cmds']['cmd1']['exitcode'] != 0)) {
49 $ret['errmsg'] = $r['cmds']['cmd1']['last_errmsg'];
60 $ret['errmsg'] = 'cannot generate: '
61 . $r['cmds']['cmd1']['last_errmsg']
62 . ' [' . $r['cmds']['cmd1']['err_buf'] . ']';
50 63 break; break;
51 64 } }
52 65
53 66 $a = array( $a = array(
54 67 'cmds' => array( 'cmds' => array(
55 68 'cmd1' => array( 'cmd1' => array(
56 'cmd' => 'gpg2'
57 . ' --keyring ' . $ekr
58 . ' --no-default-keyring'
69 'cmd' => $base
59 70 . ' --export-secret-keys' . ' --export-secret-keys'
60 71 . ' --armour' . ' --armour'
61 72 ) )
 
... ... function rg_gpg_key_gen($user_id)
63 74 ); );
64 75 $r = rg_exec2($a); $r = rg_exec2($a);
65 76 if (($r['ok'] != 1) || ($r['cmds']['cmd1']['exitcode'] != 0)) { if (($r['ok'] != 1) || ($r['cmds']['cmd1']['exitcode'] != 0)) {
66 $ret['errmsg'] = $r['last_errmsg'];
77 $ret['errmsg'] = 'cannot export secret: '
78 . $r['cmds']['cmd1']['last_errmsg']
79 . ' [' . $r['cmds']['cmd1']['err_buf'] . ']';
67 80 break; break;
68 81 } }
69 82 $ret['priv_key'] = $r['cmds']['cmd1']['in_buf']; $ret['priv_key'] = $r['cmds']['cmd1']['in_buf'];
 
... ... function rg_gpg_key_gen($user_id)
71 84 $a = array( $a = array(
72 85 'cmds' => array( 'cmds' => array(
73 86 'cmd1' => array( 'cmd1' => array(
74 'cmd' => 'gpg2'
75 . ' --keyring ' . $ekr
76 . ' --no-default-keyring'
87 'cmd' => $base
77 88 . ' --export' . ' --export'
78 89 . ' --armour' . ' --armour'
79 90 ) )
 
... ... function rg_gpg_key_gen($user_id)
81 92 ); );
82 93 $r = rg_exec2($a); $r = rg_exec2($a);
83 94 if (($r['ok'] != 1) || ($r['cmds']['cmd1']['exitcode'] != 0)) { if (($r['ok'] != 1) || ($r['cmds']['cmd1']['exitcode'] != 0)) {
84 $ret['errmsg'] = $r['last_errmsg'];
95 $ret['errmsg'] = 'cannot export public: '
96 . $r['cmds']['cmd1']['last_errmsg']
97 . ' [' . $r['cmds']['cmd1']['err_buf'] . ']';
85 98 break; break;
86 99 } }
87 100 $ret['pub_key'] = $r['cmds']['cmd1']['in_buf']; $ret['pub_key'] = $r['cmds']['cmd1']['in_buf'];
88 101
89 @unlink($kr);
90
91 rg_unlock('gpg_keyring.lock');
92
93 102 $ret['ok'] = 1; $ret['ok'] = 1;
94 103 } while (0); } while (0);
95 104
105 @unlink($kr);
106 @unlink($kr . meta);
107
96 108 return $ret; return $ret;
97 109 } }
File inc/graph.inc.php changed (mode: 100644) (index 6911cc6..df0cd7f)
... ... function rg_graph_query($db, $start, $end, $unit, $mode, $query, $params,
148 148 if ($p === FALSE) if ($p === FALSE)
149 149 break; break;
150 150
151 if (!isset($row['value']))
152 $row['value'] = 1;
153
151 154 if (!empty($decode_func)) { if (!empty($decode_func)) {
152 155 $_x = $decode_func($row['value']); $_x = $decode_func($row['value']);
153 156 if ($_x === FALSE) { if ($_x === FALSE) {
 
... ... function rg_graph_query($db, $start, $end, $unit, $mode, $query, $params,
228 231 */ */
229 232 function rg_graph($a) function rg_graph($a)
230 233 { {
231 rg_log_ml('DEBUG: a[data]: ' . print_r($a['data'], TRUE));
234 rg_log_debug('a[data]: ' . print_r($a['data'], TRUE));
232 235 if (!isset($a['scale_style'])) if (!isset($a['scale_style']))
233 236 $a['scale_style'] = 'font-size: 8pt'; $a['scale_style'] = 'font-size: 8pt';
234 237 if (!isset($a['now_style'])) if (!isset($a['now_style']))
 
... ... function rg_graph($a)
250 253
251 254 $c = count($a['data']['list']); $c = count($a['data']['list']);
252 255 $a['w'] = ($c - 1) * $a['gap'] + $c * $a['data_line_width']; $a['w'] = ($c - 1) * $a['gap'] + $c * $a['data_line_width'];
253 rg_log('DEBUG: count=' . count($a['data']['list']) . ' len=' . $len);
254 rg_log('DEBUG: a[w]=' . $a['w']);
256 rg_log_debug('count=' . count($a['data']['list']) . ' len=' . $len);
257 rg_log_debug('a[w]=' . $a['w']);
255 258
256 259 $time_date_height = 25; $time_date_height = 25;
257 260 $w = $data_start_x + 2 + $a['w'] + 2 + 10; $w = $data_start_x + 2 + $a['w'] + 2 + 10;
258 261 $h = $data_start_y + 2 + $a['h'] + 1 + 2 + $time_date_height + 20; $h = $data_start_y + 2 + $a['h'] + 1 + 2 + $time_date_height + 20;
259 rg_log('DEBUG: w=' . $w);
262 rg_log_debug('w=' . $w);
260 263
261 264 $ret = '<svg width="' . $w . '" height="' . $h . '"' $ret = '<svg width="' . $w . '" height="' . $h . '"'
262 265 . ' viewbox="0 0 ' . $w . ' ' . $h . '"' . ' viewbox="0 0 ' . $w . ' ' . $h . '"'
File inc/keys.inc.php changed (mode: 100644) (index f0e1e78..29e5fd6)
... ... require_once(__DIR__ . '/events.inc.php');
7 7 require_once(__DIR__ . '/cache.inc.php'); require_once(__DIR__ . '/cache.inc.php');
8 8
9 9 if (!isset($rg_max_ssh_keys)) if (!isset($rg_max_ssh_keys))
10 $rg_max_ssh_keys = 10;
10 $rg_max_ssh_keys = 30;
11 11
12 12 $rg_keys_error = ""; $rg_keys_error = "";
13 13
 
... ... function rg_keys_event_new($db, $event)
54 54 // mark keys dirty // mark keys dirty
55 55 $ret[] = array_merge($event, array( $ret[] = array_merge($event, array(
56 56 'category' => 'rg_keys_event_regen', 'category' => 'rg_keys_event_regen',
57 'prio' => 10)
57 'prio' => 10,
58 'source' => 'keys_event_new')
58 59 ); );
59 60
60 61 // notify user // notify user
 
... ... function rg_keys_event_del($db, $event)
76 77 // mark keys dirty // mark keys dirty
77 78 $ret[] = array_merge($event, array( $ret[] = array_merge($event, array(
78 79 'category' => 'rg_keys_event_regen', 'category' => 'rg_keys_event_regen',
79 'prio' => 10)
80 'prio' => 10,
81 'source' => 'keys_event_del')
80 82 ); );
81 83
82 84 // notify user // notify user
 
... ... function rg_keys_event_regen($db, $event)
100 102 $last = 0; $last = 0;
101 103
102 104 if ($event['itime'] < $last) { if ($event['itime'] < $last) {
103 rg_log("DEBUG: event itime(" . $event['itime'] . ") < last($last)."
104 . " Skip regeneration of keys.");
105 rg_log_debug('event itime(' . $event['itime'] . ') < last(' . $last . ')'
106 . '; skip regeneration of keys');
105 107 } else { } else {
106 108 $r = rg_keys_regen($db); $r = rg_keys_regen($db);
107 109 if ($r === FALSE) if ($r === FALSE)
 
... ... function rg_keys_info($key)
238 240 $error = TRUE; $error = TRUE;
239 241 $off = 0; $off = 0;
240 242 while (1) { while (1) {
241 rg_log("DEBUG: off=$off");
243 rg_log_debug('off=' . $off);
242 244
243 245 // -1 signals that we used the whole string // -1 signals that we used the whole string
244 246 if ($off == -1) if ($off == -1)
 
... ... function rg_keys_info($key)
253 255 $ret['key'] = str_replace(' ', '', $ret['key']); $ret['key'] = str_replace(' ', '', $ret['key']);
254 256 $off = $pos + 1; $off = $pos + 1;
255 257 } }
256 rg_log("DEBUG: pos=$pos off=$off key=" . $ret['key']);
258 rg_log_debug('pos=' . $pos . ' off=' . $off . ' key=' . $ret['key']);
257 259
258 260 $d = base64_decode($ret['key']); $d = base64_decode($ret['key']);
259 261 if ($d === FALSE) { if ($d === FALSE) {
 
... ... function rg_keys_info($key)
277 279 continue; continue;
278 280 } }
279 281 $type2 = substr($d, 4, $len); $type2 = substr($d, 4, $len);
280 rg_log("DEBUG: type2=$type2");
282 rg_log_debug('type2=' . $type2);
281 283 if (strcasecmp($ret['type'], $type2) != 0) { if (strcasecmp($ret['type'], $type2) != 0) {
282 284 rg_keys_set_error('key type mismatch: ' . $ret['type'] . ' != ' . $type2); rg_keys_set_error('key type mismatch: ' . $ret['type'] . ' != ' . $type2);
283 285 break; break;
 
... ... function rg_keys_info($key)
336 338 break; break;
337 339 } }
338 340
339 rg_log('DEBUG: count=' . $count);
341 rg_log_debug('count=' . $count);
340 342 $have_all_chunks = TRUE; $have_all_chunks = TRUE;
341 343 $used = 4 + $len; $used = 4 + $len;
342 344 for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
 
... ... function rg_keys_info($key)
348 350 } }
349 351 $_t = unpack('N', substr($d, $used, 4)); $used += 4; $_t = unpack('N', substr($d, $used, 4)); $used += 4;
350 352 $xlen = $_t[1]; $xlen = $_t[1];
351 rg_log('DEBUG: xlen=' . $xlen);
352 //rg_log('DEBUG: bin: ' . bin2hex(substr($d, $used, $xlen)));
353 //rg_log('DEBUG: ascii: ' . substr($d, $used, $xlen));
353 rg_log_debug('xlen=' . $xlen);
354 //rg_log_debug('bin: ' . bin2hex(substr($d, $used, $xlen)));
355 //rg_log_debug('ascii: ' . substr($d, $used, $xlen));
354 356 if ($d_len < $used + $xlen) { if ($d_len < $used + $xlen) {
355 357 rg_keys_set_error('key is too short (chunk ' . $i . '):' rg_keys_set_error('key is too short (chunk ' . $i . '):'
356 358 . ' ' . $d_len . ' < ' . ($used + $xlen)); . ' ' . $d_len . ' < ' . ($used + $xlen));
 
... ... function rg_keys_info($key)
359 361 } }
360 362
361 363 if ($i == $bits_pos) { if ($i == $bits_pos) {
362 rg_log("DEBUG: bits_sub=$bits_sub bits_div=$bits_div");
364 rg_log_debug('bits_sub=' . $bits_sub . ' bits_div=' . $bits_div);
363 365 $ret['bits'] = (($xlen - $bits_sub) / $bits_div) * 8; $ret['bits'] = (($xlen - $bits_sub) / $bits_div) * 8;
364 366 if (isset($fixes[$ret['bits']])) { if (isset($fixes[$ret['bits']])) {
365 rg_log('DEBUG: apply fix from ' . $ret['bits'] . ' to ' . $fixes[$ret['bits']]);
367 rg_log_debug('apply fix from ' . $ret['bits'] . ' to ' . $fixes[$ret['bits']]);
366 368 $ret['bits'] = $fixes[$ret['bits']]; $ret['bits'] = $fixes[$ret['bits']];
367 369 } }
368 370 } else if ($i == $extra_info_pos) { } else if ($i == $extra_info_pos) {
369 371 $_x = unpack('a*', substr($d, $used, $xlen)); $_x = unpack('a*', substr($d, $used, $xlen));
370 372 $ret['extra_info'] = 'application=' . $_x[1]; $ret['extra_info'] = 'application=' . $_x[1];
371 rg_log('DEBUG: extra_info set to [' . $ret['extra_info'] . ']');
373 rg_log_debug('extra_info set to [' . $ret['extra_info'] . ']');
372 374 } }
373 375
374 376 $used += $xlen; $used += $xlen;
375 377 } }
376 378 if ($have_all_chunks === FALSE) { if ($have_all_chunks === FALSE) {
377 rg_log('DEBUG: not all chunk present, starting over');
379 rg_log_debug('not all chunk present, starting over');
378 380 continue; continue;
379 381 } }
380 382
 
... ... function rg_keys_info($key)
406 408 } }
407 409
408 410 /* /*
409 * Remove keys from database for user 'ui'
411 * Remove keys from database for user 'ui_login'
410 412 */ */
411 function rg_keys_remove($db, $ui, $list)
413 function rg_keys_remove($db, $ui_login, $list)
412 414 { {
413 415 rg_prof_start("keys_remove"); rg_prof_start("keys_remove");
414 416 rg_log_enter("keys_remove: list=" . rg_array2string($list)); rg_log_enter("keys_remove: list=" . rg_array2string($list));
 
... ... function rg_keys_remove($db, $ui, $list)
419 421 foreach ($list as $key_id => $junk) foreach ($list as $key_id => $junk)
420 422 $my_list[] = sprintf("%u", $key_id); $my_list[] = sprintf("%u", $key_id);
421 423
422 $params = array("uid" => $ui['uid']);
424 $params = array("uid" => $ui_login['uid']);
423 425 $sql_list = implode(", ", $my_list); $sql_list = implode(", ", $my_list);
424 426 $sql = "DELETE FROM keys" $sql = "DELETE FROM keys"
425 427 . " WHERE uid = @@uid@@" . " WHERE uid = @@uid@@"
 
... ... function rg_keys_remove($db, $ui, $list)
435 437 $event = array( $event = array(
436 438 'category' => 'keys_event_del', 'category' => 'keys_event_del',
437 439 'prio' => 50, 'prio' => 50,
438 'ui' => $ui,
440 'ui_login' => $ui_login,
439 441 'keys' => implode(',', $my_list)); 'keys' => implode(',', $my_list));
440 442 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
441 443 if ($r !== TRUE) { if ($r !== TRUE) {
 
... ... function rg_keys_remove($db, $ui, $list)
444 446 break; break;
445 447 } }
446 448
447 $key = 'user' . '::' . $ui['uid'] . '::' . 'keys';
449 $key = 'user' . '::' . $ui_login['uid'] . '::' . 'keys';
448 450 foreach ($my_list as $_key_id) foreach ($my_list as $_key_id)
449 451 rg_cache_unset($key . '::' . $_key_id, rg_cache_unset($key . '::' . $_key_id,
450 452 RG_SOCKET_NO_WAIT); RG_SOCKET_NO_WAIT);
 
... ... function rg_keys_max($db)
505 507 * Adds a key * Adds a key
506 508 * Returns the key_id of the key. * Returns the key_id of the key.
507 509 */ */
508 function rg_keys_add($db, $ui, $key, $flags)
510 function rg_keys_add($db, $ui_login, $key, $flags)
509 511 { {
510 512 rg_prof_start("keys_add"); rg_prof_start("keys_add");
511 513 rg_log_enter('keys_add: flags=' . $flags . ' key=' . $key); rg_log_enter('keys_add: flags=' . $flags . ' key=' . $key);
 
... ... function rg_keys_add($db, $ui, $key, $flags)
527 529
528 530 // Check if we are over the maximum // Check if we are over the maximum
529 531 // the config after update may not have this defined. // the config after update may not have this defined.
530 $no_of_keys = rg_keys_count($db, $ui['uid']);
532 $no_of_keys = rg_keys_count($db, $ui_login['uid']);
531 533 if ($no_of_keys === FALSE) if ($no_of_keys === FALSE)
532 534 break; break;
533 535
 
... ... function rg_keys_add($db, $ui, $key, $flags)
547 549
548 550 $params = array( $params = array(
549 551 'itime' => $itime, 'itime' => $itime,
550 'uid' => $ui['uid'],
552 'uid' => $ui_login['uid'],
551 553 'key' => $ki['type'] . ' ' . $ki['key'] 'key' => $ki['type'] . ' ' . $ki['key']
552 554 . ' ' . $ki['comment'], . ' ' . $ki['comment'],
553 555 'count' => 0, 'count' => 0,
 
... ... function rg_keys_add($db, $ui, $key, $flags)
572 574 $event = array( $event = array(
573 575 'category' => 'keys_event_new', 'category' => 'keys_event_new',
574 576 'prio' => 50, 'prio' => 50,
575 'ui' => $ui,
577 'ui_login' => $ui_login,
576 578 'ki' => $ki, 'ki' => $ki,
577 579 'key_id' => $key_id); 'key_id' => $key_id);
578 580 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
 
... ... function rg_keys_add($db, $ui, $key, $flags)
590 592 } }
591 593 $do_rollback = 0; $do_rollback = 0;
592 594
593 $_key = 'user' . '::' . $ui['uid'] . '::'
595 $_key = 'user' . '::' . $ui_login['uid'] . '::'
594 596 . 'keys' . '::' . $key_id; . 'keys' . '::' . $key_id;
595 597 rg_cache_merge($_key, $params, RG_SOCKET_NO_WAIT); rg_cache_merge($_key, $params, RG_SOCKET_NO_WAIT);
596 598
 
... ... function rg_keys_add($db, $ui, $key, $flags)
611 613 /* /*
612 614 * Update first_use, last_use, last_ip and count * Update first_use, last_use, last_ip and count
613 615 */ */
614 function rg_keys_update_use($db, $uid, $key_id, $ip, $cmd)
616 function rg_keys_update_use($db, $uid, $key_id, $cmd)
615 617 { {
616 618 // The build system will not update table 'keys' // The build system will not update table 'keys'
617 619 if ($key_id == 0) if ($key_id == 0)
618 620 return TRUE; return TRUE;
619 621
620 622 rg_prof_start("keys_update_use"); rg_prof_start("keys_update_use");
621 rg_log_enter("keys_update_use: uid=$uid key_id=$key_id"
622 . ", ip=$ip, cmd=$cmd");
623 rg_log_enter('keys_update_use: uid=' . $uid . ' key_id=' . $key_id
624 . ' cmd=' . $cmd);
623 625
624 626 $ret = FALSE; $ret = FALSE;
625 627 while (1) { while (1) {
 
... ... function rg_keys_update_use($db, $uid, $key_id, $ip, $cmd)
636 638
637 639 // We will not update the field if is too soon // We will not update the field if is too soon
638 640 if (isset($c['last_use']) if (isset($c['last_use'])
639 && (strcmp($ip, $c['last_ip']) == 0)
641 && (strcmp(rg_ip(), $c['last_ip']) == 0)
640 642 && (strcmp($cmd, $c['last_cmd']) == 0) && (strcmp($cmd, $c['last_cmd']) == 0)
641 643 && ($now - $c['last_use'] < 60)) && ($now - $c['last_use'] < 60))
642 644 $update_last_use = FALSE; $update_last_use = FALSE;
 
... ... function rg_keys_update_use($db, $uid, $key_id, $ip, $cmd)
645 647 $params = array( $params = array(
646 648 'now' => $now, 'now' => $now,
647 649 'key_id' => $key_id, 'key_id' => $key_id,
648 'ip' => $ip,
650 'ip' => rg_ip(),
649 651 'last_cmd' => $cmd); 'last_cmd' => $cmd);
650 652
651 653 if ($update_first_use) { if ($update_first_use) {
 
... ... function rg_keys_update_use($db, $uid, $key_id, $ip, $cmd)
679 681
680 682 $a = array( $a = array(
681 683 'last_use' => $now, 'last_use' => $now,
682 'last_ip' => $ip,
684 'last_ip' => rg_ip(),
683 685 'last_cmd' => $cmd); 'last_cmd' => $cmd);
684 686 rg_cache_merge($key, $a, RG_SOCKET_NO_WAIT); rg_cache_merge($key, $a, RG_SOCKET_NO_WAIT);
685 687 } }
 
... ... function rg_keys_regen($db)
744 746 global $rg_keys_file; global $rg_keys_file;
745 747 global $rg_scripts; global $rg_scripts;
746 748
747 rg_prof_start("keys_regen");
749 rg_prof_start('keys_regen');
750 rg_log_enter('keys_regen');
748 751
749 752 $now = time(); $now = time();
750 753 $ret = FALSE; $ret = FALSE;
 
... ... function rg_keys_regen($db)
756 759 } }
757 760 $akp = intval($akp); $akp = intval($akp);
758 761 if ($akp == 1) { if ($akp == 1) {
762 rg_log_debug('No need to regenerate because'
763 . ' AuthorizedKeysCommand is active');
759 764 if (file_exists($rg_keys_file)) if (file_exists($rg_keys_file))
760 unlink($rg_keys_file);
765 @unlink($rg_keys_file);
761 766 $ret = TRUE; $ret = TRUE;
762 767 break; break;
763 768 } }
 
... ... function rg_keys_regen($db)
864 869 break; break;
865 870 } }
866 871
867 rg_prof_end("keys_regen");
872 rg_log_exit();
873 rg_prof_end('keys_regen');
868 874 return $ret; return $ret;
869 875 } }
870 876
871 877 /* /*
872 878 * List keys * List keys
873 879 */ */
874 function rg_keys_list($db, $ui)
880 function rg_keys_list($db, $ui_login)
875 881 { {
876 882 rg_prof_start("keys_list"); rg_prof_start("keys_list");
877 rg_log_enter("keys_list: uid=" . $ui['uid']);
883 rg_log_enter("keys_list: uid=" . $ui_login['uid']);
878 884
879 885 $ret = FALSE; $ret = FALSE;
880 886 while (1) { while (1) {
881 $params = array("uid" => $ui['uid']);
887 $params = array('uid' => $ui_login['uid']);
882 888 $sql = "SELECT * FROM keys WHERE uid = @@uid@@" $sql = "SELECT * FROM keys WHERE uid = @@uid@@"
883 889 . " ORDER BY itime DESC"; . " ORDER BY itime DESC";
884 890 $res = rg_sql_query_params($db, $sql, $params); $res = rg_sql_query_params($db, $sql, $params);
File inc/ldap.inc.php changed (mode: 100644) (index a4d3122..434dd30)
... ... function rg_ldap_login($db, $user, $pass, &$ui)
297 297 $r = rg_ldap_sync_get_cache($db, $user); $r = rg_ldap_sync_get_cache($db, $user);
298 298 if ($r['ok'] === 1) { if ($r['ok'] === 1) {
299 299 foreach ($r['list'] as $a) { foreach ($r['list'] as $a) {
300 rg_log_ml('DEBUG: cache: ' . print_r($a, TRUE));
300 rg_log_debug('cache: ' . print_r($a, TRUE));
301 301 // TODO: test if the entry is expired // TODO: test if the entry is expired
302 302 // TODO: encrypt password! // TODO: encrypt password!
303 303 if (strcmp($a['password'], $pass) != 0) { if (strcmp($a['password'], $pass) != 0) {
304 rg_log('DEBUG: passwords do not match ['
304 rg_log_debug('passwords do not match ['
305 305 . $a['password'] . '] [' . $pass . ']'); . $a['password'] . '] [' . $pass . ']');
306 306 continue; continue;
307 307 } }
 
... ... function rg_ldap_login($db, $user, $pass, &$ui)
313 313 continue; continue;
314 314 } }
315 315
316 rg_log('DEBUG: Found a good cache entry!');
316 rg_log_debug('Found a good cache entry!');
317 317 rg_ldap_a_and_si_to_a_ui($ui, $a, rg_ldap_a_and_si_to_a_ui($ui, $a,
318 318 $sl['list'][$server_id]); $sl['list'][$server_id]);
319 319
 
... ... function rg_ldap_login($db, $user, $pass, &$ui)
335 335
336 336 $r = rg_ldap_core_connect($si['url'], $si['timeout']); $r = rg_ldap_core_connect($si['url'], $si['timeout']);
337 337 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
338 rg_log('DEBUG: cannot connect: ' . $r['errmsg']);
338 rg_log_debug('cannot connect: ' . $r['errmsg']);
339 339 $ret['errmsg'] = $r['errmsg']; $ret['errmsg'] = $r['errmsg'];
340 340 continue; continue;
341 341 } }
342 342 $con = $r['con']; $con = $r['con'];
343 rg_log('DEBUG: connected to ' . $si['url']);
343 rg_log_debug('connected to ' . $si['url']);
344 344
345 rg_log('DEBUG: binding as [' . $si['bind_dn'] . ']');
345 rg_log_debug('binding as [' . $si['bind_dn'] . ']');
346 346 $r = rg_ldap_core_bind($con, $si['bind_dn'], $r = rg_ldap_core_bind($con, $si['bind_dn'],
347 347 $si['bind_pass']); $si['bind_pass']);
348 348 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
349 rg_log('DEBUG: cannot bind: ' . $r['errmsg']);
349 rg_log_debug('cannot bind: ' . $r['errmsg']);
350 350 $ret['errmsg'] = $r['errmsg']; $ret['errmsg'] = $r['errmsg'];
351 351 continue; continue;
352 352 } }
353 rg_log('DEBUG: bind1 ok!');
353 rg_log_debug('bind1 ok!');
354 354
355 355 // TODO: should I validate uid field - injection? // TODO: should I validate uid field - injection?
356 356 $uid_attr = strtolower($si['uid_attr']); $uid_attr = strtolower($si['uid_attr']);
 
... ... function rg_ldap_login($db, $user, $pass, &$ui)
362 362 if (!empty($si['filter'])) if (!empty($si['filter']))
363 363 $filter = '(&' . $filter $filter = '(&' . $filter
364 364 . '(' . ldap_escape($si['filter'], NULL, LDAP_ESCAPE_FILTER) . '))'; . '(' . ldap_escape($si['filter'], NULL, LDAP_ESCAPE_FILTER) . '))';
365 rg_log('DEBUG: filter: ' . $filter);
366 rg_log('DEBUG: base=' . $si['user_base']);
365 rg_log_debug('filter: ' . $filter);
366 rg_log_debug('base=' . $si['user_base']);
367 367
368 368 $deref = LDAP_DEREF_NEVER; // TODO: this should be in $si $deref = LDAP_DEREF_NEVER; // TODO: this should be in $si
369 369 $attr = array('cn', 'mail', 'entryUUID', 'memberOf', $attr = array('cn', 'mail', 'entryUUID', 'memberOf',
 
... ... function rg_ldap_login($db, $user, $pass, &$ui)
374 374 $attr, 0 /*attronly*/, 0 /*sizelimit*/, $attr, 0 /*attronly*/, 0 /*sizelimit*/,
375 375 0 /*timelimit*/, $deref); 0 /*timelimit*/, $deref);
376 376 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
377 rg_log('DEBUG: cannot search: ' . $r['errmsg']);
377 rg_log_debug('cannot search: ' . $r['errmsg']);
378 378 $ret['errmsg'] = $r['errmsg']; $ret['errmsg'] = $r['errmsg'];
379 379 continue; continue;
380 380 } }
381 381 if (empty($r['data']) || !isset($r['data'][0])) { if (empty($r['data']) || !isset($r['data'][0])) {
382 rg_log('DEBUG: cannot find data');
382 rg_log_debug('cannot find data');
383 383 $ret['errmsg'] = 'user not found'; $ret['errmsg'] = 'user not found';
384 384 continue; continue;
385 385 } }
 
... ... function rg_ldap_login($db, $user, $pass, &$ui)
387 387 // Have to test here if we can bind with the user found // Have to test here if we can bind with the user found
388 388 // We may have more users, but we will select the first one // We may have more users, but we will select the first one
389 389 $d = $r['data'][0]; $d = $r['data'][0];
390 rg_log('DEBUG: binding as [' . $d['dn'] . '] pass=' . $pass);
390 rg_log_debug('binding as [' . $d['dn'] . '] pass=' . $pass);
391 391 $r = rg_ldap_core_bind($con, $d['dn'], $pass); $r = rg_ldap_core_bind($con, $d['dn'], $pass);
392 392 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
393 rg_log('DEBUG: cannot bind: ' . $r['errmsg']);
393 rg_log_debug('cannot bind: ' . $r['errmsg']);
394 394 $ret['errmsg'] = $r['errmsg']; $ret['errmsg'] = $r['errmsg'];
395 395 continue; continue;
396 396 } }
397 rg_log('DEBUG: bind2 ok!');
397 rg_log_debug('bind2 ok!');
398 398
399 399 unset($ret['errmsg']); unset($ret['errmsg']);
400 400 $found = TRUE; $found = TRUE;
 
... ... function rg_ldap_login($db, $user, $pass, &$ui)
403 403 if (!$found) if (!$found)
404 404 break; break;
405 405
406 rg_log_ml('DEBUG: got data from LDAP: d=' . print_r($d, TRUE));
406 rg_log_debug('got data from LDAP: d=' . print_r($d, TRUE));
407 407
408 408 // $a will be the $ret['post'] // $a will be the $ret['post']
409 409 // It will be used to test if an update into 'users' is needed. // It will be used to test if an update into 'users' is needed.
 
... ... function rg_ldap_login($db, $user, $pass, &$ui)
419 419 // TODO: really needed? I think not, we will use it in ldap_cache // TODO: really needed? I think not, we will use it in ldap_cache
420 420 //$a['uid_number'] = isset($d['uidnumber'][0]) ? $d['mail'][0] : ''; //$a['uid_number'] = isset($d['uidnumber'][0]) ? $d['mail'][0] : '';
421 421 $a['password'] = $pass; $a['password'] = $pass;
422 rg_log_ml('DEBUG: built a=' . print_r($a, TRUE));
422 rg_log_debug('built a=' . print_r($a, TRUE));
423 423
424 424 rg_ldap_a_and_si_to_a_ui($ui, $a, $si); rg_ldap_a_and_si_to_a_ui($ui, $a, $si);
425 425
 
... ... function rg_ldap_login($db, $user, $pass, &$ui)
429 429 $ui['is_admin'] = 0; $ui['is_admin'] = 0;
430 430 if (isset($d['memberof'])) { if (isset($d['memberof'])) {
431 431 for ($j = 0; $j < $d['memberof']['count']; $j++) { for ($j = 0; $j < $d['memberof']['count']; $j++) {
432 //rg_log('DEBUG: comparing ' . $d['memberof'][$j] . ' with ' . $si['admin_group']);
432 //rg_log_debug('comparing ' . $d['memberof'][$j] . ' with ' . $si['admin_group']);
433 433 // TODO: Do I have to escape `? // TODO: Do I have to escape `?
434 434 $r = @preg_match('`' . $si['admin_group'] . '`uD', $d['memberof'][$j]); $r = @preg_match('`' . $si['admin_group'] . '`uD', $d['memberof'][$j]);
435 435 if ($r === 1) { if ($r === 1) {
 
... ... function rg_ldap_login($db, $user, $pass, &$ui)
445 445
446 446 $ui['ok'] = 1; $ui['ok'] = 1;
447 447
448 rg_log_ml('DEBUG: ui: ' . print_r($ui, TRUE));
448 rg_log_debug('ui: ' . print_r($ui, TRUE));
449 449
450 450 // Prepare these for 'login_post' function, to update the cache. // Prepare these for 'login_post' function, to update the cache.
451 451 $ret['post'] = $a; $ret['post'] = $a;
 
... ... function rg_ldap_login_post($db, $uid, $post)
473 473 { {
474 474 rg_log_enter('ldap_login_post'); rg_log_enter('ldap_login_post');
475 475
476 rg_log_ml('DEBUG: uid=' . $uid);
477 rg_log_ml('DEBUG: post: ' . print_r($post, TRUE));
476 rg_log_debug('uid=' . $uid);
477 rg_log_debug('post: ' . print_r($post, TRUE));
478 478
479 479 $ret = array('ok' => 0); $ret = array('ok' => 0);
480 480 while (1) { while (1) {
481 481 if ($post['uid'] != $uid) { if ($post['uid'] != $uid) {
482 rg_log('DEBUG: we need to update ldap_cache.uid');
482 rg_log_debug('we need to update ldap_cache.uid');
483 483 $post['uid'] = $uid; $post['uid'] = $uid;
484 484 $r = rg_ldap_sync_update_cache($db, $post); $r = rg_ldap_sync_update_cache($db, $post);
485 485 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
 
... ... function rg_ldap_add_high_level($db, $rg, $op, $paras)
561 561 rg_prof_start('ldap_add_high_level'); rg_prof_start('ldap_add_high_level');
562 562 rg_log_enter('ldap_add_high_level op=' . $op); rg_log_enter('ldap_add_high_level op=' . $op);
563 563
564 rg_log('DEBUG: paras:' . rg_array2string($paras));
564 rg_log_debug('paras:' . rg_array2string($paras));
565 565
566 566 $ret = ''; $ret = '';
567 567 $errmsg = array(); $errmsg = array();
 
... ... function rg_ldap_add_high_level($db, $rg, $op, $paras)
610 610 'ca_cert' => rg_var_str('ldap::ca_cert') 'ca_cert' => rg_var_str('ldap::ca_cert')
611 611 ); );
612 612
613 $r = rg_ldap_add($db, $rg['login_ui']['uid'], $rg['ldap']);
613 $ui_login = rg_ui_login();
614 $r = rg_ldap_add($db, $ui_login['uid'], $rg['ldap']);
614 615 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
615 616 $errmsg[] = rg_ldap_error(); $errmsg[] = rg_ldap_error();
616 617 break; break;
File inc/ldap_core.inc.php changed (mode: 100644) (index 4f32857..d5db063)
... ... function rg_ldap_core_search($con, $base_dn, $filter, $attr, $attronly,
141 141 $ret['errmsg'] = ldap_error($con) . ' [' . $e . ']'; $ret['errmsg'] = ldap_error($con) . ' [' . $e . ']';
142 142 break; break;
143 143 } }
144 //rg_log_ml('DEBUG: entries: ' . print_r($ret['data'], TRUE));
144 //rg_log_debug('entries: ' . print_r($ret['data'], TRUE));
145 145
146 146 $ret['ok'] = 1; $ret['ok'] = 1;
147 147 break; break;
 
... ... function rg_ldap_core_ldif2array($data)
192 192
193 193 $error = FALSE; $error = FALSE;
194 194 while (1) { while (1) {
195 rg_log('DEBUG: looping again, off=' . $off);
195 rg_log_debug('looping again, off=' . $off);
196 196 if ($off === $end) { if ($off === $end) {
197 197 rg_log('off is at the end'); rg_log('off is at the end');
198 198 $off = $end + 1; $off = $end + 1;
File inc/ldap_sync.inc.php changed (mode: 100644) (index 4c12b7d..e58a04d)
... ... function rg_ldap_sync_update_cache($db, $l)
49 49 { {
50 50 rg_log_enter('ldap_sync_update_cache'); rg_log_enter('ldap_sync_update_cache');
51 51
52 rg_log_ml('DEBUG: l: ' . print_r($l, TRUE));
52 rg_log_debug('l: ' . print_r($l, TRUE));
53 53
54 54 $ret = array('ok' => 0); $ret = array('ok' => 0);
55 55 while (1) { while (1) {
 
... ... function rg_ldap_sync_apply($db, $server_id, $data)
172 172 $csn = array(); $csn = array();
173 173 foreach ($data as $block_id => $block) { foreach ($data as $block_id => $block) {
174 174 if (isset($block['entryCSN'][0])) { if (isset($block['entryCSN'][0])) {
175 rg_log('DEBUG: entryCSN is present!');
175 rg_log_debug('entryCSN is present!');
176 176 $c = $block['entryCSN'][0]; $c = $block['entryCSN'][0];
177 177 // Example: 20171001075924.155248Z#000000#001#000000 // Example: 20171001075924.155248Z#000000#001#000000
178 178 $_t = explode('#', $c); $_t = explode('#', $c);
 
... ... function rg_ldap_sync_apply($db, $server_id, $data)
180 180 if (!isset($csn[$_s]) || ($c > $csn[$_s])) if (!isset($csn[$_s]) || ($c > $csn[$_s]))
181 181 $csn[$_s] = $c; $csn[$_s] = $c;
182 182 } else { } else {
183 rg_log('DEBUG: entryCSN is NOT present!');
183 rg_log_debug('entryCSN is NOT present!');
184 184 } }
185 185
186 186 if (!isset($block['objectClass'])) { if (!isset($block['objectClass'])) {
 
... ... function rg_ldap_sync_apply($db, $server_id, $data)
214 214 $l['uuid'] = isset($block['entryUUID'][0]) ? $block['entryUUID'][0] : ''; $l['uuid'] = isset($block['entryUUID'][0]) ? $block['entryUUID'][0] : '';
215 215 // Verifications // Verifications
216 216 if (empty($l['ldap_uid'])) { if (empty($l['ldap_uid'])) {
217 rg_log('DEBUG: ldap_uid is not present!');
217 rg_log_debug('ldap_uid is not present!');
218 218 continue; continue;
219 219 } }
220 220 if (empty($l['uuid'])) { if (empty($l['uuid'])) {
221 rg_log('DEBUG: entryUUID is not present!');
221 rg_log_debug('entryUUID is not present!');
222 222 continue; continue;
223 223 } }
224 224
225 rg_log_ml('DEBUG: l:' . print_r($l, TRUE));
225 rg_log_debug('l:' . print_r($l, TRUE));
226 226
227 227 $r = rg_ldap_sync_update_cache($db, $l); $r = rg_ldap_sync_update_cache($db, $l);
228 228 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
 
... ... function rg_ldap_sync_apply($db, $server_id, $data)
238 238 if (isset($ret['errmsg'])) if (isset($ret['errmsg']))
239 239 break; break;
240 240
241 rg_log_ml('DEBUG: csn: ' . print_r($csn, TRUE));
241 rg_log_debug('csn: ' . print_r($csn, TRUE));
242 242 $r = rg_ldap_sync_update_server($db, $server_id, $r = rg_ldap_sync_update_server($db, $server_id,
243 243 implode(';', $csn)); implode(';', $csn));
244 244 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
 
... ... function rg_ldap_sync_apply($db, $server_id, $data)
269 269 function rg_ldap_sync_data($db, $server_id, $s) function rg_ldap_sync_data($db, $server_id, $s)
270 270 { {
271 271 rg_log_enter('ldap_sync_data'); rg_log_enter('ldap_sync_data');
272 rg_log('DEBUG: s=' . $s);
272 rg_log_debug('s=' . $s);
273 273
274 274 $ret = array(); $ret = array();
275 275 $ret['ok'] = 0; $ret['ok'] = 0;
File inc/log.inc.php changed (mode: 100644) (index 40465f3..eaa99f1)
... ... function rg_log_ml($str)
115 115 } }
116 116 } }
117 117
118 function rg_log_debug($m)
119 {
120 if (!rg_debug())
121 return;
122
123 rg_log_ml('DEBUG: ' . $m);
124 }
125
118 126 /* /*
119 127 * This function will log fatal errors. * This function will log fatal errors.
120 128 */ */
 
... ... function rg_error_core($msg)
133 141 return; return;
134 142
135 143 $me = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : "?"; $me = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : "?";
136 $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '?';
137 144
138 145 $dir = $rg_log_dir; $dir = $rg_log_dir;
139 146
 
... ... function rg_error_core($msg)
145 152 'Script: ' . $me . "\n" 'Script: ' . $me . "\n"
146 153 . 'log_sid: ' . $rg_log_sid . "\n" . 'log_sid: ' . $rg_log_sid . "\n"
147 154 . 'Date: ' . gmdate('Y-m-d H:i:s') . "\n" . 'Date: ' . gmdate('Y-m-d H:i:s') . "\n"
148 . 'IP: ' . $ip . "\n"
155 . 'IP: ' . rg_ip() . "\n"
149 156 . $bt . "\n", . $bt . "\n",
150 157 FILE_APPEND); FILE_APPEND);
151 158 if ($r === FALSE) if ($r === FALSE)
File inc/login/login.php changed (mode: 100644) (index c373394..5904091)
... ... while ($rg['doit'] == 1) {
20 20 } }
21 21
22 22 $r = rg_user_login_by_user_pass($db, $user, $pass, $login_token, $r = rg_user_login_by_user_pass($db, $user, $pass, $login_token,
23 $rg['ip'], $lock_ip, $rg['https'], $rg['hostname'],
24 $rg['login_ui']);
23 $lock_ip, $rg['https'], $rg['hostname']);
25 24 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
26 25 $errmsg[] = $r['errmsg']; $errmsg[] = $r['errmsg'];
27 26 break; break;
28 27 } }
29 28
30 29 // redirect to home page // redirect to home page
31 $url = rg_re_userpage($rg['login_ui']);
30 $url = rg_re_userpage(rg_ui_login());
32 31 rg_redirect($url); rg_redirect($url);
33 32 } }
34 33
File inc/mail.inc.php changed (mode: 100644) (index bdac111..2682c6d)
... ... function rg_mail_template($template, $more)
34 34 if (!isset($more['ignore_debug'])) if (!isset($more['ignore_debug']))
35 35 $more['ignore_debug'] = 0; $more['ignore_debug'] = 0;
36 36
37 if (!isset($more['ui']['ignore_confirmed']))
38 $more['ui']['ignore_confirmed'] = 0;
37 if (!isset($more['ui_login']['ignore_confirmed']))
38 $more['ui_login']['ignore_confirmed'] = 0;
39 39
40 if (($more['ui']['ignore_confirmed'] == 0)
41 && ($more['ui']['confirmed'] == 0)) {
40 if (($more['ui_login']['ignore_confirmed'] == 0)
41 && ($more['ui_login']['confirmed'] == 0)) {
42 42 rg_log('Confirmed is 0 and ignore_confirmed is 0!'); rg_log('Confirmed is 0 and ignore_confirmed is 0!');
43 43 $ret = TRUE; $ret = TRUE;
44 44 break; break;
45 45 } }
46 46
47 if (empty($more['ui']['email'])) {
47 if (empty($more['ui_login']['email'])) {
48 48 $ret = TRUE; $ret = TRUE;
49 49 break; break;
50 50 } }
 
... ... function rg_mail_template($template, $more)
66 66
67 67 $body = rg_template($template . ".body.txt", $more, FALSE /*xss*/); $body = rg_template($template . ".body.txt", $more, FALSE /*xss*/);
68 68
69 rg_log("CHECK: mail_template(" . $more['ui']['email']
69 rg_log("CHECK: mail_template(" . $more['ui_login']['email']
70 70 . ", $subject, $body, $header, -f $rg_admin_email"); . ", $subject, $body, $header, -f $rg_admin_email");
71 if (($more['debug'] == 1) && ($more['ignore_debug'] == 0)) {
72 if (!isset($more['ui']['uid']))
73 $k = $more['ui']['email'];
71 if ((rg_debug() > 0) && ($more['ignore_debug'] == 0)) {
72 if (!isset($more['ui_login']['uid']))
73 $k = $more['ui_login']['email'];
74 74 else else
75 $k = $more['ui']['uid'];
75 $k = $more['ui_login']['uid'];
76 76
77 77 rg_cache_set('DEBUG::' . $k . '::mail::' . $template, rg_cache_set('DEBUG::' . $k . '::mail::' . $template,
78 78 array( array(
79 79 'header' => $header, 'header' => $header,
80 80 'subject' => $subject, 'subject' => $subject,
81 'to' => $more['ui']['email'],
81 'to' => $more['ui_login']['email'],
82 82 'body' => $body 'body' => $body
83 83 ), RG_SOCKET_NO_WAIT); ), RG_SOCKET_NO_WAIT);
84 84 $ret = TRUE; $ret = TRUE;
85 85 break; break;
86 86 } }
87 87
88 $ret = mail($more['ui']['email'], $subject, $body, $header,
88 $ret = mail($more['ui_login']['email'], $subject, $body, $header,
89 89 "-f $rg_admin_email"); "-f $rg_admin_email");
90 90 if ($ret === FALSE) if ($ret === FALSE)
91 rg_log("Sending mail failed to=" . $more['ui']['email']
91 rg_log("Sending mail failed to=" . $more['ui_login']['email']
92 92 . " subject=$subject!"); . " subject=$subject!");
93 93 break; break;
94 94 } }
 
... ... function rg_mail_template($template, $more)
97 97 return $ret; return $ret;
98 98 } }
99 99
100 ?>
File inc/mr.inc.php changed (mode: 100644) (index 915c636..96eb57a)
... ... function rg_mr_event_add_to_db($db, $a)
121 121 // TODO: git may fail to update the reference after this hook; // TODO: git may fail to update the reference after this hook;
122 122 // the mr code should check if the update was done. // the mr code should check if the update was done.
123 123 $mr = 'refs/mr/' . $id; $mr = 'refs/mr/' . $id;
124 $reason = $a['ui']['username'] . ' pushed a merge request'
124 $ui_login = rg_ui_login();
125 $reason = $ui_login['username'] . ' pushed a merge request'
125 126 . ' for ref ' . $a['refname'] . ' for ref ' . $a['refname']
126 127 . ' into ' . $mr; . ' into ' . $mr;
127 128 $r = rg_git_update_ref($a['repo_path'], $mr, '', $a['new_rev'], $reason); $r = rg_git_update_ref($a['repo_path'], $mr, '', $a['new_rev'], $reason);
 
... ... function rg_mr_event_add_to_db($db, $a)
131 132 } }
132 133
133 134 $a['id'] = $id; $a['id'] = $id;
134 $a['who'] = $a['ui']['uid'];
135 $a['who'] = $ui_login['uid'];
135 136 $sql = 'INSERT INTO merge_requests (repo_id, id, itime' $sql = 'INSERT INTO merge_requests (repo_id, id, itime'
136 137 . ', namespace, refname, old_rev, new_rev, done, ip' . ', namespace, refname, old_rev, new_rev, done, ip'
137 138 . ', who)' . ', who)'
 
... ... function rg_mr_data($db, $type, $start, $end, $unit, $mode)
369 370 $params = array('start' => $start, 'end' => $end); $params = array('start' => $start, 'end' => $end);
370 371 switch ($type) { switch ($type) {
371 372 case 'create_mr': case 'create_mr':
372 $q = 'SELECT 1 AS value, itime FROM merge_requests'
373 $q = 'SELECT itime FROM merge_requests'
373 374 . ' WHERE itime >= @@start@@ AND itime <= @@end@@'; . ' WHERE itime >= @@start@@ AND itime <= @@end@@';
374 375 break; break;
375 376
 
... ... function rg_mr_high_level($db, &$rg, $paras)
413 414 $op = ''; $op = '';
414 415 } }
415 416
416 rg_log('DEBUG: op=' . $op);
417 rg_log_debug('op=' . $op);
417 418 $rg['menu']['mr'][$op] = 1; $rg['menu']['mr'][$op] = 1;
418 419 $rg['HTML:menu_repo_level2'] = $rg['HTML:menu_repo_level2'] =
419 420 rg_template('repo/mr/menu.html', $rg, TRUE /*xss*/); rg_template('repo/mr/menu.html', $rg, TRUE /*xss*/);
 
... ... function rg_mr_high_level($db, &$rg, $paras)
446 447 $against = rg_git_short($mri['refname']); $against = rg_git_short($mri['refname']);
447 448
448 449 $mr_op = array_shift($paras); $mr_op = array_shift($paras);
449 rg_log('DEBUG: mr_op=' . $mr_op);
450 rg_log_debug('mr_op=' . $mr_op);
450 451 if (strcmp($mr_op, 'merge') == 0) { if (strcmp($mr_op, 'merge') == 0) {
451 452 if ($rg['can_admin'] !== 1) { if ($rg['can_admin'] !== 1) {
452 453 $ret .= rg_warning('Not allowed!'); $ret .= rg_warning('Not allowed!');
 
... ... function rg_mr_high_level($db, &$rg, $paras)
467 468 'category' => 'mr_merge', 'category' => 'mr_merge',
468 469 'prio' => 30, 'prio' => 30,
469 470 'ri' => $rg['ri'], 'ri' => $rg['ri'],
470 'ui' => $rg['login_ui'],
471 471 'repo_path' => $rg['repo_path'], 'repo_path' => $rg['repo_path'],
472 472 'mri' => $mri, 'mri' => $mri,
473 473 'merge_against' => $against, 'merge_against' => $against,
 
... ... function rg_mr_high_level($db, &$rg, $paras)
502 502 . ' (' . rg_git_error() . ').'); . ' (' . rg_git_error() . ').');
503 503 break; break;
504 504 } }
505 rg_log('DEBUG: can merge without conflict:' . ($r == 1 ? 'yes' : 'no'));
505 rg_log_debug('can merge without conflict:' . ($r == 1 ? 'yes' : 'no'));
506 506 $mri['can_merge_without_conflicts'] = $r; $mri['can_merge_without_conflicts'] = $r;
507 507
508 508 if ($mri['can_merge_without_conflicts'] == 0) { if ($mri['can_merge_without_conflicts'] == 0) {
 
... ... function rg_mr_high_level($db, &$rg, $paras)
517 517 $mri['HTML:status'] = rg_git_merge_tree_html( $mri['HTML:status'] = rg_git_merge_tree_html(
518 518 $rg['repo_path'], $base, $against, $rg['repo_path'], $base, $against,
519 519 $mri['new_rev']); $mri['new_rev']);
520 rg_log_ml('DEBUG: status: ' . print_r($mri['HTML:status'], TRUE));
520 rg_log_debug('status: ' . print_r($mri['HTML:status'], TRUE));
521 521 $mri['HTML:body'] .= rg_template( $mri['HTML:body'] .= rg_template(
522 522 'repo/mr/conflicts.html', $mri, TRUE /*xss*/); 'repo/mr/conflicts.html', $mri, TRUE /*xss*/);
523 523 } }
 
... ... function rg_mr_high_level($db, &$rg, $paras)
539 539 $rg['rg_form_token'] = rg_token_get($db, $rg, 'mr_merge'); $rg['rg_form_token'] = rg_token_get($db, $rg, 'mr_merge');
540 540 } }
541 541
542 //rg_log_ml('DEBUG: mri: ' . print_r($mri, TRUE));
542 //rg_log_debug('mri: ' . print_r($mri, TRUE));
543 543 $rg['mr'] = $mri; $rg['mr'] = $mri;
544 544
545 545 $hints = array(); $hints = array();
File inc/prof.inc.php changed (mode: 100644) (index ad270b8..738ab25)
... ... function rg_prof_start($label)
34 34 $mem = memory_get_peak_usage() - $peak0; $mem = memory_get_peak_usage() - $peak0;
35 35
36 36 $rg_prof_tmp[$label] = $rg_prof_state; $rg_prof_tmp[$label] = $rg_prof_state;
37 $rg_prof_tmp[$label]['time_ms'] = sprintf("%u", microtime(TRUE) * 1000);
37 $rg_prof_tmp[$label]['time'] = sprintf("%u", microtime(TRUE) * 1000);
38 38 $rg_prof_tmp[$label]['mem'] = intval($mem / 1024); $rg_prof_tmp[$label]['mem'] = intval($mem / 1024);
39 39 $rg_prof_tmp[$label]['level'] = 1; $rg_prof_tmp[$label]['level'] = 1;
40 40 $rg_prof_tmp[$label]['runs'] = 1; $rg_prof_tmp[$label]['runs'] = 1;
 
... ... function rg_prof_end($label)
63 63 $mem = memory_get_peak_usage() - $peak0; $mem = memory_get_peak_usage() - $peak0;
64 64
65 65 $c = $rg_prof_state; $c = $rg_prof_state;
66 $c['time_ms'] = sprintf("%u", microtime(TRUE) * 1000);
66 $c['time'] = sprintf("%u", microtime(TRUE) * 1000);
67 67 $c['runs'] = $start['runs']; $start['runs'] = 0; $c['runs'] = $start['runs']; $start['runs'] = 0;
68 68 $c['mem'] = intval($mem / 1024); $c['mem'] = intval($mem / 1024);
69 69 $c['level'] = 0; // just to not complain that is not defined $c['level'] = 0; // just to not complain that is not defined
 
... ... function rg_prof_html()
136 136
137 137 function rg_prof_sort($a, $b) function rg_prof_sort($a, $b)
138 138 { {
139 if (!isset($a['time_ms']))
139 if (!isset($a['time']))
140 140 return 1; return 1;
141 if (!isset($b['time_ms']))
141 if (!isset($b['time']))
142 142 return 1; return 1;
143 143
144 return $a['time_ms'] > $b['time_ms'];
144 return $a['time'] > $b['time'];
145 145 } }
146 146
147 147 function rg_prof_text() function rg_prof_text()
 
... ... function rg_prof_text()
158 158 $vars[$k] = 1; $vars[$k] = 1;
159 159 unset($vars['level']); unset($vars['level']);
160 160
161 // sort by time_ms
161 // sort by time
162 162 uasort($rg_prof_main, "rg_prof_sort"); uasort($rg_prof_main, "rg_prof_sort");
163 163
164 164 $add = ''; $add = '';
 
... ... function rg_prof_text()
171 171
172 172 $add = ""; $add = "";
173 173 foreach ($rg_prof_main as $label => $per_label) { foreach ($rg_prof_main as $label => $per_label) {
174 if (($per_label['time_ms'] == 0) && ($per_label['mem'] < 20))
174 if (($per_label['time'] == 0) && ($per_label['mem'] < 20))
175 175 continue; continue;
176 176
177 177 $ret .= $add; $ret .= $add;
File inc/ratelimit.inc.php changed (mode: 100644) (index 01243f2..c28c23a)
5 5 // TODO: rate limit 404 errors // TODO: rate limit 404 errors
6 6
7 7 /* /*
8 * Returns 1 in case of errors (fake no over limit).
8 * Returns 1 in case of errors (fake "no over limit").
9 9 * Returns >0 when the @ip is under limit (the return value represents how * Returns >0 when the @ip is under limit (the return value represents how
10 10 * many requests are still allowed. * many requests are still allowed.
11 11 * Returns 0 if the user is over limit. * Returns 0 if the user is over limit.
12 12 */ */
13 function rg_rate_limit($db, $ip)
13 function rg_rate_limit($db)
14 14 { {
15 $period = rg_state_get($db, 'rate_limit_period');
16 if (($period === FALSE) || ($period == 0))
17 return 1;
18
19 $limit = rg_state_get($db, 'rate_limit_max');
20 if (($limit === FALSE) || ($limit == 0))
21 return 1;
22
23 $now = time();
24 $t = $now - $period;
25
26 $ip = str_replace(':', '_', $ip); // escape IPv6
27 $r = rg_cache_get('ratelimit::' . $ip);
28 if (($r !== FALSE) && ($r > $now)) {
29 rg_log('IP is over limit (from cache) till ' . $r
30 . ' (' . ($r - $now) . 's)');
31 return 0;
32 }
15 rg_log_enter('rate_limit');
16
17 $ret = 1;
18 while (1) {
19 $period = rg_state_get($db, 'rate_limit_period');
20 if (($period === FALSE) || ($period == 0))
21 break;
22
23 $limit = rg_state_get($db, 'rate_limit_max');
24 if (($limit === FALSE) || ($limit == 0))
25 break;
26
27 $now = time();
28
29 $ip = str_replace(':', '_', rg_ip()); // escape IPv6
30 $row = rg_cache_get('ratelimit::' . $ip);
31 if ($row !== FALSE)
32 rg_log_debug('from cache: row=' . rg_array2string($row));
33 if (($row === FALSE) || ($row['start'] + $period < $now)) {
34 $params = array('t' => time() - $period, 'ip' => $ip);
35 $sql = 'SELECT MIN(itime) AS start, COUNT(1) AS count'
36 . ' FROM conns'
37 . ' WHERE itime >= @@t@@'
38 . ' AND ip = @@ip@@';
39 $res = rg_sql_query_params($db, $sql, $params);
40 if ($res === FALSE)
41 break;
42 $row = rg_sql_fetch_array($res);
43 if ($row['count'] == 0)
44 $row = array('start' => $now, 'count' => 0);
45 rg_sql_free_result($res);
46 rg_log_debug('from db: row=' . rg_array2string($row));
47 }
48
49 $row['count']++;
50 if ($row['count'] > $limit) {
51 rg_log('IP is over limit (' . $limit . ')');
52 $ret = 0;
53 break;
54 }
55
56 rg_cache_set('ratelimit::' . $ip, $row, RG_SOCKET_NO_WAIT);
33 57
34 $params = array('t' => time() - $period, 'ip' => $ip);
35 $sql = 'SELECT MIN(itime) AS min, COUNT(1) AS count FROM conns'
36 . ' WHERE itime >= @@t@@'
37 . ' AND ip = @@ip@@';
38 $res = rg_sql_query_params($db, $sql, $params);
39 if ($res === FALSE)
40 return 1;
41 $row = rg_sql_fetch_array($res);
42 rg_sql_free_result($res);
43
44 if ($row['count'] > $limit) {
45 rg_log('IP is over limit (' . $limit . '); set cache to '
46 . ($row['min'] + $period)
47 . ' (' . ($row['min'] + $period - $now) . 's)');
48 // We want to cache the result, as long as is true
49 rg_cache_set('ratelimit::' . $ip, $row['min'] + $period,
50 RG_SOCKET_NO_WAIT);
51 return 0;
58 rg_log('IP is not over limit (count=' . $row['count'] . '/' . $limit . ')');
59 $ret = $limit - $row['count'];
60 break;
52 61 } }
53 62
54 rg_log('IP is not over limit (count=' . $row['count'] . ')');
55 return $limit - $row['count'];
63 rg_log_exit();
64 return $ret;
56 65 } }
File inc/repo.inc.php changed (mode: 100644) (index d33b8f3..4cf7435)
... ... $rg_repo_rights = array(
40 40 'd' => 'Delete bugs', 'd' => 'Delete bugs',
41 41 'E' => 'Create/edit repo', 'E' => 'Create/edit repo',
42 42 'G' => 'Grant rights', 'G' => 'Grant rights',
43 'g' => 'Revoke rights',
43 44 'K' => 'Lock repo', 'K' => 'Lock repo',
44 45 'r' => 'Reopen bugs', 'r' => 'Reopen bugs',
45 'T' => 'Delete artifacts',
46 46 't' => 'Access artifacts', 't' => 'Access artifacts',
47 'T' => 'Delete artifacts',
47 48 'W' => 'Manage hooks' 'W' => 'Manage hooks'
48 49 ); );
49 50
 
... ... function rg_repo_next_id($db, $field, $repo_id)
94 95 break; break;
95 96 } }
96 97
97 rg_log('DEBUG: next_id=' . $next_id);
98 rg_log_debug('next_id=' . $next_id);
98 99
99 100 rg_log_exit(); rg_log_exit();
100 101 rg_prof_end('repo_next_id'); rg_prof_end('repo_next_id');
 
... ... function rg_repo_cosmetic($db, &$row)
138 139 $_ui['username'], $row['name']); $_ui['username'], $row['name']);
139 140 $row['clone_url_git'] = rg_re_repo_git($_ui['organization'], $row['clone_url_git'] = rg_re_repo_git($_ui['organization'],
140 141 $_ui['username'], $row['name']); $_ui['username'], $row['name']);
141 $row['clone_url_http'] = rg_base_url()
142 $row['clone_url_http'] = rg_base_url($db, '', '')
142 143 . rg_re_repo_http($_ui['organization'], . rg_re_repo_http($_ui['organization'],
143 144 $_ui['username'], $row['name']); $_ui['username'], $row['name']);
144 145 } }
 
... ... function rg_repo_rights_inject($db, $obj_id, $type, $owner, $uid)
260 261 $a['prio'] = 0; $a['prio'] = 0;
261 262 $a['who'] = $owner; // TODO: not clear if correct/good $a['who'] = $owner; // TODO: not clear if correct/good
262 263 $a['right_id'] = 0; $a['right_id'] = 0;
263 $a['ip'] = "";
264 264 $a['can_be_deleted'] = 0; $a['can_be_deleted'] = 0;
265 $a['ip'] = '';
265 266 $a['description'] = "Autogenerated"; $a['description'] = "Autogenerated";
266 267
267 268 if ($uid > 0) { if ($uid > 0) {
 
... ... function rg_repo_rights_inject($db, $obj_id, $type, $owner, $uid)
326 327 return $ret; return $ret;
327 328 } }
328 329
329 /*
330 * Returns TRUE if the login user has @rights rights
331 */
332 function rg_repo_has_rights($db, $rg, $rights)
333 {
334 $x = array();
335 $x['obj_id'] = $rg['ri']['repo_id'];
336 $x['type'] = 'repo';
337 $x['owner'] = $rg['ri']['uid'];
338 $x['uid'] = $rg['login_ui']['uid'];
339 $x['username'] = $rg['login_ui']['username'];
340 $x['needed_rights'] = $rights;
341 $x['ip'] = $rg['ip'];
342 $x['misc'] = '';
343 return rg_rights_allow($db, $x);
344 }
345
346 330 /* /*
347 331 * Bring a ref to a canonical format (refs/x/name) * Bring a ref to a canonical format (refs/x/name)
348 332 * TODO: move to git.inc? * TODO: move to git.inc?
 
... ... function rg_repo_event_symlink_by_name($db, $e)
543 527 { {
544 528 rg_prof_start("repo_event_symlink_by_name"); rg_prof_start("repo_event_symlink_by_name");
545 529
546 $id_path = rg_repo_path_by_id($e['ui']['uid'], $e['ri']['repo_id']);
547 $id_path_rel = rg_repo_path_by_id_rel($e['ui']['uid'], $e['ri']['repo_id']);
548 $new_path = rg_repo_path_by_name($e['ui']['uid'], $e['ri']['name']);
530 $id_path = rg_repo_path_by_id($e['ui_login']['uid'], $e['ri']['repo_id']);
531 $id_path_rel = rg_repo_path_by_id_rel($e['ui_login']['uid'], $e['ri']['repo_id']);
532 $new_path = rg_repo_path_by_name($e['ui_login']['uid'], $e['ri']['name']);
549 533
550 534 $ret = FALSE; $ret = FALSE;
551 535 while (1) { while (1) {
 
... ... function rg_repo_event_storage_create($db, $e)
612 596
613 597 $ret = FALSE; $ret = FALSE;
614 598 while (1) { while (1) {
615 $by_id_path = rg_repo_path_by_id($e['ui']['uid'], $e['ri']['repo_id']);
599 $by_id_path = rg_repo_path_by_id($e['ui_login']['uid'], $e['ri']['repo_id']);
616 600 if (!is_dir($by_id_path)) { if (!is_dir($by_id_path)) {
617 601 if (mkdir($by_id_path, 0700, TRUE) === FALSE) { if (mkdir($by_id_path, 0700, TRUE) === FALSE) {
618 602 rg_repo_set_error("could not create folder $dst"); rg_repo_set_error("could not create folder $dst");
 
... ... function rg_repo_history_insert($db, $event)
715 699 rg_prof_start("repo_history_insert"); rg_prof_start("repo_history_insert");
716 700 rg_log_enter("repo_history_insert: event=" . rg_array2string($event)); rg_log_enter("repo_history_insert: event=" . rg_array2string($event));
717 701
718 if (!isset($event['ui']['uid']))
719 $event['ui']['uid'] = 0;
720
721 702 $ret = FALSE; $ret = FALSE;
722 703 while (1) { while (1) {
723 704 $now = time(); $now = time();
724 705 $params = array("now" => $now, $params = array("now" => $now,
725 706 "repo_id" => $event['ri']['repo_id'], "repo_id" => $event['ri']['repo_id'],
726 "uid" => $event['ui']['uid'],
707 "uid" => $event['ui_login']['uid'],
727 708 "cat" => $event['history_category'], "cat" => $event['history_category'],
728 709 "mess" => $event['history_message']); "mess" => $event['history_message']);
729 710 $sql = "INSERT INTO repo_history_" . gmdate("Y_m", $now) $sql = "INSERT INTO repo_history_" . gmdate("Y_m", $now)
 
... ... function rg_repo_event_push($db, $event)
780 761 * Returns last events from repo_history * Returns last events from repo_history
781 762 * @category: 0 for any * @category: 0 for any
782 763 * @number: number of entries * @number: number of entries
783 * @max_seconds: limit the search to less than max_seconds in the past
764 * @min_time: limit the search to earlier than min_time timestamp
784 765 */ */
785 function rg_repo_history_load($db, $repo_id, $category, $number, $max_seconds)
766 function rg_repo_history_load($db, $repo_id, $category, $number, $min_time)
786 767 { {
787 768 rg_prof_start("repo_history_load"); rg_prof_start("repo_history_load");
788 rg_log_enter("repo_history_load: repo_id=$repo_id, category=$category"
789 . ", number=$number max_seconds=$max_seconds");
769 rg_log_enter('repo_history_load: repo_id=' . $repo_id . ' category=' . $category
770 . ', number=' . $number . ' min_time=' . $min_time);
790 771
791 772 $ret = FALSE; $ret = FALSE;
792 773 while (1) { while (1) {
 
... ... function rg_repo_history_load($db, $repo_id, $category, $number, $max_seconds)
802 783 else else
803 784 $limit_sql = " LIMIT 50"; $limit_sql = " LIMIT 50";
804 785
805 $time_sql = "";
806 if ($max_seconds > 0)
807 $time_sql = " AND itime >= " . ($now - $max_seconds);
786 $time_sql = '';
787 if ($min_time > 0)
788 $time_sql = ' AND itime >= ' . $min_time;
808 789
809 $sql = "SELECT * FROM repo_history"
810 . " WHERE repo_id = $repo_id"
790 $sql = 'SELECT itime, category, message, uid'
791 . ' FROM repo_history'
792 . ' WHERE repo_id = ' . $repo_id
811 793 . $category_sql . $category_sql
812 794 . $time_sql . $time_sql
813 . " ORDER BY itime DESC"
795 . ' ORDER BY itime DESC'
814 796 . $limit_sql; . $limit_sql;
815 797 $res = rg_sql_query($db, $sql); $res = rg_sql_query($db, $sql);
816 798 if ($res === FALSE) if ($res === FALSE)
 
... ... function rg_repo_path_by_name($uid, $repo_name)
929 911 /* /*
930 912 * Delete a repo * Delete a repo
931 913 */ */
932 function rg_repo_delete($db, $repo_id, $ui)
914 function rg_repo_delete($db, $repo_id, $ui_login)
933 915 { {
934 916 rg_prof_start("repo_delete"); rg_prof_start("repo_delete");
935 rg_log_enter("repo_delete: uid=" . $ui['uid'] . ", repo_id=$repo_id");
917 rg_log_enter("repo_delete: uid=" . $ui_login['uid'] . ", repo_id=$repo_id");
936 918
937 919 $ret = FALSE; $ret = FALSE;
938 920 while (1) { while (1) {
 
... ... function rg_repo_delete($db, $repo_id, $ui)
960 942 $event = array( $event = array(
961 943 'category' => 'repo_event_del', 'category' => 'repo_event_del',
962 944 'prio' => 50, 'prio' => 50,
963 'ui' => $ui,
945 'ui_login' => $ui_login,
964 946 'ri' => array( 'ri' => array(
965 947 'name' => $ri['name'], 'name' => $ri['name'],
966 948 'repo_id' => $repo_id 'repo_id' => $repo_id
 
... ... function rg_repo_delete($db, $repo_id, $ui)
975 957 rg_event_signal_daemon("", 0); rg_event_signal_daemon("", 0);
976 958
977 959 rg_cache_unset('repo_by_id::' . $repo_id, RG_SOCKET_NO_WAIT); rg_cache_unset('repo_by_id::' . $repo_id, RG_SOCKET_NO_WAIT);
978 rg_cache_unset('repo_by_name::' . $ui['uid']
960 rg_cache_unset('repo_by_name::' . $ui_login['uid']
979 961 . '::' . $ri['name'], RG_SOCKET_NO_WAIT); . '::' . $ri['name'], RG_SOCKET_NO_WAIT);
980 rg_cache_unset('user' . '::' . $ui['uid'] . '::' . 'has_repos',
962 rg_cache_unset('user' . '::' . $ui_login['uid'] . '::' . 'has_repos',
981 963 RG_SOCKET_NO_WAIT); RG_SOCKET_NO_WAIT);
982 964
983 965 $ret = TRUE; $ret = TRUE;
 
... ... function rg_repo_insert_rename($db, $uid, $repo_id, $old_name)
1085 1067
1086 1068 /* /*
1087 1069 * Creates/updates a repository * Creates/updates a repository
1088 * @login_ui - info of the user doing the update.
1070 * @ui_login - info of the user doing the update.
1089 1071 * TODO: Warning, it may not be the owner. * TODO: Warning, it may not be the owner.
1090 1072 * TODO: where do we validate if the user has enough public/private slots? * TODO: where do we validate if the user has enough public/private slots?
1091 1073 */ */
1092 function rg_repo_edit($db, $login_ui, &$new)
1074 function rg_repo_edit($db, $ui_login, &$new)
1093 1075 { {
1094 1076 rg_prof_start("repo_edit"); rg_prof_start("repo_edit");
1095 rg_log_enter("repo_edit: login_uid=" . $login_ui['uid']
1096 . " new=" . rg_array2string($new));
1077 rg_log_enter('repo_edit: login_uid=' . $ui_login['uid']
1078 . ' new=' . rg_array2string($new));
1097 1079
1098 1080 // TODO: test if user is allowed to add a repository // TODO: test if user is allowed to add a repository
1099 1081 // TODO: test if user did not cross the limit for number of repos // TODO: test if user did not cross the limit for number of repos
 
... ... function rg_repo_edit($db, $login_ui, &$new)
1105 1087
1106 1088 if ($new['repo_id'] == 0) { if ($new['repo_id'] == 0) {
1107 1089 // Check if name is already taken // Check if name is already taken
1108 $ri = rg_repo_info($db, 0, $login_ui['uid'],
1090 $ri = rg_repo_info($db, 0, $ui_login['uid'],
1109 1091 $new['name']); $new['name']);
1110 1092 if ($ri['ok'] != 1) if ($ri['ok'] != 1)
1111 1093 break; break;
 
... ... function rg_repo_edit($db, $login_ui, &$new)
1118 1100 // Test if repo_id is valid // Test if repo_id is valid
1119 1101 // TODO: also here we must test if we have a dup name! // TODO: also here we must test if we have a dup name!
1120 1102 $ri = rg_repo_info($db, $new['repo_id'], $ri = rg_repo_info($db, $new['repo_id'],
1121 $login_ui['uid'], "");
1103 $ui_login['uid'], '');
1122 1104 if ($ri['ok'] != 1) if ($ri['ok'] != 1)
1123 1105 break; break;
1124 1106 if ($ri['exists'] != 1) { if ($ri['exists'] != 1) {
 
... ... function rg_repo_edit($db, $login_ui, &$new)
1133 1115 // Check if the user renamed the repo // Check if the user renamed the repo
1134 1116 if (strcmp($new['name'], $ri['name']) != 0) { if (strcmp($new['name'], $ri['name']) != 0) {
1135 1117 $renamed = 1; $renamed = 1;
1136 $r = rg_repo_insert_rename($db, $login_ui['uid'],
1118 $r = rg_repo_insert_rename($db, $ui_login['uid'],
1137 1119 $new['repo_id'], $ri['name']); $new['repo_id'], $ri['name']);
1138 1120 if ($r !== TRUE) if ($r !== TRUE)
1139 1121 break; break;
 
... ... function rg_repo_edit($db, $login_ui, &$new)
1144 1126
1145 1127 // Small fixes // Small fixes
1146 1128 $new['itime'] = time(); $new['itime'] = time();
1147 $new['uid'] = $login_ui['uid'];
1129 $new['uid'] = $ui_login['uid'];
1148 1130 if (!isset($new['main_branch'])) if (!isset($new['main_branch']))
1149 1131 $new['main_branch'] = ''; $new['main_branch'] = '';
1150 1132
 
... ... function rg_repo_edit($db, $login_ui, &$new)
1192 1174 $cat = 'repo_event_new'; $cat = 'repo_event_new';
1193 1175 $hcat = REPO_CAT_CREATE; $hcat = REPO_CAT_CREATE;
1194 1176 $hmess = "Repository has been created"; $hmess = "Repository has been created";
1195 $notification = "repo_create-" . $login_ui['uid']
1196 . "-" . $row['repo_id'];
1177 $notification = 'repo_create-' . $ui_login['uid']
1178 . '-' . $row['repo_id'];
1197 1179 $old_description = ""; $old_description = "";
1198 1180 $new['repo_id'] = $row['repo_id']; $new['repo_id'] = $row['repo_id'];
1199 1181 } else { } else {
 
... ... function rg_repo_edit($db, $login_ui, &$new)
1209 1191 'category' => $cat, 'category' => $cat,
1210 1192 'prio' => 50, 'prio' => 50,
1211 1193 'notification' => $notification, 'notification' => $notification,
1212 'ui' => $login_ui,
1194 'ui_login' => $ui_login,
1213 1195 'history_category' => $hcat, 'history_category' => $hcat,
1214 1196 'history_message' => $hmess); 'history_message' => $hmess);
1215 1197 $event = rg_array_merge($event, 'ri_old', $ri); $event = rg_array_merge($event, 'ri_old', $ri);
1216 $new['url'] = rg_base_url()
1217 . rg_re_repopage($login_ui, $new['name']);
1198 $new['url'] = rg_base_url($db, '', '')
1199 . rg_re_repopage($ui_login, $new['name']);
1218 1200 $event = rg_array_merge($event, 'ri', $new); $event = rg_array_merge($event, 'ri', $new);
1219 1201 $event['ri_old']['description_md5'] = md5($old_description); $event['ri_old']['description_md5'] = md5($old_description);
1220 1202 $event['ri']['description_md5'] = md5($new['description']); $event['ri']['description_md5'] = md5($new['description']);
 
... ... function rg_repo_edit($db, $login_ui, &$new)
1229 1211 $new['exists'] = 1; $new['exists'] = 1;
1230 1212 rg_cache_merge("repo_by_id::" . $new['repo_id'], $new, rg_cache_merge("repo_by_id::" . $new['repo_id'], $new,
1231 1213 RG_SOCKET_NO_WAIT); RG_SOCKET_NO_WAIT);
1232 rg_cache_set("repo_by_name::" . $login_ui['uid'] . "::"
1214 rg_cache_set("repo_by_name::" . $ui_login['uid'] . "::"
1233 1215 . $new['name'], $new['repo_id'], RG_SOCKET_NO_WAIT); . $new['name'], $new['repo_id'], RG_SOCKET_NO_WAIT);
1234 1216
1235 1217 rg_event_signal_daemon('', 0); rg_event_signal_daemon('', 0);
 
... ... function rg_repo_have($db, $uid)
1281 1263 /* /*
1282 1264 * List repositories * List repositories
1283 1265 */ */
1284 function rg_repo_list_query($db, $url, $sql, $params, $login_ui)
1266 function rg_repo_list_query($db, $url, $sql, $params, $ui_login)
1285 1267 { {
1286 1268 rg_prof_start("repo_list_query"); rg_prof_start("repo_list_query");
1287 1269 rg_log("repo_list_query: url=$url, sql=$sql..."); rg_log("repo_list_query: url=$url, sql=$sql...");
 
... ... function rg_repo_list_query($db, $url, $sql, $params, $login_ui)
1312 1294 rg_sql_free_result($res); rg_sql_free_result($res);
1313 1295
1314 1296 rg_prof_end("repo_list_query"); rg_prof_end("repo_list_query");
1315 return rg_template_table("repo/list", $d, $login_ui);
1297 return rg_template_table('repo/list', $d, $ui_login);
1316 1298 } }
1317 1299
1318 1300 /* /*
1319 * List repos of page user 'ui'.
1301 * List repos of page user 'ui_login'.
1320 1302 * @uid - owner of the to be listed repos * @uid - owner of the to be listed repos
1321 1303 */ */
1322 1304 function rg_repo_list($db, $rg, $url, $uid, $limit) function rg_repo_list($db, $rg, $url, $uid, $limit)
1323 1305 { {
1324 rg_log("repo_list: url=$url uid=" . $uid
1325 . " login_uid=" . $rg['login_ui']['uid']);
1306 rg_log('repo_list: url=' . $url . ' uid=' . $uid);
1326 1307
1308 $ui_login = rg_ui_login();
1327 1309 $params = array( $params = array(
1328 "uid" => $uid,
1329 "login_uid" => $rg['login_ui']['uid']);
1310 'uid' => $uid,
1311 'login_uid' => $ui_login['uid']);
1330 1312
1331 1313 if ($uid > 0) if ($uid > 0)
1332 1314 $add = ' AND uid = @@uid@@'; $add = ' AND uid = @@uid@@';
 
... ... function rg_repo_list($db, $rg, $url, $uid, $limit)
1334 1316 $add = ' AND uid != @@login_uid@@'; $add = ' AND uid != @@login_uid@@';
1335 1317
1336 1318 // TODO: also admin must be able to see them? // TODO: also admin must be able to see them?
1337 if (($rg['login_ui']['uid'] == 0)
1338 || ($rg['login_ui']['uid'] != $uid))
1339 $add .= " AND public = 1";
1319 if (($ui_login['uid'] == 0) || ($ui_login['uid'] != $uid))
1320 $add .= ' AND public = 1';
1340 1321
1341 1322 if ($limit > 0) if ($limit > 0)
1342 1323 $add_limit = ' LIMIT ' . $limit; $add_limit = ' LIMIT ' . $limit;
 
... ... function rg_repo_list($db, $rg, $url, $uid, $limit)
1349 1330 . ' ORDER BY name' . ' ORDER BY name'
1350 1331 . $add_limit; . $add_limit;
1351 1332
1352 return rg_repo_list_query($db, $url, $sql, $params, $rg['login_ui']);
1333 return rg_repo_list_query($db, $url, $sql, $params, $ui_login);
1353 1334 } }
1354 1335
1355 1336 /* /*
1356 * Search in all repositories owned by 'login_ui' or public
1337 * Search in all repositories owned by 'ui_login' or public
1357 1338 * We need to exclude private repositories. * We need to exclude private repositories.
1358 1339 */ */
1359 function rg_repo_search($db, $login_ui, $q)
1340 function rg_repo_search($db, $ui_login, $q)
1360 1341 { {
1361 1342 rg_prof_start("repo_search"); rg_prof_start("repo_search");
1362 1343 rg_log("repo_search: q=[$q]"); rg_log("repo_search: q=[$q]");
1363 1344
1364 1345 $admin = 0; $admin = 0;
1365 if (isset($login_ui['admin']) && ($login_ui['admin'] == 1))
1346 if (isset($ui_login['admin']) && ($ui_login['admin'] == 1))
1366 1347 $admin = 1; $admin = 1;
1367 1348
1368 1349 $params = array("q" => "%" . $q . "%", $params = array("q" => "%" . $q . "%",
1369 "uid" => $login_ui['uid']);
1350 'uid' => $ui_login['uid']);
1370 1351
1371 1352 $sql = "SELECT * FROM repos" $sql = "SELECT * FROM repos"
1372 1353 . " WHERE deleted = 0" . " WHERE deleted = 0"
 
... ... function rg_repo_search($db, $login_ui, $q)
1374 1355 . " AND (name ILIKE @@q@@ OR description ILIKE @@q@@)" . " AND (name ILIKE @@q@@ OR description ILIKE @@q@@)"
1375 1356 . " ORDER BY master, name" . " ORDER BY master, name"
1376 1357 . " LIMIT 50"; . " LIMIT 50";
1377 $r = rg_repo_list_query($db, "", $sql, $params, $login_ui);
1358 $r = rg_repo_list_query($db, "", $sql, $params, $ui_login);
1378 1359
1379 1360 rg_prof_end("repo_search"); rg_prof_end("repo_search");
1380 1361 return $r; return $r;
 
... ... function rg_repo_size($uid, $repo_id)
1389 1370 $git = rg_dir_size($git_path); $git = rg_dir_size($git_path);
1390 1371 if ($git === FALSE) if ($git === FALSE)
1391 1372 return FALSE; return FALSE;
1392 //rg_log_ml('DEBUG: XXX: git:' . print_r($git, TRUE));
1373 //rg_log_debug('XXX: git:' . print_r($git, TRUE));
1393 1374 $git_size = intval($git['blocks'] / 2 / 1024); $git_size = intval($git['blocks'] / 2 / 1024);
1394 1375
1395 1376 $artifact_path = rg_repo_artifacts_path_by_id($uid, $repo_id); $artifact_path = rg_repo_artifacts_path_by_id($uid, $repo_id);
1396 1377 $a = rg_dir_size($artifact_path); $a = rg_dir_size($artifact_path);
1397 1378 if ($a === FALSE) if ($a === FALSE)
1398 1379 return FALSE; return FALSE;
1399 //rg_log_ml('DEBUG: XXX: a:' . print_r($a, TRUE));
1380 //rg_log_debug('XXX: a:' . print_r($a, TRUE));
1400 1381 $a_size = intval($a['blocks'] / 2 / 1024); $a_size = intval($a['blocks'] / 2 / 1024);
1401 1382
1402 1383 return array( return array(
 
... ... function rg_repo_lock($db, $repo_id, $uid, $lock, $reason)
1535 1516 rg_cache_unset($key, RG_SOCKET_NO_WAIT); rg_cache_unset($key, RG_SOCKET_NO_WAIT);
1536 1517 } }
1537 1518
1538 $h = array('ri' => array(), 'ui' => array());
1519 $h = array('ri' => array(), 'ui_login' => array());
1539 1520 $h['ri']['repo_id'] = $repo_id; $h['ri']['repo_id'] = $repo_id;
1540 $h['ui']['uid'] = $uid;
1521 $h['ui_login']['uid'] = $uid;
1541 1522 $h['history_category'] = $lock == 1 ? REPO_CAT_LOCK : REPO_CAT_UNLOCK; $h['history_category'] = $lock == 1 ? REPO_CAT_LOCK : REPO_CAT_UNLOCK;
1542 1523 $h['history_message'] = 'Repository ' . $h['history_message'] = 'Repository ' .
1543 1524 ($lock == 1 ? 'locked' : 'unlocked') . ': ' . $reason; ($lock == 1 ? 'locked' : 'unlocked') . ': ' . $reason;
 
... ... function rg_repo_data($db, $type, $start, $end, $unit, $mode)
1561 1542 $params = array('start' => $start, 'end' => $end); $params = array('start' => $start, 'end' => $end);
1562 1543 switch ($type) { switch ($type) {
1563 1544 case 'create_repo': case 'create_repo':
1564 $q = 'SELECT 1 AS value, itime FROM repos'
1545 $q = 'SELECT itime FROM repos'
1565 1546 . ' WHERE itime >= @@start@@ AND itime <= @@end@@'; . ' WHERE itime >= @@start@@ AND itime <= @@end@@';
1566 1547 break; break;
1567 1548 case 'create_bug': case 'create_bug':
1568 $q = 'SELECT 1 AS value, itime FROM bugs'
1549 $q = 'SELECT itime FROM bugs'
1569 1550 . ' WHERE itime >= @@start@@ AND itime <= @@end@@'; . ' WHERE itime >= @@start@@ AND itime <= @@end@@';
1570 1551 break; break;
1571 1552 case 'history': case 'history':
1572 $q = 'SELECT 1 AS value, itime FROM repo_history'
1553 $q = 'SELECT itime FROM repo_history'
1573 1554 . ' WHERE itime >= @@start@@ AND itime <= @@end@@'; . ' WHERE itime >= @@start@@ AND itime <= @@end@@';
1574 1555 break; break;
1575 1556 default: default:
 
... ... function rg_repo_data($db, $type, $start, $end, $unit, $mode)
1589 1570 */ */
1590 1571 function rg_repo_admin_rights($db, $rg, $type) function rg_repo_admin_rights($db, $rg, $type)
1591 1572 { {
1592 rg_log("rg_repo_admin_rights type=$type");
1593
1594 /* 'repo' is correct here, we test for granting rights on repo */
1595 $x = array();
1596 $x['obj_id'] = $rg['ri']['repo_id'];
1597 $x['type'] = 'repo';
1598 $x['owner'] = $rg['ri']['uid'];
1599 $x['uid'] = $rg['login_ui']['uid'];
1600 $x['username'] = $rg['login_ui']['username'];
1601 $x['needed_rights'] = 'G';
1602 $x['ip'] = $rg['ip'];
1603 $x['misc'] = "";
1604 if (rg_rights_allow($db, $x) !== TRUE)
1605 return rg_template("user/repo/rights/deny.html", $rg, TRUE /* xss */);
1606
1607 $ret = "";
1573 rg_log('rg_repo_admin_rights type=' . $type);
1608 1574
1609 $a = array();
1610 $a['type'] = $type;
1611 $a['right_id'] = rg_var_uint("right_id");
1612 $a['edit_id'] = rg_var_uint("edit_id");
1613 $a['username'] = trim(rg_var_str("username"));
1614 $a['rights'] = rg_rights_a2s(rg_var_str("rights"));
1615 $a['misc'] = trim(rg_var_str("misc"));
1616 $a['ip'] = trim(rg_var_str("ip"));
1617 $a['prio'] = rg_var_uint("prio");
1618 $a['description'] = trim(rg_var_str("description"));
1619 //rg_log_ml("CHECK: a(POST)=" . print_r($a, TRUE));
1575 $obj_id = $rg['ri']['repo_id'];
1620 1576
1621 $errmsg = array();
1622 $list_errmsg = array();
1623
1624 $load_defaults = 1;
1625
1626 $delete = rg_var_bool("delete");
1627 while ($delete == 1) {
1628 if (!rg_valid_referer()) {
1629 $errmsg[] = "invalid referer; try again";
1630 break;
1631 }
1632
1633 if (!rg_token_valid($db, $rg, 'repo_admin_rights', FALSE)) {
1634 $errmsg[] = "invalid token; try again";
1635 break;
1636 }
1637
1638 $list = rg_var_uint("rights_delete_ids");
1639 if (empty($list)) {
1640 $list_errmsg[] = "please select at least one item";
1641 break;
1642 }
1643
1644 $my_list = array();
1645 foreach ($list as $k => $junk)
1646 $my_list[] = $k;
1647
1648 $r = rg_rights_delete_list($db, $type, $rg['ri']['repo_id'], $my_list);
1649 if ($r !== TRUE) {
1650 $list_errmsg[] = "cannot delete rights: " . rg_rights_error();
1651 break;
1652 }
1653
1654 $ret .= rg_template("user/repo/rights/delete_ok.html", $rg, TRUE /* xss */);
1655 break;
1656 }
1657
1658 // edit
1659 while ($a['edit_id'] > 0) {
1660 $owner = $rg['ri']['uid'];
1661 $r = rg_rights_get($db, $rg['ri']['repo_id'], $type,
1662 $owner, -1, $a['edit_id']);
1663 if ($r['ok'] != 1) {
1664 $list_errmsg[] = "cannot load rights: " . rg_rights_error();
1665 break;
1666 }
1667
1668 if (empty($r['list'])) {
1669 $list_errmsg[] = "right not found";
1670 break;
1671 }
1577 if (rg_rights_allow2($db, 'repo', $obj_id, 'G', '') !== TRUE)
1578 return rg_template('rights/deny.html', $rg, TRUE /*xss*/);
1672 1579
1673 // Only one right is returned when we edit by right_id
1674 $a = $r['list'][0];
1675
1676 $load_defaults = 0;
1677 break;
1678 }
1679
1680 $grant = rg_var_bool("grant");
1681 while ($grant == 1) {
1682 $load_defaults = 0;
1683
1684 if (!rg_valid_referer()) {
1685 $errmsg[] = "invalid referer; try again";
1686 break;
1687 }
1688
1689 if (!rg_token_valid($db, $rg, 'repo_admin_rights', FALSE)) {
1690 $errmsg[] = "invalid token; try again";
1691 break;
1692 }
1693
1694 if (strcmp($a['username'], '*') == 0) {
1695 $a['uid'] = 0;
1696 } else {
1697 $_ui = rg_user_info($db, 0, $a['username'], "");
1698 if ($_ui['exists'] == 1) {
1699 $a['uid'] = $_ui['uid'];
1700 } else {
1701 $errmsg[] = rg_user_error();
1702 break;
1703 }
1704 }
1705
1706 $a['obj_id'] = $rg['ri']['repo_id'];
1707 $a['who'] = $rg['login_ui']['uid'];
1708 $r = rg_rights_set($db, $type, $a);
1709 if ($r !== TRUE) {
1710 $errmsg[] = rg_rights_error();
1711 break;
1712 }
1713
1714 $ret .= rg_template("user/repo/rights/grant_ok.html", $rg, TRUE /* xss */);
1715
1716 $load_defaults = 1;
1717 break;
1718 }
1719
1720 if ($load_defaults == 1) {
1721 $rg['right_id'] = 0;
1722 $rg['username'] = "";
1723 $rg['rights'] = rg_rights_default($type);
1724 $rg['description'] = "";
1725 $rg['misc'] = "";
1726 $rg['ip'] = "";
1727 $rg['prio'] = 100;
1728 } else {
1729 $rg = rg_array_merge($rg, '', $a);
1730 }
1731
1732 $rg['rg_form_token'] = rg_token_get($db, $rg, 'repo_admin_rights');
1733 $rg['HTML:errmsg'] = rg_template_errmsg($errmsg);
1734 $rg['HTML:list_errmsg'] = rg_template_errmsg($list_errmsg);
1735 $rg['HTML:rights_checkboxes'] = rg_rights_checkboxes($type, "rights",
1736 $rg['rights']);
1737
1738 // list rights
1739 $r = rg_rights_get($db, $rg['ri']['repo_id'], $type, $rg['ri']['uid'],
1740 -1, 0);
1741 if ($r['ok'] != 1)
1742 $ret .= rg_warning("Cannot load rights. Try later.");
1743 else
1744 $ret .= rg_template_table("user/repo/rights/list_" . $type,
1745 $r['list'], $rg);
1746
1747 $ret .= rg_template("user/repo/rights/form_" . $type . ".html", $rg, TRUE /* xss */);
1748
1749 // hints
1750 $hints = array();
1751 $hints[]['HTML:hint'] = rg_template("hints/repo/edit_rights.html",
1752 $rg, TRUE /* xss */);
1753 $hints[]['HTML:hint'] = rg_template("hints/repo/edit_"
1754 . $type . "_rights.html", $rg, TRUE /* xss */);
1755 $ret .= rg_template_table("hints/list", $hints, $rg);
1756
1757 return $ret;
1580 $owner = $rg['ri']['uid'];
1581 return rg_rights_high_level($db, $rg, 'repo', $type, $owner, $obj_id);
1758 1582 } }
1759 1583
1760 1584 /* /*
 
... ... function rg_repo_admin_delete($db, $rg)
1764 1588 { {
1765 1589 $ret = ""; $ret = "";
1766 1590
1767 $x = array();
1768 $x['obj_id'] = $rg['ri']['repo_id'];
1769 $x['type'] = 'repo';
1770 $x['owner'] = $rg['ri']['uid'];
1771 $x['uid'] = $rg['login_ui']['uid'];
1772 $x['username'] = $rg['login_ui']['username'];
1773 $x['needed_rights'] = 'D';
1774 $x['ip'] = $rg['ip'];
1775 $x['misc'] = "";
1776 if (rg_rights_allow($db, $x) !== TRUE)
1591 $obj_id = $rg['ri']['repo_id'];
1592 if (rg_rights_allow2($db, 'repo', $obj_id, 'D', '') !== TRUE)
1777 1593 return rg_template("user/repo/delete/deny.html", $rg, TRUE /* xss */); return rg_template("user/repo/delete/deny.html", $rg, TRUE /* xss */);
1778 1594
1779 1595 $are_you_sure = rg_var_uint("are_you_sure"); $are_you_sure = rg_var_uint("are_you_sure");
 
... ... function rg_repo_admin_delete($db, $rg)
1803 1619 } }
1804 1620
1805 1621 rg_log_ml("CHECK: rg: " . print_r($rg, TRUE)); rg_log_ml("CHECK: rg: " . print_r($rg, TRUE));
1806 $r = rg_repo_delete($db, $rg['ri']['repo_id'], $rg['login_ui']);
1622 $ui_login = rg_ui_login();
1623 $r = rg_repo_delete($db, $rg['ri']['repo_id'], $ui_login);
1807 1624 if ($r === FALSE) { if ($r === FALSE) {
1808 1625 $errmsg[] = rg_repo_error(); $errmsg[] = rg_repo_error();
1809 1626 break; break;
 
... ... function rg_repo_edit_high_level($db, &$rg)
1854 1671 else else
1855 1672 $edit = FALSE; $edit = FALSE;
1856 1673
1674 $ui_login = rg_ui_login();
1675
1857 1676 // User is not logged in? // User is not logged in?
1858 if (!$edit && ($rg['login_ui']['uid'] == 0)) {
1859 $ret .= rg_template("user/repo/deny_create.html", $rg, TRUE /* xss */);
1677 if (!$edit && ($ui_login['uid'] == 0)) {
1678 $ret .= rg_template('user/repo/deny_create.html', $rg, TRUE /*xss*/);
1860 1679 $load_form = FALSE; $load_form = FALSE;
1861 1680 break; break;
1862 1681 } }
1863 1682
1864 1683 if ($edit) { if ($edit) {
1865 $x = array();
1866 $x['obj_id'] = $rg['ri']['repo_id'];
1867 $x['type'] = 'repo';
1868 $x['owner'] = $rg['ri']['uid'];
1869 $x['uid'] = $rg['login_ui']['uid'];
1870 $x['username'] = $rg['login_ui']['username'];
1871 $x['needed_rights'] = 'E'; // E = create/edit
1872 $x['ip'] = $rg['ip'];
1873 $x['misc'] = "";
1874 if (rg_rights_allow($db, $x) !== TRUE) {
1875 $ret .= rg_template("user/repo/deny_edit.html", $rg, TRUE /* xss */);
1684 $obj_id = $rg['ri']['repo_id'];
1685 if (rg_rights_allow2($db, 'repo', $obj_id, 'E', '') !== TRUE) {
1686 $ret .= rg_template('user/repo/deny_edit.html',
1687 $rg, TRUE /*xss*/);
1876 1688 $load_form = FALSE; $load_form = FALSE;
1877 1689 break; break;
1878 1690 } }
 
... ... function rg_repo_edit_high_level($db, &$rg)
1922 1734 break; break;
1923 1735 } }
1924 1736
1925 $r = rg_repo_edit($db, $rg['login_ui'], $rg['ri']);
1737 $r = rg_repo_edit($db, $ui_login, $rg['ri']);
1926 1738 if ($r === FALSE) { if ($r === FALSE) {
1927 1739 $errmsg[] = rg_repo_error(); $errmsg[] = rg_repo_error();
1928 1740 break; break;
1929 1741 } }
1930 1742
1931 $rg['ri']['home'] = rg_re_repopage($rg['login_ui'],
1932 $rg['ri']['name']);
1743 $rg['ri']['home'] = rg_re_repopage($ui_login, $rg['ri']['name']);
1933 1744 if ($edit) { if ($edit) {
1934 1745 $ret .= rg_template("repo/edit_ok.html", $rg, TRUE /*xss*/); $ret .= rg_template("repo/edit_ok.html", $rg, TRUE /*xss*/);
1935 1746 } else { } else {
 
... ... function rg_repo_lock_high_level($db, &$rg)
1974 1785 $errmsg = array(); $errmsg = array();
1975 1786 $show_form = TRUE; $show_form = TRUE;
1976 1787 while (1) { while (1) {
1977 $x = array();
1978 $x['obj_id'] = $rg['ri']['repo_id'];
1979 $x['type'] = 'repo';
1980 $x['owner'] = $rg['ri']['uid'];
1981 $x['uid'] = $rg['login_ui']['uid'];
1982 $x['username'] = $rg['login_ui']['username'];
1983 $x['needed_rights'] = 'K';
1984 $x['ip'] = $rg['ip'];
1985 $x['misc'] = '';
1986 if (rg_rights_allow($db, $x) !== TRUE) {
1788 $obj_id = $rg['ri']['repo_id'];
1789 if (rg_rights_allow2($db, 'repo', $obj_id, 'K', '') !== TRUE) {
1987 1790 $ret .= rg_template("user/repo/deny_lock.html", $ret .= rg_template("user/repo/deny_lock.html",
1988 1791 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
1989 1792 $show_form = FALSE; $show_form = FALSE;
 
... ... function rg_repo_lock_high_level($db, &$rg)
2014 1817 break; break;
2015 1818 } }
2016 1819
1820 $ui_login = rg_ui_login();
2017 1821 $r = rg_repo_lock($db, $rg['ri']['repo_id'], $r = rg_repo_lock($db, $rg['ri']['repo_id'],
2018 $rg['login_ui']['uid'], $lock, $rg['ri']['reason']);
1822 $ui_login['uid'], $lock, $rg['ri']['reason']);
2019 1823 if ($r === FALSE) { if ($r === FALSE) {
2020 1824 $errmsg[] = rg_repo_error(); $errmsg[] = rg_repo_error();
2021 1825 break; break;
 
... ... function rg_repo_admin($db, &$rg, $paras)
2066 1870 $rg['allow_grant_rights'] = 0; $rg['allow_grant_rights'] = 0;
2067 1871 $rg['allow_delete_repo'] = 0; $rg['allow_delete_repo'] = 0;
2068 1872
2069 $x = array();
2070 $x['obj_id'] = $rg['ri']['repo_id'];
2071 $x['type'] = 'repo';
2072 $x['owner'] = $rg['ri']['uid'];
2073 $x['uid'] = $rg['login_ui']['uid'];
2074 $x['username'] = $rg['login_ui']['username'];
2075 $x['ip'] = $rg['ip'];
2076 $x['misc'] = '';
2077
2078 $x['needed_rights'] = 'E';
2079 if (rg_rights_allow($db, $x) === TRUE)
1873 $obj_id = $rg['ri']['repo_id'];
1874 if (rg_rights_allow2($db, 'repo', $obj_id, 'E', '') === TRUE)
2080 1875 $rg['allow_edit_repo'] = 1; $rg['allow_edit_repo'] = 1;
2081 $x['needed_rights'] = 'K';
2082 if (rg_rights_allow($db, $x) === TRUE)
1876 if (rg_rights_allow2($db, 'repo', $obj_id, 'K', '') === TRUE)
2083 1877 $rg['allow_lock_repo'] = 1; $rg['allow_lock_repo'] = 1;
2084 $x['needed_rights'] = 'G';
2085 if (rg_rights_allow($db, $x) === TRUE)
1878 if (rg_rights_allow2($db, 'repo', $obj_id, 'G', '') === TRUE)
2086 1879 $rg['allow_grant_rights'] = 1; $rg['allow_grant_rights'] = 1;
2087 $x['needed_rights'] = 'D';
2088 if (rg_rights_allow($db, $x) === TRUE)
1880 if (rg_rights_allow2($db, 'repo', $obj_id, 'D', '') === TRUE)
2089 1881 $rg['allow_delete_repo'] = 1; $rg['allow_delete_repo'] = 1;
2090 1882
2091 1883 $rg['menu']['repo'][$_op] = 1; $rg['menu']['repo'][$_op] = 1;
2092 $rg['HTML:menu_repo_level2'] = rg_template("user/repo/menu.html", $rg, TRUE /* xss */);
1884 $rg['HTML:menu_repo_level2'] = rg_template("user/repo/menu.html", $rg, TRUE /*xss*/);
2093 1885
2094 1886 switch ($_op) { switch ($_op) {
2095 1887 case 'repo_rights': case 'repo_rights':
 
... ... function rg_repo_search_high_level($db, $rg, $ui, $url)
2136 1928 $rg['q'] = $q; $rg['q'] = $q;
2137 1929 $rg['HTML:errmsg'] = rg_template_errmsg($errmsg); $rg['HTML:errmsg'] = rg_template_errmsg($errmsg);
2138 1930 $rg['search_url'] = $url; $rg['search_url'] = $url;
2139 $ret .= rg_template("repo/search.html", $rg, TRUE /* xss */);
1931 $ret .= rg_template("repo/search.html", $rg, TRUE /*xss*/);
2140 1932
2141 1933 while ($rg['doit'] == 1) { while ($rg['doit'] == 1) {
2142 1934 $_t = rg_repo_search($db, $ui, $q); $_t = rg_repo_search($db, $ui, $q);
 
... ... function rg_repo_search_high_level($db, $rg, $ui, $url)
2154 1946
2155 1947 /* /*
2156 1948 * Discover top menu helper * Discover top menu helper
2157 * @ui - acts like login_ui
1949 * @ui - acts like ui_login
2158 1950 */ */
2159 1951 function rg_repo_discover($db, $op, $rg, $ui) function rg_repo_discover($db, $op, $rg, $ui)
2160 1952 { {
 
... ... function rg_repo_stats($rg)
2219 2011 } }
2220 2012
2221 2013 $s = rg_git_stats($log); $s = rg_git_stats($log);
2222 //rg_log_ml('DEBUG: stats: ' . print_r($s, TRUE));
2014 //rg_log_debug('stats: ' . print_r($s, TRUE));
2223 2015 $rg['ri']['stats'] = $s['global']; $rg['ri']['stats'] = $s['global'];
2224 2016
2225 2017 $rg['ri']['HTML:authors'] = rg_template_table('repo/stats/authors', $rg['ri']['HTML:authors'] = rg_template_table('repo/stats/authors',
 
... ... function rg_repo_commit_labels($db, $repo_id, $head)
2283 2075 break; break;
2284 2076 } }
2285 2077
2286 //rg_log_ml('DEBUG: commit_labels: ' . print_r($ret, TRUE));
2078 //rg_log_debug('commit_labels: ' . print_r($ret, TRUE));
2287 2079
2288 2080 rg_log_exit(); rg_log_exit();
2289 2081 rg_prof_end('repo_commit_labels'); rg_prof_end('repo_commit_labels');
 
... ... function rg_repo_commit_labels_html($db, $repo_id, $commit)
2305 2097 $rg = array(); $rg = array();
2306 2098
2307 2099 $r = rg_repo_commit_labels($db, $repo_id, $commit); $r = rg_repo_commit_labels($db, $repo_id, $commit);
2308 //rg_log_ml('DEBUG: r: ' . print_r($r, TRUE));
2100 //rg_log_debug('r: ' . print_r($r, TRUE));
2309 2101 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
2310 2102 $ret = rg_template('repo/cl/ierror.html', $ret = rg_template('repo/cl/ierror.html',
2311 2103 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
 
... ... function rg_repo_api($db, $a, $json)
2378 2170 // From this point below, we have a repo // From this point below, we have a repo
2379 2171 rg_stats_conns_set('repo_id', $ri['repo_id']); rg_stats_conns_set('repo_id', $ri['repo_id']);
2380 2172
2381 $x = array();
2382 $x['obj_id'] = $ri['repo_id'];
2383 $x['type'] = 'repo';
2384 $x['owner'] = $ri['uid'];
2385 $x['uid'] = $a['login_ui']['uid'];
2386 $x['username'] = $a['login_ui']['username'];
2387 $x['needed_rights'] = 'A'; // A = Access repo; E = create/edit
2388 $x['ip'] = $a['ip'];
2389 $x['misc'] = '';
2173 $obj_id = $ri['repo_id'];
2174 $allow = array();
2175 $allow['A'] = rg_rights_allow2($db, 'repo', $obj_id, 'A', '') === TRUE;
2176 $allow['a'] = rg_rights_allow2($db, 'repo', $obj_id, 'a', '') === TRUE;
2390 2177
2391 2178 if (strcmp($cmd, 'repo_info') == 0) { if (strcmp($cmd, 'repo_info') == 0) {
2392 if (rg_rights_allow($db, $x) !== TRUE) {
2179 if (!$allow['A']) {
2393 2180 $ret['error'] = 'invalid user or no rights'; $ret['error'] = 'invalid user or no rights';
2394 2181 break; break;
2395 2182 } }
 
... ... function rg_repo_api($db, $a, $json)
2400 2187
2401 2188 if ((strcmp($cmd, 'repo_pr_list') == 0) if ((strcmp($cmd, 'repo_pr_list') == 0)
2402 2189 || (strcmp($cmd, 'repo_mr_list') == 0)) { || (strcmp($cmd, 'repo_mr_list') == 0)) {
2403 if (rg_rights_allow($db, $x) !== TRUE) {
2190 if (!$allow['A']) {
2404 2191 $ret['error'] = 'invalid user or no rights'; $ret['error'] = 'invalid user or no rights';
2405 2192 break; break;
2406 2193 } }
 
... ... function rg_repo_api($db, $a, $json)
2425 2212 } }
2426 2213
2427 2214 if (strcmp($cmd, 'repo_bug_list') == 0) { if (strcmp($cmd, 'repo_bug_list') == 0) {
2428 $y = $x;
2429 $y['needed_rights'] = 'a'; // a = Access bug repo
2430 if (rg_rights_allow($db, $y) !== TRUE) {
2215 if (!$allow['a']) {
2431 2216 $ret['error'] = 'invalid user or no rights'; $ret['error'] = 'invalid user or no rights';
2432 2217 break; break;
2433 2218 } }
 
... ... function rg_repo_api($db, $a, $json)
2459 2244 } }
2460 2245 $bug_id = intval($json['bug_id']); $bug_id = intval($json['bug_id']);
2461 2246
2462 $y = $x;
2463 $y['needed_rights'] = 'a'; // a = Access bug repo
2464 if (rg_rights_allow($db, $y) !== TRUE) {
2247 if (!$allow['a']) {
2465 2248 $ret['error'] = 'invalid user or no rights'; $ret['error'] = 'invalid user or no rights';
2466 2249 break; break;
2467 2250 } }
 
... ... function rg_repo_api($db, $a, $json)
2488 2271 /* /*
2489 2272 * Helper for SSH/GIT/HTTP(S) fetch/push * Helper for SSH/GIT/HTTP(S) fetch/push
2490 2273 * @host - the host name accessed - may be different than the good one * @host - the host name accessed - may be different than the good one
2491 * @ip - from where the connections come
2492 2274 * @cmd: 'git-upload-pack' or 'git-receive-pack' * @cmd: 'git-upload-pack' or 'git-receive-pack'
2493 2275 * @flags: B = bypass rights check (for example, for a global worker) * @flags: B = bypass rights check (for example, for a global worker)
2494 2276 * TODO: move it to user.inc.php?! * TODO: move it to user.inc.php?!
2495 2277 */ */
2496 function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2278 function rg_repo_fetch_push_helper($db, $host, $prefix, $repo_user,
2497 2279 $repo, $cmd, $flags) $repo, $cmd, $flags)
2498 2280 { {
2499 2281 global $rg_log_sid; global $rg_log_sid;
2500 2282
2501 2283 rg_prof_start('repo_fetch_push_helper'); rg_prof_start('repo_fetch_push_helper');
2502 2284 rg_log_enter('repo_fetch_push_helper: host=' . $host rg_log_enter('repo_fetch_push_helper: host=' . $host
2503 . ' ip=' . $ip . ' prefix=' . $prefix . ' user=[' . $user . ']'
2285 . ' prefix=' . $prefix . ' repo_user=[' . $repo_user . ']'
2504 2286 . ' repo=[' . $repo . '] cmd=[' . $cmd . '] flags=' . $flags); . ' repo=[' . $repo . '] cmd=[' . $cmd . '] flags=' . $flags);
2505 2287
2506 2288 $ret = array('ok' => 0, 'allow' => 0, 'push_allowed' => 0); $ret = array('ok' => 0, 'allow' => 0, 'push_allowed' => 0);
2507 2289 while (1) { while (1) {
2508 // Extracts command and computes permissions
2290 // Extracts command and set needed permissions
2509 2291 if (strncasecmp($cmd, 'git-upload-pack', 15) == 0) { if (strncasecmp($cmd, 'git-upload-pack', 15) == 0) {
2510 2292 $cmd = 'git-upload-pack'; $cmd = 'git-upload-pack';
2511 2293 $needed_rights = 'F'; $needed_rights = 'F';
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2522 2304
2523 2305 // Validity/security checks // Validity/security checks
2524 2306 // Load info about the owner // Load info about the owner
2525 if (rg_user_ok($user) !== TRUE) {
2307 if (rg_user_ok($repo_user) !== TRUE) {
2526 2308 $ret['errmsg'] = 'user is invalid (' . rg_user_error() . ')'; $ret['errmsg'] = 'user is invalid (' . rg_user_error() . ')';
2527 2309 break; break;
2528 2310 } }
2529 $ret['owner_ui'] = rg_user_info($db, 0, $user, '');
2530 if ($ret['owner_ui']['ok'] != 1) {
2311 $ui_page = rg_user_info($db, 0, $repo_user, '');
2312 if ($ui_page['ok'] != 1) {
2531 2313 $ret['errmsg'] = 'internal problems; try again later, please'; $ret['errmsg'] = 'internal problems; try again later, please';
2532 2314 break; break;
2533 2315 } }
2534 if ($ret['owner_ui']['exists'] != 1) {
2316 if ($ui_page['exists'] != 1) {
2535 2317 $ret['errmsg'] = 'user does not exists'; $ret['errmsg'] = 'user does not exists';
2536 2318 break; break;
2537 2319 } }
2320 rg_ui_page_set($ui_page);
2538 2321
2539 2322 // TODO: What if the user is deleted? // TODO: What if the user is deleted?
2540 2323
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2543 2326 $ret['errmsg'] = rg_repo_error(); $ret['errmsg'] = rg_repo_error();
2544 2327 break; break;
2545 2328 } }
2546 $ret['ri'] = rg_repo_info($db, 0, $ret['owner_ui']['uid'], $repo);
2329 $ret['ri'] = rg_repo_info($db, 0, $ui_page['uid'], $repo);
2547 2330 if ($ret['ri']['ok'] != 1) { if ($ret['ri']['ok'] != 1) {
2548 2331 $ret['errmsg'] = 'internal problems; try again later, please'; $ret['errmsg'] = 'internal problems; try again later, please';
2549 2332 break; break;
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2557 2340 break; break;
2558 2341 } }
2559 2342
2343 $ui_login = rg_ui_login();
2560 2344 $ls = rg_repo_lock_status($db, $ret['ri']['repo_id']); $ls = rg_repo_lock_status($db, $ret['ri']['repo_id']);
2561 2345 if ($ls['ok'] != 1) { if ($ls['ok'] != 1) {
2562 2346 $ret['errmsg'] = 'could not get lock status: ' . rg_repo_error(); $ret['errmsg'] = 'could not get lock status: ' . rg_repo_error();
2563 2347 break; break;
2564 2348 } }
2565 if (($ls['status'] == 1) && ($login_ui['uid'] != $ls['uid'])) {
2349 if (($ls['status'] == 1) && ($ui_login['uid'] != $ls['uid'])) {
2566 2350 $_u = rg_user_info($db, $ls['uid'], '', ''); $_u = rg_user_info($db, $ls['uid'], '', '');
2567 2351 if ($_u['exists'] == 1) if ($_u['exists'] == 1)
2568 2352 $_user = $_u['username']; $_user = $_u['username'];
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2574 2358 break; break;
2575 2359 } }
2576 2360
2577 $repo_path = rg_repo_path_by_id($ret['owner_ui']['uid'],
2361 $repo_path = rg_repo_path_by_id($ui_page['uid'],
2578 2362 $ret['ri']['repo_id']); $ret['ri']['repo_id']);
2579 2363 $ret['repo_path'] = $repo_path; $ret['repo_path'] = $repo_path;
2580 2364
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2583 2367 $ret['ok'] = 1; $ret['ok'] = 1;
2584 2368
2585 2369 if (!strstr($flags, 'B')) { if (!strstr($flags, 'B')) {
2586 $x = array();
2587 $x['obj_id'] = $ret['ri']['repo_id'];
2588 $x['type'] = 'repo_refs';
2589 $x['owner'] = $ret['ri']['uid'];
2590 $x['uid'] = $login_ui['uid'];
2591 $x['username'] = $login_ui['uid'] == 0 ? '' : $login_ui['username'];
2592 $x['needed_rights'] = $needed_rights;
2593 $x['ip'] = $ip;
2594 $x['misc'] = '';
2595 $r = rg_rights_allow($db, $x);
2370 $obj_id = $ret['ri']['repo_id'];
2371 $r = rg_rights_allow2($db, 'repo_refs', $obj_id, $needed_rights, '');
2372 // TODO: 'misc' is not used?
2596 2373 // TODO: what if an error occured? How do we signal this?! $r must have ok key // TODO: what if an error occured? How do we signal this?! $r must have ok key
2597 2374 if ($r !== TRUE) { if ($r !== TRUE) {
2598 2375 $ret['errmsg'] = 'non existing repo or you are not allowed to push'; $ret['errmsg'] = 'non existing repo or you are not allowed to push';
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2604 2381 // TODO: change rg_rights_allow to return what rights are // TODO: change rg_rights_allow to return what rights are
2605 2382 // allowed and use it. // allowed and use it.
2606 2383 if ($ret['push'] == 1) { if ($ret['push'] == 1) {
2607 $x['needed_rights'] = 'P';
2608 $r = rg_rights_allow($db, $x);
2384 $r = rg_rights_allow2($db, 'repo_refs', $obj_id, 'P', '');
2609 2385 if ($r === TRUE) if ($r === TRUE)
2610 2386 $ret['push_allowed'] = 1; $ret['push_allowed'] = 1;
2611 2387 } }
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2617 2393 // username/uid of the connecting user. // username/uid of the connecting user.
2618 2394 if (isset($_SERVER['SSH_CONNECTION'])) { if (isset($_SERVER['SSH_CONNECTION'])) {
2619 2395 if (($ret['ri']['public'] == 0) || ($ret['push'] == 1)) { if (($ret['ri']['public'] == 0) || ($ret['push'] == 1)) {
2620 $r = rg_totp_verify_ip($db, $login_ui['uid'],
2621 $ip);
2396 $r = rg_totp_verify_ip($db, $ui_login['uid'],
2397 rg_ip());
2622 2398 if (($r['ok'] !== 1) if (($r['ok'] !== 1)
2623 2399 || ($r['enrolled'] && empty($r['ip_list']))) { || ($r['enrolled'] && empty($r['ip_list']))) {
2624 2400 $ret['errmsg'] = rg_totp_error(); $ret['errmsg'] = rg_totp_error();
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2636 2412 // TODO: put process in a cgroup? // TODO: put process in a cgroup?
2637 2413
2638 2414 if (($ret['push'] == 1) if (($ret['push'] == 1)
2639 && rg_user_over_limit($db, $ret['owner_ui'], $max)) {
2415 && rg_user_over_limit($db, $ui_page, $max)) {
2640 2416 // TODO: be aware that a push may mean a delete => // TODO: be aware that a push may mean a delete =>
2641 2417 // free space?! // free space?!
2642 2418 // We should mark the repo over limit when we compute // We should mark the repo over limit when we compute
2643 2419 // the disk space - same problem // the disk space - same problem
2644 2420 $ret['errmsg'] = 'cannot push: user is over limit' $ret['errmsg'] = 'cannot push: user is over limit'
2645 . ' (' . $ret['owner_ui']['disk_used_mb'] . 'MiB >= '
2421 . ' (' . $ui_page['disk_used_mb'] . 'MiB >= '
2646 2422 . $max . 'MiB)'; . $max . 'MiB)';
2647 2423 break; break;
2648 2424 } }
 
... ... function rg_repo_fetch_push_helper($db, $host, $ip, $login_ui, $prefix, $user,
2651 2427 $ret['allow'] = 1; $ret['allow'] = 1;
2652 2428
2653 2429 // Put in environment all we need // Put in environment all we need
2654 putenv('ROCKETGIT_LOGIN_UID=' . $login_ui['uid']);
2655 putenv('ROCKETGIT_LOGIN_URL=' . rg_re_userpage($login_ui));
2430 putenv('ROCKETGIT_LOGIN_UID=' . $ui_login['uid']);
2431 putenv('ROCKETGIT_LOGIN_URL=' . rg_re_userpage($ui_login));
2656 2432 putenv('ROCKETGIT_REPO_ID=' . $ret['ri']['repo_id']); putenv('ROCKETGIT_REPO_ID=' . $ret['ri']['repo_id']);
2657 2433 putenv('ROCKETGIT_REPO_PATH=' . $repo_path); putenv('ROCKETGIT_REPO_PATH=' . $repo_path);
2658 2434 putenv('ROCKETGIT_REPO_NAME=' . $ret['ri']['name']); putenv('ROCKETGIT_REPO_NAME=' . $ret['ri']['name']);
2659 2435 putenv('ROCKETGIT_REPO_UID=' . $ret['ri']['uid']); putenv('ROCKETGIT_REPO_UID=' . $ret['ri']['uid']);
2436 putenv('ROCKETGIT_REPO_USERNAME=' . $ui_page['username']);
2660 2437 putenv('ROCKETGIT_REPO_CLONE_URL=' . $ret['ri']['clone_url_http']); putenv('ROCKETGIT_REPO_CLONE_URL=' . $ret['ri']['clone_url_http']);
2661 putenv('ROCKETGIT_IP=' . $ip);
2438 putenv('ROCKETGIT_IP=' . rg_ip());
2662 2439 putenv('ROCKETGIT_ITIME=' . microtime(TRUE)); putenv('ROCKETGIT_ITIME=' . microtime(TRUE));
2663 2440 putenv('ROCKETGIT_HOST=' . $host); putenv('ROCKETGIT_HOST=' . $host);
2664 2441 putenv('ROCKETGIT_LOG_SID=' . $rg_log_sid); putenv('ROCKETGIT_LOG_SID=' . $rg_log_sid);
2442 putenv('ROCKETGIT_DEBUG=' . rg_debug());
2665 2443 if (($ret['push'] == 1) && ($ret['push_allowed'] == 0)) { if (($ret['push'] == 1) && ($ret['push_allowed'] == 0)) {
2666 rg_log('DEBUG: We need to clone the namespace...');
2444 rg_log_debug('We need to clone the namespace...');
2667 2445 $namespace = 'rg_' . rg_id(8); $namespace = 'rg_' . rg_id(8);
2668 2446 rg_log('namespace is ' . $namespace); rg_log('namespace is ' . $namespace);
2669 2447 putenv('GIT_NAMESPACE=' . $namespace); putenv('GIT_NAMESPACE=' . $namespace);
File inc/repo/repo.php changed (mode: 100644) (index d714b52..ccffea2)
1 1 <?php <?php
2 2 // This page is shown when user press main menu "My repositories" // This page is shown when user press main menu "My repositories"
3 3
4 $ui_login = rg_ui_login();
5
4 6 $_repo = ''; $_repo = '';
5 7
6 8 if (empty($paras)) { if (empty($paras)) {
7 if (rg_repo_have($db, $rg['login_ui']['uid']) == 0)
9 if (rg_repo_have($db, $ui_login['uid']) == 0)
8 10 $_subop = 'create'; $_subop = 'create';
9 11 else else
10 12 $_subop = 'list'; $_subop = 'list';
 
... ... case 'create':
23 25 break; break;
24 26
25 27 case 'search': case 'search':
26 $_repo .= rg_repo_search_high_level($db, $rg, $rg['login_ui'],
27 '/op/repo');
28 $_repo .= rg_repo_search_high_level($db, $rg, $ui_login, '/op/repo');
28 29 break; break;
29 30
30 31 case 'list': case 'list':
31 $_repo .= rg_repo_list($db, $rg, "", $rg['login_ui']['uid'], 0);
32 $_repo .= rg_repo_list($db, $rg, '', $ui_login['uid'], 0);
32 33 break; break;
33 34 } }
34 35
File inc/rights.inc.php changed (mode: 100644) (index 93e6173..84ca2dd)
... ... require_once(__DIR__ . '/util2.inc.php');
3 3 require_once(__DIR__ . '/log.inc.php'); require_once(__DIR__ . '/log.inc.php');
4 4 require_once(__DIR__ . '/sql.inc.php'); require_once(__DIR__ . '/sql.inc.php');
5 5 require_once(__DIR__ . '/user.inc.php'); require_once(__DIR__ . '/user.inc.php');
6 require_once(__DIR__ . '/git.inc.php');
6 require_once(__DIR__ . '/events.inc.php');
7 7
8 8 $rg_rights = array(); $rg_rights = array();
9 9 $rg_rights_default = array(); $rg_rights_default = array();
 
... ... function rg_rights_get($db, $obj_id, $type, $owner, $uid, $right_id)
309 309 global $rg_rights_inject; global $rg_rights_inject;
310 310
311 311 rg_prof_start('rights_get'); rg_prof_start('rights_get');
312 rg_log_enter("rg_rights_get: obj_id=$obj_id type=$type owner=$owner"
313 . " uid=$uid right_id=$right_id");
312 rg_log_enter('rights_get: obj_id=' . $obj_id . ' type=' . $type
313 . ' owner=' . $owner . ' uid=' . $uid . ' right_id=' . $right_id);
314 314
315 315 $ret = array(); $ret = array();
316 316 $ret['ok'] = 0; $ret['ok'] = 0;
 
... ... function rg_rights_get($db, $obj_id, $type, $owner, $uid, $right_id)
364 364 uasort($r2, 'rg_rights_sort_helper'); uasort($r2, 'rg_rights_sort_helper');
365 365
366 366 // cosmetic // cosmetic
367 //rg_log_ml('DEBUG: before cosmetic: ' . print_r($r2, TRUE));
367 //rg_log_debug('before cosmetic: ' . print_r($r2, TRUE));
368 368 foreach ($r2 as $index => &$row) foreach ($r2 as $index => &$row)
369 369 rg_rights_cosmetic($db, $row); rg_rights_cosmetic($db, $row);
370 370
 
... ... function rg_rights_get($db, $obj_id, $type, $owner, $uid, $right_id)
386 386 function rg_rights_set($db, $type, $a) function rg_rights_set($db, $type, $a)
387 387 { {
388 388 rg_prof_start("rights_set"); rg_prof_start("rights_set");
389 rg_log_enter("rg_rights_set: type=$type a=" . rg_array2string($a));
389 rg_log_enter('rights_set: type=' . $type . ' a=' . rg_array2string($a));
390 390
391 391 $ret = FALSE; $ret = FALSE;
392 $rollback = FALSE;
392 393 while (1) { while (1) {
393 394 if (($a['prio'] < 10) || ($a['prio'] > 30000)) { if (($a['prio'] < 10) || ($a['prio'] > 30000)) {
394 395 rg_rights_set_error("prio must be between 10 and 30000"); rg_rights_set_error("prio must be between 10 and 30000");
 
... ... function rg_rights_set($db, $type, $a)
399 400 if ($r !== TRUE) if ($r !== TRUE)
400 401 break; break;
401 402
403 if (rg_sql_begin($db) !== TRUE) {
404 rg_rights_set_error('cannot start transaction');
405 break;
406 }
407 $rollback = TRUE;
408
409 if (!isset($a['who'])) {
410 $ui_login = rg_ui_login();
411 $a['who'] = $ui_login['uid'];
412 }
413
402 414 $a['type'] = $type; $a['type'] = $type;
403 415 $a['now'] = time(); $a['now'] = time();
404 416 if ($a['right_id'] > 0) if ($a['right_id'] > 0)
 
... ... function rg_rights_set($db, $type, $a)
431 443 $key = "rights_by_obj_id::" . $a['obj_id'] . "::" . $a['type']; $key = "rights_by_obj_id::" . $a['obj_id'] . "::" . $a['type'];
432 444 rg_cache_unset($key, RG_SOCKET_NO_WAIT); rg_cache_unset($key, RG_SOCKET_NO_WAIT);
433 445
446 $ev = array(
447 'category' => 'rights_grant',
448 'prio' => 100,
449 'info' => $a
450 );
451 $r = rg_event_add($db, $ev);
452 if ($r !== TRUE) {
453 rg_rights_set_error('cannot add event');
454 break;
455 }
456
457 if (rg_sql_commit($db) !== TRUE) {
458 rg_rights_set_error('cannot commit');
459 break;
460 }
461 $rollback = FALSE;
462
463 rg_event_signal_daemon('', 0);
464
434 465 $ret = TRUE; $ret = TRUE;
435 466 break; break;
436 467 } }
468 if ($rollback)
469 rg_sql_rollback($db);
437 470
438 471 rg_log_exit(); rg_log_exit();
439 472 rg_prof_end("rights_set"); rg_prof_end("rights_set");
 
... ... function rg_rights_mask($val, $mask)
461 494 */ */
462 495 function rg_rights_split_ip($ip) function rg_rights_split_ip($ip)
463 496 { {
497 rg_debug() && rg_log('rights_split_ip: ip=' . $ip);
498
464 499 $ret = array(); $ret = array();
465 500
466 501 $ret['prefix_len'] = -1; $ret['prefix_len'] = -1;
 
... ... function rg_rights_split_ip($ip)
592 627 */ */
593 628 function rg_rights_validate_ip($list) function rg_rights_validate_ip($list)
594 629 { {
595 $list = preg_replace("/[,\n]/", " ", $list);
630 $list = preg_replace("/[,\s]+/", ' ', $list);
596 631 $list = trim($list); $list = trim($list);
597 632 if (empty($list)) if (empty($list))
598 633 return TRUE; return TRUE;
 
... ... function rg_rights_validate_ip($list)
616 651 */ */
617 652 function rg_rights_test_ip($list, $ip) function rg_rights_test_ip($list, $ip)
618 653 { {
654 rg_debug() && rg_log('rights_test_ip: ip=' . $ip);
655
619 656 $r = rg_rights_split_ip($ip); $r = rg_rights_split_ip($ip);
620 657 if ($r === FALSE) { if ($r === FALSE) {
621 658 rg_log("An invalid IP has been specified [$ip]. Ignore it."); rg_log("An invalid IP has been specified [$ip]. Ignore it.");
 
... ... function rg_rights_test($list, $needed_rights, $ip, $misc)
666 703
667 704 $ret = FALSE; $ret = FALSE;
668 705 while (1) { while (1) {
669 if (!is_array($list)) {
670 rg_rights_set_error("list is not array");
671 break;
672 }
673
674 if (empty($needed_rights)) {
675 $ret = TRUE;
676 break;
677 }
678
679 706 $needed = explode("|", $needed_rights); $needed = explode("|", $needed_rights);
680 707
681 708 foreach ($list as $k => $v) { foreach ($list as $k => $v) {
709 rg_debug() && rg_log('k=' . $k . ': ' . rg_array2string($v));
682 710 // Test IP // Test IP
683 if (rg_rights_test_ip($v['ip'], $ip) !== TRUE) {
684 rg_log("CHECK: ip [$ip] does not match with [" . $v['ip'] . "]");
711 if (rg_rights_test_ip($v['ip'], $ip) !== TRUE)
685 712 continue; continue;
686 }
687 713
688 714 // Test 'misc' match // Test 'misc' match
689 715 if (!empty($v['misc'])) { if (!empty($v['misc'])) {
690 716 $cmp_func = $rg_rights_cmp_func[$v['type']]; $cmp_func = $rg_rights_cmp_func[$v['type']];
691 717 $r = $cmp_func($v['misc'], $misc); $r = $cmp_func($v['misc'], $misc);
692 718 if ($r !== TRUE) { if ($r !== TRUE) {
693 rg_log("DEBUG: cmp function returned !TRUE");
719 rg_log_debug('cmp function returned !TRUE');
694 720 continue; continue;
695 721 } }
696 722 } }
697 723
698 724 // empty = no rights => stop processing // empty = no rights => stop processing
699 // This check must be after ip/isc tests!
700 if (strlen($v['rights']) == 0)
725 // This check must be after ip/misc tests!
726 if (empty($v['rights']))
701 727 break; break;
702 728
703 729 // Test rights // Test rights
 
... ... function rg_rights_test($list, $needed_rights, $ip, $misc)
705 731 foreach ($needed as $needed1) { foreach ($needed as $needed1) {
706 732 $r = rg_rights_mask($v['rights'], $needed1); $r = rg_rights_mask($v['rights'], $needed1);
707 733 if (strcmp($r, $needed1) != 0) { if (strcmp($r, $needed1) != 0) {
708 rg_log("[$r] != [$needed1]! Continue.");
734 rg_log('mask[' . $r . '] != needed['
735 . $needed1 . ']! Continue.');
709 736 continue; continue;
710 737 } }
711 738 $have_a_match = TRUE; $have_a_match = TRUE;
 
... ... function rg_rights_test($list, $needed_rights, $ip, $misc)
714 741 if ($have_a_match === FALSE) if ($have_a_match === FALSE)
715 742 continue; continue;
716 743
717 //rg_log('DEBUG: rule ' . $k . ' matched.');
744 rg_log_debug('rule id ' . $k . ' matched.');
718 745 $ret = TRUE; $ret = TRUE;
719 746 break; break;
720 747 } }
 
... ... function rg_rights_allow($db, $a)
736 763 { {
737 764 $obj_id = $a['obj_id']; $obj_id = $a['obj_id'];
738 765 $type = $a['type']; $type = $a['type'];
739 $owner = $a['owner'];
740 $uid = $a['uid'];
741 $username = $a['username'];
766 if (isset($a['owner'])) {
767 $owner = $a['owner'];
768 } else {
769 $ui_page = rg_ui_page();
770 $owner = $ui_page['uid'];
771 }
772 if (isset($a['uid'])) {
773 $uid = $a['uid'];
774 $username = $a['username'];
775 } else {
776 $ui_login = rg_ui_login();
777 $uid = $ui_login['uid'];
778 $username = $ui_login['username'];
779 }
742 780 $needed_rights = $a['needed_rights']; $needed_rights = $a['needed_rights'];
743 $ip = $a['ip'];
744 $misc = $a['misc'];
781 $misc = isset($a['misc']) ? $a['misc'] : '';
782
783 // TODO - what about IP restrictions, for example?
784 //if ($uid == $owner)
785 // return TRUE;
745 786
746 787 $right_id = 0; $right_id = 0;
747 788 // TODO: we may pass $a? // TODO: we may pass $a?
 
... ... function rg_rights_allow($db, $a)
749 790 if ($r['ok'] != 1) if ($r['ok'] != 1)
750 791 return FALSE; return FALSE;
751 792
793 // TODO: we may call rg_rights_test here and return if it is ok [perf]
794
752 795 // We must replace @USER@ with the logged-in user // We must replace @USER@ with the logged-in user
753 796 if ($uid > 0) { if ($uid > 0) {
754 797 foreach ($r['list'] as $index => &$e) { foreach ($r['list'] as $index => &$e) {
 
... ... function rg_rights_allow($db, $a)
760 803 $username, $e['misc']); $username, $e['misc']);
761 804 rg_log("DEBUG [" . $_old . "] -> [" . $e['misc'] . "]"); rg_log("DEBUG [" . $_old . "] -> [" . $e['misc'] . "]");
762 805 } }
763 //rg_log_ml("DEBUG: r[list]=" . print_r($r['list'], TRUE));
806 //rg_log_debug('r[list]=' . print_r($r['list'], TRUE));
807 }
808
809 $r = rg_rights_test($r['list'], $needed_rights, rg_ip(), $misc);
810 if ($r !== TRUE) {
811 rg_rights_set_error('you do not have rights');
812 return FALSE;
764 813 } }
765 814
766 return rg_rights_test($r['list'], $needed_rights, $ip, $misc);
815 return TRUE;
816 }
817
818 /*
819 * Just a simple helper for rg_rights_allow
820 */
821 function rg_rights_allow2($db, $type, $obj_id, $needed_rights, $misc)
822 {
823 $x = array();
824 $x['type'] = $type;
825 $x['obj_id'] = $obj_id;
826 $x['needed_rights'] = $needed_rights;
827 $x['misc'] = $misc;
828 return rg_rights_allow($db, $x);
767 829 } }
768 830
769 831 /* /*
 
... ... function rg_rights_delete_list($db, $type, $obj_id, $list)
802 864 return TRUE; return TRUE;
803 865 } }
804 866
867 /*
868 * Helper for high level functions - get rights data for a request
869 */
870 function rg_rights_load_vars()
871 {
872 $a = array();
873 $a['right_id'] = rg_var_uint('right_id');
874 $a['edit_id'] = rg_var_uint('edit_id');
875 $a['username'] = trim(rg_var_str('username'));
876 $a['rights'] = rg_rights_a2s(rg_var_str('rights'));
877 $a['misc'] = trim(rg_var_str('misc'));
878 $a['ip'] = trim(rg_var_str('ip'));
879 $a['prio'] = rg_var_uint('prio');
880 $a['description'] = trim(rg_var_str('description'));
881 //rg_log_ml('CHECK: a(POST)=' . print_r($a, TRUE));
882
883 return $a;
884 }
885
886 /*
887 * High level function for admin rights
888 * @base_type: 'type' to check for Grant/Revoke rights (think about 'repo',
889 * where we have Grant/Revoke on 'repo' type, not 'repo_*' types.
890 */
891 function rg_rights_high_level($db, $rg, $base_type, $type, $owner, $obj_id)
892 {
893 rg_log_enter('rights_high_level base_type=' . $base_type
894 . ' type=' . $type
895 . ' owner=' . $owner . ' obj_id=' . $obj_id);
896
897 $ret = '';
898
899 $a = rg_rights_load_vars();
900 $a['type'] = $type;
901
902 $list_errmsg = array();
903 $errmsg = array();
904
905 $load_defaults = TRUE;
906
907 $delete = rg_var_bool('delete');
908 while ($delete == 1) {
909 if (!rg_valid_referer()) {
910 $errmsg[] = 'invalid referer; try again';
911 break;
912 }
913
914 if (!rg_token_valid($db, $rg, 'rights-' . $type, FALSE)) {
915 $errmsg[] = 'invalid token; try again';
916 break;
917 }
918
919 $list = rg_var_uint('rights_delete_ids');
920 if (empty($list)) {
921 $list_errmsg[] = 'please select at least one item';
922 break;
923 }
924
925 $my_list = array();
926 foreach ($list as $k => $junk)
927 $my_list[] = $k;
928
929 $r = rg_rights_allow2($db, $base_type, $obj_id, 'g', '');
930 if ($r !== TRUE) {
931 $errmsg[] = rg_rights_error();
932 break;
933 }
934
935 $r = rg_rights_delete_list($db, $type, $obj_id, $my_list);
936 if ($r !== TRUE) {
937 $list_errmsg[] = 'cannot delete rights: ' . rg_rights_error();
938 break;
939 }
940
941 $ret .= rg_template('rights/delete_ok.html', $rg, TRUE /*xss*/);
942 break;
943 }
944
945 // edit
946 while ($a['edit_id'] > 0) {
947 $r = rg_rights_get($db, $obj_id, $type, $owner, -1, $a['edit_id']);
948 if ($r['ok'] != 1) {
949 $list_errmsg[] = 'cannot load rights: ' . rg_rights_error();
950 break;
951 }
952
953 if (empty($r['list'])) {
954 $list_errmsg[] = 'right not found';
955 break;
956 }
957
958 // Only one right is returned when we edit by right_id
959 $a = $r['list'][0];
960
961 $load_defaults = FALSE;
962 break;
963 }
964
965 $rg['HTML:grant_note'] = '';
966 $grant = rg_var_uint('grant');
967 while ($grant == 1) {
968 $load_defaults = FALSE;
969
970 if (!rg_valid_referer()) {
971 $errmsg[] = 'invalid referer; try again';
972 break;
973 }
974
975 if (!rg_token_valid($db, $rg, 'rights-' . $type, FALSE)) {
976 $errmsg[] = 'invalid token; try again';
977 break;
978 }
979
980 if (strcmp($a['username'], '*') == 0) {
981 $a['uid'] = 0;
982 } else {
983 $_ui = rg_user_info($db, 0, $a['username'], '');
984 if ($_ui['exists'] == 1) {
985 $a['uid'] = $_ui['uid'];
986 } else {
987 $errmsg[] = rg_template_blind('rights/invalid_user.html');
988 break;
989 }
990 }
991
992 $r = rg_rights_allow2($db, $base_type, $obj_id, 'G', '');
993 if ($r !== TRUE) {
994 $errmsg[] = rg_rights_error();
995 break;
996 }
997
998 $a['obj_id'] = $obj_id;
999 $r = rg_rights_set($db, $type, $a);
1000 if ($r !== TRUE) {
1001 $errmsg[] = rg_rights_error();
1002 break;
1003 }
1004
1005 $rg['HTML:grant_note'] = rg_template('rights/grant_ok.html',
1006 $rg, TRUE /*xss*/);
1007
1008 $load_defaults = TRUE;
1009 break;
1010 }
1011
1012 if ($load_defaults) {
1013 $rg['right_id'] = 0;
1014 $rg['username'] = '';
1015 $rg['rights'] = rg_rights_default($type);
1016 $rg['description'] = '';
1017 $rg['misc'] = '';
1018 $rg['ip'] = '';
1019 $rg['prio'] = 100;
1020 } else {
1021 $rg = rg_array_merge($rg, '', $a);
1022 }
1023
1024 $rg['rg_form_token'] = rg_token_get($db, $rg, 'rights-' . $type);
1025 $rg['HTML:grant_errmsg'] = rg_template_errmsg($errmsg);
1026 $rg['HTML:list_errmsg'] = rg_template_errmsg($list_errmsg);
1027 $rg['HTML:rights_checkboxes'] = rg_rights_checkboxes($type, 'rights',
1028 $rg['rights']);
1029
1030 // list rights
1031 $r = rg_rights_get($db, $obj_id, $type, $owner, -1, 0);
1032 if ($r['ok'] != 1)
1033 $ret .= rg_warning('Cannot load rights. Try later.');
1034 else
1035 $ret .= rg_template_table('rights/list_' . $type, $r['list'], $rg);
1036
1037 $ret .= rg_template('rights/form_' . $type . '.html', $rg, TRUE /*xss*/);
1038
1039 // hints
1040 $hints = array();
1041 $hints[]['HTML:hint'] = rg_template('hints/rights/edit_rights.html',
1042 $rg, TRUE /*xss*/);
1043 $hints[]['HTML:hint'] = rg_template('hints/rights/edit_'
1044 . $type . '.html', $rg, TRUE /*xss*/);
1045 $ret .= rg_template_table('hints/list', $hints, $rg);
1046
1047 rg_log_exit();
1048 return $ret;
1049 }
File inc/sess.inc.php changed (mode: 100644) (index 2135023..ef7eb3a)
... ... function rg_sess_add($db, $uid, $sid, $session_time, $lock_ip)
14 14 . " lock_ip=$lock_ip"); . " lock_ip=$lock_ip");
15 15
16 16 if ($lock_ip == 1) if ($lock_ip == 1)
17 $ip = @$_SERVER['REMOTE_ADDR'];
17 $ip = rg_ip();
18 18 else else
19 19 $ip = ""; $ip = "";
20 20 $now = time(); $now = time();
 
... ... function rg_sess_valid($db, $sid)
90 90 break; break;
91 91 } }
92 92
93 $ip = @$_SERVER['REMOTE_ADDR'];
93 $ip = rg_ip();
94 94 if (!empty($r['ip']) && (strcmp($r['ip'], $ip) != 0)) { if (!empty($r['ip']) && (strcmp($r['ip'], $ip) != 0)) {
95 95 rg_log("Session invalid because of IP" rg_log("Session invalid because of IP"
96 96 . " login=" . $r['ip'] . " now=$ip."); . " login=" . $r['ip'] . " now=$ip.");
 
... ... function rg_sess_update($db, $sess)
125 125 while (1) { while (1) {
126 126 if ($sess['last_db_write'] + 60 > $now) { if ($sess['last_db_write'] + 60 > $now) {
127 127 $_diff = $now - $sess['last_db_write']; $_diff = $now - $sess['last_db_write'];
128 rg_log("DEBUG: last_db_write is fresh enough (" . $_diff . "s).");
128 rg_log_debug('last_db_write is fresh enough (' . $_diff . 's)');
129 129 $ret = TRUE; $ret = TRUE;
130 130 break; break;
131 131 } }
 
... ... function rg_sess_update($db, $sess)
157 157 /* /*
158 158 * Destroy session * Destroy session
159 159 */ */
160 function rg_sess_destroy($db, $sid, &$ui)
160 function rg_sess_destroy($db, $sid)
161 161 { {
162 162 rg_prof_start("sess_destroy"); rg_prof_start("sess_destroy");
163 163 rg_log_enter("sess_destroy: sid=$sid..."); rg_log_enter("sess_destroy: sid=$sid...");
 
... ... function rg_sess_destroy($db, $sid, &$ui)
176 176 // Delete all tokens associated with this session // Delete all tokens associated with this session
177 177 rg_token_delete($db, $sid, ''); rg_token_delete($db, $sid, '');
178 178
179 $ui = array();
180 $ui['uid'] = 0;
181 $ui['is_admin'] = 0;
179 rg_ui_login_reset();
182 180
183 181 rg_cache_unset('sess' . '::' . $sid . '::'. 'info', rg_cache_unset('sess' . '::' . $sid . '::'. 'info',
184 182 RG_SOCKET_NO_WAIT); RG_SOCKET_NO_WAIT);
 
... ... function rg_sess_destroy($db, $sid, &$ui)
192 190 return $ret; return $ret;
193 191 } }
194 192
195 ?>
File inc/sql.inc.php changed (mode: 100644) (index 3f47828..6deab38)
2 2 require_once(__DIR__ . '/log.inc.php'); require_once(__DIR__ . '/log.inc.php');
3 3 require_once(__DIR__ . '/prof.inc.php'); require_once(__DIR__ . '/prof.inc.php');
4 4
5
6 $_sql_add = @file_get_contents('/home/rocketgit/sql_add');
7 if ($_sql_add !== FALSE)
8 $rg_sql .= ' ' . trim($_sql_add);
9
10
5 11 // Some constants for sql error codes // Some constants for sql error codes
6 12 define('RG_SQL_UNIQUE_VIOLATION', '23505'); define('RG_SQL_UNIQUE_VIOLATION', '23505');
7 13 define('RG_SQL_UNDEFINED_TABLE', '42P01'); define('RG_SQL_UNDEFINED_TABLE', '42P01');
 
... ... function rg_sql_open_nodelay($h)
64 70
65 71 if ($rg_sql_debug > 40) { if ($rg_sql_debug > 40) {
66 72 rg_log('My pid: ' . getmypid()); rg_log('My pid: ' . getmypid());
67 rg_log_ml('DEBUG: rg_sql_conn: ' . print_r($rg_sql_conn, TRUE));
73 rg_log_debug('rg_sql_conn: ' . print_r($rg_sql_conn, TRUE));
68 74 } }
69 75
70 76 if (isset($rg_sql_conn[$h]['db'])) { if (isset($rg_sql_conn[$h]['db'])) {
 
... ... function rg_sql_open($str)
153 159 } }
154 160
155 161 /* /*
156 * Escaping
162 * Escaping [obsolete - do not use]
157 163 */ */
158 164 function rg_sql_escape($h, $str) function rg_sql_escape($h, $str)
159 165 { {
 
... ... function rg_sql_query0($db, $sql, $r, $start_ts, $ignore, &$ignore_kicked)
192 198 } }
193 199 if (($state !== NULL) && (strcmp($state, '00000') !== 0)) { if (($state !== NULL) && (strcmp($state, '00000') !== 0)) {
194 200 if ($rg_sql_debug > 0) if ($rg_sql_debug > 0)
195 rg_log('DB: state=' . $state);
201 rg_log('DB: error_code=' . $state);
196 202
197 203 foreach ($ignore as $code) { foreach ($ignore as $code) {
198 204 if (strcmp($code, $state) == 0) { if (strcmp($code, $state) == 0) {
File inc/ssh.inc.php changed (mode: 100644) (index 41479d2..d499ab1)
... ... function rg_ssh_error()
26 26 return $rg_ssh_error; return $rg_ssh_error;
27 27 } }
28 28
29 function rg_ssh_status($db, $login_ui)
29 function rg_ssh_status($db)
30 30 { {
31 31 rg_log('ssh_status'); rg_log('ssh_status');
32 32
 
... ... function rg_ssh_status($db, $login_ui)
38 38 /* /*
39 39 * List repos * List repos
40 40 */ */
41 function rg_ssh_repos($db, $login_ui)
41 function rg_ssh_repos($db)
42 42 { {
43 43 rg_log('ssh_repos'); rg_log('ssh_repos');
44 44
45 $params = array('uid' => $login_ui['uid']);
45 $ui_login = rg_ui_login();
46
47 $params = array('uid' => $ui_login['uid']);
46 48 $sql = 'SELECT * FROM repos' $sql = 'SELECT * FROM repos'
47 49 . ' WHERE uid = @@uid@@' . ' WHERE uid = @@uid@@'
48 50 . ' AND deleted = 0' . ' AND deleted = 0'
 
... ... function rg_ssh_repos($db, $login_ui)
67 69 /* /*
68 70 * Info about a repo * Info about a repo
69 71 */ */
70 function rg_ssh_repo($db, $login_ui, $paras)
72 function rg_ssh_repo($db, $paras)
71 73 { {
72 74 rg_log('ssh_repo: ' . rg_array2string($paras)); rg_log('ssh_repo: ' . rg_array2string($paras));
73 75
 
... ... function rg_ssh_repo($db, $login_ui, $paras)
76 78 exit(0); exit(0);
77 79 } }
78 80
81 $ui_login = rg_ui_login();
82
79 83 $repo_name = trim($paras[0]); $repo_name = trim($paras[0]);
80 84
81 $ri = rg_repo_info($db, 0, $login_ui['uid'], $repo_name);
85 $ri = rg_repo_info($db, 0, $ui_login['uid'], $repo_name);
82 86 if ($ri['exists'] != 1) { if ($ri['exists'] != 1) {
83 87 fwrite(STDERR, 'Error: unknown repo.' . "\n"); fwrite(STDERR, 'Error: unknown repo.' . "\n");
84 88 exit(0); exit(0);
 
... ... function rg_ssh_totp_verify_ip($db, $uid, $ip)
166 170 /* /*
167 171 * Deal with TOTP stuff * Deal with TOTP stuff
168 172 */ */
169 function rg_ssh_totp($db, $ip, $login_ui, $paras)
173 function rg_ssh_totp($db, $paras)
170 174 { {
171 175 global $rg_ssh_host; global $rg_ssh_host;
172 176
173 177 rg_prof_start('ssh_totp'); rg_prof_start('ssh_totp');
174 rg_log_enter('ssh_totp ip=' . $ip . ' uid=' . $login_ui['uid']
175 . ' paras=' . rg_array2string($paras));
176 178
179 rg_log_enter('ssh_totp paras=' . rg_array2string($paras));
180
181 $ui_login = rg_ui_login();
177 182 $cmd = array_shift($paras); $cmd = array_shift($paras);
178 183 switch ($cmd) { switch ($cmd) {
179 184 case 'enroll': // this has nothing to do with scratch codes case 'enroll': // this has nothing to do with scratch codes
180 185 if (empty($paras)) { if (empty($paras)) {
181 186 $secret = rg_totp_base32_generate(16); $secret = rg_totp_base32_generate(16);
182 187
183 $r = rg_totp_enroll($db, $login_ui['uid'], 'SSH',
184 $secret, $ip, 'f');
188 $r = rg_totp_enroll($db, $ui_login['uid'], 'SSH',
189 $secret, rg_ip(), 'f');
185 190 if ($r !== TRUE) { if ($r !== TRUE) {
186 191 fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n");
187 192 break; break;
 
... ... function rg_ssh_totp($db, $ip, $login_ui, $paras)
199 204
200 205 $token = array_shift($paras); $token = array_shift($paras);
201 206
202 $v = rg_totp_device_verify($db, $login_ui['uid'], $token);
207 $v = rg_totp_device_verify($db, $ui_login['uid'], $token);
203 208 if ($v['token_valid'] != 1) { if ($v['token_valid'] != 1) {
204 209 fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n");
205 210 break; break;
 
... ... function rg_ssh_totp($db, $ip, $login_ui, $paras)
232 237 } }
233 238 //rg_log("token=$token days=$days hours=$hours minutes=$minutes"); //rg_log("token=$token days=$days hours=$hours minutes=$minutes");
234 239
235 $v = rg_totp_verify_any($db, $login_ui['uid'], $token);
240 $v = rg_totp_verify_any($db, $ui_login['uid'], $token);
236 241 if ($v['token_valid'] != 1) { if ($v['token_valid'] != 1) {
237 242 fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n");
238 243 break; break;
 
... ... function rg_ssh_totp($db, $ip, $login_ui, $paras)
241 246 $expire_ts = gmmktime(gmdate('H') + $hours, $expire_ts = gmmktime(gmdate('H') + $hours,
242 247 gmdate('i') + $minutes, gmdate('s'), gmdate('m'), gmdate('i') + $minutes, gmdate('s'), gmdate('m'),
243 248 gmdate('d') + $days, gmdate('Y')); gmdate('d') + $days, gmdate('Y'));
244 $r = rg_totp_add_ip($db, $login_ui['uid'], $v['id'],
245 $ip, $expire_ts);
249 $r = rg_totp_add_ip($db, $ui_login['uid'], $v['id'],
250 rg_ip(), $expire_ts);
246 251 if ($r === FALSE) { if ($r === FALSE) {
247 252 fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n");
248 253 break; break;
249 254 } }
250 255
251 echo 'Success! IP ' . $ip . ' added and is valid till '
256 echo 'Success! IP ' . rg_ip() . ' added and is valid till '
252 257 . gmdate('Y-m-d H:i:s', $expire_ts) . ' (UTC).' . "\n"; . gmdate('Y-m-d H:i:s', $expire_ts) . ' (UTC).' . "\n";
253 258 break; break;
254 259
255 260 case 'list-val': case 'list-val':
256 $r = rg_ssh_totp_verify_ip($db, $login_ui['uid'], $ip);
261 $r = rg_ssh_totp_verify_ip($db, $ui_login['uid'], rg_ip());
257 262 if ($r === FALSE) if ($r === FALSE)
258 263 break; break;
259 264
 
... ... function rg_ssh_totp($db, $ip, $login_ui, $paras)
270 275 case 'unenroll': case 'unenroll':
271 276 $token = array_shift($paras); $token = array_shift($paras);
272 277
273 $v = rg_totp_verify_any($db, $login_ui['uid'], $token);
278 $v = rg_totp_verify_any($db, $ui_login['uid'], $token);
274 279 if ($v['token_valid'] != 1) { if ($v['token_valid'] != 1) {
275 280 fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n");
276 281 break; break;
277 282 } }
278 283
279 $r = rg_totp_unenroll($db, $login_ui['uid']);
284 $r = rg_totp_unenroll($db, $ui_login['uid']);
280 285 if ($r !== TRUE) { if ($r !== TRUE) {
281 286 fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n");
282 287 break; break;
 
... ... function rg_ssh_totp($db, $ip, $login_ui, $paras)
288 293 case 'remove-device': case 'remove-device':
289 294 $token = array_shift($paras); $token = array_shift($paras);
290 295
291 $v = rg_totp_device_verify($db, $login_ui['uid'], $token);
296 $v = rg_totp_device_verify($db, $ui_login['uid'], $token);
292 297 if ($v['token_valid'] != 1) { if ($v['token_valid'] != 1) {
293 298 fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n");
294 299 break; break;
295 300 } }
296 301
297 302 $a = array($v['id'] => ''); $a = array($v['id'] => '');
298 $r = rg_totp_remove($db, $login_ui['uid'], $a);
303 $r = rg_totp_remove($db, $ui_login['uid'], $a);
299 304 if ($r !== TRUE) { if ($r !== TRUE) {
300 305 fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n");
301 306 break; break;
 
... ... function rg_ssh_totp($db, $ip, $login_ui, $paras)
313 318
314 319 $del_ip = array_shift($paras); $del_ip = array_shift($paras);
315 320
316 if (rg_ssh_totp_verify_ip($db, $login_ui['uid'], $ip) === FALSE)
321 if (rg_ssh_totp_verify_ip($db, $ui_login['uid'], rg_ip()) === FALSE)
317 322 break; break;
318 323
319 $r = rg_totp_del_ip($db, $login_ui['uid'], $del_ip);
324 $r = rg_totp_del_ip($db, $ui_login['uid'], $del_ip);
320 325 if ($r['found'] != 1) { if ($r['found'] != 1) {
321 326 fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n");
322 327 break; break;
 
... ... function rg_ssh_totp($db, $ip, $login_ui, $paras)
350 355 /* /*
351 356 * Deal with API * Deal with API
352 357 */ */
353 function rg_ssh_api($db, $ip, $login_ui, $paras)
358 function rg_ssh_api($db, $paras)
354 359 { {
355 360 rg_prof_start('ssh_api'); rg_prof_start('ssh_api');
356 361 rg_log_enter('ssh_api paras=' . rg_array2string($paras)); rg_log_enter('ssh_api paras=' . rg_array2string($paras));
 
... ... function rg_ssh_api($db, $ip, $login_ui, $paras)
381 386
382 387 $a['cmd'] = $cmd; $a['cmd'] = $cmd;
383 388 $x = array(); $x = array();
384 $x['login_ui'] = $login_ui;
385 $x['ip'] = $ip;
389 $x['ip'] = rg_ip();
386 390 $ret = array_merge($ret, rg_api($db, $x, $a)); $ret = array_merge($ret, rg_api($db, $x, $a));
387 391 break; break;
388 392 } }
389 393
390 rg_log_ml('DEBUG: ret: ' . print_r($ret, TRUE));
394 rg_log_debug('ret: ' . print_r($ret, TRUE));
391 395
392 396 rg_log_exit(); rg_log_exit();
393 397 rg_prof_end('ssh_api'); rg_prof_end('ssh_api');
 
... ... function rg_ssh_api($db, $ip, $login_ui, $paras)
397 401 /* /*
398 402 * Returns TRUE if we need to stop execution * Returns TRUE if we need to stop execution
399 403 */ */
400 function rg_ssh_dispatch($db, $ip, $login_ui, $orig_cmd)
404 function rg_ssh_dispatch($db, $orig_cmd)
401 405 { {
402 406 rg_log('ssh_dispatch orig_cmd=[' . $orig_cmd . ']'); rg_log('ssh_dispatch orig_cmd=[' . $orig_cmd . ']');
403 407
 
... ... function rg_ssh_dispatch($db, $ip, $login_ui, $orig_cmd)
415 419 case '': break; case '': break;
416 420 case 'totp': break; // totp will verify the ip only for some commands case 'totp': break; // totp will verify the ip only for some commands
417 421 default: default:
418 $r = rg_totp_verify_ip($db, $login_ui['uid'], $ip);
422 $ui_login = rg_ui_login();
423 $r = rg_totp_verify_ip($db, $ui_login['uid'], rg_ip());
419 424 if (($r['ok'] !== 1) if (($r['ok'] !== 1)
420 425 || ($r['enrolled'] && empty($r['ip_list']))) { || ($r['enrolled'] && empty($r['ip_list']))) {
421 426 fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n"); fwrite(STDERR, 'Error: ' . rg_totp_error() . ".\n");
 
... ... function rg_ssh_dispatch($db, $ip, $login_ui, $orig_cmd)
426 431
427 432 // Now, we can safely execute the command // Now, we can safely execute the command
428 433 switch ($cmd) { switch ($cmd) {
429 case 'status': rg_ssh_status($db, $login_ui); return TRUE;
430 case 'repos': rg_ssh_repos($db, $login_ui); return TRUE;
431 case 'repo': rg_ssh_repo($db, $login_ui, $paras); return TRUE;
432 case 'totp': rg_ssh_totp($db, $ip, $login_ui, $paras); return TRUE;
433 case 'api': rg_ssh_api($db, $ip, $login_ui, $paras); return TRUE;
434 case 'status': rg_ssh_status($db); return TRUE;
435 case 'repos': rg_ssh_repos($db); return TRUE;
436 case 'repo': rg_ssh_repo($db, $paras); return TRUE;
437 case 'totp': rg_ssh_totp($db, $paras); return TRUE;
438 case 'api': rg_ssh_api($db, $paras); return TRUE;
434 439 case '': case '':
435 440 fwrite(STDERR, "\n" fwrite(STDERR, "\n"
436 441 . 'Available commmands:' . "\n" . 'Available commmands:' . "\n"
 
... ... function rg_ssh_data($db, $type, $start, $end, $unit, $mode)
454 459 $params = array('start' => $start, 'end' => $end); $params = array('start' => $start, 'end' => $end);
455 460 switch ($type) { switch ($type) {
456 461 case 'create_key': case 'create_key':
457 $q = 'SELECT 1 AS value, itime FROM keys'
462 $q = 'SELECT itime FROM keys'
458 463 . ' WHERE itime >= @@start@@ AND itime <= @@end@@'; . ' WHERE itime >= @@start@@ AND itime <= @@end@@';
459 464 break; break;
460 465 default: default:
File inc/state.inc.php changed (mode: 100644) (index f2a1c54..3934dfe)
... ... function rg_state_get($db, $var)
41 41 $ret = $r; $ret = $r;
42 42 break; break;
43 43 } }
44
45 44 // So, we get an error from the cache daemon. // So, we get an error from the cache daemon.
46 45 // The only way is to go to database directly. // The only way is to go to database directly.
47 46
48 // Let's see if the 'state' table is present
49 $r = rg_sql_rel_exists($db, 'state');
50 if ($r === FALSE)
51 break;
52 if ($r === 0) {
53 $ret = '';
54 break;
55 }
56
47 $params = array();
48 $ignore = array(RG_SQL_UNDEFINED_TABLE);
57 49 $sql = 'SELECT * FROM state'; $sql = 'SELECT * FROM state';
58 $res = rg_sql_query($db, $sql);
50 $res = rg_sql_query_params_ignore($db, $sql, $params, $ignore, $kicked);
59 51 if ($res === FALSE) { if ($res === FALSE) {
60 rg_state_set_error(rg_sql_error());
52 if (!$kicked) {
53 rg_state_set_error(rg_sql_error());
54 break;
55 }
56
57 // table does not exists
58 $ret = '';
61 59 break; break;
62 60 } }
63 61
 
... ... function rg_state_get_uint($db, $var)
102 100 return intval($r); return intval($r);
103 101 } }
104 102
103 /*
104 * Return a state as an array
105 */
106 function rg_state_get_array($db, $var)
107 {
108 $r = rg_state_get($db, $var);
109 if ($r === FALSE)
110 return FALSE;
111
112 if (empty($r))
113 return array();
114
115 return rg_unserialize($r);
116 }
117
105 118 /* /*
106 119 * Set state * Set state
107 120 */ */
 
... ... function rg_state_set($db, $var, $value)
149 162 return $ret; return $ret;
150 163 } }
151 164
152 ?>
165 /*
166 * Set state - array version
167 */
168 function rg_state_set_array($db, $var, $value)
169 {
170 return rg_state_set($db, $var, rg_serialize($value));
171 }
172
File inc/stats.inc.php changed (mode: 100644) (index 50d8c0c..df091b6)
... ... function rg_stats_conns_insert($db)
108 108
109 109 $ret = FALSE; $ret = FALSE;
110 110 while (1) { while (1) {
111 $rg_stats_conns_paras['ip'] = rg_ip();
112
111 113 if (!isset($rg_stats_conns_paras['elap'])) if (!isset($rg_stats_conns_paras['elap']))
112 $rg_stats_conns_paras['elap'] = intval((microtime(TRUE) - $rg_stats_conns_paras['start']) * 1000);
114 $rg_stats_conns_paras['elap'] = intval((microtime(TRUE)
115 - $rg_stats_conns_paras['start']) * 1000);
113 116 $rg_stats_conns_paras['start'] = intval($rg_stats_conns_paras['start']); $rg_stats_conns_paras['start'] = intval($rg_stats_conns_paras['start']);
114 117
115 118 $list = array( $list = array(
 
... ... function rg_stats_conns_insert($db)
118 121 'referer' => '', 'referer' => '',
119 122 'url' => '', 'url' => '',
120 123 'uid' => 0, 'uid' => 0,
121 'repo_id' => 0
124 'login_uid' => 0,
125 'repo_id' => 0,
126 'bytes_in' => 0,
127 'bytes_out' => 0
122 128 ); );
123 129 foreach ($list as $k => $v) foreach ($list as $k => $v)
124 130 if (!isset($rg_stats_conns_paras[$k])) if (!isset($rg_stats_conns_paras[$k]))
125 131 $rg_stats_conns_paras[$k] = $v; $rg_stats_conns_paras[$k] = $v;
126 132
127 133 if (rg_is_bot($rg_stats_conns_paras['ua'])) { if (rg_is_bot($rg_stats_conns_paras['ua'])) {
134 //rg_log($rg_stats_conns_paras['ua'] . ' is bot! Skip!');
128 135 $ret = TRUE; $ret = TRUE;
129 136 break; break;
130 137 } }
131 138
132 139 $sql = 'INSERT INTO conns_' . gmdate('Y_m', $rg_stats_conns_paras['start']) $sql = 'INSERT INTO conns_' . gmdate('Y_m', $rg_stats_conns_paras['start'])
133 . ' (type, uid, repo_id, itime, ip, url'
134 . ', referer, elap, ua, cmd)'
135 . ' VALUES (@@type@@, @@uid@@'
140 . ' (type, uid, login_uid, repo_id, itime, ip, url'
141 . ', referer, elap, ua, cmd, bytes_in, bytes_out)'
142 . ' VALUES (@@type@@, @@uid@@, @@login_uid@@'
136 143 . ', @@repo_id@@, @@start@@, @@ip@@, @@url@@' . ', @@repo_id@@, @@start@@, @@ip@@, @@url@@'
137 . ', @@referer@@, @@elap@@, @@ua@@, @@cmd@@)';
144 . ', @@referer@@, @@elap@@, @@ua@@, @@cmd@@'
145 . ', @@bytes_in@@, @@bytes_out@@)';
138 146 $res = rg_sql_query_params($db, $sql, $rg_stats_conns_paras); $res = rg_sql_query_params($db, $sql, $rg_stats_conns_paras);
139 147 if ($res == FALSE) { if ($res == FALSE) {
140 148 rg_internal_error('cannot insert conns: ' . rg_sql_error()); rg_internal_error('cannot insert conns: ' . rg_sql_error());
 
... ... function rg_stats_conns_set($para, $value)
157 165 { {
158 166 global $rg_stats_conns_paras; global $rg_stats_conns_paras;
159 167
160 //rg_log('DEBUG: stats_conns_set ' . $para . '=[' . $value . ']');
168 //rg_log_debug('stats_conns_set ' . $para . '=[' . $value . ']');
161 169 $rg_stats_conns_paras[$para] = $value; $rg_stats_conns_paras[$para] = $value;
162 170 } }
163 171
 
... ... function rg_conns_data($db, $type, $start, $end, $unit, $mode)
170 178 $params = array('start' => $start, 'end' => $end); $params = array('start' => $start, 'end' => $end);
171 179 switch ($type) { switch ($type) {
172 180 case 'total': case 'total':
173 $q = 'SELECT 1 AS value, itime FROM conns'
181 $q = 'SELECT itime FROM conns'
174 182 . ' WHERE itime >= @@start@@ AND itime <= @@end@@'; . ' WHERE itime >= @@start@@ AND itime <= @@end@@';
175 183 break; break;
176 184
File inc/struct.inc.php changed (mode: 100644) (index 6de69af..4736a5c)
... ... $rg_sql_struct[47]['other'] = array(
733 733 'ALTER TABLE pkg_subrepos ADD distro_info TEXT NOT NULL DEFAULT \'\'', 'ALTER TABLE pkg_subrepos ADD distro_info TEXT NOT NULL DEFAULT \'\'',
734 734 'pkg_repo password' => 'pkg_repo password' =>
735 735 'ALTER TABLE pkg_repos ADD password TEXT NOT NULL DEFAULT \'\'', 'ALTER TABLE pkg_repos ADD password TEXT NOT NULL DEFAULT \'\'',
736 'conns bytes' =>
737 'ALTER TABLE conns ADD bytes BIGINT NOT NULL DEFAULT -1',
736 'conns bytes in' =>
737 'ALTER TABLE conns ADD bytes_in BIGINT NOT NULL DEFAULT -1',
738 'conns bytes out' =>
739 'ALTER TABLE conns ADD bytes_out BIGINT NOT NULL DEFAULT -1',
738 740 'keys flags' => 'keys flags' =>
739 'ALTER TABLE keys ADD flags TEXT NOT NULL DEFAULT \'\''
741 'ALTER TABLE keys ADD flags TEXT NOT NULL DEFAULT \'\'',
742 'keys spurious index on id' =>
743 'DROP INDEX IF EXISTS keys_i_key_id'
740 744 ); );
741 745
742 746 // Do not forget to add the new created tables to statistics. // Do not forget to add the new created tables to statistics.
 
... ... function rg_sql_struct_update_needed($db)
847 851 break; break;
848 852 } }
849 853
850 rg_log('DEBUG: sql_schema_ver=' . $rg_sql_schema_ver
854 rg_log_debug('sql_schema_ver=' . $rg_sql_schema_ver
851 855 . ' != old=' . $old); . ' != old=' . $old);
852 856 $ret = 1; $ret = 1;
853 857 break; break;
 
... ... function rg_sql_struct_update($db, $flags)
868 872 rg_log_enter("sql_struct_update: flags=$flags"); rg_log_enter("sql_struct_update: flags=$flags");
869 873
870 874 $ret = FALSE; $ret = FALSE;
871 $locked = FALSE;
872 875 $rollback = 0; $rollback = 0;
873 876 while (1) { while (1) {
874 877 $old = rg_sql_struct_get_current_ver($db); $old = rg_sql_struct_get_current_ver($db);
 
... ... function rg_sql_struct_update($db, $flags)
880 883 break; break;
881 884 } }
882 885
883 // If we cannot lock, return error
884 if (rg_lock("schema_update.lock") === FALSE)
885 break;
886 $locked = TRUE;
887
888 886 if (rg_sql_begin($db) !== TRUE) if (rg_sql_begin($db) !== TRUE)
889 887 break; break;
890 888 $rollback = 1; $rollback = 1;
 
... ... function rg_sql_struct_update($db, $flags)
912 910 if ($rollback == 1) if ($rollback == 1)
913 911 rg_sql_rollback($db); rg_sql_rollback($db);
914 912
915 if ($locked)
916 rg_unlock('schema_update.lock');
917
918 913 rg_log_exit(); rg_log_exit();
919 914 return $ret; return $ret;
920 915 } }
 
... ... function rg_sql_struct_parts_update($db)
948 943 break; break;
949 944 if ($last_ts == 0) if ($last_ts == 0)
950 945 $last_ts = gmmktime(0, 0, 0, gmdate('m') - 1, 1, gmdate('Y')); $last_ts = gmmktime(0, 0, 0, gmdate('m') - 1, 1, gmdate('Y'));
951 rg_log('DEBUG: last_ts=' . $last_ts . ' (' . gmdate('Y-m-d', $last_ts) . ')');
946 rg_log_debug('last_ts=' . $last_ts . ' (' . gmdate('Y-m-d', $last_ts) . ')');
952 947
953 948 // goot_ts = What month should be covered? // goot_ts = What month should be covered?
954 949 $good_ts = gmmktime(0, 0, 0, gmdate('m') + 1, 1, gmdate('Y')); $good_ts = gmmktime(0, 0, 0, gmdate('m') + 1, 1, gmdate('Y'));
955 rg_log('DEBUG: good_ts=' . $good_ts . ' (' . gmdate('Y-m-d', $good_ts) . ')');
950 rg_log_debug('good_ts=' . $good_ts . ' (' . gmdate('Y-m-d', $good_ts) . ')');
956 951
957 952 $cur_list = sha1(rg_serialize($rg_sql_struct_parts)); $cur_list = sha1(rg_serialize($rg_sql_struct_parts));
958 rg_log('DEBUG: last_list=[' . $last_list . '] cur_list=[' . $cur_list . ']');
953 rg_log_debug('last_list=[' . $last_list . '] cur_list=[' . $cur_list . ']');
959 954 if (strcmp($last_list, $cur_list) != 0) { if (strcmp($last_list, $cur_list) != 0) {
960 955 // We need to set last_ts to first day of the previous month // We need to set last_ts to first day of the previous month
961 956 $last_ts = gmmktime(0, 0, 0, gmdate('m') - 1, 1, gmdate('Y')); $last_ts = gmmktime(0, 0, 0, gmdate('m') - 1, 1, gmdate('Y'));
962 rg_log('DEBUG: list of the parts changed. Set last_ts to ' . $last_ts);
957 rg_log_debug('list of the parts changed. Set last_ts to ' . $last_ts);
963 958 $doit = TRUE; $doit = TRUE;
964 959 break; break;
965 960 } }
 
... ... function rg_sql_struct_parts_update($db)
976 971 break; break;
977 972 } }
978 973
979 rg_log('DEBUG: doit=' . ($doit ? 1 : 0) . ' ret=' . ($ret === FALSE ? 'FALSE' : 'TRUE'));
974 rg_log_debug('doit=' . ($doit ? 1 : 0)
975 . ' ret=' . ($ret === FALSE ? 'FALSE' : 'TRUE'));
980 976 $rollback = 0; $rollback = 0;
981 977 $locked = FALSE; $locked = FALSE;
982 978 while ($doit) { while ($doit) {
983 979 // If we cannot lock, return error // If we cannot lock, return error
984 if (rg_lock('parts_create.lock') === FALSE)
980 if (rg_lock('parts_create.lock', 0) === FALSE)
985 981 break; break;
986 982 $locked = TRUE; $locked = TRUE;
987 983
 
... ... function rg_sql_struct_parts_update($db)
993 989 $month = gmdate('m', $last_ts) + 1; $month = gmdate('m', $last_ts) + 1;
994 990 $year = gmdate('Y', $last_ts); $year = gmdate('Y', $last_ts);
995 991 $ts = gmmktime(0, 0, 0, $month, 1, $year); $ts = gmmktime(0, 0, 0, $month, 1, $year);
996 rg_log('DEBUG: ts=' . $ts . ' good_ts=' . $good_ts . ' month=' . $month);
992 rg_log_debug('ts=' . $ts . ' good_ts=' . $good_ts . ' month=' . $month);
997 993 while ($ts <= $good_ts) { while ($ts <= $good_ts) {
998 rg_log('DEBUG: ts=' . $ts);
994 rg_log_debug('ts=' . $ts);
999 995
1000 996 $month++; $month++;
1001 997 $next_ts = gmmktime(0, 0, 0, $month, 1, $year); $next_ts = gmmktime(0, 0, 0, $month, 1, $year);
 
... ... function rg_sql_struct_parts_update($db)
1096 1092 */ */
1097 1093 function rg_struct_ok($db) function rg_struct_ok($db)
1098 1094 { {
1095 rg_log_enter('struct_ok');
1096
1099 1097 $ret = FALSE; $ret = FALSE;
1100 while (1) {
1098 $locked = FALSE;
1099 do {
1101 1100 $restart_cache = FALSE; $restart_cache = FALSE;
1102 1101
1103 $r = rg_sql_struct_update_needed($db);
1104 if ($r === FALSE)
1102 $ud = rg_sql_struct_update_needed($db);
1103 if ($ud === FALSE)
1104 break;
1105
1106 if ($ud === 0) { // struct update not needed
1107 $uf = rg_fixes_needed($db);
1108 if ($uf === FALSE)
1109 break;
1110 if ($uf === 0) {
1111 $ret = TRUE;
1112 break;
1113 }
1114 } else {
1115 $uf = 1;
1116 }
1117
1118 if (rg_lock('schema_update.lock', 0) === FALSE)
1105 1119 break; break;
1106 if ($r == 1) {
1120 $locked = TRUE;
1121
1122 if ($ud === 1) {
1107 1123 $r = rg_sql_struct_update($db, 0); $r = rg_sql_struct_update($db, 0);
1108 1124 if ($r !== TRUE) if ($r !== TRUE)
1109 1125 break; break;
1110 rg_cache_restart();
1111 1126 } }
1112 1127
1113 $r = rg_fixes_needed($db);
1114 if ($r === FALSE)
1115 break;
1116 if ($r == 1) {
1128 if ($uf === 1) {
1117 1129 $r = rg_fixes_update($db); $r = rg_fixes_update($db);
1118 1130 if ($r !== TRUE) if ($r !== TRUE)
1119 1131 break; break;
1120 rg_cache_restart();
1121 1132 } }
1122 1133
1134 rg_cache_restart();
1135
1123 1136 $r = rg_sql_struct_parts_update($db); $r = rg_sql_struct_parts_update($db);
1124 1137 if ($r !== TRUE) if ($r !== TRUE)
1125 1138 break; break;
 
... ... function rg_struct_ok($db)
1132 1145 sha512(microtime(TRUE))); sha512(microtime(TRUE)));
1133 1146
1134 1147 $ret = TRUE; $ret = TRUE;
1135 break;
1136 }
1148 } while (0);
1137 1149
1150 if ($locked)
1151 rg_unlock('schema_update.lock');
1152
1153 rg_log_exit();
1138 1154 return $ret; return $ret;
1139 1155 } }
1140 1156
File inc/token.inc.php changed (mode: 100644) (index fbfbaab..4c6e355)
... ... function rg_token_valid($db, $rg, $tag, $double_allowed)
130 130
131 131 $hash = substr($hash, 0, 16); $hash = substr($hash, 0, 16);
132 132 if (strcmp($sign, $hash) != 0) { if (strcmp($sign, $hash) != 0) {
133 rg_log("DEBUG: substr(token, 16, 16)=$sign !="
134 . " hash_hmac(data,key)=$hash data=$data");
133 rg_log_debug('substr(token, 16, 16)=' . $sign . ' !='
134 . ' hash_hmac(data,key)=' . $hash . ' data=' . $data);
135 135 rg_token_set_error("token invalid"); rg_token_set_error("token invalid");
136 136 rg_security_violation_no_exit("invalid token (sign)"); rg_security_violation_no_exit("invalid token (sign)");
137 137 break; break;
 
... ... function rg_token_get($db, $rg, $tag)
241 241 } }
242 242 $sign = substr($sign, 0, 16); $sign = substr($sign, 0, 16);
243 243 $ret = $rand . $sign; $ret = $rand . $sign;
244 rg_log('DEBUG: generated token ' . $ret);
244 rg_log_debug('generated token ' . $ret);
245 245 $ret2 = $ret; $ret2 = $ret;
246 246
247 if ($rg['debug'] == 1)
247 if (rg_debug() > 0)
248 248 $ret2 .= ':' . $tag; $ret2 .= ':' . $tag;
249 249
250 250 rg_cache_set($key, $ret2, RG_SOCKET_NO_WAIT); rg_cache_set($key, $ret2, RG_SOCKET_NO_WAIT);
File inc/totp.inc.php changed (mode: 100644) (index d8f347a..b2ef532)
... ... function rg_totp_compute($key, $tc, $digits)
104 104 function rg_totp_verify_tc($key, $tc, $token) function rg_totp_verify_tc($key, $tc, $token)
105 105 { {
106 106 $t = rg_totp_compute($key, $tc, 6); $t = rg_totp_compute($key, $tc, 6);
107 //rg_log('DEBUG: compute[tc=' . $tc . ']=' . $t);
107 //rg_log_debug('compute[tc=' . $tc . ']=' . $t);
108 108 if (strcmp($token, $t) == 0) if (strcmp($token, $t) == 0)
109 109 return $tc; return $tc;
110 110
 
... ... function rg_totp_verify($key, $ts, $token)
131 131 $list = array($tc, $tc - 1, $tc - 2, $tc + 1, $tc + 2); $list = array($tc, $tc - 1, $tc - 2, $tc + 1, $tc + 2);
132 132 foreach ($list as $tc) { foreach ($list as $tc) {
133 133 $ret = rg_totp_verify_tc($key, $tc, $token); $ret = rg_totp_verify_tc($key, $tc, $token);
134 //rg_log('DEBUG: using tc ' . $tc . ', ret=' . $ret);
134 //rg_log_debug('using tc ' . $tc . ', ret=' . $ret);
135 135 if ($ret !== FALSE) if ($ret !== FALSE)
136 136 break; break;
137 137 } }
 
... ... function rg_totp_text($secret)
171 171
172 172 $extra = urlencode(gmdate('Y-m-d H:i')); $extra = urlencode(gmdate('Y-m-d H:i'));
173 173 $secret = urlencode($secret); $secret = urlencode($secret);
174 $issuer = urlencode($rg['hostname']);
174 $issuer = urlencode($rg['base_url']);
175 175 $cmd = "qrencode -o - --level=M --margin=2 --type=UTF8" $cmd = "qrencode -o - --level=M --margin=2 --type=UTF8"
176 176 . " 'otpauth://totp/$extra?secret=$secret&issuer=$issuer'"; . " 'otpauth://totp/$extra?secret=$secret&issuer=$issuer'";
177 177 $a = rg_exec($cmd, '', FALSE, FALSE, FALSE); $a = rg_exec($cmd, '', FALSE, FALSE, FALSE);
 
... ... function rg_totp_sc_verify($db, $uid, $token)
775 775 $ret['enrolled'] = 1; $ret['enrolled'] = 1;
776 776
777 777 foreach ($per_itime as $sc => $junk) { foreach ($per_itime as $sc => $junk) {
778 rg_log('DEBUG: comparing with ' . $sc);
778 rg_log_debug('comparing with ' . $sc);
779 779 if (strcmp($sc, $token) == 0) { if (strcmp($sc, $token) == 0) {
780 780 $r = rg_totp_sc_remove($db, $uid, $r = rg_totp_sc_remove($db, $uid,
781 781 $itime, $token); $itime, $token);
 
... ... function rg_totp_sc_verify($db, $uid, $token)
798 798 break; break;
799 799 } }
800 800
801 rg_log_ml('DEBUG: sc_verify returns: ' . print_r($ret, TRUE));
801 rg_log_debug('sc_verify returns: ' . print_r($ret, TRUE));
802 802
803 803 rg_log_exit(); rg_log_exit();
804 804 rg_prof_end('totp_sc_verify'); rg_prof_end('totp_sc_verify');
 
... ... function rg_totp_sc_list($db, $uid)
854 854 if ($ret['ok'] == 1) if ($ret['ok'] == 1)
855 855 rg_totp_sc_cosmetic_list($ret['list']); rg_totp_sc_cosmetic_list($ret['list']);
856 856
857 //rg_log_ml('DEBUG: sc_list ret[list]: ' . print_r($ret['list'], TRUE));
857 //rg_log_debug('sc_list ret[list]: ' . print_r($ret['list'], TRUE));
858 858
859 859 rg_log_exit(); rg_log_exit();
860 860 rg_prof_end('totp_sc_list'); rg_prof_end('totp_sc_list');
 
... ... function rg_totp_verify_any($db, $uid, $token)
1119 1119 break; break;
1120 1120 } }
1121 1121
1122 rg_log_ml("DEBUG: verify_any returns: " . print_r($ret, TRUE));
1122 rg_log_debug('verify_any returns: ' . print_r($ret, TRUE));
1123 1123
1124 1124 rg_log_exit(); rg_log_exit();
1125 1125 rg_prof_end('totp_verify_any'); rg_prof_end('totp_verify_any');
 
... ... function rg_totp_sc_high_level($db, $rg, $paras)
1136 1136
1137 1137 $ret = ''; $ret = '';
1138 1138
1139 $ui_login = rg_ui_login();
1140
1139 1141 $rg['HTML:gen_errmsg'] = ''; $rg['HTML:gen_errmsg'] = '';
1140 1142 $gen_errmsg = array(); $gen_errmsg = array();
1141 1143 $generate = rg_var_uint('generate'); $generate = rg_var_uint('generate');
 
... ... function rg_totp_sc_high_level($db, $rg, $paras)
1150 1152 break; break;
1151 1153 } }
1152 1154
1153 $r = rg_totp_sc_generate($db, $rg['login_ui']['uid'], 20);
1155 $r = rg_totp_sc_generate($db, $ui_login['uid'], 20);
1154 1156 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
1155 1157 $gen_errmsg[] = rg_totp_error(); $gen_errmsg[] = rg_totp_error();
1156 1158 break; break;
 
... ... function rg_totp_sc_high_level($db, $rg, $paras)
1178 1180 } }
1179 1181
1180 1182 $list = rg_var_str("delete_list"); $list = rg_var_str("delete_list");
1181 $r = rg_totp_sc_remove_list($db, $rg['login_ui']['uid'], $list);
1183 $r = rg_totp_sc_remove_list($db, $ui_login['uid'], $list);
1182 1184 if ($r !== TRUE) { if ($r !== TRUE) {
1183 1185 $del_errmsg[] = 'cannot delete: ' . rg_totp_error(); $del_errmsg[] = 'cannot delete: ' . rg_totp_error();
1184 1186 break; break;
 
... ... function rg_totp_sc_high_level($db, $rg, $paras)
1193 1195 $rg['rg_form_token'] = rg_token_get($db, $rg, 'sc'); $rg['rg_form_token'] = rg_token_get($db, $rg, 'sc');
1194 1196 $ret .= rg_template('user/settings/totp/sc/gen.html', $rg, TRUE /*xss*/); $ret .= rg_template('user/settings/totp/sc/gen.html', $rg, TRUE /*xss*/);
1195 1197
1196 $r = rg_totp_sc_list($db, $rg['login_ui']['uid']);
1198 $r = rg_totp_sc_list($db, $ui_login['uid']);
1197 1199 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
1198 1200 $rg['totp_errmsg'] = rg_totp_error(); $rg['totp_errmsg'] = rg_totp_error();
1199 1201 $ret .= rg_template('user/settings/totp/sc/list_err.html', $ret .= rg_template('user/settings/totp/sc/list_err.html',
 
... ... function rg_totp_sc_high_level($db, $rg, $paras)
1201 1203 } else { } else {
1202 1204 // prepare list // prepare list
1203 1205 $_list = array(); $_list = array();
1204 //rg_log_ml('DEBUG: prepare sc list: ' . print_r($r['list'], TRUE));
1206 //rg_log_debug('prepare sc list: ' . print_r($r['list'], TRUE));
1205 1207 foreach ($r['list'] as $itime => $per_itime) { foreach ($r['list'] as $itime => $per_itime) {
1206 1208 foreach ($per_itime as $junk => $sc) { foreach ($per_itime as $junk => $sc) {
1207 1209 if (!isset($_list[$itime])) { if (!isset($_list[$itime])) {
 
... ... function rg_totp_list_high_level($db, $rg, $paras)
1238 1240
1239 1241 $ret = ''; $ret = '';
1240 1242
1243 $ui_login = rg_ui_login();
1244
1241 1245 $del_errmsg = array(); $del_errmsg = array();
1242 1246 $rg['HTML:del_errmsg'] = ''; $rg['HTML:del_errmsg'] = '';
1243 1247 $rg['HTML:del_status'] = ''; $rg['HTML:del_status'] = '';
 
... ... function rg_totp_list_high_level($db, $rg, $paras)
1255 1259 } }
1256 1260
1257 1261 $list = rg_var_str("delete_list"); $list = rg_var_str("delete_list");
1258 $r = rg_totp_remove($db, $rg['login_ui']['uid'], $list);
1262 $r = rg_totp_remove($db, $ui_login['uid'], $list);
1259 1263 if ($r !== TRUE) { if ($r !== TRUE) {
1260 1264 $del_errmsg[] = 'cannot delete: ' . rg_totp_error(); $del_errmsg[] = 'cannot delete: ' . rg_totp_error();
1261 1265 break; break;
 
... ... function rg_totp_list_high_level($db, $rg, $paras)
1266 1270 break; break;
1267 1271 } }
1268 1272
1269 $r = rg_totp_device_list($db, $rg['login_ui']['uid']);
1273 $r = rg_totp_device_list($db, $ui_login['uid']);
1270 1274 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
1271 1275 $rg['totp_errmsg'] = rg_totp_error(); $rg['totp_errmsg'] = rg_totp_error();
1272 1276 $ret .= rg_template('user/settings/totp/list_err.html', $ret .= rg_template('user/settings/totp/list_err.html',
 
... ... function rg_totp_enroll_high_level($db, $rg, $paras)
1329 1333 break; break;
1330 1334 } }
1331 1335
1332 $ip = $_SERVER['REMOTE_ADDR'];
1333 $r = rg_totp_enroll($db, $rg['login_ui']['uid'],
1334 $name, $secret, $ip, 't');
1336 $ui_login = rg_ui_login();
1337 $r = rg_totp_enroll($db, $ui_login['uid'],
1338 $name, $secret, rg_ip(), 't');
1335 1339 if ($r !== TRUE) { if ($r !== TRUE) {
1336 1340 $errmsg[] = rg_totp_error(); $errmsg[] = rg_totp_error();
1337 1341 break; break;
File inc/user.inc.php changed (mode: 100644) (index f3f9098..51f292d)
... ... $rg_user_rights = array(
18 18 "R" => "Remove user", "R" => "Remove user",
19 19 "S" => "Suspend user", "S" => "Suspend user",
20 20 "G" => "Grant rights", "G" => "Grant rights",
21 'R' => 'Revoke rights',
21 22 "M" => "Give admin rights" "M" => "Give admin rights"
22 23 ); );
23 24
 
... ... function rg_user_error()
39 40 return $rg_user_error; return $rg_user_error;
40 41 } }
41 42
43
44 /* Functions for template system */
45 function rg_user_template_ui_login($param)
46 {
47 $r = rg_ui_login();
48 rg_user_cosmetic($r);
49
50 $ret = array();
51
52 if (isset($r['HTML:' . $param])) {
53 $ret['value'] = $r['HTML:' . $param];
54 $ret['html'] = 1;
55 return $ret;
56 }
57
58 if (isset($r[$param])) {
59 $ret['value'] = $r[$param];
60 $ret['html'] = 0;
61 return $ret;
62 }
63
64 rg_log_debug('ui_page: param=' . $param . ' not found; r: ' . print_r($r, TRUE));
65
66 return '?';
67 }
68 rg_template_func('UI_LOGIN', 'rg_user_template_ui_login');
69
70 function rg_user_template_ui_page($param)
71 {
72 $r = rg_ui_page();
73 rg_user_cosmetic($r);
74
75 $ret = array();
76
77 if (isset($r['HTML:' . $param])) {
78 $ret['value'] = $r['HTML:' . $param];
79 $ret['html'] = 1;
80 return $ret;
81 }
82
83 if (isset($r[$param])) {
84 $ret['value'] = $r[$param];
85 $ret['html'] = 0;
86 return $ret;
87 }
88
89 rg_log_debug('ui_page: param=' . $param . ' not found; r: ' . print_r($r, TRUE));
90
91 return '?';
92 }
93 rg_template_func('UI_PAGE', 'rg_user_template_ui_page');
94
95
42 96 /* /*
43 97 * Event functions * Event functions
44 98 */ */
 
... ... function rg_user_event_ask_email_confirmation($db, $ev)
68 122 rg_log('rg_user_event_ask_email_confirmation: ev=' rg_log('rg_user_event_ask_email_confirmation: ev='
69 123 . rg_array2string($ev)); . rg_array2string($ev));
70 124
71 if (!isset($ev['ui']['email'])) {
72 $ev['ui'] = rg_user_info($db, $ev['ui']['uid'], '', '');
73 if ($ev['ui']['exists'] != 1)
74 return FALSE;
75 }
76
77 $ev['ui']['ignore_confirmed'] = 1;
125 $ev['ui_login']['ignore_confirmed'] = 1;
78 126 rg_mail_template('mail/user/econf', $ev); rg_mail_template('mail/user/econf', $ev);
79 127
80 128 return array(); return array();
 
... ... function rg_user_event_new($db, $event)
87 135 { {
88 136 $ret = array(); $ret = array();
89 137
90 //rg_log_ml('DEBUG: user_event_new: event: ' . print_r($event, TRUE));
138 //rg_log_debug('user_event_new: event: ' . print_r($event, TRUE));
91 139
92 140 $event['op'] = 'new'; $event['op'] = 'new';
93 141
 
... ... function rg_user_event_new($db, $event)
105 153 /* /*
106 154 * Event for login * Event for login
107 155 */ */
108 function rg_user_event_login($db, $event)
156 function rg_user_event_login($db, $ev)
109 157 { {
110 158 $ret = FALSE; $ret = FALSE;
111 159 while (1) { while (1) {
112 $r = rg_user_set_last_seen($db, $event['ui']['uid'], $event['itime'],
113 $event['ip']);
160 $r = rg_user_set_last_seen($db, $ev['ui_login']['uid'],
161 $ev['itime'], $ev['ip']);
114 162 if ($r !== TRUE) if ($r !== TRUE)
115 163 break; break;
116 164
 
... ... function rg_user_empty()
168 216 'username' => '', 'username' => '',
169 217 'exists' => 0, 'exists' => 0,
170 218 'organization' => 0, 'organization' => 0,
171 'confirmed' => 0
172 );
219 'confirmed' => 0,
220 'email' => ''
221 );
173 222 } }
174 223
175 224 /* /*
 
... ... function rg_user_link_by_name($db, $event)
196 245 { {
197 246 rg_log("user_link_by_name: event=" . rg_array2string($event)); rg_log("user_link_by_name: event=" . rg_array2string($event));
198 247
199 $by_id = rg_user_path_by_id($event['ui']['uid']);
248 $by_id = rg_user_path_by_id($event['ui_login']['uid']);
200 249 if (!is_dir($by_id) && (mkdir($by_id, 0700, TRUE) === FALSE)) { if (!is_dir($by_id) && (mkdir($by_id, 0700, TRUE) === FALSE)) {
201 250 rg_user_set_error("cannot mkdir by_id=$by_id (" . rg_php_err() . ")"); rg_user_set_error("cannot mkdir by_id=$by_id (" . rg_php_err() . ")");
202 251 return FALSE; return FALSE;
203 252 } }
204 253
205 $by_name = rg_user_path_by_name($event['ui']['username']);
254 $by_name = rg_user_path_by_name($event['ui_login']['username']);
206 255 $by_name_parent = dirname($by_name); $by_name_parent = dirname($by_name);
207 256 if (!is_dir($by_name_parent) if (!is_dir($by_name_parent)
208 257 && (mkdir($by_name_parent, 0700, TRUE) === FALSE)) { && (mkdir($by_name_parent, 0700, TRUE) === FALSE)) {
 
... ... function rg_user_link_by_name($db, $event)
210 259 return FALSE; return FALSE;
211 260 } }
212 261
213 $by_id_rel = rg_user_path_by_id_rel($event['ui']['uid']);
262 $by_id_rel = rg_user_path_by_id_rel($event['ui_login']['uid']);
214 263 if (is_link($by_name)) if (is_link($by_name))
215 264 unlink($by_name); unlink($by_name);
216 265 if (symlink($by_id_rel, $by_name) === FALSE) { if (symlink($by_id_rel, $by_name) === FALSE) {
 
... ... function rg_user_insert_rename($db, $uid, $old_name)
432 481 * Rename a user * Rename a user
433 482 * We keep the old name around, so the clients do not break. * We keep the old name around, so the clients do not break.
434 483 */ */
435 function rg_user_rename($db, $ui, $new_name)
484 function rg_user_rename($db, $ui_login, $new_name)
436 485 { {
437 486 rg_prof_start("user_rename"); rg_prof_start("user_rename");
438 rg_log_enter("user_rename: from=[" . $ui['username'] . "]"
487 rg_log_enter("user_rename: from=[" . $ui_login['username'] . "]"
439 488 . " to=[" . $new_name . "]..."); . " to=[" . $new_name . "]...");
440 489
441 $user_path = rg_user_path_by_id($ui['uid']);
442 $old_path = rg_user_path_by_id_rel($ui['uid']);
490 $user_path = rg_user_path_by_id($ui_login['uid']);
491 $old_path = rg_user_path_by_id_rel($ui_login['uid']);
443 492 $new_path = rg_user_path_by_name($new_name); $new_path = rg_user_path_by_name($new_name);
444 493 rg_log("old_path=$old_path new_path=$new_path"); rg_log("old_path=$old_path new_path=$new_path");
445 494
 
... ... function rg_user_rename($db, $ui, $new_name)
484 533 } }
485 534
486 535 // TOOD: transaction? // TOOD: transaction?
487 $r = rg_user_insert_rename($db, $ui['uid'], $new_name);
536 $r = rg_user_insert_rename($db, $ui_login['uid'], $new_name);
488 537 if ($r !== TRUE) if ($r !== TRUE)
489 538 break; break;
490 539
 
... ... function rg_user_rename($db, $ui, $new_name)
492 541 $event = array( $event = array(
493 542 'category' => 'user_event_rename', 'category' => 'user_event_rename',
494 543 'prio' => 50, 'prio' => 50,
495 'ui' => $ui,
496 'rename_from' => $ui['username'],
544 'ui_login' => $ui_login,
545 'rename_from' => $ui_login['username'],
497 546 'rename_to' => $new_name 'rename_to' => $new_name
498 547 ); );
499 548 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
 
... ... function rg_user_rename($db, $ui, $new_name)
519 568 function rg_user_edit_no_check($db, $d) function rg_user_edit_no_check($db, $d)
520 569 { {
521 570 rg_prof_start('user_edit_no_check'); rg_prof_start('user_edit_no_check');
522 rg_log_enter('user_edit_no_check: d: ' . rg_array2string($d));
571 rg_log_enter('user_edit_no_check');
572
573 if (rg_debug() > 0)
574 rg_log('d: ' . rg_array2string($d));
523 575
524 576 $ret = array('ok' => 0, 'already_exists' => 0); $ret = array('ok' => 0, 'already_exists' => 0);
525 577 while (1) { while (1) {
 
... ... function rg_user_edit_no_check($db, $d)
599 651 $ret['errmsg'] = 'cannot insert/update user info'; $ret['errmsg'] = 'cannot insert/update user info';
600 652 break; break;
601 653 } }
602 rg_log('DEBUG: username already present');
654 rg_log_debug('username already present');
603 655 $ret['already_exists'] = 1; $ret['already_exists'] = 1;
604 656 break; break;
605 657 } }
 
... ... function rg_user_edit_no_check($db, $d)
620 672 $event = array( $event = array(
621 673 'category' => 'user_event_new', 'category' => 'user_event_new',
622 674 'prio' => 50, 'prio' => 50,
623 'ui' => $d2,
624 'base_url' => rg_base_url()
675 'ui_login' => $d2,
676 'base_url' => rg_base_url($db, '', '')
625 677 ); );
626 678 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
627 679 if ($r === FALSE) { if ($r === FALSE) {
 
... ... function rg_user_edit_no_check($db, $d)
635 687
636 688 if (isset($d['ask_for_email_confirmation']) if (isset($d['ask_for_email_confirmation'])
637 689 && ($d['ask_for_email_confirmation'] == 1)) { && ($d['ask_for_email_confirmation'] == 1)) {
638 $r = rg_user_ask_for_email_confirmation($db, $d['uid']);
690 $r = rg_user_ask_for_email_confirmation($db, $d);
639 691 if ($r === FALSE) { if ($r === FALSE) {
640 692 $ret['errmsg'] = 'cannot add event'; $ret['errmsg'] = 'cannot add event';
641 693 break; break;
 
... ... function rg_user_edit_no_check($db, $d)
645 697
646 698 // TODO: should we cache here the user_by_uid and user_by_name // TODO: should we cache here the user_by_uid and user_by_name
647 699
648 $ret['ui'] = $d;
700 $ret['ui_login'] = $d;
649 701 $ret['ok'] = 1; $ret['ok'] = 1;
650 702 break; break;
651 703 } }
 
... ... function rg_user_edit($db, $d)
682 734 break; break;
683 735 } }
684 736
685 $ret = $r['ui']['uid'];
737 $ret = $r['ui_login']['uid'];
686 738 break; break;
687 739 } }
688 740
 
... ... function rg_user_remove($db, $rg, $uid)
703 755
704 756 $ret = FALSE; $ret = FALSE;
705 757 while (1) { while (1) {
706 $x = array();
707 $x['obj_id'] = $uid;
708 $x['type'] = 'user';
709 $x['owner'] = $uid;
710 $x['uid'] = $rg['login_ui']['uid'];
711 $x['username'] = $rg['login_ui']['username'];
712 $x['needed_rights'] = 'R';
713 $x['ip'] = $rg['ip'];
714 $x['misc'] = '';
715 if (rg_rights_allow($db, $x) !== TRUE)
758 if (rg_rights_allow($db, $rg, 'user', $uid, 'R', '') !== TRUE) {
759 rg_user_set_error('no rights');
716 760 break; break;
761 }
717 762
718 763 $now = time(); $now = time();
719 764 $params = array( $params = array(
 
... ... function rg_user_remove($db, $rg, $uid)
734 779 . '::' . 'deleted', $now, RG_SOCKET_NO_WAIT); . '::' . 'deleted', $now, RG_SOCKET_NO_WAIT);
735 780
736 781 // invalidate session // invalidate session
737 rg_sess_destroy($db, $rg['sid'], $rg['login_ui']);
782 rg_sess_destroy($db, $rg['sid']);
738 783
739 784 $ret = TRUE; $ret = TRUE;
740 785 break; break;
 
... ... function rg_user_set_last_seen($db, $uid, $ts, $ip)
872 917 /* /*
873 918 * Loads ui based on sid, if possible * Loads ui based on sid, if possible
874 919 */ */
875 function rg_user_login_by_sid($db, &$rg)
920 function rg_user_login_by_sid($db, $rg)
876 921 { {
877 922 rg_prof_start("user_login_by_sid"); rg_prof_start("user_login_by_sid");
878 923 rg_log_enter("user_login_by_sid: sid=" . $rg['sid']); rg_log_enter("user_login_by_sid: sid=" . $rg['sid']);
879 924
880 // Make sure it is not passed by client
881 $rg['login_ui'] = rg_user_empty();
882
883 925 $ret = FALSE; $ret = FALSE;
884 926 while (1) { while (1) {
885 927 if (empty($rg['sid'])) if (empty($rg['sid']))
 
... ... function rg_user_login_by_sid($db, &$rg)
894 936 break; break;
895 937
896 938 $uid = $sess['uid']; $uid = $sess['uid'];
897 $rg['login_ui'] = rg_user_info($db, $uid, "", "");
898 if ($rg['login_ui']['exists'] != 1) {
939 $ui_login = rg_user_info($db, $uid, "", "");
940 if ($ui_login['exists'] != 1) {
899 941 rg_log("Uid $uid does not exists (" . rg_user_error() . ")!"); rg_log("Uid $uid does not exists (" . rg_user_error() . ")!");
900 942 rg_user_set_error("invalid uid"); rg_user_set_error("invalid uid");
901 943 break; break;
902 944 } }
945 rg_ui_login_set($ui_login);
903 946
904 947 rg_sess_update($db, $sess); rg_sess_update($db, $sess);
905 948
 
... ... function rg_user_pass_valid($db, $uid, $pass)
928 971
929 972 $ui = rg_user_info($db, $uid, "", ""); $ui = rg_user_info($db, $uid, "", "");
930 973 if ($ui['exists'] != 1) { if ($ui['exists'] != 1) {
974 rg_log_debug('ui: ' . print_r($ui, TRUE));
931 975 rg_user_set_error("user does not exists"); rg_user_set_error("user does not exists");
932 976 break; break;
933 977 } }
 
... ... function rg_user_pass_valid($db, $uid, $pass)
938 982 break; break;
939 983 } }
940 984
941 rg_log("Pass is valid.");
942 985 $ret = TRUE; $ret = TRUE;
943 986 break; break;
944 987 } }
 
... ... function rg_user_set_session_cookie($db, $uid, $sess_time, $lock_ip, $https,
969 1012 else else
970 1013 $sid = "X" . $sid; $sid = "X" . $sid;
971 1014
972 rg_log('DEBUG: setting cookie \'' . $cookie_name . '\' to ' . $sid);
1015 rg_log_debug('setting cookie [' . $cookie_name . '] to [' . $sid . ']');
973 1016 setcookie($cookie_name, $sid, 0, '/', $domain, $secure, setcookie($cookie_name, $sid, 0, '/', $domain, $secure,
974 1017 TRUE /*httponly*/); TRUE /*httponly*/);
975 1018
 
... ... function rg_user_set_session_cookie($db, $uid, $sess_time, $lock_ip, $https,
980 1023 /* /*
981 1024 * Auto login the user * Auto login the user
982 1025 */ */
983 function rg_user_auto_login($db, $uid, $lock_ip, $https, $domain, &$ui)
1026 function rg_user_auto_login($db, $uid, $lock_ip, $https, $domain)
984 1027 { {
985 1028 rg_prof_start("user_auto_login"); rg_prof_start("user_auto_login");
986 1029 rg_log_enter("user_auto_login: uid=$uid lock_ip=$lock_ip"); rg_log_enter("user_auto_login: uid=$uid lock_ip=$lock_ip");
 
... ... function rg_user_auto_login($db, $uid, $lock_ip, $https, $domain, &$ui)
992 1035 break; break;
993 1036
994 1037 if ($ui['exists'] != 1) { if ($ui['exists'] != 1) {
1038 rg_log_debug('ui: ' . print_r($ui, TRUE));
995 1039 rg_log("user does not exists"); rg_log("user does not exists");
996 1040 break; break;
997 1041 } }
1042 rg_ui_login_set($ui);
998 1043
999 1044 rg_user_set_session_cookie($db, $uid, $ui['session_time'], rg_user_set_session_cookie($db, $uid, $ui['session_time'],
1000 1045 $lock_ip, $https, $domain); $lock_ip, $https, $domain);
 
... ... function rg_user_auto_login($db, $uid, $lock_ip, $https, $domain, &$ui)
1011 1056 /* /*
1012 1057 * Helper for rg_user_login_by_user_pass for db * Helper for rg_user_login_by_user_pass for db
1013 1058 */ */
1014 function rg_user_login_by_user_pass_db($db, $user, $pass, $ip, $lock_ip, $https,
1015 $domain, &$ui)
1059 function rg_user_login_by_user_pass_db($db, $user, $pass, $lock_ip, $https,
1060 $domain)
1016 1061 { {
1017 1062 global $rg_account_email_confirm; global $rg_account_email_confirm;
1018 1063
 
... ... function rg_user_login_by_user_pass_db($db, $user, $pass, $ip, $lock_ip, $https,
1021 1066 . ' lock_ip=' . $lock_ip . ' https=' . $https . ' lock_ip=' . $lock_ip . ' https=' . $https
1022 1067 . ' domain=' . $domain); . ' domain=' . $domain);
1023 1068
1024 $ui = rg_user_empty();
1025
1026 1069 $ret = FALSE; $ret = FALSE;
1027 1070 while (1) { while (1) {
1028 1071 $ui0 = rg_user_info($db, 0, $user, ""); $ui0 = rg_user_info($db, 0, $user, "");
1029 1072 if ($ui0['ok'] != 1) if ($ui0['ok'] != 1)
1030 1073 break; break;
1031 1074 if ($ui0['exists'] != 1) { if ($ui0['exists'] != 1) {
1075 rg_log_debug('ui0: ' . print_r($ui0, TRUE));
1032 1076 rg_user_set_error('invalid user, pass or login token'); rg_user_set_error('invalid user, pass or login token');
1033 rg_log('user doesn\'t exists');
1077 rg_log('user does not exists');
1034 1078 break; break;
1035 1079 } }
1036 1080
 
... ... function rg_user_login_by_user_pass_db($db, $user, $pass, $ip, $lock_ip, $https,
1047 1091 break; break;
1048 1092 } }
1049 1093
1050 $ui = $ui0;
1094 rg_ui_login_set($ui0);
1051 1095 $ret = TRUE; $ret = TRUE;
1052 1096 break; break;
1053 1097 } }
 
... ... function rg_user_login_by_user_pass_db($db, $user, $pass, $ip, $lock_ip, $https,
1061 1105 * Authorize a user * Authorize a user
1062 1106 */ */
1063 1107 function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token, function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1064 $ip, $lock_ip, $https, $domain, &$ui)
1108 $lock_ip, $https, $domain)
1065 1109 { {
1066 1110 global $rg_login_functions; global $rg_login_functions;
1067 1111
1068 // TODO: what about $ui - for ldap will not have some elements.
1069 // Should we fake them?
1070
1071 1112 rg_prof_start('user_login_by_user_pass_helper'); rg_prof_start('user_login_by_user_pass_helper');
1072 1113 rg_log_enter('user_login_by_user_pass_helper: user=' . $user rg_log_enter('user_login_by_user_pass_helper: user=' . $user
1073 1114 . ' login_token=' . $login_token . ' lock_ip=' . $lock_ip . ' login_token=' . $login_token . ' lock_ip=' . $lock_ip
1074 1115 . ' https=' . $https . ' domain=' . $domain); . ' https=' . $https . ' domain=' . $domain);
1075 1116
1076 $ui = rg_user_empty();
1077
1078 1117 $ret = array(); $ret = array();
1079 1118 $ret['ok'] = 0; $ret['ok'] = 0;
1080 1119 while (1) { while (1) {
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1084 1123 break; break;
1085 1124 } }
1086 1125
1126 $ui = rg_user_empty();
1087 1127 while (1) { while (1) {
1088 1128 $r = rg_user_login_by_user_pass_db($db, $user, $pass, $r = rg_user_login_by_user_pass_db($db, $user, $pass,
1089 $ip, $lock_ip, $https, $domain, $ui);
1090 if ($r === TRUE)
1129 $lock_ip, $https, $domain);
1130 if ($r === TRUE) {
1131 $ui = rg_ui_login();
1091 1132 break; break;
1133 }
1092 1134
1093 1135 $ret['errmsg'] = rg_user_error(); $ret['errmsg'] = rg_user_error();
1094 1136
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1105 1147 break; break;
1106 1148
1107 1149 // We found a good user/pass combination // We found a good user/pass combination
1108 rg_log_ml('DEBUG: post: ' . print_r($post, TRUE));
1109 rg_log_ml('DEBUG: ui returned by login callback: ' . print_r($ui, TRUE));
1150 rg_log_debug('post: ' . print_r($post, TRUE));
1151 rg_log_debug('ui returned by login callback: '
1152 . print_r($ui, TRUE));
1110 1153
1111 1154 $check_for_changes = TRUE; $check_for_changes = TRUE;
1112 1155 if ($ui['uid'] == 0) { if ($ui['uid'] == 0) {
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1114 1157 // We update the table and call the callback // We update the table and call the callback
1115 1158 // to set uid into external auth table. // to set uid into external auth table.
1116 1159
1117 rg_log('DEBUG: user not in \'users\' table (ui[uid] 0), add it');
1118 $ui['last_ip'] = $ip;
1160 rg_log_debug('user not in \'users\' table (ui[uid] 0), add it');
1161 $ui['last_ip'] = rg_ip();
1119 1162 $r = rg_user_edit_no_check($db, $ui); $r = rg_user_edit_no_check($db, $ui);
1120 1163 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
1121 1164 if ($r['already_exists'] == 0) { if ($r['already_exists'] == 0) {
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1123 1166 break; break;
1124 1167 } }
1125 1168
1126 rg_log('DEBUG: user is already present'
1169 rg_log_debug('user is already present'
1127 1170 . '; lookup by username'); . '; lookup by username');
1128 1171 $ui = rg_user_info($db, 0, $ui['username'], ''); $ui = rg_user_info($db, 0, $ui['username'], '');
1129 1172 if ($ui['ok'] !== 1) { if ($ui['ok'] !== 1) {
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1131 1174 break; break;
1132 1175 } }
1133 1176 } else { } else {
1134 $ui['uid'] = $r['ui']['uid'];
1177 $ui['uid'] = $r['ui_login']['uid'];
1135 1178 $check_for_changes = FALSE; $check_for_changes = FALSE;
1136 1179 } }
1137 1180
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1149 1192 // User found, but some fields may have old // User found, but some fields may have old
1150 1193 // values and we may need to update 'users'. // values and we may need to update 'users'.
1151 1194
1152 rg_log('DEBUG: user exists in db (ui[uid]!=0), load info');
1195 rg_log_debug('user exists in db (ui[uid]!=0), load info');
1153 1196 $ui = rg_user_info($db, $ui['uid'], '', ''); $ui = rg_user_info($db, $ui['uid'], '', '');
1154 1197 if ($ui['ok'] !== 1) { if ($ui['ok'] !== 1) {
1155 1198 $ret['errmsg'] = rg_user_error(); $ret['errmsg'] = rg_user_error();
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1164 1207 break; break;
1165 1208
1166 1209 if (strcmp($ui['username'], $post['username']) != 0) { if (strcmp($ui['username'], $post['username']) != 0) {
1167 rg_log('DEBUG: different username: ' . $ui['username'] . ' != ' . $post['username']);
1210 rg_log_debug('different username: ' . $ui['username'] . ' != ' . $post['username']);
1168 1211 $ui['username'] = $post['username']; $ui['username'] = $post['username'];
1169 1212 $do_update = TRUE; $do_update = TRUE;
1170 1213 break; break;
1171 1214 } }
1172 1215
1173 1216 if (strcmp($ui['email'], $post['mail']) != 0) { if (strcmp($ui['email'], $post['mail']) != 0) {
1174 rg_log('DEBUG: different mail');
1217 rg_log_debug('different mail');
1175 1218 $ui['email'] = $post['mail']; $ui['email'] = $post['mail'];
1176 1219 $do_update = TRUE; $do_update = TRUE;
1177 1220 break; break;
1178 1221 } }
1179 1222
1180 1223 if (strcmp($ui['realname'], $post['realname']) != 0) { if (strcmp($ui['realname'], $post['realname']) != 0) {
1181 rg_log('DEBUG: different realname');
1224 rg_log_debug('different realname');
1182 1225 $ui['realname'] = $post['realname']; $ui['realname'] = $post['realname'];
1183 1226 $do_update = TRUE; $do_update = TRUE;
1184 1227 break; break;
1185 1228 } }
1186 1229
1187 1230 if (strcmp($ui['pass'], $post['password']) != 0) { if (strcmp($ui['pass'], $post['password']) != 0) {
1188 rg_log('DEBUG: different passwords');
1231 rg_log_debug('different passwords');
1189 1232 $ui['pass'] = $post['password']; $ui['pass'] = $post['password'];
1190 1233 $ui['pass2'] = $post['password']; $ui['pass2'] = $post['password'];
1191 1234 $do_update = TRUE; $do_update = TRUE;
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1200 1243 break; break;
1201 1244 } }
1202 1245 if ($do_update) { if ($do_update) {
1203 rg_log('DEBUG: desync between sql and ldap');
1246 rg_log_debug('desync between sql and ldap');
1204 1247
1205 1248 // If we do not have pass2, we do not want // If we do not have pass2, we do not want
1206 1249 // to change the password. // to change the password.
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1219 1262 if (isset($ret['errmsg'])) if (isset($ret['errmsg']))
1220 1263 break; break;
1221 1264
1265 rg_log_debug('ui: ' . print_r($ui, TRUE));
1266 if ($ui['exists'] != 1) {
1267 $ret['errmsg'] = 'invalid user, pass or login token';
1268 rg_log('user does not exists');
1269 break;
1270 }
1271
1222 1272 if ($ui['deleted'] > 0) { if ($ui['deleted'] > 0) {
1223 1273 $ret['errmsg'] = 'invalid user, pass or login token'; $ret['errmsg'] = 'invalid user, pass or login token';
1224 1274 rg_log('account is deleted'); rg_log('account is deleted');
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1236 1286 $ret['errmsg'] = 'login token error: ' . rg_totp_error(); $ret['errmsg'] = 'login token error: ' . rg_totp_error();
1237 1287 break; break;
1238 1288 } }
1239 //rg_log_ml('DEBUG: vi: ' . print_r($vi, TRUE));
1289 rg_log_debug('vi: ' . print_r($vi, TRUE));
1240 1290 if (($vi['enrolled'] == 1) && ($vi['token_valid'] != 1)) { if (($vi['enrolled'] == 1) && ($vi['token_valid'] != 1)) {
1241 1291 // It may be possible that the login_token to be appended // It may be possible that the login_token to be appended
1242 1292 // to the pass. // to the pass.
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1256 1306 } }
1257 1307 } }
1258 1308
1309 rg_user_auto_login($db, $ui['uid'], $lock_ip, $https,
1310 $domain, $ui);
1311
1259 1312 $event = array( $event = array(
1260 1313 'category' => 'user_event_login', 'category' => 'user_event_login',
1261 1314 'prio' => 100, 'prio' => 100,
1262 'ui' => $ui,
1263 1315 'itime' => time()); 'itime' => time());
1264 1316 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
1265 1317 if ($r !== TRUE) { if ($r !== TRUE) {
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1268 1320 } }
1269 1321 rg_event_signal_daemon('', 0); rg_event_signal_daemon('', 0);
1270 1322
1271 rg_user_auto_login($db, $ui['uid'], $lock_ip, $https, $domain,
1272 $ui);
1273
1274 1323 $ret['ok'] = 1; $ret['ok'] = 1;
1275 1324 break; break;
1276 1325 } }
 
... ... function rg_user_login_by_user_pass_helper($db, $user, $pass, $login_token,
1281 1330 } }
1282 1331
1283 1332 function rg_user_login_by_user_pass($db, $user, $pass, $login_token, function rg_user_login_by_user_pass($db, $user, $pass, $login_token,
1284 $ip, $lock_ip, $https, $domain, &$ui)
1333 $lock_ip, $https, $domain)
1285 1334 { {
1286 1335 rg_prof_start('user_login_by_user_pass'); rg_prof_start('user_login_by_user_pass');
1287 1336 rg_log_enter('rg_user_login_by_user_pass'); rg_log_enter('rg_user_login_by_user_pass');
1288 1337
1289 while (1) {
1338 do {
1290 1339 $ret = rg_user_login_by_user_pass_helper($db, $user, $pass, $ret = rg_user_login_by_user_pass_helper($db, $user, $pass,
1291 $login_token, $ip, $lock_ip, $https, $domain, $ui);
1340 $login_token, $lock_ip, $https, $domain);
1292 1341 if ($ret['ok'] == 1) if ($ret['ok'] == 1)
1293 1342 break; break;
1294 1343
 
... ... function rg_user_login_by_user_pass($db, $user, $pass, $login_token,
1299 1348 $lt = substr($pass, -6); $lt = substr($pass, -6);
1300 1349 $pass2 = substr($pass, 0, -6); $pass2 = substr($pass, 0, -6);
1301 1350 $ret = rg_user_login_by_user_pass_helper($db, $user, $pass2, $ret = rg_user_login_by_user_pass_helper($db, $user, $pass2,
1302 $lt, $ip, $lock_ip, $https, $domain, $ui);
1351 $lt, $lock_ip, $https, $domain);
1303 1352 if ($ret['ok'] == 1) if ($ret['ok'] == 1)
1304 1353 break; break;
1305 1354
 
... ... function rg_user_login_by_user_pass($db, $user, $pass, $login_token,
1307 1356 $lt = substr($pass, -8); $lt = substr($pass, -8);
1308 1357 $pass2 = substr($pass, 0, -8); $pass2 = substr($pass, 0, -8);
1309 1358 $ret = rg_user_login_by_user_pass_helper($db, $user, $pass2, $ret = rg_user_login_by_user_pass_helper($db, $user, $pass2,
1310 $lt, $ip, $lock_ip, $https, $domain, $ui);
1311 break;
1312 }
1359 $lt, $lock_ip, $https, $domain);
1360 if ($ret['ok'] == 1)
1361 break;
1362
1363 rg_log_debug('invalid login: ' . $pass);
1364 } while (0);
1313 1365
1314 1366 rg_log_exit(); rg_log_exit();
1315 1367 rg_prof_end('user_login_by_user_pass'); rg_prof_end('user_login_by_user_pass');
 
... ... function rg_user_login_by_user_pass($db, $user, $pass, $login_token,
1320 1372 * Suspend an account * Suspend an account
1321 1373 * 1=suspend, 0=unsuspend * 1=suspend, 0=unsuspend
1322 1374 */ */
1323 function rg_user_suspend($db, $rg, $uid, $op)
1375 function rg_user_suspend($db, $uid, $op)
1324 1376 { {
1325 1377 rg_log_enter("user_suspend: uid=$uid, op=$op"); rg_log_enter("user_suspend: uid=$uid, op=$op");
1326 1378
1327 1379 $ret = FALSE; $ret = FALSE;
1328 1380 while (1) { while (1) {
1329 $x = array();
1330 $x['obj_id'] = $uid;
1331 $x['type'] = 'user';
1332 $x['owner'] = $uid;
1333 $x['uid'] = $rg['login_ui']['uid'];
1334 $x['username'] = $rg['login_ui']['username'];
1335 $x['needed_rights'] = 'S';
1336 $x['ip'] = $rg['ip'];
1337 $x['misc'] = "";
1338 if (rg_rights_allow($db, $x) !== TRUE)
1381 if (rg_rights_allow2($db, 'user', $uid, 'S', '') !== TRUE)
1339 1382 break; break;
1340 1383
1341 1384 $now = time(); $now = time();
 
... ... function rg_user_suspend($db, $rg, $uid, $op)
1372 1415 * Make/remove admin * Make/remove admin
1373 1416 * @op: 1=make, 0=remove * @op: 1=make, 0=remove
1374 1417 */ */
1375 function rg_user_make_admin($db, $rg, $uid, $op)
1418 function rg_user_make_admin($db, $uid, $op)
1376 1419 { {
1377 1420 rg_prof_start("user_make_admin"); rg_prof_start("user_make_admin");
1378 1421 rg_log_enter("user_make_admin: uid=$uid, op=$op"); rg_log_enter("user_make_admin: uid=$uid, op=$op");
1379 1422
1380 1423 $ret = FALSE; $ret = FALSE;
1381 1424 while (1) { while (1) {
1382 $x = array();
1383 $x['obj_id'] = $uid;
1384 $x['type'] = 'user';
1385 $x['owner'] = $uid;
1386 $x['uid'] = $rg['login_ui']['uid'];
1387 $x['username'] = $rg['login_ui']['username'];
1388 $x['needed_rights'] = 'M';
1389 $x['ip'] = $rg['ip'];
1390 $x['misc'] = "";
1391 if (rg_rights_allow($db, $x) !== TRUE)
1425 if (rg_rights_allow2($db, 'user', $uid, 'M', '') !== TRUE)
1392 1426 break; break;
1393 1427
1394 1428 $params = array("op" => $op, "uid" => $uid); $params = array("op" => $op, "uid" => $uid);
 
... ... function rg_user_forgot_pass_mail_prepare($db, $email)
1587 1621 rg_log("Internal error."); rg_log("Internal error.");
1588 1622 break; break;
1589 1623 } }
1590 if ($r['exists'] == 0) {
1591 rg_log("User does not exists.");
1624 if ($r['exists'] != 1) {
1625 rg_log('User does not exists');
1592 1626 $ret['ok'] = 1; $ret['ok'] = 1;
1593 1627 break; break;
1594 1628 } }
 
... ... function rg_user_forgot_pass_mail_prepare($db, $email)
1613 1647 break; break;
1614 1648 } }
1615 1649
1616 rg_log("DEBUG: user_forgot_pass_mail_prepare: ret=" . rg_array2string($ret));
1650 rg_log_debug('user_forgot_pass_mail_prepare: ret='
1651 . rg_array2string($ret));
1617 1652
1618 1653 rg_log_exit(); rg_log_exit();
1619 1654 rg_prof_end('user_forgot_pass_mail_prepare'); rg_prof_end('user_forgot_pass_mail_prepare');
 
... ... function rg_user_forgot_pass_mail($db, $rg, $email)
1644 1679
1645 1680 $ret['exists'] = 1; $ret['exists'] = 1;
1646 1681
1647 $rg['ui'] = $rg['login_ui'];
1648 $rg['ui']['email'] = $email;
1649 $rg['ui']['ignore_confirmed'] = 1;
1682 $rg['ui_login'] = rg_ui_login();
1683 $rg['ui_login']['email'] = $email; // TODO: why do I overwrite the e-mail?!
1684 $rg['ui_login']['ignore_confirmed'] = 1;
1650 1685 $rg['forgot_token'] = $r['token']; $rg['forgot_token'] = $r['token'];
1651 1686
1652 1687 $r = rg_mail_template('mail/user/forgot/recover', $rg); $r = rg_mail_template('mail/user/forgot/recover', $rg);
 
... ... function rg_user_forgot_pass_mail($db, $rg, $email)
1659 1694 break; break;
1660 1695 } }
1661 1696
1662 //rg_log("DEBUG: user_forgot_pass_mail: ret=" . rg_array2string($ret) . ".");
1697 rg_log_debug('user_forgot_pass_mail: ret='
1698 . rg_array2string($ret));
1699
1663 1700 rg_log_exit(); rg_log_exit();
1664 1701 rg_prof_end('user_forgot_pass_mail'); rg_prof_end('user_forgot_pass_mail');
1665 1702 return $ret; return $ret;
 
... ... function rg_user_data($db, $type, $start, $end, $unit, $mode)
1873 1910 $params = array('start' => $start, 'end' => $end); $params = array('start' => $start, 'end' => $end);
1874 1911 switch ($type) { switch ($type) {
1875 1912 case 'create_account': case 'create_account':
1876 $q = 'SELECT 1 AS value, itime FROM users'
1913 $q = 'SELECT itime FROM users'
1877 1914 . ' WHERE itime >= @@start@@ AND itime <= @@end@@' . ' WHERE itime >= @@start@@ AND itime <= @@end@@'
1878 1915 . ' AND is_admin = 0'; . ' AND is_admin = 0';
1879 1916 break; break;
 
... ... function rg_user_data($db, $type, $start, $end, $unit, $mode)
1894 1931 return $ret; return $ret;
1895 1932 } }
1896 1933
1934 $__ui_page = rg_user_empty();
1935 function rg_ui_page()
1936 {
1937 global $__ui_page;
1938
1939 return $__ui_page;
1940 }
1941
1942 function rg_ui_page_reset()
1943 {
1944 global $__ui_page;
1945
1946 rg_log_debug('ui_page_reset');
1947 $__ui_page = rg_user_empty();
1948 }
1949
1950 function rg_ui_page_set($a)
1951 {
1952 global $__ui_page;
1953
1954 rg_log_debug('ui_page_set');
1955 $__ui_page = $a;
1956 }
1957
1958 $__ui_login = rg_user_empty();
1959 function rg_ui_login()
1960 {
1961 global $__ui_login;
1962
1963 return $__ui_login;
1964 }
1965
1966 function rg_ui_login_reset()
1967 {
1968 global $__ui_login;
1969
1970 rg_log_debug('ui_login_reset');
1971 $__ui_login = rg_user_empty();
1972 }
1973
1974 function rg_ui_login_set($a)
1975 {
1976 global $__ui_login;
1977
1978 rg_log_debug('ui_login_set');
1979 $__ui_login = $a;
1980 }
1981
1982
1897 1983 /* /*
1898 1984 * High level functions * High level functions
1899 1985 */ */
 
... ... function rg_user_data($db, $type, $start, $end, $unit, $mode)
1901 1987 /* /*
1902 1988 * High-level function for editing a user * High-level function for editing a user
1903 1989 */ */
1904 function rg_user_edit_high_level($db, &$rg)
1990 function rg_user_edit_high_level($db, $rg)
1905 1991 { {
1906 1992 global $rg_session_time; global $rg_session_time;
1907 1993
 
... ... function rg_user_edit_high_level($db, &$rg)
1918 2004
1919 2005 $owner = $rg['target_ui']['uid']; $owner = $rg['target_ui']['uid'];
1920 2006 if ($owner > 0) { if ($owner > 0) {
1921 $x = array();
1922 $x['obj_id'] = $rg['target_ui']['uid'];
1923 $x['type'] = 'user';
1924 $x['owner'] = $owner;
1925 $x['uid'] = $rg['login_ui']['uid'];
1926 $x['username'] = $rg['login_ui']['username'];
1927 $x['needed_rights'] = 'E';
1928 $x['ip'] = $rg['ip'];
1929 $x['misc'] = "";
1930 if (rg_rights_allow($db, $x) !== TRUE) {
1931 $ret .= rg_template("access_denied.html", $rg, TRUE /* xss */);
2007 $obj_id = $rg['target_ui']['uid'];
2008 if (rg_rights_allow2($db, 'user', $obj_id, 'E', '') !== TRUE) {
2009 $ret .= rg_template("access_denied.html", $rg, TRUE /*xss*/);
1932 2010 return $ret; return $ret;
1933 2011 } }
1934 2012 } }
 
... ... function rg_user_edit_high_level($db, &$rg)
1985 2063 $ui['tos'] = 1; $ui['tos'] = 1;
1986 2064 else else
1987 2065 $ui['tos'] = rg_var_uint('tos'); $ui['tos'] = rg_var_uint('tos');
1988 $ui['last_ip'] = $rg['ip'];
2066 $ui['last_ip'] = rg_ip();
1989 2067
1990 2068 $ui['confirm_token'] = rg_id(20); $ui['confirm_token'] = rg_id(20);
1991 2069 if ($rg['target_ui']['uid'] > 0) { if ($rg['target_ui']['uid'] > 0) {
 
... ... function rg_user_edit_high_level($db, &$rg)
2015 2093 } }
2016 2094
2017 2095 if ($ui['tos'] != 1) { if ($ui['tos'] != 1) {
2018 $errmsg[] = rg_template('user/tos_deny.html', $rg, TRUE /*xss*/);
2096 $errmsg[] = rg_template_blind('user/tos_deny.html');
2019 2097 break; break;
2020 2098 } }
2021 2099
 
... ... function rg_user_edit_high_level($db, &$rg)
2029 2107 break; break;
2030 2108 } }
2031 2109
2032 if (($rg['login_ui']['is_admin'] != 1) && ($ui['is_admin'] != 0)) {
2110 $ui_login = rg_ui_login();
2111 if (($ui_login['is_admin'] != 1) && ($ui['is_admin'] != 0)) {
2033 2112 $errmsg[] = "you are not admin, you cannot give admin rights"; $errmsg[] = "you are not admin, you cannot give admin rights";
2034 2113 break; break;
2035 2114 } }
 
... ... function rg_user_api($db, $a, $json)
2103 2182 break; break;
2104 2183 } }
2105 2184
2185 $ui_login = rg_ui_login();
2186
2106 2187 // TODO: allow also a master user to access user info // TODO: allow also a master user to access user info
2107 if (($a['login_ui']['is_admin'] != 1)
2108 && ($a['target_ui']['uid'] != $a['login_ui']['uid'])) {
2188 if (($ui_login['is_admin'] != 1)
2189 && ($a['target_ui']['uid'] != $ui_login['uid'])) {
2109 2190 $ret['error'] = 'invalid user or no rights'; $ret['error'] = 'invalid user or no rights';
2110 2191 rg_log('user has no rights'); rg_log('user has no rights');
2111 2192 break; break;
 
... ... function rg_user_api($db, $a, $json)
2168 2249 /* /*
2169 2250 * Add an ask-for-email-confirmation event to queue * Add an ask-for-email-confirmation event to queue
2170 2251 */ */
2171 function rg_user_ask_for_email_confirmation($db, $uid)
2252 function rg_user_ask_for_email_confirmation($db, $ui_login)
2172 2253 { {
2173 $ui = rg_user_info($db, $uid, '', '');
2174 if ($ui['exists'] != 1)
2175 return FALSE;
2176
2177 2254 $ev = array( $ev = array(
2178 2255 'category' => 'ask-email-confirmation', 'category' => 'ask-email-confirmation',
2179 2256 'prio' => 200, 'prio' => 200,
2180 'ui' => $ui,
2181 'base_url' => rg_base_url()
2257 'ui_login' => $ui_login,
2258 'base_url' => rg_base_url($db, '', '')
2182 2259 ); );
2183 2260 $r = rg_event_add($db, $ev); $r = rg_event_add($db, $ev);
2184 2261 if ($r !== TRUE) if ($r !== TRUE)
 
... ... function rg_user_list_to_full_info($db, $list)
2195 2272 { {
2196 2273 $ret = array(); $ret = array();
2197 2274 foreach ($list as $index => $uid) { foreach ($list as $index => $uid) {
2198 $ret['ui'] = rg_user_info($db, $uid, '', '');
2199 if ($ret['ui']['ok'] != 1)
2275 $ui = rg_user_info($db, $uid, '', '');
2276 if ($ui['ok'] != 1)
2200 2277 return FALSE; return FALSE;
2201 2278
2202 if ($ret['ui']['exists'] != 1)
2279 if ($ui['exists'] != 1)
2203 2280 continue; continue;
2281
2282 $ret[$uid] = $ui;
2204 2283 } }
2205 2284
2206 2285 return $ret; return $ret;
 
... ... function rg_process_input($content_length, $content_encoding, &$err)
2220 2299 $te = isset($_SERVER['HTTP_TRANSFER_ENCODING']) ? $te = isset($_SERVER['HTTP_TRANSFER_ENCODING']) ?
2221 2300 $_SERVER['HTTP_TRANSFER_ENCODING'] : ''; $_SERVER['HTTP_TRANSFER_ENCODING'] : '';
2222 2301
2223 rg_log_enter('DEBUG: process_input: content_length=' . $content_length
2302 rg_log_enter('process_input: content_length=' . $content_length
2224 2303 . ' content_encoding=' . $content_encoding . ' content_encoding=' . $content_encoding
2225 2304 . ' te=' . $te); . ' te=' . $te);
2226 2305
 
... ... function rg_user_http_git($db, $rg, $paras)
2326 2405 $service = 'git-receive-pack'; $service = 'git-receive-pack';
2327 2406 else else
2328 2407 $service = isset($_REQUEST['service']) ? $_REQUEST['service'] : ''; $service = isset($_REQUEST['service']) ? $_REQUEST['service'] : '';
2329 rg_log('DEBUG: service=' . $service);
2408 if (!empty($service))
2409 rg_log_debug('service=' . $service);
2330 2410
2331 2411 $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
2332 2412
 
... ... function rg_user_http_git($db, $rg, $paras)
2355 2435 } }
2356 2436 $repo = array_shift($paras); $repo = array_shift($paras);
2357 2437 $file = implode('/', $paras); $file = implode('/', $paras);
2358 rg_log('DEBUG: file=' . $file);
2438 rg_log_debug('file=' . $file);
2359 2439
2360 2440 header('Expires: Fri, 01 Jan 1980 00:00:00 GMT'); header('Expires: Fri, 01 Jan 1980 00:00:00 GMT');
2361 2441 header('Pragma: no-cache'); header('Pragma: no-cache');
 
... ... function rg_user_http_git($db, $rg, $paras)
2367 2447 $authd = array('ok' => 0); $authd = array('ok' => 0);
2368 2448 $u = ''; $u = '';
2369 2449 $no_user_provided = TRUE; $no_user_provided = TRUE;
2370 $auth_ui = rg_user_empty();
2371 2450 while (isset($_SERVER['PHP_AUTH_USER']) while (isset($_SERVER['PHP_AUTH_USER'])
2372 2451 && isset($_SERVER['PHP_AUTH_PW'])) { && isset($_SERVER['PHP_AUTH_PW'])) {
2373 2452 $u = $_SERVER['PHP_AUTH_USER']; $u = $_SERVER['PHP_AUTH_USER'];
2374 2453 $p = $_SERVER['PHP_AUTH_PW']; $p = $_SERVER['PHP_AUTH_PW'];
2375 rg_log('DEBUG: HTTP auth: u=' . $u);
2454 rg_log_debug('HTTP auth: u=' . $u);
2376 2455
2377 2456 $no_user_provided = FALSE; $no_user_provided = FALSE;
2378 2457
 
... ... function rg_user_http_git($db, $rg, $paras)
2381 2460 if (empty($u)) if (empty($u))
2382 2461 break; break;
2383 2462
2384 $auth_ui = rg_user_info($db, 0, $u, '');
2385 if ($auth_ui['ok'] !== 1) {
2386 rg_log('DEBUG: set errror (500): ' . rg_user_error());
2463 $r = rg_user_info($db, 0, $u, '');
2464 if ($r['ok'] !== 1) {
2465 rg_log_debug('set errror (500): ' . rg_user_error());
2387 2466 header('X-Rocketgit-Error: ' . rg_user_error()); header('X-Rocketgit-Error: ' . rg_user_error());
2388 2467 header($protocol . ' 500 Internal server error'); header($protocol . ' 500 Internal server error');
2389 2468 break; break;
2390 2469 } }
2391 2470 $authd = rg_user_login_by_user_pass($db, $u, $p, $authd = rg_user_login_by_user_pass($db, $u, $p,
2392 '' /*login_token*/, $rg['ip'], TRUE /*lock IP*/,
2393 $rg['https'], $rg['hostname'], $rg['login_ui']);
2471 '' /*login_token*/, TRUE /*lock IP*/,
2472 $rg['https'], $rg['hostname']);
2394 2473 break; break;
2395 2474 } }
2396 2475
2397 2476 $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
2398 // TODO: not clear if passing here login_ui is correct I think it is.
2399 2477 $helper_flags = ''; $helper_flags = '';
2400 $r = rg_repo_fetch_push_helper($db, $host, $rg['ip'],
2401 $rg['login_ui'], $prefix, $user, $repo, $service,
2402 $helper_flags);
2403 rg_log_ml('DEBUG: repo_fetch_push_helper returns: ' . print_r($r, TRUE));
2478 $r = rg_repo_fetch_push_helper($db, $host, $prefix, $user,
2479 $repo, $service, $helper_flags);
2480 rg_log_debug('repo_fetch_push_helper returns: ' . print_r($r, TRUE));
2404 2481 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
2405 rg_log('DEBUG: set errror: ' . $r['errmsg']);
2482 rg_log_debug('set errror: ' . $r['errmsg']);
2406 2483 header('X-Rocketgit-Error: ' . $r['errmsg']); header('X-Rocketgit-Error: ' . $r['errmsg']);
2407 2484
2408 if (isset($r['owner_ui'])) {
2409 if ($r['owner_ui']['ok'] != 1) {
2410 header($protocol . ' 500 Internal server error');
2411 break;
2412 }
2485 $ui_page = rg_ui_page();
2486 if ($ui_page['ok'] != 1) {
2487 header($protocol . ' 500 Internal server error');
2488 break;
2489 }
2413 2490
2414 if ($r['owner_ui']['exists'] != 1) {
2415 header($protocol . ' 404 Not found');
2416 break;
2417 }
2491 // TODO: what about 'deleted' etc.?
2492 if ($ui_page['exists'] != 1) {
2493 header($protocol . ' 404 Not found');
2494 break;
2418 2495 } }
2419 2496
2420 2497 if (isset($r['ri'])) { if (isset($r['ri'])) {
 
... ... function rg_user_http_git($db, $rg, $paras)
2423 2500 break; break;
2424 2501 } }
2425 2502
2503 // TODO: what about locked?
2426 2504 if (($r['ri']['exists'] != 1) if (($r['ri']['exists'] != 1)
2427 2505 || ($r['ri']['deleted'] > 0)) { || ($r['ri']['deleted'] > 0)) {
2428 2506 header($protocol . ' 404 Not found'); header($protocol . ' 404 Not found');
 
... ... function rg_user_http_git($db, $rg, $paras)
2436 2514 $repo_path = $r['repo_path']; $repo_path = $r['repo_path'];
2437 2515
2438 2516 // for 'conns' stats // for 'conns' stats
2439 rg_stats_conns_set('uid', $r['owner_ui']['uid']);
2517 $ui_login = rg_ui_login();
2518 rg_stats_conns_set('login_uid', $ui_login['uid']);
2519 rg_stats_conns_set('uid', $r['ri']['uid']);
2440 2520 rg_stats_conns_set('repo_id', $r['ri']['repo_id']); rg_stats_conns_set('repo_id', $r['ri']['repo_id']);
2441 2521
2442 2522 // push_allowed is only about the rights, not about auth/login_tokens // push_allowed is only about the rights, not about auth/login_tokens
2443 rg_log('DEBUG: push=' . $r['push']
2523 rg_log_debug('push=' . $r['push']
2444 2524 . ' push_allowed=' . $r['push_allowed'] . ' push_allowed=' . $r['push_allowed']
2445 2525 . ' no_user_provided=' . ($no_user_provided ? 'yes' : 'no') . ' no_user_provided=' . ($no_user_provided ? 'yes' : 'no')
2446 . ' authd=' . ($authd['ok'] === 1 ? 'yes' : 'no')
2447 . ' exists=' . $auth_ui['exists']);
2526 . ' authd=' . ($authd['ok'] === 1 ? 'yes' : 'no'));
2448 2527 $send_401 = FALSE; $send_401 = FALSE;
2449 2528 while (1) { while (1) {
2450 2529 if ($r['allow'] !== 1) { if ($r['allow'] !== 1) {
2451 rg_log('DEBUG: allow != 1 => 401');
2530 rg_log_debug('allow != 1 => 401');
2452 2531 // Connecting user has no rights to push, not even anon. // Connecting user has no rights to push, not even anon.
2453 2532 // The user may be authed at this point, but may try another // The user may be authed at this point, but may try another
2454 2533 // user/pass combination. // user/pass combination.
 
... ... function rg_user_http_git($db, $rg, $paras)
2457 2536 } }
2458 2537
2459 2538 if ($r['push'] !== 1) { if ($r['push'] !== 1) {
2460 rg_log('DEBUG: it is a fetch');
2539 rg_log_debug('it is a fetch');
2461 2540 break; break;
2462 2541 } }
2463 2542
2464 2543 if ($no_user_provided) { if ($no_user_provided) {
2465 rg_log('DEBUG: no user provided');
2544 rg_log_debug('no user provided');
2466 2545 $send_401 = TRUE; $send_401 = TRUE;
2467 2546 break; break;
2468 2547 } }
2469 2548
2470 if (($authd['ok'] !== 1) && ($auth_ui['exists'] == 1)) {
2471 rg_log('DEBUG: user exists but not authenticated');
2549 $ui_login = rg_ui_login();
2550 if (($authd['ok'] !== 1) && ($ui_login['exists'] == 1)) {
2551 rg_log_debug('user exists but not authenticated');
2472 2552 $send_401 = TRUE; $send_401 = TRUE;
2473 2553 break; break;
2474 2554 } }
 
... ... function rg_user_http_git($db, $rg, $paras)
2476 2556 break; break;
2477 2557 } }
2478 2558 if ($send_401) { if ($send_401) {
2479 rg_log('DEBUG: sending 401');
2559 rg_log_debug('sending 401');
2480 2560 header($protocol . ' 401 Unauthorized status'); header($protocol . ' 401 Unauthorized status');
2481 2561 header('WWW-Authenticate: Basic' header('WWW-Authenticate: Basic'
2482 2562 . ' realm="Use user \'guest\' if you have no account"'); . ' realm="Use user \'guest\' if you have no account"');
2483 2563 echo 'RocketGit: Info: == Welcome to RocketGit! ==' . "\n"; echo 'RocketGit: Info: == Welcome to RocketGit! ==' . "\n";
2484 2564 echo 'RocketGit: Info: you are connecting from IP ' echo 'RocketGit: Info: you are connecting from IP '
2485 . $rg['ip'] . ' by http(s).' . "\n";
2565 . rg_ip() . ' by ' . $protocol . '.' . "\n";
2486 2566 echo 'RocketGit: Info: date/time: ' . gmdate('Y-m-d H:i:s') echo 'RocketGit: Info: date/time: ' . gmdate('Y-m-d H:i:s')
2487 2567 . ' (UTC), debug id ' . $rg_log_sid . '.' . "\n"; . ' (UTC), debug id ' . $rg_log_sid . '.' . "\n";
2488 2568 echo 'RocketGit: Info: Use user \'guest\' with any' echo 'RocketGit: Info: Use user \'guest\' with any'
 
... ... function rg_user_http_git($db, $rg, $paras)
2497 2577 intval($_SERVER['CONTENT_LENGTH']) : 0; intval($_SERVER['CONTENT_LENGTH']) : 0;
2498 2578 $content_encoding = isset($_SERVER['HTTP_CONTENT_ENCODING']) ? $content_encoding = isset($_SERVER['HTTP_CONTENT_ENCODING']) ?
2499 2579 $_SERVER['HTTP_CONTENT_ENCODING'] : ''; $_SERVER['HTTP_CONTENT_ENCODING'] : '';
2500 rg_log('DEBUG: cl=' . $content_length . ' ce=' . $content_encoding . '.');
2580 rg_log_debug('cl=' . $content_length . ' ce=' . $content_encoding . '.');
2501 2581
2502 2582 $input_fd = @fopen('php://input', 'r'); $input_fd = @fopen('php://input', 'r');
2503 2583 if ($input_fd === FALSE) { if ($input_fd === FALSE) {
 
... ... function rg_user_http_git($db, $rg, $paras)
2521 2601 $cmd['cmds']['cmd1']['out_buf_helper'] = 'rg_exec2_helper_gzip_in'; $cmd['cmds']['cmd1']['out_buf_helper'] = 'rg_exec2_helper_gzip_in';
2522 2602
2523 2603 if (strcmp($file, 'info/refs') == 0) { if (strcmp($file, 'info/refs') == 0) {
2524 rg_log('DEBUG: info/refs');
2604 rg_log_debug('info/refs');
2525 2605 // TODO: we should allow this only if the connecting // TODO: we should allow this only if the connecting
2526 2606 // user has fetch rights! // user has fetch rights!
2527 2607 header('Content-Type: application/x-' header('Content-Type: application/x-'
 
... ... function rg_user_http_git($db, $rg, $paras)
2548 2628 } }
2549 2629
2550 2630 if (strcasecmp($rg['ct'], 'application/x-git-upload-pack-request') == 0) { if (strcasecmp($rg['ct'], 'application/x-git-upload-pack-request') == 0) {
2551 rg_log('DEBUG: git-upload-pack...');
2631 rg_log_debug('git-upload-pack...');
2552 2632
2553 2633 header('Content-Type: application/x-git-upload-pack-result'); header('Content-Type: application/x-git-upload-pack-result');
2554 2634
 
... ... function rg_user_http_git($db, $rg, $paras)
2559 2639 /* /*
2560 2640 rg_git_info_pack("\x02", '== Welcome to RocketGit! =='); rg_git_info_pack("\x02", '== Welcome to RocketGit! ==');
2561 2641 rg_git_info_pack("\x02", 'you are connecting from IP ' rg_git_info_pack("\x02", 'you are connecting from IP '
2562 . $rg['ip'] . ' by http(s).');
2642 . rg_ip() . ' by ' . $protocol . '.');
2563 2643 rg_git_info_pack("\x02", 'date/time: ' . gmdate('Y-m-d H:i:s') rg_git_info_pack("\x02", 'date/time: ' . gmdate('Y-m-d H:i:s')
2564 2644 . ' (UTC), debug id ' . $rg_log_sid . '.'); . ' (UTC), debug id ' . $rg_log_sid . '.');
2565 2645 // If user does not connect to the correct URL, correct them // If user does not connect to the correct URL, correct them
 
... ... function rg_user_http_git($db, $rg, $paras)
2586 2666
2587 2667 rg_log('Done!'); rg_log('Done!');
2588 2668 } else if (strcasecmp($rg['ct'], 'application/x-git-receive-pack-request') == 0) { } else if (strcasecmp($rg['ct'], 'application/x-git-receive-pack-request') == 0) {
2589 rg_log('DEBUG: git-receive-pack...');
2669 rg_log_debug('git-receive-pack...');
2590 2670
2591 2671 header('Content-Type: application/x-git-receive-pack-result'); header('Content-Type: application/x-git-receive-pack-result');
2592 2672
2593 2673 rg_git_info_pack("\x02", '== Welcome to RocketGit! =='); rg_git_info_pack("\x02", '== Welcome to RocketGit! ==');
2594 2674 rg_git_info_pack("\x02", 'you are connecting from IP ' rg_git_info_pack("\x02", 'you are connecting from IP '
2595 . $rg['ip'] . ' by http(s).');
2675 . rg_ip() . ' by ' . $protocol . '.');
2596 2676 rg_git_info_pack("\x02", 'date/time: ' . gmdate('Y-m-d H:i:s') rg_git_info_pack("\x02", 'date/time: ' . gmdate('Y-m-d H:i:s')
2597 2677 . ' (UTC), debug id ' . $rg_log_sid . '.'); . ' (UTC), debug id ' . $rg_log_sid . '.');
2598 2678 // If user does not connect to the correct URL, correct them // If user does not connect to the correct URL, correct them
 
... ... function rg_user_delete_account_high_level($db, $rg, $paras)
2668 2748 break; break;
2669 2749 } }
2670 2750
2671 $r = rg_user_remove($db, $rg, $rg['login_ui']['uid']);
2751 $ui_login = rg_ui_login();
2752 $r = rg_user_remove($db, $rg, $ui_login['uid']);
2672 2753 if ($r !== TRUE) { if ($r !== TRUE) {
2673 2754 $errmsg[] = rg_user_error(); $errmsg[] = rg_user_error();
2674 2755 break; break;
File inc/user/confirm.php changed (mode: 100644) (index cd5aa05..4d83a04)
... ... if ($uid !== FALSE) {
9 9
10 10 // auto-login // auto-login
11 11 $lock_ip = 0; // TODO: What should we do here? Present a form? $lock_ip = 0; // TODO: What should we do here? Present a form?
12 rg_user_auto_login($db, $uid, $lock_ip, $rg['https'], $rg['hostname'],
13 $rg['login_ui']);
12 rg_user_auto_login($db, $uid, $lock_ip, $rg['https'], $rg['hostname']);
14 13 } else { } else {
15 14 // error // error
16 15 $_confirm = rg_template('user/bad_token.html', $rg, TRUE /*xss*/); $_confirm = rg_template('user/bad_token.html', $rg, TRUE /*xss*/);
17 16 } }
18 17
19 ?>
File inc/user/forgot.php changed (mode: 100644) (index c5d0b2e..53fa01d)
... ... if ($rg['doit'] == 1) {
37 37 rg_user_forgot_pass_destroy($db, $r['uid']); rg_user_forgot_pass_destroy($db, $r['uid']);
38 38 // auto-login // auto-login
39 39 if (!rg_user_auto_login($db, $r['uid'], $lock_ip, if (!rg_user_auto_login($db, $r['uid'], $lock_ip,
40 $rg['https'], $rg['hostname'], $rg['login_ui'])) {
41 $_forgot = rg_template("msg/internal_err.html", TRUE /* xss */);
40 $rg['https'], $rg['hostname'])) {
41 $_forgot = rg_template('msg/internal_err.html', $rg, TRUE /*xss*/);
42 42 return; return;
43 43 } }
44 44
45 45 // redirect to home // redirect to home
46 $url = rg_re_userpage($rg['login_ui']);
46 $url = rg_re_userpage(rg_ui_login());
47 47 rg_redirect($url); rg_redirect($url);
48 48 } }
49 49 } }
 
... ... $rg['forgot_token'] = $forgot_token;
52 52 $rg['pass1'] = $pass1; $rg['pass1'] = $pass1;
53 53 $rg['pass2'] = $pass2; $rg['pass2'] = $pass2;
54 54 $rg['HTML:errmsg'] = rg_template_errmsg($errmsg); $rg['HTML:errmsg'] = rg_template_errmsg($errmsg);
55 $_forgot .= rg_template("user/forgot.html", $rg, TRUE /* xss */);
56 ?>
55 $_forgot .= rg_template('user/forgot.html', $rg, TRUE /*xss*/);
File inc/user/home-page.php changed (mode: 100644) (index 81ae897..42c2743)
1 1 <?php <?php
2 2 $_home = ''; $_home = '';
3 3
4 $rg['page_ui'] = rg_user_info($db, 0, $user, "");
5 if (($rg['page_ui']['exists'] == 0)
6 || ($rg['page_ui']['suspended'] > 0)
7 || ($rg['page_ui']['deleted'] > 0)) {
4 $ui_page = rg_user_info($db, 0, $user, '');
5 if (($ui_page['exists'] == 0) || ($ui_page['suspended'] > 0)
6 || ($ui_page['deleted'] > 0)) {
8 7 $_home .= rg_template("user/invalid.html", $rg, TRUE /*xss*/); $_home .= rg_template("user/invalid.html", $rg, TRUE /*xss*/);
9 8 return; return;
10 9 } }
10 rg_ui_page_set($ui_page);
11 11
12 rg_watch_hl_process($db, $rg, 'user', $rg['page_ui']['uid'],
13 0, $rg['current_url']);
12 rg_watch_hl_process($db, $rg, 'user', $ui_page['uid'], 0, $rg['current_url']);
14 13
15 14 $_home .= rg_template('user/home.html', $rg, TRUE /*xss*/); $_home .= rg_template('user/home.html', $rg, TRUE /*xss*/);
16 15
17 16 // List of repositories // List of repositories
18 //$_home .= 'Repositories:';
19 $_home .= rg_repo_list($db, $rg, '', $rg['page_ui']['uid'], 0);
17 $_home .= rg_repo_list($db, $rg, '', $ui_page['uid'], 0);
20 18
21 19
22 20 // hints // hints
23 21 $hints = array(); $hints = array();
24 22
25 if ($rg['page_ui']['uid'] == $rg['login_ui']['uid']) {
26 if (empty($rg['login_ui']['email']))
23 $ui_login = rg_ui_login();
24 if ($ui_page['uid'] == $ui_login['uid']) {
25 if (empty($ui_login['email']))
27 26 $hints[]['HTML:hint'] = rg_template('user/hints/empty_email.html', $hints[]['HTML:hint'] = rg_template('user/hints/empty_email.html',
28 27 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
29 else if ($rg['login_ui']['confirmed'] == 0)
28 else if ($ui_login['confirmed'] == 0)
30 29 $hints[]['HTML:hint'] = rg_template('user/hints/econf.html', $hints[]['HTML:hint'] = rg_template('user/hints/econf.html',
31 30 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
32 31
33 $r = rg_totp_enrolled($db, $rg['login_ui']['uid']);
32 $r = rg_totp_enrolled($db, $ui_login['uid']);
34 33 if (($r['ok'] == 1) && ($r['enrolled'] == 0)) if (($r['ok'] == 1) && ($r['enrolled'] == 0))
35 34 $hints[]['HTML:hint'] = rg_template('user/hints/totp.html', $hints[]['HTML:hint'] = rg_template('user/hints/totp.html',
36 35 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
 
... ... if ($rg['page_ui']['uid'] == $rg['login_ui']['uid']) {
38 37
39 38 $_home .= rg_template_table('hints/list', $hints, $rg); $_home .= rg_template_table('hints/list', $hints, $rg);
40 39
40 rg_ui_page_reset();
File inc/user/keys/keys.php changed (mode: 100644) (index dd4e7f7..dbc6542)
1 1 <?php <?php
2 2 $_keys = ''; $_keys = '';
3 3
4 $ui_login = rg_ui_login();
5
4 6 $add_errmsg = array(); $add_errmsg = array();
5 7 $del_errmsg = array(); $del_errmsg = array();
6 8
 
... ... while (rg_var_uint('add') == 1) {
25 27 } }
26 28
27 29 $flags = ''; $flags = '';
28 $_r = rg_keys_add($db, $rg['login_ui'], $key, $flags);
30 $_r = rg_keys_add($db, $ui_login, $key, $flags);
29 31 if ($_r === FALSE) { if ($_r === FALSE) {
30 32 $add_errmsg[] = rg_keys_error(); $add_errmsg[] = rg_keys_error();
31 33 break; break;
32 34 } }
33 35
34 $rg['HTML:add_status'] = rg_template('user/keys/add_ok.html', $rg, TRUE /* xss */);
36 $rg['HTML:add_status'] = rg_template('user/keys/add_ok.html', $rg, TRUE /*xss*/);
35 37 $key = ''; $key = '';
36 38 break; break;
37 39 } }
 
... ... while (rg_var_uint('delete') == 1) {
52 54 break; break;
53 55 } }
54 56
55 if (rg_keys_remove($db, $rg['login_ui'], $key_delete_ids) !== TRUE) {
57 if (rg_keys_remove($db, $ui_login, $key_delete_ids) !== TRUE) {
56 58 $del_errmsg[] = rg_keys_error(); $del_errmsg[] = rg_keys_error();
57 59 break; break;
58 60 } }
 
... ... $rg['key'] = $key;
68 70 $rg['rg_form_token'] = rg_token_get($db, $rg, 'keys'); $rg['rg_form_token'] = rg_token_get($db, $rg, 'keys');
69 71 $rg['HTML:add_form'] = rg_template('user/keys/add.html', $rg, TRUE /*xss*/); $rg['HTML:add_form'] = rg_template('user/keys/add.html', $rg, TRUE /*xss*/);
70 72
71 $keys_list = rg_keys_list($db, $rg['login_ui']);
73 $keys_list = rg_keys_list($db, $ui_login);
72 74 if ($keys_list === FALSE) if ($keys_list === FALSE)
73 75 $rg['HTML:keys'] = rg_warning('Could not load keys. Try later.'); // TODO $rg['HTML:keys'] = rg_warning('Could not load keys. Try later.'); // TODO
74 76 else else
File inc/user/pass/pass.php changed (mode: 100644) (index 75ced4b..5eb1944)
... ... while (1) {
27 27 break; break;
28 28 } }
29 29
30 if (!rg_user_pass_valid($db, $rg['login_ui']['uid'], $old_pass)) {
30 $ui_login = rg_ui_login();
31 if (!rg_user_pass_valid($db, $ui_login['uid'], $old_pass)) {
31 32 $errmsg[] = "old password is invalid"; $errmsg[] = "old password is invalid";
32 33 break; break;
33 34 } }
34 35
35 if (!rg_user_set_pass($db, $rg['login_ui']['uid'], $pass1)) {
36 if (!rg_user_set_pass($db, $ui_login['uid'], $pass1)) {
36 37 $errmsg[] = rg_user_error(); $errmsg[] = rg_user_error();
37 38 break; break;
38 39 } }
 
... ... if ($show_form == 1) {
52 53 $_pass .= rg_template("user/pass.html", $rg, TRUE /*xss*/); $_pass .= rg_template("user/pass.html", $rg, TRUE /*xss*/);
53 54 } }
54 55
55 ?>
File inc/user/repo-page.php changed (mode: 100644) (index d4fd3cb..6f3155c)
... ... if (rg_user_ok($user) !== TRUE) {
5 5 $_repo_page .= rg_warning("Invalid user!"); $_repo_page .= rg_warning("Invalid user!");
6 6 return; return;
7 7 } }
8 $rg['page_ui'] = rg_user_info($db, 0, $user, "");
9 if ($rg['page_ui']['ok'] != 1) {
8 $ui_page = rg_user_info($db, 0, $user, '');
9 if ($ui_page['ok'] != 1) {
10 10 $_repo_page .= rg_warning("Internal error!"); $_repo_page .= rg_warning("Internal error!");
11 11 return; return;
12 12 } }
13 if ($rg['page_ui']['exists'] != 1) {
13 if ($ui_page['exists'] != 1) {
14 14 $_repo_page .= rg_template("user/invalid.html", $rg, TRUE /*xss*/); $_repo_page .= rg_template("user/invalid.html", $rg, TRUE /*xss*/);
15 15 return; return;
16 16 } }
17 rg_ui_page_set($ui_page);
18 $rg['ui_page'] = $ui_page;
17 19
18 20 if (rg_repo_ok($repo) !== TRUE) { if (rg_repo_ok($repo) !== TRUE) {
19 21 $_repo_page .= rg_template('repo/err/invalid.html', $rg, TRUE /*xss*/); $_repo_page .= rg_template('repo/err/invalid.html', $rg, TRUE /*xss*/);
20 22 return; return;
21 23 } }
22 $rg['ri'] = rg_repo_info($db, 0, $rg['page_ui']['uid'], $repo);
24 $rg['ri'] = rg_repo_info($db, 0, $ui_page['uid'], $repo);
23 25 if ($rg['ri']['ok'] != 1) { if ($rg['ri']['ok'] != 1) {
24 26 $_repo_page .= rg_warning("Internal error!"); $_repo_page .= rg_warning("Internal error!");
25 27 return; return;
 
... ... while (1) {
33 35 if ($rg['ri']['deleted'] > 0) if ($rg['ri']['deleted'] > 0)
34 36 break; break;
35 37
36 $x = array();
37 $x['obj_id'] = $rg['ri']['repo_id'];
38 $x['type'] = 'repo';
39 $x['owner'] = $rg['ri']['uid'];
40 $x['uid'] = $rg['login_ui']['uid'];
41 $x['username'] = $rg['login_ui']['username'];
42 $x['needed_rights'] = 'A';
43 $x['ip'] = $rg['ip'];
44 $x['misc'] = "";
45 if (rg_rights_allow($db, $x) !== TRUE)
38 $obj_id = $rg['ri']['repo_id'];
39 if (rg_rights_allow2($db, 'repo', $obj_id, 'A', '') !== TRUE)
46 40 break; break;
47 41
48 42 $allow = TRUE; $allow = TRUE;
 
... ... if ($allow !== TRUE) {
56 50 if (!isset($rg['ri']['git_dir_done'])) if (!isset($rg['ri']['git_dir_done']))
57 51 $rg['ri']['git_dir_done'] = 0; $rg['ri']['git_dir_done'] = 0;
58 52
59 $x['needed_rights'] = 'E';
60 $can_admin = rg_rights_allow($db, $x) === TRUE ? 1 : 0;
53 $can_admin = rg_rights_allow2($db, 'repo', $obj_id, 'E', '') === TRUE ? 1 : 0;
61 54
62 $rg['url_user'] = rg_re_userpage($rg['page_ui']);
63 $rg['url_repo'] = rg_re_repopage($rg['page_ui'], $repo);
55 $rg['url_user'] = rg_re_userpage($ui_page);
56 $rg['url_repo'] = rg_re_repopage($ui_page, $repo);
64 57 $rg['can_admin'] = $can_admin; $rg['can_admin'] = $can_admin;
65 58 $rg['HTML:hints'] = ''; $rg['HTML:hints'] = '';
66 59 $rg['mr'] = array('id' => ''); $rg['mr'] = array('id' => '');
67 60
68 61 $rg['repo_path'] = rg_repo_path_by_id($rg['ri']['uid'], $rg['ri']['repo_id']); $rg['repo_path'] = rg_repo_path_by_id($rg['ri']['uid'], $rg['ri']['repo_id']);
69 rg_log('repo_path=' . $rg['repo_path']);
62 rg_log_debug('repo_path=' . $rg['repo_path']);
70 63 putenv('GIT_DIR=' . $rg['repo_path']); // TODO: this will be removed after all functios will got a path para putenv('GIT_DIR=' . $rg['repo_path']); // TODO: this will be removed after all functios will got a path para
71 64
72 65 $rg['HTML:menu_repo_level2'] = ''; $rg['HTML:menu_repo_level2'] = '';
 
... ... function rg_add_clone_hints($db, &$rg, $ref)
95 88 $hints[]['HTML:hint'] = rg_template("hints/repo/git_setup.html", $hints[]['HTML:hint'] = rg_template("hints/repo/git_setup.html",
96 89 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
97 90
98 if ($rg['ri']['uid'] == $rg['login_ui']['uid']) {
91 $ui_login = rg_ui_login();
92 if ($rg['ri']['uid'] == $ui_login['uid']) {
99 93 $hints[]['HTML:hint'] = rg_template("hints/repo/clone_owner.html", $hints[]['HTML:hint'] = rg_template("hints/repo/clone_owner.html",
100 94 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
101 95 } else { } else {
 
... ... function rg_add_clone_hints($db, &$rg, $ref)
110 104 $hints[]['HTML:hint'] = rg_template("hints/repo/clone_git.html", $hints[]['HTML:hint'] = rg_template("hints/repo/clone_git.html",
111 105 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
112 106
113 $x = array();
114 $x['obj_id'] = $rg['ri']['repo_id'];
115 $x['type'] = 'repo_refs';
116 $x['owner'] = $rg['ri']['uid'];
117 $x['uid'] = $rg['login_ui']['uid'];
118 $x['username'] = $rg['login_ui']['username'];
119 $x['needed_rights'] = 'H'; /* anon push */
120 $x['ip'] = $rg['ip'];
121 $x['misc'] = $ref;
122 if (rg_rights_allow($db, $x) === TRUE)
107 $obj_id = $rg['ri']['repo_id'];
108 /* H = anon push */
109 if (rg_rights_allow2($db, 'repo_refs', $obj_id, 'H', $ref) === TRUE)
123 110 $hints[]['HTML:hint'] = rg_template("hints/repo/anon_push.html", $hints[]['HTML:hint'] = rg_template("hints/repo/anon_push.html",
124 111 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
125 112 } }
 
... ... function repo_page_cb_input($index, &$a, $stream)
139 126 break; break;
140 127
141 128 case 2: // stderr case 2: // stderr
142 rg_log('DEBUG: ' . $a['err_buf']);
129 rg_log_debug('err_buf=' . $a['err_buf']);
143 130 $a['err_buf'] = ''; $a['err_buf'] = '';
144 131 break; break;
145 132 } }
 
... ... function rg_repo_page_source($db, &$rg, &$paras)
242 229 } }
243 230
244 231 $existing_refs = rg_git_refs($rg['repo_path']); $existing_refs = rg_git_refs($rg['repo_path']);
245 rg_log_ml('DEBUG: existing_refs: ' . print_r($existing_refs, TRUE));
232 rg_log_debug('existing_refs: ' . print_r($existing_refs, TRUE));
246 233
247 234 $paras2 = array(array_shift($paras), array_shift($paras)); $paras2 = array(array_shift($paras), array_shift($paras));
248 rg_log('DEBUG: paras: [' . rg_array2string($paras) . ']');
235 rg_log_debug('paras: [' . rg_array2string($paras) . ']');
249 236 $list = array( $list = array(
250 237 $paras2, $paras2,
251 238 array('branch', $rg['ri']['main_branch']), array('branch', $rg['ri']['main_branch']),
 
... ... function rg_repo_page_source($db, &$rg, &$paras)
258 245
259 246 $ok = FALSE; $ok = FALSE;
260 247 foreach ($list as $a) { foreach ($list as $a) {
261 rg_log('DEBUG: a=[' . rg_array2string($a) . ']');
248 rg_log_debug('a=[' . rg_array2string($a) . ']');
262 249 $type_ref = rg_git_parse_ref($a); $type_ref = rg_git_parse_ref($a);
263 rg_log('DEBUG: type_ref: ' . rg_array2string($type_ref));
250 rg_log_debug('type_ref: ' . rg_array2string($type_ref));
264 251 if (rg_git_ref_valid($existing_refs, if (rg_git_ref_valid($existing_refs,
265 252 $type_ref['ref_type'], $type_ref['ref_val']) === TRUE) { $type_ref['ref_type'], $type_ref['ref_val']) === TRUE) {
266 253 $ref = $type_ref['ref_path']; $ref = $type_ref['ref_path'];
 
... ... function rg_repo_page_source($db, &$rg, &$paras)
269 256 } }
270 257 } }
271 258 if ($ok) { if ($ok) {
272 rg_log('DEBUG: ref=[' . $ref . ']');
259 rg_log_debug('ref=[' . $ref . ']');
273 260 $rg = array_merge($rg, $type_ref); $rg = array_merge($rg, $type_ref);
274 261
275 262 $bt = rg_git_branches_and_tags($existing_refs, $bt = rg_git_branches_and_tags($existing_refs,
 
... ... function rg_repo_page_source($db, &$rg, &$paras)
281 268 $ret .= rg_template('repo/source.html', $rg, TRUE /*xss*/); $ret .= rg_template('repo/source.html', $rg, TRUE /*xss*/);
282 269 } }
283 270
284 rg_log('DEBUG: _subsubop=[' . $_subsubop . ']');
271 rg_log_debug('_subsubop=[' . $_subsubop . ']');
285 272 if (strcmp($_subsubop, 'tree') == 0) { if (strcmp($_subsubop, 'tree') == 0) {
286 273 $type = array_shift($paras); $type = array_shift($paras);
287 rg_log('DEBUG: tree: type=' . $type);
274 rg_log_debug('tree: type=' . $type);
288 275 if (strncmp($type, 'blob', 4) == 0) { if (strncmp($type, 'blob', 4) == 0) {
289 276 repo_page_blob($ret, $type, $rg, $paras, $ref); repo_page_blob($ret, $type, $rg, $paras, $ref);
290 277 } else if (strcmp($type, 'tree') == 0) { } else if (strcmp($type, 'tree') == 0) {
 
... ... function rg_repo_page_source($db, &$rg, &$paras)
321 308 } }
322 309
323 310 // show the log // show the log
324 $log = rg_git_log($rg['repo_path'], 10, '', $ref, FALSE, 0);
311 $log = rg_git_log($rg['repo_path'], 20, '', $ref, FALSE, 0);
325 312 if ($log === FALSE) { if ($log === FALSE) {
326 313 $ret .= rg_template('internal_err.html', $ret .= rg_template('internal_err.html',
327 314 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
328 315 break; break;
329 316 } }
330
331 //rg_log_ml('DEBUG: log: ' . print_r($log, TRUE));
317 //rg_log_debug('log: ' . print_r($log, TRUE));
332 318 $ret .= rg_git_log_template($log, 'repo/log', $rg); $ret .= rg_git_log_template($log, 'repo/log', $rg);
319 //rg_log_debug('ret: ' . $ret);
333 320
334 $type = array_shift($paras);
335 //rg_log('DEBUG: log: type=' . $type);
336 if ((strcmp($type, 'commit') == 0)) {
337 if (empty($paras))
338 $commit = FALSE;
339 else
340 $commit = rg_git_reference($paras[0]);
321 if ((strcmp($type_ref['ref_type'], 'commit') == 0)) {
322 $commit = rg_git_reference($type_ref['ref_val']);
341 323 if ($commit === FALSE) { if ($commit === FALSE) {
342 324 rg_log('Invalid commit; make it empty.'); rg_log('Invalid commit; make it empty.');
343 325 // TODO: give an error on the page?! // TODO: give an error on the page?!
 
... ... $_subop = empty($paras) ? "history" : array_shift($paras);
377 359 if (strcmp($_subop, "history") == 0) { if (strcmp($_subop, "history") == 0) {
378 360 rg_add_clone_hints($db, $rg, ''); rg_add_clone_hints($db, $rg, '');
379 361
380 $hist = rg_repo_history_load($db, $rg['ri']['repo_id'], 0, 20, 0);
362 $time_limit = $rg['ri']['itime'];
363 $hist = rg_repo_history_load($db, $rg['ri']['repo_id'], 0, 20, $time_limit);
381 364 if ($hist === FALSE) if ($hist === FALSE)
382 365 $_repo_body .= rg_warning("Cannot load history. Try again later."); $_repo_body .= rg_warning("Cannot load history. Try again later.");
383 366 else else
 
... ... if (strcmp($_subop, "history") == 0) {
392 375 } else if (strcmp($_subop, 'artifacts') == 0) { } else if (strcmp($_subop, 'artifacts') == 0) {
393 376 include(__DIR__ . '/repo/artifacts/main.php'); include(__DIR__ . '/repo/artifacts/main.php');
394 377 $_repo_body .= $artifacts_body; $_repo_body .= $artifacts_body;
378 } else if (strcmp($_subop, 'pkg') == 0) {
379 $_repo_body .= rg_packages_repo_page($db, $rg);
395 380 } else if (strcmp($_subop, "stats") == 0) { } else if (strcmp($_subop, "stats") == 0) {
396 381 $_repo_body .= rg_repo_stats($rg); $_repo_body .= rg_repo_stats($rg);
397 382 } else if (strcmp($_subop, "mr") == 0) { } else if (strcmp($_subop, "mr") == 0) {
 
... ... if (strcmp($_subop, "history") == 0) {
401 386 rg_watch_hl_process($db, $rg, 'repo', $rg['ri']['repo_id'], rg_watch_hl_process($db, $rg, 'repo', $rg['ri']['repo_id'],
402 387 0 /*obj_id2*/, $rg['current_url']); 0 /*obj_id2*/, $rg['current_url']);
403 388
404 $rg['per_repo_menu'][$_subop] = 1;
389 $rg['per_repo_menu'] = $_subop;
405 390 $rg['HTML:repo_body'] = $_repo_body; $rg['HTML:repo_body'] = $_repo_body;
406 391 $_repo_page = rg_template("repo/main.html", $rg, TRUE /*xss*/); $_repo_page = rg_template("repo/main.html", $rg, TRUE /*xss*/);
407 392
393 rg_ui_page_reset();
File inc/user/repo/artifacts/main.php changed (mode: 100644) (index 81040ed..5fc961b)
... ... include_once(__DIR__ . '/../../../artifacts.inc.php');
3 3
4 4 $_artifacts_body = ''; $_artifacts_body = '';
5 5
6 $rg['can_save'] = $rg['login_ui']['uid'] > 0 ? 1 : 0;
6 $ui_login = rg_ui_login();
7 $rg['can_save'] = $ui_login['uid'] > 0 ? 1 : 0;
7 8
8 $x = array();
9 $x['obj_id'] = $rg['ri']['repo_id'];
10 $x['type'] = 'repo';
11 $x['owner'] = $rg['ri']['uid'];
12 $x['uid'] = $rg['login_ui']['uid'];
13 $x['username'] = $rg['login_ui']['username'];
14 $x['ip'] = $rg['ip'];
15 $x['misc'] = '';
16 $x['needed_rights'] = 't';
17 if (rg_rights_allow($db, $x) !== TRUE) {
9 $obj_id = $rg['ri']['repo_id'];
10 if (rg_rights_allow2($db, 'repo', $obj_id, 't', '') !== TRUE) {
11 // TODO: should I return 403/404 etc.?
18 12 $artifacts_body = rg_template('repo/artifacts/deny_access.html', $artifacts_body = rg_template('repo/artifacts/deny_access.html',
19 13 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
20 14 return; return;
21 15 } }
22 $x['needed_rights'] = 'T';
23 $rg['allow_artifacts_del'] = (rg_rights_allow($db, $x) === TRUE) ? 1 : 0;
16 if (rg_rights_allow2($db, 'repo', $obj_id, 'T', '') === TRUE)
17 $rg['allow_artifacts_del'] = 1;
18 else
19 $rg['allow_artifacts_del'] = 0;
24 20
25 21 $_op = empty($paras) ? 'list' : array_shift($paras); $_op = empty($paras) ? 'list' : array_shift($paras);
26 22 $rg['menu']['sub2'][$_op] = 1; $rg['menu']['sub2'][$_op] = 1;
 
... ... $rg['menu']['sub2'][$_op] = 1;
28 24 $rg['HTML:menu_repo_level2'] = $rg['HTML:menu_repo_level2'] =
29 25 rg_template('repo/artifacts/menu.html', $rg, TRUE /*xss*/); rg_template('repo/artifacts/menu.html', $rg, TRUE /*xss*/);
30 26
31 rg_log_ml('DEBUG: paras: ' . print_r($paras, TRUE));
27 rg_log_debug('paras: ' . print_r($paras, TRUE));
32 28 $path = implode('/', $paras); $path = implode('/', $paras);
33 29
34 30 switch ($_op) { switch ($_op) {
 
... ... switch ($_op) {
38 34 // break; // break;
39 35
40 36 case 'download': case 'download':
41 $i = rg_artifacts_load_file($rg['page_ui']['uid'], $rg['ri']['repo_id'], $path);
37 $ui_page = rg_ui_page();
38 $i = rg_artifacts_load_file($ui_page['uid'], $rg['ri']['repo_id'], $path);
42 39 if ($i === FALSE) { if ($i === FALSE) {
43 40 $rg['HTML:artifacts_error'] = rg_artifacts_error(); $rg['HTML:artifacts_error'] = rg_artifacts_error();
44 41 $_artifacts_body .= rg_template('repo/artifacts/error.html', $rg, TRUE /*xss*/); $_artifacts_body .= rg_template('repo/artifacts/error.html', $rg, TRUE /*xss*/);
 
... ... case 'download':
50 47 header('Content-Disposition: attachment; filename="' . $fn . '"'); header('Content-Disposition: attachment; filename="' . $fn . '"');
51 48 header('Content-Length: ' . $i['size']); header('Content-Length: ' . $i['size']);
52 49
53 readfile($i['full_path']);
54 exit(0);
50 $bytes_out = readfile($i['full_path']);
51 rg_stats_conns_set('bytes_out', $bytes_out);
52 $artifacts_body = '';
53 $skip_etag = TRUE;
54 rg_debug() && header('X-RocketGit-skip-etag: 1');
55 $skip_compression = TRUE;
56 rg_debug() && header('X-RocketGit-skip-compression: 1');
57 return;
55 58
56 59 default: // list default: // list
57 rg_log('DEBUG: path=' . $path);
58 $d = rg_artifacts_load($rg['page_ui']['uid'], $rg['ri']['repo_id'], $path);
60 rg_log_debug('path=' . $path);
61 $d = rg_artifacts_load($ui_page['uid'], $rg['ri']['repo_id'], $path);
59 62 if ($d === FALSE) { if ($d === FALSE) {
60 63 $rg['HTML:artifacts_error'] = rg_artifacts_error(); $rg['HTML:artifacts_error'] = rg_artifacts_error();
61 64 $_artifacts_body .= rg_template('repo/artifacts/error.html', $rg, TRUE /*xss*/); $_artifacts_body .= rg_template('repo/artifacts/error.html', $rg, TRUE /*xss*/);
File inc/user/repo/bug/main.php changed (mode: 100644) (index 5987060..b789cb9)
1 1 <?php <?php
2 2 $_bug_body = ''; $_bug_body = '';
3 3
4 $rg['can_save'] = $rg['login_ui']['uid'] > 0 ? 1 : 0;
5
6 $rg['allow_bug_add'] = 0;
7 $x = array();
8 $x['obj_id'] = $rg['ri']['repo_id'];
9 $x['type'] = 'repo';
10 $x['owner'] = $rg['ri']['uid'];
11 $x['uid'] = $rg['login_ui']['uid'];
12 $x['username'] = $rg['login_ui']['username'];
13 $x['ip'] = $rg['ip'];
14 $x['misc'] = '';
15 $x['needed_rights'] = 'B';
16 if (rg_rights_allow($db, $x) === TRUE)
4 $ui_login = rg_ui_login();
5 $rg['can_save'] = $ui_login['uid'] > 0 ? 1 : 0;
6
7 $obj_id = $rg['ri']['repo_id'];
8 if (rg_rights_allow2($db, 'repo', $obj_id, 'B', '') === TRUE)
17 9 $rg['allow_bug_add'] = 1; $rg['allow_bug_add'] = 1;
10 else
11 $rg['allow_bug_add'] = 0;
18 12
19 13 $_op = empty($paras) ? "list" : array_shift($paras); $_op = empty($paras) ? "list" : array_shift($paras);
20 14 $rg['menu']['sub2'][$_op] = 1; $rg['menu']['sub2'][$_op] = 1;
 
... ... case 'list':
50 44
51 45 $_search_name = rg_var_str("name"); $_search_name = rg_var_str("name");
52 46 $r = rg_bug_search_remove($db, $rg['ri']['repo_id'], $r = rg_bug_search_remove($db, $rg['ri']['repo_id'],
53 $rg['login_ui']['uid'], $_search_name);
47 $ui_login['uid'], $_search_name);
54 48 if ($r === FALSE) if ($r === FALSE)
55 49 $_bug_body .= rg_warning("Error: cannot delete search!"); // TODO $_bug_body .= rg_warning("Error: cannot delete search!"); // TODO
56 50 } }
57 51
58 $r = rg_bug_search_load_all($db, $rg['ri']['repo_id'],
59 $rg['login_ui']['uid']);
52 $r = rg_bug_search_load_all($db, $rg['ri']['repo_id'], $ui_login['uid']);
60 53 if ($r === FALSE) { if ($r === FALSE) {
61 54 $_bug_body .= rg_warning("Error: cannot load all searches!"); // TODO $_bug_body .= rg_warning("Error: cannot load all searches!"); // TODO
62 55 } else { } else {
 
... ... case 'list':
65 58 } }
66 59
67 60 $filter = rg_bug_search_load($db, $rg['ri']['repo_id'], $filter = rg_bug_search_load($db, $rg['ri']['repo_id'],
68 $rg['login_ui']['uid'], $_search);
61 $ui_login['uid'], $_search);
69 62 if ($filter === FALSE) { if ($filter === FALSE) {
70 63 $_bug_body .= rg_warning("Error: cannot load search!"); // TODO $_bug_body .= rg_warning("Error: cannot load search!"); // TODO
71 64 $filter = array(); $filter = array();
 
... ... case 'list':
74 67 if (isset($filter['name'])) if (isset($filter['name']))
75 68 $rg['search_name'] = $filter['name']; $rg['search_name'] = $filter['name'];
76 69
77 $r = rg_bug_search($db, $rg['ri']['repo_id'], $rg['login_ui']['uid'], $filter);
70 $r = rg_bug_search($db, $rg['ri']['repo_id'], $ui_login['uid'], $filter);
78 71 if ($r === FALSE) { if ($r === FALSE) {
79 72 // TODO: do something OK here! // TODO: do something OK here!
80 73 $_bug_body .= rg_warning("Error: Cannot search bugs!"); $_bug_body .= rg_warning("Error: Cannot search bugs!");
File inc/user/repo/bug/search/search.php changed (mode: 100644) (index 7366e2f..bd928b3)
... ... if ($rg['doit'] == 0) {
37 37 $_x['standard'] = 0; $_x['standard'] = 0;
38 38
39 39 while (1) { while (1) {
40 $ui_login = rg_ui_login();
40 41 $bugs = rg_bug_search($db, $rg['ri']['repo_id'], $bugs = rg_bug_search($db, $rg['ri']['repo_id'],
41 $rg['login_ui']['uid'], $_x);
42 $ui_login['uid'], $_x);
42 43 if ($bugs === FALSE) { if ($bugs === FALSE) {
43 44 $errmsg[] = "Cannot search bug (" . rg_bug_error() . ")."; $errmsg[] = "Cannot search bug (" . rg_bug_error() . ").";
44 45 break; break;
File inc/user/repo/bug/show/add_note.php changed (mode: 100644) (index 0c4d38a..ee9bdb6)
... ... while (1) {
25 25 break; break;
26 26 } }
27 27
28 $x = array();
29 $x['obj_id'] = $rg['ri']['repo_id'];
30 $x['type'] = 'repo';
31 $x['owner'] = $rg['ri']['uid'];
32 $x['uid'] = $rg['login_ui']['uid'];
33 $x['username'] = $rg['login_ui']['username'];
34 $x['needed_rights'] = 'B';
35 $x['ip'] = $rg['ip'];
36 $x['misc'] = '';
37 if (rg_rights_allow($db, $x) !== TRUE) {
28 $obj_id = $rg['ri']['repo_id'];
29 if (rg_rights_allow2($db, 'repo', $obj_id, 'B', '') !== TRUE) {
38 30 $note_errmsg[] = rg_template("repo/bug/note/deny_add.html", $rg, TRUE /*xss*/); $note_errmsg[] = rg_template("repo/bug/note/deny_add.html", $rg, TRUE /*xss*/);
39 31 break; break;
40 32 } }
 
... ... while (1) {
42 34 // add note // add note
43 35 $_d = array(); $_d = array();
44 36 $_d['note'] = $note; $_d['note'] = $note;
37 $ui_login = rg_ui_login();
45 38 $ret = rg_bug_note_add($db, $rg['ri']['repo_id'], $bug_id, $ret = rg_bug_note_add($db, $rg['ri']['repo_id'], $bug_id,
46 $rg['login_ui']['uid'], $_d);
39 $ui_login['uid'], $_d);
47 40 if ($ret === FALSE) { if ($ret === FALSE) {
48 41 $note_errmsg[] = "Cannot add note (" . rg_bug_error() . ")"; $note_errmsg[] = "Cannot add note (" . rg_bug_error() . ")";
49 42 break; break;
 
... ... $rg['rg_form_token_tag'] = 'note_add';
60 53 $rg['rg_form_token'] = rg_token_get($db, $rg, 'note_add'); $rg['rg_form_token'] = rg_token_get($db, $rg, 'note_add');
61 54 $rg['note'] = $note; $rg['note'] = $note;
62 55 $rg['HTML:note_add'] = rg_template("repo/bug/note_add.html", $rg, TRUE /* xss */); $rg['HTML:note_add'] = rg_template("repo/bug/note_add.html", $rg, TRUE /* xss */);
63 ?>
File inc/user/repo/bug/show/show.php changed (mode: 100644) (index 21d1fcd..0a2aa88)
1 1 <?php <?php
2 2 // TODO: security checks // TODO: security checks
3 3
4 $ui_login = rg_ui_login();
5
4 6 $_bug_show = ''; $_bug_show = '';
5 7
6 8 $rg['HTML:bug_edit'] = ''; $rg['HTML:bug_edit'] = '';
 
... ... if ($ibug['exists'] != 1) {
18 20 return; return;
19 21 } }
20 22
21 $x = array();
22 $x['obj_id'] = $rg['ri']['repo_id'];
23 $x['type'] = 'repo';
24 $x['owner'] = $rg['ri']['uid'];
25 $x['uid'] = $rg['login_ui']['uid'];
26 $x['username'] = $rg['login_ui']['username'];
27 $x['ip'] = $rg['ip'];
28 $x['misc'] = '';
23 $obj_id = $rg['ri']['repo_id'];
29 24
30 25 // If bug is deleted and the user does not have 'delete' rights, deny access. // If bug is deleted and the user does not have 'delete' rights, deny access.
31 26 if ($ibug['deleted'] > 0) { if ($ibug['deleted'] > 0) {
32 $x['needed_rights'] = 'd';
33 if (rg_rights_allow($db, $x) !== TRUE) {
27 if (rg_rights_allow2($db, 'repo', $obj_id, 'd', '') !== TRUE) {
34 28 $_bug_body .= rg_template("repo/bug/deleted.html", $rg, TRUE /*xss*/); $_bug_body .= rg_template("repo/bug/deleted.html", $rg, TRUE /*xss*/);
35 29 return; return;
36 30 } }
 
... ... while (1) {
61 55 $ibug['state_text'] = rg_bug_state($ibug['state']); $ibug['state_text'] = rg_bug_state($ibug['state']);
62 56
63 57 if ($ibug['state'] == 1) { // reopen if ($ibug['state'] == 1) { // reopen
64 $x['needed_rights'] = 'r';
65 if (rg_rights_allow($db, $x) !== TRUE) {
58 if (rg_rights_allow2($db, 'repo', $obj_id, 'r', '') !== TRUE) {
66 59 rg_template("repo/bug/deny_reopen.html", $rg, TRUE /*xss*/); rg_template("repo/bug/deny_reopen.html", $rg, TRUE /*xss*/);
67 60 break; break;
68 61 } }
69 62 } else { // close } else { // close
70 $x['needed_rights'] = 'C';
71 if (rg_rights_allow($db, $x) !== TRUE) {
63 if (rg_rights_allow2($db, 'repo', $obj_id, 'C', '') !== TRUE) {
72 64 rg_template("repo/bug/deny_close.html", $rg, TRUE /*xss*/); rg_template("repo/bug/deny_close.html", $rg, TRUE /*xss*/);
73 65 break; break;
74 66 } }
 
... ... while (1) {
84 76 break; break;
85 77 } }
86 78
87 $ret = rg_bug_edit($db, $rg['login_ui'], $rg['ri'], $ibug);
79 $ret = rg_bug_edit($db, $ui_login, $rg['ri'], $ibug);
88 80 if ($ret === FALSE) { if ($ret === FALSE) {
89 81 $close_reopen_error = rg_warning('Cannot edit bug (' . rg_bug_error() . ')', $rg); $close_reopen_error = rg_warning('Cannot edit bug (' . rg_bug_error() . ')', $rg);
90 82 break; break;
 
... ... while (rg_var_uint('del_doit') == 1) {
147 139 break; break;
148 140 } }
149 141
150 $x['needed_rights'] = 'd';
151 if (rg_rights_allow($db, $x) !== TRUE) {
142 if (rg_rights_allow2($db, 'repo', $obj_id, 'd', '') !== TRUE) {
152 143 $delete_error = rg_template("repo/bug/deny_delete.html", $delete_error = rg_template("repo/bug/deny_delete.html",
153 144 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
154 145 break; break;
155 146 } }
156 147
157 $r = rg_bug_delete_undelete($db, $rg['login_ui']['uid'],
148 $r = rg_bug_delete_undelete($db, $ui_login['uid'],
158 149 $rg['ri']['repo_id'], $ibug['bug_id'], $del_undel); $rg['ri']['repo_id'], $ibug['bug_id'], $del_undel);
159 150 if ($r === FALSE) { if ($r === FALSE) {
160 151 $delete_error = rg_warning(rg_bug_error(), $rg); $delete_error = rg_warning(rg_bug_error(), $rg);
File inc/user/settings.php changed (mode: 100644) (index a4cbfff..991feed)
1 1 <?php <?php
2 2 $_settings = ''; $_settings = '';
3 3
4 if ($rg['login_ui']['uid'] == 0) {
4 $ui_login = rg_ui_login();
5 if ($ui_login['uid'] == 0) {
5 6 $_settings .= rg_template('user/login_first.html', $rg, TRUE /*xss*/); $_settings .= rg_template('user/login_first.html', $rg, TRUE /*xss*/);
6 7 return; return;
7 8 } }
8 9
9 $rg['target_ui'] = $rg['login_ui'];
10 $rg['target_ui'] = $ui_login;
10 11
11 12 $errmsg = array(); $errmsg = array();
12 13
 
... ... case 'workers':
43 44 $_settings_body = rg_worker_high_level($db, $rg, $paras); $_settings_body = rg_worker_high_level($db, $rg, $paras);
44 45 break; break;
45 46
47 case 'packages':
48 $_settings_body = rg_packages_high_level($db, $rg, $paras);
49 break;
50
46 51 case 'delete_account': case 'delete_account':
47 52 $_settings_body = rg_user_delete_account_high_level($db, $rg, $paras); $_settings_body = rg_user_delete_account_high_level($db, $rg, $paras);
48 53 break; break;
 
... ... default:
55 60 } }
56 61 $rg['url'] = $rg['url_up']; $rg['url'] = $rg['url_up'];
57 62
58 $rg['set_menu'][$_subop] = 1;
63 $rg['set_menu'] = $_subop;
59 64 $_settings = rg_template('user/settings/menu.html', $rg, TRUE /*xss*/); $_settings = rg_template('user/settings/menu.html', $rg, TRUE /*xss*/);
60 65 $_settings .= '<div class="generic_body">' . "\n"; $_settings .= '<div class="generic_body">' . "\n";
61 66 $_settings .= $_settings_body; $_settings .= $_settings_body;
File inc/util.inc.php changed (mode: 100644) (index 6e2c018..198e2fc)
... ... register_shutdown_function("rg_error_shutdown");
7 7
8 8 define('RG_SOCKET_NO_WAIT', 0x01); define('RG_SOCKET_NO_WAIT', 0x01);
9 9
10 define('RG_LOCK_BLOCK', 1 << 0);
11
10 12 if (!isset($rg_util_debug)) if (!isset($rg_util_debug))
11 13 $rg_util_debug = FALSE; $rg_util_debug = FALSE;
12 14 if (strcmp(getenv('ROCKETGIT_UTIL_DEBUG'), '1') == 0) if (strcmp(getenv('ROCKETGIT_UTIL_DEBUG'), '1') == 0)
13 15 $rg_util_debug = TRUE; $rg_util_debug = TRUE;
14 16
15 17 $rg_util_error = ""; $rg_util_error = "";
18 $rg_php_err = '-';
16 19
17 20 function rg_util_set_error($str) function rg_util_set_error($str)
18 21 { {
 
... ... function rg_php_err()
43 46 //$a = error_get_last(); //$a = error_get_last();
44 47 //if ($a === NULL) { //if ($a === NULL) {
45 48 $ret = $rg_php_err; $ret = $rg_php_err;
46 $rg_php_err = '';
49 $rg_php_err = '-';
47 50 //} else { //} else {
48 51 // $ret = $a['message']; // $ret = $a['message'];
49 52 // error_clear_last(); // error_clear_last();
 
... ... function rg_1024($v)
90 93 return number_format($v) . "GiB"; return number_format($v) . "GiB";
91 94 $v /= 1024; $v /= 1024;
92 95
93 return number_format($v) . "TiB";
96 if ($v <= 9999)
97 return number_format($v) . "TiB";
98 $v /= 1024;
99
100 return number_format($v) . "PiB";
94 101 } }
95 102
96 103 /* /*
97 * Transforms a kilo/mega/giga into bytes
104 * Transforms a kilo/mega/giga/tera into bytes
98 105 * Example: 8M -> 8388608 * Example: 8M -> 8388608
99 106 */ */
100 107 function rg_mega2bytes($s) function rg_mega2bytes($s)
 
... ... function rg_mega2bytes($s)
106 113 return $r * 1024 * 1024; return $r * 1024 * 1024;
107 114 if (stristr($s, 'g')) if (stristr($s, 'g'))
108 115 return $r * 1024 * 1024 * 1024; return $r * 1024 * 1024 * 1024;
116 if (stristr($s, 't'))
117 return $r * 1024 * 1024 * 1024 * 1024;
109 118
110 119 return $r; return $r;
111 120 } }
 
... ... function rg_id($len)
166 175 * Locks a file * Locks a file
167 176 */ */
168 177 $_lock = array(); $_lock = array();
169 function rg_lock($file)
178 function rg_lock($file, $flags)
170 179 { {
171 180 global $_lock; global $_lock;
172 181 global $rg_lock_dir; global $rg_lock_dir;
 
... ... function rg_lock($file)
176 185
177 186 // Double locking? // Double locking?
178 187 if (isset($_lock[$file])) { if (isset($_lock[$file])) {
179 rg_internal_error("Double locking [$file]: "
180 . rg_array2string($_lock));
188 rg_util_set_error('double locking error [' . $file . ']');
181 189 return FALSE; return FALSE;
182 190 } }
183 191
184 192 $f = @fopen($rg_lock_dir . "/" . $file, "w"); $f = @fopen($rg_lock_dir . "/" . $file, "w");
185 193 if ($f === FALSE) { if ($f === FALSE) {
186 rg_internal_error('Cannot open lock: ' . rg_php_err() . '.');
194 rg_util_set_error('cannot open lock [' . $file . ']: '
195 . rg_php_err());
187 196 return FALSE; return FALSE;
188 197 } }
189 198
190 if (!@flock($f, LOCK_EX | LOCK_NB, $wouldblock)) {
199 $x = LOCK_EX | LOCK_NB;
200 if ($flags & RG_LOCK_BLOCK)
201 $x &= ~LOCK_NB;
202 if (!@flock($f, $x, $wouldblock)) {
191 203 if ($wouldblock == 1) if ($wouldblock == 1)
192 rg_log('Cannot lock: already locked');
204 rg_util_set_error('lock already locked [' . $file . ']');
193 205 else else
194 rg_log('Cannot lock: ' . rg_php_err());
206 rg_util_set_error('cannot lock [' . $file . ']: '
207 . rg_php_err());
195 208 fclose($f); fclose($f);
196 209 return FALSE; return FALSE;
197 210 } }
 
... ... function rg_lock($file)
199 212 fwrite($f, getmypid() . "\n"); fwrite($f, getmypid() . "\n");
200 213
201 214 $_lock[$file] = $f; $_lock[$file] = $f;
202 rg_log('Lock [' . $file . '] acquired.');
215 rg_log('Lock acquired [' . $file . ']');
203 216
204 217 return TRUE; return TRUE;
205 218 } }
206 219
207 220 function rg_lock_or_exit($file) function rg_lock_or_exit($file)
208 221 { {
209 if (rg_lock($file) === FALSE)
222 if (rg_lock($file, 0) === FALSE)
210 223 exit(0); exit(0);
211 224 } }
212 225
 
... ... function rg_unlock($file)
215 228 global $_lock; global $_lock;
216 229
217 230 if (!isset($_lock[$file])) { if (!isset($_lock[$file])) {
218 rg_internal_error('Lock [' . $file . '] not taken!');
231 rg_internal_error('Lock not taken [' . $file . ']');
219 232 return FALSE; return FALSE;
220 233 } }
221 234
222 235 fclose($_lock[$file]); fclose($_lock[$file]);
223 rg_log('Lock [' . $file . '] unlocked.');
236 rg_log('Lock unlocked [' . $file . ']');
237 unset($_lock[$file]);
224 238 } }
225 239
226 240 /* /*
 
... ... function rg_load()
312 326 */ */
313 327 function rg_xss_safe($str) function rg_xss_safe($str)
314 328 { {
315 if (!defined('ENT_HTML401'))
316 define('ENT_HTML401', 0);
317 return htmlspecialchars($str, ENT_QUOTES | ENT_HTML401, 'UTF-8');
329 return htmlspecialchars($str,
330 ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5, 'UTF-8');
318 331 } }
319 332
320 333 /* /*
 
... ... function rg_re_bugpage($ui, $repo_name, $bug_id)
357 370 return rg_re_repopage($ui, $repo_name) . "/bug/" . $bug_id; return rg_re_repopage($ui, $repo_name) . "/bug/" . $bug_id;
358 371 } }
359 372
360 /*
361 * Returns the correct URL to the current virtual host
362 */
363 function rg_base_url()
364 {
365 global $rg_base_url;
366
367 return $rg_base_url;
368 }
369
370 373 /* /*
371 374 * Builds a host[+port] * Builds a host[+port]
372 375 */ */
 
... ... function rg_base_url_host_port($hostname, $port, $default_port)
383 386 * @http(s)_allow: '0' if not allowed, FALSE if unknown, else port number * @http(s)_allow: '0' if not allowed, FALSE if unknown, else port number
384 387 * Note: at least one of http_allow or https_allow will be set to a port number. * Note: at least one of http_allow or https_allow will be set to a port number.
385 388 */ */
386 function rg_base_url_build($hostname, $http_allow, $https_allow)
389 function rg_base_url_build($hostname, $http_allow, $https_allow, $user, $pass)
387 390 { {
388 global $rg_base_url;
389
390 391 // We are forced to use something if we cannot get them from cache/db // We are forced to use something if we cannot get them from cache/db
391 392 if (($hostname === FALSE) || empty($hostname)) if (($hostname === FALSE) || empty($hostname))
392 393 $hostname = php_uname('n'); $hostname = php_uname('n');
393 394
395 if (!empty($user))
396 $add = rawurlencode($user) . ':' . rawurlencode($pass) . '@';
397 else
398 $add = '';
399
394 400 // Prefer httpS // Prefer httpS
395 if (intval($https_allow) > 0) {
396 $rg_base_url = 'https://' . rg_base_url_host_port($hostname, $https_allow, 443);
397 return;
398 }
401 if (intval($https_allow) > 0)
402 return 'https://' . $add
403 . rg_base_url_host_port($hostname, $https_allow, 443);
399 404
400 $rg_base_url = 'http://' . rg_base_url_host_port($hostname, $http_allow, 80);
405 return 'http://' . $add
406 . rg_base_url_host_port($hostname, $http_allow, 80);
401 407 } }
402 408
403 409 function rg_re_repo_ssh($organization, $user, $repo) function rg_re_repo_ssh($organization, $user, $repo)
 
... ... function rg_var_str_nocr($name)
485 491 return str_replace($k, $v, rg_var_str($name)); return str_replace($k, $v, rg_var_str($name));
486 492 } }
487 493
494 function rg_var_str_list($name)
495 {
496 $a = trim(rg_var_str($name));
497 $a = str_replace("\n", ' ', $a);
498 $a = str_replace("\r", ' ', $a);
499 $a = str_replace("\t", ' ', $a);
500 $old = '';
501 while (strcmp($old, $a) != 0) {
502 $old = $a;
503 $a = str_replace(' ', ' ', $a);
504 }
505
506 return $a;
507 }
508
488 509 function rg_var_int($name) function rg_var_int($name)
489 510 { {
490 511 $r = rg_var_str($name); $r = rg_var_str($name);
 
... ... function rg_array_merge($src, $namespace, $a)
685 706 return $ret; return $ret;
686 707 } }
687 708
709 /*
710 * Returns the members of the array, excluding arrays
711 */
712 function rg_array_filter_arrays($a)
713 {
714 $ret = array();
715 foreach ($a as $k => $v) {
716 if (is_array($v))
717 continue;
718 $ret[$k] = $v;
719 }
720
721 return $ret;
722 }
723
688 724 /* /*
689 725 * Performs a lookup of a var of type 'a::b::c' into an array and * Performs a lookup of a var of type 'a::b::c' into an array and
690 726 * returns FALSE or the value * returns FALSE or the value
 
... ... function rg_template_find_true_and_false(&$s, $off, &$true_start, &$true_end,
800 836
801 837 $true_start = strpos($s, '{{', $off); $true_start = strpos($s, '{{', $off);
802 838 if ($true_start === FALSE) { if ($true_start === FALSE) {
803 //rg_log("DEBUG: no '{{'!");
839 //rg_log_debug('no \'{{\'!');
804 840 //rg_log_exit(); //rg_log_exit();
805 841 return -1; return -1;
806 842 } }
807 843 $true_start += 2; $true_start += 2;
808 844
809 845 if (strncmp(substr($s, $true_start, 1), "\n", 1) == 0) { if (strncmp(substr($s, $true_start, 1), "\n", 1) == 0) {
810 //rg_log("DEBUG: true starts with CR, remove it");
846 //rg_log_debug('true starts with CR, remove it');
811 847 $true_start++; $true_start++;
812 848 } }
813 849
814 850 $true_end = rg_template_find_closing($s, $true_start); $true_end = rg_template_find_closing($s, $true_start);
815 851 if ($true_end == -1) { if ($true_end == -1) {
816 //rg_log("DEBUG: no true_end!");
852 //rg_log_debug('no true_end!');
817 853 //rg_log_exit(); //rg_log_exit();
818 854 return -1; return -1;
819 855 } }
820 //rg_log("DEBUG: true_start=$true_start true_end=$true_end [" . substr($s, $true_end, 3) . "...]"
821 // . " true=[" . substr($s, $true_start, $true_end - $true_start + 1) . "]");
856 //rg_log_debug('true_start=' . $true_start
857 // . ' true_end=' . $true_end . ' [' . substr($s, $true_end, 3) . '...]'
858 // . ' true=[' . substr($s, $true_start, $true_end - $true_start + 1) . ']');
822 859
823 860 // We try to detect if we have an else // We try to detect if we have an else
824 861 $false_start = -1; $false_end = -1; $false_start = -1; $false_end = -1;
 
... ... function rg_template_find_true_and_false(&$s, $off, &$true_start, &$true_end,
826 863 if ($x !== FALSE) { if ($x !== FALSE) {
827 864 $gap = substr($s, $true_end + 3, $x - $true_end - 3); $gap = substr($s, $true_end + 3, $x - $true_end - 3);
828 865 $gap = trim($gap); $gap = trim($gap);
829 //rg_log("DEBUG: gap = [$gap]");
866 //rg_log_debug('gap = [' . $gap . ']');
830 867 if (empty($gap)) { if (empty($gap)) {
831 868 $false_start = $x + 2; $false_start = $x + 2;
832 869 if (strncmp(substr($s, $false_start, 1), "\n", 1) == 0) { if (strncmp(substr($s, $false_start, 1), "\n", 1) == 0) {
833 //rg_log("DEBUG: false starts with CR, remove it");
870 //rg_log_debug('false starts with CR, remove it');
834 871 $false_start++; $false_start++;
835 872 } }
836 873 $false_end = rg_template_find_closing($s, $x + 2); $false_end = rg_template_find_closing($s, $x + 2);
837 //rg_log("DEBUG: false=[" . substr($s, $false_start, $false_end - $false_start + 1) . "]");
874 //rg_log_debug('false=[' . substr($s, $false_start, $false_end - $false_start + 1) . ']');
838 875 } else { } else {
839 //rg_log("DEBUG: gap prevents parsing stuff as false, we have only true part");
876 //rg_log_debug('gap prevents parsing stuff as false, we have only true part');
840 877 } }
841 878 } else { } else {
842 //rg_log("DEBUG: cannot find '{{'");
879 //rg_log_debug('cannot find \'{{\'');
843 880 } }
844 881
845 882 //rg_log_exit(); //rg_log_exit();
 
... ... function rg_template_string_if(&$s, $off, &$data, &$next, $xss_protection)
892 929 if ($false_start != -1) if ($false_start != -1)
893 930 $x = substr($s, $false_start, $false_end - $false_start + 1); $x = substr($s, $false_start, $false_end - $false_start + 1);
894 931 } }
895 //rg_log("DEBUG: x=[$x]");
932 //rg_log_debug('x=[' . $x . ']');
896 933
897 934 $ret .= rg_template_string($x, 0, $data, $xss_protection); $ret .= rg_template_string($x, 0, $data, $xss_protection);
898 935
 
... ... function rg_template_string_if(&$s, $off, &$data, &$next, $xss_protection)
904 941 if (strncmp(substr($s, $next, 1), "\n", 1) == 0) if (strncmp(substr($s, $next, 1), "\n", 1) == 0)
905 942 $next++; $next++;
906 943
907 //rg_log("DEBUG: next: [" . substr($s, $next) . "]");
944 //rg_log_debug('next: [' . substr($s, $next) . ']');
908 945 //rg_log_exit(); //rg_log_exit();
909 946 rg_prof_end("template_string_if"); rg_prof_end("template_string_if");
910 947 return $ret; return $ret;
 
... ... function rg_template_string(&$s, $off, &$data, $xss_protection)
924 961
925 962 $ret = ''; $ret = '';
926 963 while (strlen(substr($s, $off, 1)) == 1) { while (strlen(substr($s, $off, 1)) == 1) {
927 //rg_log("DEBUG: template_string: s+off=[" . substr($s, $off) . "]");
964 //rg_log_debug('template_string: s+off=[' . substr($s, $off) . ']');
928 965 $pos = strpos($s, '@@', $off); $pos = strpos($s, '@@', $off);
929 966 if ($pos === FALSE) { if ($pos === FALSE) {
930 967 $ret .= substr($s, $off); $ret .= substr($s, $off);
 
... ... function rg_template_string(&$s, $off, &$data, $xss_protection)
934 971
935 972 // copy everything before '@@' // copy everything before '@@'
936 973 $ret .= substr($s, $off, $pos - $off); $ret .= substr($s, $off, $pos - $off);
937 //rg_log("DEBUG: after copy all before @@, ret=[$ret]");
974 //rg_log_debug('after copy all before @@, ret=[' . $ret . ']');
938 975 $off = $pos; $off = $pos;
939 976
940 977 $s2 = substr($s, $off, 5); $s2 = substr($s, $off, 5);
 
... ... function rg_template_string(&$s, $off, &$data, $xss_protection)
961 998 $off = $pos2 + 2; $off = $pos2 + 2;
962 999
963 1000 $var = substr($s, $var_start, $var_end - $var_start + 1); $var = substr($s, $var_start, $var_end - $var_start + 1);
964 //rg_log("DEBUG: var=[$var]");
1001 //rg_log_debug('var=[' . $var . ']');
965 1002
966 1003 $value = rg_template_tree_lookup($var, $data, $xss_protection); $value = rg_template_tree_lookup($var, $data, $xss_protection);
967 1004 if ($value === FALSE) { if ($value === FALSE) {
 
... ... function rg_template_string(&$s, $off, &$data, $xss_protection)
969 1006 if (strncmp($var, 'IMG:', 4) == 0) { if (strncmp($var, 'IMG:', 4) == 0) {
970 1007 $path = substr($var, 4); $path = substr($var, 4);
971 1008 $path = rg_template_string($path, 0, $data, $xss_protection); $path = rg_template_string($path, 0, $data, $xss_protection);
972 //rg_log("DEBUG: found an img tag path=[$path]!");
1009 //rg_log_debug('found an img tag path=[' . $path . ']');
973 1010 $value = rg_theme_resolve_path($path); $value = rg_theme_resolve_path($path);
974 1011 } else if (strncmp($var, 'FUNC:', 5) == 0) { } else if (strncmp($var, 'FUNC:', 5) == 0) {
975 1012 $rest = substr($var, 5); $rest = substr($var, 5);
976 //rg_log("DEBUG: found a function call rest=[$rest]!");
1013 //rg_log_debug('found a function call rest=[' . $rest . ']');
977 1014 $fpos = strpos($rest, ':'); $fpos = strpos($rest, ':');
978 1015 if ($fpos === FALSE) { if ($fpos === FALSE) {
979 1016 // no params // no params
1017 $func = $rest;
980 1018 $_param = ''; $_param = '';
981 1019 } else { } else {
982 $_param = '@@' . substr($rest, $fpos + 1) . '@@';
1020 $func = substr($rest, 0, $fpos);
1021 $_param = substr($rest, $fpos + 1);
983 1022 } }
984 1023
985 $func = substr($rest, 0, $fpos);
986 //rg_log("DEBUG: func=$func _param=$_param");
1024 //rg_log_debug('func=[' . $func . '] _param=[' . $_param . ']');
987 1025
988 1026 // out var may be with '@@' // out var may be with '@@'
989 1027 $param = rg_template_string($_param, 0, $data, $xss_protection); $param = rg_template_string($_param, 0, $data, $xss_protection);
990 1028
991 if (isset($rg_template_functions[$func]))
992 $value = $rg_template_functions[$func]($param);
1029 if (isset($rg_template_functions[$func])) {
1030 if (strncmp($param, '@@', 2) == 0) {
1031 $param = substr($param, 2);
1032 $param = substr($param, 0, -2);
1033 }
1034 $r = $rg_template_functions[$func]($param);
1035 //rg_debug() && rg_log(' func returned [' . $r . ']');
1036 $value = $r['value'];
1037 if ($xss_protection && ($r['html'] !== 1))
1038 $value = rg_xss_safe($value);
1039 }
993 1040 } else if (strncmp($var, 'URL_ESCAPE:', 11) == 0) { } else if (strncmp($var, 'URL_ESCAPE:', 11) == 0) {
994 1041 $rest = substr($var, 11); $rest = substr($var, 11);
995 1042 $value = rg_template_tree_lookup($rest, $data, FALSE /*xss*/); $value = rg_template_tree_lookup($rest, $data, FALSE /*xss*/);
996 1043 $value = rawurlencode($value); $value = rawurlencode($value);
1044 } else if (strncmp($var, 'ESCAPE_SHELL_ARG:', 17) == 0) {
1045 $rest = substr($var, 17);
1046 $value = rg_template_tree_lookup($rest, $data, FALSE /*xss*/);
1047 $value = escapeshellarg($value);
997 1048 } else if (strncmp($var, 'TEMPLATE:', 9) == 0) { } else if (strncmp($var, 'TEMPLATE:', 9) == 0) {
998 1049 $path = substr($var, 9); $path = substr($var, 9);
999 rg_log("DEBUG: found a template path=[$path]!");
1050 rg_log_debug('found a template path=[' . $path . ']');
1000 1051 $value = rg_template($path, $data, $xss_protection); $value = rg_template($path, $data, $xss_protection);
1001 1052 } else if (strncmp($var, 'SET:', 4) == 0) { } else if (strncmp($var, 'SET:', 4) == 0) {
1002 1053 $rest = substr($var, 4); $rest = substr($var, 4);
1003 rg_log("DEBUG: found a set rest=[$rest]!");
1054 rg_log_debug('found a set rest=[' . $rest . ']');
1004 1055 $_t = explode('=', $rest, 2); $_t = explode('=', $rest, 2);
1005 1056 if (isset($_t[1])) if (isset($_t[1]))
1006 1057 $data[$_t[0]] = $_t[1]; $data[$_t[0]] = $_t[1];
 
... ... function rg_template_string(&$s, $off, &$data, $xss_protection)
1008 1059 } else if (strcmp($var, 'DUMP') == 0) { } else if (strcmp($var, 'DUMP') == 0) {
1009 1060 $value = rg_xss_safe(print_r($data, TRUE)); $value = rg_xss_safe(print_r($data, TRUE));
1010 1061 } else { } else {
1011 //rg_log("DEBUG: VAR [$var] NOT FOUND!");
1062 // You do not want to activate next line because of spurious lookups
1063 rg_log('WARN: var [' . $var . '] not found');
1012 1064 } }
1013 1065 } }
1014 //rg_log("DEBUG: var=[$var] value=[$value]");
1066 //rg_log_debug('var=[' . $var . '] value=[' . $value . ']');
1015 1067 $ret .= $value; $ret .= $value;
1016 1068 } }
1017 1069
1018 //rg_log("DEBUG: ret=[$ret]");
1070 //rg_log_debug('ret=[' . $ret . ']');
1019 1071 //rg_log_exit(); //rg_log_exit();
1020 1072 rg_prof_end('template_string'); rg_prof_end('template_string');
1021 1073 return $ret; return $ret;
 
... ... function rg_template_blind($file)
1060 1112 function rg_template($file, &$data, $xss_protection) function rg_template($file, &$data, $xss_protection)
1061 1113 { {
1062 1114 rg_prof_start('template'); rg_prof_start('template');
1063 //rg_log_enter('template: ' . $file);
1115 rg_log_enter('template: ' . $file);
1064 1116
1065 1117 $ret = ''; $ret = '';
1066 1118 while (1) { while (1) {
 
... ... function rg_template($file, &$data, $xss_protection)
1072 1124 break; break;
1073 1125 } }
1074 1126
1075 //rg_log("DEBUG: rg_template returns [$ret]");
1076 //rg_log_exit();
1127 //rg_log_debug('rg_template returns [' . $ret . ']');
1128 rg_log_exit();
1077 1129 rg_prof_end('template'); rg_prof_end('template');
1078 1130 return $ret; return $ret;
1079 1131 } }
 
... ... function rg_socket_recv_wait($socket, $wait, $timeout)
2169 2221 if ($timeout === NULL) { if ($timeout === NULL) {
2170 2222 $tv_sec = NULL; $tv_sec = NULL;
2171 2223 $tv_usec = NULL; $tv_usec = NULL;
2224 $limit = 0;
2225 } else if ($timeout == 0) {
2226 $tv_sec = 0;
2227 $tv_usec = 0;
2228 $limit = 0;
2172 2229 } else { } else {
2173 2230 $tv_sec = $timeout / 1000; $tv_sec = $timeout / 1000;
2174 2231 $tv_usec = ($timeout % 1000) * 1000; $tv_usec = ($timeout % 1000) * 1000;
2232 $limit = microtime(TRUE) + $timeout / 1000;
2175 2233 } }
2176 2234
2177 2235 $ret_buf = ''; $ret_buf = '';
 
... ... function rg_socket_recv_wait($socket, $wait, $timeout)
2199 2257 rg_log('Cannot receive: ' . socket_strerror(socket_last_error())); rg_log('Cannot receive: ' . socket_strerror(socket_last_error()));
2200 2258 break; break;
2201 2259 } }
2260 if ($r === 0) {
2261 rg_log('Cannot receive (zero)');
2262 break;
2263 }
2264
2202 2265 //rg_log("Received [$buf]"); //rg_log("Received [$buf]");
2203 2266 $ret_buf .= $buf; $ret_buf .= $buf;
2204 2267
 
... ... function rg_socket_recv_wait($socket, $wait, $timeout)
2208 2271 break; break;
2209 2272 } }
2210 2273
2211 break;
2274 $t = microtime(TRUE);
2275 if ($t > $limit)
2276 break;
2277
2278 $tv_sec = intval($t - $limit);
2279 $tv_usec = (($t - $limit) * 1000) % 1000;
2212 2280 } }
2213 2281
2214 2282 rg_prof_end('socket_recv_wait'); rg_prof_end('socket_recv_wait');
 
... ... function rg_socket_send($socket, $buf)
2229 2297 while (1) { while (1) {
2230 2298 $r = @socket_send($socket, substr($buf, $off), $len - $off, 0); $r = @socket_send($socket, substr($buf, $off), $len - $off, 0);
2231 2299 if ($r === FALSE) { if ($r === FALSE) {
2232 rg_log("Could not send (" . socket_strerror(socket_last_error()) . ")!");
2300 rg_log('Could not send data to socket ('
2301 . socket_strerror(socket_last_error()) . ')!');
2233 2302 break; break;
2234 2303 } }
2235 2304 //rg_log("Sent $r bytes (" . substr($buf, $off, $r) . ")."); //rg_log("Sent $r bytes (" . substr($buf, $off, $r) . ").");
 
... ... function rg_socket($path, $buf, $timeout, $tries, $flags)
2278 2347
2279 2348 break; break;
2280 2349 } }
2350 rg_prof_end('socket-connect');
2281 2351 if ($r === FALSE) { if ($r === FALSE) {
2282 2352 rg_log('Could not connect the socket [' . $path . ']' rg_log('Could not connect the socket [' . $path . ']'
2283 2353 . '(' . socket_strerror(socket_last_error()) . ')!'); . '(' . socket_strerror(socket_last_error()) . ')!');
2284 2354 break; break;
2285 2355 } }
2286 rg_prof_end('socket-connect');
2287 2356
2288 2357 $rg_socket_cache[$path] = $socket; $rg_socket_cache[$path] = $socket;
2289 2358 } }
 
... ... function rg_socket($path, $buf, $timeout, $tries, $flags)
2302 2371 } }
2303 2372
2304 2373 $ret = rg_socket_recv_wait($socket, "\n", $timeout); $ret = rg_socket_recv_wait($socket, "\n", $timeout);
2374 if ($ret === FALSE) {
2375 socket_close($socket);
2376 unset($rg_socket_cache[$path]);
2377 break;
2378 }
2379
2305 2380 break; break;
2306 2381 } }
2307 2382
 
... ... function rg_age($ts)
2374 2449 } }
2375 2450
2376 2451 /* /*
2377 * Returns the path into the temporary area
2452 * Returns a path to a temporary directory.
2453 * Timeout parameter will instruct the clean task when it can be removed.
2454 * Use 0 for timeout_in_minutes to not clean that temp dir/file.
2455 * TODO: The clean procedure is not done yet!
2378 2456 */ */
2379 function rg_tmp_path($file)
2457 function rg_tmp_path($name, $timeout_in_minutes)
2380 2458 { {
2381 2459 global $rg_state_dir; global $rg_state_dir;
2382 2460
2383 return $rg_state_dir . '/tmp/' . $file;
2461 $p = $rg_state_dir . '/tmp/' . $name;
2462 if ($timeout_in_minutes > 0)
2463 @file_put_contents($p . '.meta', time() + $timeout_in_minutes * 60);
2464
2465 return $p;
2384 2466 } }
2385 2467
2386 2468 /* /*
 
... ... function rg_gzencode($c, &$orig_len, &$comp_len)
2735 2817 /* /*
2736 2818 * Output data to client * Output data to client
2737 2819 */ */
2738 function rg_web_output($c)
2820 function rg_web_output($c, $disable)
2739 2821 { {
2740 $acc = @$_SERVER['HTTP_ACCEPT_ENCODING'];
2741 if (stristr($acc, 'gzip')) {
2742 $c = rg_gzencode($c, $orig_len, $comp_len);
2743 header('Content-Encoding: gzip');
2744 header('Content-Length: ' . $comp_len);
2822 $comp_len = 0;
2823
2824 if ($disable === FALSE) {
2825 $acc = @$_SERVER['HTTP_ACCEPT_ENCODING'];
2826 if (stristr($acc, 'gzip')) {
2827 $c = rg_gzencode($c, $orig_len, $comp_len);
2828 header('Content-Encoding: gzip');
2829 header('Content-Length: ' . $comp_len);
2830 }
2745 2831 } }
2746 2832
2833 if ($comp_len == 0)
2834 $comp_len = strlen($c);
2835
2747 2836 echo $c; echo $c;
2837
2838 return $comp_len;
2748 2839 } }
2749 2840
2750 2841 /* /*
 
... ... function rg_array_flat($prefix, $a)
2793 2884 */ */
2794 2885 function rg_array_top($a, $nr) function rg_array_top($a, $nr)
2795 2886 { {
2887 if ($nr == 0)
2888 return $a;
2889
2796 2890 $ret = array(); $ret = array();
2797 2891 $i = 0; $i = 0;
2798 2892 foreach ($a as $k => $v) { foreach ($a as $k => $v) {
 
... ... function rg_save($file, $a)
2817 2911
2818 2912 $r = @rename($file . '.tmp', $file); $r = @rename($file . '.tmp', $file);
2819 2913 if ($r === FALSE) { if ($r === FALSE) {
2914 @unlink($file . '.tmp');
2820 2915 rg_internal_error('Cannot rename: ' . rg_php_err()); rg_internal_error('Cannot rename: ' . rg_php_err());
2821 2916 return FALSE; return FALSE;
2822 2917 } }
 
... ... function rg_save($file, $a)
2830 2925 function rg_is_bot($ua) function rg_is_bot($ua)
2831 2926 { {
2832 2927 if (empty($ua)) return FALSE; if (empty($ua)) return FALSE;
2928 if (strstr($ua, ' Adsbot/')) return TRUE;
2833 2929 if (strstr($ua, ' AhrefsBot')) return TRUE; if (strstr($ua, ' AhrefsBot')) return TRUE;
2930 if (strstr($ua, ' aiHitBot/')) return TRUE;
2834 2931 if (strstr($ua, 'Applebot/')) return TRUE; if (strstr($ua, 'Applebot/')) return TRUE;
2835 if (strcmp($ua, 'AWeb') == 0) return TRUE;
2932 if (strstr($ua, 'AWeb')) return TRUE;
2933 if (strstr($ua, ' Babya Discoverer ')) return TRUE;
2934 if (strstr($ua, ' Baiduspider/')) return TRUE;
2935 if (strstr($ua, ' Barkrowler/')) return TRUE;
2836 2936 if (strstr($ua, 'BananaBot/')) return TRUE; if (strstr($ua, 'BananaBot/')) return TRUE;
2837 2937 if (strstr($ua, ' bingbot')) return TRUE; if (strstr($ua, ' bingbot')) return TRUE;
2838 2938 if (strstr($ua, ' BLEXBot/')) return TRUE; if (strstr($ua, ' BLEXBot/')) return TRUE;
2839 2939 if (strstr($ua, 'CATExplorador')) return TRUE; if (strstr($ua, 'CATExplorador')) return TRUE;
2840 if (strncmp($ua, 'CCBot/', 6) == 0) return TRUE;
2940 if (strstr($ua, 'CCBot/')) return TRUE;
2941 if (strstr($ua, ' CensysInspect/')) return TRUE;
2841 2942 if (strstr($ua, 'CISPA Webcrawler ')) return TRUE; if (strstr($ua, 'CISPA Webcrawler ')) return TRUE;
2943 if (strstr($ua, 'clark-Crowler2/')) return TRUE;
2842 2944 if (strstr($ua, ' Cliqzbot/')) return TRUE; if (strstr($ua, ' Cliqzbot/')) return TRUE;
2843 2945 if (strstr($ua, ' coccocbot-web')) return TRUE; if (strstr($ua, ' coccocbot-web')) return TRUE;
2844 2946 if (strstr($ua, 'dcrawl/')) return TRUE; if (strstr($ua, 'dcrawl/')) return TRUE;
 
... ... function rg_is_bot($ua)
2852 2954 if (strstr($ua, 'GarlikCrawler/')) return TRUE; if (strstr($ua, 'GarlikCrawler/')) return TRUE;
2853 2955 if (strstr($ua, 'Gigabot ')) return TRUE; if (strstr($ua, 'Gigabot ')) return TRUE;
2854 2956 if (strstr($ua, ' Googlebot')) return TRUE; if (strstr($ua, ' Googlebot')) return TRUE;
2855 if (strcmp($ua, 'googlebot') == 0) return TRUE;
2957 if (strstr($ua, 'googlebot')) return TRUE;
2856 2958 if (strstr($ua, 'Googlebot-Image/')) return TRUE; if (strstr($ua, 'Googlebot-Image/')) return TRUE;
2857 if (strcmp($ua, 'Googlebot-News') == 0) return TRUE;
2959 if (strstr($ua, 'Googlebot-News')) return TRUE;
2858 2960 if (strstr($ua, 'Googlebot-Video/')) return TRUE; if (strstr($ua, 'Googlebot-Video/')) return TRUE;
2859 2961 if (strstr($ua, 'GoScraper')) return TRUE; if (strstr($ua, 'GoScraper')) return TRUE;
2860 2962 if (strstr($ua, 'ichiro/')) return TRUE; if (strstr($ua, 'ichiro/')) return TRUE;
2861 if (strcmp($ua, 'Internet-structure-research-project-bot') == 0) return TRUE;
2963 if (strstr($ua, 'Internet-structure-research-project-bot')) return TRUE;
2862 2964 if (strstr($ua, 'Lawinsiderbot/')) return TRUE; if (strstr($ua, 'Lawinsiderbot/')) return TRUE;
2863 2965 if (strstr($ua, 'LightspeedSystemsCrawler')) return TRUE; if (strstr($ua, 'LightspeedSystemsCrawler')) return TRUE;
2966 if (strstr($ua, ' Linguee Bot ')) return TRUE;
2864 2967 if (strstr($ua, 'ltx71 ')) return TRUE; if (strstr($ua, 'ltx71 ')) return TRUE;
2968 if (strstr($ua, ' MaCoCu;')) return TRUE;
2865 2969 if (strstr($ua, ' Mail.RU_Bot')) return TRUE; if (strstr($ua, ' Mail.RU_Bot')) return TRUE;
2970 if (strstr($ua, ' MauiBot ')) return TRUE;
2971 if (strstr($ua, ' MegaIndex.ru/')) return TRUE;
2866 2972 if (strstr($ua, ' MJ12bot')) return TRUE; if (strstr($ua, ' MJ12bot')) return TRUE;
2867 2973 if (strstr($ua, ' MojeekBot')) return TRUE; if (strstr($ua, ' MojeekBot')) return TRUE;
2868 2974 if (strstr($ua, 'msnbot-media/')) return TRUE; if (strstr($ua, 'msnbot-media/')) return TRUE;
2975 if (strstr($ua, ' MTRobot/')) return TRUE;
2976 if (strstr($ua, ' NetcraftSurveyAgent/')) return TRUE;
2869 2977 if (strstr($ua, 'NewsGator FetchLinks extension/')) return TRUE; if (strstr($ua, 'NewsGator FetchLinks extension/')) return TRUE;
2978 if (strstr($ua, 'netEstate NE Crawler ')) return TRUE;
2979 if (strstr($ua, 'nu.marginalia.wmsa.edge-crawler')) return TRUE;
2980 if (strstr($ua, 'OpenSearch@MPDL ')) return TRUE;
2981 if (strstr($ua, ' PageThing ')) return TRUE;
2870 2982 if (strstr($ua, 'PageThing.com')) return TRUE; if (strstr($ua, 'PageThing.com')) return TRUE;
2871 2983 if (strstr($ua, 'Pandalytics')) return TRUE; if (strstr($ua, 'Pandalytics')) return TRUE;
2872 2984 if (strstr($ua, 'panscient.com')) return TRUE; if (strstr($ua, 'panscient.com')) return TRUE;
2873 2985 if (strstr($ua, ' PetalBot')) return TRUE; if (strstr($ua, ' PetalBot')) return TRUE;
2874 2986 if (strstr($ua, 'pimeyes.com crawler')) return TRUE; if (strstr($ua, 'pimeyes.com crawler')) return TRUE;
2987 if (strstr($ua, ' proximic;')) return TRUE;
2988 if (strstr($ua, 'Re-re Studio ')) return TRUE;
2875 2989 if (strstr($ua, 'Robot Terminator ')) return TRUE; if (strstr($ua, 'Robot Terminator ')) return TRUE;
2876 2990 if (strstr($ua, 'rpmlint/')) return TRUE; if (strstr($ua, 'rpmlint/')) return TRUE;
2877 2991 if (strstr($ua, 'SaaSHub')) return TRUE; if (strstr($ua, 'SaaSHub')) return TRUE;
2992 if (strstr($ua, ' SemanticScholarBot')) return TRUE;
2878 2993 if (strstr($ua, 'Screaming Frog SEO Spider')) return TRUE; if (strstr($ua, 'Screaming Frog SEO Spider')) return TRUE;
2879 if (strcmp($ua, 'SemrushBot') == 0) return TRUE;
2994 if (strstr($ua, ' Seekport Crawler')) return TRUE;
2995 if (strstr($ua, ' SemrushBot')) return TRUE;
2996 if (strstr($ua, ' SEOkicks;')) return TRUE;
2997 if (strstr($ua, 'serpstatbot/')) return TRUE;
2880 2998 if (strstr($ua, ' SeznamBot')) return TRUE; if (strstr($ua, ' SeznamBot')) return TRUE;
2881 if (strcmp($ua, 'Sidetrade indexer bot') == 0) return TRUE;
2999 if (strstr($ua, 'Sidetrade indexer bot')) return TRUE;
2882 3000 if (strstr($ua, 'Slackbot-LinkExpanding ')) return TRUE; if (strstr($ua, 'Slackbot-LinkExpanding ')) return TRUE;
2883 3001 if (strstr($ua, 'Sogou web spider')) return TRUE; if (strstr($ua, 'Sogou web spider')) return TRUE;
2884 3002 if (strstr($ua, 'TelegramBot ')) return TRUE; if (strstr($ua, 'TelegramBot ')) return TRUE;
 
... ... function rg_is_bot($ua)
2886 3004 if (strstr($ua, 'TprAdsTxtCrawler')) return TRUE; if (strstr($ua, 'TprAdsTxtCrawler')) return TRUE;
2887 3005 if (strstr($ua, 'TurnitinBot ')) return TRUE; if (strstr($ua, 'TurnitinBot ')) return TRUE;
2888 3006 if (strstr($ua, 'Twitterbot/')) return TRUE; if (strstr($ua, 'Twitterbot/')) return TRUE;
3007 if (strstr($ua, ' VelenPublicWebCrawler/')) return TRUE;
2889 3008 if (strstr($ua, 'Wappalyzer')) return TRUE; if (strstr($ua, 'Wappalyzer')) return TRUE;
2890 3009 if (strstr($ua, ' webtechbot;')) return TRUE; if (strstr($ua, ' webtechbot;')) return TRUE;
3010 if (strstr($ua, 'http://webmeup-crawler.com/')) return TRUE;
2891 3011 if (strstr($ua, 'Xenu Link Sleuth/')) return TRUE; if (strstr($ua, 'Xenu Link Sleuth/')) return TRUE;
2892 if (strcmp($ua, 'XYZ Spider') == 0) return TRUE;
2893 if (strncmp($ua, 'yacybot ', 8) == 0) return TRUE;
2894 if (strstr($ua, ' YandexBot')) return TRUE;
2895 if (strcmp($ua, ' YisouSpider') == 0) return TRUE;
3012 if (strstr($ua, 'XYZ Spider')) return TRUE;
3013 if (strstr($ua, 'yacybot ')) return TRUE;
3014 if (strstr($ua, '/yacy.net/')) return TRUE;
3015 if (strstr($ua, ' YandexBot/')) return TRUE;
3016 if (strstr($ua, ' YandexImages/')) return TRUE;
3017 if (strstr($ua, ' YisouSpider')) return TRUE;
2896 3018 if (strstr($ua, 'ZoomBot ')) return TRUE; if (strstr($ua, 'ZoomBot ')) return TRUE;
3019 if (strstr($ua, 'ZoominfoBot ')) return TRUE;
2897 3020
2898 3021 return FALSE; return FALSE;
2899 3022 } }
 
... ... function rg_path2url($path)
2938 3061 } }
2939 3062
2940 3063 /* /*
2941 * Check if a file is inside a directory and return 'stat' info if TRUE
3064 * Check if a file (relative to @root) is inside a directory and return
3065 * 'stat' info if TRUE.
2942 3066 */ */
2943 3067 function rg_path_validate($root, $path) function rg_path_validate($root, $path)
2944 3068 { {
2945 $last = substr($root, -1);
2946 if (strcmp($last, '/') != 0)
2947 $root .= '/';
3069 rg_log_enter('path_validate root=' . $root . ' path=' . $path);
2948 3070
2949 $ret = array();
2950 $ret['realpath'] = @realpath($root . $path);
2951 if ($ret['realpath'] === FALSE) {
2952 rg_util_set_error('path ' . $root . $path . ' does not exists');
2953 return FALSE;
2954 }
3071 $ret = FALSE;
3072 do {
3073 $last = substr($root, -1);
3074 if (strcmp($last, '/') != 0)
3075 $root .= '/';
3076
3077 $a = array();
3078 $a['realpath'] = @realpath($root . $path);
3079 if ($a['realpath'] === FALSE) {
3080 rg_util_set_error('path ' . $root . $path . ' does not exists');
3081 break;
3082 }
2955 3083
2956 if (strncmp($ret['realpath'], $root, strlen($root)) != 0) {
2957 rg_util_set_error('path ' . $path . ' is trying to escape root ' . $root);
2958 return FALSE;
2959 }
3084 if (strncmp($a['realpath'], $root, strlen($root)) != 0) {
3085 rg_util_set_error('path [' . $path . '] is trying to escape'
3086 . ' root [' . $root . ']');
3087 break;
3088 }
2960 3089
2961 $ret['stat'] = @stat($ret['realpath']);
2962 if ($ret['stat'] === FALSE) {
2963 rg_util_set_error('cannot stat ' . $ret['realpath']
2964 . ': ' . rg_php_err());
2965 return FALSE;
2966 }
3090 $a['stat'] = @stat($a['realpath']);
3091 if ($a['stat'] === FALSE) {
3092 rg_util_set_error('cannot stat ' . $a['realpath']
3093 . ': ' . rg_php_err());
3094 break;
3095 }
2967 3096
3097 $ret = $a;
3098 } while (0);
3099
3100 rg_log_exit();
2968 3101 return $ret; return $ret;
2969 3102 } }
2970 3103
 
... ... function rg_dir_size($dir)
3135 3268 return $ret; return $ret;
3136 3269 } }
3137 3270
3271 /*
3272 * Creates all needed directories in a path to a file (NOT a dir)
3273 */
3274 function rg_create_dirs($path)
3275 {
3276 $ret = array('ok' => 0);
3277 do {
3278 $d = dirname($path);
3279 if (strcmp($d, '/') == 0) {
3280 $ret['ok'] = 1;
3281 break;
3282 }
3283
3284 if (strcmp($d, '.') != 0) {
3285 // Try to create the parent
3286 $ret = rg_create_dirs($d);
3287 if ($ret['ok'] != 1)
3288 break;
3289 }
3290
3291 $r = @stat($d);
3292 if ($r !== FALSE) {
3293 $ret['ok'] = 1;
3294 break;
3295 }
3296
3297 $r = @mkdir($d, 0700);
3298 if ($r === FALSE) {
3299 $ret['errmsg'] = rg_php_err();
3300 break;
3301 }
3302
3303 $ret['ok'] = 1;
3304 } while (0);
3305
3306 return $ret;
3307 }
3308
3309 $_ip = '';
3310 function rg_ip_set($ip)
3311 {
3312 global $_ip;
3313
3314 $_ip = rg_fix_ip($ip);
3315 }
3316
3317 function rg_ip()
3318 {
3319 global $_ip;
3320
3321 return $_ip;
3322 }
3323
3324 $_t = @file_get_contents('/home/rocketgit/rg_debug');
3325 $rg_debug = ($_t !== FALSE) ? intval($_t) : 0;
3326 function rg_debug_set($level)
3327 {
3328 global $rg_debug;
3329
3330 $rg_debug |= intval($level);
3331 rg_log('DEBUG: rg_debug set to ' . $rg_debug);
3332 }
3333
3334 function rg_debug()
3335 {
3336 global $rg_debug;
3337
3338 return $rg_debug;
3339 }
3340
3341 $rg_debug_html = array();
3342 function rg_debug_html_set($k, $v)
3343 {
3344 global $rg_debug_html;
3345
3346 //rg_log_debug('rg_debug_html_set called [' . $k . '] [' . rg_array2string($v) . ']');
3347 $rg_debug_html[$k] = $v;
3348 }
3349
3350 /* Functions for template system */
3351 function rg_debug_html($junk)
3352 {
3353 global $rg_debug_html;
3354
3355 if (rg_debug() == 0)
3356 return '';
3357
3358 $ret = array(
3359 'html' => 1, // not really html
3360 'value' => '<!-- --rg_debug_html-- '
3361 . json_encode($rg_debug_html)
3362 . ' --rg_debug_html-- -->'
3363 );
3364
3365 return $ret;
3366 }
3367 rg_template_func('RG_DEBUG_HTML', 'rg_debug_html');
File inc/watch.inc.php changed (mode: 100644) (index e131cc7..4afbfea)
... ... function rg_watch_del($db, $type, $login_uid, $obj_id1, $obj_id2)
153 153 if ($r === FALSE) if ($r === FALSE)
154 154 break; break;
155 155 if ($r === 0) { // already deleted if ($r === 0) { // already deleted
156 rg_log('DEBUG: watch not active, nothing to do');
156 rg_log_debug('watch not active, nothing to do');
157 157 $ret = TRUE; $ret = TRUE;
158 158 break; break;
159 159 } }
 
... ... function rg_watch_hl_process($db, &$rg, $type, $obj_id1, $obj_id2, $url)
259 259 $rg['HTML:watch_error'] = ''; $rg['HTML:watch_error'] = '';
260 260 while (1) { while (1) {
261 261 // If user is not logged in, we cannot add a watch // If user is not logged in, we cannot add a watch
262 if ($rg['login_ui']['uid'] == 0) {
262 $ui_login = rg_ui_login();
263 if ($ui_login['uid'] == 0) {
263 264 $ret = TRUE; $ret = TRUE;
264 265 break; break;
265 266 } }
266 267
267 268 // The owner is already watching his repos // The owner is already watching his repos
268 if ($rg['login_ui']['uid'] == $rg['page_ui']['uid']) {
269 $ui_page = rg_ui_page();
270 if ($ui_login['uid'] == $ui_page['uid']) {
269 271 $ret = TRUE; $ret = TRUE;
270 272 break; break;
271 273 } }
272 274
273 $watch = rg_watch_load($db, $type, $rg['login_ui']['uid'],
275 $watch = rg_watch_load($db, $type, $ui_login['uid'],
274 276 $obj_id1, $obj_id2); $obj_id1, $obj_id2);
275 277 if ($watch === FALSE) if ($watch === FALSE)
276 278 break; break;
 
... ... function rg_watch_hl_process($db, &$rg, $type, $obj_id1, $obj_id2, $url)
299 301 $next_value = 1 - $watch; $next_value = 1 - $watch;
300 302 } }
301 303
302 rg_log('DEBUG: watch=' . $watch . ' next_value=' . $next_value);
304 rg_log_debug('watch=' . $watch . ' next_value=' . $next_value);
303 305 $rg['watch'] = array( $rg['watch'] = array(
304 306 'type' => $type, 'type' => $type,
305 307 'url' => $url, 'url' => $url,
 
... ... function rg_watch_hl_process($db, &$rg, $type, $obj_id1, $obj_id2, $url)
315 317 } }
316 318
317 319 if ($watch == 0) if ($watch == 0)
318 $r = rg_watch_add($db, $type, $rg['login_ui']['uid'],
320 $r = rg_watch_add($db, $type, $ui_login['uid'],
319 321 $obj_id1, $obj_id2); $obj_id1, $obj_id2);
320 322 else else
321 $r = rg_watch_del($db, $type, $rg['login_ui']['uid'],
323 $r = rg_watch_del($db, $type, $ui_login['uid'],
322 324 $obj_id1, $obj_id2); $obj_id1, $obj_id2);
323 325 if ($r === FALSE) if ($r === FALSE)
324 326 break; break;
File inc/wh/amazon.inc.php changed (mode: 100644) (index 0c19f40..5c225a6)
... ... function rg_amazon_auth($a)
40 40 $qs = ''; $qs = '';
41 41 } }
42 42
43 rg_log('DEBUG: ret[query_string]=' . $ret['query_string']);
43 rg_log_debug('ret[query_string]=' . $ret['query_string']);
44 44
45 45 if (!empty($a['content'])) { if (!empty($a['content'])) {
46 46 $a['x-amz-content-sha256'] = hash('sha256', $a['content'], TRUE); $a['x-amz-content-sha256'] = hash('sha256', $a['content'], TRUE);
47 rg_log('DEBUG: a[content] is set to: ' . $a['content']);
47 rg_log_debug('a[content] is set to: ' . $a['content']);
48 48 $a['iheaders']['x-amz-content-sha256'] = $a['iheaders']['x-amz-content-sha256'] =
49 49 bin2hex($a['x-amz-content-sha256']); bin2hex($a['x-amz-content-sha256']);
50 50 } else { } else {
51 51 $a['x-amz-content-sha256'] = hash('sha256', $a['x-amz-content-sha256'] = hash('sha256',
52 52 $ret['query_string'], TRUE); $ret['query_string'], TRUE);
53 rg_log('DEBUG: a[content] is not set');
53 rg_log_debug('a[content] is not set');
54 54 } }
55 rg_log_ml('DEBUG: a[iheaders]: ' . rg_array2string($a['iheaders']));
55 rg_log_debug('a[iheaders]: ' . rg_array2string($a['iheaders']));
56 56
57 57 $iheaders_final = array(); $iheaders_final = array();
58 58 $iheaders_list = array(); $iheaders_list = array();
 
... ... function rg_amazon_auth($a)
74 74 . $iheaders_final . $iheaders_final
75 75 . $iheaders_list . "\n" . $iheaders_list . "\n"
76 76 . bin2hex($a['x-amz-content-sha256']); . bin2hex($a['x-amz-content-sha256']);
77 rg_log_ml('DEBUG: canonical_request:' . "\n" . $canonical_request
77 rg_log_debug('canonical_request:' . "\n" . $canonical_request
78 78 . "\n" . '==='); . "\n" . '===');
79 79
80 80 $string_to_sign = 'AWS4-HMAC-SHA256' . "\n" $string_to_sign = 'AWS4-HMAC-SHA256' . "\n"
 
... ... function rg_amazon_auth($a)
88 88 rg_log_ml('string_to_sign:' . "\n" . $string_to_sign rg_log_ml('string_to_sign:' . "\n" . $string_to_sign
89 89 . "\n" . '==='); . "\n" . '===');
90 90
91 rg_log('DEBUG: secret_access_key=' . $a['secret_access_key'] . '.');
91 rg_log_debug('secret_access_key=' . $a['secret_access_key'] . '.');
92 92 $date_key = hash_hmac('sha256', gmdate('Ymd', $a['ts']), $date_key = hash_hmac('sha256', gmdate('Ymd', $a['ts']),
93 93 'AWS4' . $a['secret_access_key'], TRUE); 'AWS4' . $a['secret_access_key'], TRUE);
94 rg_log('DEBUG: date_key=' . bin2hex($date_key));
94 rg_log_debug('date_key=' . bin2hex($date_key));
95 95 $date_region_key = hash_hmac('sha256', $a['region'], $date_region_key = hash_hmac('sha256', $a['region'],
96 96 $date_key, TRUE); $date_key, TRUE);
97 rg_log('DEBUG: date_region_key=' . bin2hex($date_region_key));
97 rg_log_debug('date_region_key=' . bin2hex($date_region_key));
98 98 $date_region_service_key = hash_hmac('sha256', $date_region_service_key = hash_hmac('sha256',
99 99 $service, $date_region_key, TRUE); $service, $date_region_key, TRUE);
100 rg_log('DEBUG: service=' . $service . ' date_region_service_key=' . bin2hex($date_region_service_key));
100 rg_log_debug('service=' . $service . ' date_region_service_key=' . bin2hex($date_region_service_key));
101 101 $signing_key = hash_hmac('sha256', 'aws4_request', $signing_key = hash_hmac('sha256', 'aws4_request',
102 102 $date_region_service_key, TRUE); $date_region_service_key, TRUE);
103 rg_log('DEBUG: signing_key=' . bin2hex($signing_key));
103 rg_log_debug('signing_key=' . bin2hex($signing_key));
104 104 $signature = hash_hmac('sha256', $string_to_sign, $signing_key); $signature = hash_hmac('sha256', $string_to_sign, $signing_key);
105 rg_log('DEBUG: signature=' . $signature);
105 rg_log_debug('signature=' . $signature);
106 106
107 107 $cred = $a['access_key_id'] $cred = $a['access_key_id']
108 108 . '/' . gmdate('Ymd', $a['ts']) . '/' . gmdate('Ymd', $a['ts'])
 
... ... function rg_amazon_curl($url, $method, $headers, $data)
166 166 curl_setopt($c, CURLOPT_STDERR, $err); curl_setopt($c, CURLOPT_STDERR, $err);
167 167
168 168 $r = curl_exec($c); $r = curl_exec($c);
169 rg_log_ml('DEBUG: curl_exec returned: ' . $r);
169 rg_log_debug('curl_exec returned: ' . $r);
170 170
171 171 if ($err !== FALSE) { if ($err !== FALSE) {
172 172 rewind($err); rewind($err);
173 173 $xerr = @fread($err, 16 * 4096); $xerr = @fread($err, 16 * 4096);
174 174 fclose($err); fclose($err);
175 175 $ret['debug'] = $xerr; $ret['debug'] = $xerr;
176 rg_log_ml('DEBUG: xerr=' . "\n" . $xerr);
176 rg_log_debug('xerr=' . "\n" . $xerr);
177 177 } }
178 178
179 179 if ($r === FALSE) { if ($r === FALSE) {
180 180 $ret['errmsg'] = curl_error($c); $ret['errmsg'] = curl_error($c);
181 181
182 182 $_info = curl_getinfo($c); $_info = curl_getinfo($c);
183 rg_log_ml('Debug: ' . rg_array2string($_info));
183 rg_log_debug('_info: ' . rg_array2string($_info));
184 184 break; break;
185 185 } }
186 186
187 187 $_info = curl_getinfo($c); $_info = curl_getinfo($c);
188 rg_log_ml('Debug: ' . rg_array2string($_info));
188 rg_log_debug('_info: ' . rg_array2string($_info));
189 189
190 190 if (($_info['http_code'] != 200) if (($_info['http_code'] != 200)
191 191 && ($_info['http_code'] != 301)) { && ($_info['http_code'] != 301)) {
 
... ... function rg_amazon_req($a)
209 209 { {
210 210 rg_prof_start('amazon_req'); rg_prof_start('amazon_req');
211 211 rg_log_enter('amazon_req'); rg_log_enter('amazon_req');
212 rg_log_ml('DEBUG: a:' . rg_array2string($a));
212 rg_log_debug('a:' . rg_array2string($a));
213 213
214 214 $ret = array('ok' => 0); $ret = array('ok' => 0);
215 215 while (1) { while (1) {
 
... ... function rg_amazon_req($a)
248 248 $headers[] = 'Authorization: ' . $auth['data']; $headers[] = 'Authorization: ' . $auth['data'];
249 249 foreach ($auth['iheaders'] as $head => $val) foreach ($auth['iheaders'] as $head => $val)
250 250 $headers[] = $head . ': ' . $val; $headers[] = $head . ': ' . $val;
251 rg_log_ml('DEBUG: HEADERS:' . rg_array2string($headers));
251 rg_log_debug('HEADERS:' . rg_array2string($headers));
252 252
253 253 $ret = rg_amazon_curl($url, $a['method'], $headers, $ret = rg_amazon_curl($url, $a['method'], $headers,
254 254 $a['content']); $a['content']);
File inc/wh/cloud.inc.php changed (mode: 100644) (index 32cbc4f..03fa943)
... ... function rg_wh_cloud_send_one($db, $ev)
24 24 $wh = &$ev['wh']; $wh = &$ev['wh'];
25 25
26 26 $xid = rg_id(8); $xid = rg_id(8);
27 $f = 'wh-' . $ev['ui']['uid'] . '-' . $wh['id'] . '-' . $xid . '.zip';
28 $path = rg_tmp_path($f);
27 $f = 'wh-' . $ev['ui_login']['uid'] . '-' . $wh['id']
28 . '-' . $xid . '.zip';
29 $path = rg_tmp_path($f, 120);
29 30
30 31 $last_output = ''; $last_output = '';
31 32 while (1) { while (1) {
 
... ... function rg_wh_cloud_send_one($db, $ev)
76 77 } }
77 78 @unlink($path); @unlink($path);
78 79
79 rg_wh_set_last_output($db, $ev['ui']['uid'], $wh['id'],
80 rg_wh_set_last_output($db, $ev['ui_login']['uid'], $wh['id'],
80 81 substr($last_output, 0, 4096)); substr($last_output, 0, 4096));
81 82
82 if ($ev['debug'] == 1)
83 rg_cache_set('DEBUG::' . $ev['ui']['uid']
84 . '::webhooks::' . $wh['id'], $last_output,
85 RG_SOCKET_NO_WAIT);
83 if (rg_debug()) {
84 $k = 'DEBUG::' . $ev['ui_login']['uid']
85 . '::webhooks::' . $wh['id'];
86 rg_log_debug('setting key [' . $k . '] to ' . $last_output);
87 rg_cache_set($k, $last_output, RG_SOCKET_NO_WAIT);
88 }
86 89
87 90 rg_prof_end('wh_cloud_send_one'); rg_prof_end('wh_cloud_send_one');
88 91 return $ret; return $ret;
 
... ... function rg_wh_cloud_send($db, $ev)
99 102 $ret = array(); $ret = array();
100 103
101 104 // First, get the list of hooks // First, get the list of hooks
102 $r = rg_wh_list($db, $ev['ui']['uid']);
105 $r = rg_wh_list($db, $ev['ui_login']['uid']);
103 106 if ($r['ok'] != 1) if ($r['ok'] != 1)
104 107 return FALSE; return FALSE;
105 108
 
... ... function rg_wh_cloud_send($db, $ev)
109 112 continue; continue;
110 113
111 114 if (strchr($wh['flags'], 'D')) { if (strchr($wh['flags'], 'D')) {
112 rg_log('DEBUG: hook is disabled');
115 rg_log_debug('hook is disabled');
113 116 continue; continue;
114 117 } }
115 118
116 119 // If the web hook does not contain our type, skip it // If the web hook does not contain our type, skip it
117 120 if (!strchr($wh['idata']['events'], $ev['wh_event'])) { if (!strchr($wh['idata']['events'], $ev['wh_event'])) {
118 rg_log('DEBUG: ' . $ev['wh_event']
121 rg_log_debug('' . $ev['wh_event']
119 122 . ' is not present in [' . ' is not present in ['
120 123 . $wh['idata']['events'] . ']'); . $wh['idata']['events'] . ']');
121 124 continue; continue;
File inc/wh/core.inc.php changed (mode: 100644) (index 0aa85b5..af2dfb7)
... ... function rg_wh_cosmetic(&$list)
131 131 { {
132 132 global $rg_wh_plugins; global $rg_wh_plugins;
133 133
134 rg_log('DEBUG: rg_wh_cosmetic');
134 rg_log_debug('rg_wh_cosmetic');
135 135
136 136 foreach ($list as $id => &$row) { foreach ($list as $id => &$row) {
137 137 $type = $row['htype']; $type = $row['htype'];
 
... ... function rg_wh_list($db, $uid)
254 254 } }
255 255
256 256 while (($row = rg_sql_fetch_array($res))) { while (($row = rg_sql_fetch_array($res))) {
257 //rg_log_ml('DEBUG: wh_list: row: ' . rg_array2string($row));
257 //rg_log_debug('wh_list: row: ' . rg_array2string($row));
258 258 $id = $row['id']; $id = $row['id'];
259 259 if (!empty($row['idata'])) { if (!empty($row['idata'])) {
260 260 $row['idata'] = rg_unserialize($row['idata']); $row['idata'] = rg_unserialize($row['idata']);
 
... ... function rg_wh_add($db, $uid, $data)
343 343 . '::' . $data['id']; . '::' . $data['id'];
344 344 rg_cache_merge($key, $data, RG_SOCKET_NO_WAIT); rg_cache_merge($key, $data, RG_SOCKET_NO_WAIT);
345 345
346 rg_debug_html_set('wh', $data);
347
346 348 $ret['ok'] = 1; $ret['ok'] = 1;
347 349 break; break;
348 350 } }
 
... ... function rg_wh_fill_vars(&$rg)
414 416 $rg['wh']['flags'] = rg_var_a2s('wh::flags'); $rg['wh']['flags'] = rg_var_a2s('wh::flags');
415 417 $rg['wh']['refname'] = rg_var_str('wh::refname'); $rg['wh']['refname'] = rg_var_str('wh::refname');
416 418 $rg['wh']['itime'] = time(); $rg['wh']['itime'] = time();
417 $rg['wh']['add_ip'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
419 $rg['wh']['add_ip'] = rg_ip();
418 420 $rg['wh']['description'] = trim(rg_var_str('wh::description')); $rg['wh']['description'] = trim(rg_var_str('wh::description'));
419 421 $rg['wh']['idata'] = array(); $rg['wh']['idata'] = array();
420 422
 
... ... function rg_wh_add_form($db, &$rg)
507 509 { {
508 510 global $rg_wh_plugins; global $rg_wh_plugins;
509 511
510 rg_log('DEBUG: wh_add_form');
512 rg_log_debug('wh_add_form');
511 513 while (1) { while (1) {
512 514 $type = $rg['wh']['htype']; $type = $rg['wh']['htype'];
513 515
 
... ... function rg_wh_add_form($db, &$rg)
532 534 break; break;
533 535 } }
534 536
535 rg_log_ml('DEBUG: AFTER wh_add_form: wh[idata]: '
537 rg_log_debug('AFTER wh_add_form: wh[idata]: '
536 538 . rg_array2string($rg['wh']['idata'])); . rg_array2string($rg['wh']['idata']));
537 539 } }
538 540
 
... ... function rg_wh_replace_tags(&$ev)
633 635 //rg_log_ml('wh_replace_tags: ev=' . rg_array2string($ev)); //rg_log_ml('wh_replace_tags: ev=' . rg_array2string($ev));
634 636
635 637 $branch = isset($ev['refname']) ? rg_repo_ref_nice($ev['refname']) : ''; $branch = isset($ev['refname']) ? rg_repo_ref_nice($ev['refname']) : '';
636 //rg_log('DEBUG: branch=' . $branch);
638 //rg_log_debug('branch=' . $branch);
637 639 $repo_name = isset($ev['ri']['name']) ? $ev['ri']['name'] : ''; $repo_name = isset($ev['ri']['name']) ? $ev['ri']['name'] : '';
638 640 $new_rev = isset($ev['new_rev']) ? $ev['new_rev'] : ''; $new_rev = isset($ev['new_rev']) ? $ev['new_rev'] : '';
639 641
 
... ... function rg_wh_call_callback($type, $subtype, $cb, &$xret, &$para1, &$para2)
742 744 break; break;
743 745
744 746 $pt = $rg_wh_plugins[$type]; $pt = $rg_wh_plugins[$type];
745 //rg_log_ml('DEBUG: pt: ' . rg_array2string($pt));
747 //rg_log_debug('pt: ' . rg_array2string($pt));
746 748 if (isset($pt['cb'][$cb])) { if (isset($pt['cb'][$cb])) {
747 rg_log('DEBUG: calling type callback ' . $cb);
749 rg_log_debug('calling type callback ' . $cb);
748 750 $xret = $pt['cb'][$cb]($para1, $para2); $xret = $pt['cb'][$cb]($para1, $para2);
749 751 $ret = TRUE; $ret = TRUE;
750 752 } else { } else {
751 rg_log('DEBUG: type cb [' . $cb . '] not defined!');
753 rg_log_debug('type cb [' . $cb . '] not defined!');
752 754 } }
753 755
754 756 $si = rg_wh_find_subtype($type, $subtype); $si = rg_wh_find_subtype($type, $subtype);
755 //rg_log_ml('DEBUG: si: ' . rg_array2string($si));
757 //rg_log_debug('si: ' . rg_array2string($si));
756 758 if ($si === FALSE) if ($si === FALSE)
757 759 break; break;
758 760
759 761 if (!isset($si['cb'][$cb])) { if (!isset($si['cb'][$cb])) {
760 rg_log('DEBUG: subtype cb ' . $cb . ' is not defined!');
762 rg_log_debug('subtype cb ' . $cb . ' is not defined!');
761 763 break; break;
762 764 } }
763 765
764 rg_log('DEBUG: calling subtype callback ' . $cb);
766 rg_log_debug('calling subtype callback ' . $cb);
765 767 $xret = $si['cb'][$cb]($para1, $para2); $xret = $si['cb'][$cb]($para1, $para2);
766 768 $ret = TRUE; $ret = TRUE;
767 769 break; break;
File inc/wh/http.inc.php changed (mode: 100644) (index 2464f5e..3ab9d4c)
... ... function rg_wh_http_send_helper($db, &$ev)
22 22 // replace ##tags## // replace ##tags##
23 23 rg_wh_replace_tags($ev); rg_wh_replace_tags($ev);
24 24
25 if ($ev['debug'] == 1)
26 rg_log_ml('wh_http_send_one: event[wh][idata]: '
25 rg_debug() && rg_log_ml('wh_http_send_one: event[wh][idata]: '
27 26 . rg_array2string($ev['wh']['idata'])); . rg_array2string($ev['wh']['idata']));
28 27
29 28 $headers = array(); $headers = array();
 
... ... function rg_wh_http_send_helper($db, &$ev)
67 66 $xid = rg_id(8); $xid = rg_id(8);
68 67
69 68 if (!empty($ev['wh']['idata']['client_cert'])) { if (!empty($ev['wh']['idata']['client_cert'])) {
70 rg_log('DEBUG: will provide client cert...');
71 $f = 'wh-' . $ev['ui']['uid'] . '-' . $ev['wh']['id'] . '-client-' . $xid;
69 rg_log_debug('will provide client cert...');
70 $f = 'wh-' . $ev['ui_login']['uid'] . '-' . $ev['wh']['id'] . '-client-' . $xid;
72 71 $cert_file = rg_tmp_file($f, $ev['wh']['idata']['client_cert']); $cert_file = rg_tmp_file($f, $ev['wh']['idata']['client_cert']);
73 72 if ($cert_file === FALSE) if ($cert_file === FALSE)
74 73 break; break;
75 74
76 75 curl_setopt($c, CURLOPT_SSLCERT, $cert_file); curl_setopt($c, CURLOPT_SSLCERT, $cert_file);
77 76 } else { } else {
78 rg_log('DEBUG: will NOT provide client cert...');
77 rg_log_debug('will NOT provide client cert...');
79 78 // TODO: Somehow, without next line, the cert is still sent! // TODO: Somehow, without next line, the cert is still sent!
80 79 // TODO: With next line, curl tries to find the empty file name // TODO: With next line, curl tries to find the empty file name
81 80 //curl_setopt($c, CURLOPT_SSLCERT, FALSE); //curl_setopt($c, CURLOPT_SSLCERT, FALSE);
 
... ... function rg_wh_http_send_helper($db, &$ev)
83 82 } }
84 83
85 84 if (!empty($ev['wh']['idata']['client_ca_cert'])) { if (!empty($ev['wh']['idata']['client_ca_cert'])) {
86 $f = 'wh-' . $ev['ui']['uid'] . '-' . $ev['wh']['id'] . '-ca-' . $xid;
85 $f = 'wh-' . $ev['ui_login']['uid'] . '-' . $ev['wh']['id'] . '-ca-' . $xid;
87 86 $ca_file = rg_tmp_file($f, $ev['wh']['idata']['client_ca_cert']); $ca_file = rg_tmp_file($f, $ev['wh']['idata']['client_ca_cert']);
88 87 if ($ca_file === FALSE) if ($ca_file === FALSE)
89 88 break; break;
 
... ... function rg_wh_http_send_helper($db, &$ev)
123 122 break; break;
124 123 } }
125 124
126 rg_log_ml('DEBUG: Answer: ' . rg_array2string($r));
125 rg_log_debug('Answer: ' . rg_array2string($r));
127 126 $xerr .= $r; $xerr .= $r;
128 127
129 128 $debug_value = 'OK'; $debug_value = 'OK';
 
... ... function rg_wh_http_send_helper($db, &$ev)
138 137 if ($ca_file !== FALSE) if ($ca_file !== FALSE)
139 138 @unlink($ca_file); @unlink($ca_file);
140 139
141 rg_wh_set_last_output($db, $ev['ui']['uid'], $ev['wh']['id'], $xerr);
140 rg_wh_set_last_output($db, $ev['ui_login']['uid'], $ev['wh']['id'], $xerr);
142 141
143 if ($ev['debug'] == 1)
144 rg_cache_set('DEBUG::' . $ev['ui']['uid']
142 if (rg_debug()) {
143 $k = 'DEBUG::' . $ev['ui_login']['uid']
145 144 . '::webhooks::' . $ev['wh']['idata']['opaque'] . '::webhooks::' . $ev['wh']['idata']['opaque']
146 . '::' . $ev['wh']['id'],
147 $debug_value, RG_SOCKET_NO_WAIT);
145 . '::' . $ev['wh']['id'];
146 rg_log_debug('setting key [' . $k . '] to ' . $debug_value);
147 rg_cache_set($k, $debug_value, RG_SOCKET_NO_WAIT);
148 }
148 149
149 150 rg_log_exit(); rg_log_exit();
150 151 rg_prof_end('wh_http_send_helper'); rg_prof_end('wh_http_send_helper');
 
... ... function rg_wh_http_send($db, $ev)
182 183 //rg_log_ml('wh_http_send: event: ' . rg_array2string($ev)); //rg_log_ml('wh_http_send: event: ' . rg_array2string($ev));
183 184
184 185 // First, get the list of hooks // First, get the list of hooks
185 $r = rg_wh_list($db, $ev['ui']['uid']);
186 $r = rg_wh_list($db, $ev['ui_login']['uid']);
186 187 if ($r['ok'] != 1) if ($r['ok'] != 1)
187 188 return FALSE; return FALSE;
188 189
 
... ... function rg_wh_http_send($db, $ev)
201 202
202 203 // If the web hook does not contain our type, skip it // If the web hook does not contain our type, skip it
203 204 if (!strchr($wh['idata']['events'], $ev['wh_event'])) { if (!strchr($wh['idata']['events'], $ev['wh_event'])) {
204 rg_log('DEBUG: ' . $ev['wh_event']
205 rg_log_debug('' . $ev['wh_event']
205 206 . ' is not present in [' . ' is not present in ['
206 207 . $wh['idata']['events'] . ']'); . $wh['idata']['events'] . ']');
207 208 continue; continue;
 
... ... function rg_wh_http_send($db, $ev)
209 210
210 211 if (isset($ev['ri']['name']) if (isset($ev['ri']['name'])
211 212 && !rg_wh_repo_match($wh['repo'], $ev['ri']['name'])) { && !rg_wh_repo_match($wh['repo'], $ev['ri']['name'])) {
212 rg_log('DEBUG: hook is not for repo ' . $ev['ri']['name']);
213 rg_log_debug('hook is not for repo ' . $ev['ri']['name']);
213 214 continue; continue;
214 215 } }
215 216
216 217 if (isset($ev['refname']) if (isset($ev['refname'])
217 218 && !rg_repo_compare_refs($wh['refname'], $ev['refname'])) { && !rg_repo_compare_refs($wh['refname'], $ev['refname'])) {
218 rg_log('DEBUG: hook is not for ref ' . $ev['refname']);
219 rg_log_debug('hook is not for ref ' . $ev['refname']);
219 220 continue; continue;
220 221 } }
221 222
 
... ... function rg_wh_http_itype($itype)
303 304 */ */
304 305 function rg_wh_http_cosmetic_pre(&$row) function rg_wh_http_cosmetic_pre(&$row)
305 306 { {
306 rg_log('DEBUG: wh_http_cosmetic:' . rg_array2string($row));
307 rg_log_debug('wh_http_cosmetic:' . rg_array2string($row));
307 308
308 309 $row['idata']['itype_text'] = rg_wh_http_itype($row['idata']['itype']); $row['idata']['itype_text'] = rg_wh_http_itype($row['idata']['itype']);
309 310
 
... ... function rg_wh_http_cosmetic_pre(&$row)
322 323 */ */
323 324 function rg_wh_http_cosmetic_post(&$row) function rg_wh_http_cosmetic_post(&$row)
324 325 { {
325 rg_log('DEBUG: wh_http_cosmetic_post:' . rg_array2string($row));
326 rg_log_debug('wh_http_cosmetic_post:' . rg_array2string($row));
326 327
327 328 $row['idata']['HTML:private'] = rg_template( $row['idata']['HTML:private'] = rg_template(
328 329 'user/settings/wh/http/show.html', $row, TRUE /*xss*/); 'user/settings/wh/http/show.html', $row, TRUE /*xss*/);
 
... ... function rg_wh_http_fill_vars(&$rg)
348 349
349 350 $rg['wh']['idata'] = $a; $rg['wh']['idata'] = $a;
350 351
351 //rg_log_ml('DEBUG: AFTTER wh_http_fill_vars: ' . rg_array2string($a));
352 //rg_log_debug('AFTTER wh_http_fill_vars: ' . rg_array2string($a));
352 353 } }
353 354
354 355 /* /*
 
... ... function rg_wh_http_add_form_pre($db, &$rg)
432 433 */ */
433 434 function rg_wh_http_add_form_post($db, &$rg) function rg_wh_http_add_form_post($db, &$rg)
434 435 { {
435 rg_log('DEBUG: wh_http_add_form_post');
436 rg_log_debug('wh_http_add_form_post');
436 437
437 438 $rg['HTML:custom_form'] = rg_template('user/settings/wh/http/form.html', $rg['HTML:custom_form'] = rg_template('user/settings/wh/http/form.html',
438 439 $rg, TRUE /*xss*/); $rg, TRUE /*xss*/);
File inc/wh/http/matrix.inc.php changed (mode: 100644) (index 9d2504f..4426c43)
... ... function rg_wh_matrix_fill_vars(&$rg, &$junk)
15 15 function rg_wh_matrix_send($db, $ev) function rg_wh_matrix_send($db, $ev)
16 16 { {
17 17 rg_log_enter('rg_wh_matrix_send'); rg_log_enter('rg_wh_matrix_send');
18 //rg_log_ml('DEBUG: wh_matrix_send: ev: ' . rg_array2string($ev));
18 //rg_log_debug('wh_matrix_send: ev: ' . rg_array2string($ev));
19 19
20 20 $ret = FALSE; $ret = FALSE;
21 21 while (1) { while (1) {
 
... ... function rg_wh_matrix_send($db, $ev)
42 42
43 43 rg_wh_http_send_helper($db, $ev1); rg_wh_http_send_helper($db, $ev1);
44 44 // TODO: what to do with the error code? // TODO: what to do with the error code?
45 rg_log_ml('DEBUG: helper returned: ' . rg_array2string($ev1['wh']));
45 rg_log_debug('helper returned: ' . rg_array2string($ev1['wh']));
46 46 $j = @json_decode($ev1['wh']['out']['body'], TRUE); $j = @json_decode($ev1['wh']['out']['body'], TRUE);
47 rg_log_ml('DEBUG: JSON: ' . rg_array2string($j));
47 rg_log_debug('JSON: ' . rg_array2string($j));
48 48 if ($j === NULL) { if ($j === NULL) {
49 rg_log('DEBUG: cannot decode json; what to do? TODO');
49 rg_log_debug('cannot decode json; what to do? TODO');
50 50 break; break;
51 51 } }
52 52 if (isset($j['errcode'])) { if (isset($j['errcode'])) {
 
... ... function rg_wh_matrix_send($db, $ev)
62 62
63 63 // join // join
64 64 // https://matrix.org/docs/spec/client_server/r0.2.0#id157 // https://matrix.org/docs/spec/client_server/r0.2.0#id157
65 rg_log_ml('DEBUG: now, joining room: ' . rg_array2string($ev));
65 rg_log_debug('now, joining room: ' . rg_array2string($ev));
66 66 $ev2 = $ev; $ev2 = $ev;
67 67 $ev2['wh']['idata']['url'] .= '/_matrix/client/r0/join/' $ev2['wh']['idata']['url'] .= '/_matrix/client/r0/join/'
68 68 . rawurlencode($ev2['wh']['idata']['room']) . rawurlencode($ev2['wh']['idata']['room'])
 
... ... function rg_wh_matrix_send($db, $ev)
71 71 $ev2['wh']['idata']['final'] = json_encode($b); $ev2['wh']['idata']['final'] = json_encode($b);
72 72
73 73 rg_wh_http_send_helper($db, $ev2); rg_wh_http_send_helper($db, $ev2);
74 rg_log_ml('DEBUG: helper returned: ' . rg_array2string($ev2['wh']['out']));
74 rg_log_debug('helper returned: ' . rg_array2string($ev2['wh']['out']));
75 75
76 76
77 77 // message // message
78 78 // https://matrix.org/docs/spec/client_server/latest#id320 // https://matrix.org/docs/spec/client_server/latest#id320
79 rg_log_ml('DEBUG: now, sending the message ev: ' . rg_array2string($ev));
79 rg_log_debug('now, sending the message ev: ' . rg_array2string($ev));
80 80 $ev2 = $ev; $ev2 = $ev;
81 81 $ev2['wh']['idata']['url'] .= '/_matrix/client/r0/rooms/' $ev2['wh']['idata']['url'] .= '/_matrix/client/r0/rooms/'
82 82 . rawurlencode($ev2['wh']['idata']['room']) . rawurlencode($ev2['wh']['idata']['room'])
 
... ... function rg_wh_matrix_send($db, $ev)
88 88 $ev2['wh']['idata']['final'] = json_encode($b); $ev2['wh']['idata']['final'] = json_encode($b);
89 89
90 90 rg_wh_http_send_helper($db, $ev2); rg_wh_http_send_helper($db, $ev2);
91 rg_log_ml('DEBUG: helper returned: ' . rg_array2string($ev2['wh']['out']));
91 rg_log_debug('helper returned: ' . rg_array2string($ev2['wh']['out']));
92 92 // TODO: what to do with the error code? // TODO: what to do with the error code?
93 rg_log_ml('DEBUG: helper returned: ' . rg_array2string($ev2['wh']));
93 rg_log_debug('helper returned: ' . rg_array2string($ev2['wh']));
94 94 $j = @json_decode($ev2['wh']['out']['body'], TRUE); $j = @json_decode($ev2['wh']['out']['body'], TRUE);
95 rg_log_ml('DEBUG: JSON: ' . rg_array2string($j));
95 rg_log_debug('JSON: ' . rg_array2string($j));
96 96 if ($j === NULL) { if ($j === NULL) {
97 rg_log('DEBUG: cannot decode json; what to do? TODO');
97 rg_log_debug('cannot decode json; what to do? TODO');
98 98 break; break;
99 99 } }
100 100 if (isset($j['errcode'])) { if (isset($j['errcode'])) {
 
... ... function rg_wh_matrix_send($db, $ev)
113 113 function rg_wh_matrix_add_form_pre($db, &$rg) function rg_wh_matrix_add_form_pre($db, &$rg)
114 114 { {
115 115 $a = $rg['wh']['idata']; $a = $rg['wh']['idata'];
116 rg_log_ml('DEBUG: wh_matrix_add_form_pre: ' . rg_array2string($a));
116 rg_log_debug('wh_matrix_add_form_pre: ' . rg_array2string($a));
117 117
118 118 if (!isset($rg['wh']['description'])) if (!isset($rg['wh']['description']))
119 119 $rg['wh']['description'] = 'Matrix.org integration'; $rg['wh']['description'] = 'Matrix.org integration';
File inc/wh/lambda.inc.php changed (mode: 100644) (index ba71f85..df00b1f)
... ... function rg_wh_lambda_send_one($db, $ev)
42 42 break; break;
43 43 } }
44 44
45 rg_wh_set_last_output($db, $ev['ui']['uid'], $wh['id'],
45 rg_wh_set_last_output($db, $ev['ui_login']['uid'], $wh['id'],
46 46 substr($last_output, 0, 4096)); substr($last_output, 0, 4096));
47 47
48 if ($ev['debug'] == 1)
49 rg_cache_set('DEBUG::' . $ev['ui']['uid']
50 . '::webhooks::' . $wh['id'], $last_output,
51 RG_SOCKET_NO_WAIT);
48 if (rg_debug()) {
49 $k = 'DEBUG::' . $ev['ui_login']['uid']
50 . '::webhooks::' . $wh['id'];
51 rg_log_debug('setting key [' . $k . '] to ' . $last_output);
52 rg_cache_set($k, $last_output, RG_SOCKET_NO_WAIT);
53 }
52 54
53 55 rg_prof_end('wh_lambda_send_one'); rg_prof_end('wh_lambda_send_one');
54 56 return $ret; return $ret;
 
... ... function rg_wh_lambda_send($db, $ev)
65 67 $ret = array(); $ret = array();
66 68
67 69 // First, get the list of hooks // First, get the list of hooks
68 $r = rg_wh_list($db, $ev['ui']['uid']);
70 $r = rg_wh_list($db, $ev['ui_login']['uid']);
69 71 if ($r['ok'] != 1) if ($r['ok'] != 1)
70 72 return FALSE; return FALSE;
71 73
 
... ... function rg_wh_lambda_send($db, $ev)
80 82
81 83 // If the web hook does not contain our type, skip it // If the web hook does not contain our type, skip it
82 84 if (!strchr($wh['idata']['events'], $ev['wh_event'])) { if (!strchr($wh['idata']['events'], $ev['wh_event'])) {
83 rg_log('DEBUG: ' . $ev['wh_event']
85 rg_log_debug('' . $ev['wh_event']
84 86 . ' is not present in [' . ' is not present in ['
85 87 . $wh['idata']['events'] . ']'); . $wh['idata']['events'] . ']');
86 88 continue; continue;
 
... ... function rg_wh_lambda_send($db, $ev)
88 90
89 91 if (isset($ev['ri']['name']) if (isset($ev['ri']['name'])
90 92 && !rg_repo_compare_refs($wh['repo'], $ev['ri']['name'])) { && !rg_repo_compare_refs($wh['repo'], $ev['ri']['name'])) {
91 rg_log('DEBUG: hook is not for this repo');
93 rg_log_debug('hook is not for this repo');
92 94 continue; continue;
93 95 } }
94 96
95 97 if (isset($ev['refname']) if (isset($ev['refname'])
96 98 && !rg_repo_compare_refs($wh['refname'], $ev['refname'])) { && !rg_repo_compare_refs($wh['refname'], $ev['refname'])) {
97 rg_log('DEBUG: hook is not for this ref');
99 rg_log_debug('hook is not for this ref');
98 100 continue; continue;
99 101 } }
100 102
File inc/workers.inc.php changed (mode: 100644) (index 15f0811..2ce8cc0)
... ... function rg_worker_event_add($db, $ev)
35 35 { {
36 36 $ret = array(); $ret = array();
37 37
38 $ret[] = array_merge($ev, array(
39 'category' => 'rg_keys_event_regen',
40 'prio' => 10)
41 );
38 $ev['category'] = 'rg_keys_event_regen';
39 $ev['prio'] = 10;
40 $ev['source'] = 'worker_event_add';
41 $ret[] = $ev;
42 42
43 43 return $ret; return $ret;
44 44 } }
 
... ... function rg_worker_event_del($db, $ev)
50 50 { {
51 51 $ret = array(); $ret = array();
52 52
53 $ret[] = array_merge($ev, array(
54 'category' => 'rg_keys_event_regen',
55 'prio' => 10)
56 );
53 $ev['category'] = 'rg_keys_event_regen';
54 $ev['prio'] = 10;
55 $ev['source'] = 'worker_event_del';
56 $ret[] = $ev;
57 57
58 58 return $ret; return $ret;
59 59 } }
 
... ... function rg_worker_find_by_name($db, $uid, $name)
240 240 $ret = 0; $ret = 0;
241 241
242 242 foreach ($wi as $id => $i) { foreach ($wi as $id => $i) {
243 rg_log('DEBUG: comparing with [' . $i['name'] . ']...');
243 rg_log_debug('comparing with [' . $i['name'] . ']...');
244 244 if (strcasecmp($i['name'], $name) == 0) { if (strcasecmp($i['name'], $name) == 0) {
245 245 $ret = $i; $ret = $i;
246 246 break; break;
 
... ... function rg_worker_add($db, $uid, $a)
261 261 rg_prof_start('worker_add'); rg_prof_start('worker_add');
262 262 rg_log_enter('worker_add'); rg_log_enter('worker_add');
263 263
264 //rg_log_ml('DEBUG: uid=' . $uid . ', a: ' . print_r($a, TRUE));
264 //rg_log_debug('uid=' . $uid . ', a: ' . print_r($a, TRUE));
265 265
266 266 $ret = FALSE; $ret = FALSE;
267 267 while (1) { while (1) {
 
... ... function rg_worker_add($db, $uid, $a)
304 304 $event = array( $event = array(
305 305 'category' => 'worker_event_add', 'category' => 'worker_event_add',
306 306 'prio' => 50, 'prio' => 50,
307 'ui' => array('uid' => $uid),
307 'ui_login' => array('uid' => $uid),
308 308 'add' => $a['id'] == 0 ? 1 : 0, 'add' => $a['id'] == 0 ? 1 : 0,
309 309 'id' => $id); 'id' => $id);
310 310 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
 
... ... function rg_worker_update($db, $uid, $id, $a)
341 341 rg_prof_start('worker_update'); rg_prof_start('worker_update');
342 342 rg_log_enter('worker_update'); rg_log_enter('worker_update');
343 343
344 rg_log_ml('DEBUG: a: ' . print_r($a, TRUE));
344 rg_log_debug('a: ' . print_r($a, TRUE));
345 345
346 346 $ret = FALSE; $ret = FALSE;
347 347 while (1) { while (1) {
 
... ... function rg_worker_update($db, $uid, $id, $a)
389 389 } }
390 390 rg_sql_free_result($res); rg_sql_free_result($res);
391 391
392 if ($uid == 0) {
393 // enable distros only if the worker is global = added by an admin
394 $_list = array();
395 foreach ($a['env'] as $env => $junk)
396 $_list[] = $env;
397 $r = rg_env_enable($db, $_list);
398 if ($r['ok'] != 1) {
399 rg_worker_set_error('cannot enable env: ' . $r['errmsg']);
400 break;
401 }
402 }
403
392 404 $event = array( $event = array(
393 405 'category' => 'worker_event_add', 'category' => 'worker_event_add',
394 406 'prio' => 50, 'prio' => 50,
395 'ui' => array('uid' => $uid),
407 'ui_login' => array('uid' => $uid),
396 408 'add' => 0, 'add' => 0,
397 409 'id' => $id); 'id' => $id);
398 410 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
 
... ... function rg_worker_environments($db, $uid)
432 444 $r = rg_worker_list($db, $uid); $r = rg_worker_list($db, $uid);
433 445 if ($r === FALSE) if ($r === FALSE)
434 446 break; break;
447 $user_envs = $r;
435 448 } }
436 449
437 450 $global_envs = rg_worker_list($db, 0); $global_envs = rg_worker_list($db, 0);
438 451 if ($global_envs === FALSE) if ($global_envs === FALSE)
439 452 break; break;
440 453
454 $limit = time() - 31 * 24 * 3600;
455
441 456 $r = array_merge($user_envs, $global_envs); $r = array_merge($user_envs, $global_envs);
442 457 $ret = array(); $ret = array();
443 458 foreach ($r as $id => $i) { foreach ($r as $id => $i) {
444 459 if (empty($i['env'])) if (empty($i['env']))
445 460 continue; continue;
446 461
462 if ($i['last_connect'] < $limit) {
463 rg_log_debug('worker did not connect recently; skip it');
464 continue;
465 }
466
447 467 $list = rg_unserialize($i['env']); $list = rg_unserialize($i['env']);
448 468 if ($list === FALSE) if ($list === FALSE)
449 469 continue; continue;
470 //rg_log_debug('id=' . $id . ': ' . rg_array2string($list));
450 471
451 472 foreach ($list as $env => $junk) foreach ($list as $env => $junk)
452 $ret[$env] = $env;
473 $ret[] = $env;
453 474 } }
454 475
455 uksort($ret, 'rg_worker_sort_alpha');
456 //rg_log_ml('DEBUG: workers_environments: ret=' . print_r($ret, TRUE));
476 usort($ret, 'rg_worker_sort_alpha');
477 //rg_log_debug('ret=' . rg_array2string($ret));
457 478 break; break;
458 479 } }
459 480
 
... ... function rg_worker_remove($db, $uid, $list)
491 512 $event = array( $event = array(
492 513 'category' => 'worker_event_del', 'category' => 'worker_event_del',
493 514 'prio' => 50, 'prio' => 50,
494 'ui' => array('uid' => $uid),
515 'ui_login' => array('uid' => $uid),
495 516 'keys' => implode(',', $my_list)); 'keys' => implode(',', $my_list));
496 517 $r = rg_event_add($db, $event); $r = rg_event_add($db, $event);
497 518 if ($r !== TRUE) { if ($r !== TRUE) {
 
... ... function rg_worker_data($db, $type, $worker_id, $start, $end, $unit, $mode)
612 633 */ */
613 634 function rg_worker_graphs($db, $r) function rg_worker_graphs($db, $r)
614 635 { {
615 rg_log_ml('DEBUG: worker_graphs: ' . print_r($r, TRUE));
636 rg_log_debug('worker_graphs: ' . print_r($r, TRUE));
616 637
617 638 $period = 'hour'; $period = 'hour';
618 639 $start = gmmktime(0, 0, 0, gmdate('m') - 1, gmdate('d'), gmdate('Y')); $start = gmmktime(0, 0, 0, gmdate('m') - 1, gmdate('d'), gmdate('Y'));
 
... ... function rg_worker_add_high_level($db, $rg, $op, $paras)
675 696 $errmsg = array(); $errmsg = array();
676 697
677 698 // All admins will have 'who' == 0 // All admins will have 'who' == 0
678 if ($rg['login_ui']['is_admin'] == 1)
699 $ui_login = rg_ui_login();
700 if ($ui_login['is_admin'] == 1)
679 701 $target_uid = 0; $target_uid = 0;
680 702 else else
681 $target_uid = $rg['login_ui']['uid'];
703 $target_uid = $ui_login['uid'];
682 704
683 705 $rg['worker'] = array(); $rg['worker'] = array();
684 706 if (strcmp($op, 'add') == 0) { if (strcmp($op, 'add') == 0) {
 
... ... function rg_worker_add_high_level($db, $rg, $op, $paras)
702 724 $errmsg[] = 'no worker id received'; $errmsg[] = 'no worker id received';
703 725 } }
704 726 } }
705 rg_log_ml('DEBUG: rg[worker]: ' . print_r($rg['worker'], TRUE));
727 rg_log_debug('rg[worker]: ' . print_r($rg['worker'], TRUE));
706 728
707 729 $doit = rg_var_uint('doit'); $doit = rg_var_uint('doit');
708 730 while ($doit == 1) { while ($doit == 1) {
 
... ... function rg_worker_list_high_level($db, $rg, $paras)
779 801 $errmsg = array(); $errmsg = array();
780 802 $rg['HTML:status'] = ''; $rg['HTML:status'] = '';
781 803
782 if ($rg['login_ui']['is_admin'] == 1)
804 $ui_login = rg_ui_login();
805 if ($ui_login['is_admin'] == 1)
783 806 $target_uid = 0; $target_uid = 0;
784 807 else else
785 $target_uid = $rg['login_ui']['uid'];
808 $target_uid = $ui_login['uid'];
786 809
787 810 $doit = rg_var_uint('doit'); $doit = rg_var_uint('doit');
788 811 while ($doit == 1) { while ($doit == 1) {
File rocketgit.spec.in changed (mode: 100644) (index 549c564..8758a1e)
... ... Source: http://kernel.embedromix.ro/us/rocketgit/%{name}-%{version}.tar.gz
14 14 URL: https://rocketgit.com/ URL: https://rocketgit.com/
15 15 BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
16 16 BuildArch: noarch BuildArch: noarch
17
18 # fuse is required for rgfs
17 19 Requires: httpd-filesystem, nginx-filesystem, php-fpm, php-cli, php-pgsql, php-mbstring Requires: httpd-filesystem, nginx-filesystem, php-fpm, php-cli, php-pgsql, php-mbstring
18 20 Requires: git-core, cronie, xinetd, php-json, php-ldap Requires: git-core, cronie, xinetd, php-json, php-ldap
19 Requires: util-linux, qrencode
21 Requires: util-linux, qrencode, fuse, openssh-server, gpg
22
20 23 # SELinux stuff # SELinux stuff
21 24 # https://fedoraproject.org/wiki/SELinux_Policy_Modules_Packaging_Draft?rd=PackagingDrafts/SELinux/PolicyModules # https://fedoraproject.org/wiki/SELinux_Policy_Modules_Packaging_Draft?rd=PackagingDrafts/SELinux/PolicyModules
22 25 BuildRequires: checkpolicy, selinux-policy-devel, systemd, php-cli BuildRequires: checkpolicy, selinux-policy-devel, systemd, php-cli
 
... ... fi
60 63 %systemd_post @PRJ@-fpm.service %systemd_post @PRJ@-fpm.service
61 64 [ -r /tmp/rgsdebug ] && echo "systemd_post builder..." [ -r /tmp/rgsdebug ] && echo "systemd_post builder..."
62 65 %systemd_post @PRJ@-builder.service %systemd_post @PRJ@-builder.service
66 [ -r /tmp/rgsdebug ] && echo "systemd_post fs..."
67 %systemd_post @PRJ@-fs.service
63 68 [ -r /tmp/rgsdebug ] && echo "'post' done..." [ -r /tmp/rgsdebug ] && echo "'post' done..."
64 69
65 70 %preun %preun
66 71 %systemd_preun @PRJ@-fpm.service %systemd_preun @PRJ@-fpm.service
67 72 %systemd_preun @PRJ@-builder.service %systemd_preun @PRJ@-builder.service
73 %systemd_preun @PRJ@-fs.service
68 74 %systemd_preun @PRJ@-worker@\*.service %systemd_preun @PRJ@-worker@\*.service
69 75
70 76 %postun %postun
 
... ... if [ $1 = 0 ]; then
77 83 fi fi
78 84 %systemd_postun_with_restart @PRJ@-fpm.service %systemd_postun_with_restart @PRJ@-fpm.service
79 85 %systemd_postun_with_restart @PRJ@-builder.service %systemd_postun_with_restart @PRJ@-builder.service
86 %systemd_postun_with_restart @PRJ@-fs.service
80 87 %systemd_postun_with_restart @PRJ@-worker@\*.service %systemd_postun_with_restart @PRJ@-worker@\*.service
81 88
82 89 %prep %prep
File root/index.php changed (mode: 100644) (index 3f72bd8..1857ff7)
... ... if (!isset($rg_account_allow_creation))
54 54 $rg['rg_account_allow_creation'] = $rg_account_allow_creation; $rg['rg_account_allow_creation'] = $rg_account_allow_creation;
55 55
56 56 // Init variables // Init variables
57 if (isset($_SERVER['REMOTE_ADDR']))
58 rg_ip_set($_SERVER['REMOTE_ADDR']);
57 59 $rg['rg_redirect_html'] = 0; $rg['rg_redirect_html'] = 0;
58 60 $rg['rg_theme_url'] = '/themes/' . rawurlencode($rg_theme); $rg['rg_theme_url'] = '/themes/' . rawurlencode($rg_theme);
59 $rg['login_ui'] = rg_user_empty();
60 61 $rg['target_ui'] = array("ok" => 1, "exists" => 0, "uid" => 0); $rg['target_ui'] = array("ok" => 1, "exists" => 0, "uid" => 0);
61 $rg['page_ui'] = array("ok" => 1, "exists" => 0, "uid" => 0);
62 62 $rg['ri'] = array('exists' => 0, 'repo_id' => 0, 'uid' => 0); $rg['ri'] = array('exists' => 0, 'repo_id' => 0, 'uid' => 0);
63 63 $rg['bug'] = array("bug_id" => 0); $rg['bug'] = array("bug_id" => 0);
64 64 $rg['https'] = strcmp(rg_var_str('HTTPS'), 'on') == 0 ? 1 : 0; $rg['https'] = strcmp(rg_var_str('HTTPS'), 'on') == 0 ? 1 : 0;
65 65
66 66
67 67 $sparas = rg_var_str('SCRIPT_NAME'); $sparas = rg_var_str('SCRIPT_NAME');
68 rg_log($rg['ip'] . ' ' . @$_SERVER['REQUEST_METHOD'] . ' ' . $sparas);
68 rg_log(rg_ip() . ' ' . @$_SERVER['REQUEST_METHOD'] . ' ' . $sparas);
69 69 $rg['current_url'] = rawurlencode($sparas); $rg['current_url'] = rawurlencode($sparas);
70 70 $rg['url'] = '/op'; $rg['url'] = '/op';
71 71 $paras = explode("/", trim($sparas, "/")); $paras = explode("/", trim($sparas, "/"));
 
... ... if (isset($req['pass1']))
103 103 if (isset($req['pass2'])) if (isset($req['pass2']))
104 104 $req['pass2'] = '*****'; $req['pass2'] = '*****';
105 105 if (!empty($req)) if (!empty($req))
106 rg_log("DEBUG: _REQUEST: " . rg_array2string($req));
106 rg_log('_REQUEST: ' . rg_array2string($req));
107 107 if (!empty($_COOKIE)) if (!empty($_COOKIE))
108 rg_log("DEBUG: _COOKIE: " . rg_array2string($_COOKIE));
108 rg_log('_COOKIE: ' . rg_array2string($_COOKIE));
109 109
110 110 //rg_log_ml('_SERVER: ' . print_r($_SERVER, TRUE)); //rg_log_ml('_SERVER: ' . print_r($_SERVER, TRUE));
111 111 $_list = array('SERVER_PROTOCOL', 'HTTP_CACHE_CONTROL', $_list = array('SERVER_PROTOCOL', 'HTTP_CACHE_CONTROL',
 
... ... if ($r === FALSE) {
126 126 exit(0); exit(0);
127 127 } }
128 128
129 $rg['debug'] = rg_state_get($db, 'debug');
129 rg_debug_set(rg_state_get($db, 'debug'));
130 130
131 $lim = rg_rate_limit($db, $rg['ip']);
132 if ($lim == 0) {
131 $lim = rg_rate_limit($db);
132 if (($lim == 0) && (rg_debug() == 0)) {
133 133 rg_log('Too many requests'); rg_log('Too many requests');
134 134 header($rg['proto'] . ' 429 Too many requests'); header($rg['proto'] . ' 429 Too many requests');
135 135 echo 'Too many requests. Please slow down.' . "\n"; echo 'Too many requests. Please slow down.' . "\n";
 
... ... if ($rg['https'] == 1) {
186 186 } }
187 187 } }
188 188
189 rg_log('DEBUG: hostname=' . $hostname . ' http_allow=' . $http_allow
190 . ' https_allow=' . $https_allow);
191 rg_base_url_build($hostname, $http_allow, $https_allow);
192 rg_log('DEBUG: base_url=' . rg_base_url());
189 //rg_log_debug('hostname=' . $hostname . ' http_allow=' . $http_allow
190 // . ' https_allow=' . $https_allow);
193 191 $rg['hostname'] = $hostname; $rg['hostname'] = $hostname;
194 192 $rg['hostname_port'] = $rg['hostname_port'] =
195 193 rg_base_url_host_port($hostname, $port, $rg['https'] == 0 ? 80 : 443); rg_base_url_host_port($hostname, $port, $rg['https'] == 0 ? 80 : 443);
196 194 $rg['http_allow'] = $http_allow; $rg['http_allow'] = $http_allow;
197 195 $rg['https_allow'] = $https_allow; $rg['https_allow'] = $https_allow;
198 $rg['base_url'] = rg_base_url();
196 $rg['base_url'] = rg_base_url($db, '', '');
197
198
199 rg_user_login_by_sid($db, $rg);
200 // If user provided an old/expired sid, we generate a new one, pre-login
201 $ui_login = rg_ui_login();
202 if (($ui_login['uid'] == 0) && (strncmp($rg['sid'], 'X', 1) != 0))
203 $rg['sid'] = '';
204 if (empty($rg['sid'])) {
205 $rg['sid'] = rg_user_set_session_cookie($db, 0 /*uid*/, 600,
206 FALSE /*lock_ip*/, $rg['https'], $rg['hostname']);
207 rg_log('User has no sid, generate one [' . $rg['sid'] . ']');
208 }
199 209
210 if (isset($_SERVER['CONTENT_LENGTH']))
211 rg_stats_conns_set('bytes_in', intval($_SERVER['CONTENT_LENGTH']));
200 212
201 $skip_etag_and_compression = FALSE;
213 $skip_etag = FALSE;
214 $skip_compression = FALSE;
202 215
203 216 // Is it a http push/fetch? // Is it a http push/fetch?
204 217 $r = rg_user_http_git($db, $rg, $paras); $r = rg_user_http_git($db, $rg, $paras);
205 218 if ($r === TRUE) { if ($r === TRUE) {
206 219 rg_stats_conns_set('type', 'git-over-http'); rg_stats_conns_set('type', 'git-over-http');
207 $skip_etag_and_compression = TRUE;
220 $skip_etag = TRUE;
221 rg_debug() && header('X-RocketGit-skip-etag: 1');
222 $skip_compression = TRUE;
223 rg_debug() && header('X-RocketGit-skip-compression: 1');
224 } else if (strcmp($_op, 'pkgrepo') == 0) {
225 // This section is called by 'dnf' & co.
226 rg_log_ml('_SERVER: ' . print_r($_SERVER, TRUE));
227 rg_stats_conns_set('type', 'pkgrepo');
228 $_pass = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
229
230 // Because everything is done in 'rg_packages_web' and nothing is
231 // returned, we will skip the output phase.
232 $skip_etag = TRUE;
233 rg_debug() && header('X-RocketGit-skip-etag: 1');
234 $skip_compression = TRUE;
235 rg_debug() && header('X-RocketGit-skip-compression: 1');
236
237 rg_packages_web($db, $rg, $paras, $_pass);
208 238 } else if (strcmp($_op, 'api') == 0) { // API dispatch } else if (strcmp($_op, 'api') == 0) { // API dispatch
209 239 rg_stats_conns_set('type', 'api-over-http'); rg_stats_conns_set('type', 'api-over-http');
210 240
 
... ... if ($r === TRUE) {
226 256 while (1) { while (1) {
227 257 $key_id = FALSE; $key_id = FALSE;
228 258
229 $rg['login_ui'] = rg_user_info($db, 0, $_user, '');
230 if ($rg['login_ui']['ok'] != 1) {
259 $ui_login = rg_user_info($db, 0, $_user, '');
260 if ($ui_login['ok'] != 1) {
231 261 $e = array('error' => rg_user_error()); $e = array('error' => rg_user_error());
232 262 break; break;
233 263 } }
234 264
235 if ($rg['login_ui']['exists'] != 1) {
265 if ($ui_login['exists'] != 1) {
236 266 $e = array('error' => 'invalid user or apikey'); $e = array('error' => 'invalid user or apikey');
237 267 break; break;
238 268 } }
269 rg_ui_login_set($ui_login);
239 270
240 $key_id = rg_ak_valid($db, $rg['login_ui']['uid'], $_key);
271 $key_id = rg_ak_valid($db, $ui_login['uid'], $_key);
241 272 if ($key_id === FALSE) { if ($key_id === FALSE) {
242 273 $e = array('error' => 'invalid user or apikey'); $e = array('error' => 'invalid user or apikey');
243 274 break; break;
 
... ... if ($r === TRUE) {
261 292 } else { // normal web request } else { // normal web request
262 293 rg_stats_conns_set('type', 'http'); rg_stats_conns_set('type', 'http');
263 294
264 rg_user_login_by_sid($db, $rg);
265 //rg_log('DEBUG: After login_by_sid, login_ui=' . rg_array2string($rg['login_ui']));
266 // If user provided an old/expired sid, we generate a new one, pre-login
267 if (($rg['login_ui']['uid'] == 0) && (strncmp($rg['sid'], "X", 1) != 0))
268 $rg['sid'] = "";
269 if (empty($rg['sid'])) {
270 $rg['sid'] = rg_user_set_session_cookie($db, 0 /*uid*/, 600,
271 FALSE /*lock_ip*/, $rg['https'], $rg['hostname']);
272 rg_log("User has no sid, generate one [" . $rg['sid'] . "]");
273 }
274
275 295 $body = ""; $body = "";
276 296
277 297 // Some variables from the database // Some variables from the database
 
... ... if ($r === TRUE) {
280 300 $r = rg_state_get($db, "first_install"); $r = rg_state_get($db, "first_install");
281 301 if ($r === FALSE) { if ($r === FALSE) {
282 302 // Probably we cannot connect to database/cache // Probably we cannot connect to database/cache
283 $body .= rg_template('admin/db_error.html', TRUE /*xss*/);
303 $body .= rg_template('admin/db_error.html', $rg, TRUE /*xss*/);
284 304 } else if ($r === '') { } else if ($r === '') {
285 305 $body .= rg_init($db, $rg); $body .= rg_init($db, $rg);
286 306 } else { } else {
 
... ... if ($r === TRUE) {
290 310 include(__DIR__ . '/../inc/dispatch/dispatch.php'); include(__DIR__ . '/../inc/dispatch/dispatch.php');
291 311 } }
292 312
293 if ($rg['login_ui']['uid'] > 0) {
313 $ui_login = rg_ui_login();
314 if ($ui_login['uid'] > 0) {
294 315 $rg['logout_token'] = rg_token_get($db, $rg, 'logout'); $rg['logout_token'] = rg_token_get($db, $rg, 'logout');
295 316 } else { } else {
296 317 $rg['logout_token'] = ''; $rg['logout_token'] = '';
 
... ... if ($r === TRUE) {
299 320
300 321 // Redirect if http is not allowed and the user is not logged in // Redirect if http is not allowed and the user is not logged in
301 322 if (($rg['https'] == 0) if (($rg['https'] == 0)
302 && ($rg['login_ui']['uid'] == 0)
323 && ($ui_login['uid'] == 0)
303 324 && (strcmp($http_allow, '0') == 0)) && (strcmp($http_allow, '0') == 0))
304 rg_redirect(rg_base_url() . $sparas);
325 rg_redirect(rg_base_url($db, '', '') . $sparas);
305 326
306 327
307 328 $rg['HTML:rg_body'] = $body; $rg['HTML:rg_body'] = $body;
308 329 $_c = rg_template('index.html', $rg, TRUE /*xss*/); $_c = rg_template('index.html', $rg, TRUE /*xss*/);
309 330
310 rg_stats_conns_set('uid', $rg['page_ui']['uid']);
331 rg_stats_conns_set('login_uid', $ui_login['uid']);
332 $ui_page = rg_ui_page();
333 rg_stats_conns_set('uid', $ui_page['uid']);
311 334 if ($rg['ri']['exists'] > 0) if ($rg['ri']['exists'] > 0)
312 335 rg_stats_conns_set('repo_id', $rg['ri']['repo_id']); rg_stats_conns_set('repo_id', $rg['ri']['repo_id']);
313 336 } }
314 337
315 if ($skip_etag_and_compression == FALSE) {
338 if ($skip_etag === FALSE) {
316 339 // TODO: really?! What about API? // TODO: really?! What about API?
317 340 header('Cache-Control: private, no-cache'); header('Cache-Control: private, no-cache');
318 341
319 342 // Caching // Caching
320 343 if ((strcmp($rg['proto'], 'HTTP/1.1') == 0) || (strcmp($rg['proto'], 'HTTP/2.0') == 0)) { if ((strcmp($rg['proto'], 'HTTP/1.1') == 0) || (strcmp($rg['proto'], 'HTTP/2.0') == 0)) {
321 while (1) {
344 do {
322 345 $we_have = sha1($_c); $we_have = sha1($_c);
323 346 if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
324 347 $client_have = $_SERVER['HTTP_IF_NONE_MATCH']; $client_have = $_SERVER['HTTP_IF_NONE_MATCH'];
 
... ... if ($skip_etag_and_compression == FALSE) {
331 354 } }
332 355
333 356 header('ETag: ' . $we_have); header('ETag: ' . $we_have);
334 rg_web_output($_c);
335 break;
336 }
357 $bytes_out = rg_web_output($_c, $skip_compression);
358 rg_stats_conns_set('bytes_out', $bytes_out);
359 } while (0);
337 360 } else { } else {
338 361 //rg_log('WARN: Un-handled protocol [' . $rg['proto'] . ']'); //rg_log('WARN: Un-handled protocol [' . $rg['proto'] . ']');
339 rg_web_output($_c);
362 $bytes_out = rg_web_output($_c, $skip_compression);
363 rg_stats_conns_set('bytes_out', $bytes_out);
340 364 } }
341 365 } }
342 366
343 367 rg_prof_end('MAIN'); rg_prof_end('MAIN');
344 rg_prof_log();
345 368
346 if (function_exists('fastcgi_finish_request'))
369 if (function_exists('fastcgi_finish_request')) {
347 370 fastcgi_finish_request(); fastcgi_finish_request();
371 rg_log_debug('request finished; follows background work');
372 }
348 373 // Now, answer was delivered to the client, we can do some boring tasks. // Now, answer was delivered to the client, we can do some boring tasks.
349 374
350 375 while (strcmp($_op, 'api') == 0) { while (strcmp($_op, 'api') == 0) {
351 376 if ($key_id === FALSE) if ($key_id === FALSE)
352 377 break; break;
353 378
354 rg_ak_update_use($db, $rg['login_ui']['uid'], $key_id,
355 $rg['ip'], $post);
379 rg_ak_update_use($db, $ui_login['uid'], $key_id, $post);
356 380 break; break;
357 381 } }
358 382
359 $list = array('start', 'ip', 'ua', 'referer');
383 $list = array('start', 'ua', 'referer');
360 384 foreach ($list as $k) foreach ($list as $k)
361 385 rg_stats_conns_set($k, $rg[$k]); rg_stats_conns_set($k, $rg[$k]);
362 //TODO: lines below override the good ones in case of api calls
363 //rg_stats_conns_set('uid', $rg['ri']['uid']);
364 //rg_stats_conns_set('repo_id', $rg['ri']['repo_id']);
365 386 rg_stats_conns_set('url', $sparas); rg_stats_conns_set('url', $sparas);
366 387 rg_stats_conns_insert($db); rg_stats_conns_insert($db);
367 388
368 rg_log('Done');
389 rg_prof_log();
File samples/nginx.conf changed (mode: 100644) (index 9ce6ab7..e7c9bb2)
1 # HTTP server
2 server {
3 listen 80;
4 listen [::]:80;
5 server_name rg.domain.tld; # add here, space separated, more names
6 server_tokens off;
7 root /usr/share/rocketgit/root;
8
9 tcp_nopush on;
10 sendfile on;
11
12 # TODO - is ok in this context?
13 client_max_body_size 1000m;
14 # more than that is written into a file first
15 client_body_buffer_size 128k;
16
17 # timeouts
18 client_body_timeout 10;
19 client_header_timeout 10;
20 keepalive_timeout 30;
21 send_timeout 10;
22
23 # Security (ClickJacking)
24 add_header X-Frame-Options DENY;
25 # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
26 add_header X-Content-Type-Options nosniff;
27 # XSS protection
28 add_header X-XSS-Protection "1; mode=block";
29
30 access_log /var/log/nginx/rg-access.log;
31 error_log /var/log/nginx/rg-error.log;
32
33 if ($request_method !~ ^(GET|HEAD|POST|OPTIONS)$) { return 444; }
34
35 # Force the use of only one name even if we have more aliases.
36 # Before un-commenting it, change SERVERNAME and PORT to real values
37 #if ($host != SERVERNAME) {
38 # rewrite ^/?(.*)$ http://SERVERNAME:PORT/$1 permanent;
39 #}
40
41 location ~ ^/(favicon\.ico|themes/.*|robots\.txt|\.well-known/.*)$ {
42 expires 1d;
43 }
44
45 location / {
46 gzip on;
47 #gzip_comp_level 6;
48 gzip_types text/plain text/xml text/css text/javascript application/javascript application/x-javascript;
49
50 # To be able to know that the client closed the connection
51 # TODO: equivalent for apache?
52 fastcgi_ignore_client_abort off;
53
54 # To allow streaming of the response data to client
55 fastcgi_buffering off;
56
57 # TODO
58 fastcgi_keep_conn on;
59
60 include /etc/nginx/fastcgi_params;
61 fastcgi_param SCRIPT_FILENAME $document_root/index.php$fastcgi_script_name;
62
63 fastcgi_pass unix:/run/rocketgit.sock;
64 }
1 upstream rgfs {
2 server 127.0.0.1:65300;
65 3 } }
66 4
67 # HTTPS server
68 5 server { server {
69 listen 443 ssl http2;
70 listen [::]:443 ssl http2;
6 listen 443 ssl http2 backlog=128 rcvbuf=64k;
7 listen [::]:443 ssl http2 backlog=128 rcvbuf=64k;
8 listen 80 backlog=128 rcvbuf=64k;
9 listen [::]:80 backlog=128 rcvbuf=64k;
10
71 11 server_name rg.domain.tld; # add here, space separated, more names server_name rg.domain.tld; # add here, space separated, more names
72 12 server_tokens off; server_tokens off;
73 13 root /usr/share/rocketgit/root; root /usr/share/rocketgit/root;
 
... ... server {
83 23 # timeouts # timeouts
84 24 client_body_timeout 10; client_body_timeout 10;
85 25 client_header_timeout 10; client_header_timeout 10;
86 keepalive_timeout 30;
26 keepalive_timeout 10;
87 27 send_timeout 10; send_timeout 10;
88 28
89 29 # Security (ClickJacking) # Security (ClickJacking)
 
... ... server {
95 35 # Security (STS) # Security (STS)
96 36 add_header Strict-Transport-Security "max-age=31536000"; add_header Strict-Transport-Security "max-age=31536000";
97 37
98 access_log /var/log/nginx/rg-ssl-access.log;
99 error_log /var/log/nginx/rg-ssl-error.log;
38 access_log /var/log/nginx/rg-access.log;
39 error_log /var/log/nginx/rg-error.log;
100 40
101 41 if ($request_method !~ ^(GET|HEAD|POST|OPTIONS)$) { return 444; } if ($request_method !~ ^(GET|HEAD|POST|OPTIONS)$) { return 444; }
102 42
103 43 # Force the use of only one name even if we have more aliases. # Force the use of only one name even if we have more aliases.
104 44 # Before un-commenting it, change SERVERNAME and PORT to real values # Before un-commenting it, change SERVERNAME and PORT to real values
105 45 #if ($host != SERVERNAME) { #if ($host != SERVERNAME) {
106 # rewrite ^/?(.*)$ https://SERVERNAME[:PORT]/$1 permanent;
46 # rewrite ^/?(.*)$ $scheme://SERVERNAME[:$server_port]/$1 permanent;
107 47 #} #}
108 48
109 49 location ~ ^/(favicon\.ico|themes/.*|robots\.txt|\.well-known/.*)$ { location ~ ^/(favicon\.ico|themes/.*|robots\.txt|\.well-known/.*)$ {
 
... ... server {
113 53 gzip_types text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json image/svg+xml; gzip_types text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json image/svg+xml;
114 54 } }
115 55
56 location /rgfs {
57 proxy_pass http://rgfs;
58 proxy_http_version 1.1;
59 proxy_set_header X-Original-IP $remote_addr/$remote_port;
60 proxy_set_header Upgrade $http_upgrade;
61 proxy_set_header Connection "upgrade";
62 proxy_read_timeout 30;
63 proxy_buffering off;
64 }
65
116 66 location / { location / {
117 67 gzip on; gzip on;
118 68 gzip_comp_level 5; gzip_comp_level 5;
119 gzip_types text/plain text/xml application/json image/svg+xml;
69 gzip_types text/plain text/xml application/json image/svg+xml text/css text/javascript application/javascript application/x-javascript;
120 70
121 71 # To be able to know that the client closed the connection # To be able to know that the client closed the connection
122 72 # TODO: equivalent for apache? # TODO: equivalent for apache?
 
... ... server {
130 80
131 81 include /etc/nginx/fastcgi_params; include /etc/nginx/fastcgi_params;
132 82 fastcgi_param SCRIPT_FILENAME $document_root/index.php$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root/index.php$fastcgi_script_name;
83 fastcgi_param WEB_ssl_session_id $ssl_session_id;
133 84
134 85 fastcgi_pass unix:/run/rocketgit.sock; fastcgi_pass unix:/run/rocketgit.sock;
135 86 } }
File samples/rocketgit-fs.service copied from file samples/rocketgit-builder.service (similarity 67%) (mode: 100644) (index 5b85769..8e3e8ed)
1 1 [Unit] [Unit]
2 Description=RocketGit build dispatcher
2 Description=RocketGit file system daemon
3 3
4 4 [Service] [Service]
5 5 Type=exec Type=exec
6 ExecStart=/usr/share/rocketgit/scripts/builder.sh
6 ExecStart=/usr/share/rocketgit/scripts/rgfs.sh
7 7 User=rocketgit User=rocketgit
8 8 Group=rocketgit Group=rocketgit
9 9 PrivateTmp=true PrivateTmp=true
File samples/sshd-akc.conf added (mode: 100644) (index 0000000..c32e884)
1 Match User rocketgit
2 AuthorizedKeysCommand /usr/sbin/rg_authorize %f
3 AuthorizedKeysCommandUser rocketgit
4 AuthenticationMethods publickey
5
File selinux/.gitignore changed (mode: 100644) (index 933ba1e..298ce56)
1 1 out out
2 2 restore.sh restore.sh
3 rocketgit.te
3 rocketgit.te
4 *.good
File techdocs/html_escape.txt added (mode: 100644) (index 0000000..0f21cf5)
1 The whole HTML encoding is a mess!
2
3 We have the following functions:
4 - htmlspecialchars &"'<> -> &amp; &quot; &apos; &lt; &gt;
5 - htmlentities htmlspecialchars + (è -> &egrave;) & co. Not used
6 - rawurlencode [^-_.~0-9a-zA-Z] -> %xx
7 - urlencode [^-_.0-9a-zA-Z] -> %xx + ' ' -> '+' Not used
8
9 We have the following RG things:
10 URL_ESCAPE: [rawurlencode()]
11 HTML_SPECIAL: [htmlspecialchars()]
12
13 What is the difference between @@URL_ESCAPE:var@@ and @@var@@? None.
14
15 We have the following cases:
16 - <a href="case1">case2</a>
17 - <a href="javascript:alert(document.cookie)">
18 Fix: be sure the above is not alone inside '"'.
19 - <a href="http://bla?x=1&2"> - we want x to be sent as '1&2', not '1'.
20 - <input ... value="untrusted"> - #2 - quote ' and "
21 - <a href="bla?value=UNTRUSTED"> - #5 - rawurlencode
22 - <bla>UNTRUSTED</bla> - #1 - htmlspecialchars
23
24 Dangers:
25 - XSS
26 - an var 'a/b/c' in context X/@@var@@/Y encoded as X/a/b/c/Y'.
27 - var='">danger<"'; string: '<a href="bla@@var@@">'
28
29 Info:
30 - https://stackoverflow.com/questions/4782988/url-html-escaping-encoding
31 They say, inside 'href' to use htmlspecialchars('?a=' . urlencode('b')).
32 Basically, only '&' is encoded by 'htmlspecialchars'.
33 For the rest of the cases, use 'htmlspecialchars'.
34 - https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
35
36 Plan:
37 - @@var@@ whould call htmlspecialchars - we assume that the majority of
38 the cases are things outside html tags (<>). [HTML Body]
39 So HTML_SPECIAL: will go.
40 - For URLs we have two cases:
41 - we want a path, so '/' must be escaped - need to find where I use this
42 - we have a file name and we do not want '/' to be escaped
43 @@URL_ESCAPE:var@@ [rawurlencode]
44 - What about 'ș' in URLs?
45 - What to do with rg_xss_safe()?
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/rocketgit

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main