$db = new SpotDb($settings['db']); $db->connect(); echo "Connected to the database.." . PHP_EOL; $spotSettings = SpotSettings::singleton($db, $settings); $spotSigning = new SpotSigning(); $spotPosting = new SpotPosting($db, $spotSettings); $spotUserSystem = new SpotUserSystem($db, $spotSettings); echo "Initialized classes.." . PHP_EOL; $spot['category'] = 0; $spot['website'] = 'http://www.moviemeter.nl/film/69912'; $spot['body'] = 'Hierbij een cover van de film Colombiana. Met dank aan de originele poster van deze cover'; $spot['poster'] = 'Spotweb Test User'; $spot['tag'] = ''; $spot['key'] = 7; $spot['title'] = 'Colombiana cover (SWtest2)'; echo "Spot Title will be: " . $spot['title'] . PHP_EOL; $spot['category'] = 0; $spot["subcata"] = "a5|"; $spot['subcatb'] = ''; $spot['subcatc'] = ''; $spot['subcatd'] = 'd30|'; $spot['subcatz'] = 'z2|'; echo "Generating hash.." . PHP_EOL; $spot['newmessageid'] = substr($spotSigning->makeExpensiveHash('<' . $spotSigning->makeRandomStr(15), '@spot.net>'), 1, -1); echo "Hash generated.." . PHP_EOL; $user = $spotUserSystem->getUser(USERID); $user['privatekey'] = $db->getUserPrivateRsaKey($user['userid']); echo "Posting spot... " . PHP_EOL; var_dump($spotPosting->postSpot($user, $spot, 'tests/test.jpg', 'tests/test.nzb'));
function getCleanRandomString($len) { $spotParser = new SpotParser(); $spotSigning = new SpotSigning(); return substr($spotParser->specialString(base64_encode($spotSigning->makeRandomStr($len))), 0, $len); }
function postFullSpot($user, $serverPrivKey, $newsgroup, $spot) { # instantiate the necessary objects $spotSigning = new SpotSigning(); /* * Create the spotnet from header part accrdoing to the following structure: * From: [Nickname] <[USER PUBLIC KEY]@[CAT][KEY-ID][SUBCAT].[SIZE].[RANDOM].[DATE].[CUSTOM-ID].[CUSTOM-VALUE].[SIGNATURE]> */ $spotHeader = $spot['category'] + 1 . $spot['key']; // Append the category and keyid # Process each subcategory and add them to the from header foreach ($spot['subcatlist'] as $subcat) { $spotHeader .= $subcat[0] . str_pad(substr($subcat, 1), 2, '0', STR_PAD_LEFT); } # foreach $spotHeader .= '.' . $spot['filesize']; $spotHeader .= '.' . 10; // some kind of magic number? $spotHeader .= '.' . time(); $spotHeader .= '.' . $spotSigning->makeRandomStr(4); $spotHeader .= '.' . $spotSigning->makeRandomStr(3); # If a tag is given, add it to the subject if (strlen(trim($spot['tag'])) > 0) { $spot['title'] = $spot['title'] . ' | ' . $spot['tag']; } # if # sign the header by using the users' key $header_signature = $spotSigning->signMessage($user['privatekey'], $spot['title'] . $spotHeader . $spot['poster']); # sign the XML with the users' key $xml_signature = $spotSigning->signMessage($user['privatekey'], $spot['spotxml']); # Extract the users' publickey $userPubKey = $spotSigning->getPublicKey($user['privatekey']); # Create the From header $spotnetFrom = $user['username'] . ' <' . $this->_spotParser->specialString($userPubKey['publickey']['modulo']) . '@'; $header = 'From: ' . $spotnetFrom . $spotHeader . '.' . $this->_spotParser->specialString($header_signature['signature']) . ">\r\n"; # Add the Spotnet XML file, but split it in chunks of 900 characters $tmpXml = explode("\r\n", chunk_split($spot['spotxml'], 900)); foreach ($tmpXml as $xmlChunk) { if (strlen(trim($xmlChunk)) > 0) { $header .= 'X-XML: ' . $xmlChunk . "\r\n"; } # if } # foreach $header .= 'X-XML-Signature: ' . $this->_spotParser->specialString($xml_signature['signature']) . "\r\n"; # post the message return $this->postSignedMessage($user, $serverPrivKey, $newsgroup, $spot, $header); }