Skip to content

Commit

Permalink
Merge pull request #683 from Safihre/develop
Browse files Browse the repository at this point in the history
Generate new HTTPS-certificates and more
  • Loading branch information
shypike committed Sep 19, 2016
2 parents 790bcd7 + e27f0c5 commit bd19962
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 12 deletions.
25 changes: 25 additions & 0 deletions interfaces/Config/templates/config_general.tmpl
Expand Up @@ -143,11 +143,13 @@
<div class="field-pair">
<label class="config" for="https_cert">$T('opt-https_cert')</label>
<input type="text" name="https_cert" id="https_cert" value="$https_cert" />
<button class="btn btn-default generate_cert" title="$T('explain-new-cert')"><span class="glyphicon glyphicon-repeat"></span></button>
<span class="desc">$T('explain-https_cert')</span>
</div>
<div class="field-pair">
<label class="config" for="https_key">$T('opt-https_key')</label>
<input type="text" name="https_key" id="https_key" value="$https_key" />
<button class="btn btn-default generate_cert" title="$T('explain-new-cert')"><span class="glyphicon glyphicon-repeat"></span></button>
<span class="desc">$T('explain-https_key')</span>
</div>
<div class="field-pair">
Expand Down Expand Up @@ -257,6 +259,29 @@
// No save on this button click
e.preventDefault();
});

\$('.generate_cert').click(function(e) {
if(!confirm('$T('explain-new-cert')')) {
return;
}

// Submit request and then restart
$.ajax({
type: "POST",
url: "../../tapi",
data: { mode: 'config', name: 'regenerate_certs', apikey: \$('#apikey').val() },
success: function(msg) {
do_restart()
}
});

e.preventDefault();
})

// Only allow re-generate if default certs
if(\$('#https_cert').val() != 'server.cert') {
\$('.generate_cert').attr('disabled', 'disabled')
}
});
</script>

Expand Down
15 changes: 14 additions & 1 deletion interfaces/Config/templates/config_rss.tmpl
Expand Up @@ -51,7 +51,7 @@
</td>
<td class="title">
<a href="?feed=$rss[$feed_item]['link']" class="subscription-title path feed <!--#if int($rss[$feed_item]['enable']) != 0 then 'feed_enabled' else 'feed_disabled'#-->">
<div class="favicon" style="background-image: url(https://www.google.com/s2/favicons?domain=$rss[$feed_item]['baselink']&amp;alt=feed);"></div> $feed_item
<div class="favicon" data-domain="$rss[$feed_item]['baselink']"></div> $feed_item
</a>
</td>
<td class="controls">
Expand Down Expand Up @@ -478,6 +478,19 @@ function urlencode(str) {
}

\$(document).ready(function(){
\$('.favicon').each(function(i, theContainer) {
// Easy favicon grabber
var favUrl = '//' + \$(theContainer).data('domain') + '/favicon.ico'
\$(theContainer).css({'background': 'url('+favUrl+')', 'background-size': '16px 16px'})

// Does the image exist? Otherwise place a glyphicon
var testFavImg= new Image();
testFavImg.src = favUrl;
testFavImg.onerror = function (evt){
\$(theContainer).append('<span class="glyphicon glyphicon-list"></span>')
}
})

\$('.tabs a').click(function (e) {
e.preventDefault()
\$(this).tab('show')
Expand Down
18 changes: 14 additions & 4 deletions interfaces/Config/templates/config_scheduling.tmpl
Expand Up @@ -55,8 +55,8 @@ else:
</optgroup>
<optgroup label="$T('cmenu-servers')">
<!--#for $server in $actions_servers.keys()#-->
<option value="$server" data-action="1"data-noarg="1">$T('sch-enable_server') "$actions_servers[$server]"</option>
<option value="$server" data-action="0"data-noarg="1">$T('sch-disable_server') "$actions_servers[$server]"</option>
<option value="$server" data-action="1" data-noarg="1">$T('sch-enable_server') "$actions_servers[$server]"</option>
<option value="$server" data-action="0" data-noarg="1">$T('sch-disable_server') "$actions_servers[$server]"</option>
<!--#end for#-->
</optgroup>
</select>
Expand Down Expand Up @@ -109,12 +109,22 @@ else:
\$('#action').on('change', function() {
// Set the action
\$('#arguments').val((\$(this).find('option:selected').data('action')))
// Arguments

// Is it speedlimit?
if(\$(this).find('option:selected').val() == 'speedlimit') {
\$('#hidden_arguments').show()
\$('#hidden_arguments input').attr('placeholder', 'Bytes/s, "1M" = 1 MB/s, "500K" = 500 KB/s')
} else {
\$('#hidden_arguments').hide()
\$('#hidden_arguments input').attr('placeholder', '')
}

/* Arguments - since we only have speedlimit with arguments, disabled for now
if(\$(this).find('option:selected').data('noarg')) {
\$('#hidden_arguments').hide()
} else {
\$('#hidden_arguments').show()
}
}*/
})
</script>
<!--#include $webdir + "/_inc_footer_uc.tmpl"#-->
6 changes: 4 additions & 2 deletions interfaces/Config/templates/staticcfg/css/style.css
Expand Up @@ -234,7 +234,8 @@ textarea:hover, input[type="date"]:hover, input[type="datetime"]:hover, input[ty
.disabled .clearBtn,
.disabled .patternKey,
.disabled .show_qrcode,
.disabled .generate_key {
.disabled .generate_key,
.disabled .generate_cert {
color: #aaa !important;
}
.padTable p {
Expand Down Expand Up @@ -500,7 +501,8 @@ h2.activeRSS {
height: 16px;
width: 16px;
float: left;
margin-right: 2px;
margin: 0 6px 0 2px;
text-align: center;
}
.feed {
text-decoration: none;
Expand Down
2 changes: 1 addition & 1 deletion interfaces/Glitter/templates/include_messages.tmpl
Expand Up @@ -36,7 +36,7 @@
</tr>
<!-- /ko -->
<!-- ko if: !hasMessages() && displayTabbed() -->
<tr>
<tr class="table-messages-none">
<td>$T('none')</td>
<td></td>
</tr>
Expand Down

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions interfaces/Glitter/templates/static/stylesheets/glitter.css
Expand Up @@ -882,6 +882,10 @@ tr.queue-item>td:first-child>a {
opacity: 1;
}

.table-messages .table-messages-none td {
padding: 10px 15px !important;
}

.table-messages .label {
margin-right: 8px;
min-width: 100px;
Expand Down
14 changes: 13 additions & 1 deletion sabnzbd/api.py
Expand Up @@ -56,7 +56,7 @@
from sabnzbd.utils.pathbrowser import folders_at_path
from sabnzbd.misc import loadavg, to_units, diskfree, disktotal, get_ext, \
get_filename, int_conv, globber, globber_full, time_format, remove_all, \
starts_with_path, cat_convert, clip_path
starts_with_path, cat_convert, clip_path, create_https_certificates
from sabnzbd.encoding import xml_name, unicoder, special_fixer, platform_encode, html_escape
from sabnzbd.postproc import PostProcessor
from sabnzbd.articlecache import ArticleCache
Expand Down Expand Up @@ -874,6 +874,17 @@ def _api_config_set_nzbkey(output, kwargs):
return report(output, keyword='nzbkey', data=cfg.nzb_key())


def _api_config_regenerate_certs(output, kwargs):
# Make sure we only over-write default locations
result = False
if sabnzbd.cfg.https_cert() is sabnzbd.cfg.https_cert.default() and sabnzbd.cfg.https_key() is sabnzbd.cfg.https_key.default():
https_cert = sabnzbd.cfg.https_cert.get_path()
https_key = sabnzbd.cfg.https_key.get_path()
result = create_https_certificates(https_cert, https_key)
sabnzbd.RESTART_REQ = True
return report(output, data=result)


def _api_config_test_server(output, kwargs):
""" API: accepts output, server-params """
result, msg = test_nntp_server_dict(kwargs)
Expand Down Expand Up @@ -979,6 +990,7 @@ def _api_server_stats(name, output, kwargs):
'set_pause': (_api_config_set_pause, 2),
'set_apikey': (_api_config_set_apikey, 3),
'set_nzbkey': (_api_config_set_nzbkey, 3),
'regenerate_certs': (_api_config_regenerate_certs, 3),
'test_server': (_api_config_test_server, 2)
}

Expand Down
1 change: 1 addition & 0 deletions sabnzbd/skintext.py
Expand Up @@ -335,6 +335,7 @@
'explain-https_port' : TT('If empty, the standard port will only listen to HTTPS.'),
'opt-https_cert' : TT('HTTPS Certificate'),
'explain-https_cert' : TT('File name or path to HTTPS Certificate.'),
'explain-new-cert': TT('Generate new self-signed certificate and key. Requires SABnzbd restart!'),
'opt-https_key' : TT('HTTPS Key'),
'explain-https_key' : TT('File name or path to HTTPS Key.'),
'opt-https_chain' : TT('HTTPS Chain Certifcates'),
Expand Down

0 comments on commit bd19962

Please sign in to comment.