| 3 | | /* merge_ext_followme_priv($dest) { |
|---|
| 4 | | * |
|---|
| 5 | | * The purpose of this function is to take a destination |
|---|
| 6 | | * that was either a core extension OR a findmefollow-destination |
|---|
| 7 | | * and convert it so that they are merged and handled just like |
|---|
| 8 | | * direct-did routing |
|---|
| 9 | | * |
|---|
| 10 | | * Assuming an extension number of 222: |
|---|
| 11 | | * |
|---|
| 12 | | * The two formats that existed for findmefollow were: |
|---|
| 13 | | * |
|---|
| 14 | | * ext-findmefollow,222,1 |
|---|
| 15 | | * ext-findmefollow,FM222,1 |
|---|
| 16 | | * |
|---|
| 17 | | * The one format that existed for core was: |
|---|
| 18 | | * |
|---|
| 19 | | * ext-local,222,1 |
|---|
| 20 | | * |
|---|
| 21 | | * In all those cases they should be converted to: |
|---|
| 22 | | * |
|---|
| 23 | | * from-did-direct,222,1 |
|---|
| 24 | | * |
|---|
| 25 | | */ |
|---|
| 26 | | function merge_ext_followme_priv($dest) { |
|---|
| 27 | | |
|---|
| 28 | | if (preg_match("/^\s*ext-findmefollow,(FM)?(\d+),(\d+)/",$dest,$matches) || |
|---|
| 29 | | preg_match("/^\s*ext-local,(FM)?(\d+),(\d+)/",$dest,$matches) ) { |
|---|
| 30 | | // matches[2] => extn |
|---|
| 31 | | // matches[3] => priority |
|---|
| 32 | | return "from-did-direct,".$matches[2].",".$matches[3]; |
|---|
| 33 | | } else { |
|---|
| 34 | | return $dest; |
|---|
| 35 | | } |
|---|
| 36 | | } |
|---|
| 37 | | |
|---|
| 38 | | outn("Upgrading Inbound Routing to allow for Music on Hold per DID.."); |
|---|
| 39 | | |
|---|
| 40 | | $sql = "SELECT mohclass FROM incoming"; |
|---|
| 41 | | $confs = $db->getRow($sql, DB_FETCHMODE_ASSOC); |
|---|
| 42 | | if (!DB::IsError($confs)) { // no error... Already done |
|---|
| 43 | | out("Not Required"); |
|---|
| 44 | | } else { |
|---|
| 45 | | $sql = "ALTER TABLE incoming ADD mohclass VARCHAR ( 80 ) DEFAULT \"default\""; |
|---|
| 46 | | $results = $db->query($sql); |
|---|
| 47 | | if(DB::IsError($results)) { |
|---|
| 48 | | die($results->getMessage()); |
|---|
| 49 | | } |
|---|
| 50 | | out("Done"); |
|---|
| 51 | | } |
|---|
| 52 | | |
|---|
| 53 | | outn("Upgrading Inbound Routing to provide a description field.."); |
|---|
| 54 | | |
|---|
| 55 | | $sql = "SELECT description FROM incoming"; |
|---|
| 56 | | $confs = $db->getRow($sql, DB_FETCHMODE_ASSOC); |
|---|
| 57 | | if (!DB::IsError($confs)) { // no error... Already done |
|---|
| 58 | | out("Not Required"); |
|---|
| 59 | | } else { |
|---|
| 60 | | $sql = "ALTER TABLE incoming ADD description VARCHAR ( 80 ) NULL"; |
|---|
| 61 | | $results = $db->query($sql); |
|---|
| 62 | | if(DB::IsError($results)) { |
|---|
| 63 | | die($results->getMessage()); |
|---|
| 64 | | } |
|---|
| 65 | | out("Done"); |
|---|
| 66 | | } |
|---|
| 67 | | |
|---|
| 68 | | outn("Upgrading Inbound Routing to provide a CID Prefix field.."); |
|---|
| 69 | | |
|---|
| 70 | | $sql = "SELECT grppre FROM incoming"; |
|---|
| 71 | | $confs = $db->getRow($sql, DB_FETCHMODE_ASSOC); |
|---|
| 72 | | if (!DB::IsError($confs)) { // no error... Already done |
|---|
| 73 | | out("Not Required"); |
|---|
| 74 | | } else { |
|---|
| 75 | | $sql = "ALTER TABLE incoming ADD grppre VARCHAR ( 80 ) NULL"; |
|---|
| 76 | | $results = $db->query($sql); |
|---|
| 77 | | if(DB::IsError($results)) { |
|---|
| 78 | | die($results->getMessage()); |
|---|
| 79 | | } |
|---|
| 80 | | out("Done"); |
|---|
| 81 | | } |
|---|
| 82 | | |
|---|
| 83 | | outn("Upgrading Users/Extension Table to allow for Music on Hold per Direct DID.."); |
|---|
| 84 | | |
|---|
| 85 | | $sql = "SELECT mohclass FROM users"; |
|---|
| 86 | | $confs = $db->getRow($sql, DB_FETCHMODE_ASSOC); |
|---|
| 87 | | if (!DB::IsError($confs)) { // no error... Already done |
|---|
| 88 | | out("Not Required"); |
|---|
| 89 | | } else { |
|---|
| 90 | | $sql = "ALTER TABLE users ADD mohclass VARCHAR ( 80 ) DEFAULT \"default\""; |
|---|
| 91 | | $results = $db->query($sql); |
|---|
| 92 | | if(DB::IsError($results)) { |
|---|
| 93 | | die($results->getMessage()); |
|---|
| 94 | | } |
|---|
| 95 | | out("Done"); |
|---|
| 96 | | } |
|---|
| 97 | | |
|---|
| 98 | | $sql = "SELECT sipname FROM users"; |
|---|
| 99 | | $confs = $db->getRow($sql, DB_FETCHMODE_ASSOC); |
|---|
| 100 | | if (!DB::IsError($confs)) { // no error... Already done |
|---|
| 101 | | out("Not Required"); |
|---|
| 102 | | } else { |
|---|
| 103 | | $sql = "ALTER TABLE users ADD sipname VARCHAR ( 50 ) NULL "; |
|---|
| 104 | | $results = $db->query($sql); |
|---|
| 105 | | if(DB::IsError($results)) { |
|---|
| 106 | | die($results->getMessage()); |
|---|
| 107 | | } |
|---|
| 108 | | out("Done"); |
|---|
| 109 | | } |
|---|
| 110 | | |
|---|
| 111 | | outn("Checking for Global var VMX_CONTEXT.."); |
|---|
| 112 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_CONTEXT'"); |
|---|
| | 3 | outn("Checking for Global var MIXMON_FORMAT.."); |
|---|
| | 4 | $nrows = $db->getOne("SELECT count(*) from globals where variable='MIXMON_FORMAT'"); |
|---|
| 138 | | outn("Checking for Global var VMX_TIMEDEST_EXT.."); |
|---|
| 139 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_TIMEDEST_EXT'"); |
|---|
| 140 | | if (!$nrows) { |
|---|
| 141 | | $db->query("insert into globals values ('VMX_TIMEDEST_EXT', 'dovm')"); |
|---|
| 142 | | out("Created"); |
|---|
| 143 | | } else { |
|---|
| 144 | | out("Already exists!"); |
|---|
| 145 | | } |
|---|
| 146 | | |
|---|
| 147 | | outn("Checking for Global var VMX_TIMEDEST_PRI.."); |
|---|
| 148 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_TIMEDEST_PRI'"); |
|---|
| 149 | | if (!$nrows) { |
|---|
| 150 | | $db->query("insert into globals values ('VMX_TIMEDEST_PRI', '1')"); |
|---|
| 151 | | out("Created"); |
|---|
| 152 | | } else { |
|---|
| 153 | | out("Already exists!"); |
|---|
| 154 | | } |
|---|
| 155 | | |
|---|
| 156 | | outn("Checking for Global var VMX_LOOPDEST_CONTEXT.."); |
|---|
| 157 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_LOOPDEST_CONTEXT'"); |
|---|
| 158 | | if (!$nrows) { |
|---|
| 159 | | $db->query("insert into globals values ('VMX_LOOPDEST_CONTEXT', '')"); |
|---|
| 160 | | out("Created"); |
|---|
| 161 | | } else { |
|---|
| 162 | | out("Already exists!"); |
|---|
| 163 | | } |
|---|
| 164 | | |
|---|
| 165 | | outn("Checking for Global var VMX_LOOPDEST_EXT.."); |
|---|
| 166 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_LOOPDEST_EXT'"); |
|---|
| 167 | | if (!$nrows) { |
|---|
| 168 | | $db->query("insert into globals values ('VMX_LOOPDEST_EXT', 'dovm')"); |
|---|
| 169 | | out("Created"); |
|---|
| 170 | | } else { |
|---|
| 171 | | out("Already exists!"); |
|---|
| 172 | | } |
|---|
| 173 | | |
|---|
| 174 | | outn("Checking for Global var VMX_LOOPDEST_PRI.."); |
|---|
| 175 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_LOOPDEST_PRI'"); |
|---|
| 176 | | if (!$nrows) { |
|---|
| 177 | | $db->query("insert into globals values ('VMX_LOOPDEST_PRI', '1')"); |
|---|
| 178 | | out("Created"); |
|---|
| 179 | | } else { |
|---|
| 180 | | out("Already exists!"); |
|---|
| 181 | | } |
|---|
| 182 | | |
|---|
| 183 | | outn("Checking for Global var VMX_OPTS_TIMEOUT.."); |
|---|
| 184 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_OPTS_TIMEOUT'"); |
|---|
| 185 | | if (!$nrows) { |
|---|
| 186 | | $db->query("insert into globals values ('VMX_OPTS_TIMEOUT', '')"); |
|---|
| 187 | | out("Created"); |
|---|
| 188 | | } else { |
|---|
| 189 | | out("Already exists!"); |
|---|
| 190 | | } |
|---|
| 191 | | |
|---|
| 192 | | outn("Checking for Global var VMX_OPTS_LOOP.."); |
|---|
| 193 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_OPTS_LOOP'"); |
|---|
| 194 | | if (!$nrows) { |
|---|
| 195 | | $db->query("insert into globals values ('VMX_OPTS_LOOP', '')"); |
|---|
| 196 | | out("Created"); |
|---|
| 197 | | } else { |
|---|
| 198 | | out("Already exists!"); |
|---|
| 199 | | } |
|---|
| 200 | | |
|---|
| 201 | | outn("Checking for Global var VMX_OPTS_DOVM.."); |
|---|
| 202 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_OPTS_DOVM'"); |
|---|
| 203 | | if (!$nrows) { |
|---|
| 204 | | $db->query("insert into globals values ('VMX_OPTS_DOVM', '')"); |
|---|
| 205 | | out("Created"); |
|---|
| 206 | | } else { |
|---|
| 207 | | out("Already exists!"); |
|---|
| 208 | | } |
|---|
| 209 | | |
|---|
| 210 | | outn("Checking for Global var VMX_TIMEOUT.."); |
|---|
| 211 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_TIMEOUT'"); |
|---|
| 212 | | if (!$nrows) { |
|---|
| 213 | | $db->query("insert into globals values ('VMX_TIMEOUT', '2')"); |
|---|
| 214 | | out("Created"); |
|---|
| 215 | | } else { |
|---|
| 216 | | out("Already exists!"); |
|---|
| 217 | | } |
|---|
| 218 | | |
|---|
| 219 | | outn("Checking for Global var VMX_REPEAT.."); |
|---|
| 220 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_REPEAT'"); |
|---|
| 221 | | if (!$nrows) { |
|---|
| 222 | | $db->query("insert into globals values ('VMX_REPEAT', '1')"); |
|---|
| 223 | | out("Created"); |
|---|
| 224 | | } else { |
|---|
| 225 | | out("Already exists!"); |
|---|
| 226 | | } |
|---|
| 227 | | |
|---|
| 228 | | outn("Checking for Global var VMX_LOOPS.."); |
|---|
| 229 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_LOOPS'"); |
|---|
| 230 | | if (!$nrows) { |
|---|
| 231 | | $db->query("insert into globals values ('VMX_LOOPS', '1')"); |
|---|
| 232 | | out("Created"); |
|---|
| 233 | | } else { |
|---|
| 234 | | out("Already exists!"); |
|---|
| 235 | | } |
|---|
| 236 | | |
|---|
| 237 | | outn("Checking for Global var TRANSFER_CONTEXT.."); |
|---|
| 238 | | $nrows = $db->getOne("SELECT count(*) from globals where variable='TRANSFER_CONTEXT'"); |
|---|
| 239 | | if (!$nrows) { |
|---|
| 240 | | $db->query("insert into globals values ('TRANSFER_CONTEXT', 'from-internal-xfer')"); |
|---|
| 241 | | out("Created"); |
|---|
| 242 | | } else { |
|---|
| 243 | | out("Already exists!"); |
|---|
| 244 | | } |
|---|
| 245 | | |
|---|
| 246 | | outn("Alter tables incoming to increase field length.. "); |
|---|
| 247 | | $db->query("ALTER TABLE incoming CHANGE alertinfo alertinfo VARCHAR( 255 ) NULL"); |
|---|
| 248 | | out("Altered"); |
|---|
| 249 | | |
|---|
| 250 | | outn("Merging findmefollow and core extension destinations for incoming routes.."); |
|---|
| 251 | | |
|---|
| 252 | | $results = array(); |
|---|
| 253 | | $sql = "SELECT cidnum, extension, destination FROM incoming"; |
|---|
| 254 | | $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); |
|---|
| 255 | | if (DB::IsError($results)) { // error - table must not be there |
|---|
| 256 | | out("Not Required"); |
|---|
| 257 | | } else { |
|---|
| 258 | | foreach ($results as $result) { |
|---|
| 259 | | $old_dest = $result['destination']; |
|---|
| 260 | | $extension = $result['extension']; |
|---|
| 261 | | $cidnum = $result['cidnum']; |
|---|
| 262 | | |
|---|
| 263 | | $new_dest = merge_ext_followme_priv(trim($old_dest)); |
|---|
| 264 | | if ($new_dest != $old_dest) { |
|---|
| 265 | | $sql = "UPDATE incoming SET destination = '$new_dest' WHERE cidnum = '$cidnum' AND extension = '$extension' AND destination = '$old_dest'"; |
|---|
| 266 | | $results = $db->query($sql); |
|---|
| 267 | | if(DB::IsError($results)) { |
|---|
| 268 | | die($results->getMessage()); |
|---|
| 269 | | } |
|---|
| 270 | | } |
|---|
| 271 | | } |
|---|
| 272 | | out("Done"); |
|---|
| 273 | | } |
|---|
| 274 | | |
|---|