mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-08-16 17:00:30 +02:00
fix configuration issue during anonymization
This commit is contained in:
@@ -35,7 +35,7 @@ const config: Config = {
|
|||||||
GITHUB_TOKEN: "",
|
GITHUB_TOKEN: "",
|
||||||
DEFAULT_QUOTA: 2 * 1024 * 1024 * 1024 * 8,
|
DEFAULT_QUOTA: 2 * 1024 * 1024 * 1024 * 8,
|
||||||
MAX_FILE_SIZE: 10 * 1024 * 1024, // in b
|
MAX_FILE_SIZE: 10 * 1024 * 1024, // in b
|
||||||
MAX_REPO_SIZE: 8 * 1024, // in kb
|
MAX_REPO_SIZE: 500 * 8 * 1024, // in kb
|
||||||
ENABLE_DOWNLOAD: false,
|
ENABLE_DOWNLOAD: false,
|
||||||
AUTH_CALLBACK: "http://localhost:5000/github/auth",
|
AUTH_CALLBACK: "http://localhost:5000/github/auth",
|
||||||
ANONYMIZATION_MASK: "XXXX",
|
ANONYMIZATION_MASK: "XXXX",
|
||||||
|
|||||||
@@ -341,7 +341,7 @@
|
|||||||
<small class="form-text text-muted"
|
<small class="form-text text-muted"
|
||||||
>How the repository will be anonymized. Stream mode will
|
>How the repository will be anonymized. Stream mode will
|
||||||
request the content on the flight. This is the only
|
request the content on the flight. This is the only
|
||||||
option for repositories bigger than 10mb. Download will
|
option for repositories bigger than {{site_options.MAX_REPO_SIZE * 1024| humanFileSize}}. Download will
|
||||||
download the repository the repository on the
|
download the repository the repository on the
|
||||||
anonymous.4open.science server, it is faster and offer
|
anonymous.4open.science server, it is faster and offer
|
||||||
more features.</small
|
more features.</small
|
||||||
|
|||||||
+32
-10
@@ -357,6 +357,7 @@ angular
|
|||||||
function ($scope, $http, $location) {
|
function ($scope, $http, $location) {
|
||||||
$scope.title = "Main";
|
$scope.title = "Main";
|
||||||
$scope.user = { status: "connection" };
|
$scope.user = { status: "connection" };
|
||||||
|
$scope.site_options;
|
||||||
|
|
||||||
$scope.path = $location.url();
|
$scope.path = $location.url();
|
||||||
$scope.paths = $location.path().substring(1).split("/");
|
$scope.paths = $location.path().substring(1).split("/");
|
||||||
@@ -386,6 +387,18 @@ angular
|
|||||||
}
|
}
|
||||||
getUser();
|
getUser();
|
||||||
|
|
||||||
|
function getOptions() {
|
||||||
|
$http.get("/api/options").then(
|
||||||
|
(res) => {
|
||||||
|
if (res) $scope.site_options = res.data;
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
$scope.site_options = null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
getOptions();
|
||||||
|
|
||||||
function getMessage() {
|
function getMessage() {
|
||||||
$http.get("/api/message").then(
|
$http.get("/api/message").then(
|
||||||
(res) => {
|
(res) => {
|
||||||
@@ -435,7 +448,6 @@ angular
|
|||||||
notebook: true,
|
notebook: true,
|
||||||
loc: true,
|
loc: true,
|
||||||
link: true,
|
link: true,
|
||||||
mode: "GitHubDownload",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getDefault() {
|
function getDefault() {
|
||||||
@@ -859,7 +871,7 @@ angular
|
|||||||
resetValidity();
|
resetValidity();
|
||||||
const res = await $http.get(`/api/repo/${o.owner}/${o.repo}/`);
|
const res = await $http.get(`/api/repo/${o.owner}/${o.repo}/`);
|
||||||
$scope.details = res.data;
|
$scope.details = res.data;
|
||||||
if ($scope.details.size > 500 * 1024 * 8) {
|
if ($scope.details.size > $scope.site_options.MAX_REPO_SIZE) {
|
||||||
$scope.options.mode = "GitHubStream";
|
$scope.options.mode = "GitHubStream";
|
||||||
$scope.anonymize.mode.$$element[0].disabled = true;
|
$scope.anonymize.mode.$$element[0].disabled = true;
|
||||||
}
|
}
|
||||||
@@ -902,41 +914,51 @@ angular
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!$scope.options.link) {
|
if (!$scope.options.link) {
|
||||||
content = content.replace(urlRegex, "XXXX");
|
content = content.replace(
|
||||||
|
urlRegex,
|
||||||
|
$scope.site_options.ANONYMIZATION_MASK
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const host = document.location.protocol + "//" + document.location.host;
|
||||||
|
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
new RegExp(
|
new RegExp(
|
||||||
`\\b${$scope.repoUrl}/blob/${$scope.source.branch}\\b`,
|
`\\b${$scope.repoUrl}/blob/${$scope.source.branch}\\b`,
|
||||||
"gi"
|
"gi"
|
||||||
),
|
),
|
||||||
`https://anonymous.4open.science/r/${$scope.repoId}`
|
`${host}/r/${$scope.repoId}`
|
||||||
);
|
);
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
new RegExp(
|
new RegExp(
|
||||||
`\\b${$scope.repoUrl}/tree/${$scope.source.branch}\\b`,
|
`\\b${$scope.repoUrl}/tree/${$scope.source.branch}\\b`,
|
||||||
"gi"
|
"gi"
|
||||||
),
|
),
|
||||||
`https://anonymous.4open.science/r/${$scope.repoId}`
|
`${host}/r/${$scope.repoId}`
|
||||||
);
|
);
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
new RegExp(`\\b${$scope.repoUrl}`, "gi"),
|
new RegExp(`\\b${$scope.repoUrl}`, "gi"),
|
||||||
`https://anonymous.4open.science/r/${$scope.repoId}`
|
`${host}/r/${$scope.repoId}`
|
||||||
);
|
);
|
||||||
|
const terms = $scope.terms.split("\n");
|
||||||
for (let term of $scope.terms.split("\n")) {
|
for (let i = 0; i < terms.length; i++) {
|
||||||
|
const term = terms[i];
|
||||||
if (term.trim() == "") {
|
if (term.trim() == "") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// remove whole url if it contains the term
|
// remove whole url if it contains the term
|
||||||
|
|
||||||
content = content.replace(urlRegex, (match) => {
|
content = content.replace(urlRegex, (match) => {
|
||||||
if (new RegExp(`\\b${term}\\b`, "gi").test(match)) return "XXXX";
|
if (new RegExp(`\\b${term}\\b`, "gi").test(match))
|
||||||
|
return $scope.site_options.ANONYMIZATION_MASK + "-" + (i + 1);
|
||||||
return match;
|
return match;
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove the term in the text
|
// remove the term in the text
|
||||||
content = content.replace(new RegExp(`\\b${term}\\b`, "gi"), "XXXX");
|
content = content.replace(
|
||||||
|
new RegExp(`\\b${term}\\b`, "gi"),
|
||||||
|
$scope.site_options.ANONYMIZATION_MASK + "-" + (i + 1)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.anonymize_readme = content;
|
$scope.anonymize_readme = content;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import repositoryPublic from "./repository-public";
|
|||||||
import file from "./file";
|
import file from "./file";
|
||||||
import webview from "./webview";
|
import webview from "./webview";
|
||||||
import user from "./user";
|
import user from "./user";
|
||||||
|
import option from "./option";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
repositoryPrivate,
|
repositoryPrivate,
|
||||||
@@ -10,4 +11,5 @@ export default {
|
|||||||
file,
|
file,
|
||||||
webview,
|
webview,
|
||||||
user,
|
user,
|
||||||
|
option,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import * as express from "express";
|
||||||
|
import config from "../../config";
|
||||||
|
export const router = express.Router();
|
||||||
|
|
||||||
|
router.get("/", async (req: express.Request, res: express.Response) => {
|
||||||
|
res.json({
|
||||||
|
ENABLE_DOWNLOAD: config.ENABLE_DOWNLOAD,
|
||||||
|
MAX_FILE_SIZE: config.MAX_FILE_SIZE,
|
||||||
|
MAX_REPO_SIZE: config.MAX_REPO_SIZE,
|
||||||
|
ANONYMIZATION_MASK: config.ANONYMIZATION_MASK,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
||||||
@@ -159,6 +159,22 @@ router.get(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// get repository information
|
||||||
|
router.get("/:repoId/", async (req: express.Request, res: express.Response) => {
|
||||||
|
try {
|
||||||
|
const repo = await getRepo(req, res, { nocheck: true });
|
||||||
|
if (!repo) throw new Error("repo_not_found");
|
||||||
|
|
||||||
|
const user = await getUser(req);
|
||||||
|
if (user.username != repo.model.owner) {
|
||||||
|
return res.status(401).send({ error: "not_authorized" });
|
||||||
|
}
|
||||||
|
res.json((await db.getRepository(req.params.repoId)).toJSON());
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error, res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function validateNewRepo(repoUpdate) {
|
function validateNewRepo(repoUpdate) {
|
||||||
const validCharacters = /^[0-9a-zA-Z\-\_]+$/;
|
const validCharacters = /^[0-9a-zA-Z\-\_]+$/;
|
||||||
if (
|
if (
|
||||||
@@ -184,7 +200,19 @@ function validateNewRepo(repoUpdate) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateRepoModel(model: IAnonymizedRepositoryDocument, repoUpdate) {
|
function updateRepoModel(
|
||||||
|
model: IAnonymizedRepositoryDocument,
|
||||||
|
repoUpdate: any
|
||||||
|
) {
|
||||||
|
if (repoUpdate.source.type) {
|
||||||
|
model.source.type = repoUpdate.source.type;
|
||||||
|
if (
|
||||||
|
model.source.type != "GitHubStream" &&
|
||||||
|
model.source.type != "GitHubDownload"
|
||||||
|
) {
|
||||||
|
model.source.type = "GitHubStream";
|
||||||
|
}
|
||||||
|
}
|
||||||
model.source.commit = repoUpdate.source.commit;
|
model.source.commit = repoUpdate.source.commit;
|
||||||
model.source.branch = repoUpdate.source.branch;
|
model.source.branch = repoUpdate.source.branch;
|
||||||
model.conference = repoUpdate.conference;
|
model.conference = repoUpdate.conference;
|
||||||
@@ -204,22 +232,6 @@ function updateRepoModel(model: IAnonymizedRepositoryDocument, repoUpdate) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// get repository information
|
|
||||||
router.get("/:repoId/", async (req: express.Request, res: express.Response) => {
|
|
||||||
try {
|
|
||||||
const repo = await getRepo(req, res, { nocheck: true });
|
|
||||||
if (!repo) throw new Error("repo_not_found");
|
|
||||||
|
|
||||||
const user = await getUser(req);
|
|
||||||
if (user.username != repo.model.owner) {
|
|
||||||
return res.status(401).send({ error: "not_authorized" });
|
|
||||||
}
|
|
||||||
res.json((await db.getRepository(req.params.repoId)).toJSON());
|
|
||||||
} catch (error) {
|
|
||||||
handleError(error, res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// update a repository
|
// update a repository
|
||||||
router.post(
|
router.post(
|
||||||
"/:repoId/",
|
"/:repoId/",
|
||||||
@@ -273,15 +285,11 @@ router.post("/", async (req: express.Request, res: express.Response) => {
|
|||||||
repo.repoId = repoUpdate.repoId;
|
repo.repoId = repoUpdate.repoId;
|
||||||
repo.anonymizeDate = new Date();
|
repo.anonymizeDate = new Date();
|
||||||
repo.owner = user.username;
|
repo.owner = user.username;
|
||||||
repo.source = {
|
|
||||||
type:
|
updateRepoModel(repo, repoUpdate);
|
||||||
repoUpdate.options.mode == "download"
|
repo.source.accessToken = user.accessToken;
|
||||||
? "GitHubDownload"
|
repo.source.repositoryId = repository.model.id;
|
||||||
: "GitHubStream",
|
repo.source.repositoryName = repoUpdate.fullName;
|
||||||
accessToken: user.accessToken,
|
|
||||||
repositoryId: repository.model.id,
|
|
||||||
repositoryName: repoUpdate.fullName,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (repo.source.type == "GitHubDownload") {
|
if (repo.source.type == "GitHubDownload") {
|
||||||
// details.size is in kilobytes
|
// details.size is in kilobytes
|
||||||
@@ -290,8 +298,6 @@ router.post("/", async (req: express.Request, res: express.Response) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRepoModel(repo, repoUpdate);
|
|
||||||
|
|
||||||
await repo.save();
|
await repo.save();
|
||||||
res.send("ok");
|
res.send("ok");
|
||||||
new Repository(repo).anonymize();
|
new Repository(repo).anonymize();
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ router.get(
|
|||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
url: redirectURL,
|
url: redirectURL,
|
||||||
download: !!config.ENABLE_DOWNLOAD,
|
download:
|
||||||
|
!!config.ENABLE_DOWNLOAD && repo.source.type == "GitHubDownload",
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, res);
|
handleError(error, res);
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ export default async function start() {
|
|||||||
app.use("/github", rate, connection.router);
|
app.use("/github", rate, connection.router);
|
||||||
|
|
||||||
// api routes
|
// api routes
|
||||||
|
app.use("/api/options", rate, router.option);
|
||||||
app.use("/api/user", rate, router.user);
|
app.use("/api/user", rate, router.user);
|
||||||
app.use("/api/repo", rate, router.repositoryPublic);
|
app.use("/api/repo", rate, router.repositoryPublic);
|
||||||
app.use("/api/repo", rate, router.file);
|
app.use("/api/repo", rate, router.file);
|
||||||
|
|||||||
Reference in New Issue
Block a user