Rev 6 | Rev 8 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6 | Rev 7 | ||
---|---|---|---|
1 | #!/usr/bin/php |
1 | #!/usr/bin/php |
2 | <?php |
2 | <?php |
3 | 3 | ||
4 | require_once __DIR__ . '/includes/db.inc.php'; |
4 | require_once __DIR__ . '/includes/db.inc.php'; |
5 | require_once __DIR__ . '/includes/src.inc.php'; |
5 | require_once __DIR__ . '/includes/src.inc.php'; |
6 | 6 | ||
7 | if ($argc <> 2) { |
7 | if ($argc <> 2) { |
8 | echo "Syntax: $argv[0] <line>\n"; |
8 | echo "Syntax: $argv[0] <line>\n"; |
9 | exit(2); |
9 | exit(2); |
10 | } |
10 | } |
11 | 11 | ||
- | 12 | if (isset($stam_cfg['weblog2_system']) && !empty($stam_cfg['weblog2_system'])) { |
|
- | 13 | ||
- | 14 | ||
- | 15 | $ent = rtrim($argv[1]); |
|
- | 16 | ||
- | 17 | # --- |
|
- | 18 | ||
- | 19 | ||
- | 20 | $oidplus_rest_auth = $stam_cfg['weblog2_auth']; |
|
- | 21 | ||
- | 22 | /* |
|
- | 23 | $data = array(); |
|
- | 24 | $ch = curl_init($stam_cfg['weblog2_system']."rest/v1/objects/oid:".$stam_cfg['weblog2_oid']); |
|
- | 25 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
- | 26 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); |
|
- | 27 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); |
|
- | 28 | curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer $oidplus_rest_auth")); |
|
- | 29 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
- | 30 | $i=0; for($i=0;$i<10;$i++) { $response = curl_exec($ch); if ($response) { break; } else { sleep(1); } } |
|
- | 31 | if ((!$response) || (json_decode($response,true)['status'] < 0)) |
|
- | 32 | { |
|
- | 33 | fwrite(STDERR, "Weblog GET failed: $response\n"); |
|
- | 34 | exit(2); |
|
- | 35 | } |
|
- | 36 | #echo "$response\n\n"; |
|
- | 37 | $children = json_decode($response,true)['children']; |
|
- | 38 | if (count($children) == 0) { |
|
- | 39 | $lfd = 1; |
|
- | 40 | } else { |
|
- | 41 | natsort($children); |
|
- | 42 | $last = end($children); |
|
- | 43 | $arcs = explode('.', $last); |
|
- | 44 | $lfd = end($arcs)+1; |
|
- | 45 | } |
|
- | 46 | */ |
|
- | 47 | ||
- | 48 | $lfd = floor(microtime(true)*10000); |
|
- | 49 | ||
- | 50 | $data = array("title" => "STAM Weblog Entry", "description" => $ent, "ra_email" => "info@daniel-marschall.de"); |
|
- | 51 | $ch = curl_init($stam_cfg['weblog2_system']."rest/v1/objects/oid:".$stam_cfg['weblog2_oid'].".".$lfd); |
|
- | 52 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
- | 53 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
|
- | 54 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); |
|
- | 55 | curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer $oidplus_rest_auth")); |
|
- | 56 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
- | 57 | $i=0; for($i=0;$i<10;$i++) { $response = curl_exec($ch); if ($response) { break; } else { sleep(1); } } |
|
- | 58 | if ((!$response) || (json_decode($response,true)['status'] < 0)) |
|
- | 59 | { |
|
- | 60 | fwrite(STDERR, "Weblog POST failed: $response\n"); |
|
- | 61 | exit(2); |
|
- | 62 | } |
|
- | 63 | #echo "$response\n\n"; |
|
- | 64 | ||
- | 65 | echo green("Weblog written (".$stam_cfg['weblog2_oid'].".$lfd)!\n"); |
|
- | 66 | ||
- | 67 | # --- |
|
- | 68 | ||
- | 69 | ||
- | 70 | ||
- | 71 | ||
- | 72 | ||
- | 73 | } |
|
- | 74 | ||
- | 75 | ||
- | 76 | ||
- | 77 | } |
|
- | 78 | ||
12 | if (isset($stam_cfg['weblog_host']) && !empty($stam_cfg['weblog_host'])) { |
79 | if (isset($stam_cfg['weblog_host']) && !empty($stam_cfg['weblog_host'])) { |
13 | db_close(); |
80 | db_close(); |
14 | 81 | ||
15 | $weblog_host = $stam_cfg['weblog_host']; |
82 | $weblog_host = $stam_cfg['weblog_host']; |
16 | $weblog_user = $stam_cfg['weblog_user']; |
83 | $weblog_user = $stam_cfg['weblog_user']; |
17 | $weblog_pass = $stam_cfg['weblog_pass']; |
84 | $weblog_pass = $stam_cfg['weblog_pass']; |
18 | $weblog_base = $stam_cfg['weblog_base']; |
85 | $weblog_base = $stam_cfg['weblog_base']; |
19 | 86 | ||
20 | if (!db_connect($weblog_host, $weblog_user, $weblog_pass)) { |
87 | if (!db_connect($weblog_host, $weblog_user, $weblog_pass)) { |
21 | fwrite(STDERR, "Weblog MySQL connect error\n"); |
88 | fwrite(STDERR, "Weblog MySQL connect error\n"); |
22 | exit(2); |
89 | exit(2); |
23 | } |
90 | } |
24 | 91 | ||
25 | if (!db_select_db($weblog_base)) { |
92 | if (!db_select_db($weblog_base)) { |
26 | fwrite(STDERR, "Weblog MySQL DB select error\n"); |
93 | fwrite(STDERR, "Weblog MySQL DB select error\n"); |
27 | db_close(); |
94 | db_close(); |
28 | exit(2); |
95 | exit(2); |
29 | } |
96 | } |
30 | 97 | ||
31 | $ent = rtrim($argv[1]); |
98 | $ent = rtrim($argv[1]); |
32 | 99 | ||
33 | if (isset($stam_cfg['weblog_password']) && !empty($stam_cfg['weblog_password'])) { |
100 | if (isset($stam_cfg['weblog_password']) && !empty($stam_cfg['weblog_password'])) { |
34 | $iv = 'AAAAAAAAAAAAAAAA'; |
101 | $iv = 'AAAAAAAAAAAAAAAA'; |
35 | $ent = base64_encode(openssl_encrypt($ent, 'AES-128-CBC', $stam_cfg['weblog_password'], OPENSSL_RAW_DATA, $iv)); |
102 | $ent = base64_encode(openssl_encrypt($ent, 'AES-128-CBC', $stam_cfg['weblog_password'], OPENSSL_RAW_DATA, $iv)); |
36 | } |
103 | } |
37 | 104 | ||
38 | $x = db_query("INSERT INTO stam_weblog (ts, inp) VALUES ( |
105 | $x = db_query("INSERT INTO stam_weblog (ts, inp) VALUES ( |
39 | NOW(), |
106 | NOW(), |
40 | '".db_real_escape_string($ent)."' |
107 | '".db_real_escape_string($ent)."' |
41 | )"); |
108 | )"); |
42 | if (!$x) { |
109 | if (!$x) { |
43 | fwrite(STDERR, db_error()."\n"); |
110 | fwrite(STDERR, db_error()."\n"); |
44 | db_close(); |
111 | db_close(); |
45 | exit(1); |
112 | exit(1); |
46 | } |
113 | } |
47 | 114 | ||
48 | $id = db_insert_id(); |
115 | $id = db_insert_id(); |
49 | if (!$id) { |
116 | if (!$id) { |
50 | fwrite(STDERR, "Error: Could not insert\n"); |
117 | fwrite(STDERR, "Error: Could not insert\n"); |
51 | db_close(); |
118 | db_close(); |
52 | exit(1); |
119 | exit(1); |
53 | } |
120 | } |
54 | 121 | ||
55 | echo green("Weblog written\n"); |
122 | echo green("Weblog written\n"); |
56 | } |
123 | } |
57 | 124 | ||
58 | # --- |
125 | # --- |
59 | 126 | ||
60 | function green($txt) { |
127 | function green($txt) { |
61 | return "\033[1;32;40m".$txt."\033[0m"; |
128 | return "\033[1;32;40m".$txt."\033[0m"; |
62 | } |
129 | } |