Project

General

Profile

Bug #3538

CaptivePortal passthrumac delete captiveportal_get_ipfw_passthru_ruleno and captiveportal_get_dn_passthru_ruleno functions

Added by Sabri Arslan over 7 years ago. Updated over 7 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
Captive Portal
Target version:
Start date:
03/20/2014
Due date:
% Done:

100%

Estimated time:
Plus Target Version:
Release Notes:
Default
Affected Version:
2.1
Affected Architecture:
amd64

Description

In captive portal i successfully added passthrumac. But when i want to delete mac it can't delete ipfw pipe and rule. It only delete xml passthrumac entry.

in the body of rule number functions cut -d values is wrong. the valid code be like below. (sorry for bad english. i hope someone understand issue).

function captiveportal_get_dn_passthru_ruleno($value) {
.
.
.
        $_gb = exec("/sbin/ipfw -x {$cpzone} show | /usr/bin/grep {$value} |  /usr/bin/grep -v grep | /usr/bin/cut -d \" \" -f 5 | /usr/bin/head -n 1", $output);

must be
function captiveportal_get_dn_passthru_ruleno($value) {
.
.
.
        $_gb = exec("/sbin/ipfw -x {$cpzone} show | /usr/bin/grep {$value} |  /usr/bin/grep -v grep | /usr/bin/cut -d \" \" -f 20 | /usr/bin/head -n 1", $output);

and

function captiveportal_get_ipfw_passthru_ruleno($value) {
.
.
.
        $_gb = exec("/sbin/ipfw -x {$cpzone} show | /usr/bin/grep {$value} |  /usr/bin/grep -v grep | /usr/bin/cut -d \" \" -f 5 | /usr/bin/head -n 1", $output);

must be
function captiveportal_get_ipfw_passthru_ruleno($value) {
.
.
.
        $_gb = exec("/sbin/ipfw -x {$cpzone} show | /usr/bin/grep {$value} |  /usr/bin/grep -v grep | /usr/bin/cut -d \" \" -f 1 | /usr/bin/head -n 1", $output);

Associated revisions

Revision c4fb986b (diff)
Added by Renato Botelho over 7 years ago

Fix deletion of ipfw rules and pipes for passthru mac, it fixes #3538

Revision dae77fe3 (diff)
Added by Renato Botelho over 7 years ago

Fix deletion of ipfw rules and pipes for passthru mac, it fixes #3538

History

#1 Updated by Sabri Arslan over 7 years ago

cut -d \" \" -f 20 not true still searching

#2 Updated by Sabri Arslan over 7 years ago

Finally fully working code is below

function captiveportal_get_ipfw_passthru_ruleno($value) {
    global $config, $g, $cpzone;

    $cpcfg = $config['captiveportal'][$cpzone];
    if(!isset($cpcfg['enable']))
        return NULL;

    $cpruleslck = lock("captiveportalrules{$cpzone}", LOCK_EX);
    $ruleno = NULL;
    if (file_exists("{$g['vardb_path']}/captiveportal_{$cpzone}.rules")) {
        $rules = unserialize(file_get_contents("{$g['vardb_path']}/captiveportal_{$cpzone}.rules"));
        unset($output);
        $_gb = exec("/sbin/ipfw -x {$cpzone} show | /usr/bin/grep {$value} |  /usr/bin/grep -v grep | /usr/bin/head -n 1", $output);
        if(is_array($output)&&count($output)>0) {
            $t=split(" ",$output[0]);
            if(is_array($t)&&count($t)>0) {
                $ruleno = intval($t[0]);
            }
        }
        $ruleno = intval($output[0]);
        if (!$rules[$ruleno])
            $ruleno = NULL;
    }
    unlock($cpruleslck);
    unset($rules);

    return $ruleno;
}

function captiveportal_get_dn_passthru_ruleno($value) {
    global $config, $g, $cpzone;

    $cpcfg = $config['captiveportal'][$cpzone];
    if(!isset($cpcfg['enable']))
        return NULL;

    $cpruleslck = lock("captiveportalrulesdn", LOCK_EX);
    $ruleno = NULL;
    if (file_exists("{$g['vardb_path']}/captiveportaldn.rules")) {
        $rules = unserialize(file_get_contents("{$g['vardb_path']}/captiveportaldn.rules"));
        unset($output);
        $_gb = exec("/sbin/ipfw -x {$cpzone} show | /usr/bin/grep {$value} |  /usr/bin/grep -v grep | /usr/bin/head -n 1", $output);
        if(is_array($output)&&count($output)>0) {
            $t=split("pipe",$output[0]);
            if(is_array($t)&&count($t)>0) {
                $r=split("ip",$t[1]);
                if(is_array($r)&&count($r)>0) {
                    $ruleno = intval($r[0]);
                }
            }
        }
        if (!$rules[$ruleno])
            $ruleno = NULL;
        unset($rules);
    }
    unlock($cpruleslck);

    return $ruleno;
}

#3 Updated by Phillip Davis over 7 years ago

It will be much easier to quickly review your change if you edit on GitHub and submit a pull request: https://github.com/pfsense/pfsense

#4 Updated by Renato Botelho over 7 years ago

  • Status changed from New to Feedback
  • % Done changed from 0 to 100

#6 Updated by Renato Botelho over 7 years ago

  • Status changed from Feedback to Resolved

Also available in: Atom PDF