mirror of
https://gitnet.fr/deblan/gist.git
synced 2021-08-14 08:30:49 +02:00
Ciphered GIST cloning
This commit is contained in:
parent
c8d35c23bb
commit
6ab827bf94
@ -17,7 +17,14 @@
|
||||
</p>
|
||||
<p>
|
||||
{{ form_errors(form.content) }}
|
||||
{{ form_widget(form.content) }}
|
||||
|
||||
{% set class = 'form-control' %}
|
||||
|
||||
{% if gist.cipher %}
|
||||
{% set class = class ~ ' cipher-editor' %}
|
||||
{% endif %}
|
||||
|
||||
{{ form_widget(form.content, {attr: {class: class}}) }}
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" class="btn btn-primary" value="{{ 'form.submit'|trans }}">
|
||||
@ -29,3 +36,13 @@
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{% if gist.cipher %}
|
||||
<script>
|
||||
var cipherGistClone = true;
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
{{ parent() }}
|
||||
{% endblock %}
|
||||
|
@ -50,14 +50,14 @@
|
||||
<div class="col-md-12" id="embed">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
{% if not gist.cipher %}
|
||||
<div class="pull-right actions">
|
||||
<a target="_blank" href="{{ path('view', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
|
||||
<span class="btn btn-warning btn-xs">
|
||||
{{ commit|slice(0, 10) }}
|
||||
</span>
|
||||
</a>
|
||||
<div class="pull-right actions">
|
||||
<a target="_blank" href="{{ path('view', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
|
||||
<span class="btn btn-warning btn-xs">
|
||||
{{ commit|slice(0, 10) }}
|
||||
</span>
|
||||
</a>
|
||||
|
||||
{% if not gist.cipher %}
|
||||
<a target="_blank" href="{{ path('raw', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
|
||||
<span class="glyphicon glyphicon-eye-open"></span>
|
||||
{{ 'gist.action.raw'|trans }}
|
||||
@ -66,12 +66,13 @@
|
||||
<span class="glyphicon glyphicon-save-file"></span>
|
||||
{{ 'gist.action.download'|trans }}
|
||||
</a>
|
||||
<a target="_blank" href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="btn btn-success btn-sm">
|
||||
<span class="glyphicon glyphicon-copy"></span>
|
||||
{{ 'gist.action.clone'|trans }}
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<a target="_blank" href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="btn btn-success btn-sm">
|
||||
<span class="glyphicon glyphicon-copy"></span>
|
||||
{{ 'gist.action.clone'|trans }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{ gist.title ? gist.title : 'gist.untitled'|trans }}
|
||||
</div>
|
||||
|
@ -11,21 +11,19 @@
|
||||
{% block body %}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{% if not gist.cipher %}
|
||||
<ul class="nav nav-tabs">
|
||||
<li>
|
||||
<a href="{{ path('view', {gist: gist.file}) }}">
|
||||
{{ 'gist.action.view'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
<li class="active">
|
||||
<a href="{{ path('revisions', {gist: gist.file}) }}">
|
||||
{{ 'gist.action.history'|trans }}
|
||||
<span class="badge">{{ history|length }}</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
<ul class="nav nav-tabs">
|
||||
<li>
|
||||
<a href="{{ path('view', {gist: gist.file}) }}" class="cipher-link">
|
||||
{{ 'gist.action.view'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
<li class="active">
|
||||
<a href="{{ path('revisions', {gist: gist.file}) }}" class="cipher-link">
|
||||
{{ 'gist.action.history'|trans }}
|
||||
<span class="badge">{{ history|length }}</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
@ -33,42 +31,40 @@
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="tab-content">
|
||||
{% if not gist.cipher %}
|
||||
<div id="revisions" class="tab-pane in active">
|
||||
{% for commit in history %}
|
||||
<div class="commit">
|
||||
<p>
|
||||
<a href="{{ path('view', {gist: gist.file, commit: commit.commit}) }}" class="btn btn-warning btn-sm">
|
||||
{{ commit.commit|slice(0, 10) }}
|
||||
<div id="revisions" class="tab-pane in active">
|
||||
{% for commit in history %}
|
||||
<div class="commit">
|
||||
<p>
|
||||
<a href="{{ path('view', {gist: gist.file, commit: commit.commit}) }}" class="btn btn-warning btn-sm cipher-link">
|
||||
{{ commit.commit|slice(0, 10) }}
|
||||
</a>
|
||||
|
||||
{% if loop.first %}<span class="btn btn-info btn-sm">init</span>{% endif %}
|
||||
|
||||
{% if not loop.first %}
|
||||
<a href="#diff-{{ loop.index }}" data-target="#diff-{{ loop.index }}" class="btn btn-default btn-sm show-diff">
|
||||
diff
|
||||
</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
<p>
|
||||
{{ commit.date|date('date.format'|trans) }}
|
||||
</p>
|
||||
<div>
|
||||
{% if not loop.first %}
|
||||
|
||||
{% if loop.first %}<span class="btn btn-info btn-sm">init</span>{% endif %}
|
||||
|
||||
{% if not loop.first %}
|
||||
<a href="#diff-{{ loop.index }}" data-target="#diff-{{ loop.index }}" class="btn btn-default btn-sm show-diff">
|
||||
diff
|
||||
</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
<p>
|
||||
{{ commit.date|date('date.format'|trans) }}
|
||||
</p>
|
||||
<div>
|
||||
{% if not loop.first %}
|
||||
|
||||
<div class="diff" id="diff-{{ loop.index }}">
|
||||
{{ commit.diff|raw }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="diff" id="diff-{{ loop.index }}">
|
||||
{{ commit.diff|raw }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if not loop.last %}
|
||||
<hr />
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if not loop.last %}
|
||||
<hr />
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -16,29 +16,28 @@
|
||||
{% block body %}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
{% if not gist.cipher %}
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active">
|
||||
<a href="{{ path('view', {gist: gist.file}) }}">
|
||||
{{ 'gist.action.view'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ path('revisions', {gist: gist.file}) }}">
|
||||
{{ 'gist.action.history'|trans }}
|
||||
<span class="badge">{{ history|length }}</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active">
|
||||
<a href="{{ path('view', {gist: gist.file}) }}" class="cipher-link">
|
||||
{{ 'gist.action.view'|trans }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ path('revisions', {gist: gist.file}) }}" class="cipher-link">
|
||||
{{ 'gist.action.history'|trans }}
|
||||
<span class="badge">{{ history|length }}</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
{% if not gist.cipher %}
|
||||
<div class="pull-right actions">
|
||||
<span class="btn btn-warning btn-xs">
|
||||
{{ commit|slice(0, 10) }}
|
||||
</span>
|
||||
<div class="pull-right actions">
|
||||
<span class="btn btn-warning btn-xs">
|
||||
{{ commit|slice(0, 10) }}
|
||||
</span>
|
||||
|
||||
{% if not gist.cipher %}
|
||||
<a href="{{ path('raw', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
|
||||
<span class="glyphicon glyphicon-eye-open"></span>
|
||||
{{ 'gist.action.raw'|trans }}
|
||||
@ -47,12 +46,13 @@
|
||||
<span class="glyphicon glyphicon-save-file"></span>
|
||||
{{ 'gist.action.download'|trans }}
|
||||
</a>
|
||||
<a href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="btn btn-success btn-sm">
|
||||
<span class="glyphicon glyphicon-copy"></span>
|
||||
{{ 'gist.action.clone'|trans }}
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<a href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="btn btn-success btn-sm cipher-link">
|
||||
<span class="glyphicon glyphicon-copy"></span>
|
||||
{{ 'gist.action.clone'|trans }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{ gist.title ? gist.title : 'gist.untitled'|trans }}
|
||||
|
||||
|
@ -71,10 +71,10 @@
|
||||
</ul>
|
||||
{% block langs %}
|
||||
<p class="navbar-text navbar-right">
|
||||
<a class="lang btn btn-xs" href="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge({_locale: 'en'})) }}">
|
||||
<a class="lang btn btn-xs cipher-link" href="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge({_locale: 'en'})) }}">
|
||||
<span class="flag-icon flag-icon-gb"></span>
|
||||
</a>
|
||||
<a class="lang btn btn-xs" href="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge({_locale: 'fr'})) }}">
|
||||
<a class="lang btn btn-xs cipher-link" href="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge({_locale: 'fr'})) }}">
|
||||
<span class="flag-icon flag-icon-fr"></span>
|
||||
</a>
|
||||
</p>
|
||||
|
@ -94,8 +94,15 @@ var mainEditorEvents = function() {
|
||||
});
|
||||
|
||||
$('#main-form').submit(function(e) {
|
||||
if ($('.cipher-input:checked').val() === 'yes') {
|
||||
var passphrase = randomString(256, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
if ($('.cipher-input:checked').val() === 'yes' || typeof cipherGistClone !== 'undefined') {
|
||||
var key = getKey();
|
||||
|
||||
if (key) {
|
||||
var passphrase = key;
|
||||
} else {
|
||||
var passphrase = randomString(256, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
}
|
||||
|
||||
var content = $('#form_content').val();
|
||||
var encrypted = CryptoJS.AES.encrypt(content, passphrase, {
|
||||
format: JsonFormatter
|
||||
@ -123,25 +130,43 @@ var viewerEvents = function() {
|
||||
|
||||
$(document).ready(function() {
|
||||
var key = getKey();
|
||||
|
||||
var $cipherEditor = $('.cipher-editor');
|
||||
var $embedInput = $('#embed-input');
|
||||
var to = ' ';
|
||||
|
||||
if (0 !== $render.length && key) {
|
||||
var decrypted = CryptoJS.AES.decrypt($render.html(), key, {
|
||||
format: JsonFormatter
|
||||
if (key) {
|
||||
$('.cipher-link').each(function() {
|
||||
var href = $(this).attr('href');
|
||||
href = href + '#key=' + key;
|
||||
|
||||
$(this).attr('href', href);
|
||||
});
|
||||
$render.text(decrypted.toString(CryptoJS.enc.Utf8));
|
||||
SyntaxHighlighter.all();
|
||||
|
||||
to = ' data-key="#key=' + key + '" ';
|
||||
var to = ' ';
|
||||
|
||||
$('.lang').each(function() {
|
||||
$(this).attr('href', $(this).attr('href') + '#key=' + key);
|
||||
});
|
||||
}
|
||||
if (0 !== $render.length || $cipherEditor.length !== 0) {
|
||||
|
||||
if ($embedInput.length) {
|
||||
$embedInput.val($embedInput.val().replace('%key%', to));
|
||||
if ($render.length !== 0) {
|
||||
var decrypted = CryptoJS.AES.decrypt($render.html(), key, {
|
||||
format: JsonFormatter
|
||||
});
|
||||
|
||||
$render.text(decrypted.toString(CryptoJS.enc.Utf8));
|
||||
SyntaxHighlighter.all();
|
||||
|
||||
to = ' data-key="#key=' + key + '" ';
|
||||
} else {
|
||||
var decrypted = CryptoJS.AES.decrypt($cipherEditor.val(), key, {
|
||||
format: JsonFormatter
|
||||
});
|
||||
|
||||
$cipherEditor.val(decrypted.toString(CryptoJS.enc.Utf8));
|
||||
}
|
||||
}
|
||||
|
||||
if ($embedInput.length) {
|
||||
$embedInput.val($embedInput.val().replace('%key%', to));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user