function parseXover($subj, $from, $date, $messageid, $rsakeys) { $_CAT = 0; $_FSIZE = 1; // initialiseer wat variabelen $spot = array(); // Eerst splitsen we de header string op in enkel de category info e.d. $fromInfoPos = strpos($from, '<'); if ($fromInfoPos === false) { return false; } else { # Haal de postername en de <>'s weg $fromAddress = explode('@', substr($from, $fromInfoPos + 1, -1)); if (count($fromAddress) < 2) { return false; } # if $spot['header'] = $fromAddress[1]; } # if $spot['verified'] = false; $spot['filesize'] = 0; $spot['messageid'] = substr($messageid, 1, strlen($messageid) - 2); # als de spot in de toekomst ligt, dan corrigeren we dat naar nu if (time() < strtotime($date)) { $spot['stamp'] = time(); } else { $spot['stamp'] = strtotime($date); } # if $fields = explode('.', $spot['header']); if (count($fields) >= 6) { $spot['filesize'] = $fields[$_FSIZE]; $spot['category'] = substr($fields[$_CAT], 0, 1) - 1.0; // extract de posters name $spot['poster'] = substr($from, 0, $fromInfoPos - 1); // key id $spot['keyid'] = (int) substr($fields[$_CAT], 1, 1); if ($spot['keyid'] >= 0) { $expression = ''; $strInput = substr($fields[$_CAT], 2); $recentKey = $spot['keyid'] != 1; if ($recentKey) { if (strlen($strInput) == 0 || strlen($strInput) % 3 != 0) { return; } # if $subcatAr = $this->splitBySizEx($strInput, 3); foreach ($subcatAr as $str) { if (strlen($str) > 0) { $expression .= strtolower(substr($str, 0, 1)) . (int) substr($str, 1) . '|'; } # if } # foeeach } else { $list = array(); for ($i = 0; $i < strlen($strInput); $i++) { if ($strInput[$i] == 0 && !is_numeric($strInput[$i]) && strlen($expression) > 0) { $list[] = $expression; $expression = ''; } # if $expression .= $strInput[$i]; } # for $list[] = $expression; $expression = ''; foreach ($list as $str) { $expression .= strtolower(substr($str, 0, 1)) . substr($str, 1) . '|'; } # foreach } # else if $recentKey # Break up the subcategories per subcat-type if (strlen($expression) > 0) { $subcats = explode('|', $expression); $spot['subcata'] = ''; $spot['subcatb'] = ''; $spot['subcatc'] = ''; $spot['subcatd'] = ''; $spot['subcatz'] = ''; foreach ($subcats as $subcat) { if (in_array(strtolower(substr($subcat, 0, 1)), array('a', 'b', 'c', 'd', 'z')) !== false) { $spot['subcat' . strtolower(substr($subcat, 0, 1))] .= $subcat . '|'; } # if } # foreach # We vullen hier de z categorieen alvast op in het geval er geen Z category gegeven is if (empty($spot['subcatz'])) { $spot['subcatz'] = SpotCategories::createSubcatz($spot['category'], $spot['subcata'] . $spot['subcatb'] . $spot['subcatd']); } # if } # if if (strpos($subj, '=?') !== false && strpos($subj, '?=') !== false) { # Make sure its as simple as possible $subj = str_replace('?= =?', '?==?', $subj); $subj = str_replace('\\r', '', trim($this->oldEncodingParse($subj))); $subj = str_replace('\\n', '', $subj); } # if if ($recentKey) { $tmp = explode('|', $subj); $spot['title'] = trim($tmp[0]); if (count($tmp) > 1) { $spot['tag'] = trim($tmp[1]); } else { $spot['tag'] = ''; } # else } else { $tmp = explode('|', $subj); if (count($tmp) <= 1) { $tmp = array($subj); } # if $spot['tag'] = trim($tmp[count($tmp) - 1]); # remove the tags from the array array_pop($tmp); array_pop($tmp); $spot['title'] = trim(implode('|', $tmp)); if (strpos($spot['title'], chr(0xc2)) !== false | strpos($spot['title'], chr(0xc3)) !== false) { $spot['title'] = trim($this->oldEncodingParse($spot['title'])); } # if } # if recentKey if (strlen($spot['title']) != 0 && strlen($spot['poster']) != 0) { # Als er een recentkey is (key <> 1), OF de spot is na 2010 geplaatst, dan moet # de spot gesigned zijn. $mustbeSigned = $recentKey | $spot['stamp'] > 1293870080; if ($mustbeSigned) { $spot['headersign'] = $fields[count($fields) - 1]; if (strlen($spot['headersign']) != 0) { $spot['wassigned'] = true; # KeyID 7 betekent dat alleen een hashcash vereist is if ($spot['keyid'] == 7) { $userSignedHash = sha1('<' . $spot['messageid'] . '>', false); $spot['verified'] = substr($userSignedHash, 0, 3) == '0000'; } else { # the signature this header is signed with $signature = $this->unspecialString($spot['headersign']); $spotSigning = new SpotSigning(); $spot['verified'] = $spotSigning->verifySpotHeader($spot, $signature, $rsakeys); } # else } # if } else { $spot['verified'] = true; $spot['wassigned'] = false; } # if doesnt need to be signed, pretend that it is } # if } # if } # if # Nu zetten we de titel en dergelijke om naar utf8, we kunnen # dat niet eerder doen omdat anders de RSA signature niet meer # klopt. if ($spot !== false && $spot['verified']) { $spot['title'] = utf8_encode($spot['title']); $spot['poster'] = utf8_encode($spot['poster']); $spot['tag'] = utf8_encode($spot['tag']); } # f return $spot; }
function parseXover($subj, $from, $date, $messageid, $rsakeys, $use_openssl) { $_ID = 2; $_CAT = 0; // initialiseer wat variabelen $spot = array(); // Eerst splitsen we de header string op in enkel de category info e.d. $tmpHdr = preg_split('(<|>)', $from); if (count($tmpHdr) < 2) { return null; } # if $tmpHdr = explode('@', $tmpHdr[1]); if (count($tmpHdr) < 2) { return false; } # if $spot['header'] = $tmpHdr[1]; $spot['verified'] = false; $spot['messageid'] = substr($messageid, 1, strlen($messageid) - 2); if (time() < strtotime($date)) { $spot['stamp'] = time(); } else { $spot['stamp'] = strtotime($date); } # if $fields = explode('.', $spot['header']); if (count($fields) >= 6) { $spot['id'] = $fields[$_ID]; if ($spot['id'] > 9) { $spot['category'] = substr($fields[$_CAT], 0, 1) - 1.0; // extract de posters name $spot['poster'] = explode('<', $from); $spot['poster'] = trim($spot['poster'][0]); // key id $spot['keyid'] = (int) substr($fields[$_CAT], 1, 1); // groupname $spot['groupname'] = 'free.pt'; if ($spot['keyid'] >= 1) { $expression = ''; $strInput = substr($fields[$_CAT], 2); $recentKey = $spot['keyid'] != 1; if ($recentKey) { if (strlen($strInput) == 0 || strlen($strInput) % 3 != 0) { exit; } # if $subcatAr = $this->splitBySizEx($strInput, 3); foreach ($subcatAr as $str) { if (strlen($str) > 0) { $expression .= strtolower(substr($str, 0, 1)) . (int) substr($str, 1) . '|'; } # if } # foeeach $spot['subcat'] = (int) substr($subcatAr[0], 1); } else { $list = array(); for ($i = 0; $i < strlen($strInput); $i++) { if ($strInput[$i] == 0 && !is_numeric($strInput[$i]) && strlen($expression) > 0) { $list[] = $expression; $expression = ''; } # if $expression .= $strInput[$i]; } # for $list[] = $expression; $expression = ''; foreach ($list as $str) { $expression .= strtolower(substr($str, 0, 1)) . substr($str, 1) . '|'; } # foreach $spot['subcat'] = (int) substr($list[0], 1); } # else if $recentKey # Break up the subcategories per subcat-type if (strlen($expression) > 0) { $subcats = explode('|', $expression); $spot['subcata'] = ''; $spot['subcatb'] = ''; $spot['subcatc'] = ''; $spot['subcatd'] = ''; foreach ($subcats as $subcat) { if (array_search(strtolower(substr($subcat, 0, 1)), array('a', 'b', 'c', 'd')) !== false) { $spot['subcat' . strtolower(substr($subcat, 0, 1))] .= $subcat . '|'; } # if } # foreach } # if if (strpos($subj, '=?') !== false && strpos($subj, '?=') !== false) { # Make sure its as simple as possible $subj = str_replace('?= =?', '?==?', $subj); $subj = str_replace('\\r', '', trim($this->oldEncodingParse($subj))); $subj = str_replace('\\n', '', $subj); } # if if ($recentKey) { if (strpos($subj, '|') !== false) { $tmp = explode('|', $subj); $spot['title'] = trim($tmp[0]); $spot['tag'] = trim($tmp[1]); } else { $spot['title'] = trim($subj); $spot['tag'] = ''; } # else } else { $tmp = explode('|', $subj); if (count($tmp) <= 1) { $tmp = array($subj); } # if $spot['tag'] = trim($tmp[count($tmp) - 1]); # remove the tags from the array array_pop($tmp); array_pop($tmp); $spot['title'] = trim(implode('|', $tmp)); if (strpos($spot['title'], chr(0xc2)) !== false | strpos($spot['title'], chr(0xc3)) !== false) { $spot['title'] = trim($this->oldEncodingParse($spot['title'])); } # if } # if recentKey if (strlen($spot['title']) != 0 && strlen($spot['poster']) != 0 && ($spot['id'] >= 1000000 || $recentKey)) { # Vanaf spot-id 1385910 komen we KeyID's 2 tegen, dus vanaf daar gaan we alle niet-signed posts weigeren. $mustbeSigned = $recentKey | !$recentKey & $spot['id'] > 1385910; # FIXME # # somehow there is a check that the key is only validated for spots with key id 2 ? # not sure about the code as it only seems to execute for more than 25000 spots or something? # $mustbeSigned = $mustbeSigned & $spot['keyid'] >= 2; # and verify the signature it if ($mustbeSigned) { $spot['headersign'] = $fields[count($fields) - 1]; if (strlen($spot['headersign']) != 0) { $spot['wassigned'] = true; # KeyID 7 betekent dat het serverless signed is if ($spot['keyid'] == 7) { $userSignedHash = sha1('<' . $spot['messageid'] . '>', false); $spot['verified'] = substr($userSignedHash, 0, 3) == '0000'; } else { # the signature this header is signed with $signature = $this->unspecialString($spot['headersign']); $spotSigning = new SpotSigning($use_openssl); $spot['verified'] = $spotSigning->verifySpotHeader($spot, $signature, $rsakeys); } # else } # if } else { $spot['verified'] = true; $spot['wassigned'] = false; } # if doesnt need to be signed, pretend that it is } # if } # if } # if } # if return $spot; }