dial rules ( in trunks ) won't save

Discussion in 'General' started by lunix, Oct 18, 2007.

  1. lunix

    Joined:
    Oct 17, 2007
    Messages:
    6
    Likes Received:
    0
    Hi all,

    I am trying to set some dial rules to add 02 to any 8 digit number dialed. When I click save the page refreshes and the rules have disappeared.
    I have run a diff over all files in /etc/asterisk and nothing is changed.
    What am I doing wrong or is this a bug ?
    I have installed from 0.8.5 cd and no updates run.

    02+9XXXXXXX
    02+8XXXXXXX
    02+4XXXXXXX
    02+6XXXXXXX

    Mick<br><br>Post edited by: lunix, at: 2007/10/18 00:26
     
  2. sappsys

    Joined:
    Oct 26, 2007
    Messages:
    5
    Likes Received:
    0
    Ok, I know why this is broken, and I have made a fix to my code.
    For some reason, the $localPrefixFile variable in /var/www/html/admin/modules/core/page.trunks.php is going out of scope, and when it is then subsequently referenced in functions.inc.php, it is blank.

    strange, the author says...
    global $localPrefixFile; // probably not the best way

    I agree. I have made my code so that the variable gets passed as a parameter between the relevant functions instead of relying on the global variable, and now i can store trunk dial rules.


    diff -u core.copy/functions.inc.php core/functions.inc.php
    --- core.copy/functions.inc.php 2007-10-27 01:08:28.000000000 +0100
    +++ core/functions.inc.php 2007-10-27 01:14:00.000000000 +0100
    @@ -1592,31 +1592,31 @@
    }


    -function core_trunks_addDialRules($trunknum, $dialrules) {
    +function core_trunks_addDialRules($trunknum, $dialrules, $localPrefixFile) {
    $values = array();
    $i = 1;
    foreach ($dialrules as $rule) {
    $values["rule".$i++] = $rule;
    }

    - $conf = core_trunks_readDialRulesFile();
    + $conf = core_trunks_readDialRulesFile($localPrefixFile);

    // rewrite for this trunk
    $conf["trunk-".$trunknum] = $values;

    - core_trunks_writeDialRulesFile($conf);
    + core_trunks_writeDialRulesFile($conf, $localPrefixFile);
    }

    -function core_trunks_readDialRulesFile() {
    - global $localPrefixFile; // probably not the best way
    +function core_trunks_readDialRulesFile($localPrefixFile) {
    +// global $localPrefixFile; // probably not the best way

    core_trunks_parse_conf($localPrefixFile, $conf, $section);

    return $conf;
    }

    -function core_trunks_writeDialRulesFile($conf) {
    - global $localPrefixFile; // probably not the best way
    +function core_trunks_writeDialRulesFile($conf, $localPrefixFile) {
    +// global $localPrefixFile; // probably not the best way

    $fd = fopen($localPrefixFile,"w");
    foreach ($conf as $section=>$values) {
    @@ -1750,8 +1750,8 @@
    return isset($register)?$register:null;
    }

    -function core_trunks_getDialRules($trunknum) {
    - $conf = core_trunks_readDialRulesFile();
    +function core_trunks_getDialRules($trunknum, $localPrefixFile) {
    + $conf = core_trunks_readDialRulesFile($localPrefixFile);
    if (isset($conf["trunk-".$trunknum])) {
    return $conf["trunk-".$trunknum];
    }
    @@ -1784,13 +1784,13 @@
    return isset($routes)?$routes:null;
    }

    -function core_trunks_deleteDialRules($trunknum) {
    - $conf = core_trunks_readDialRulesFile();
    +function core_trunks_deleteDialRules($trunknum, $localPrefixFile) {
    + $conf = core_trunks_readDialRulesFile($localPrefixFile);

    // remove rules for this trunk
    unset($conf["trunk-".$trunknum]);

    - core_trunks_writeDialRulesFile($conf);
    + core_trunks_writeDialRulesFile($conf, $localPrefixFile);
    }

    /* end page.trunks.php functions */
    diff -u core.copy/page.trunks.php core/page.trunks.php
    --- core.copy/page.trunks.php 2007-09-06 23:22:06.000000000 +0100
    +++ core/page.trunks.php 2007-10-27 01:11:07.000000000 +0100
    @@ -61,7 +61,7 @@
    case "addtrunk":
    $trunknum = core_trunks_add($tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid);

    - core_trunks_addDialRules($trunknum, $dialrules);
    + core_trunks_addDialRules($trunknum, $dialrules, $localPrefixFile);
    needreload();
    redirect_standard();
    break;
    @@ -74,7 +74,7 @@
    */

    // this can rewrite too, so edit is the same
    - core_trunks_addDialRules($trunknum, $dialrules);
    + core_trunks_addDialRules($trunknum, $dialrules, $localPrefixFile);
    needreload();
    redirect_standard('extdisplay');
    break;
    @@ -85,7 +85,7 @@
    /* //DIALRULES
    deleteTrunkRules($channelid);
    */
    - core_trunks_deleteDialRules($trunknum);
    + core_trunks_deleteDialRules($trunknum, $localPrefixFile);
    needreload();
    redirect_standard();
    break;
    @@ -252,7 +252,7 @@


    if (count($dialrules) == 0) {
    - if ($temp = core_trunks_getDialRules($trunknum)) {
    + if ($temp = core_trunks_getDialRules($trunknum, $localPrefixFile)) {
    foreach ($temp as $key=>$val) {
    // extract all ruleXX keys
    if (preg_match("/^rule\d+$/",$key)) {


    I am quite happy for somebody to go.. all you needed was this one line fix :)
    But anyway.. that's why it's broken...
     
  3. sappsys

    Joined:
    Oct 26, 2007
    Messages:
    5
    Likes Received:
    0
    hmm.. it posted my comment twice.. removed this one..<br><br>Post edited by: sappsys, at: 2007/10/27 02:33
     
  4. lunix

    Joined:
    Oct 17, 2007
    Messages:
    6
    Likes Received:
    0
    Thats awesome.
    I will hopefully try this out tomorrow some time.

    Thanks

    Mick
    _lunix_
     

Share This Page