Commit ad5f767a authored by ueli heuer's avatar ueli heuer 👾
Browse files

- SQL Syntax in uppercase

- Trying to access array offset on value of type null on lin 639
parent 4d6282ec
......@@ -49,11 +49,11 @@ class ipnet {
switch ($type) {
case 'link':
$link_id = $id;
$device_sql = sprintf('select device_id
from dvg_device_link
where link_id =\'%d\'
and start_time <= curdate()
and (stop_time is null or stop_time >= curdate())',$link_id);
$device_sql = sprintf('SELECT device_id
FROM dvg_device_link
WHERE link_id =\'%d\'
AND start_time <= curdate()
AND (stop_time is null or stop_time >= curdate())',$link_id);
$device_r = $CONFIG->DB->query($device_sql);
DVG_error::check($device_r);
......@@ -64,12 +64,12 @@ class ipnet {
break;
case 'device':
$device_id = $id;
$link_sql = sprintf('select link_id
from dvg_device_link
where device_id = \'%d\'
and start_time <= curdate()
and (stop_time is null or stop_time >= curdate())',$device_id);
$link_r = $CONFIG->DB->query($link_sql);
$link_sql = sprintf('SELECT link_id
FROM dvg_device_link
WHERE device_id = \'%d\'
AND start_time <= curdate()
AND (stop_time is null or stop_time >= curdate())',$device_id);
$LINK_R = $CONFIG->DB->query($link_sql);
DVG_error::check($link_r);
$link_count = $link_r->rowCount();
......@@ -79,11 +79,11 @@ class ipnet {
break;
case 'bbcs':
$bbcs_id = $id;
$link_sql = sprintf('select link_id
from dvg_device_link
where device_id = \'%d\'
and start_time <= curdate()
and (stop_time is null or stop_time >= curdate())',$device_id);
$link_sql = sprintf('SELECT link_id
FROM dvg_device_link
WHERE device_id = \'%d\'
AND Start_time <= curdate()
AND (stop_time is null or stop_time >= curdate())',$device_id);
$link_r = $CONFIG->DB->query($link_sql);
$link_count = $link_r->rowCount();
......@@ -98,15 +98,15 @@ class ipnet {
$this->save($type,$id);
}
$ip_sql = sprintf('select it.id, it.device_id, it.link_id,
$ip_sql = sprintf('SELECT it.id, it.device_id, it.link_id,
it.base_addr, it.dev_addr, it.broadcast_addr, it.vrf, dv.name,
it.stop_date
from dvg_ipv4_table it
left join dvg_vrf dv on (it.vrf = dv.id)
where ( %s it.link_id = \'%d\' )
and it.start_date <= curdate()
and ( it.stop_date is null or it.stop_date >= curdate() ) %s
order by it.base_addr',
FROM dvg_ipv4_table it
LEFT JOIN dvg_vrf dv on (it.vrf = dv.id)
WHERE ( %s it.link_id = \'%d\' )
AND it.start_date <= curdate()
AND ( it.stop_date is null OR it.stop_date >= curdate() ) %s
ORDER by it.base_addr',
$link_only ? '' : sprintf('it.device_id = \'%d\' or',$device_id),
$link_id,
($link_ipv4_id > 0 && $action == 'edit-ip') ?
......@@ -194,6 +194,7 @@ class ipnet {
return $tab;
}
// }}}
// phpcs:ignore error
function show__($radius_id,$bk_radius_id,$link_id,$bk_link_id,$device_id,$tab,$edit=TRUE,$title='IPv4 Net',$type,$id) //{{{
{
......@@ -207,17 +208,17 @@ class ipnet {
$this->save($type,$id);
}
$ip_sql = sprintf('select ip4.id,ip4.radius_id, ip4.link_id,
$ip_sql = sprintf('SELECT ip4.id,ip4.radius_id, ip4.link_id,
ip4.base_addr,ip4.dev_addr, ip4.broadcast_addr,
dv.id, dv.name, dv.rd
from dvg_ipv4_table ip4
left join dvg_vrf dv on (ip4.vrf = dv.id
and dv.start_date <= curdate()
and (dv.stop_date is null or dv.stop_date >= curdate()))
where (0 %s %s %s %s %s)
and ip4.start_date <= curdate()
and (ip4.stop_date is null or ip4.stop_date >= curdate() )
order by ip4.broadcast_addr - ip4.base_addr, ip4.base_addr',
FROM dvg_ipv4_table ip4
LEFT JOIN dvg_vrf dv ON (ip4.vrf = dv.id
AND dv.start_date <= curdate()
AND (dv.stop_date is null or dv.stop_date >= curdate()))
WHERE (0 %s %s %s %s %s)
AND ip4.start_date <= curdate()
AND (ip4.stop_date is null or ip4.stop_date >= curdate() )
ORDER by ip4.broadcast_addr - ip4.base_addr, ip4.base_addr',
$radius_id ? sprintf('or ip4.radius_id =\'%d\'',$radius_id)
: '',
$bk_radius_id ? sprintf('or ip4.radius_id =\'%d\'',
......@@ -297,10 +298,10 @@ class ipnet {
$PAGE->objAjax->processRequest();
}
$tab_cols = $tab->get_cols();
$net_sql = sprintf('select base_addr,dev_addr,broadcast_addr,
$net_sql = sprintf('SELECT base_addr,dev_addr,broadcast_addr,
start_date,stop_date,created,vrf
from dvg_ipv4_table
where id=\'%d\'',$ipv4_id);
FROM dvg_ipv4_table
WHERE id=\'%d\'',$ipv4_id);
$net_r = $CONFIG->DB->query($net_sql);
DVG_error::check($net_r);
......@@ -397,8 +398,8 @@ class ipnet {
}
if ( $ip->ip ) {
if ($ipv4_id) { // update ....
$net_sql = sprintf ("update dvg_ipv4_table
set base_addr='%s',
$net_sql = sprintf ("UPDATE dvg_ipv4_table
SET base_addr='%s',
dev_addr=%s,
broadcast_addr='%s',
vrf='%s',
......@@ -406,7 +407,7 @@ class ipnet {
stop_date=%s,
user='%s',
changed=now()
where id = '%s'",
WHERE id = '%s'",
$ip->base,
$ip->ip == $ip->base ? 'null' : "'$ip->ip'",
$ip->broadcast,
......@@ -418,13 +419,13 @@ class ipnet {
$result = $CONFIG->DBW->query($net_sql);
DVG_error::check($result);
DVG_log::syslog(LOG_INFO,
sprintf("update IPV4 address: id=$ipv4_id, ip='$ipv4net' " .
sprintf("UPDATE IPV4 address: id=$ipv4_id, ip='$ipv4net' " .
"vrf='$vrf_id' start_date=$ip_start, stop_date=$ip_stop"));
} else { // a new-entry
$net_sql = sprintf('insert into dvg_ipv4_table
$net_sql = sprintf('INSERT INTO dvg_ipv4_table
(id,%s_id,base_addr,dev_addr,broadcast_addr,vrf,
start_date,stop_date,user,changed,creator,created)
values (null, %s, \'%s\', %s, \'%s\', \'%s\',
VALUES (null, %s, \'%s\', %s, \'%s\', \'%s\',
%s, %s, \'%s\', now(), \'%s\', now())',
$type,$remote_id,
$ip->base,
......@@ -437,7 +438,7 @@ class ipnet {
$result = $CONFIG->DBW->query($net_sql);
DVG_error::check($result);
$ipv4_id = $CONFIG->DB->lastInsertID('dvg_ipv4_table');
DVG_log::syslog(LOG_INFO,sprintf("insert IPV4 address: " .
DVG_log::syslog(LOG_INFO,sprintf("INSERT IPV4 address: " .
"id=$ipv4_id, ip='$ipv4net' vrf='$vrf_id' " .
"start_date=$ip_start, stop_date=$ip_stop"));
}
......@@ -452,38 +453,38 @@ class ipnet {
switch ($type) {
case self::TYPE_RADIUS:
$net_sql = "select id,base_addr,dev_addr,broadcast_addr,
$net_sql = "SELECT id,base_addr,dev_addr,broadcast_addr,
start_date,stop_date,created,vrf
from dvg_ipv4_table
where start_date <= curdate()
and (stop_date is null or stop_date >= curdate())
and radius_id = '$id'";
FROM dvg_ipv4_table
WHERE start_date <= curdate()
AND (stop_date is null OR stop_date >= curdate())
AND radius_id = '$id'";
break;
case self::TYPE_DEVICE:
$net_sql = "select id,base_addr,dev_addr,broadcast_addr,
$net_sql = "SELECT id,base_addr,dev_addr,broadcast_addr,
start_date,stop_date,created,vrf
from dvg_ipv4_table
where start_date <= curdate()
and (stop_date is null or stop_date >= curdate())
and device_id = '$id'";
FROM dvg_ipv4_table
WHERE start_date <= curdate()
AND (stop_date is null OR stop_date >= curdate())
AND device_id = '$id'";
break;
case self::TYPE_LINK:
$net_sql = "select id,base_addr,dev_addr,broadcast_addr,
$net_sql = "SELECT id,base_addr,dev_addr,broadcast_addr,
start_date,stop_date,created,vrf
from dvg_ipv4_table
where start_date <= curdate()
and (stop_date is null or stop_date >= curdate())
and link_id = '$id'";
FROM dvg_ipv4_table
WHERE start_date <= curdate()
AND (stop_date is null OR stop_date >= curdate())
AND link_id = '$id'";
break;
case self::TYPE_HOST:
break;
case self::TYPE_IP:
$net_sql = "select id,base_addr,dev_addr,broadcast_addr,
$net_sql = "SELECT id,base_addr,dev_addr,broadcast_addr,
start_date,stop_date,created,vrf
from dvg_ipv4_table
where start_date <= curdate()
and (stop_date is null or stop_date >= curdate())
and id='$id'";
FROM dvg_ipv4_table
WHERE start_date <= curdate()
AND (stop_date is null OR stop_date >= curdate())
AND id='$id'";
break;
}
......@@ -592,78 +593,78 @@ class ipnet {
switch ($type) {
case self::TYPE_DEVICE:
$net_ins = "insert into dvg_ipv4_table(id,device_id,
$net_ins = "INSERT INTO dvg_ipv4_table(id,device_id,
base_addr, dev_addr, broadcast_addr, vrf,
start_date, stop_date, user, created, changed)
values (null,'%s','%s',%s,'%s','%s',%s,%s,'%s',now(),now()";
$net_upd = "update dvg_ipv4_table
set device_id='%s', base_addr='%s', dev_addr=%s, broadcast_addr='%s',
VALUES (null,'%s','%s',%s,'%s','%s',%s,%s,'%s',now(),now()";
$net_upd = "UPDATE dvg_ipv4_table
SET device_id='%s', base_addr='%s', dev_addr=%s, broadcast_addr='%s',
vrf='%s', start_date=%s, stop_date=%s, user='%s',changed=now()
where id = '%s'";
WHERE id = '%s'";
break;
case self::TYPE_LINK:
$net_ins = "insert into dvg_ipv4_table(id,link_id,
$net_ins = "INSERT INTO dvg_ipv4_table(id,link_id,
base_addr, dev_addr, broadcast_addr, vrf,
start_date, stop_date, user, created, changed)
values (null,'%s','%s',%s,'%s','%s',%s,%s,'%s',now(),now());";
$net_upd = "update dvg_ipv4_table
VALUES (null,'%s','%s',%s,'%s','%s',%s,%s,'%s',now(),now());";
$net_upd = "UPDATE dvg_ipv4_table
set link_id='%s', base_addr='%s', dev_addr=%s, broadcast_addr='%s',
vrf='%s', start_date=%s, stop_date=%s, user='%s',changed=now()
where id = '%s';";
WHERE id = '%s';";
break;
case self::TYPE_RADIUS:
$net_ins = "insert into dvg_ipv4_table(id,radius_id,
$net_ins = "INSERT INTO dvg_ipv4_table(id,radius_id,
base_addr, dev_addr, broadcast_addr, vrf,
start_date, stop_date, user, created, changed)
values (null,'%s','%s',%s,'%s','%s',%s,%s,'%s',now(),now());";
$net_upd = "update dvg_ipv4_table
set radius_id='%s', base_addr='%s', dev_addr=%s, broadcast_addr='%s',
VALUES (null,'%s','%s',%s,'%s','%s',%s,%s,'%s',now(),now());";
$net_upd = "UPDATE dvg_ipv4_table
SET radius_id='%s', base_addr='%s', dev_addr=%s, broadcast_addr='%s',
vrf='%s', start_date=%s, stop_date=%s, user='%s',changed=now()
where id = '%s';";
WHERE id = '%s';";
break;
case self::TYPE_HOST:
break;
case self::TYPE_IP:
$net_ins = "insert into dvg_ipv4_table(id,null,
$net_ins = "INSERT INTO dvg_ipv4_table(id,null,
base_addr, dev_addr, broadcast_addr, vrf,
start_date, stop_date, user, created, changed)
values (null,'%s','%s',%s,'%s','%s',%s,%s,'%s',now(),now())";
$net_upd = "update dvg_ipv4_table
set id='%s', base_addr='%s', dev_addr=%s, broadcast_addr='%s',
VALUES (null,'%s','%s',%s,'%s','%s',%s,%s,'%s',now(),now())";
$net_upd = "UPDATE dvg_ipv4_table
SET id='%s', base_addr='%s', dev_addr=%s, broadcast_addr='%s',
vrf='%s', start_date=%s, stop_date=%s, user='%s',changed=now()
where id = '%s'";
WHERE id = '%s'";
break;
}
for ($i=0; $i<=$ipv4_count; $i++ ) {
if ( $ipv4_net[$i] != '' ) {
if (! is_null($ipv4_net) && $ipv4_net[$i] != '' ) {
$ip = DVG_ipv4format::validate($ipv4_net[$i]);
if ( $ipv4_start[$i] == '' ) {
$ipv4start = 'null';
} else {
$ipv4start = "'$ipv4_start[$i]'";
if ( $ipv4_start[$i] == '' ) {
$ipv4start = 'null';
} else {
$ipv4start = "'$ipv4_start[$i]'";
}
if ( $ipv4_stop[$i] == '' ) {
if ( !is_null($stop_date) && $stop_date != 'null') {
$ipv4stop = $stop_date;
} else {
$ipv4stop = 'null';
$ipv4stop = 'null';
}
} else {
$ipv4stop = "'$ipv4_stop[$i]'";
$ipv4stop = "'$ipv4_stop[$i]'";
}
if ( $ipv4_id[$i] == 0 ) { // insert new entry
$result = $CONFIG->DBW->query(sprintf($net_ins,
$id, $ip->base,
$ip->ip == $ip->base ? 'null' : "'$ip->ip'",
$ip->broadcast,
$ip->broadcast,
$vrf_id[$i], $ipv4start, $ipv4stop, $USER->user_name));
DVG_error::check($result);
} else { // update entry
$result = $CONFIG->DBW->query(sprintf($net_upd,
$id, $ip->base,
$ip->ip == $ip->base ? 'null' : "'$ip->ip'",
$ip->broadcast,
$ip->broadcast,
$vrf_id[$i], $ipv4start, $ipv4stop, $USER->user_name,
$ipv4_id[$i]));
DVG_error::check($result);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment