Rev 5 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5 | Rev 6 | ||
---|---|---|---|
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 <> 1) { |
7 | if ($argc <> 1) { |
8 | echo "Syntax: $argv[0]\n"; |
8 | echo "Syntax: $argv[0]\n"; |
9 | exit(2); |
9 | exit(2); |
10 | } |
10 | } |
11 | 11 | ||
12 | if (isset($stam_cfg['weblog_host']) && !empty($stam_cfg['weblog_host'])) { |
12 | if (isset($stam_cfg['weblog_host']) && !empty($stam_cfg['weblog_host'])) { |
13 | db_close(); |
13 | db_close(); |
14 | 14 | ||
15 | $weblog_host = $stam_cfg['weblog_host']; |
15 | $weblog_host = $stam_cfg['weblog_host']; |
16 | $weblog_user = $stam_cfg['weblog_user']; |
16 | $weblog_user = $stam_cfg['weblog_user']; |
17 | $weblog_pass = $stam_cfg['weblog_pass']; |
17 | $weblog_pass = $stam_cfg['weblog_pass']; |
18 | $weblog_base = $stam_cfg['weblog_base']; |
18 | $weblog_base = $stam_cfg['weblog_base']; |
19 | 19 | ||
20 | if (!db_connect($weblog_host, $weblog_user, $weblog_pass)) { |
20 | if (!db_connect($weblog_host, $weblog_user, $weblog_pass)) { |
21 | fwrite(STDERR, "Weblog MySQL connect error\n"); |
21 | fwrite(STDERR, "Weblog MySQL connect error\n"); |
22 | exit(2); |
22 | exit(2); |
23 | } |
23 | } |
24 | 24 | ||
25 | if (!db_select_db($weblog_base)) { |
25 | if (!db_select_db($weblog_base)) { |
26 | fwrite(STDERR, "Weblog MySQL DB select error\n"); |
26 | fwrite(STDERR, "Weblog MySQL DB select error\n"); |
27 | weblog_close(); |
27 | db_close(); |
28 | exit(2); |
28 | exit(2); |
29 | } |
29 | } |
30 | 30 | ||
31 | db_query("TRUNCATE TABLE stam_weblog"); |
31 | db_query("TRUNCATE TABLE stam_weblog"); |
32 | 32 | ||
33 | $home = posix_getpwuid(posix_getuid())['dir']; |
33 | $home = posix_getpwuid(posix_getuid())['dir']; |
34 | $ents = file($home.'/.stam_history'); |
34 | $ents = file($home.'/.stam_history'); |
35 | foreach ($ents as $ent) { |
35 | foreach ($ents as $ent) { |
36 | if (isset($stam_cfg['weblog_password']) && !empty($stam_cfg['weblog_password'])) { |
36 | if (isset($stam_cfg['weblog_password']) && !empty($stam_cfg['weblog_password'])) { |
37 | $iv = 'AAAAAAAAAAAAAAAA'; |
37 | $iv = 'AAAAAAAAAAAAAAAA'; |
38 | $ent = base64_encode(openssl_encrypt($ent, 'AES-128-CBC', $stam_cfg['weblog_password'], OPENSSL_RAW_DATA, $iv)); |
38 | $ent = base64_encode(openssl_encrypt($ent, 'AES-128-CBC', $stam_cfg['weblog_password'], OPENSSL_RAW_DATA, $iv)); |
39 | } |
39 | } |
40 | 40 | ||
41 | $x = db_query("INSERT INTO stam_weblog (ts, inp) VALUES ( |
41 | $x = db_query("INSERT INTO stam_weblog (ts, inp) VALUES ( |
42 | NOW(), |
42 | NOW(), |
43 | '".db_real_escape_string($ent)."' |
43 | '".db_real_escape_string($ent)."' |
44 | )"); |
44 | )"); |
45 | if (!$x) { |
45 | if (!$x) { |
46 | fwrite(STDERR, db_error()."\n"); |
46 | fwrite(STDERR, db_error()."\n"); |
47 | db_close(); |
47 | db_close(); |
48 | exit(1); |
48 | exit(1); |
49 | } |
49 | } |
50 | 50 | ||
51 | $id = db_insert_id(); |
51 | $id = db_insert_id(); |
52 | if (!$id) { |
52 | if (!$id) { |
53 | fwrite(STDERR, "Error: Could not insert\n"); |
53 | fwrite(STDERR, "Error: Could not insert\n"); |
54 | db_close(); |
54 | db_close(); |
55 | exit(1); |
55 | exit(1); |
56 | } |
56 | } |
57 | 57 | ||
58 | echo green("Weblog written!\n"); |
58 | echo green("Weblog written!\n"); |
59 | } |
59 | } |
60 | } |
60 | } |
61 | 61 | ||
62 | # --- |
62 | # --- |
63 | 63 | ||
64 | function green($txt) { |
64 | function green($txt) { |
65 | return "\033[1;32;40m".$txt."\033[0m"; |
65 | return "\033[1;32;40m".$txt."\033[0m"; |
66 | } |
66 | } |