Пример #1
0
function deleteEvent($day, $month, $year, $time, $buffertime, $userID)
{
    foundAppointment($day, $month, $year, $userID);
    $q = "DELETE FROM `UCPM_appointments` WHERE (TIME(starttime) >= '{$time}') AND (TIME(starttime) <= '{$buffertime}') AND (DATE(starttime) = '{$year}-{$month}-{$day}') AND (userID='{$userID}') ";
    $result = mysql_query($q) or die(mysql_error());
    checkDeleted($day, $month, $year, $buffertime, $userID);
}
Пример #2
0
function accept_connection($socket)
{
    while (1) {
        try {
            $conn = stream_socket_accept($socket, 0);
            stream_set_blocking($conn, 0);
            stream_set_timeout($conn, 120);
            debug("new connection");
            $start = time();
            while (!feof($conn)) {
                if (time() - $start > 10) {
                    break;
                }
                $req = trim(stream_socket_recvfrom($conn, 1024));
                if (strlen($req) == 0) {
                    continue;
                }
                debug("received {$req}");
                $eof = false;
                if (strpos($req, "EOF") !== false) {
                    $eof = true;
                    $req = str_replace("EOF", "", $req);
                }
                $cmd = explode("|", $req);
                debug("command count: " . (count($cmd) - 1));
                for ($i = 0; $i < count($cmd) - 1; $i++) {
                    $c = $cmd[$i];
                    debug("command #{$i}: {$c}");
                    $c = preg_replace('/ 0+(\\d+)$/', ' $1', $c);
                    $id = substr($c, 0, strpos($c, " "));
                    $c = substr($c, strpos($c, " ") + 1);
                    if (!preg_match(SYNTAX, $c) && !preg_match(SYNTAX_IP, $c) && !preg_match(SYNTAX_PORT, $c) || !is_numeric($id) && $id != '*') {
                        debug("invalid entry: " . $cmd[$i]);
                        continue;
                    }
                    $host = substr($c, strpos($c, "-s ") + strlen("-s "), strpos($c, "/32") - strpos($c, "-s ") - strlen("-s "));
                    $cmds = array();
                    $type = substr($c, 0, strpos($c, " "));
                    debug("type = {$type}");
                    if ((preg_match(SYNTAX, $c) || preg_match(SYNTAX_IP, $c)) && preg_match('/[^0-9\\.]/', $host)) {
                        debug("getting ip");
                        $ips = getips($id, $host, $type);
                        //debug("lock block 1 took " .(microtime(true) - $start));
                        debug("got ip");
                        // for these hosts, let the rules be evicted rather than remove them, since it will be overkill
                        // as they are used very often
                        foreach ($ips as $ip) {
                            $cmds[] = str_replace($host, $ip, $c);
                        }
                    } else {
                        $cmds[] = $c;
                    }
                    foreach ($cmds as $c) {
                        $c = substr($c, strpos($c, " ") + 1);
                        lock();
                        //$start = microtime(true);
                        $adds = getVar();
                        if ($type == '-A') {
                            $exists = $adds[$c];
                            if ($exists && my_array_search($id, $adds[$c]) !== false) {
                                unlock();
                                continue;
                            }
                            $adds[$c][] = $id . ":" . time();
                            setVar($adds);
                            if (!$exists) {
                                debug("adding entry {$c}");
                                iptables($c, "-A");
                            }
                        } else {
                            if ($type == '-D') {
                                if (checkDeleted($adds, $id, $c)) {
                                    debug("deleting entry {$c}");
                                    iptables($c, "-D");
                                }
                            }
                        }
                        //debug("lock block 2 took " .(microtime(true) - $start));
                        unlock();
                    }
                }
                if ($eof) {
                    debug("next..");
                    break;
                }
                usleep(50000);
            }
            stream_socket_sendto($conn, "BYE");
            @fclose($conn);
        } catch (Exception $e) {
            try {
                unlock();
                // in case it was locked
                unlock(DNS_INDEX);
            } catch (Exception $ex) {
                // ignore
            }
        }
        usleep(50000);
    }
}