mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-05-25 18:37:47 +02:00
update
This commit is contained in:
@@ -3,7 +3,7 @@ import uuid
|
|||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
import os
|
import os
|
||||||
|
import urllib
|
||||||
|
|
||||||
# non standards, in requirements.txt
|
# non standards, in requirements.txt
|
||||||
from flask import Flask, request, Markup, render_template, redirect, url_for
|
from flask import Flask, request, Markup, render_template, redirect, url_for
|
||||||
@@ -48,12 +48,12 @@ class Anonymous_Github:
|
|||||||
content = content.replace(term, "XXX")
|
content = content.replace(term, "XXX")
|
||||||
return content
|
return content
|
||||||
if ".md" in file.name:
|
if ".md" in file.name:
|
||||||
return "<div class='markdown-body'>%s</div>" % removeTerms(Markup(self.github.render_markdown(file.decoded_content)), terms)
|
return Markup("<div class='markdown-body'>%s</div>" % removeTerms(self.github.render_markdown(file.decoded_content), terms))
|
||||||
if ".jpg" in file.name or ".png" in file.name or ".png" in file.name or ".gif" in file.name:
|
if ".jpg" in file.name or ".png" in file.name or ".png" in file.name or ".gif" in file.name:
|
||||||
return Markup("<img src='%s' alt='%s'>" % (file.url, file.name))
|
return Markup("<img src='%s' alt='%s'>" % (file.url, file.name))
|
||||||
if ".html" in file.name:
|
if ".html" in file.name:
|
||||||
return removeTerms(Markup(file.decoded_content), terms)
|
return removeTerms(Markup(file.decoded_content), terms)
|
||||||
if ".txt" in file.name or ".java" in file.name or ".py" in file.name:
|
if ".txt" in file.name or ".log" in file.name or ".xml" in file.name or ".java" in file.name or ".py" in file.name:
|
||||||
return removeTerms(Markup("<pre>" + file.decoded_content + "</pre>"), terms)
|
return removeTerms(Markup("<pre>" + file.decoded_content + "</pre>"), terms)
|
||||||
return Markup("<a href='%s'>Download %s</a>" % (file.url, file.name))
|
return Markup("<a href='%s'>Download %s</a>" % (file.url, file.name))
|
||||||
|
|
||||||
@@ -78,17 +78,24 @@ class Anonymous_Github:
|
|||||||
if repo[-1] == '/':
|
if repo[-1] == '/':
|
||||||
repo = repo[:-1]
|
repo = repo[:-1]
|
||||||
g_repo = self.github.get_repo(repo)
|
g_repo = self.github.get_repo(repo)
|
||||||
current_folder = g_repo.get_contents(path)
|
current_folder = g_repo.get_contents(urllib.quote(path))
|
||||||
current_file = None
|
current_file = None
|
||||||
if type(current_folder) is github.ContentFile.ContentFile:
|
if type(current_folder) is github.ContentFile.ContentFile:
|
||||||
current_file = current_folder
|
current_file = current_folder
|
||||||
current_folder = g_repo.get_contents(os.path.dirname(path))
|
current_folder = g_repo.get_contents(urllib.quote(os.path.dirname(path)))
|
||||||
else:
|
else:
|
||||||
for f in current_folder:
|
for f in current_folder:
|
||||||
if f.name.lower() == "readme.md" or f.name.lower() == "index.html":
|
if f.name.lower() == "readme.md" or f.name.lower() == "index.html":
|
||||||
current_file = f
|
current_file = f
|
||||||
break
|
break
|
||||||
return render_template('repo.html', terms=data["terms"], current_repository=id, current_file=current_file, current_folder=current_folder)
|
|
||||||
|
return render_template('repo.html',
|
||||||
|
name=data['name'],
|
||||||
|
terms=data["terms"],
|
||||||
|
current_repository=id,
|
||||||
|
current_file=current_file,
|
||||||
|
current_folder=current_folder,
|
||||||
|
path=path.split("/") if path != '' else [])
|
||||||
|
|
||||||
@application.route('/', methods=['GET'])
|
@application.route('/', methods=['GET'])
|
||||||
def index():
|
def index():
|
||||||
@@ -98,15 +105,17 @@ class Anonymous_Github:
|
|||||||
def add_repository():
|
def add_repository():
|
||||||
id = str(uuid.uuid4())
|
id = str(uuid.uuid4())
|
||||||
repo = request.form['githubRepository']
|
repo = request.form['githubRepository']
|
||||||
terms = request.form['terms']
|
terms = request.form['terms'],
|
||||||
|
repo_name = request.form['name']
|
||||||
|
|
||||||
config_path = self.config_dir + "/" + str(id)
|
config_path = self.config_dir + "/" + str(id)
|
||||||
os.mkdir(config_path)
|
os.mkdir(config_path)
|
||||||
with open(config_path + "/config.json", 'w') as outfile:
|
with open(config_path + "/config.json", 'w') as outfile:
|
||||||
json.dump({
|
json.dump({
|
||||||
"id": id,
|
"id": id,
|
||||||
|
"name": repo_name,
|
||||||
"repository": repo,
|
"repository": repo,
|
||||||
"terms": terms.split("\n")
|
"terms": terms.split()
|
||||||
}, outfile)
|
}, outfile)
|
||||||
return redirect(url_for('repository', id=id))
|
return redirect(url_for('repository', id=id))
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
.main {
|
||||||
|
width: 80%;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files {
|
||||||
|
border: 1px solid #dddddd;
|
||||||
|
border-bottom: initial;
|
||||||
|
margin: 15px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files a {
|
||||||
|
display: block;
|
||||||
|
padding: 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files .file, .files .dir, .files .parent_folder {
|
||||||
|
border-bottom: 1px solid #dddddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.files .file.active, .files .file:hover, .files .dir:hover, .files .parent_folder:hover {
|
||||||
|
background: #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paths {
|
||||||
|
margin: 15px;
|
||||||
|
border: 1px solid #dddddd;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 8px
|
||||||
|
}
|
||||||
|
|
||||||
|
.paths a {
|
||||||
|
color: #000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.paths .path::after {
|
||||||
|
content: '/';
|
||||||
|
color: #dddddd;
|
||||||
|
padding-left: 4px;
|
||||||
|
}
|
||||||
+24
-15
@@ -7,23 +7,32 @@
|
|||||||
|
|
||||||
<!-- Bootstrap CSS -->
|
<!-- Bootstrap CSS -->
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
|
||||||
|
|
||||||
|
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet" type="text/css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container-fluid">
|
<div class="main">
|
||||||
<h1>GihHub Anonymous</h1>
|
<div class="container-fluid">
|
||||||
<form action="" method="post">
|
<h1>GihHub Anonymous</h1>
|
||||||
<div class="form-group">
|
<form action="" method="post">
|
||||||
<label for="githubRepository">GitHub Repository</label>
|
<div class="form-group">
|
||||||
<input type="url" class="form-control" name="githubRepository" id="githubRepository" aria-describedby="githubRepository" placeholder="GitHub Repository">
|
<label for="name">GitHub Repository</label>
|
||||||
<small id="githubRepositoryHelp" class="form-text text-muted">The github url to the repository that you want to anonymous.</small>
|
<input type="url" class="form-control" name="name" id="name" aria-describedby="name" placeholder="Anonymous Name">
|
||||||
</div>
|
<small id="nameHelp" class="form-text text-muted">The anonymous name of the repository.</small>
|
||||||
<div class="form-group">
|
</div>
|
||||||
<label for="ignoredTerms">The text to remove from the repository</label>
|
<div class="form-group">
|
||||||
<textarea class="form-control" name="terms" id="ignoredTerms" rows="5"></textarea>
|
<label for="githubRepository">GitHub Repository</label>
|
||||||
<small id="ignoredTermsHelp" class="form-text text-muted">One term per line.</small>
|
<input type="url" class="form-control" name="githubRepository" id="githubRepository" aria-describedby="githubRepository" placeholder="GitHub Repository">
|
||||||
</div>
|
<small id="githubRepositoryHelp" class="form-text text-muted">The github url to the repository that you want to anonymous.</small>
|
||||||
<button type="submit" class="btn btn-primary">Submit</button>
|
</div>
|
||||||
</form>
|
<div class="form-group">
|
||||||
|
<label for="ignoredTerms">The text to remove from the repository</label>
|
||||||
|
<textarea class="form-control" name="terms" id="ignoredTerms" rows="5"></textarea>
|
||||||
|
<small id="ignoredTermsHelp" class="form-text text-muted">One term per line.</small>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
||||||
|
|||||||
+22
-12
@@ -9,21 +9,31 @@
|
|||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
|
||||||
|
|
||||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.8.0/github-markdown.min.css" rel="stylesheet" type="text/css" />
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.8.0/github-markdown.min.css" rel="stylesheet" type="text/css" />
|
||||||
|
|
||||||
|
<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet" type="text/css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container-fluid">
|
<div class="main">
|
||||||
<table class="table">
|
<div class="container-fluid">
|
||||||
<tbody>
|
<div class="paths">
|
||||||
{% for item in current_folder %}
|
{% set current_path = '/repository/' + current_repository %}
|
||||||
<tr>
|
<span class="path"><a href="{{ current_path }}">{{ name }}</a></span>
|
||||||
<td><a href="/repository/{{ current_repository }}/{{ item.path }}">{{ item.name }}</a> </td>
|
{% for item in path %}
|
||||||
</tr>
|
{% set current_path = current_path + "/" + item %}
|
||||||
|
<span class="path"><a href="{{ current_path }}">{{ item }}</a></span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</div>
|
||||||
</table>
|
<div class="files">
|
||||||
{% if current_file %}
|
{% for item in current_folder %}
|
||||||
{{ current_file|file_render(terms) }}
|
<div class="{{ item.type }} {% if item == current_file %}active{% endif %}">
|
||||||
{% endif %}
|
<a href="/repository/{{ current_repository }}/{{ item.path }}">{{ item.name }}</a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% if current_file %}
|
||||||
|
{{ current_file|file_render(terms) }}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user