Project

General

Profile

Actions

Bug #3538

closed

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:
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);

Actions #1

Updated by Sabri Arslan over 7 years ago

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

Actions #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;
}
Actions #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

Actions #4

Updated by Renato Botelho over 7 years ago

  • Status changed from New to Feedback
  • % Done changed from 0 to 100
Actions #6

Updated by Renato Botelho over 7 years ago

  • Status changed from Feedback to Resolved
Actions

Also available in: Atom PDF