Ejemplo n.º 1
0
/**
 * retrieves information by regex from the messages (headers/body)
 *
 * if regex matches it will return what is in the first ()
 *
 * @param string $regex
 * @param clsMailMsg $oMSG
 * @param bool $header should be scanned from specified header rather
 * @return string
 */
function getfrommmsg($regex, $oMSG, $header = false)
{
    /* header match */
    if ($header !== false) {
        if (isset($oMSG->headers[$header])) {
            if (preg_match($regex, $oMSG->headers[$header], $m)) {
                return $m[1];
            }
        }
        return false;
    }
    /* body match */
    if (!is_array($oMSG->parts)) {
        $oMSG->parts = array($oMSG->body);
    }
    $oBP = new clsMailMsg();
    $oBP->processMessage(implode("\n", $oMSG->parts[0]));
    if (isset($oBP->headers["Content-Transfer-Encoding"]) && $oBP->headers["Content-Transfer-Encoding"] == "base64") {
        $bp = explode("\n", base64_decode(implode("\n", $oBP->body)));
    } else {
        $bp = $oBP->body;
    }
    foreach ($bp as $l) {
        $l = trim($l);
        if (preg_match($regex, $l, $m)) {
            return $m[1];
        }
    }
    return false;
}
Ejemplo n.º 2
0
/**
 * handles a order request
 *
 * @param string $key
 * @param clsMailMsg $oMSG
 * @param array $config
 * @return bool
 */
function request_order($key, $oMSG, $config)
{
    if (($stds = msg_std($oMSG)) === false) {
        return false;
    }
    list($compname, $ipaddr, $bustel, $fromwho, $email) = $stds;
    /* other side key */
    if (($yourkey = getfrommmsg(REGEX_YOURKEY, $oMSG)) === false) {
        return false;
    }
    /* validate keys */
    if (($keyinfo = trhKeyPair($key, $yourkey)) === false) {
        return false;
    }
    $custid = $keyinfo["custid"];
    if (count($oMSG->parts) < 2) {
        print "Invalid message: count(parts) < 2\n";
        return false;
    }
    $attach = new clsMailMsg();
    $attach->processMessage(implode("\r\n", $oMSG->parts[1]));
    if ($attach->getAttachmentFilename() != "data.xml") {
        print "Invalid message part. Disposition name != data.xml\n";
        return false;
    }
    $XML = base64_decode(preg_replace("/[ \r\n\t]/", "", implode("", $attach->body)));
    global $reqpur_activetag, $purch_info, $purch_items;
    $reqpur_activetag = $purch_info = $purch_items = array();
    $parser = xml_parser_create();
    xml_set_element_handler($parser, "stElement", "endElement");
    xml_parse($parser, $XML, true);
    xml_parser_free($parser);
    $i = grp(m("approved", "n"), m("custid", $custid), m(raw("trhkey"), dbrow("0.0.0.0/0", "{$keyinfo['send_key']}", "{$keyinfo['recv_key']}")));
    $purch_info = array_merge($purch_info, $i);
    foreach ($purch_info as $k => $v) {
        if (empty($v)) {
            $purch_info[$k] = raw("NULL");
        }
    }
    $upd = new dbUpdate("recvpurch", "trh", $purch_info);
    $upd->run(DB_INSERT);
    $recvpurch_id = pglib_lastid("trh.recvpurch", "id");
    $upd->setTable("recvpurch_items", "trh");
    foreach ($purch_items as $pi_det) {
        unset($pi_det["id"]);
        $pi_det["recvpurch_id"] = $recvpurch_id;
        $upd->setOpt($pi_det);
        $upd->run(DB_INSERT);
    }
    print "Purchase inserted.\n";
    $userinfo = qryUsers($config["MANAGEUSER"]);
    msgSend($userinfo["username"], "Purchase received via Transheks. Click <a target='mainframe' href='../transheks/order_approve.php'>here</a> to view.");
}