コード例 #1
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);
    }
}
コード例 #2
0
ファイル: updatejson.php プロジェクト: rhertzog/lcs
 if ($_POST['action'] == "modif_event") {
     $config = HTMLPurifier_Config::createDefault();
     //$config->set('Core.Encoding', 'ISO-8859-15');
     $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
     $purifier = new HTMLPurifier($config);
     $_id = $purifier->purify($_POST['di']);
     $_title = $purifier->purify($_POST['title']);
     $_matiere = $purifier->purify($_POST['ereitam']);
     $_start = $purifier->purify($_POST['trats']);
     $_end = $purifier->purify($_POST['dne']);
     $_url = $purifier->purify($_POST['lru']);
     $filename = "../json_files/" . $_SESSION['login'] . ".json";
     $evenements = json_decode(file_get_contents($filename), true);
     //chercher un event depuis son id
     $needle = array('id' => $_POST['di']);
     $key = my_array_search($needle, $evenements);
     if ($key != false) {
         $evenements[$key]['title'] = $_title;
         $evenements[$key]['matiere'] = $_matiere;
         $evenements[$key]['start'] = $_start;
         $evenements[$key]['end'] = $_end;
         $evenements[$key]['allDay'] = false;
         $evenements[$key]['url'] = $_url;
     }
     $datas = json_encode($evenements);
     exec("/usr/bin/sudo /usr/share/lcs/scripts/chaccess_cdt.sh Writable jsonfiles " . $_SESSION['login']);
     if (file_put_contents($filename, $datas)) {
         echo 'OK';
     }
     exec("/usr/bin/sudo /usr/share/lcs/scripts/chaccess_cdt.sh NoWritable jsonfiles");
 }
コード例 #3
0
ファイル: import.php プロジェクト: pneff/contagged
function vcard_entry($vcf)
{
    $entry = array();
    $entry['name'] = $vcf['N'][0]['value'][0][0];
    $entry['givenname'] = trim($vcf['N'][0]['value'][1][0] . ' ' . $vcf['N'][0]['value'][2][0]);
    $entry['title'] = $vcf['N'][0]['value'][3][0];
    $entry['organization'] = $vcf['ORG'][0]['value'][0][0];
    $entry['office'] = $vcf['ORG'][0]['value'][1][0];
    $entry['note'] = $vcf['NOTE'][0]['value'][0][0];
    $entry['url'] = $vcf['URL'][0]['value'][0][0];
    $entry['photo'] = $vcf['PHOTO'][0]['value'][0][0];
    $bday = $vcf['BDAY'][0]['value'][0][0];
    $entry['birthday'] = substr($bday, 0, 4) . '-' . substr($bday, 4, 2) . '-' . substr($bday, 6, 2);
    foreach ((array) $vcf['TEL'] as $tel) {
        if (empty($entry['phone']) && (my_array_search('WORK', (array) $tel['param']['TYPE']) != false || my_array_search('VOICE', (array) $tel['param']['TYPE']) != false)) {
            // Work phone
            $entry['phone'] = $tel['value'][0][0];
        } elseif (empty($entry['fax']) && my_array_search('FAX', (array) $tel['param']['TYPE']) !== false) {
            $entry['fax'] = $tel['value'][0][0];
        } elseif (empty($entry['mobile']) && my_array_search('CELL', (array) $tel['param']['TYPE']) !== false) {
            $entry['mobile'] = $tel['value'][0][0];
        } elseif (empty($entry['pager']) && my_array_search('PAGER', (array) $tel['param']['TYPE']) !== false) {
            $entry['pager'] = $tel['value'][0][0];
        } elseif (empty($entry['homephone']) && my_array_search('HOME', (array) $tel['param']['TYPE']) !== false && my_array_search('VOICE', (array) $tel['param']['TYPE']) !== false) {
            $entry['homephone'] = $tel['value'][0][0];
        }
    }
    foreach ((array) $vcf['EMAIL'] as $mail) {
        if (!in_array($mail['value'][0][0], (array) $entry['mail'])) {
            $entry['mail'][] = $mail['value'][0][0];
        }
    }
    foreach ((array) $vcf['ADR'] as $adr) {
        if (my_array_search('HOME', (array) $adr['param']['TYPE']) !== false) {
            $entry['homestreet'] = $adr['value'][2][0] . "\n" . $adr['value'][5][0] . " " . $adr['value'][3][0];
            //ort
        } elseif (my_array_search('WORK', (array) $adr['param']['TYPE']) !== false) {
            $entry['street'] = $adr['value'][2][0];
            $entry['location'] = $adr['value'][3][0];
            $entry['zip'] = $adr['value'][5][0];
            $entry['country'] = $adr['value'][6][0];
            $entry['state'] = $adr['value'][4][0];
        }
    }
    return $entry;
}