Example #1
0
#!/usr/bin/php
<?php 
/*
 * private/event_handler.php
 */
require_once "db.php";
if (count($argv) > 1) {
    if ($argv[1] == "RECEIVED" || $argv[1] == "REPORT") {
        wait_read_gsm(PATH_INCOMING, PATH_RECEIVED);
    }
    if ($argv[1] == "SENT") {
        check_sent_gsm($argv[2]);
    }
}
function wait_read_gsm($path_incoming, $path_received)
{
    global $db;
    $d = dir($path_incoming);
    while (false !== ($entry = $d->read())) {
        if ($entry != "." && $entry != "..") {
            $file = $entry;
            $full_msg = file_get_contents($path_incoming . $file);
            // парсим файл
            $smsfile = parse_sms_file($full_msg);
            $phone = $smsfile['From'];
            $dt = $smsfile['Sent'];
            $alphabet = $smsfile['Alphabet'];
            if (isset($alphabet) && $alphabet == "UCS2") {
                $msg = iconv("UCS-2BE", "UTF-8", $smsfile['Msg']);
            } else {
                $msg = $smsfile['Msg'];
Example #2
0
    if (posix_setsid() == -1) {
        die("could not detach from terminal");
    }
    // setup signal handlers
    pcntl_signal(SIGTERM, "sig_handler");
    pcntl_signal(SIGHUP, "sig_handler");
    // loop forever performing tasks
    while (true) {
        // from fork
        require_once "../private/config.php";
        require_once "../httpsdocs/includes/smpp/smppclient.class.php";
        require_once "../httpsdocs/includes/smpp/sockettransport.class.php";
        require_once "../private/db.php";
        require_once "log.php";
        sms_send_gsm(PATH_OUTGOUING);
        check_sent_gsm(PATH_SENT);
        sms_send_smpp($smpp_hosts, $smpp_port, $smpp_login, $smpp_password, $smpp_from);
        sleep(1);
    }
} else {
    print "nosignal, use start|stop\n";
    exit;
}
function sms_send_gsm($path_outgoing)
{
    // gsm send
    global $db;
    $select = "select id, phonenumber, msg from sms where direction = 1 and process = 0 and method = 'gsm';";
    if ($result = $db->query($select)) {
        while ($row = $result->fetch_assoc()) {
            $id = $row['id'];