예제 #1
0
function get_instance_stats()
{
    // Overall Ports/Devices statistics
    $stats['ports'] = dbFetchCell("SELECT COUNT(*) FROM ports");
    $stats['devices'] = dbFetchCell("SELECT COUNT(*) FROM devices");
    $stats['edition'] = OBSERVIUM_EDITION;
    // Per-feature statistics
    $stats['sensors'] = dbFetchCell("SELECT COUNT(*) FROM `sensors`");
    $stats['services'] = dbFetchCell("SELECT COUNT(*) FROM `services`");
    $stats['applications'] = dbFetchCell("SELECT COUNT(*) FROM `applications`");
    $stats['bgp'] = dbFetchCell("SELECT COUNT(*) FROM `bgpPeers`");
    $stats['ospf'] = dbFetchCell("SELECT COUNT(*) FROM `ospf_ports`");
    $stats['eigrp'] = dbFetchCell("SELECT COUNT(*) FROM `eigrp_ports`");
    $stats['ipsec_tunnels'] = dbFetchCell("SELECT COUNT(*) FROM `ipsec_tunnels`");
    $stats['munin_plugins'] = dbFetchCell("SELECT COUNT(*) FROM `munin_plugins`");
    $stats['pseudowires'] = dbFetchCell("SELECT COUNT(*) FROM `pseudowires`");
    $stats['vrfs'] = dbFetchCell("SELECT COUNT(*) FROM `vrfs`");
    $stats['vminfo'] = dbFetchCell("SELECT COUNT(*) FROM `vminfo`");
    $stats['users'] = dbFetchCell("SELECT COUNT(*) FROM `users`");
    $stats['bills'] = dbFetchCell("SELECT COUNT(*) FROM `bills`");
    $stats['alerts'] = dbFetchCell("SELECT COUNT(*) FROM `alert_table`");
    $stats['alert_tests'] = dbFetchCell("SELECT COUNT(*) FROM `alert_tests`");
    $stats['slas'] = dbFetchCell("SELECT COUNT(*) FROM `slas`");
    $stats['statuses'] = dbFetchCell("SELECT COUNT(*) FROM `status`");
    $stats['groups'] = dbFetchCell("SELECT COUNT(*) FROM `groups`");
    $stats['group_members'] = dbFetchCell("SELECT COUNT(*) FROM `group_table`");
    $stats['poller_time'] = dbFetchCell("SELECT SUM(`last_polled_timetaken`) FROM devices");
    $stats['discovery_time'] = dbFetchCell("SELECT SUM(`last_discovered_timetaken`) FROM devices");
    $stats['php_version'] = phpversion();
    $os_text = external_exec("DISTROFORMAT=export " . $GLOBALS['config']['install_dir'] . "/scripts/distro");
    foreach (explode("\n", $os_text) as $part) {
        list($a, $b) = explode("=", $part);
        $stats['os'][$a] = $b;
    }
    // sysObjectID for Generic devices
    foreach (dbFetchRows("SELECT `sysObjectID`, COUNT(*) AS `count` FROM `devices` WHERE `os` = 'generic' GROUP BY `sysObjectID`") as $data) {
        $stats['generics'][$data['sysObjectID']] = $data['count'];
    }
    // Per-OS counts
    foreach (dbFetchRows("SELECT COUNT(*) AS `count`, `os` FROM `devices` GROUP BY `os`") as $data) {
        $stats['devicetypes'][$data['os']] = $data['count'];
    }
    // Per-type counts
    foreach (dbFetchRows("SELECT COUNT(*) AS `count`, `type` FROM `devices` GROUP BY `type`") as $data) {
        $stats['types'][$data['type']] = $data['count'];
    }
    // Per-apptype counts
    foreach (dbFetchRows("SELECT COUNT(*) AS `count`, `app_type` FROM `applications` GROUP BY `app_type`") as $data) {
        $stats['app_types'][$data['app_type']] = $data['count'];
    }
    $stats['misc']['max_len']['port_label'] = dbFetchCell("SELECT MAX(LENGTH(`port_label`)) FROM `ports`");
    $stats['misc']['max_len']['port_label_short'] = dbFetchCell("SELECT MAX(LENGTH(`port_label_short`)) FROM `ports`");
    $stats['misc']['max_len']['port_label_base'] = dbFetchCell("SELECT MAX(LENGTH(`port_label_base`)) FROM `ports`");
    $stats['misc']['max_len']['port_label_num'] = dbFetchCell("SELECT MAX(LENGTH(`port_label_num`)) FROM `ports`");
    $stats['version'] = OBSERVIUM_VERSION;
    $stats['uuid'] = get_unique_id();
    return $stats;
}
예제 #2
0
파일: cart.php 프로젝트: CSFix/L3-Eticaret
 private function getIdentifier()
 {
     $idt = '';
     if (!Sentry::check()) {
         if (!Cookie::has('Anon_Cart_Extension')) {
             Cookie::forever('Anon_Cart_Extension', get_unique_id());
         }
         $idt = Cookie::get('Anon_Cart_Extension');
     } else {
         $idt = Sentry::user()->id;
     }
     return $idt;
 }
예제 #3
0
     $filterent['destination']['address'] = $_POST['localip'];
     $dstpfrom = $_POST['localbeginport'];
     $dstpto = $dstpfrom + $_POST['dstendport'] - $_POST['dstbeginport'];
     if ($dstpfrom == $dstpto) {
         $filterent['destination']['port'] = $dstpfrom;
     } else {
         $filterent['destination']['port'] = $dstpfrom . "-" . $dstpto;
     }
     /*
      * Our firewall filter description may be no longer than
      * 63 characters, so don't let it be.
      */
     $filterent['descr'] = substr("NAT " . $_POST['descr'], 0, 62);
     // If this is a new rule, create an ID and add the rule
     if ($_POST['filter-rule-association'] == 'add-associated') {
         $filterent['associated-rule-id'] = $natent['associated-rule-id'] = get_unique_id();
         $filterent['created'] = make_config_revision_entry(null, gettext("NAT Port Forward"));
         $config['filter']['rule'][] = $filterent;
     }
     mark_subsystem_dirty('filter');
 }
 if (isset($a_nat[$id]['created']) && is_array($a_nat[$id]['created'])) {
     $natent['created'] = $a_nat[$id]['created'];
 }
 $natent['updated'] = make_config_revision_entry();
 // Allow extending of the firewall edit page and include custom input validation
 pfSense_handle_custom_code("/usr/local/pkg/firewall_nat/pre_write_config");
 // Update the NAT entry now
 if (isset($id) && $a_nat[$id]) {
     $a_nat[$id] = $natent;
 } else {
예제 #4
0
                     $org++;
                     // has org info
                 } else {
                     if ($matches[1] == 'Comment') {
                         continue;
                         // skip comments
                     }
                 }
             }
             $response .= $line . PHP_EOL;
         }
     }
 } else {
     // Use RIPE whois API query
     $whois_url = 'https://stat.ripe.net/data/whois/data.json?';
     $whois_url .= 'sourceapp=' . urlencode(OBSERVIUM_PRODUCT . '-' . get_unique_id());
     $whois_url .= '&resource=' . urlencode($ip);
     $request = get_http_request($whois_url);
     if ($request) {
         $request = json_decode($request, TRUE);
         // Convert to array
         if ($request['status'] == 'ok' && count($request['data']['records'])) {
             $whois_parts = array();
             foreach ($request['data']['records'] as $i => $parts) {
                 $key = $parts[0]['key'];
                 if (in_array($key, array('NetRange', 'inetnum', 'inet6num'))) {
                     $org = 0;
                     $whois_parts[0] = '';
                     foreach ($parts as $part) {
                         if (in_array($part['key'], array('Ref', 'source', 'nic-hdl-br'))) {
                             break;
예제 #5
0
/**
 * Store encrypted password in $_SESSION['user_encpass'], required for some auth mechanism, ie ldap
 *
 * @param  string $auth_password Plain password
 * @param  string $key           Key for password encrypt
 * @return string                Encrypted password
 */
function session_encrypt_password($auth_password, $key)
{
    // Store encrypted password
    if ($GLOBALS['config']['auth_mechanism'] == 'ldap' && !($GLOBALS['config']['auth_ldap_bindanonymous'] || strlen($GLOBALS['config']['auth_ldap_binddn'] . $GLOBALS['config']['auth_ldap_bindpw']))) {
        if (check_extension_exists('mcrypt')) {
            // For some admin LDAP functions required store encrypted password in session (userslist)
            $_SESSION['user_encpass'] = encrypt($auth_password, $key . get_unique_id());
        } else {
            $_SESSION['user_encpass'] = base64_encode($auth_password);
            $_SESSION['mcrypt_required'] = 1;
        }
    }
    return $_SESSION['user_encpass'];
}
예제 #6
0
function get_geolocation($address, $geo_db = array(), $dns_only = FALSE)
{
    global $config;
    $ok = FALSE;
    $location = array('location' => $address);
    // Init location array
    $location['location_geoapi'] = strtolower(trim($config['geocoding']['api']));
    if (!isset($config['geo_api'][$location['location_geoapi']])) {
        // Use default if unknown api
        $location['location_geoapi'] = 'openstreetmap';
    }
    $api_params =& $config['geo_api'][$location['location_geoapi']];
    // Link to api specific params
    $params = $api_params['params'];
    // Init base request params
    // GEO API KEY and rate limits
    $ratelimit = FALSE;
    if (strlen($config['geocoding']['api_key']) && isset($api_params['request_params']['key'])) {
        $param = $api_params['request_params']['key'];
        $params[$param] = escape_html($config['geocoding']['api_key']);
        // KEYs is never used special characters
        if (isset($api_params['ratelimit_key'])) {
            $ratelimit = $api_params['ratelimit_key'];
        }
    } else {
        if (isset($api_params['ratelimit'])) {
            $ratelimit = $api_params['ratelimit'];
        }
    }
    if (isset($api_params['request_params']['id'])) {
        $params[$api_params['request_params']['id']] = OBSERVIUM_PRODUCT . '-' . substr(get_unique_id(), 0, 8);
    }
    if (isset($api_params['request_params']['uuid'])) {
        $params[$api_params['request_params']['uuid']] = get_unique_id();
    }
    if (isset($config['geocoding']['enable']) && $config['geocoding']['enable']) {
        $reverse = FALSE;
        // by default forward geocoding
        $debug_msg = "Geocoding ENABLED, try detect device coordinates:" . PHP_EOL;
        // If device coordinates set manually, use Reverse Geocoding.
        if ($geo_db['location_manual']) {
            $location['location_lat'] = $geo_db['location_lat'];
            $location['location_lon'] = $geo_db['location_lon'];
            $reverse = TRUE;
            $debug_msg .= '  MANUAL coordinates - SET' . PHP_EOL;
        } else {
            if ($config['geocoding']['dns']) {
                /**
                 * Ack! dns_get_record not only cannot retrieve LOC records, but it also actively filters them when using
                 * DNS_ANY as query type (which, admittedly would not be all that reliable as per the manual).
                 *
                 * Example LOC:
                 *   "20 31 55.893 N 4 57 38.269 E 45.00m 10m 100m 10m"
                 *
                 * From Wikipedia: d1 [m1 [s1]] {"N"|"S"}  d2 [m2 [s2]] {"E"|"W"}
                 *
                 * Parsing this is something for Net_DNS2 as it has the code for it.
                 */
                if ($geo_db['hostname']) {
                    //include_once('Net/DNS2.php');
                    //include_once('Net/DNS2/RR/LOC.php');
                    $resolver = new Net_DNS2_Resolver();
                    try {
                        $response = $resolver->query($geo_db['hostname'], 'LOC', 'IN');
                    } catch (Net_DNS2_Exception $e) {
                        print_debug('  ' . $e->getMessage() . ' (' . $geo_db['hostname'] . ')');
                    }
                } else {
                    $response = FALSE;
                    print_debug("  DNS LOC enabled, but device hostname empty.");
                }
                if ($response) {
                    if (OBS_DEBUG > 1) {
                        var_dump($response->answer);
                    }
                    foreach ($response->answer as $answer) {
                        if (is_numeric($answer->latitude) && is_numeric($answer->longitude)) {
                            $location['location_lat'] = $answer->latitude;
                            $location['location_lon'] = $answer->longitude;
                            $reverse = TRUE;
                            break;
                        } else {
                            if (is_numeric($answer->degree_latitude) && is_numeric($answer->degree_longitude)) {
                                $ns_multiplier = $answer->ns_hem == 'N' ? 1 : -1;
                                $ew_multiplier = $answer->ew_hem == 'E' ? 1 : -1;
                                $location['location_lat'] = round($answer->degree_latitude + $answer->min_latitude / 60 + $answer->sec_latitude / 3600, 7) * $ns_multiplier;
                                $location['location_lon'] = round($answer->degree_longitude + $answer->min_longitude / 60 + $answer->sec_longitude / 3600, 7) * $ew_multiplier;
                                $reverse = TRUE;
                                break;
                            }
                        }
                    }
                    if (isset($location['location_lat'])) {
                        $debug_msg .= '  DNS LOC records - FOUND' . PHP_EOL;
                    } else {
                        $debug_msg .= '  DNS LOC records - NOT FOUND' . PHP_EOL;
                        if ($dns_only) {
                            // If we check only DNS LOC records but it not found, exit
                            print_debug($debug_msg);
                            return FALSE;
                        }
                    }
                }
            }
        }
        if ($reverse || !preg_match('/^<?(unknown|none)>?$/i', $address)) {
            /**
             * If location string contains coordinates use Reverse Geocoding.
             * Valid strings:
             *   Some location [33.234, -56.22]
             *   Some location (33.234 -56.22)
             *   Some location [33.234;-56.22]
             *   33.234,-56.22
             */
            $pattern = '/(?:^|[\\[(])\\s*(?<lat>[+-]?\\d+(?:\\.\\d+)*)\\s*[,; ]\\s*(?<lon>[+-]?\\d+(?:\\.\\d+)*)\\s*(?:[\\])]|$)/';
            if (!$reverse && preg_match($pattern, $address, $matches)) {
                if ($matches['lat'] >= -90 && $matches['lat'] <= 90 && $matches['lon'] >= -180 && $matches['lon'] <= 180) {
                    $location['location_lat'] = $matches['lat'];
                    $location['location_lon'] = $matches['lon'];
                    $reverse = TRUE;
                }
            }
            if ($reverse) {
                $debug_msg .= '  by REVERSE query (API: ' . strtoupper($config['geocoding']['api']) . ', LAT: ' . $location['location_lat'] . ', LON: ' . $location['location_lon'] . ') - ';
                $url = $api_params['reverse_url'];
                if (isset($api_params['reverse_params'])) {
                    // Additional params for reverse query
                    $params = array_merge($params, $api_params['reverse_params']);
                }
                if (!is_numeric($location['location_lat']) || !is_numeric($location['location_lat'])) {
                    // Do nothing for empty, skip requests for empty coordinates
                } else {
                    if (isset($api_params['request_params']['lat']) && isset($api_params['request_params']['lon'])) {
                        $ok = TRUE;
                        $param = $api_params['request_params']['lat'];
                        $params[$param] = $location['location_lat'];
                        $param = $api_params['request_params']['lon'];
                        $params[$param] = $location['location_lon'];
                    } else {
                        if (isset($api_params['request_params']['latlon'])) {
                            $ok = TRUE;
                            $param = $api_params['request_params']['latlon'];
                            $params[$param] = $location['location_lat'] . ',' . $location['location_lon'];
                        }
                    }
                }
            } else {
                $debug_msg .= '  by PARSING sysLocation (API: ' . strtoupper($config['geocoding']['api']) . ') - ';
                $url = $api_params['direct_url'];
                if (isset($api_params['direct_params'])) {
                    // Additional params for reverse query
                    $params = array_merge($params, $api_params['direct_params']);
                }
                if ($address != '') {
                    $ok = TRUE;
                    $param = $api_params['request_params']['address'];
                    $params[$param] = urlencode($address);
                    //$request = $url . urlencode($address);
                }
            }
            if (OBS_DEBUG > 1) {
                print_vars($api_params);
                print_vars($params);
            }
            if ($ok) {
                // Build request query
                $request = build_request_url($url, $params, $api_params['method']);
                // First request
                $mapresponse = get_http_request($request, NULL, $ratelimit);
                switch ($GLOBALS['response_headers']['code'][0]) {
                    case '4':
                        // 4xx (timeout, rate limit, forbidden)
                    // 4xx (timeout, rate limit, forbidden)
                    case '5':
                        // 5xx (server error)
                        $geo_status = strtoupper($GLOBALS['response_headers']['status']);
                        $debug_msg .= $geo_status . PHP_EOL;
                        if (OBS_DEBUG < 2) {
                            // Hide API KEY from output
                            $request = str_replace($api_params['request_params']['key'] . '=' . escape_html($config['geocoding']['api_key']), $api_params['request_params']['key'] . '=' . '***', $request);
                        }
                        $debug_msg .= '  GEO API REQUEST: ' . $request;
                        print_debug($debug_msg);
                        // Return old array with new status (for later recheck)
                        unset($geo_db['hostname'], $geo_db['location_updated']);
                        $location['location_status'] = $debug_msg;
                        $location['location_updated'] = format_unixtime($config['time']['now'], 'Y-m-d G:i:s');
                        //print_vars($location);
                        //print_vars($geo_db);
                        return array_merge($geo_db, $location);
                }
                $data = json_decode($mapresponse, TRUE);
                //print_vars($data);
                $geo_status = 'NOT FOUND';
                $api_specific = is_file($config['install_dir'] . '/includes/geolocation/' . $location['location_geoapi'] . '.inc.php');
                if ($api_specific) {
                    // API specific parser
                    require_once $config['install_dir'] . '/includes/geolocation/' . $location['location_geoapi'] . '.inc.php';
                    if ($data === FALSE) {
                        // Return old array with new status (for later recheck)
                        unset($geo_db['hostname'], $geo_db['location_updated']);
                        //$location['location_status']  = $debug_msg;
                        $location['location_updated'] = format_unixtime($config['time']['now'], 'Y-m-d G:i:s');
                        //print_vars($location);
                        //print_vars($geo_db);
                        return array_merge($geo_db, $location);
                    }
                } else {
                    if (!isset($location['location_lat'])) {
                        $data = $data[0];
                        if (!count($data) && strpos($address, ',')) {
                            // We seem to have hit a snag geocoding. It might be that the first element of the address is a business name.
                            // Lets drop the first element and see if we get anything better! This works more often than one might expect.
                            list(, $address_new) = explode(',', $address, 2);
                            //$request_new = $url.urlencode($address);
                            $param = $api_params['request_params']['address'];
                            $params[$param] = urlencode($address_new);
                            $request_new = build_request_url($url, $params, $api_params['method']);
                            $mapresponse = get_http_request($request_new, NULL, $ratelimit);
                            $data_new = json_decode($mapresponse, TRUE);
                            if (count($data_new[0])) {
                                // We only want the first entry in the returned data.
                                $data = $data_new[0];
                                $request = $request_new;
                            }
                        }
                    }
                }
                if (OBS_DEBUG > 1 && count($data)) {
                    var_dump($data);
                }
            } else {
                $geo_status = 'NOT REQUESTED';
            }
        }
    }
    if (!$api_specific) {
        // Nominatum
        if (!$reverse) {
            // If using reverse queries, do not change lat/lon
            $location['location_lat'] = $data['lat'];
            $location['location_lon'] = $data['lon'];
        }
        foreach (array('town', 'city', 'hamlet', 'village') as $param) {
            if (isset($data['address'][$param])) {
                $location['location_city'] = $data['address'][$param];
                break;
            }
        }
        $location['location_state'] = $data['address']['state'];
        $location['location_county'] = isset($data['address']['county']) ? $data['address']['county'] : $data['address']['state_district'];
        $location['location_country'] = $data['address']['country_code'];
    }
    // Use defaults if empty values
    if (!strlen($location['location_lat']) || !strlen($location['location_lon'])) {
        // Reset to empty coordinates
        $location['location_lat'] = array('NULL');
        $location['location_lon'] = array('NULL');
        //$location['location_lat'] = $config['geocoding']['default']['lat'];
        //$location['location_lon'] = $config['geocoding']['default']['lon'];
        //if (is_numeric($config['geocoding']['default']['lat']) && is_numeric($config['geocoding']['default']['lon']))
        //{
        //  $location['location_manual']     = 1; // Set manual key for ability reset from WUI
        //}
    } else {
        // Always round lat/lon same as DB precision (DECIMAL(10,7))
        $location['location_lat'] = round($location['location_lat'], 7);
        $location['location_lon'] = round($location['location_lon'], 7);
    }
    foreach (array('city', 'county', 'state') as $entry) {
        // Remove duplicate County/State words
        $param = 'location_' . $entry;
        $location[$param] = strlen($location[$param]) ? str_ireplace(' ' . $entry, '', $location[$param]) : 'Unknown';
    }
    if (strlen($location['location_country'])) {
        $location['location_country'] = strtolower($location['location_country']);
        $geo_status = 'FOUND';
    } else {
        $location['location_country'] = 'Unknown';
    }
    // Print some debug informations
    $debug_msg .= $geo_status . PHP_EOL;
    if (OBS_DEBUG < 2) {
        // Hide API KEY from output
        $request = str_replace($api_params['request_params']['key'] . '=' . escape_html($config['geocoding']['api_key']), $api_params['request_params']['key'] . '=' . '***', $request);
    }
    $debug_msg .= '  GEO API REQUEST: ' . $request;
    if ($geo_status == 'FOUND') {
        $debug_msg .= PHP_EOL . '  GEO LOCATION: ';
        $debug_msg .= country_from_code($location['location_country']) . ' (Country), ' . $location['location_state'] . ' (State), ';
        $debug_msg .= $location['location_county'] . ' (County), ' . $location['location_city'] . ' (City)';
        $debug_msg .= PHP_EOL . '  GEO COORDINATES: ';
        $debug_msg .= $location['location_lat'] . ' (Latitude), ' . $location['location_lon'] . ' (Longitude)';
    } else {
        $debug_msg .= PHP_EOL . '  QUERY DATE: ' . date('r');
        // This is requered for increase data in DB
    }
    print_debug($debug_msg);
    $location['location_status'] = $debug_msg;
    return $location;
}
예제 #7
0
/**
 * Bind with either the configured bind DN, the user's configured DN, or anonymously, depending on config.
 * Private function for this LDAP module only.
 *
 * @param string $username Bind username (optional)
 * @param string $password Bind password (optional)
 * @return bool FALSE if bind succeeded, TRUE if not
*/
function ldap_bind_dn($username = "", $password = "")
{
    global $config, $ds, $cache;
    print_debug("LDAP[Bind DN called]");
    // Avoid binding multiple times on one resource, this upsets some LDAP servers.
    if (isset($cache['ldap_bind_result'])) {
        return $cache['ldap_bind_result'];
    } else {
        if ($config['auth_ldap_binddn']) {
            print_debug("LDAP[Bind][" . $config['auth_ldap_binddn'] . "]");
            $bind = ldap_bind($ds, $config['auth_ldap_binddn'], $config['auth_ldap_bindpw']);
        } else {
            // Try anonymous bind if configured to do so
            if ($config['auth_ldap_bindanonymous']) {
                print_debug("LDAP[Bind][anonymous]");
                $bind = ldap_bind($ds);
            } else {
                if (($username == '' || $password == '') && isset($_SESSION['user_encpass'])) {
                    // Use session credintials
                    print_debug("LDAP[Bind][session]");
                    $username = $_SESSION['username'];
                    if (!isset($_SESSION['mcrypt_required'])) {
                        $password = decrypt($_SESSION['user_encpass'], session_unique_id() . get_unique_id());
                    } else {
                        // WARNING, requires mcrypt
                        $password = base64_decode($_SESSION['user_encpass'], TRUE);
                    }
                }
                print_debug("LDAP[Bind][" . $config['auth_ldap_prefix'] . $username . $config['auth_ldap_suffix'] . "]");
                $bind = ldap_bind($ds, $config['auth_ldap_prefix'] . $username . $config['auth_ldap_suffix'], $password);
            }
        }
    }
    if ($bind) {
        $cache['ldap_bind_result'] = 0;
        return FALSE;
    } else {
        $cache['ldap_bind_result'] = 1;
        print_debug("Error binding to LDAP server: " . implode(',', $config['auth_ldap_server']) . ': ' . ldap_error($ds));
        session_logout();
        return TRUE;
    }
}
예제 #8
0
파일: act.php 프로젝트: jcolfej/botsArena
         $bot2 = $bot;
         $_SESSION['bot2'] = $bot;
         $bot2Exists = true;
     }
     if ($bot1Exists && $bot2Exists) {
         break;
     }
 }
 if (!$bot1Exists or !$bot2Exists) {
     error(500, "missing parameter 2");
 }
 if (!is_it_possible_to_place_ships_on_grid($postValues['gridWidth'], $postValues['gridHeight'], $postValues['nbShip1'], $postValues['nbShip2'], $postValues['nbShip3'], $postValues['nbShip4'], $postValues['nbShip5'], $postValues['nbShip6'])) {
     error(404, "grid is too little for these ships");
 }
 //vars checked, lets init the initGame
 $_SESSION['matchId'] = get_unique_id();
 for ($player = 1; $player <= 2; $player++) {
     if ($player == 1) {
         $opponentName = $bot2['name'];
         $currentBot = $bot1;
     } else {
         $opponentName = $bot1['name'];
         $currentBot = $bot2;
     }
     $botParamsToSend = array('game' => 'Battleship', 'match_id' => $_SESSION['matchId'] . "-1", 'act' => 'init', 'opponent' => $opponentName, 'width' => $postValues['gridWidth'], 'height' => $postValues['gridHeight'], 'ship1' => $postValues['nbShip1'], 'ship2' => $postValues['nbShip2'], 'ship3' => $postValues['nbShip3'], 'ship4' => $postValues['nbShip4'], 'ship5' => $postValues['nbShip5'], 'ship6' => $postValues['nbShip6']);
     $anwserPlayer = get_IA_Response($currentBot['url'], $botParamsToSend);
     $boatsPlayer = json_decode(html_entity_decode($anwserPlayer));
     if (!$boatsPlayer) {
         echo $currentBot['name'] . " a fait une réponse non conforme, il perd." . $anwserPlayer;
         if ($player == 1) {
             save_battle('Battleship', $bot1['name'], $bot2['name'], 2);
<?php

/**
 * Local-scope static variables
 */
function get_unique_id()
{
    static $idEnumerator = null;
    if ($idEnumerator === null) {
        $idEnumerator = 0;
    }
    return $idEnumerator++;
}
echo get_unique_id() . "\n";
// Output: 0
echo get_unique_id() . "\n";
// Output: 1
echo get_unique_id() . "\n";
// Output: 2