Rev 6 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4 | daniel-mar | 1 | #!/usr/bin/php |
2 | <?php |
||
3 | |||
4 | require_once __DIR__ . '/includes/db.inc.php'; |
||
5 | require_once __DIR__ . '/includes/src.inc.php'; |
||
6 | |||
7 | if ($argc <> 1) { |
||
8 | echo "Syntax: $argv[0]\n"; |
||
9 | exit(2); |
||
10 | } |
||
11 | |||
7 | daniel-mar | 12 | if (isset($stam_cfg['weblog2_system']) && !empty($stam_cfg['weblog2_system'])) { |
13 | |||
14 | |||
15 | # --- |
||
16 | |||
17 | |||
18 | $oidplus_rest_auth = $stam_cfg['weblog2_auth']; |
||
19 | |||
20 | $data = array(); |
||
21 | $ch = curl_init($stam_cfg['weblog2_system']."rest/v1/objects/oid:".$stam_cfg['weblog2_oid']); |
||
22 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
23 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); |
||
24 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); |
||
25 | curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer $oidplus_rest_auth")); |
||
26 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
||
27 | $i=0; for($i=0;$i<10;$i++) { $response = curl_exec($ch); if ($response) { break; } else { sleep(1); } } |
||
28 | if ((!$response) || (json_decode($response,true)['status'] < 0)) |
||
29 | { |
||
30 | fwrite(STDERR, "Weblog GET failed: $response\n"); |
||
31 | #weblog_close(); |
||
32 | exit(2); |
||
33 | } |
||
34 | #echo "$response\n\n"; |
||
35 | $children = json_decode($response,true)['children']; |
||
36 | |||
37 | foreach ($children as $child) { |
||
38 | $data = array(); |
||
39 | $ch = curl_init($stam_cfg['weblog2_system']."rest/v1/objects/".$child); |
||
40 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
41 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); |
||
42 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); |
||
43 | curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer $oidplus_rest_auth")); |
||
44 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
||
45 | $i=0; for($i=0;$i<10;$i++) { $response = curl_exec($ch); if ($response) { break; } else { sleep(1); } } |
||
46 | if ((!$response) || (json_decode($response,true)['status'] < 0)) |
||
47 | { |
||
48 | fwrite(STDERR, "Weblog GET failed: $response\n"); |
||
49 | #weblog_close(); |
||
50 | exit(2); |
||
51 | } |
||
52 | #echo "$response\n\n"; |
||
53 | $data = json_decode($response,true); |
||
54 | $ent = $data['description']; |
||
55 | |||
56 | if (isset($stam_cfg['weblog_password']) && !empty($stam_cfg['weblog_password'])) { |
||
57 | $iv = 'AAAAAAAAAAAAAAAA'; |
||
58 | $ent = openssl_decrypt(base64_decode($ent), 'AES-128-CBC', $stam_cfg['weblog_password'], OPENSSL_RAW_DATA, $iv); |
||
59 | } |
||
60 | |||
61 | echo $data['created'] . ': ' . trim($ent) . "\n"; |
||
62 | } |
||
63 | |||
64 | |||
65 | |||
66 | # --- |
||
67 | |||
68 | |||
69 | |||
70 | |||
71 | } |
||
72 | |||
4 | daniel-mar | 73 | if (isset($stam_cfg['weblog_host']) && !empty($stam_cfg['weblog_host'])) { |
74 | db_close(); |
||
75 | |||
76 | $weblog_host = $stam_cfg['weblog_host']; |
||
77 | $weblog_user = $stam_cfg['weblog_user']; |
||
78 | $weblog_pass = $stam_cfg['weblog_pass']; |
||
79 | $weblog_base = $stam_cfg['weblog_base']; |
||
80 | |||
81 | if (!db_connect($weblog_host, $weblog_user, $weblog_pass)) { |
||
82 | fwrite(STDERR, "Weblog MySQL connect error\n"); |
||
83 | exit(2); |
||
84 | } |
||
85 | |||
86 | if (!db_select_db($weblog_base)) { |
||
87 | fwrite(STDERR, "Weblog MySQL DB select error\n"); |
||
6 | daniel-mar | 88 | db_close(); |
4 | daniel-mar | 89 | exit(2); |
90 | } |
||
91 | |||
92 | $res = db_query("select * from stam_weblog order by id asc"); |
||
93 | while ($row = db_fetch_array($res)) { |
||
94 | $ent = $row['inp']; |
||
95 | if (isset($stam_cfg['weblog_password']) && !empty($stam_cfg['weblog_password'])) { |
||
96 | $iv = 'AAAAAAAAAAAAAAAA'; |
||
97 | $ent = openssl_decrypt(base64_decode($ent), 'AES-128-CBC', $stam_cfg['weblog_password'], OPENSSL_RAW_DATA, $iv); |
||
98 | } |
||
7 | daniel-mar | 99 | echo $row['ts'] . ': ' . trim($ent) . "\n"; |
4 | daniel-mar | 100 | |
101 | } |
||
102 | } |
||
103 | |||
104 | # --- |
||
105 | |||
106 | function green($txt) { |
||
107 | return "\033[1;32;40m".$txt."\033[0m"; |
||
108 | } |