Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pascal Engélibert
Barre de financement intégrable
Commits
005938df
Commit
005938df
authored
Jul 12, 2020
by
Pascal Engélibert
🚴
Browse files
Store cache
parent
10b55213
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
005938df
...
...
@@ -8,5 +8,5 @@ Générateur de barre de financement intégrable dans une page web pour suivre l
*
Déposez l'ensemble des fichiers dans un dossier sur votre serveur
*
Paramétrez votre serveur web (Apache ou Nginx) pour rendre le dossier accessible depuis le web
*
Le dossier img/qrcodes doit être accessible en écriture pour le compte utilisé par votre serveur web (en général www-data)
*
Le générateur sera alors accessible via http(s)://votredomaine.com/votre_chemin/generate.php
\ No newline at end of file
*
Les dossiers
`img/qrcodes`
et
`cache`
doivent être accessibles en écriture pour le compte utilisé par votre serveur web (en général
`www-data`
)
*
Le générateur sera alors accessible via http(s)://votredomaine.com/votre_chemin/generate.php
iframe.php
View file @
005938df
<?php
// CONFIG
$CACHE_TXS
=
3600
;
// txs cache duration in seconds (0 to disable)
$CACHE_UD
=
86400
;
// UD cache duration in seconds (0 to disable)
$CACHE_DIR
=
'cache/'
;
$ALLOW_CLIENT_NODE
=
false
;
// set true is security problem
$NODE
=
array
(
'https://g1.duniter.org'
,
'https://g1.librelois.fr'
,
'https://g1.cgeek.fr'
,
'https://duniter.normandie-libre.fr'
,
'https://g1.presles.fr'
,
'https://g1.mithril.re'
);
$FONT_COLOR
=
'#212529'
;
...
...
@@ -8,6 +11,9 @@ $BG_COLOR = '#FFF';
$BORDER_COLOR
=
'#343a40'
;
$PROGRESS_COLOR
=
'#ffc107'
;
if
((
$CACHE_TXS
!=
0
or
$CACHE_UD
!=
0
)
and
!
file_exists
(
$CACHE_DIR
))
mkdir
(
$CACHE_DIR
);
if
(
isset
(
$_GET
[
'lang'
]))
{
if
(
empty
(
$_GET
[
'lang'
]))
$langdetect
=
true
;
else
$lang
=
$_GET
[
'lang'
];
...
...
@@ -107,22 +113,34 @@ $PROGRESS_COLOR = '#ffc107';
echo
'<div>'
.
tr
(
'error_target_missing'
)
.
'</div>'
;
exit
;
}
// Récupération des transactions entrantes entre la date de début et la date du jour
$start_timestamp
=
$start_date
->
getTimestamp
();
$today_timestamp
=
$today
->
getTimestamp
();
$url_json
=
'/tx/history/'
.
$pubkey
.
'/times/'
.
$start_timestamp
.
'/'
.
$today_timestamp
;
shuffle
(
$nodes
);
// shuffle for load balancing
foreach
(
$nodes
as
&
$node
)
{
// Test each node and keep the first which works
$json
=
@
file_get_contents
(
$node
.
$url_json
,
false
,
stream_context_create
(
array
(
'http'
=>
array
(
'timeout'
=>
10.0
))));
if
(
$json
!==
false
)
break
;
$json
=
null
;
$cache_filename
=
$CACHE_DIR
.
$pubkey
.
'_'
.
$start_timestamp
.
'.json'
;
if
(
$CACHE_TXS
!=
0
and
file_exists
(
$cache_filename
)
and
time
()
-
filemtime
(
$cache_filename
)
<
$CACHE_TXS
)
{
$json
=
file_get_contents
(
$cache_filename
);
}
if
(
$json
===
false
){
echo
'<div>'
.
tr
(
'error_connect_node'
)
.
'</div>'
;
exit
;
if
(
!
$json
)
{
$url_json
=
'/tx/history/'
.
$pubkey
.
'/times/'
.
$start_timestamp
.
'/'
.
$today_timestamp
;
shuffle
(
$nodes
);
// shuffle for load balancing
foreach
(
$nodes
as
&
$node
)
{
// Test each node and keep the first which works
$json
=
@
file_get_contents
(
$node
.
$url_json
,
false
,
stream_context_create
(
array
(
'http'
=>
array
(
'timeout'
=>
10.0
))));
if
(
$json
!==
false
)
break
;
}
if
(
$json
===
false
){
echo
'<div>'
.
tr
(
'error_connect_node'
)
.
'</div>'
;
exit
;
}
if
(
$CACHE_UD
!=
0
)
{
file_put_contents
(
$cache_filename
,
$json
);
}
}
$json
=
json_decode
(
$json
);
$transactions
=
$json
->
history
->
received
;
$total
=
0
;
...
...
@@ -158,7 +176,7 @@ $PROGRESS_COLOR = '#ffc107';
}
$donors
=
count
(
$donneurs
);
if
(
$display_graph
){
// On complète le tableau avec la derni
e
re transaction et pour la date de visualisation du graph
// On complète le tableau avec la derni
è
re transaction et pour la date de visualisation du graph
e
array_push
(
$array_final
,
[
't'
=>
$tmp_timestamp
*
1000
,
'y'
=>
(
string
)
$total
]);
array_push
(
$array_final
,
[
't'
=>
$today_timestamp
*
1000
,
'y'
=>
(
string
)
$total
]);
$array_line
=
[[
't'
=>
$start_timestamp
*
1000
,
'y'
=>
(
string
)
$target
],[
't'
=>
$today_timestamp
*
1000
,
'y'
=>
(
string
)
$target
]];
...
...
@@ -176,17 +194,43 @@ $PROGRESS_COLOR = '#ffc107';
// Si l'unité est relative
if
(
$unit
==
'relative'
){
// On récupère le dernier block qui contient le DU
$url_json
=
$node
.
'/blockchain/with/ud'
;
$json
=
file_get_contents
(
$url_json
);
$json
=
json_decode
(
$json
);
$last_block_with_ud
=
end
(
$json
->
result
->
blocks
);
$ud
=
null
;
if
(
$CACHE_UD
!=
0
and
file_exists
(
$CACHE_DIR
.
'ud.txt'
)
and
time
()
-
filemtime
(
$CACHE_DIR
.
'ud.txt'
)
<
$CACHE_UD
)
{
$ud
=
floatval
(
file_get_contents
(
$CACHE_DIR
.
'ud.txt'
));
}
if
(
!
$ud
)
{
// On récupère le dernier bloc qui contient le DU
$url_json
=
$node
.
'/blockchain/with/ud'
;
if
(
isset
(
$node
))
$json
=
file_get_contents
(
$url_json
);
else
{
shuffle
(
$nodes
);
// shuffle for load balancing
foreach
(
$nodes
as
&
$node
)
{
// Test each node and keep the first which works
$json
=
@
file_get_contents
(
$node
.
$url_json
,
false
,
stream_context_create
(
array
(
'http'
=>
array
(
'timeout'
=>
10.0
))));
if
(
$json
!==
false
)
break
;
}
if
(
$json
===
false
){
echo
'<div>'
.
tr
(
'error_connect_node'
)
.
'</div>'
;
exit
;
}
}
$json
=
json_decode
(
$json
);
$last_block_with_ud
=
end
(
$json
->
result
->
blocks
);
// Puis on récupère le montant du DU pour mettre à jour les données
$url_json
=
$node
.
'/blockchain/block/'
.
$last_block_with_ud
;
$json
=
file_get_contents
(
$url_json
);
$json
=
json_decode
(
$json
);
$ud
=
$json
->
dividend
/
100
;
if
(
$CACHE_UD
!=
0
)
{
file_put_contents
(
$CACHE_DIR
.
'ud.txt'
,
strval
(
$ud
));
}
}
// Puis on récupère le montant du DU pour mettre à jour les données
$url_json
=
$node
.
'/blockchain/block/'
.
$last_block_with_ud
;
$json
=
file_get_contents
(
$url_json
);
$json
=
json_decode
(
$json
);
$ud
=
$json
->
dividend
/
100
;
$total
=
round
(
$total
/
$ud
);
if
(
$display_graph
){
for
(
$i
=
0
;
$i
<
count
(
$array_final
);
$i
++
){
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment