Commit ccf7e692 authored by Erase's avatar Erase
Browse files

Update generate.php : change token

parent f480e7f8
<?php
//~ Ajax only
if(!array_key_exists('isAjax', $_POST) || $_POST['isAjax'] !== "true"){
exit('No ajax');
}
//~ Check token
session_start();
if(empty($_SESSION['csrf_token'])){
$_SESSION['csrf_token'] = uniqid(rand(), true);
}
$headers = apache_request_headers();
if(array_key_exists('CsrfToken', $headers) && isset($headers['CsrfToken'])){
if ($headers['CsrfToken'] !== $_SESSION['csrf_token']) {
//~ Wrong token
$_d['sucess'] = false;
$_d['message'] = "Problème lors de la vérification du token";
header('Content-type: text/json');
echo json_encode($_d);
exit;
}
}else {
//~ No token
$_d['sucess'] = false;
$_d['message'] = "Problème de token";
header('Content-type: text/json');
echo json_encode($_d);
exit;
}
//~ Include RSS Fusion
require_once 'vendor/RSS-Fusion/index.php';
//~ Array for return
$_d = array(
'sucess' => false,
'message' => "",
'data' => array()
);
//~ Check data
if(array_key_exists('flux', $_POST) && !empty($_POST['flux'])){
$_links = array_unique(
array_map('trim',
explode(' ', $_POST['flux'])
)
);
//~ Where to look
if(array_key_exists('where', $_POST) && !empty($_POST['where'])){
\Config::set('where', $_POST['where']);
}
//~ Show or hide keywords
if(array_key_exists('filter', $_POST) && !empty($_POST['filter'])){
$mode = "_starWords";
if($_POST['filter'] === 'hide'){
$mode = "_badWords";
}
if(!empty($_POST['words'])){
Config::set($mode, array_unique(
array_map('trim',
explode(',', $_POST['words'])
)
));
}
}
$oFeeds = new FeedReader($_links);
if(!is_null($oFeeds->objParseFeed)){
//~ Config is ok ! Storage
$conf_storage = json_encode(array(
'flux' => $_links,
'where' => \Config::get('where'),
'_starWords' => \Config::get('_starWords'),
'_badWords' => \Config::get('_badWords')
));
$conf_name = str_replace('.', '', uniqid(rand(), true));
$path = TL_ROOT . '/../../c/';
if(file_put_contents($path.$conf_name, $conf_storage)){
//~ Generate link to return
$_d['sucess'] = true;
$_d['message'] = "Voici le lien RSS relatif à votre configuration";
$_d['data'] = array(
'file' => './flux.php?c='.$conf_name,
'_' => $_POST
);
//~ Delete old file conf
if ($handle = opendir($path)){
//~ Loop through the directory
while (false !== ($file = readdir($handle))){
//~ Check the file we're doing is actually a file
if (is_file($path.$file) && $file !== 'index.php' && $file !== '.gitignore'){
//~ Check if the file is older than 3 week old
if (filemtime($path.$file) < (time() - (3 * 7 * 24 * 60 * 60))){ //~ 3 weeks
//~ Do the deletion
unlink($path.$file);
}
}
}
}
}else{
//~ Error
$_d['sucess'] = false;
$_d['message'] = "Une erreur est survenue lors de l'enregistrement de votre configuration";
}
}else{
$_d['sucess'] = false;
$_d['message'] = "Une erreur est survenue lors du chargement de flux RSS";
}
}else{
//~ No data
$_d['sucess'] = false;
$_d['message'] = "Merci de renseigner au moins une URL de flux RSS";
}
header('Content-type: text/json');
echo json_encode($_d);
exit;
<?php
//~ Ajax only
if(!array_key_exists('isAjax', $_POST) || $_POST['isAjax'] !== "true"){
exit('No ajax');
}
//~ Check token
session_start();
if(empty($_SESSION['csrf_token'])){
$_SESSION['csrf_token'] = uniqid(rand(), true);
}
$headers = apache_request_headers();
if(!array_key_exists('t', $_POST) || !empty($_POST['t'])){
if ($_POST['t'] !== $_SESSION['csrf_token']) {
//~ Wrong token
$_d['sucess'] = false;
$_d['message'] = "Problème lors de la vérification du token";
header('Content-type: text/json');
echo json_encode($_d);
exit;
}
}else {
//~ No token
$_d['sucess'] = false;
$_d['message'] = "Problème de token";
header('Content-type: text/json');
echo json_encode($_d);
exit;
}
//~ Include RSS Fusion
require_once 'vendor/RSS-Fusion/index.php';
//~ Array for return
$_d = array(
'sucess' => false,
'message' => "",
'data' => array()
);
//~ Check data
if(array_key_exists('flux', $_POST) && !empty($_POST['flux'])){
$_links = array_unique(
array_map('trim',
explode(' ', $_POST['flux'])
)
);
//~ Where to look
if(array_key_exists('where', $_POST) && !empty($_POST['where'])){
\Config::set('where', $_POST['where']);
}
//~ Show or hide keywords
if(array_key_exists('filter', $_POST) && !empty($_POST['filter'])){
$mode = "_starWords";
if($_POST['filter'] === 'hide'){
$mode = "_badWords";
}
if(!empty($_POST['words'])){
Config::set($mode, array_unique(
array_map('trim',
explode(',', $_POST['words'])
)
));
}
}
$oFeeds = new FeedReader($_links);
if(!is_null($oFeeds->objParseFeed)){
//~ Config is ok ! Storage
$conf_storage = json_encode(array(
'flux' => $_links,
'where' => \Config::get('where'),
'_starWords' => \Config::get('_starWords'),
'_badWords' => \Config::get('_badWords')
));
$conf_name = str_replace('.', '', uniqid(rand(), true));
$path = TL_ROOT . '/../../c/';
if(file_put_contents($path.$conf_name, $conf_storage)){
//~ Generate link to return
$_d['sucess'] = true;
$_d['message'] = "Voici le lien RSS relatif à votre configuration";
$_d['data'] = array(
'file' => './flux.php?c='.$conf_name,
'_' => $_POST
);
//~ Delete old file conf
if ($handle = opendir($path)){
//~ Loop through the directory
while (false !== ($file = readdir($handle))){
//~ Check the file we're doing is actually a file
if (is_file($path.$file) && $file !== 'index.php' && $file !== '.gitignore'){
//~ Check if the file is older than 3 week old
if (filemtime($path.$file) < (time() - (3 * 7 * 24 * 60 * 60))){ //~ 3 weeks
//~ Do the deletion
unlink($path.$file);
}
}
}
}
}else{
//~ Error
$_d['sucess'] = false;
$_d['message'] = "Une erreur est survenue lors de l'enregistrement de votre configuration";
}
}else{
$_d['sucess'] = false;
$_d['message'] = "Une erreur est survenue lors du chargement de flux RSS";
}
}else{
//~ No data
$_d['sucess'] = false;
$_d['message'] = "Merci de renseigner au moins une URL de flux RSS";
}
header('Content-type: text/json');
echo json_encode($_d);
exit;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment