forked from BitVote/bitvote.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitvote.php
More file actions
59 lines (50 loc) · 1.29 KB
/
Copy pathbitvote.php
File metadata and controls
59 lines (50 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
function connect_db($path){
$db_name = 'bitvotedb';
// use the @ to suppress php/psql error message
$lines = file($path);
$master_usr = $lines[0];
$master_pwd = $lines[1];
$con = @pg_connect("host=localhost dbname=$db_name user=$master_usr password=$master_pwd");
return $con;
}
function pad($topad, $n){
$resp = strval($topad);
$len = strlen($resp);
while ($len < $n){
$resp = "0" . $resp;
$len ++;
}
return $resp;
}
function seconds_to_time($seconds){
$hours = (int) ($seconds / 3600);
$minutes = (int) (($seconds - $hours * 3600)/60);
$seconds = $seconds - $minutes*60 - $hours*3600;
return pad($hours, 2) . ":" . pad($minutes, 2) . ":" . pad($seconds, 2);
}
function returns_key($a){
return $a[0];
}
function list_vote_chain(){
echo "\n";
if (($con = connect_db('auth.txt'))){
$sql = "SELECT * FROM votes";
$result = pg_query($con, $sql);
$votes = array();
while($row = pg_fetch_array($result)){
$url = $row[0];
$time = $row[1]; // convert to time format
$votes[$url] = (int) $time;
}
arsort($votes);
foreach ($votes as $url => $time){
$time_str = seconds_to_time($time);
echo "$time_str <a href='http://$url'>http://$url</a>\n";
}
}
}
function get_users_ip(){
echo htmlspecialchars($_SERVER['REMOTE_ADDR']);
}
?>