mirror of
https://github.com/aljazceru/gitpear.git
synced 2025-12-17 14:14:22 +01:00
@@ -30,6 +30,10 @@ function isShared (name) {
|
|||||||
return fs.existsSync(`${APP_HOME}/${name}/.git-daemon-export-ok`)
|
return fs.existsSync(`${APP_HOME}/${name}/.git-daemon-export-ok`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getACL (name) {
|
||||||
|
return fs.readFileSync(`${APP_HOME}/${name}/.git-daemon-export-ok`).toString().split('\n').filter(Boolean)
|
||||||
|
}
|
||||||
|
|
||||||
function list (sharedOnly) {
|
function list (sharedOnly) {
|
||||||
const repos = fs.readdirSync(APP_HOME)
|
const repos = fs.readdirSync(APP_HOME)
|
||||||
if (!sharedOnly) return repos.filter(r => !r.startsWith('.') && isInitialized(r))
|
if (!sharedOnly) return repos.filter(r => !r.startsWith('.') && isInitialized(r))
|
||||||
@@ -125,4 +129,5 @@ module.exports = {
|
|||||||
isDaemonRunning,
|
isDaemonRunning,
|
||||||
removeDaemonPid,
|
removeDaemonPid,
|
||||||
shareWith,
|
shareWith,
|
||||||
|
getACL,
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/rpc.js
17
src/rpc.js
@@ -101,17 +101,24 @@ module.exports = class RPC {
|
|||||||
async parseReq(req) {
|
async parseReq(req) {
|
||||||
let payload
|
let payload
|
||||||
let request = JSON.parse(req.toString())
|
let request = JSON.parse(req.toString())
|
||||||
|
const result = {
|
||||||
|
repoName: request.body.url?.split('/')?.pop(),
|
||||||
|
branch: request.body.data?.split('#')[0],
|
||||||
|
url: request.body.url
|
||||||
|
}
|
||||||
if (process.env.GIT_PEAR_AUTH) {
|
if (process.env.GIT_PEAR_AUTH) {
|
||||||
payload = await acl.getId({
|
payload = await acl.getId({
|
||||||
...request.body,
|
...request.body,
|
||||||
payload: request.header
|
payload: request.header
|
||||||
})
|
})
|
||||||
|
// read .git-daemon-export-ok
|
||||||
|
// check if payload.userId is presenet there
|
||||||
|
const aclList = home.getACL(result.repoName)
|
||||||
|
if (!aclList.includes(payload.userId)) {
|
||||||
|
throw new Error(`You are not allowed to access this repo: ${payload.userId}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return result
|
||||||
repoName: request.body.url?.split('/')?.pop(),
|
|
||||||
branch: request.body.data?.split('#')[0],
|
|
||||||
url: request.body.url
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user