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 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/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\"> </td></tr>\n"; |
$empty_line = "<tr style=\"border: 1px\"><td colspan=\"4\"> </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/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/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/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/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/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/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/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 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(); |