L
L
lFaTaL1Ty2012-09-05 14:10:38
PHP
lFaTaL1Ty, 2012-09-05 14:10:38

Editing a PHP script, in an Asus router, for a fee?

Habravchane, I'm in a desperate state, I need help as quickly as possible, and they won't help anywhere as quickly as possible.

The situation is this:
There is an RT-N16 router with enthusiast firmware, a script is running on it that counts user traffic. Link to the description of the script goo.gl/be2bE

Recently, it was necessary to limit the user limit. To do this, the script has additional functionality in the form of a php script that checks for violations by users of the limit and disables them.
(as a person who doesn’t understand PHP AT ALL and hardly understands Linux, I can’t describe in more detail)
The problem is that the script works for monthly limits, and I need the same thing, but only a daily limit ...

Who can help is ready to pay the n-th amount to a Qiwi or WM wallet.
Skype contact lfatal1ty

Please help!

Answer the question

In order to leave comments, you need to log in

5 answer(s)
L
lFaTaL1Ty, 2012-09-05
@lFaTaL1Ty

So the solution was found and the work was paid for, unfortunately the person is not even a Habravchan (it's still amazing what a huge community can help, given that many just read, and not just write.)

From the author
Изменения для того, что бы выключать пользователей по дневному лимиту:
В файле «FileExtractor.php» создадим дополнительную функцию «getUserTrafByThisDay» (чтобы особо не вдаваться, за основу возьмём уже готовую функцию «getUserTrafByDay» немного изменив её), получится:
FileExtractor.php
public function getUserTrafByThisDay(&$totalDay, &$totalIP) {
        $thisdate = date('Y-m-d');
        $handle1 = fopen($this->world.$thisdate, "r");
        $handle2 = fopen($this->city.$thisdate, "r");
        $sum['win'] = '0';
        $sum['wout'] = '0';
        $sum['cin'] = '0';
        $sum['cout'] = '0';
        while ($userinfo = fscanf($handle1, "%s\t%s\t%s\n")) {
             $userByIp[$userinfo[0]]['win'] = $userinfo[1];
              $userByIp[$userinfo[0]]['wout'] = $userinfo[2];
              $sum['win'] = bcadd($sum['win'], $userinfo[1]);
              $sum['wout'] = bcadd($sum['wout'], $userinfo[2]);
               if (isset($totalIP[$userinfo[0]])) {
                   $totalIP[$userinfo[0]]['win'] = bcadd($totalIP[$userinfo[0]]['win'], $userinfo[1]);
                   $totalIP[$userinfo[0]]['wout'] = bcadd($totalIP[$userinfo[0]]['wout'], $userinfo[2]);
               }
     else {
                   $totalIP[$userinfo[0]]['win'] = $userinfo[1];
                   $totalIP[$userinfo[0]]['wout'] = $userinfo[2];
                   $totalIP[$userinfo[0]]['cin'] = '0';
                   $totalIP[$userinfo[0]]['cout'] = '0';
              }
        }
        while ($userinfo = fscanf($handle2, "%s\t%s\t%s\n")) {
             $userByIp[$userinfo[0]]['cin'] = $userinfo[1];
             $userByIp[$userinfo[0]]['cout'] = $userinfo[2];                    
             $sum['cin'] = bcadd($sum['cin'], $userinfo[1]);
             $sum['cout'] = bcadd($sum['cout'], $userinfo[2]);
              if (isset($totalIP[$userinfo[0]])) {
                  $totalIP[$userinfo[0]]['cin'] = bcadd($totalIP[$userinfo[0]]['cin'], $userinfo[1]);
                  $totalIP[$userinfo[0]]['cout'] = bcadd($totalIP[$userinfo[0]]['cout'], $userinfo[2]);
              }
              else {
                   $totalIP[$userinfo[0]]['cin'] = $userinfo[1];
                   $totalIP[$userinfo[0]]['cout'] = $userinfo[2];
              }
        }
        fclose($handle1);
        fclose($handle2);
        $trafByDay[$thisdate] = $userByIp;
        $totalDay[$thisdate] = $sum;
        unset ($userByIp);
        unset ($sum);
        return $trafByDay;
    }


Убрали сканирование файлов в директории, теперь считываем файл с именем в виде текущей даты.
Соответственно в скрипте, который устанавливает лимит «limit.php» меняем название функции, строка 31:
$trafByDay = $fe->getUserTrafByDay($totalDay, $totalIP);
на
$trafByDay = $fe->getUserTrafByThisDay($totalDay, $totalIP);

If any of the users do not mind sharing an invite with a person.
I unfortunately do not have such an opportunity, but a sensible person. His mail is [email protected]

L
lFaTaL1Ty, 2012-09-05
@lFaTaL1Ty

The script itself
<?php class Limit { private $limitFile = "billing/limit"; private $users = "/usr/local/etc/ethers"; private $userMAC; private $userLimit; private function getLimit() { $handle = fopen($this->limitFile, "r"); while ($userinfo = fscanf($handle, "%s\t%s\t%s\t%s\n")) { $this->userLimit[$userinfo[0]]['in'] = $userinfo[1]; $this->userLimit[$userinfo[0]]['out'] = $userinfo[2]; $this->userLimit[$userinfo[0]]['total'] = $userinfo[3]; } fclose($handle); } private function getUserMAC() { $handle = fopen($this->users, "r"); while ($userinfo = fscanf($handle, "%s\t%s\n")) { $this->userMAC[$userinfo[1]] = $userinfo[0]; } fclose($handle); } public function disableUsers() { $this->getLimit(); $this->getUserMAC(); include_once("FileExtractor.php"); $fe = new FileExtractor(); $trafByDay = $fe->getUserTrafByDay($totalDay, $totalIP); foreach ($this->userLimit as $ip => $limit) { if (isset ($this->userMAC[$ip]) && isset ($totalIP[$ip]) && ( bccomp(bcdiv($totalIP[$ip]['win'], '1048576'), $limit['in']) == 1 || bccomp(bcdiv($totalIP[$ip]['wout'], '1048576'), $limit['out']) == 1 || bccomp(bcdiv(bcadd($totalIP[$ip]['win'], $totalIP[$ip]['wout']), '1048576'), $limit['total']) == 1 ) ){ shell_exec('iptables -D MAC_IP -s '.$ip.' -m mac --mac-source '.$this->userMAC[$ip].' -j RETURN'); } } } } $limit = new Limit(); $limit->disableUsers(); ?>

G
Gregory, 2012-09-05
@difiso

The script itself does not need to be changed. It is enough to change the lock reset time. Read the article to the point

All limits are set as integers.
the user is given 1750MB of incoming, 275MB of outgoing traffic and 2010MB of total traffic (incoming + outgoing). When the user reaches at least one of the limits, it will be disabled.
You can not enter all users in this file if we do not want to set a limit for them.
+ It is necessary to configure
crons: Add to crontab:
*/5 * * * * root cd /opt/share/www/statistic/ &&  /opt/bin/php ./limit.php > /dev/null 2>&1
1 0 1 * * root /user/local/sbin/makefilter

You need to change the line
1 0 1 * * root /user/local/sbin/makefilter

on (for reset at midnight)
0 0 * * * root /user/local/sbin/makefilter

D
Dolios, 2012-09-05
@Dolios

Give the script in a readable form. Wrap the formatted source with the "source" tag. To understand the porridge of letters is too lazy

G
Gregory, 2012-09-05
@difiso

Judging by the scripts, the removal of the blocking occurs by deleting the billing files, so try changing the lines
in the file codebilling.php

$yesterday = date("Y-m", time()-300);
if (date("Y-m") != $yesterday) {

on the lines
$yesterday = date("Y-m-d", time()-300);
if (date("Y-m-d") != $yesterday) {

Justify. This ifdeletes files with data about the used traffic. In their absence, the blocking should be removed. You can get to this block if only 5 minutes ago it was not the same month and year as now (the next month has come). Therefore, to unlock daily, you need to check another day. That is, "Y-m"you need to replace it with "Y-m-d", which will allow you to delete files every day. Well, my previous answer about cron should also be taken into account.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question