This commit is contained in:
tdurieux
2017-09-29 10:11:19 +02:00
parent fc1978769e
commit ef74603914
4 changed files with 104 additions and 35 deletions

View File

@@ -3,7 +3,7 @@ import uuid
import json
import socket
import os
import urllib
# non standards, in requirements.txt
from flask import Flask, request, Markup, render_template, redirect, url_for
@@ -48,12 +48,12 @@ class Anonymous_Github:
content = content.replace(term, "XXX")
return content
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:
return Markup("<img src='%s' alt='%s'>" % (file.url, file.name))
if ".html" in file.name:
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 Markup("<a href='%s'>Download %s</a>" % (file.url, file.name))
@@ -78,17 +78,24 @@ class Anonymous_Github:
if repo[-1] == '/':
repo = repo[:-1]
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
if type(current_folder) is github.ContentFile.ContentFile:
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:
for f in current_folder:
if f.name.lower() == "readme.md" or f.name.lower() == "index.html":
current_file = f
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'])
def index():
@@ -98,15 +105,17 @@ class Anonymous_Github:
def add_repository():
id = str(uuid.uuid4())
repo = request.form['githubRepository']
terms = request.form['terms']
terms = request.form['terms'],
repo_name = request.form['name']
config_path = self.config_dir + "/" + str(id)
os.mkdir(config_path)
with open(config_path + "/config.json", 'w') as outfile:
json.dump({
"id": id,
"name": repo_name,
"repository": repo,
"terms": terms.split("\n")
"terms": terms.split()
}, outfile)
return redirect(url_for('repository', id=id))

41
static/css/style.css Normal file
View File

@@ -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;
}

View File

@@ -7,23 +7,32 @@
<!-- 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 href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container-fluid">
<h1>GihHub Anonymous</h1>
<form action="" method="post">
<div class="form-group">
<label for="githubRepository">GitHub Repository</label>
<input type="url" class="form-control" name="githubRepository" id="githubRepository" aria-describedby="githubRepository" placeholder="GitHub Repository">
<small id="githubRepositoryHelp" class="form-text text-muted">The github url to the repository that you want to anonymous.</small>
</div>
<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 class="main">
<div class="container-fluid">
<h1>GihHub Anonymous</h1>
<form action="" method="post">
<div class="form-group">
<label for="name">GitHub Repository</label>
<input type="url" class="form-control" name="name" id="name" aria-describedby="name" placeholder="Anonymous Name">
<small id="nameHelp" class="form-text text-muted">The anonymous name of the repository.</small>
</div>
<div class="form-group">
<label for="githubRepository">GitHub Repository</label>
<input type="url" class="form-control" name="githubRepository" id="githubRepository" aria-describedby="githubRepository" placeholder="GitHub Repository">
<small id="githubRepositoryHelp" class="form-text text-muted">The github url to the repository that you want to anonymous.</small>
</div>
<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>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>

View File

@@ -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 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>
<body>
<div class="container-fluid">
<table class="table">
<tbody>
{% for item in current_folder %}
<tr>
<td><a href="/repository/{{ current_repository }}/{{ item.path }}">{{ item.name }}</a> </td>
</tr>
<div class="main">
<div class="container-fluid">
<div class="paths">
{% set current_path = '/repository/' + current_repository %}
<span class="path"><a href="{{ current_path }}">{{ name }}</a></span>
{% for item in path %}
{% set current_path = current_path + "/" + item %}
<span class="path"><a href="{{ current_path }}">{{ item }}</a></span>
{% endfor %}
</tbody>
</table>
{% if current_file %}
{{ current_file|file_render(terms) }}
{% endif %}
</div>
<div class="files">
{% for item in current_folder %}
<div class="{{ item.type }} {% if item == current_file %}active{% 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>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>