Subversion Repositories stackman

Rev

Rev 6 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6 Rev 7
Line 7... Line 7...
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['weblog2_system']) && !empty($stam_cfg['weblog2_system'])) {
-
 
13
 
-
 
14
 
-
 
15
 
-
 
16
	$home = posix_getpwuid(posix_getuid())['dir'];
-
 
17
	$ents = file($home.'/.stam_history');
-
 
18
	foreach ($ents as $ent) {
-
 
19
		$ent = rtrim($ent);
-
 
20
		if (isset($stam_cfg['weblog_password']) && !empty($stam_cfg['weblog_password'])) {
-
 
21
			$iv = 'AAAAAAAAAAAAAAAA';
-
 
22
			$ent = base64_encode(openssl_encrypt($ent, 'AES-128-CBC', $stam_cfg['weblog_password'], OPENSSL_RAW_DATA, $iv));
-
 
23
		}
-
 
24
 
-
 
25
# ---
-
 
26
 
-
 
27
 
-
 
28
	$oidplus_rest_auth = $stam_cfg['weblog2_auth'];
-
 
29
 
-
 
30
	/*
-
 
31
	$data = array();
-
 
32
	$ch = curl_init($stam_cfg['weblog2_system']."rest/v1/objects/oid:".$stam_cfg['weblog2_oid']);
-
 
33
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
 
34
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
-
 
35
	curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
-
 
36
	curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer $oidplus_rest_auth"));
-
 
37
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
-
 
38
	$i=0; for($i=0;$i<10;$i++) { $response = curl_exec($ch); if ($response) { break; } else { sleep(1); } }
-
 
39
	if ((!$response) || (json_decode($response,true)['status'] < 0))
-
 
40
	{
-
 
41
		fwrite(STDERR, "Weblog GET failed: $response\n");
-
 
42
		#weblog_close();
-
 
43
		exit(2);
-
 
44
	}
-
 
45
	#echo "$response\n\n";
-
 
46
	$children = json_decode($response,true)['children'];
-
 
47
	if (count($children) == 0) {
-
 
48
		$lfd = 1;
-
 
49
	} else {
-
 
50
		natsort($children);
-
 
51
		$last = end($children);
-
 
52
		$arcs = explode('.', $last);
-
 
53
		$lfd = end($arcs)+1;
-
 
54
	}
-
 
55
	*/
-
 
56
 
-
 
57
	$lfd = floor(microtime(true)*10000);
-
 
58
 
-
 
59
	$data = array("title" => "STAM Weblog Entry", "description" => $ent, "ra_email" => "info@daniel-marschall.de");
-
 
60
	$ch = curl_init($stam_cfg['weblog2_system']."rest/v1/objects/oid:".$stam_cfg['weblog2_oid'].".".$lfd);
-
 
61
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
 
62
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
-
 
63
	curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
-
 
64
	curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer $oidplus_rest_auth"));
-
 
65
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
-
 
66
	$i=0; for($i=0;$i<10;$i++) { $response = curl_exec($ch); if ($response) { break; } else { sleep(1); } }
-
 
67
	if ((!$response) || (json_decode($response,true)['status'] < 0))
-
 
68
	{
-
 
69
		fwrite(STDERR, "Weblog POST failed: $response\n");
-
 
70
		#weblog_close();
-
 
71
		exit(2);
-
 
72
	}
-
 
73
	#echo "$response\n\n";
-
 
74
 
-
 
75
	echo green("Weblog written (".$stam_cfg['weblog2_oid'].".$lfd)!\n");
-
 
76
 
-
 
77
# ---
-
 
78
 
-
 
79
 
-
 
80
 
-
 
81
 
-
 
82
 
-
 
83
	}
-
 
84
 
-
 
85
 
-
 
86
 
-
 
87
}
-
 
88
 
12
if (isset($stam_cfg['weblog_host']) && !empty($stam_cfg['weblog_host'])) {
89
if (isset($stam_cfg['weblog_host']) && !empty($stam_cfg['weblog_host'])) {
13
	db_close();
90
	db_close();
14
 
91
 
15
	$weblog_host = $stam_cfg['weblog_host'];
92
	$weblog_host = $stam_cfg['weblog_host'];
16
	$weblog_user = $stam_cfg['weblog_user'];
93
	$weblog_user = $stam_cfg['weblog_user'];
Line 31... Line 108...
31
	db_query("TRUNCATE TABLE stam_weblog");
108
	db_query("TRUNCATE TABLE stam_weblog");
32
 
109
 
33
	$home = posix_getpwuid(posix_getuid())['dir'];
110
	$home = posix_getpwuid(posix_getuid())['dir'];
34
	$ents = file($home.'/.stam_history');
111
	$ents = file($home.'/.stam_history');
35
	foreach ($ents as $ent) {
112
	foreach ($ents as $ent) {
-
 
113
		$ent = rtrim($ent);
36
		if (isset($stam_cfg['weblog_password']) && !empty($stam_cfg['weblog_password'])) {
114
		if (isset($stam_cfg['weblog_password']) && !empty($stam_cfg['weblog_password'])) {
37
			$iv = 'AAAAAAAAAAAAAAAA';
115
			$iv = 'AAAAAAAAAAAAAAAA';
38
			$ent = base64_encode(openssl_encrypt($ent, 'AES-128-CBC', $stam_cfg['weblog_password'], OPENSSL_RAW_DATA, $iv));
116
			$ent = base64_encode(openssl_encrypt($ent, 'AES-128-CBC', $stam_cfg['weblog_password'], OPENSSL_RAW_DATA, $iv));
39
		}
117
		}
40
 
118