| File duilder added (mode: 100755) (index 0000000..62411b6) |
|
1 |
|
#!/bin/bash |
|
2 |
|
|
|
3 |
|
set -e |
|
4 |
|
|
|
5 |
|
function duilder_final() |
|
6 |
|
{ |
|
7 |
|
PRJ="${1}" |
|
8 |
|
VER="${2}" |
|
9 |
|
RELEASE_SCRIPT="${3}" |
|
10 |
|
|
|
11 |
|
# Run release script |
|
12 |
|
if [ ! -z "${RELEASE_SCRIPT}" -a -x "${RELEASE_SCRIPT}" ]; then |
|
13 |
|
echo "Running ${RELEASE_SCRIPT}..." |
|
14 |
|
${RELEASE_SCRIPT} |
|
15 |
|
fi |
|
16 |
|
} |
|
17 |
|
|
|
18 |
|
function duilder_docs() |
|
19 |
|
{ |
|
20 |
|
PRJ="${1}" |
|
21 |
|
VER="${2}" |
|
22 |
|
EXPORT_PATH="${3}" |
|
23 |
|
|
|
24 |
|
if [ ! -d "${EXPORT_PATH}" ]; then |
|
25 |
|
echo "WARN: ${EXPORT_PATH} does not exists. Skipping..." |
|
26 |
|
return |
|
27 |
|
fi |
|
28 |
|
|
|
29 |
|
echo "Copying docs to [${EXPORT_PATH}]..." |
|
30 |
|
for f in README License LICENSE Changelog Changelog-last TODO FAQ INSTALL; do |
|
31 |
|
if [ -r "${f}" ]; then |
|
32 |
|
cp -vp "${f}" "${EXPORT_PATH}/" |
|
33 |
|
fi |
|
34 |
|
done |
|
35 |
|
|
|
36 |
|
if [ -d "screenshot" ]; then |
|
37 |
|
echo "Copying screenshots..." |
|
38 |
|
mkdir -p "${EXPORT_PATH}" |
|
39 |
|
cp -vp screenshot/* "${EXPORT_PATH}/" |
|
40 |
|
fi |
|
41 |
|
} |
|
42 |
|
|
|
43 |
|
function duilder_git() |
|
44 |
|
{ |
|
45 |
|
PRJ="${1}" |
|
46 |
|
GIT_DEST="${2}" |
|
47 |
|
EXPORT_GIT="${3}" |
|
48 |
|
GIT_CHANGELOG="${4}" |
|
49 |
|
GIT_PUSH="${5}" |
|
50 |
|
|
|
51 |
|
if [ ! -x /usr/bin/git ]; then |
|
52 |
|
echo "Warning: Git not found!" |
|
53 |
|
exit 0 |
|
54 |
|
fi |
|
55 |
|
|
|
56 |
|
if [ ! -d .git ]; then |
|
57 |
|
echo "Warning: I cannot find .git directory!" |
|
58 |
|
exit 0 |
|
59 |
|
fi |
|
60 |
|
|
|
61 |
|
if [ "${EXPORT_GIT}" = "1" ]; then |
|
62 |
|
echo "Generate GIT tree for HTTP transport..." |
|
63 |
|
if [ ! -d "${GIT_DEST}/${PRJ}.git" ]; then |
|
64 |
|
git clone --bare . "${GIT_DEST}/${PRJ}.git" |
|
65 |
|
|
|
66 |
|
# Activate post-update hook |
|
67 |
|
cp "${GIT_DEST}/${PRJ}.git/hooks/post-update.sample" \ |
|
68 |
|
"${GIT_DEST}/${PRJ}.git/hooks/post-update" |
|
69 |
|
chmod a+x "${GIT_DEST}/${PRJ}.git/hooks/post-update" |
|
70 |
|
|
|
71 |
|
# add project name and description |
|
72 |
|
echo "${PRJ}" > "${GIT_DEST}/${PRJ}.git/description" |
|
73 |
|
|
|
74 |
|
# allow export by git daemon? |
|
75 |
|
#touch "${GIT_DEST}/${PRJ}.git/git-daemon-export-ok |
|
76 |
|
else |
|
77 |
|
# --force? |
|
78 |
|
echo "Running git push -v --all \"${GIT_DEST}/${PRJ}.git\"..." |
|
79 |
|
git push -v --all "${GIT_DEST}/${PRJ}.git" |
|
80 |
|
echo "Running git push -v --tags \"${GIT_DEST}/${PRJ}.git\"..." |
|
81 |
|
git push -v --tags "${GIT_DEST}/${PRJ}.git" |
|
82 |
|
fi |
|
83 |
|
(cd "${GIT_DEST}/${PRJ}.git" && git update-server-info) |
|
84 |
|
fi |
|
85 |
|
|
|
86 |
|
if [ "${GIT_PUSH}" = "1" ]; then |
|
87 |
|
echo "[*] Git push..." |
|
88 |
|
git push -v --all |
|
89 |
|
fi |
|
90 |
|
|
|
91 |
|
if [ "${GIT_CHANGELOG}" = "1" ]; then |
|
92 |
|
echo "[*] Generating Changelog from git..." |
|
93 |
|
echo -n > Changelog |
|
94 |
|
|
|
95 |
|
# get the list of tags |
|
96 |
|
i=0 |
|
97 |
|
number_of_tags=0 |
|
98 |
|
for tag in `git tag -l`; do |
|
99 |
|
if [ "${tag:0:1}" != "v" ]; then |
|
100 |
|
# skip other kind of tags beside versions |
|
101 |
|
continue |
|
102 |
|
fi |
|
103 |
|
|
|
104 |
|
tags[${i}]=${tag} |
|
105 |
|
tags_commit[${i}]=`git show-ref ${tag} | cut -d' ' -f1` |
|
106 |
|
number_of_tags=$[${number_of_tags}+1] |
|
107 |
|
|
|
108 |
|
i=$[${i}+1] |
|
109 |
|
done |
|
110 |
|
|
|
111 |
|
# get the list of commits, test if is a tag and do the diff |
|
112 |
|
prev="" |
|
113 |
|
add="" |
|
114 |
|
first=1 |
|
115 |
|
git log --pretty=oneline | cut -f1 | \ |
|
116 |
|
while read commit junk; do |
|
117 |
|
# test if it is a tag |
|
118 |
|
tag="" |
|
119 |
|
i=0 |
|
120 |
|
while [ "${i}" -lt "${number_of_tags}" ]; do |
|
121 |
|
if [ "${commit}" = "${tags_commit[${i}]}" ]; then |
|
122 |
|
tag="${tags[${i}]}" |
|
123 |
|
break |
|
124 |
|
fi |
|
125 |
|
|
|
126 |
|
i=$[${i}+1] |
|
127 |
|
done |
|
128 |
|
|
|
129 |
|
if [ -z "${tag}" ]; then |
|
130 |
|
continue |
|
131 |
|
fi |
|
132 |
|
|
|
133 |
|
if [ ! -z "${prev}" ]; then |
|
134 |
|
echo "[*] Generating Changelog from ${tag} -> ${prev}..." |
|
135 |
|
echo -en "${add}" >> Changelog |
|
136 |
|
add="\n" |
|
137 |
|
echo "[${tag} -> ${prev}]" >> Changelog |
|
138 |
|
git shortlog ${tag}..${prev} | \ |
|
139 |
|
(IFS="" |
|
140 |
|
while read line; do |
|
141 |
|
echo " ${line}" |
|
142 |
|
done) \ |
|
143 |
|
>> Changelog |
|
144 |
|
|
|
145 |
|
if [ "${first}" = "1" ]; then |
|
146 |
|
echo "[*] Generating Changelog-last..." |
|
147 |
|
cp Changelog Changelog-last |
|
148 |
|
first=0 |
|
149 |
|
fi |
|
150 |
|
fi |
|
151 |
|
prev=${tag} |
|
152 |
|
done |
|
153 |
|
fi |
|
154 |
|
} |
|
155 |
|
|
|
156 |
|
function duilder_srpm() |
|
157 |
|
{ |
|
158 |
|
PRJ="${1}" |
|
159 |
|
VER="${2}" |
|
160 |
|
EXPORT_PATH="${3}" |
|
161 |
|
BUILD_SRPM="${4}" |
|
162 |
|
SRPM_DEST="${5}" |
|
163 |
|
SRPM_POST_RUN="${6}" |
|
164 |
|
|
|
165 |
|
P="${PRJ}-${VER}" |
|
166 |
|
|
|
167 |
|
if [ ! -d "${EXPORT_PATH}" ]; then |
|
168 |
|
echo "WARN: ${EXPORT_PATH} does not exists. Skipping..." |
|
169 |
|
return |
|
170 |
|
fi |
|
171 |
|
|
|
172 |
|
if [ "${BUILD_SRPM}" != "1" ]; then |
|
173 |
|
exit 0 |
|
174 |
|
fi |
|
175 |
|
|
|
176 |
|
echo "Building SRPM..." |
|
177 |
|
rpmbuild -ts "${P}.tar.gz" |
|
178 |
|
|
|
179 |
|
PKG="${RPMBUILD}/SRPMS/${P}-1.src.rpm" |
|
180 |
|
|
|
181 |
|
# Run a rpmlint on it |
|
182 |
|
if [ -x /usr/bin/rpmlint ]; then |
|
183 |
|
echo "[*] RPMlinting..." |
|
184 |
|
rpmlint -iv "${PKG}" > rpmlint.out |
|
185 |
|
fi |
|
186 |
|
|
|
187 |
|
if [ ! -z "${SRPM_DEST}" ]; then |
|
188 |
|
echo "Copying [${PKG}] to [${SRPM_DEST}]..." |
|
189 |
|
cp -vp "${PKG}" "${SRPM_DEST}/" |
|
190 |
|
fi |
|
191 |
|
|
|
192 |
|
echo "Copying to export dir [${EXPORT_PATH}]..." |
|
193 |
|
mkdir -p "${EXPORT_PATH}" |
|
194 |
|
cp -vp "${PKG}" "${EXPORT_PATH}/" |
|
195 |
|
|
|
196 |
|
if [ -x "${SRPM_POST_RUN}" ]; then |
|
197 |
|
echo "Running post SRPM build script [${SRPM_POST_RUN}]..." |
|
198 |
|
${SRPM_POST_RUN} "${PKG}" |
|
199 |
|
fi |
|
200 |
|
} |
|
201 |
|
|
|
202 |
|
function duilder_tar() |
|
203 |
|
{ |
|
204 |
|
PRJ="${1}" |
|
205 |
|
VER="${2}" |
|
206 |
|
EXPORT_PATH="${3}" |
|
207 |
|
EXCLUDE="${4}" |
|
208 |
|
|
|
209 |
|
P="${PRJ}-${VER}" |
|
210 |
|
|
|
211 |
|
if [ ! -d "${EXPORT_PATH}" ]; then |
|
212 |
|
echo "WARN: ${EXPORT_PATH} does not exists. Skipping..." |
|
213 |
|
return |
|
214 |
|
fi |
|
215 |
|
|
|
216 |
|
echo "Generating tarball [${P}.tar.gz]..." |
|
217 |
|
ADD_EXCLUDE="" |
|
218 |
|
if [ ! -z "${EXCLUDE}" ]; then |
|
219 |
|
ADD_EXCLUDE="--exclude-from ${P}/${EXCLUDE}" |
|
220 |
|
fi |
|
221 |
|
|
|
222 |
|
(cd .. \ |
|
223 |
|
&& rm -rf "${P}" \ |
|
224 |
|
&& cp -a --link "${PRJ}" "${P}" \ |
|
225 |
|
&& tar czf "${PRJ}/${P}.tar.gz" \ |
|
226 |
|
--exclude-vcs \ |
|
227 |
|
--exclude ${P}/Makefile \ |
|
228 |
|
${ADD_EXCLUDE} \ |
|
229 |
|
"${P}" \ |
|
230 |
|
&& rm -rf "${P}" |
|
231 |
|
) |
|
232 |
|
|
|
233 |
|
echo "Copying source to ${EXPORT_PATH}/..." |
|
234 |
|
mkdir -p "${EXPORT_PATH}" |
|
235 |
|
cp -vp "${P}.tar.gz" "${EXPORT_PATH}/" |
|
236 |
|
} |
|
237 |
|
|
|
238 |
|
#################################################################### |
|
239 |
|
|
|
240 |
|
# Variables |
|
241 |
|
if [ -d "${HOME}/rpmbuild" ]; then |
|
242 |
|
RPMBUILD="${HOME}/rpmbuild" |
|
243 |
|
else |
|
244 |
|
RPMBUILD="/usr/src/redhat" |
|
245 |
|
fi |
|
246 |
|
|
|
247 |
|
|
|
248 |
|
if [ ! -r duilder.conf ]; then |
|
249 |
|
echo "You must build a duilder.conf file!" |
|
250 |
|
exit 1 |
|
251 |
|
fi |
|
252 |
|
|
|
253 |
|
source ${PWD}/duilder.conf |
|
254 |
|
|
|
255 |
|
# fixes |
|
256 |
|
if [ -z "${GIT_DEST}" ]; then |
|
257 |
|
GIT_DEST="${EXPORT_PATH}" |
|
258 |
|
fi |
|
259 |
|
|
|
260 |
|
if [ -z "${PRJ}" ]; then |
|
261 |
|
echo "ERROR: PRJ= parameter is missing." |
|
262 |
|
exit 1 |
|
263 |
|
fi |
|
264 |
|
|
|
265 |
|
if [ -z "${VER}" ]; then |
|
266 |
|
echo "ERROR: PRJ= parameter is missing." |
|
267 |
|
exit 1 |
|
268 |
|
fi |
|
269 |
|
|
|
270 |
|
if [ -z "${REV}" ]; then |
|
271 |
|
echo "ERROR: REV= parameter is missing." |
|
272 |
|
exit 1 |
|
273 |
|
fi |
|
274 |
|
|
|
275 |
|
# export variables - just in case a script cares |
|
276 |
|
export PRJ VER REV EXPORT_PATH EXPORT_GIT GIT_PUSH GIT_DEST SRPM_DEST LICENSE |
|
277 |
|
|
|
278 |
|
|
|
279 |
|
# Multiplexer |
|
280 |
|
if [ "${1}" = "docs" ]; then |
|
281 |
|
shift |
|
282 |
|
duilder_docs "$@" |
|
283 |
|
exit $? |
|
284 |
|
fi |
|
285 |
|
|
|
286 |
|
if [ "${1}" = "tar" ]; then |
|
287 |
|
shift |
|
288 |
|
duilder_tar "$@" |
|
289 |
|
exit $? |
|
290 |
|
fi |
|
291 |
|
|
|
292 |
|
if [ "${1}" = "git" ]; then |
|
293 |
|
shift |
|
294 |
|
duilder_git "$@" |
|
295 |
|
exit $? |
|
296 |
|
fi |
|
297 |
|
|
|
298 |
|
if [ "${1}" = "srpm" ]; then |
|
299 |
|
shift |
|
300 |
|
duilder_srpm "$@" |
|
301 |
|
exit $? |
|
302 |
|
fi |
|
303 |
|
|
|
304 |
|
if [ "${1}" = "final" ]; then |
|
305 |
|
shift |
|
306 |
|
duilder_final "$@" |
|
307 |
|
exit $? |
|
308 |
|
fi |
|
309 |
|
|
|
310 |
|
|
|
311 |
|
###### Main stuff |
|
312 |
|
echo |
|
313 |
|
echo "Duilder builder script" |
|
314 |
|
echo "Copyright Catalin(ux) M. BOIE" |
|
315 |
|
echo |
|
316 |
|
echo "PRJ=${PRJ}, VER=${VER}, REV=${REV}" |
|
317 |
|
echo "System: `uname -a`" |
|
318 |
|
|
|
319 |
|
ETC="/etc" |
|
320 |
|
BIN="/bin" |
|
321 |
|
USR_BIN="/usr/bin" |
|
322 |
|
USR_SBIN="/usr/sbin" |
|
323 |
|
USR_INCLUDE="/usr/include" |
|
324 |
|
USR_LIB="/usr/lib" |
|
325 |
|
USR_SHARE="/usr/share" |
|
326 |
|
USR_SHARE_DOC="/usr/share/doc/${PRJ}-${VER}" |
|
327 |
|
SBIN="/usr/sbin" |
|
328 |
|
VAR="/var" |
|
329 |
|
VAR_LOG="/var/log/${PRJ}" |
|
330 |
|
|
|
331 |
|
while [ "${1}" != "" ]; do |
|
332 |
|
VAR="`echo ${1} | cut -d'=' -f1`" |
|
333 |
|
VAL="`echo ${1} | cut -d'=' -f2`" |
|
334 |
|
case ${VAR} in |
|
335 |
|
--sysconfdir) |
|
336 |
|
ETC="${VAL}" |
|
337 |
|
;; |
|
338 |
|
--bindir) |
|
339 |
|
USR_BIN="${VAL}" |
|
340 |
|
;; |
|
341 |
|
--sbindir) |
|
342 |
|
USR_SBIN="${VAL}" |
|
343 |
|
;; |
|
344 |
|
--includedir) |
|
345 |
|
USR_INCLUDE="${VAL}" |
|
346 |
|
;; |
|
347 |
|
--libdir) |
|
348 |
|
USR_LIB="${VAL}" |
|
349 |
|
;; |
|
350 |
|
--localstatedir) |
|
351 |
|
VAR="${VAL}" |
|
352 |
|
;; |
|
353 |
|
--datadir) |
|
354 |
|
USR_SHARE="${VAL}" |
|
355 |
|
;; |
|
356 |
|
esac |
|
357 |
|
shift |
|
358 |
|
done |
|
359 |
|
|
|
360 |
|
# Truncate future sed file |
|
361 |
|
> tmp.sed |
|
362 |
|
|
|
363 |
|
DB_SUPPORT=0 |
|
364 |
|
|
|
365 |
|
echo -n "Searching for PostgreSQL..." |
|
366 |
|
set +e |
|
367 |
|
PG_VERSION="`pg_config --version 2>/dev/null`" |
|
368 |
|
set -e |
|
369 |
|
if [ -z "${PG_VERSION}" ]; then |
|
370 |
|
echo " not found." |
|
371 |
|
PG_FOUND=0 |
|
372 |
|
else |
|
373 |
|
echo " found version ${PG_VERSION}." |
|
374 |
|
PG_FOUND=1 |
|
375 |
|
PG_INC="-I`pg_config --includedir`" |
|
376 |
|
PG_LIB="-L`pg_config --libdir` -lpq" |
|
377 |
|
|
|
378 |
|
echo "s#@PG_VERSION@#${PG_VERSION}#g" >> tmp.sed |
|
379 |
|
echo "s#@PG_INC@#${PG_INC}#g" >> tmp.sed |
|
380 |
|
echo "s#@PG_LIB@#${PG_LIB}#g" >> tmp.sed |
|
381 |
|
|
|
382 |
|
DB_SUPPORT=1 |
|
383 |
|
echo "s#@DB_SUPPORT@#${DB_SUPPORT}#g" >> tmp.sed |
|
384 |
|
fi |
|
385 |
|
echo "s#@PG_FOUND@#${PG_FOUND}#g" >> tmp.sed |
|
386 |
|
|
|
387 |
|
|
|
388 |
|
echo -n "Searching for MySQL..." |
|
389 |
|
set +e |
|
390 |
|
MYSQL_VERSION="`mysql_config --version 2>/dev/null`" |
|
391 |
|
set -e |
|
392 |
|
if [ -z "${MYSQL_VERSION}" ]; then |
|
393 |
|
echo " not found." |
|
394 |
|
MYSQL_FOUND=0 |
|
395 |
|
else |
|
396 |
|
echo " found version ${MYSQL_VERSION}." |
|
397 |
|
MYSQL_FOUND=1 |
|
398 |
|
MYSQL_INC="`mysql_config --include`" |
|
399 |
|
MYSQL_LIB="`mysql_config --libs`" |
|
400 |
|
|
|
401 |
|
echo "s#@MYSQL_VERSION@#${MYSQL_VERSION}#g" >> tmp.sed |
|
402 |
|
echo "s#@MYSQL_INC@#${MYSQL_INC}#g" >> tmp.sed |
|
403 |
|
echo "s#@MYSQL_LIB@#${MYSQL_LIB}#g" >> tmp.sed |
|
404 |
|
|
|
405 |
|
DB_SUPPORT=1 |
|
406 |
|
echo "s#@DB_SUPPORT@#${DB_SUPPORT}#g" >> tmp.sed |
|
407 |
|
fi |
|
408 |
|
echo "s#@MYSQL_FOUND@#${MYSQL_FOUND}#g" >> tmp.sed |
|
409 |
|
|
|
410 |
|
echo -n "Searching for poll..." |
|
411 |
|
set +e |
|
412 |
|
echo -e "#include <poll.h> \n int main(void) { return poll(0, 0, 0); }" | gcc -x c -pipe - -o /dev/null 2>/dev/null |
|
413 |
|
E="${?}" |
|
414 |
|
set -e |
|
415 |
|
if [ "${E}" != "0" ]; then |
|
416 |
|
echo " not found." |
|
417 |
|
echo "s#@POLL_FOUND@#0#g" >> tmp.sed |
|
418 |
|
else |
|
419 |
|
echo " found." |
|
420 |
|
echo "s#@POLL_FOUND@#1#g" >> tmp.sed |
|
421 |
|
fi |
|
422 |
|
|
|
423 |
|
echo -n "Searching for epoll..." |
|
424 |
|
set +e |
|
425 |
|
echo -e "#include <sys/epoll.h> \n int main(void) { return epoll_create(64); }" | gcc -x c -pipe - -o /dev/null 2>/dev/null |
|
426 |
|
E="${?}" |
|
427 |
|
set -e |
|
428 |
|
if [ "${E}" != "0" ]; then |
|
429 |
|
echo " not found." |
|
430 |
|
echo "s#@EPOLL_FOUND@#0#g" >> tmp.sed |
|
431 |
|
else |
|
432 |
|
echo " found." |
|
433 |
|
echo "s#@EPOLL_FOUND@#1#g" >> tmp.sed |
|
434 |
|
fi |
|
435 |
|
|
|
436 |
|
echo -n "Searching for ncurses..." |
|
437 |
|
set +e |
|
438 |
|
echo -e "#include <ncurses.h> \n int main(void) { initscr(); return 0; }" | gcc -x c -pipe - -o /dev/null -lncurses 2>/dev/null |
|
439 |
|
E="${?}" |
|
440 |
|
set -e |
|
441 |
|
if [ "${E}" != "0" ]; then |
|
442 |
|
echo " not found." |
|
443 |
|
echo "s#@NCURSES_FOUND@#0#g" >> tmp.sed |
|
444 |
|
else |
|
445 |
|
echo " found." |
|
446 |
|
echo "s#@NCURSES_FOUND@#1#g" >> tmp.sed |
|
447 |
|
fi |
|
448 |
|
|
|
449 |
|
# generic stuff |
|
450 |
|
echo "s#@PRJ@#${PRJ}#g" >> tmp.sed |
|
451 |
|
echo "s#@VER@#${VER}#g" >> tmp.sed |
|
452 |
|
echo "s#@REV@#${REV}#g" >> tmp.sed |
|
453 |
|
echo "s#@ETC@#${ETC}#g" >> tmp.sed |
|
454 |
|
echo "s#@BIN@#${BIN}#g" >> tmp.sed |
|
455 |
|
echo "s#@USR_BIN@#${USR_BIN}#g" >> tmp.sed |
|
456 |
|
echo "s#@SBIN@#${SBIN}#g" >> tmp.sed |
|
457 |
|
echo "s#@USR_SBIN@#${USR_SBIN}#g" >> tmp.sed |
|
458 |
|
echo "s#@VAR@#${VAR}#g" >> tmp.sed |
|
459 |
|
echo "s#@VAR_LOG@#${VAR_LOG}#g" >> tmp.sed |
|
460 |
|
echo "s#@USR_INCLUDE@#${USR_INCLUDE}#g" >> tmp.sed |
|
461 |
|
echo "s#@USR_INC@#${USR_INCLUDE}#g" >> tmp.sed |
|
462 |
|
echo "s#@USR_LIB@#${USR_LIB}#g" >> tmp.sed |
|
463 |
|
echo "s#@USR_SHARE@#${USR_SHARE}#g" >> tmp.sed |
|
464 |
|
echo "s#@USR_SHARE_DOC@#${USR_SHARE_DOC}#g" >> tmp.sed |
|
465 |
|
# Export stuff |
|
466 |
|
echo "s#@EXPORT_PATH@#${EXPORT_PATH}#g" >> tmp.sed |
|
467 |
|
|
|
468 |
|
|
|
469 |
|
|
|
470 |
|
if [ -r Makefile.in ]; then |
|
471 |
|
echo "Building Makefile..." |
|
472 |
|
echo -n > Makefile |
|
473 |
|
echo "# duilder header starts #" >> Makefile |
|
474 |
|
echo "export PRJ := ${PRJ}" >> Makefile |
|
475 |
|
echo "export VER := ${VER}" >> Makefile |
|
476 |
|
echo "export REV := ${REV}" >> Makefile |
|
477 |
|
echo "export DESTDIR" >> Makefile |
|
478 |
|
echo >> Makefile |
|
479 |
|
echo "export I_ETC := \$(DESTDIR)${ETC}" >> Makefile |
|
480 |
|
echo "export I_BIN := \$(DESTDIR)${BIN}" >> Makefile |
|
481 |
|
echo "export I_SBIN := \$(DESTDIR)${SBIN}" >> Makefile |
|
482 |
|
echo "export I_USR_BIN := \$(DESTDIR)${USR_BIN}" >> Makefile |
|
483 |
|
echo "export I_USR_SBIN := \$(DESTDIR)${USR_SBIN}" >> Makefile |
|
484 |
|
echo "export I_USR_INCLUDE := \$(DESTDIR)${USR_INCLUDE}" >> Makefile |
|
485 |
|
echo "export I_USR_INC := \$(DESTDIR)${USR_INCLUDE}" >> Makefile |
|
486 |
|
echo "export I_USR_SHARE := \$(DESTDIR)${USR_SHARE}" >> Makefile |
|
487 |
|
echo "export I_USR_SHARE_DOC := \$(DESTDIR)${USR_SHARE_DOC}" >> Makefile |
|
488 |
|
echo "export I_USR_LIB := \$(DESTDIR)${USR_LIB}" >> Makefile |
|
489 |
|
echo "export I_LIB := \$(DESTDIR)${USR_LIB}" >> Makefile |
|
490 |
|
echo "export I_VAR := \$(DESTDIR)${VAR}" >> Makefile |
|
491 |
|
echo "export I_VAR_LOG := \$(DESTDIR)${VAR_LOG}" >> Makefile |
|
492 |
|
echo >> Makefile |
|
493 |
|
echo "# DB stuff" >> Makefile |
|
494 |
|
echo "export DB_SUPPORT := ${DB_SUPPORT}" >> Makefile |
|
495 |
|
echo "# PG" >> Makefile |
|
496 |
|
echo "export PG_FOUND := ${PG_FOUND}" >> Makefile |
|
497 |
|
echo "export PG_INC := ${PG_INC}" >> Makefile |
|
498 |
|
echo "export PG_LIB := ${PG_LIB}" >> Makefile |
|
499 |
|
echo "# MySQL" >> Makefile |
|
500 |
|
echo "export MYSQL_FOUND := ${MYSQL_FOUND}" >> Makefile |
|
501 |
|
echo "export MYSQL_INC := ${MYSQL_INC}" >> Makefile |
|
502 |
|
echo "export MYSQL_LIB := ${MYSQL_LIB}" >> Makefile |
|
503 |
|
echo >> Makefile |
|
504 |
|
echo "# duilder header ends #" >> Makefile |
|
505 |
|
echo >> Makefile |
|
506 |
|
|
|
507 |
|
sed -f tmp.sed Makefile.in >> Makefile |
|
508 |
|
|
|
509 |
|
echo >> Makefile |
|
510 |
|
echo "# duilder tail starts #" >> Makefile |
|
511 |
|
echo >> Makefile |
|
512 |
|
echo "# This is to allow exporting only the git tree" >> Makefile |
|
513 |
|
echo "dist_git:" >> Makefile |
|
514 |
|
echo " @./duilder git \"\$(PRJ)\" \"${GIT_DEST}\" \"${EXPORT_GIT}\" \"${EXPORT_PATH}\" \"${GIT_CHANGELOG}\"" >> Makefile |
|
515 |
|
echo >> Makefile |
|
516 |
|
echo ".PHONY: dist" >> Makefile |
|
517 |
|
echo "dist: clean" >> Makefile |
|
518 |
|
echo " @./duilder git \"\$(PRJ)\" \"${GIT_DEST}\" \"${EXPORT_GIT}\" \"${GIT_CHANGELOG}\"" \"${GIT_PUSH}\" >> Makefile |
|
519 |
|
echo " @./duilder tar \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\" \"${EXCLUDE}\"" >> Makefile |
|
520 |
|
echo " @./duilder srpm \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\" \"${BUILD_SRPM}\" \"${SRPM_DEST}\" \"${SRPM_POST_RUN}\"" >> Makefile |
|
521 |
|
echo " @./duilder docs \"\$(PRJ)\" \"\$(VER)\" \"${EXPORT_PATH}\"" >> Makefile |
|
522 |
|
echo " @./duilder final \"\$(PRJ)\" \"\$(VER)\" \"${RELEASE_SCRIPT}\"" >> Makefile |
|
523 |
|
echo " @rm -f \"\$(PRJ)-\$(VER).tar.gz\"" >> Makefile |
|
524 |
|
echo >> Makefile |
|
525 |
|
fi |
|
526 |
|
|
|
527 |
|
if [ -r "${PRJ}.spec.in" ]; then |
|
528 |
|
echo "Generate .spec file..." |
|
529 |
|
sed -f tmp.sed ${PRJ}.spec.in > ${PRJ}.spec |
|
530 |
|
fi |
|
531 |
|
|
|
532 |
|
if [ ! -z "${CONFIG_H}" ]; then |
|
533 |
|
echo "Generating ${CONFIG_H} file..." |
|
534 |
|
sed -f tmp.sed ${CONFIG_H}.in > ${CONFIG_H} |
|
535 |
|
fi |
|
536 |
|
|
|
537 |
|
rm -f tmp.sed |
|
538 |
|
|
|
539 |
|
if [ "`basename ${0}`" = "duilderx" ]; then |
|
540 |
|
echo "Clone myself to destination as 'duilder'..." |
|
541 |
|
cp -vpf "${0}" ${PWD}/duilder |
|
542 |
|
fi |
|
543 |
|
|
|
544 |
|
echo "Done. Run make." |
| File inc/repo.inc.php changed (mode: 100644) (index 92959fc..e07ec4c) |
| ... |
... |
require_once($INC . "/log.inc.php"); |
| 4 |
4 |
require_once($INC . "/db.inc.php"); |
require_once($INC . "/db.inc.php"); |
| 5 |
5 |
require_once($INC . "/user.inc.php"); |
require_once($INC . "/user.inc.php"); |
| 6 |
6 |
require_once($INC . "/git.inc.php"); |
require_once($INC . "/git.inc.php"); |
|
7 |
|
require_once($INC . "/rights.inc.php"); |
|
8 |
|
|
|
9 |
|
$rg_repo_zero = "0000000000000000000000000000000000000000"; |
|
10 |
|
$rg_repo_empty = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; |
| 7 |
11 |
|
|
| 8 |
12 |
$rg_repo_error = ""; |
$rg_repo_error = ""; |
| 9 |
13 |
|
|
| 10 |
|
$rg_repo_rights = array("A" => "Admin", |
|
| 11 |
|
"F" => "Fetch", |
|
| 12 |
|
"P" => "Push", |
|
| 13 |
|
"D" => "Delete branch"); |
|
|
14 |
|
$rg_repo_rights = array( |
|
15 |
|
"A" => "Admin", |
|
16 |
|
"F" => "Fetch", |
|
17 |
|
"P" => "Push", |
|
18 |
|
"D" => "Delete branch", |
|
19 |
|
"t" => "Delete tag", |
|
20 |
|
"T" => "Modify tag", |
|
21 |
|
"C" => "Create branch" |
|
22 |
|
); |
|
23 |
|
|
|
24 |
|
rg_rights_register("repo", $rg_repo_rights); |
|
25 |
|
|
| 14 |
26 |
|
|
| 15 |
27 |
function rg_repo_set_error($str) |
function rg_repo_set_error($str) |
| 16 |
28 |
{ |
{ |
| |
| ... |
... |
function rg_repo_ok($repo) |
| 34 |
46 |
global $rg_repo_allow; |
global $rg_repo_allow; |
| 35 |
47 |
global $rg_repo_max_len; |
global $rg_repo_max_len; |
| 36 |
48 |
|
|
|
49 |
|
if (empty($repo)) { |
|
50 |
|
rg_repo_set_error("Invalid repository name (empty)"); |
|
51 |
|
return FALSE; |
|
52 |
|
} |
|
53 |
|
|
| 37 |
54 |
if (rg_chars_allow($repo, $rg_repo_allow) === FALSE) { |
if (rg_chars_allow($repo, $rg_repo_allow) === FALSE) { |
| 38 |
|
rg_repo_set_error("Invalid repository name"); |
|
|
55 |
|
rg_repo_set_error("Invalid repository name (invalid chars)"); |
| 39 |
56 |
return FALSE; |
return FALSE; |
| 40 |
57 |
} |
} |
| 41 |
58 |
|
|
| 42 |
|
if (preg_match('/\.\./', $repo)) { |
|
| 43 |
|
rg_repo_set_error("Invalid repository name"); |
|
|
59 |
|
if (preg_match('/\.\./', $repo) > 0) { |
|
60 |
|
rg_repo_set_error("Invalid repository name (..)"); |
| 44 |
61 |
return FALSE; |
return FALSE; |
| 45 |
62 |
} |
} |
| 46 |
63 |
|
|
| |
| ... |
... |
function rg_repo_ok($repo) |
| 53 |
70 |
} |
} |
| 54 |
71 |
|
|
| 55 |
72 |
/* |
/* |
| 56 |
|
* Returns the path to a repository based on repo_id |
|
|
73 |
|
* Returns the path to a repository based on name |
| 57 |
74 |
*/ |
*/ |
| 58 |
|
function rg_repo_id2base($repo_id) |
|
|
75 |
|
function rg_repo_name2base($repo) |
| 59 |
76 |
{ |
{ |
| 60 |
77 |
global $rg_base_repo; |
global $rg_base_repo; |
| 61 |
78 |
|
|
| 62 |
|
$r3 = sprintf("%03u", $repo_id % 1000); |
|
|
79 |
|
$len = strlen($repo); |
|
80 |
|
$v = $repo; |
|
81 |
|
if ($len == 1) |
|
82 |
|
$v .= "_"; |
| 63 |
83 |
|
|
| 64 |
84 |
return $rg_base_repo . "/" |
return $rg_base_repo . "/" |
| 65 |
|
. $r3[0] . "/" . $r3[1] . "/" . $r3[2] . "/"; |
|
|
85 |
|
. $v[0] . "/" . $v[1] . "/"; |
| 66 |
86 |
} |
} |
| 67 |
87 |
|
|
| 68 |
88 |
/* |
/* |
| |
| ... |
... |
function rg_repo_id2base($repo_id) |
| 70 |
90 |
*/ |
*/ |
| 71 |
91 |
function rg_repo_info($db, $repo_id, $repo) |
function rg_repo_info($db, $repo_id, $repo) |
| 72 |
92 |
{ |
{ |
| 73 |
|
rg_log("repo_info: repo_id=$repo_id, repo=$repo..."); |
|
|
93 |
|
rg_log("repo_info: repo_id/repo=[$repo_id/$repo]..."); |
| 74 |
94 |
|
|
| 75 |
95 |
$ret['ok'] = 0; |
$ret['ok'] = 0; |
| 76 |
96 |
$ret['exists'] = 0; |
$ret['exists'] = 0; |
| |
| ... |
... |
function rg_repo_info($db, $repo_id, $repo) |
| 110 |
130 |
*/ |
*/ |
| 111 |
131 |
function rg_repo_allow($db, $ri, $rg_ui, $needed_rights) |
function rg_repo_allow($db, $ri, $rg_ui, $needed_rights) |
| 112 |
132 |
{ |
{ |
| 113 |
|
rg_log("repo_allow: rg_uid=" . $rg_ui['uid'] |
|
|
133 |
|
rg_log("repo_allow: repo_id=" . $ri['repo_id'] |
|
134 |
|
. " rg_uid=" . $rg_ui['uid'] |
| 114 |
135 |
. ", needed_rights=$needed_rights..."); |
. ", needed_rights=$needed_rights..."); |
| 115 |
136 |
|
|
| 116 |
137 |
if ($rg_ui['is_admin'] == 1) { |
if ($rg_ui['is_admin'] == 1) { |
| |
| ... |
... |
function rg_repo_allow($db, $ri, $rg_ui, $needed_rights) |
| 123 |
144 |
return FALSE; |
return FALSE; |
| 124 |
145 |
} |
} |
| 125 |
146 |
|
|
| 126 |
|
$rr = rg_repo_rights_get($db, $ri, $rg_ui['uid']); |
|
| 127 |
|
if ($rr['ok'] != 1) { |
|
| 128 |
|
rg_repo_set_error("No access!"); |
|
| 129 |
|
return FALSE; |
|
|
147 |
|
// anonymous acess (git://...) |
|
148 |
|
if ($rg_ui['uid'] == 0) { |
|
149 |
|
$db_rights = $ri['default_rights']; |
|
150 |
|
} else { |
|
151 |
|
$rr = rg_repo_rights_get($db, $ri, $rg_ui['uid'], 0); |
|
152 |
|
if ($rr['ok'] != 1) { |
|
153 |
|
rg_repo_set_error("No access!"); |
|
154 |
|
return FALSE; |
|
155 |
|
} |
|
156 |
|
$db_rights = $rr['rights']; |
| 130 |
157 |
} |
} |
| 131 |
|
rg_log("\tdb rights: " . $rr['rights']); |
|
|
158 |
|
rg_log("\tdb rights: " . $db_rights); |
| 132 |
159 |
|
|
| 133 |
160 |
$len = strlen($needed_rights); |
$len = strlen($needed_rights); |
| 134 |
161 |
for ($i = 0; $i < $len; $i++) { |
for ($i = 0; $i < $len; $i++) { |
| 135 |
|
if (!strstr($rr['rights'], $needed_rights[$i])) { |
|
|
162 |
|
if (!strstr($db_rights, $needed_rights[$i])) { |
| 136 |
163 |
rg_repo_set_error("No rights (" . $needed_rights[$i] . ")"); |
rg_repo_set_error("No rights (" . $needed_rights[$i] . ")"); |
| 137 |
164 |
return FALSE; |
return FALSE; |
| 138 |
165 |
} |
} |
| |
| ... |
... |
function rg_repo_allow($db, $ri, $rg_ui, $needed_rights) |
| 149 |
176 |
* TODO: put all fields into an array! |
* TODO: put all fields into an array! |
| 150 |
177 |
*/ |
*/ |
| 151 |
178 |
function rg_repo_create($db, $master, $rg_ui, $name, $max_commit_size, $desc, |
function rg_repo_create($db, $master, $rg_ui, $name, $max_commit_size, $desc, |
| 152 |
|
$rights) |
|
|
179 |
|
$rights, $max_users) |
| 153 |
180 |
{ |
{ |
| 154 |
181 |
// TODO: reorder parameters - are not logical |
// TODO: reorder parameters - are not logical |
| 155 |
182 |
rg_log("repo_create: rg_uid=" . $rg_ui['uid'] |
rg_log("repo_create: rg_uid=" . $rg_ui['uid'] |
| 156 |
183 |
. ", name=[$name], master=$master" |
. ", name=[$name], master=$master" |
| 157 |
184 |
. ", max_commit_size=$max_commit_size, desc=[$desc]" |
. ", max_commit_size=$max_commit_size, desc=[$desc]" |
| 158 |
|
. ", rights=$rights..."); |
|
|
185 |
|
. ", rights=$rights, max_users=$max_users..."); |
|
186 |
|
|
|
187 |
|
// TODO: test if user is allowed to add a repository |
| 159 |
188 |
|
|
| 160 |
189 |
if (rg_repo_ok($name) === FALSE) |
if (rg_repo_ok($name) === FALSE) |
| 161 |
190 |
return FALSE; |
return FALSE; |
| |
| ... |
... |
function rg_repo_create($db, $master, $rg_ui, $name, $max_commit_size, $desc, |
| 175 |
204 |
$itime = time(); |
$itime = time(); |
| 176 |
205 |
|
|
| 177 |
206 |
$sql = "INSERT INTO repos (uid, master, name, itime" |
$sql = "INSERT INTO repos (uid, master, name, itime" |
| 178 |
|
. ", max_commit_size, desc, git_dir_done, default_rights)" |
|
|
207 |
|
. ", max_commit_size, desc, git_dir_done, default_rights" |
|
208 |
|
. ", max_users)" |
| 179 |
209 |
. " VALUES (" . $rg_ui['uid'] . ", $master, '$e_name', $itime" |
. " VALUES (" . $rg_ui['uid'] . ", $master, '$e_name', $itime" |
| 180 |
|
. ", $max_commit_size, '$e_desc', 0, '$rights')"; |
|
|
210 |
|
. ", $max_commit_size, '$e_desc', 0, '$rights', $max_users)"; |
| 181 |
211 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
| 182 |
212 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 183 |
213 |
rg_repo_set_error("Cannot insert (" . rg_sql_error() . ")"); |
rg_repo_set_error("Cannot insert (" . rg_sql_error() . ")"); |
| |
| ... |
... |
function rg_repo_update($db, &$new) |
| 222 |
252 |
. ", name=[" . $new['name'] . "]" |
. ", name=[" . $new['name'] . "]" |
| 223 |
253 |
. ", max_commit_size=" . $new['max_commit_size'] |
. ", max_commit_size=" . $new['max_commit_size'] |
| 224 |
254 |
. ", desc=[" . $new['desc'] . "]" |
. ", desc=[" . $new['desc'] . "]" |
| 225 |
|
. ", default_rights=" . $new['default_rights']); |
|
|
255 |
|
. ", default_rights=" . $new['default_rights'] |
|
256 |
|
. ", max_users=" . $new['max_users']); |
| 226 |
257 |
|
|
| 227 |
|
if (rg_repo_ok($new['name']) === FALSE) |
|
|
258 |
|
if (rg_repo_ok($new['name']) !== TRUE) |
| 228 |
259 |
return FALSE; |
return FALSE; |
| 229 |
260 |
|
|
| 230 |
261 |
// First, test if it already exists |
// First, test if it already exists |
| |
| ... |
... |
function rg_repo_update($db, &$new) |
| 252 |
283 |
. ", max_commit_size = " . $new['max_commit_size'] |
. ", max_commit_size = " . $new['max_commit_size'] |
| 253 |
284 |
. ", desc = '$e_desc'" |
. ", desc = '$e_desc'" |
| 254 |
285 |
. ", default_rights = '" . $new['default_rights'] . "'" |
. ", default_rights = '" . $new['default_rights'] . "'" |
|
286 |
|
. ", max_users = " . $new['max_users'] |
| 255 |
287 |
. " WHERE repo_id = " . $new['repo_id']; |
. " WHERE repo_id = " . $new['repo_id']; |
| 256 |
288 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
| 257 |
289 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| |
| ... |
... |
function rg_repo_update($db, &$new) |
| 268 |
300 |
*/ |
*/ |
| 269 |
301 |
function rg_repo_list_query($db, $url, $sql) |
function rg_repo_list_query($db, $url, $sql) |
| 270 |
302 |
{ |
{ |
|
303 |
|
global $rg_ui; |
|
304 |
|
|
| 271 |
305 |
rg_log("repo_list_query: url=$url, sql=$sql..."); |
rg_log("repo_list_query: url=$url, sql=$sql..."); |
| 272 |
306 |
|
|
| 273 |
307 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
| 274 |
308 |
if ($res === FALSE) |
if ($res === FALSE) |
| 275 |
309 |
return FALSE; |
return FALSE; |
| 276 |
310 |
|
|
|
311 |
|
$admin_mode = 0; |
|
312 |
|
if ($rg_ui['is_admin'] == 1) |
|
313 |
|
$admin_mode = 1; |
|
314 |
|
|
| 277 |
315 |
$ret = "<table>\n"; |
$ret = "<table>\n"; |
| 278 |
316 |
$ret .= "<tr>\n"; |
$ret .= "<tr>\n"; |
| 279 |
317 |
$ret .= " <th>Name</th>\n"; |
$ret .= " <th>Name</th>\n"; |
|
318 |
|
if ($admin_mode == 1) |
|
319 |
|
$ret .= " <th>Owner</th>\n"; |
| 280 |
320 |
$ret .= " <th>Description</th>\n"; |
$ret .= " <th>Description</th>\n"; |
| 281 |
321 |
$ret .= " <th>Clone of</th>\n"; |
$ret .= " <th>Clone of</th>\n"; |
| 282 |
322 |
$ret .= " <th>Creation date (UTC)</th>\n"; |
$ret .= " <th>Creation date (UTC)</th>\n"; |
| 283 |
323 |
$ret .= " <th>Default rights</th>\n"; |
$ret .= " <th>Default rights</th>\n"; |
| 284 |
324 |
$ret .= " <th>Disk current/max</th>\n"; |
$ret .= " <th>Disk current/max</th>\n"; |
| 285 |
325 |
$ret .= " <th>Max commit size</th>\n"; |
$ret .= " <th>Max commit size</th>\n"; |
|
326 |
|
$ret .= " <th>Max users</th>\n"; |
| 286 |
327 |
$ret .= "</tr>\n"; |
$ret .= "</tr>\n"; |
|
328 |
|
|
| 287 |
329 |
while (($row = rg_sql_fetch_array($res))) { |
while (($row = rg_sql_fetch_array($res))) { |
| 288 |
330 |
$ret .= "<tr>\n"; |
$ret .= "<tr>\n"; |
| 289 |
331 |
$_link = rg_re_repopage($row['repo_id'], $row['name']); |
$_link = rg_re_repopage($row['repo_id'], $row['name']); |
| 290 |
332 |
$ret .= " <td><a href=\"$_link\">" . $row['name'] . "</a></td>\n"; |
$ret .= " <td><a href=\"$_link\">" . $row['name'] . "</a></td>\n"; |
|
333 |
|
if ($admin_mode == 1) { |
|
334 |
|
$_ui = rg_user_info($db, $row['uid'], "", ""); |
|
335 |
|
if ($_ui['exists'] != 1) |
|
336 |
|
$v = "?" . $row['uid'] . "?"; |
|
337 |
|
else |
|
338 |
|
$v = $_ui['user']; |
|
339 |
|
$ret .= " <td>$v</td>\n"; |
|
340 |
|
} |
| 291 |
341 |
$ret .= " <td><small>" . nl2br($row['desc']) . "</small></td>\n"; |
$ret .= " <td><small>" . nl2br($row['desc']) . "</small></td>\n"; |
| 292 |
342 |
if ($row['master'] > 0) { |
if ($row['master'] > 0) { |
| 293 |
343 |
$master_repo = "?"; |
$master_repo = "?"; |
| |
| ... |
... |
function rg_repo_list_query($db, $url, $sql) |
| 299 |
349 |
$ret .= " <td>" . gmdate("Y-m-d H:i:s", $row['itime']) . "</td>\n"; |
$ret .= " <td>" . gmdate("Y-m-d H:i:s", $row['itime']) . "</td>\n"; |
| 300 |
350 |
|
|
| 301 |
351 |
// rights |
// rights |
| 302 |
|
$_r = implode(", ", rg_repo_rights_text($row['default_rights'])); |
|
|
352 |
|
$_r = implode(", ", rg_rights_text("repo", $row['default_rights'])); |
| 303 |
353 |
$ret .= " <td>" . $_r . "</td>\n"; |
$ret .= " <td>" . $_r . "</td>\n"; |
| 304 |
354 |
|
|
| 305 |
355 |
$_max = "ulimited"; |
$_max = "ulimited"; |
| |
| ... |
... |
function rg_repo_list_query($db, $url, $sql) |
| 312 |
362 |
$_v = rg_1024($row['max_commit_size']); |
$_v = rg_1024($row['max_commit_size']); |
| 313 |
363 |
$ret .= " <td>" . $_v . "</td>\n"; |
$ret .= " <td>" . $_v . "</td>\n"; |
| 314 |
364 |
|
|
|
365 |
|
$_v = "ulimited"; |
|
366 |
|
if ($row['max_users'] > 0) |
|
367 |
|
$_v = $row['max_users']; |
|
368 |
|
$ret .= " <td>" . $_v . "</td>\n"; |
|
369 |
|
|
| 315 |
370 |
$ret .= "</tr>\n"; |
$ret .= "</tr>\n"; |
| 316 |
371 |
} |
} |
| 317 |
372 |
$ret .= "</table>\n"; |
$ret .= "</table>\n"; |
| |
| ... |
... |
function rg_repo_search($db, $q, $masters) |
| 354 |
409 |
|
|
| 355 |
410 |
$sql = "SELECT * FROM repos" |
$sql = "SELECT * FROM repos" |
| 356 |
411 |
. " WHERE deleted = 0" |
. " WHERE deleted = 0" |
| 357 |
|
. " AND name LIKE '%$e_q%'" |
|
|
412 |
|
. " AND name ILIKE '%$e_q%'" |
| 358 |
413 |
. $add |
. $add |
| 359 |
414 |
. " ORDER BY name" |
. " ORDER BY name" |
| 360 |
415 |
. " LIMIT 10"; |
. " LIMIT 10"; |
| |
| ... |
... |
function rg_repo_git_done($db, $repo_id) |
| 393 |
448 |
return TRUE; |
return TRUE; |
| 394 |
449 |
} |
} |
| 395 |
450 |
|
|
| 396 |
|
|
|
| 397 |
|
// Functions for repo rights management |
|
| 398 |
|
|
|
| 399 |
|
/* |
|
| 400 |
|
* Combine two repo rights strings |
|
| 401 |
|
*/ |
|
| 402 |
|
function rg_repo_rights_combine($a, $b) |
|
| 403 |
|
{ |
|
| 404 |
|
$len = strlen($b); |
|
| 405 |
|
for ($i = 0; $i < $len; $i++) |
|
| 406 |
|
if (!strstr($a, $b[$i])) |
|
| 407 |
|
$a .= $b[$i]; |
|
| 408 |
|
|
|
| 409 |
|
return $a; |
|
| 410 |
|
} |
|
| 411 |
|
|
|
| 412 |
451 |
/* |
/* |
| 413 |
452 |
* Get rights for a user |
* Get rights for a user |
| 414 |
453 |
*/ |
*/ |
| 415 |
|
function rg_repo_rights_get($db, $ri, $uid) |
|
|
454 |
|
function rg_repo_rights_get($db, $ri, $uid, $flags) |
| 416 |
455 |
{ |
{ |
| 417 |
|
global $rg_repo_rights; |
|
| 418 |
|
|
|
| 419 |
|
rg_log("rg_repo_rights_get: repo_id=" . $ri['repo_id'] . ", uid=$uid..."); |
|
|
456 |
|
rg_log("rg_repo_rights_get: repo_id=" . $ri['repo_id'] . ", uid=$uid" |
|
457 |
|
. " flags=$flags..."); |
| 420 |
458 |
|
|
| 421 |
459 |
$ret = array(); |
$ret = array(); |
| 422 |
460 |
$ret['ok'] = 0; |
$ret['ok'] = 0; |
| 423 |
|
$ret['exists'] = 0; |
|
| 424 |
461 |
$ret['rights'] = ""; |
$ret['rights'] = ""; |
| 425 |
462 |
|
|
| 426 |
463 |
$repo_id = $ri['repo_id']; |
$repo_id = $ri['repo_id']; |
| 427 |
464 |
|
|
| 428 |
465 |
// Give all rights to owner |
// Give all rights to owner |
| 429 |
|
$dr = $ri['default_rights']; |
|
| 430 |
466 |
if ($ri['uid'] == $uid) { |
if ($ri['uid'] == $uid) { |
| 431 |
|
foreach ($rg_repo_rights as $letter => $junk) |
|
| 432 |
|
$dr = rg_repo_rights_combine($dr, $letter); |
|
| 433 |
|
} |
|
| 434 |
|
|
|
| 435 |
|
$sql = "SELECT rights FROM repo_rights" |
|
| 436 |
|
. " WHERE repo_id = $repo_id" |
|
| 437 |
|
. " AND uid = $uid" |
|
| 438 |
|
. " LIMIT 1"; |
|
| 439 |
|
$res = rg_sql_query($db, $sql); |
|
| 440 |
|
if ($res === FALSE) { |
|
| 441 |
|
rg_repo_set_error("Cannot get info (" . rg_sql_error() . ")!"); |
|
| 442 |
|
return $ret; |
|
|
467 |
|
rg_log("\tuid $uid is the owner."); |
|
468 |
|
$dr = rg_rights_all("repo"); |
|
469 |
|
if (($flags & RG_RIGHTS_FILL_EXISTS) == 0) { |
|
470 |
|
rg_log("\tNo need to fill 'exists' field. Return."); |
|
471 |
|
$ret['rights'] = $dr; |
|
472 |
|
$ret['ok'] = 1; |
|
473 |
|
return $ret; |
|
474 |
|
} |
|
475 |
|
} else { |
|
476 |
|
$dr = $ri['default_rights']; |
| 443 |
477 |
} |
} |
| 444 |
478 |
|
|
| 445 |
|
$ret['ok'] = 1; |
|
| 446 |
|
$row = rg_sql_fetch_array($res); |
|
| 447 |
|
rg_sql_free_result($res); |
|
| 448 |
|
if (isset($row['rights'])) { |
|
| 449 |
|
$ret['rights'] = $row['rights']; |
|
| 450 |
|
$ret['exists'] = 1; |
|
|
479 |
|
$r = rg_rights_get($db, "repo", $repo_id, $uid); |
|
480 |
|
if ($r['ok'] !== 1) { |
|
481 |
|
rg_repo_set_error("Cannot get rights (" . rg_rights_error() . ")!"); |
|
482 |
|
return FALSE; |
| 451 |
483 |
} |
} |
| 452 |
484 |
|
|
| 453 |
|
$ret['rights'] = rg_repo_rights_combine($dr, $ret['rights']); |
|
| 454 |
|
rg_log("\tDEBUG rights=" . $ret['rights']); |
|
|
485 |
|
$ret['rights'] = rg_rights_combine($dr, $r['rights']); |
|
486 |
|
rg_log("\tFinal rights($dr + " . $r['rights'] . ")=" . $ret['rights']); |
| 455 |
487 |
|
|
| 456 |
488 |
return $ret; |
return $ret; |
| 457 |
489 |
} |
} |
| |
| ... |
... |
function rg_repo_rights_set($db, $ri, $uid, $rights) |
| 464 |
496 |
rg_log("rg_repo_rights_set: repo_id=" . $ri['repo_id'] |
rg_log("rg_repo_rights_set: repo_id=" . $ri['repo_id'] |
| 465 |
497 |
. ", uid=$uid, rights=$rights..."); |
. ", uid=$uid, rights=$rights..."); |
| 466 |
498 |
|
|
| 467 |
|
$repo_id = $ri['repo_id']; |
|
| 468 |
|
|
|
| 469 |
|
if (empty($rights)) { |
|
| 470 |
|
$sql = "DELETE FROM repo_rights" |
|
| 471 |
|
. " WHERE repo_id = $repo_id" |
|
| 472 |
|
. " AND uid = $uid"; |
|
| 473 |
|
} else { |
|
| 474 |
|
$e_rights = rg_sql_escape($db, $rights); |
|
| 475 |
|
|
|
| 476 |
|
$rr = rg_repo_rights_get($db, $ri, $uid); |
|
| 477 |
|
if ($rr === FALSE) |
|
| 478 |
|
return $rr; |
|
| 479 |
|
rg_log("rr: " . print_r($rr, TRUE)); |
|
| 480 |
|
|
|
| 481 |
|
if ($rr['exists'] == 1) { |
|
| 482 |
|
$sql = "UPDATE repo_rights" |
|
| 483 |
|
. " SET rights = '$e_rights'" |
|
| 484 |
|
. " WHERE repo_id = $repo_id" |
|
| 485 |
|
. " AND uid = $uid"; |
|
| 486 |
|
} else { |
|
| 487 |
|
$itime = time(); |
|
| 488 |
|
|
|
| 489 |
|
$sql = "INSERT INTO repo_rights (repo_id, uid, rights" |
|
| 490 |
|
. ", itime)" |
|
| 491 |
|
. " VALUES ($repo_id, $uid, '$e_rights'" |
|
| 492 |
|
. ", $itime)"; |
|
| 493 |
|
} |
|
| 494 |
|
} |
|
| 495 |
|
|
|
| 496 |
|
$res = rg_sql_query($db, $sql); |
|
| 497 |
|
if ($res === FALSE) { |
|
| 498 |
|
rg_repo_set_error("Cannot alter rights (" . rg_sql_error() . ")!"); |
|
|
499 |
|
$r = rg_rights_set($db, "repo", $ri['repo_id'], $uid, $rights); |
|
500 |
|
if ($r !== TRUE) { |
|
501 |
|
rg_repo_set_error("Cannot alter rights (" . rg_rights_error() . ")!"); |
| 499 |
502 |
return FALSE; |
return FALSE; |
| 500 |
503 |
} |
} |
| 501 |
|
rg_sql_free_result($res); |
|
| 502 |
504 |
|
|
| 503 |
505 |
return TRUE; |
return TRUE; |
| 504 |
506 |
} |
} |
| |
| ... |
... |
function rg_repo_rights_set($db, $ri, $uid, $rights) |
| 506 |
508 |
/* |
/* |
| 507 |
509 |
* List rights for a repo |
* List rights for a repo |
| 508 |
510 |
*/ |
*/ |
| 509 |
|
function rg_repo_rights_list($db, $repo_id, $url) |
|
|
511 |
|
function rg_repo_rights_list($db, $ri, $url) |
| 510 |
512 |
{ |
{ |
| 511 |
|
rg_log("rg_repo_rights_list: repo_id=$repo_id url=$url"); |
|
| 512 |
|
|
|
| 513 |
|
$ret = ""; |
|
|
513 |
|
rg_log("rg_repo_rights_list: repo_id=" . $ri['repo_id'] . " url=$url"); |
| 514 |
514 |
|
|
| 515 |
|
$sql = "SELECT * FROM repo_rights WHERE repo_id = $repo_id"; |
|
| 516 |
|
$res = rg_sql_query($db, $sql); |
|
| 517 |
|
if ($res === FALSE) { |
|
| 518 |
|
rg_repo_set_error("Cannot get info (" . rg_sql_error() . ")!"); |
|
|
515 |
|
$r = rg_rights_list($db, "repo", $ri['repo_id'], $url); |
|
516 |
|
if ($r === FALSE) { |
|
517 |
|
rg_repo_set_error("Cannot list rights (" . rg_rights_error() . ")"); |
| 519 |
518 |
return FALSE; |
return FALSE; |
| 520 |
519 |
} |
} |
| 521 |
520 |
|
|
| 522 |
|
$ret .= "<table>\n"; |
|
| 523 |
|
$ret .= "<tr>\n"; |
|
| 524 |
|
$ret .= " <th>User</th>\n"; |
|
| 525 |
|
$ret .= " <th>Rights</th>\n"; |
|
| 526 |
|
$ret .= " <th>Operations</th>\n"; |
|
| 527 |
|
$ret .= "</tr>\n"; |
|
| 528 |
|
while (($row = rg_sql_fetch_array($res))) { |
|
| 529 |
|
$ret .= "<tr>\n"; |
|
| 530 |
|
|
|
| 531 |
|
$_u = $row['uid']; |
|
| 532 |
|
$_ui = rg_user_info($db, $row['uid'], "", ""); |
|
| 533 |
|
if ($_ui['exists'] == 1) |
|
| 534 |
|
$_u = $_ui['user']; |
|
| 535 |
|
|
|
| 536 |
|
$ret .= " <td>" . $_u . "</td>\n"; |
|
| 537 |
|
|
|
| 538 |
|
$_r = rg_repo_rights_text($row['rights']); |
|
| 539 |
|
$_r = implode("<br />\n", $_r); |
|
| 540 |
|
$ret .= " <td>" . $_r . "</td>\n"; |
|
| 541 |
|
|
|
| 542 |
|
// operations |
|
| 543 |
|
// remove |
|
| 544 |
|
$ret .= " <td>"; |
|
| 545 |
|
$_url = $url . "&subop=2"; |
|
| 546 |
|
$v = $row['uid']; |
|
| 547 |
|
$ret .= "[<a href=\"$_url&remove_uid=$v\">Remove</a>]"; |
|
| 548 |
|
$ret .= " </td>"; |
|
| 549 |
|
$ret .= "</tr>\n"; |
|
| 550 |
|
} |
|
| 551 |
|
$ret .= "</table>\n"; |
|
| 552 |
|
rg_sql_free_result($res); |
|
| 553 |
|
|
|
| 554 |
|
return $ret; |
|
| 555 |
|
} |
|
| 556 |
|
|
|
| 557 |
|
/* |
|
| 558 |
|
* Rights -> form |
|
| 559 |
|
*/ |
|
| 560 |
|
function rg_repo_rights_checkboxes($def_rights) |
|
| 561 |
|
{ |
|
| 562 |
|
global $rg_repo_rights; |
|
| 563 |
|
|
|
| 564 |
|
$ret = ""; |
|
| 565 |
|
foreach ($rg_repo_rights as $right => $info) { |
|
| 566 |
|
$add = ""; |
|
| 567 |
|
if (strstr($def_rights, $right)) |
|
| 568 |
|
$add = " checked"; |
|
| 569 |
|
$ret .= "<input type=\"checkbox\" name=\"rights[$right]\"" |
|
| 570 |
|
. $add . " />$info<br />\n"; |
|
| 571 |
|
} |
|
| 572 |
|
|
|
| 573 |
|
return $ret; |
|
|
521 |
|
return $r; |
| 574 |
522 |
} |
} |
| 575 |
523 |
|
|
| 576 |
|
/* |
|
| 577 |
|
* List rights as text |
|
| 578 |
|
*/ |
|
| 579 |
|
function rg_repo_rights_text($rights) |
|
| 580 |
|
{ |
|
| 581 |
|
global $rg_repo_rights; |
|
| 582 |
|
|
|
| 583 |
|
$ret = array(); |
|
| 584 |
|
|
|
| 585 |
|
$len = strlen($rights); |
|
| 586 |
|
if ($len == 0) |
|
| 587 |
|
return array("None"); |
|
| 588 |
|
|
|
| 589 |
|
for ($i = 0; $i < $len; $i++) { |
|
| 590 |
|
if (isset($rg_repo_rights[$rights[$i]])) |
|
| 591 |
|
$ret[] = $rg_repo_rights[$rights[$i]]; |
|
| 592 |
|
else |
|
| 593 |
|
$ret[] = "?" . $rights[$i] . "?"; |
|
| 594 |
|
} |
|
| 595 |
|
|
|
| 596 |
|
return $ret; |
|
| 597 |
|
} |
|
| 598 |
|
|
|
| 599 |
|
/* |
|
| 600 |
|
* Transforms rights array into a string |
|
| 601 |
|
*/ |
|
| 602 |
|
function rg_repo_rights_a2s($a) |
|
| 603 |
|
{ |
|
| 604 |
|
$rights = ""; |
|
| 605 |
|
|
|
| 606 |
|
if (is_array($a)) |
|
| 607 |
|
foreach ($a as $right => $junk) |
|
| 608 |
|
$rights .= $right; |
|
| 609 |
|
|
|
| 610 |
|
return preg_replace("/[^A-Za-z0-9]/", "", $rights); |
|
| 611 |
|
} |
|
| 612 |
524 |
?> |
?> |
| File inc/rights.inc.php added (mode: 100644) (index 0000000..78f39b7) |
|
1 |
|
<?php |
|
2 |
|
require_once($INC . "/util.inc.php"); |
|
3 |
|
require_once($INC . "/log.inc.php"); |
|
4 |
|
require_once($INC . "/db.inc.php"); |
|
5 |
|
require_once($INC . "/user.inc.php"); |
|
6 |
|
require_once($INC . "/git.inc.php"); |
|
7 |
|
|
|
8 |
|
define("RG_RIGHTS_FILL_EXISTS", 1); |
|
9 |
|
|
|
10 |
|
$rg_rights = array(); |
|
11 |
|
|
|
12 |
|
$rg_rights_error = ""; |
|
13 |
|
|
|
14 |
|
function rg_rights_set_error($str) |
|
15 |
|
{ |
|
16 |
|
global $rg_rights_error; |
|
17 |
|
|
|
18 |
|
rg_log("\tError: $str"); |
|
19 |
|
$rg_rights_error = $str; |
|
20 |
|
} |
|
21 |
|
|
|
22 |
|
function rg_rights_error() |
|
23 |
|
{ |
|
24 |
|
global $rg_rights_error; |
|
25 |
|
return $rg_rights_error; |
|
26 |
|
} |
|
27 |
|
|
|
28 |
|
/* |
|
29 |
|
* Register a set of rights |
|
30 |
|
*/ |
|
31 |
|
function rg_rights_register($type, $rights) |
|
32 |
|
{ |
|
33 |
|
global $rg_rights; |
|
34 |
|
|
|
35 |
|
$rg_rights[$type] = $rights; |
|
36 |
|
} |
|
37 |
|
|
|
38 |
|
/* |
|
39 |
|
* Enforce correct chars |
|
40 |
|
*/ |
|
41 |
|
function rg_rights_fix($rights) |
|
42 |
|
{ |
|
43 |
|
return preg_replace("/[^A-Za-z0-9]/", "", $rights); |
|
44 |
|
} |
|
45 |
|
|
|
46 |
|
/* |
|
47 |
|
* Combine two repo rights strings |
|
48 |
|
*/ |
|
49 |
|
function rg_rights_combine($a, $b) |
|
50 |
|
{ |
|
51 |
|
$len = strlen($b); |
|
52 |
|
for ($i = 0; $i < $len; $i++) |
|
53 |
|
if (!strstr($a, $b[$i])) |
|
54 |
|
$a .= $b[$i]; |
|
55 |
|
|
|
56 |
|
return $a; |
|
57 |
|
} |
|
58 |
|
|
|
59 |
|
/* |
|
60 |
|
* Returns all possible rights |
|
61 |
|
*/ |
|
62 |
|
function rg_rights_all($type) |
|
63 |
|
{ |
|
64 |
|
global $rg_rights; |
|
65 |
|
|
|
66 |
|
if (!isset($rg_rights[$type])) { |
|
67 |
|
rg_log("WARN: type [$type] is not registered!"); |
|
68 |
|
return ""; |
|
69 |
|
} |
|
70 |
|
|
|
71 |
|
$ret = ""; |
|
72 |
|
foreach ($rg_rights[$type] as $letter => $junk) |
|
73 |
|
$ret = rg_rights_combine($ret, $letter); |
|
74 |
|
|
|
75 |
|
return $ret; |
|
76 |
|
} |
|
77 |
|
|
|
78 |
|
/* |
|
79 |
|
* Rights -> form |
|
80 |
|
*/ |
|
81 |
|
function rg_rights_checkboxes($type, $passed_rights) |
|
82 |
|
{ |
|
83 |
|
global $rg_rights; |
|
84 |
|
|
|
85 |
|
if (!isset($rg_rights[$type])) { |
|
86 |
|
rg_log("[$type] is not registered! " . print_r(debug_backtrace(), TRUE)); |
|
87 |
|
return ""; |
|
88 |
|
} |
|
89 |
|
|
|
90 |
|
$ret = ""; |
|
91 |
|
foreach ($rg_rights[$type] as $right => $info) { |
|
92 |
|
$add = ""; |
|
93 |
|
if (strstr($passed_rights, $right)) |
|
94 |
|
$add = " checked"; |
|
95 |
|
$ret .= "<input type=\"checkbox\" name=\"rights[$right]\"" |
|
96 |
|
. $add . " />$info<br />\n"; |
|
97 |
|
} |
|
98 |
|
|
|
99 |
|
return $ret; |
|
100 |
|
} |
|
101 |
|
|
|
102 |
|
/* |
|
103 |
|
* List rights as text |
|
104 |
|
*/ |
|
105 |
|
function rg_rights_text($type, $rights) |
|
106 |
|
{ |
|
107 |
|
global $rg_rights; |
|
108 |
|
|
|
109 |
|
$ret = array(); |
|
110 |
|
|
|
111 |
|
$len = strlen($rights); |
|
112 |
|
if ($len == 0) |
|
113 |
|
return array("None"); |
|
114 |
|
|
|
115 |
|
for ($i = 0; $i < $len; $i++) { |
|
116 |
|
if (isset($rg_rights[$type][$rights[$i]])) |
|
117 |
|
$ret[] = $rg_rights[$type][$rights[$i]]; |
|
118 |
|
else |
|
119 |
|
$ret[] = "?" . $rights[$i] . "?"; |
|
120 |
|
} |
|
121 |
|
|
|
122 |
|
return $ret; |
|
123 |
|
} |
|
124 |
|
|
|
125 |
|
/* |
|
126 |
|
* Transforms rights array into a string |
|
127 |
|
*/ |
|
128 |
|
function rg_rights_a2s($a) |
|
129 |
|
{ |
|
130 |
|
$rights = ""; |
|
131 |
|
|
|
132 |
|
if (is_array($a)) |
|
133 |
|
foreach ($a as $right => $junk) |
|
134 |
|
$rights .= $right; |
|
135 |
|
|
|
136 |
|
return rg_rights_fix($rights); |
|
137 |
|
} |
|
138 |
|
|
|
139 |
|
|
|
140 |
|
/* |
|
141 |
|
* Get rights for an object |
|
142 |
|
*/ |
|
143 |
|
function rg_rights_get($db, $type, $obj_id, $uid) |
|
144 |
|
{ |
|
145 |
|
global $rg_rights; |
|
146 |
|
|
|
147 |
|
rg_log("rg_rights_get: type=$type obj_id=$obj_id uid=$uid..."); |
|
148 |
|
|
|
149 |
|
$ret = array(); |
|
150 |
|
$ret['ok'] = 0; |
|
151 |
|
$ret['rights'] = ""; |
|
152 |
|
|
|
153 |
|
$sql = "SELECT rights FROM rights" |
|
154 |
|
. " WHERE type = '$type'" |
|
155 |
|
. " AND uid = $uid" |
|
156 |
|
. " AND obj_id = $obj_id" |
|
157 |
|
. " LIMIT 1"; |
|
158 |
|
$res = rg_sql_query($db, $sql); |
|
159 |
|
if ($res === FALSE) { |
|
160 |
|
rg_rights_set_error("Cannot get info (" . rg_sql_error() . ")!"); |
|
161 |
|
return $ret; |
|
162 |
|
} |
|
163 |
|
|
|
164 |
|
$ret['ok'] = 1; |
|
165 |
|
$ret['exists'] = 0; |
|
166 |
|
$row = rg_sql_fetch_array($res); |
|
167 |
|
rg_sql_free_result($res); |
|
168 |
|
if (isset($row['rights'])) { |
|
169 |
|
$ret['rights'] = $row['rights']; |
|
170 |
|
$ret['exists'] = 1; |
|
171 |
|
} |
|
172 |
|
|
|
173 |
|
rg_log("\tRights: " . $ret['rights']); |
|
174 |
|
|
|
175 |
|
return $ret; |
|
176 |
|
} |
|
177 |
|
|
|
178 |
|
/* |
|
179 |
|
* Set rights for an object |
|
180 |
|
*/ |
|
181 |
|
function rg_rights_set($db, $type, $obj_id, $uid, $rights) |
|
182 |
|
{ |
|
183 |
|
rg_log("rg_rights_set: type=$type obj_id=$obj_id" |
|
184 |
|
. ", uid=$uid, rights=$rights..."); |
|
185 |
|
|
|
186 |
|
$cond = " type = '$type' AND uid = $uid AND obj_id = $obj_id"; |
|
187 |
|
|
|
188 |
|
if (empty($rights)) { |
|
189 |
|
$sql = "DELETE FROM rights" |
|
190 |
|
. " WHERE $cond"; |
|
191 |
|
} else { |
|
192 |
|
$r = rg_rights_get($db, $type, $obj_id, $uid); |
|
193 |
|
if ($r['ok'] != 1) |
|
194 |
|
return $r; |
|
195 |
|
rg_log("r: " . print_r($r, TRUE)); |
|
196 |
|
|
|
197 |
|
if ($r['exists'] == 1) { |
|
198 |
|
$sql = "UPDATE rights" |
|
199 |
|
. " SET rights = '$rights'" |
|
200 |
|
. " WHERE $cond"; |
|
201 |
|
} else { |
|
202 |
|
$itime = time(); |
|
203 |
|
|
|
204 |
|
$sql = "INSERT INTO rights (type, uid, obj_id, rights" |
|
205 |
|
. ", itime)" |
|
206 |
|
. " VALUES ('$type', $uid, $obj_id, '$rights'" |
|
207 |
|
. ", $itime)"; |
|
208 |
|
} |
|
209 |
|
} |
|
210 |
|
|
|
211 |
|
$res = rg_sql_query($db, $sql); |
|
212 |
|
if ($res === FALSE) { |
|
213 |
|
rg_rights_set_error("Cannot alter rights (" . rg_sql_error() . ")!"); |
|
214 |
|
return FALSE; |
|
215 |
|
} |
|
216 |
|
rg_sql_free_result($res); |
|
217 |
|
|
|
218 |
|
return TRUE; |
|
219 |
|
} |
|
220 |
|
|
|
221 |
|
/* |
|
222 |
|
* List rights for a repo |
|
223 |
|
*/ |
|
224 |
|
function rg_rights_list($db, $type, $obj_id, $url) |
|
225 |
|
{ |
|
226 |
|
global $rg_rights; |
|
227 |
|
|
|
228 |
|
rg_log("rg_rights_list: type=$type obj_id=$obj_id url=$url"); |
|
229 |
|
|
|
230 |
|
$ret = ""; |
|
231 |
|
|
|
232 |
|
$sql = "SELECT * FROM rights WHERE type = '$type' AND obj_id = $obj_id"; |
|
233 |
|
$res = rg_sql_query($db, $sql); |
|
234 |
|
if ($res === FALSE) { |
|
235 |
|
rg_rights_set_error("Cannot get info (" . rg_sql_error() . ")!"); |
|
236 |
|
return FALSE; |
|
237 |
|
} |
|
238 |
|
|
|
239 |
|
$ret .= "<table>\n"; |
|
240 |
|
$ret .= "<tr>\n"; |
|
241 |
|
$ret .= " <th>User</th>\n"; |
|
242 |
|
$ret .= " <th>Rights</th>\n"; |
|
243 |
|
$ret .= " <th>Operations</th>\n"; |
|
244 |
|
$ret .= "</tr>\n"; |
|
245 |
|
while (($row = rg_sql_fetch_array($res))) { |
|
246 |
|
$ret .= "<tr>\n"; |
|
247 |
|
|
|
248 |
|
$_u = $row['uid']; |
|
249 |
|
$_ui = rg_user_info($db, $row['uid'], "", ""); |
|
250 |
|
if ($_ui['exists'] == 1) |
|
251 |
|
$_u = $_ui['user']; |
|
252 |
|
|
|
253 |
|
$ret .= " <td>" . $_u . "</td>\n"; |
|
254 |
|
|
|
255 |
|
$_r = rg_rights_text($type, $row['rights']); |
|
256 |
|
$_r = implode("<br />\n", $_r); |
|
257 |
|
$ret .= " <td>" . $_r . "</td>\n"; |
|
258 |
|
|
|
259 |
|
// operations |
|
260 |
|
// remove |
|
261 |
|
$ret .= " <td>"; |
|
262 |
|
$_url = $url . "&subop=2"; |
|
263 |
|
$v = $row['uid']; |
|
264 |
|
$ret .= "[<a href=\"$_url&remove_uid=$v\">Remove</a>]"; |
|
265 |
|
$ret .= " </td>"; |
|
266 |
|
$ret .= "</tr>\n"; |
|
267 |
|
} |
|
268 |
|
$ret .= "</table>\n"; |
|
269 |
|
rg_sql_free_result($res); |
|
270 |
|
|
|
271 |
|
return $ret; |
|
272 |
|
} |
|
273 |
|
|
|
274 |
|
?> |
| File inc/user.inc.php changed (mode: 100644) (index c6d7b94..ae4a415) |
| ... |
... |
require_once($INC . "/util.inc.php"); |
| 3 |
3 |
require_once($INC . "/log.inc.php"); |
require_once($INC . "/log.inc.php"); |
| 4 |
4 |
require_once($INC . "/db.inc.php"); |
require_once($INC . "/db.inc.php"); |
| 5 |
5 |
require_once($INC . "/sess.inc.php"); |
require_once($INC . "/sess.inc.php"); |
|
6 |
|
require_once($INC . "/rights.inc.php"); |
|
7 |
|
|
|
8 |
|
$rg_user_rights = array( |
|
9 |
|
"C" => "Create repository", |
|
10 |
|
"U" => "Add users" |
|
11 |
|
); |
|
12 |
|
|
|
13 |
|
rg_rights_register("user", $rg_user_rights); |
| 6 |
14 |
|
|
| 7 |
15 |
function rg_user_set_error($str) |
function rg_user_set_error($str) |
| 8 |
16 |
{ |
{ |
| |
| ... |
... |
function rg_user_error() |
| 18 |
26 |
return $_rg_user_error; |
return $_rg_user_error; |
| 19 |
27 |
} |
} |
| 20 |
28 |
|
|
|
29 |
|
/* |
|
30 |
|
* Computes password hash |
|
31 |
|
*/ |
|
32 |
|
function rg_user_pass($salt, $pass) |
|
33 |
|
{ |
|
34 |
|
global $rg_pass_key; |
|
35 |
|
|
|
36 |
|
return sha1($salt . "===" . $rg_pass_key . "===" . $pass); |
|
37 |
|
} |
|
38 |
|
|
|
39 |
|
/* |
|
40 |
|
* Validates a password |
|
41 |
|
*/ |
|
42 |
|
function rg_user_pass_ok($pass) |
|
43 |
|
{ |
|
44 |
|
if (strlen($pass) <= 4) { |
|
45 |
|
rg_user_set_error("Password is too short."); |
|
46 |
|
return FALSE; |
|
47 |
|
} |
|
48 |
|
|
|
49 |
|
return TRUE; |
|
50 |
|
} |
|
51 |
|
|
| 21 |
52 |
/* |
/* |
| 22 |
53 |
* Returns true if the user is ok |
* Returns true if the user is ok |
| 23 |
54 |
*/ |
*/ |
| |
| ... |
... |
function rg_user_ok($user) |
| 26 |
57 |
global $rg_user_allow; |
global $rg_user_allow; |
| 27 |
58 |
global $rg_user_max_len; |
global $rg_user_max_len; |
| 28 |
59 |
|
|
| 29 |
|
if (rg_chars_allow($user, $rg_user_allow) === FALSE) { |
|
| 30 |
|
rg_user_set_error("Invalid user name"); |
|
|
60 |
|
if (rg_chars_allow($user, $rg_user_allow) !== TRUE) { |
|
61 |
|
rg_user_set_error("Invalid user name (invalid chars [$user] [$rg_user_allow])"); |
| 31 |
62 |
return FALSE; |
return FALSE; |
| 32 |
63 |
} |
} |
| 33 |
64 |
|
|
| |
| ... |
... |
function rg_user_ok($user) |
| 41 |
72 |
|
|
| 42 |
73 |
/* |
/* |
| 43 |
74 |
* Add a user |
* Add a user |
|
75 |
|
* If uid > 0 - edit, else, add |
| 44 |
76 |
*/ |
*/ |
| 45 |
|
function rg_user_add($db, $user, $pass, $email, $is_admin) |
|
|
77 |
|
function rg_user_edit($db, $uid, $user, $email, $pass, $is_admin, |
|
78 |
|
$disk_quota_mb, $rights) |
| 46 |
79 |
{ |
{ |
| 47 |
80 |
global $rg_session_time; |
global $rg_session_time; |
| 48 |
81 |
|
|
| 49 |
|
rg_log("user_add: user=$user, pass=$pass, email=$email, is_admin=$is_admin..."); |
|
|
82 |
|
rg_log("user_edit: uid=$uid, user=$user email=$email" |
|
83 |
|
. " pass=$pass is_admin=$is_admin" |
|
84 |
|
. " disk_quota_mb=$disk_quota_mb rights=$rights..."); |
| 50 |
85 |
|
|
| 51 |
|
if (rg_user_ok($user) === FALSE) |
|
|
86 |
|
if (rg_user_ok($user) !== TRUE) |
| 52 |
87 |
return FALSE; |
return FALSE; |
| 53 |
88 |
|
|
| 54 |
|
$itime = time(); |
|
| 55 |
|
$e_salt = rg_id(40); |
|
| 56 |
|
$e_sha1pass = sha1($e_salt . "===" . $pass); |
|
| 57 |
|
$session_time = $rg_session_time; |
|
| 58 |
|
|
|
| 59 |
89 |
$e_user = rg_sql_escape($db, $user); |
$e_user = rg_sql_escape($db, $user); |
|
90 |
|
$e_salt = rg_id(40); |
|
91 |
|
$e_pass = rg_user_pass($e_salt, $pass); |
| 60 |
92 |
$e_email = rg_sql_escape($db, $email); |
$e_email = rg_sql_escape($db, $email); |
|
93 |
|
$e_rights = rg_sql_escape($db, $rights); |
|
94 |
|
$e_session_time = $rg_session_time; |
|
95 |
|
|
|
96 |
|
if ($uid == 0) { // add |
|
97 |
|
if (rg_user_pass_ok($pass) !== TRUE) |
|
98 |
|
return FALSE; |
|
99 |
|
|
|
100 |
|
$now = time(); |
|
101 |
|
$sql = "INSERT INTO users (user, salt, pass, email, itime" |
|
102 |
|
. ", is_admin, disk_quota_mb, rights, session_time)" |
|
103 |
|
. " VALUES ('$e_user', '$e_salt', '$e_pass'" |
|
104 |
|
. ", '$e_email', $now, $is_admin, $disk_quota_mb" |
|
105 |
|
. ", '$e_rights', $e_session_time)"; |
|
106 |
|
} else { // edit |
|
107 |
|
$salt_pass_add = ""; |
|
108 |
|
if (!empty($pass)) |
|
109 |
|
$salt_pass_add = ", pass = '$e_pass', salt = '$e_salt'"; |
|
110 |
|
|
|
111 |
|
$sql = "UPDATE users SET user = '$e_user'" |
|
112 |
|
. $salt_pass_add |
|
113 |
|
. ", email = '$e_email'" |
|
114 |
|
. ", is_admin = $is_admin" |
|
115 |
|
. ", disk_quota_mb = $disk_quota_mb" |
|
116 |
|
. ", rights = '$e_rights'" |
|
117 |
|
. ", session_time = $e_session_time" |
|
118 |
|
. " WHERE uid = $uid"; |
|
119 |
|
} |
| 61 |
120 |
|
|
| 62 |
|
$sql = "INSERT INTO users (user, salt, pass, email, itime, is_admin, session_time)" |
|
| 63 |
|
. " VALUES ('$e_user', '$e_salt', '$e_sha1pass', '$e_email'" |
|
| 64 |
|
. ", $itime, $is_admin, $session_time)"; |
|
| 65 |
121 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
| 66 |
122 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 67 |
|
rg_user_set_error("Cannot insert user (" . rg_sql_error() . ")!"); |
|
|
123 |
|
rg_user_set_error("Cannot insert/update user (" . rg_sql_error() . ")!"); |
| 68 |
124 |
return FALSE; |
return FALSE; |
| 69 |
125 |
} |
} |
| 70 |
126 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
| |
| ... |
... |
function rg_user_remove($db, $uid) |
| 95 |
151 |
*/ |
*/ |
| 96 |
152 |
function rg_user_info($db, $uid, $user, $email) |
function rg_user_info($db, $uid, $user, $email) |
| 97 |
153 |
{ |
{ |
| 98 |
|
rg_log("user_info: uid=[$uid], user=[$user], email=[$email]..."); |
|
|
154 |
|
rg_log("user_info: uid/user/email=$uid/$user/$email..."); |
| 99 |
155 |
|
|
| 100 |
156 |
$ret = array(); |
$ret = array(); |
| 101 |
157 |
$ret['ok'] = 0; |
$ret['ok'] = 0; |
| |
| ... |
... |
function rg_user_info($db, $uid, $user, $email) |
| 103 |
159 |
$ret['uid'] = 0; |
$ret['uid'] = 0; |
| 104 |
160 |
$ret['is_admin'] = 0; |
$ret['is_admin'] = 0; |
| 105 |
161 |
|
|
| 106 |
|
if (rg_user_ok($user) === FALSE) |
|
| 107 |
|
return FALSE; |
|
| 108 |
|
|
|
| 109 |
162 |
if ($uid > 0) { |
if ($uid > 0) { |
| 110 |
163 |
$add = " AND uid = " . sprintf("%u", $uid); |
$add = " AND uid = " . sprintf("%u", $uid); |
| 111 |
164 |
} else if (!empty($user)) { |
} else if (!empty($user)) { |
|
165 |
|
if (rg_user_ok($user) !== TRUE) |
|
166 |
|
return FALSE; |
|
167 |
|
|
| 112 |
168 |
$e_user = rg_sql_escape($db, $user); |
$e_user = rg_sql_escape($db, $user); |
| 113 |
169 |
$add = " AND user = '$e_user'"; |
$add = " AND user = '$e_user'"; |
| 114 |
170 |
} else if (!empty($email)) { |
} else if (!empty($email)) { |
| |
| ... |
... |
function rg_user_login_by_sid($db, $sid, &$rg_ui) |
| 163 |
219 |
rg_user_set_error("Invalid uid!"); |
rg_user_set_error("Invalid uid!"); |
| 164 |
220 |
return FALSE; |
return FALSE; |
| 165 |
221 |
rg_sess_update($db, $sid); |
rg_sess_update($db, $sid); |
|
222 |
|
|
|
223 |
|
rg_user_set_last_seen($db, $rg_ui['uid']); |
|
224 |
|
|
|
225 |
|
return TRUE; |
|
226 |
|
} |
|
227 |
|
|
|
228 |
|
/* |
|
229 |
|
* Test if a password is valid |
|
230 |
|
*/ |
|
231 |
|
function rg_user_pass_valid($db, $uid, $pass) |
|
232 |
|
{ |
|
233 |
|
rg_log("user_pass_valid: uid=$uid, pass=$pass..."); |
|
234 |
|
|
|
235 |
|
if (empty($pass)) |
|
236 |
|
return FALSE; |
|
237 |
|
|
|
238 |
|
$ui = rg_user_info($db, $uid, "", ""); |
|
239 |
|
if ($ui['exists'] != 1) |
|
240 |
|
return FALSE; |
|
241 |
|
|
|
242 |
|
$sha1pass = rg_user_pass($ui['salt'], $pass); |
|
243 |
|
if (strcmp($sha1pass, $ui['pass']) != 0) |
|
244 |
|
return FALSE; |
|
245 |
|
|
| 166 |
246 |
return TRUE; |
return TRUE; |
| 167 |
247 |
} |
} |
| 168 |
248 |
|
|
| |
| ... |
... |
function rg_user_login_by_user_pass($db, $user, $pass, &$rg_ui) |
| 189 |
269 |
} |
} |
| 190 |
270 |
rg_log("\trg_ui: " . print_r($rg_ui, TRUE)); |
rg_log("\trg_ui: " . print_r($rg_ui, TRUE)); |
| 191 |
271 |
|
|
| 192 |
|
$sha1pass = sha1($rg_ui['salt'] . "===" . $pass); |
|
|
272 |
|
if ($rg_ui['suspended'] > 0) { |
|
273 |
|
rg_user_set_error("Invalid user or pass!"); |
|
274 |
|
return FALSE; |
|
275 |
|
} |
|
276 |
|
|
|
277 |
|
$sha1pass = rg_user_pass($rg_ui['salt'], $pass); |
| 193 |
278 |
if (strcmp($sha1pass, $rg_ui['pass']) != 0) { |
if (strcmp($sha1pass, $rg_ui['pass']) != 0) { |
| 194 |
279 |
rg_user_set_error("Invalid user or pass!"); |
rg_user_set_error("Invalid user or pass!"); |
| 195 |
280 |
return FALSE; |
return FALSE; |
| |
| ... |
... |
function rg_user_login_by_user_pass($db, $user, $pass, &$rg_ui) |
| 197 |
282 |
|
|
| 198 |
283 |
$sid = rg_id(40); |
$sid = rg_id(40); |
| 199 |
284 |
rg_sess_add($db, $rg_ui['uid'], $sid, $rg_ui['session_time']); |
rg_sess_add($db, $rg_ui['uid'], $sid, $rg_ui['session_time']); |
| 200 |
|
setcookie("sid", $sid, 0); |
|
|
285 |
|
setcookie("sid", $sid, 0, "/", $_SERVER['HTTP_HOST'], |
|
286 |
|
strcmp($_SERVER['HTTPS'], "on") == 0 /* secure */, |
|
287 |
|
TRUE /* httponly */); |
|
288 |
|
|
|
289 |
|
rg_user_set_last_seen($db, $rg_ui['uid']); |
| 201 |
290 |
|
|
| 202 |
291 |
return TRUE; |
return TRUE; |
| 203 |
292 |
} |
} |
| |
| ... |
... |
function rg_user_suspend($db, $uid, $op) |
| 230 |
319 |
* Make/remove admin |
* Make/remove admin |
| 231 |
320 |
* 1=make, 0=remove |
* 1=make, 0=remove |
| 232 |
321 |
*/ |
*/ |
| 233 |
|
function rg_user_admin($db, $uid, $op) |
|
|
322 |
|
function rg_user_make_admin($db, $uid, $op) |
|
323 |
|
{ |
|
324 |
|
rg_log("user_make_admin: uid=$uid, op=$op"); |
|
325 |
|
|
|
326 |
|
$sql = "UPDATE users SET is_admin = $op WHERE uid = $uid"; |
|
327 |
|
$res = rg_sql_query($db, $sql); |
|
328 |
|
if ($res === FALSE) |
|
329 |
|
return FALSE; |
|
330 |
|
rg_sql_free_result($res); |
|
331 |
|
|
|
332 |
|
return TRUE; |
|
333 |
|
} |
|
334 |
|
|
|
335 |
|
/* |
|
336 |
|
* Update last_seen field |
|
337 |
|
*/ |
|
338 |
|
function rg_user_set_last_seen($db, $uid) |
| 234 |
339 |
{ |
{ |
| 235 |
|
rg_log("user_admin: uid=$uid, op=$op"); |
|
|
340 |
|
rg_log("user_set_last_seen: uid=$uid"); |
| 236 |
341 |
|
|
| 237 |
342 |
$now = time(); |
$now = time(); |
| 238 |
343 |
|
|
| 239 |
|
$sql = "UPDATE users SET is_admin = $op WHERE uid = $uid"; |
|
|
344 |
|
$sql = "UPDATE users SET last_seen = $now WHERE uid = $uid"; |
| 240 |
345 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
| 241 |
346 |
if ($res === FALSE) |
if ($res === FALSE) |
| 242 |
347 |
return FALSE; |
return FALSE; |
| |
| ... |
... |
function rg_user_list($db, $url) |
| 254 |
359 |
|
|
| 255 |
360 |
$ret = ""; |
$ret = ""; |
| 256 |
361 |
|
|
| 257 |
|
$xuid = rg_var_uint("xuid"); |
|
|
362 |
|
$uid = rg_var_uint("uid"); |
| 258 |
363 |
|
|
| 259 |
364 |
$suspend = rg_var_uint("suspend"); |
$suspend = rg_var_uint("suspend"); |
| 260 |
365 |
if ($suspend == 1) { |
if ($suspend == 1) { |
| 261 |
|
if (!rg_user_suspend($db, $xuid, 1)) |
|
|
366 |
|
if (!rg_user_suspend($db, $uid, 1)) |
| 262 |
367 |
$ret .= "<font color=red>Cannot suspend!</font><br />"; |
$ret .= "<font color=red>Cannot suspend!</font><br />"; |
| 263 |
368 |
} |
} |
| 264 |
369 |
|
|
| 265 |
370 |
$unsuspend = rg_var_uint("unsuspend"); |
$unsuspend = rg_var_uint("unsuspend"); |
| 266 |
371 |
if ($unsuspend == 1) { |
if ($unsuspend == 1) { |
| 267 |
|
if (!rg_user_suspend($db, $xuid, 0)) |
|
|
372 |
|
if (!rg_user_suspend($db, $uid, 0)) |
| 268 |
373 |
$ret .= "<font color=red>Cannot unsuspend!</font><br />"; |
$ret .= "<font color=red>Cannot unsuspend!</font><br />"; |
| 269 |
374 |
} |
} |
| 270 |
375 |
|
|
| 271 |
376 |
$make_admin = rg_var_uint("make_admin"); |
$make_admin = rg_var_uint("make_admin"); |
| 272 |
377 |
if ($make_admin == 1) { |
if ($make_admin == 1) { |
| 273 |
|
if (!rg_user_admin($db, $xuid, 1)) |
|
|
378 |
|
if (!rg_user_make_admin($db, $uid, 1)) |
| 274 |
379 |
$ret .= "<font color=red>Cannot make admin!</font><br />"; |
$ret .= "<font color=red>Cannot make admin!</font><br />"; |
| 275 |
380 |
} |
} |
| 276 |
381 |
|
|
| 277 |
382 |
$remove_admin = rg_var_uint("remove_admin"); |
$remove_admin = rg_var_uint("remove_admin"); |
| 278 |
383 |
if ($remove_admin == 1) { |
if ($remove_admin == 1) { |
| 279 |
|
if (!rg_user_admin($db, $xuid, 0)) |
|
|
384 |
|
if (!rg_user_make_admin($db, $uid, 0)) |
| 280 |
385 |
$ret .= "<font color=red>Cannot remove admin!</font><br />"; |
$ret .= "<font color=red>Cannot remove admin!</font><br />"; |
| 281 |
386 |
} |
} |
| 282 |
387 |
|
|
| 283 |
388 |
$remove = rg_var_uint("remove"); |
$remove = rg_var_uint("remove"); |
| 284 |
389 |
if ($remove > 0) { |
if ($remove > 0) { |
| 285 |
|
if (!rg_user_remove($db, $xuid)) |
|
|
390 |
|
if (!rg_user_remove($db, $uid)) |
| 286 |
391 |
$ret .= "<font color=red>Cannot remove!</font><br />"; |
$ret .= "<font color=red>Cannot remove!</font><br />"; |
| 287 |
392 |
} |
} |
| 288 |
393 |
|
|
| |
| ... |
... |
function rg_user_list($db, $url) |
| 303 |
408 |
$ret .= " <th>Suspended?</th>\n"; |
$ret .= " <th>Suspended?</th>\n"; |
| 304 |
409 |
$ret .= " <th>Session time</th>\n"; |
$ret .= " <th>Session time</th>\n"; |
| 305 |
410 |
$ret .= " <th>Last seen (UTC)</th>\n"; |
$ret .= " <th>Last seen (UTC)</th>\n"; |
|
411 |
|
$ret .= " <th>Rights</th>\n"; |
| 306 |
412 |
$ret .= " <th>Operations</th>\n"; |
$ret .= " <th>Operations</th>\n"; |
| 307 |
413 |
$ret .= "</tr>\n"; |
$ret .= "</tr>\n"; |
| 308 |
414 |
while (($row = rg_sql_fetch_array($res))) { |
while (($row = rg_sql_fetch_array($res))) { |
| |
| ... |
... |
function rg_user_list($db, $url) |
| 311 |
417 |
$ret .= " <td>" . $row['email'] . "</td>\n"; |
$ret .= " <td>" . $row['email'] . "</td>\n"; |
| 312 |
418 |
$ret .= " <td>" . ($row['is_admin'] == 1 ? "Yes" : "No") . "</td>\n"; |
$ret .= " <td>" . ($row['is_admin'] == 1 ? "Yes" : "No") . "</td>\n"; |
| 313 |
419 |
$ret .= " <td>" . gmdate("Y-m-d H:i:s", $row['itime']) . "</td>\n"; |
$ret .= " <td>" . gmdate("Y-m-d H:i:s", $row['itime']) . "</td>\n"; |
| 314 |
|
$_v = "unlimited"; |
|
| 315 |
420 |
if ($row['disk_quota_mb'] > 0) |
if ($row['disk_quota_mb'] > 0) |
| 316 |
421 |
$_v = rg_1024($row['disk_quota_mb']); |
$_v = rg_1024($row['disk_quota_mb']); |
|
422 |
|
else |
|
423 |
|
$_v = "unlimited"; |
| 317 |
424 |
$ret .= " <td>" . $_v . "</td>\n"; |
$ret .= " <td>" . $_v . "</td>\n"; |
| 318 |
425 |
$ret .= " <td>" . ($row['suspended'] == 0 ? "No" : "Yes") . "</th>\n"; |
$ret .= " <td>" . ($row['suspended'] == 0 ? "No" : "Yes") . "</th>\n"; |
| 319 |
426 |
$ret .= " <td>" . $row['session_time'] . "s</td>\n"; |
$ret .= " <td>" . $row['session_time'] . "s</td>\n"; |
| 320 |
|
$ret .= " <td>" . gmdate("Y-m-d", $row['last_seen']) . "</td>\n"; |
|
|
427 |
|
$v = $row['last_seen'] == 0 ? "-" : gmdate("Y-m-d", $row['last_seen']); |
|
428 |
|
$ret .= " <td>" . $v . "</td>\n"; |
|
429 |
|
$v = implode(", ", rg_rights_text("user", $row['rights'])); |
|
430 |
|
$ret .= " <td>" . $v . "</td>\n"; |
|
431 |
|
|
| 321 |
432 |
// operations |
// operations |
| 322 |
|
// suspend |
|
|
433 |
|
$_url = $url . "&uid=" . $row['uid']; |
| 323 |
434 |
$ret .= " <td>"; |
$ret .= " <td>"; |
| 324 |
|
$_url = $url . "&xuid=" . $row['uid']; |
|
|
435 |
|
|
|
436 |
|
// edit |
|
437 |
|
$ret .= "[<a href=\"$_url&subsubop=3\">Edit</a>]"; |
|
438 |
|
|
|
439 |
|
// suspend |
| 325 |
440 |
$v = "suspend=1"; $t = "Suspend"; |
$v = "suspend=1"; $t = "Suspend"; |
| 326 |
441 |
if ($row['suspended'] > 0) { |
if ($row['suspended'] > 0) { |
| 327 |
442 |
$t = "Unsuspend"; |
$t = "Unsuspend"; |
| 328 |
443 |
$v = "unsuspend=1"; |
$v = "unsuspend=1"; |
| 329 |
444 |
} |
} |
| 330 |
|
$ret .= "[<a href=\"$_url&$v\">$t</a>]"; |
|
|
445 |
|
$ret .= "[<a href=\"$_url&subsubop=1&$v\">$t</a>]"; |
|
446 |
|
|
| 331 |
447 |
// admin |
// admin |
| 332 |
448 |
$v = "make_admin=1"; $t = "Make admin"; |
$v = "make_admin=1"; $t = "Make admin"; |
| 333 |
449 |
if ($row['is_admin'] == 1) { |
if ($row['is_admin'] == 1) { |
| 334 |
450 |
$t = "Remove admin"; |
$t = "Remove admin"; |
| 335 |
451 |
$v = "remove_admin=1"; |
$v = "remove_admin=1"; |
| 336 |
452 |
} |
} |
| 337 |
|
$ret .= "[<a href=\"$_url&$v\">$t</a>]"; |
|
|
453 |
|
$ret .= "[<a href=\"$_url&subsubop=1&$v\">$t</a>]"; |
|
454 |
|
|
| 338 |
455 |
// remove |
// remove |
| 339 |
456 |
if ($row['suspended'] > 0) |
if ($row['suspended'] > 0) |
| 340 |
|
$ret .= "[<a href=\"$_url&remove=1\">Remove!</a>]"; |
|
|
457 |
|
$ret .= "[<a href=\"$_url&subsubop=1&remove=1\">Remove!</a>]"; |
|
458 |
|
|
| 341 |
459 |
$ret .= " </td>"; |
$ret .= " </td>"; |
| 342 |
460 |
$ret .= "</tr>\n"; |
$ret .= "</tr>\n"; |
| 343 |
461 |
} |
} |
| |
| ... |
... |
function rg_user_forgot_pass_uid($db, $token) |
| 381 |
499 |
} |
} |
| 382 |
500 |
|
|
| 383 |
501 |
/* |
/* |
| 384 |
|
* Reset password function (send mail) |
|
|
502 |
|
* Reset password function (send mail) - helper |
| 385 |
503 |
*/ |
*/ |
| 386 |
|
function rg_user_forgot_pass_mail($db, $email) |
|
|
504 |
|
function rg_user_forgot_pass_mail_prepare($db, $email) |
| 387 |
505 |
{ |
{ |
| 388 |
|
rg_log("user_forgot_pass_mail: email=$email"); |
|
|
506 |
|
rg_log("user_forgot_pass_mail_prepare: email=$email"); |
| 389 |
507 |
|
|
| 390 |
508 |
$expire = time() + 24 * 3600; |
$expire = time() + 24 * 3600; |
| 391 |
509 |
$token = rg_id(40); |
$token = rg_id(40); |
| |
| ... |
... |
function rg_user_forgot_pass_mail($db, $email) |
| 407 |
525 |
} |
} |
| 408 |
526 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
| 409 |
527 |
|
|
|
528 |
|
return $token; |
|
529 |
|
} |
|
530 |
|
|
|
531 |
|
/* |
|
532 |
|
* Reset password function (send mail) |
|
533 |
|
*/ |
|
534 |
|
function rg_user_forgot_pass_mail($db, $email) |
|
535 |
|
{ |
|
536 |
|
rg_log("user_forgot_pass_mail: email=$email"); |
|
537 |
|
|
|
538 |
|
$token = rg_user_forgot_pass_mail_prepare($db, $email); |
|
539 |
|
if ($token === FALSE) |
|
540 |
|
return FALSE; |
|
541 |
|
|
| 410 |
542 |
if (!mail($email, "Forgot password", |
if (!mail($email, "Forgot password", |
| 411 |
543 |
"Hello!\nIf you want to reset the password, follow:\n" |
"Hello!\nIf you want to reset the password, follow:\n" |
| 412 |
|
. "http://" . $_SERVER['SERVER_NAME'] . "/" . $_SERVER['PHP_SELF'] . "?op=6&token=$token")) { |
|
|
544 |
|
. "http://" . @$_SERVER['SERVER_NAME'] |
|
545 |
|
. "/" . @$_SERVER['PHP_SELF'] |
|
546 |
|
. "?op=6&token=$token")) { |
| 413 |
547 |
rg_user_set_error("Cannot send mail!"); |
rg_user_set_error("Cannot send mail!"); |
| 414 |
548 |
return FALSE; |
return FALSE; |
| 415 |
549 |
} |
} |
| |
| ... |
... |
function rg_user_forgot_pass_destroy($db, $uid) |
| 437 |
571 |
|
|
| 438 |
572 |
function rg_user_set_pass($db, $uid, $pass) |
function rg_user_set_pass($db, $uid, $pass) |
| 439 |
573 |
{ |
{ |
| 440 |
|
rg_log("user_set_pass..."); |
|
|
574 |
|
rg_log("user_set_pass: uid=$uid pass=$pass"); |
| 441 |
575 |
|
|
| 442 |
576 |
$e_salt = rg_id(40); |
$e_salt = rg_id(40); |
| 443 |
|
$e_sha1pass = sha1($e_salt . "===" . $pass); |
|
|
577 |
|
$e_sha1pass = rg_user_pass($e_salt, $pass); |
| 444 |
578 |
|
|
| 445 |
579 |
$sql = "UPDATE users SET" |
$sql = "UPDATE users SET" |
| 446 |
580 |
." salt = '$e_salt'" |
." salt = '$e_salt'" |
| File tests/repo.php changed (mode: 100644) (index 43b75be..3bc9499) |
| ... |
... |
$INC = "../inc"; |
| 5 |
5 |
require_once($INC . "/repo.inc.php"); |
require_once($INC . "/repo.inc.php"); |
| 6 |
6 |
require_once($INC . "/db/struct.inc.php"); |
require_once($INC . "/db/struct.inc.php"); |
| 7 |
7 |
|
|
| 8 |
|
rg_log_set_file(__FILE__ . ".log"); |
|
|
8 |
|
rg_log_set_file("repo.log"); |
|
9 |
|
|
|
10 |
|
$rg_sql_debug = 1; |
|
11 |
|
|
|
12 |
|
// defaults |
|
13 |
|
$rg_repo_max_len = 100; |
|
14 |
|
$rg_base_repo = "/u"; |
|
15 |
|
|
|
16 |
|
|
|
17 |
|
rg_log("name2base1"); |
|
18 |
|
$e = "/u/a/a/"; |
|
19 |
|
$c = rg_repo_name2base("aa"); |
|
20 |
|
if (strcmp($c, $e) != 0) { |
|
21 |
|
echo "name2base1 is not working correctly: c=$c e=$e.\n"; |
|
22 |
|
exit(1); |
|
23 |
|
} |
|
24 |
|
|
|
25 |
|
rg_log("name2base2"); |
|
26 |
|
$e = "/u/a/_/"; |
|
27 |
|
$c = rg_repo_name2base("a"); |
|
28 |
|
if (strcmp($c, $e) != 0) { |
|
29 |
|
echo "name2base2 is not working correctly: c=$c e=$e.\n"; |
|
30 |
|
exit(1); |
|
31 |
|
} |
|
32 |
|
|
|
33 |
|
rg_log("test if repo_allow works correctly (0)"); |
|
34 |
|
$rg_repo_allow = '/^[A-Za-z0-9]*$/'; |
|
35 |
|
$v = "xx"; |
|
36 |
|
$c = rg_repo_ok($v); |
|
37 |
|
if ($c !== TRUE) { |
|
38 |
|
echo "repo_allow problem for valid repo [$v] (c=$c).\n"; |
|
39 |
|
exit(1); |
|
40 |
|
} |
|
41 |
|
|
|
42 |
|
rg_log("test if repo_allow works correctly (1)"); |
|
43 |
|
$rg_repo_allow = '/^[A-Za-z0-9]*$/'; |
|
44 |
|
$v = "eyhtmcmet_"; |
|
45 |
|
$c = rg_repo_ok($v); |
|
46 |
|
if ($c !== FALSE) { |
|
47 |
|
echo "repo_allow problem for '_' in [$v] (c=$c).\n"; |
|
48 |
|
exit(1); |
|
49 |
|
} |
|
50 |
|
|
|
51 |
|
rg_log("test if repo_allow works correctly (2)"); |
|
52 |
|
$rg_repo_allow = '/^[A-Za-z0-9_.-]*$/'; |
|
53 |
|
$v = ".e&y.h-tmcmet&_.-"; |
|
54 |
|
$c = rg_repo_ok($v); |
|
55 |
|
if ($c !== FALSE) { |
|
56 |
|
echo "repo_allow problem for '&'.\n"; |
|
57 |
|
exit(1); |
|
58 |
|
} |
|
59 |
|
|
|
60 |
|
rg_log("check if we allow '..'"); |
|
61 |
|
$rg_repo_allow = '/^[A-Za-z0-9_.-]*$/'; |
|
62 |
|
$v = "a..b"; |
|
63 |
|
$c = rg_repo_ok($v); |
|
64 |
|
if ($c !== FALSE) { |
|
65 |
|
echo "repo_allow problem for '..'.\n"; |
|
66 |
|
exit(1); |
|
67 |
|
} |
|
68 |
|
|
|
69 |
|
rg_log("check len test"); |
|
70 |
|
$v = "0123456789A"; |
|
71 |
|
$rg_repo_allow = '/^[A-Za-z0-9]*$/'; |
|
72 |
|
$rg_repo_max_len = 10; |
|
73 |
|
$c = rg_repo_ok($v); |
|
74 |
|
if ($c !== FALSE) { |
|
75 |
|
echo "repo_ok: max length is not enforced!\n"; |
|
76 |
|
exit(1); |
|
77 |
|
} |
|
78 |
|
|
| 9 |
79 |
|
|
| 10 |
80 |
@unlink("repo.sqlite"); |
@unlink("repo.sqlite"); |
| 11 |
81 |
|
|
| |
| ... |
... |
if ($r === FALSE) { |
| 24 |
94 |
$sql = "INSERT INTO repos (repo_id, name, uid, itime" |
$sql = "INSERT INTO repos (repo_id, name, uid, itime" |
| 25 |
95 |
. ", disk_quota_mb, max_commit_size" |
. ", disk_quota_mb, max_commit_size" |
| 26 |
96 |
. ", master, desc, git_dir_done, default_rights)" |
. ", master, desc, git_dir_done, default_rights)" |
| 27 |
|
. " VALUES (1, 'repo1', 1, 0, 0, 0, 0, 'bla bla desc', 1, '')"; |
|
|
97 |
|
. " VALUES (1, 'repo1', 1, 0, 0, 0, 0, 'bla bla desc', 1, 'F')"; |
| 28 |
98 |
$res = rg_sql_query($db, $sql); |
$res = rg_sql_query($db, $sql); |
| 29 |
99 |
if ($res === FALSE) { |
if ($res === FALSE) { |
| 30 |
100 |
echo "Cannot insert a user!\n"; |
echo "Cannot insert a user!\n"; |
| 31 |
101 |
exit(1); |
exit(1); |
| 32 |
102 |
} |
} |
| 33 |
103 |
|
|
|
104 |
|
echo "test giving rights\n"; |
| 34 |
105 |
$repo_id = 1; |
$repo_id = 1; |
| 35 |
106 |
$ri = rg_repo_info($db, $repo_id, ""); |
$ri = rg_repo_info($db, $repo_id, ""); |
| 36 |
107 |
$uid = 10; |
$uid = 10; |
| 37 |
|
$v = rg_repo_rights_set($db, $ri, $uid, "F"); |
|
|
108 |
|
$v = rg_repo_rights_set($db, $ri, $uid, "P"); |
| 38 |
109 |
if ($v === FALSE) { |
if ($v === FALSE) { |
| 39 |
110 |
echo "Cannot give rights (1)!\n"; |
echo "Cannot give rights (1)!\n"; |
| 40 |
111 |
exit(1); |
exit(1); |
| 41 |
112 |
} |
} |
| 42 |
113 |
|
|
| 43 |
|
@unlink("repo.sqlite"); |
|
| 44 |
|
|
|
| 45 |
|
$a = "AF"; $b = "AD"; $e = "AFD"; |
|
| 46 |
|
$r = rg_repo_rights_combine($a, $b); |
|
| 47 |
|
if (strcmp($r, $e) != 0) { |
|
| 48 |
|
echo "Combine rights error1 ([$r] vs [$e])\n"; |
|
|
114 |
|
echo "owner gets all rights.\n"; |
|
115 |
|
$uid = 1; |
|
116 |
|
$e = rg_rights_all("repo"); |
|
117 |
|
$r = rg_repo_rights_get($db, $ri, $uid, 0); |
|
118 |
|
$c = $r['rights']; |
|
119 |
|
if (strcmp($c, $e) != 0) { |
|
120 |
|
echo "Owner did not get all rights: c=$c e=$e.\n"; |
| 49 |
121 |
exit(1); |
exit(1); |
| 50 |
122 |
} |
} |
| 51 |
123 |
|
|
| 52 |
|
$a = ""; $b = ""; $e = ""; |
|
| 53 |
|
$r = rg_repo_rights_combine($a, $b); |
|
| 54 |
|
if (strcmp($r, $e) != 0) { |
|
| 55 |
|
echo "Combine rights error1 ([$r] vs [$e])\n"; |
|
|
124 |
|
echo "non-owner gets correct rights: F gets from default rights.\n"; |
|
125 |
|
$uid = 12; |
|
126 |
|
$r = rg_repo_rights_set($db, $ri, $uid, "P"); |
|
127 |
|
if ($r !== TRUE) { |
|
128 |
|
echo "Cannot set rights (" . rg_repo_error() . ")!\n"; |
| 56 |
129 |
exit(1); |
exit(1); |
| 57 |
130 |
} |
} |
| 58 |
|
|
|
| 59 |
|
$a = "AXUJUNFUUFU"; $b = ""; $e = $a; |
|
| 60 |
|
$r = rg_repo_rights_combine($a, $b); |
|
| 61 |
|
if (strcmp($r, $e) != 0) { |
|
| 62 |
|
echo "Combine rights error1 ([$r] vs [$e])\n"; |
|
| 63 |
|
exit(1); |
|
| 64 |
|
} |
|
| 65 |
|
|
|
| 66 |
|
// test if repo_allow works correctly |
|
| 67 |
|
$rg_repo_allow = '/^[^A-Za-z0-9]*$/'; |
|
| 68 |
|
$v = "eyhtmcmet_"; |
|
| 69 |
|
$c = rg_repo_ok($v); |
|
| 70 |
|
if ($c !== FALSE) { |
|
| 71 |
|
echo "repo_allow problem for '_' ($c).\n"; |
|
|
131 |
|
$e = "FP"; |
|
132 |
|
$r = rg_repo_rights_get($db, $ri, $uid, 0); |
|
133 |
|
$c = $r['rights']; |
|
134 |
|
if (strcmp($c, $e) != 0) { |
|
135 |
|
echo "Non-owner did not get correct rights: c=$c e=$e.\n"; |
| 72 |
136 |
exit(1); |
exit(1); |
| 73 |
137 |
} |
} |
| 74 |
138 |
|
|
| 75 |
|
$rg_repo_allow = '/^[^A-Za-z0-9_.-]*$/'; |
|
| 76 |
|
$v = ".e&y.h-tmcmet&_.-"; |
|
| 77 |
|
$c = rg_repo_ok($v); |
|
| 78 |
|
if ($c !== FALSE) { |
|
| 79 |
|
echo "repo_allow problem for '&'.\n"; |
|
|
139 |
|
echo "owner can set separate rights for him\n"; |
|
140 |
|
$uid = 1; |
|
141 |
|
$v = rg_repo_rights_set($db, $ri, $uid, "A"); |
|
142 |
|
if ($v === FALSE) { |
|
143 |
|
echo "Owner cannot set separate rights for him!\n"; |
| 80 |
144 |
exit(1); |
exit(1); |
| 81 |
145 |
} |
} |
| 82 |
146 |
|
|
| 83 |
|
// check if we allow '..' |
|
| 84 |
|
$rg_repo_allow = '/^[^A-Za-z0-9_.-]*$/'; |
|
| 85 |
|
$v = "a..b"; |
|
| 86 |
|
$c = rg_repo_ok($v); |
|
| 87 |
|
if ($c !== FALSE) { |
|
| 88 |
|
echo "repo_allow problem for '..'.\n"; |
|
|
147 |
|
rg_log("list1"); |
|
148 |
|
$r = rg_repo_rights_list($db, $ri, "/prj1"); |
|
149 |
|
if ($r === FALSE) { |
|
150 |
|
echo "Cannot list rights (" . rg_repo_error() . ")\n"; |
| 89 |
151 |
exit(1); |
exit(1); |
| 90 |
152 |
} |
} |
| 91 |
153 |
|
|
| 92 |
|
// check len |
|
| 93 |
|
$v = "0123456789A"; |
|
| 94 |
|
$rg_repo_allow = '/^[^A-Za-z0-9]*$/'; |
|
| 95 |
|
$rg_repo_max_len = 10; |
|
| 96 |
|
$c = rg_repo_ok($v); |
|
| 97 |
|
if ($c !== FALSE) { |
|
| 98 |
|
echo "repo_ok: max length is not enforced!\n"; |
|
| 99 |
|
exit(1); |
|
| 100 |
|
} |
|
|
154 |
|
@unlink("repo.sqlite"); |
| 101 |
155 |
|
|
| 102 |
156 |
echo "OK\n"; |
echo "OK\n"; |
| 103 |
157 |
?> |
?> |