about summary refs log tree commit diff stats
path: root/update/library/trunk/instadisc.php
blob: 1b764f85c0043793a65c2344d2fc50f68fd50b42 (plain) (blame)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php

/* InstaDisc Update - A Four Island Project */

include('xmlrpc/xmlrpc.inc');

$idusSubscriptionSeriesURL = array();
$idusSubscriptionID = array();
$idusSeriesUsername = array();
$idusSeriesPassword = array();
$idusSubscriptionURL = array();
$idusSubscriptionTitle = array();
$idusSubscriptionCategory = array();
$idusSubscriptionPersonal = array();
$idusEncryptionKey = array();
$instaDisc_subCount = 0;

function instaDisc_sendItem($id, $title, $author, $url, $semantics)
{
	global $idusSubscriptionSeriesURL, $idusSubscriptionID, $idusSeriesUsername, $idusSeriesPassword, $idusSubscriptionURL, $idusSubscriptionTitle, $idusSubscriptionCategory, $idusSubscriptionPersonal, $idusEncryptionKey;

	$encID = 0;
	if (($idusEncryptionKey[$id] != '') && extension_loaded('mcrypt'))
	{
		$encID = rand(1,2147483647);

		$cipher = "rijndael-128";
		$mode = "cbc";
		$key = substr(md5(substr(str_pad($idusEncryptionKey[$id],16,$encID),0,16)),0,16);

		$td = mcrypt_module_open($cipher, "", $mode, "");

		$title = encryptString($td, $key, $title);
		$author = encryptString($td, $key, $author);
		$url = encryptString($td, $key, $url);

		foreach ($semantics as $name => $value)
		{
			$semantics[$name] = encryptString($td, $key, $value);
		}
	
		mcrypt_module_close($td);
	}
	
	$verID = rand(1,2147483647);

	$client = new xmlrpc_client($idusSubscriptionSeriesURL[$id]);
	$msg = new xmlrpcmsg("InstaDisc.sendFromUpdate", array(	new xmlrpcval($idusSeriesUsername[$id], 'string'),
								new xmlrpcval(md5($idusSeriesUsername[$id] . ':' . md5($idusSeriesPassword[$id]) . ':' . $verID), 'string'),
								new xmlrpcval($verID, 'int'),
								new xmlrpcval($idusSubscriptionSeriesURL[$id], 'string'),
								new xmlrpcval($idusSubscriptionID[$id], 'string'),
								new xmlrpcval($idusSubscriptionURL[$id], 'string'),
								new xmlrpcval($idusSubscriptionTitle[$id], 'string'),
								new xmlrpcval($idusSubscriptionCategory[$id], 'string'),
								new xmlrpcval($idusSubscriptionPersonal[$id], 'string'),
								new xmlrpcval($title, 'string'),
								new xmlrpcval($author, 'string'),
								new xmlrpcval($url, 'string'),
								new xmlrpcval(serialize($semantics), 'string'),
								new xmlrpcval($encID, 'int')));
	$resp = $client->send($msg);
        $val = $resp->value()->scalarVal();

	if ($val == 2)
	{
		return instaDisc_sendItem($id, $title, $author, $url, $semantics, $encryptionID);
	} else if ($val == 0)
	{
		return TRUE;
	} else {
		return FALSE;
	}
}

function instaDisc_addSubscription($url, $id, $un, $pw, $sUrl, $title, $cat, $personal = '', $enc = '')
{
	global $instaDisc_subCount, $idusSubscriptionSeriesURL, $idusSubscriptionID, $idusSeriesUsername, $idusSeriesPassword, $idusSubscriptionURL, $idusSubscriptionTitle, $idusSubscriptionCategory, $idusSubscriptionPersonal, $idusEncryptionKey;
	$idusSubscriptionSeriesURL[$instaDisc_subCount] = $url;
	$idusSubscriptionID[$instaDisc_subCount] = $id;
	$idusSeriesUsername[$instaDisc_subCount] = $un;
	$idusSeriesPassword[$instaDisc_subCount] = $pw;
	$idusSubscriptionURL[$instaDisc_subCount] = $sUrl;
	$idusSubscriptionTitle[$instaDisc_subCount] = $title;
	$idusSubscriptionCategory[$instaDisc_subCount] = $cat;
	$idusSubscriptionPersonal[$instaDisc_subCount] = ($personal != '' ? 'true' : 'false');
	$idusEncryptionKey[$instaDisc_subCount] = $enc;
	$instaDisc_subCount++;
}

function encryptString($td, $key, $string)
{
	mcrypt_generic_init($td, $key, strrev($key));
	$string = bin2hex(mcrypt_generic($td, $string));
	mcrypt_generic_deinit($td);

	return $string;
}

?>