diff options
Diffstat (limited to 'notes/projects/radius/sql/ippool-queries.sql')
| -rw-r--r-- | notes/projects/radius/sql/ippool-queries.sql | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/notes/projects/radius/sql/ippool-queries.sql b/notes/projects/radius/sql/ippool-queries.sql index bf3225b..9a82fc6 100644 --- a/notes/projects/radius/sql/ippool-queries.sql +++ b/notes/projects/radius/sql/ippool-queries.sql | |||
| @@ -21,7 +21,6 @@ SET ROLE radius_user; | |||
| 21 | SELECT ip.address AS address, | 21 | SELECT ip.address AS address, |
| 22 | ip.modified AS modified, | 22 | ip.modified AS modified, |
| 23 | ip.username AS username, | 23 | ip.username AS username, |
| 24 | ip.acctsession AS acctsession, | ||
| 25 | pool.name AS pool, | 24 | pool.name AS pool, |
| 26 | region.name AS region | 25 | region.name AS region |
| 27 | FROM ip | 26 | FROM ip |
| @@ -37,7 +36,7 @@ SELECT ip.address AS address, | |||
| 37 | AND ip.username LIKE lower( :'myUsername' ) | 36 | AND ip.username LIKE lower( :'myUsername' ) |
| 38 | AND nas.name LIKE lower( :'myNasName' ) | 37 | AND nas.name LIKE lower( :'myNasName' ) |
| 39 | AND pool.name LIKE lower( :'myPoolName' ) | 38 | AND pool.name LIKE lower( :'myPoolName' ) |
| 40 | AND netblock.active = TRUE | 39 | AND netblock.assignable = TRUE |
| 41 | ORDER BY ip.modified DESC, | 40 | ORDER BY ip.modified DESC, |
| 42 | ip.address ASC | 41 | ip.address ASC |
| 43 | LIMIT 1; | 42 | LIMIT 1; |
| @@ -54,12 +53,12 @@ SELECT ip.address AS address, | |||
| 54 | SELECT ip.address AS address, | 53 | SELECT ip.address AS address, |
| 55 | ip.modified AS modified, | 54 | ip.modified AS modified, |
| 56 | ip.username AS username, | 55 | ip.username AS username, |
| 57 | ip.acctsession AS acctsession, | ||
| 58 | pool.name AS pool, | 56 | pool.name AS pool, |
| 59 | region.name AS region | 57 | region.name AS region |
| 60 | FROM ip | 58 | FROM ip |
| 61 | INNER JOIN netblock | 59 | INNER JOIN netblock |
| 62 | ON netblock.network >>= ip.address | 60 | ON netblock.network >>= ip.address |
| 61 | AND netblock.assignable IS TRUE | ||
| 63 | INNER JOIN region | 62 | INNER JOIN region |
| 64 | ON region.id = netblock.regionId | 63 | ON region.id = netblock.regionId |
| 65 | INNER JOIN pool | 64 | INNER JOIN pool |
| @@ -69,7 +68,7 @@ SELECT ip.address AS address, | |||
| 69 | WHERE ip.nasId IS NULL | 68 | WHERE ip.nasId IS NULL |
| 70 | AND nas.name LIKE lower( :'myNasName' ) | 69 | AND nas.name LIKE lower( :'myNasName' ) |
| 71 | AND pool.name LIKE lower( :'myPoolName' ) | 70 | AND pool.name LIKE lower( :'myPoolName' ) |
| 72 | AND netblock.active = TRUE | 71 | AND netblock.assignable = TRUE |
| 73 | ORDER BY ip.modified ASC, | 72 | ORDER BY ip.modified ASC, |
| 74 | ip.address ASC | 73 | ip.address ASC |
| 75 | LIMIT 1; | 74 | LIMIT 1; |
| @@ -96,7 +95,7 @@ SELECT DISTINCT pool.name AS poolName, | |||
| 96 | ip.address AS address, | 95 | ip.address AS address, |
| 97 | TRUE = ALL | 96 | TRUE = ALL |
| 98 | ( | 97 | ( |
| 99 | SELECT nb2.active | 98 | SELECT nb2.assignable |
| 100 | FROM netblock AS nb2 | 99 | FROM netblock AS nb2 |
| 101 | WHERE ip.address <<= nb2.network | 100 | WHERE ip.address <<= nb2.network |
| 102 | ) AS active, | 101 | ) AS active, |
| @@ -105,8 +104,7 @@ SELECT DISTINCT pool.name AS poolName, | |||
| 105 | ) AS assigned, | 104 | ) AS assigned, |
| 106 | ip.modified AS modified, | 105 | ip.modified AS modified, |
| 107 | nas.name AS nasName, | 106 | nas.name AS nasName, |
| 108 | ip.username AS username, | 107 | ip.username AS username |
| 109 | ip.acctSession AS acctSession | ||
| 110 | FROM ip | 108 | FROM ip |
| 111 | INNER JOIN netblock | 109 | INNER JOIN netblock |
| 112 | ON ip.address <<= netblock.network | 110 | ON ip.address <<= netblock.network |
| @@ -127,15 +125,14 @@ SELECT DISTINCT pool.name AS poolName, | |||
| 127 | SELECT * | 125 | SELECT * |
| 128 | FROM netblock AS nb2 | 126 | FROM netblock AS nb2 |
| 129 | WHERE ip.address <<= nb2.network | 127 | WHERE ip.address <<= nb2.network |
| 130 | AND NOT nb2.active | 128 | AND NOT nb2.assignable |
| 131 | ) AS active, | 129 | ) AS active, |
| 132 | ( | 130 | ( |
| 133 | nasId IS NOT NULL | 131 | nasId IS NOT NULL |
| 134 | ) AS assigned, | 132 | ) AS assigned, |
| 135 | ip.modified AS modified, | 133 | ip.modified AS modified, |
| 136 | nas.name AS nasName, | 134 | nas.name AS nasName, |
| 137 | ip.username AS username, | 135 | ip.username AS username |
| 138 | ip.acctSession AS acctSession | ||
| 139 | FROM ip | 136 | FROM ip |
| 140 | INNER JOIN netblock | 137 | INNER JOIN netblock |
| 141 | ON ip.address <<= netblock.network | 138 | ON ip.address <<= netblock.network |
| @@ -153,11 +150,11 @@ SELECT DISTINCT pool.name AS poolName, | |||
| 153 | */ | 150 | */ |
| 154 | SELECT DISTINCT ip.address AS ipAddress, | 151 | SELECT DISTINCT ip.address AS ipAddress, |
| 155 | netblock.network AS network, | 152 | netblock.network AS network, |
| 156 | netblock.active AS active | 153 | netblock.assignable AS active |
| 157 | FROM ip | 154 | FROM ip |
| 158 | INNER JOIN netblock | 155 | INNER JOIN netblock |
| 159 | ON ip.address <<= netblock.network | 156 | ON ip.address <<= netblock.network |
| 160 | WHERE netblock.active = FALSE | 157 | WHERE netblock.assignable = FALSE |
| 161 | ORDER BY ipAddress; | 158 | ORDER BY ipAddress; |
| 162 | 159 | ||
| 163 | 160 | ||
| @@ -166,18 +163,18 @@ SELECT DISTINCT ip.address AS ipAddress, | |||
| 166 | */ | 163 | */ |
| 167 | SELECT DISTINCT netblock.regionId AS regionId, | 164 | SELECT DISTINCT netblock.regionId AS regionId, |
| 168 | ip.address AS ipAddress, | 165 | ip.address AS ipAddress, |
| 169 | netblock.active AS active | 166 | netblock.assignable AS active |
| 170 | FROM ip | 167 | FROM ip |
| 171 | INNER JOIN netblock | 168 | INNER JOIN netblock |
| 172 | ON ip.address <<= netblock.network | 169 | ON ip.address <<= netblock.network |
| 173 | WHERE netblock.active = TRUE | 170 | WHERE netblock.assignable = TRUE |
| 174 | AND ip.address NOT IN | 171 | AND ip.address NOT IN |
| 175 | ( | 172 | ( |
| 176 | SELECT address AS ipAddress | 173 | SELECT address AS ipAddress |
| 177 | FROM ip | 174 | FROM ip |
| 178 | INNER JOIN netblock | 175 | INNER JOIN netblock |
| 179 | ON ip.address <<= netblock.network | 176 | ON ip.address <<= netblock.network |
| 180 | AND netblock.active = FALSE | 177 | AND netblock.assignable = FALSE |
| 181 | ) | 178 | ) |
| 182 | ORDER BY ipAddress; | 179 | ORDER BY ipAddress; |
| 183 | 180 | ||
