Change method to generate tokens and allow people to generate new tokens
This commit is contained in:
parent
a79228195f
commit
68a8e8f954
@ -492,6 +492,14 @@ Router\post_action('add', function() {
|
||||
});
|
||||
|
||||
|
||||
// Re-generate tokens
|
||||
Router\get_action('generate-tokens', function() {
|
||||
|
||||
Model\new_tokens();
|
||||
Response\redirect('?action=config#api');
|
||||
});
|
||||
|
||||
|
||||
// Optimize the database manually
|
||||
Router\get_action('optimize-db', function() {
|
||||
|
||||
|
20
model.php
20
model.php
@ -102,9 +102,25 @@ function write_debug()
|
||||
}
|
||||
|
||||
|
||||
function generate_api_token()
|
||||
function generate_token()
|
||||
{
|
||||
return substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
|
||||
if (ini_get('open_basedir') === '') {
|
||||
return substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
|
||||
}
|
||||
else {
|
||||
return substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function new_tokens()
|
||||
{
|
||||
$values = array(
|
||||
'api_token' => generate_token(),
|
||||
'feed_token' => generate_token(),
|
||||
);
|
||||
|
||||
return \PicoTools\singleton('db')->table('config')->update($values);
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@ namespace Schema;
|
||||
|
||||
function version_14($pdo)
|
||||
{
|
||||
$pdo->exec('ALTER TABLE config ADD COLUMN feed_token TEXT DEFAULT "'.\Model\generate_api_token().'"');
|
||||
$pdo->exec('ALTER TABLE config ADD COLUMN feed_token TEXT DEFAULT "'.\Model\generate_token().'"');
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ function version_13($pdo)
|
||||
|
||||
function version_12($pdo)
|
||||
{
|
||||
$pdo->exec('ALTER TABLE config ADD COLUMN api_token TEXT DEFAULT "'.\Model\generate_api_token().'"');
|
||||
$pdo->exec('ALTER TABLE config ADD COLUMN api_token TEXT DEFAULT "'.\Model\generate_token().'"');
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
</div>
|
||||
<section>
|
||||
<div class="alert alert-normal">
|
||||
<h3><?= t('API') ?></h3>
|
||||
<h3 id="api"><?= t('API') ?></h3>
|
||||
<ul>
|
||||
<li><?= t('Bookmarks RSS Feed:') ?>
|
||||
<a href="<?= Helper\get_current_base_url().'feed.php?token='.urlencode($values['feed_token']) ?>" target="_blank"><?= Helper\get_current_base_url().'feed.php?token='.urlencode($values['feed_token']) ?></a>
|
||||
@ -46,6 +46,7 @@
|
||||
<li><?= t('API endpoint:') ?> <strong><?= Helper\get_current_base_url().'jsonrpc.php' ?></strong></li>
|
||||
<li><?= t('API username:') ?> <strong><?= Helper\escape($values['username']) ?></strong></li>
|
||||
<li><?= t('API token:') ?> <strong><?= Helper\escape($values['api_token']) ?></strong></li>
|
||||
<li><a href="?action=generate-tokens"><?= t('Generate new tokens') ?></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="alert alert-normal">
|
||||
|
Loading…
Reference in New Issue
Block a user