Пример #1
0
function proc_attributes(&$a)
{
    global $aaa_config;
    global $hotspot_user;
    global $hotspot_device;
    global $hotspot_code;
    $login_type = $a['Meta-Login'];
    $interval = $a['Meta-Interval'];
    $interval_value = $a['Meta-Interval-Value'];
    if ($interval_value == '') {
        $interval_value = 1;
    }
    $t = null;
    switch ($login_type) {
        case 'device':
            $obj = $hotspot_device;
            $t = db_table('devices');
            if (!check_validity($t, $obj, $a)) {
                return false;
            }
            $sum = get_device_summary($obj);
            break;
        case 'user':
            $obj = $hotspot_user;
            $t = db_table('users');
            if (!check_validity($t, $obj, $a)) {
                return false;
            }
            $sum = get_user_summary($obj);
            if ($obj['id'] != $hotspot_device['owner_id']) {
                $sql = 'UPDATE ' . db_table('devices') . ' SET owner_id = ' . $obj['id'] . ' WHERE id = ' . $hotspot_device['id'];
                db_query($sql, false);
            }
            break;
        case 'code':
            $t = db_table('codes');
            $obj = $hotspot_code;
            if (!check_validity($t, $obj, $a)) {
                return false;
            }
            $sum = get_code_summary($obj);
            if ($obj['device_id'] != $hotspot_device['id']) {
                $sql = 'UPDATE ' . $t . ' SET device_id = ' . $hotspot_device['id'] . ' WHERE id = ' . $obj['id'];
                db_query($sql, false);
            }
            break;
        default:
            return false;
    }
    switch ($interval) {
        case 'minute':
        case 'hour':
        case 'day':
        case 'month':
        case 'year':
            if ($obj['valid_until'] == '') {
                db_query('UPDATE ' . $t . ' SET valid_until = DATE_ADD(valid_from, INTERVAL ' . $interval_value . ' ' . $interval . ')', false);
            }
            break;
        default:
            break;
    }
    $swap = $aaa_config['using_swapoctets'];
    # Down
    $n = 'CoovaChilli-Max-' . ($swap ? 'Out' : 'In') . 'put-Octets';
    $v = $a[$n];
    if (isset($v) && $v > 0 && $sum['bytes_down'] > 0) {
        $s = $v - $sum['bytes_down'];
        if ($s <= 0) {
            set_reply_message($a, 'Download data limit reached', false);
            return false;
        }
        $a[$n] = $s;
    }
    # Up
    $n = 'CoovaChilli-Max-' . ($swap ? 'In' : 'Out') . 'put-Octets';
    $v = $a[$n];
    if (isset($v) && $v > 0 && $sum['bytes_up'] > 0) {
        $s = $v - $sum['bytes_up'];
        if ($s <= 0) {
            set_reply_message($a, 'Upload data limit reached', false);
            return false;
        }
        $a[$n] = $s;
    }
    # Total
    $n = 'CoovaChilli-Max-Total-Octets';
    $v = $a[$n];
    if (isset($v) && $v > 0 && ($sum['bytes_up'] > 0 || $sum['bytes_down'] > 0)) {
        $s = $v;
        if ($sum['bytes_up'] > 0) {
            $s -= $sum['bytes_up'];
        }
        if ($sum['bytes_down'] > 0) {
            $s -= $sum['bytes_down'];
        }
        if ($s <= 0) {
            set_reply_message($a, 'Total data limit reached', false);
            return false;
        }
        $a[$n] = $s;
    }
    $ses_time = $a['Acct-Session-Time'];
    if (isset($ses_time) && $ses_time > 0) {
        $ses_time -= $sum['seconds'];
        if ($ses_time <= 0) {
            set_reply_message($a, 'Time expired', false);
            return false;
        }
        set_session_timeout($a, $ses_time, true);
        unset($a['Acct-Session-Time']);
    }
    return true;
}
Пример #2
0
                mysql_query(sprintf("update bieganie_nikeplus set nikeplus_user='******', nikeplus_pass='******' where user='******'", mysql_real_escape_string($to_user)));
                biegacz_senddm($to_user, "Dane autoryzacji do NikePlus zostały uaktualnione. Szczegóły http://biegacze.adblix.pl/users/{$to_user}", 'biegacze', 'runstats');
            } else {
                // dodanie nowego
                mysql_query(sprintf("insert into bieganie_nikeplus (user, nikeplus_user, nikeplus_pass) values ('%s', '{$matches[1]}', '{$matches[2]}')", mysql_real_escape_string($to_user)));
                biegacz_senddm($to_user, "Spięcie z usługą NikePlus zostało uaktywnione. Szczegóły http://biegacze.adblix.pl/users/{$to_user}", 'biegacze', 'runstats');
            }
            mysql_query("insert into bieganie_pm_blip_id (blip_id) values ({$blip_id})");
        }
    }
}
$dm_commands = get_dm_messages('biegacze', 'runstats');
foreach ($dm_commands as $blip) {
    if ($blip->user_path == '/users/biegacze') {
        continue;
    }
    $blip_id = $blip->id;
    $blip_id_res = mysql_query("select blip_id from bieganie_pm_blip_id where blip_id = {$blip_id}");
    if (mysql_num_rows($blip_id_res) > 0) {
        continue;
    }
    if (preg_match($info_regexp, $blip->body, $matches)) {
        // wyslij dane uzytkownika $blip->user_path
        $to_user = str_replace('/users/', '', $blip->user_path);
        print "<h3>Mamy zapytanie info od {$to_user}</h3>";
        biegacz_senddm($to_user, get_user_summary($to_user), 'biegacze', 'runstats');
        mysql_query("insert into bieganie_pm_blip_id (blip_id) values ({$blip_id})");
    }
}
mysql_query("INSERT into cronjobs (name, status, lastrun) values ('biegacze 5min', 'OK', NOW())");
print "OK.";