| 124 | | list, and/or one per line by hitting enter after every one." |
| 125 | | end |
| 126 | | |
| 127 | | s = m:section(NamedSection, "outgoing_calls", "call_routing", translate("Outgoing Calls"), |
| 128 | | translate(text)) |
| 129 | | s.anonymous = true |
| 130 | | |
| 131 | | m.uci:foreach(googlemodulename, "gtalk_jabber", |
| 132 | | function(s1) |
| 133 | | -- If this provider is valid AND is enabled for outgoing calls, add it to the section. |
| 134 | | if s1.username ~= nil and s1.name ~= nil and |
| 135 | | s1.make_outgoing_calls == "yes" then |
| 136 | | patt = s:option(DynamicList, s1.name, s1.username) |
| 137 | | |
| 138 | | -- If the saved field is empty, we return a string |
| 139 | | -- telling the user that this account would dial any exten. |
| 140 | | function patt.cfgvalue(self, section) |
| 141 | | value = self.map:get(section, self.option) |
| 142 | | |
| 143 | | if value == nil then |
| 144 | | return {"Dials any number"} |
| 145 | | else |
| 146 | | return value |
| 147 | | end |
| 148 | | end |
| 149 | | |
| 150 | | -- Write only valid extensions into the config file. |
| 151 | | function patt.write(self, section, value) |
| 152 | | newvalue = {} |
| 153 | | nindex = 1 |
| 154 | | for index, field in ipairs(value) do |
| 155 | | val = luci.util.trim(value[index]) |
| 156 | | if is_valid_extension(val) == true then |
| 157 | | newvalue[nindex] = val |
| 158 | | nindex = nindex + 1 |
| 159 | | end |
| 160 | | end |
| 161 | | DynamicList.write(self, section, newvalue) |
| 162 | | end |
| 163 | | end |
| 164 | | end) |
| 165 | | |
| 166 | | m.uci:foreach(voipmodulename, "voip_provider", |
| 167 | | function(s1) |
| 168 | | |
| 169 | | -- If this provider is valid AND is enabled for outgoing calls, add it to the section. |
| 170 | | if s1.defaultuser ~= nil and s1.host ~= nil and |
| 171 | | s1.name ~= nil and s1.make_outgoing_calls == "yes" then |
| 172 | | patt = s:option(DynamicList, s1.name, s1.defaultuser .. "@" .. s1.host) |
| 173 | | |
| 174 | | -- If the saved field is empty, we return a string |
| 175 | | -- telling the user that this account would dial any exten. |
| 176 | | function patt.cfgvalue(self, section) |
| 177 | | value = self.map:get(section, self.option) |
| 178 | | |
| 179 | | if value == nil then |
| 180 | | return {"Dials any number"} |
| 181 | | else |
| 182 | | return value |
| 183 | | end |
| 184 | | end |
| 185 | | |
| 186 | | -- Write only valid extensions into the config file. |
| 187 | | function patt.write(self, section, value) |
| 188 | | newvalue = {} |
| 189 | | nindex = 1 |
| 190 | | for index, field in ipairs(value) do |
| 191 | | val = luci.util.trim(value[index]) |
| 192 | | if is_valid_extension(val) == true then |
| 193 | | newvalue[nindex] = val |
| 194 | | nindex = nindex + 1 |
| 195 | | end |
| 196 | | end |
| 197 | | DynamicList.write(self, section, newvalue) |
| 198 | | end |
| 199 | | end |
| 200 | | end) |
| 201 | | |
| 202 | | ---------------------------------------------------------------------------------------------------- |
| 203 | | s = m:section(NamedSection, "incoming_calls", "call_routing", translate("Incoming Calls"), |
| 204 | | translate("For each provider that receives calls, here you can restrict which users to ring \ |
| | 142 | list, and/or one per line by hitting enter after every one.") |
| | 143 | end |
| | 144 | |
| | 145 | |
| | 146 | s = m:section(NamedSection, "outgoing_calls", "call_routing", translate("Outgoing Calls"), text) |
| | 147 | s.anonymous = true |
| | 148 | |
| | 149 | for k,v in pairs(validoutaccounts) do |
| | 150 | patterns = s:option(DynamicList, k, v) |
| | 151 | |
| | 152 | -- If the saved field is empty, we return a string |
| | 153 | -- telling the user that this account would dial any exten. |
| | 154 | function patterns.cfgvalue(self, section) |
| | 155 | value = self.map:get(section, self.option) |
| | 156 | |
| | 157 | if value == nil then |
| | 158 | return {translate("Dials any number")} |
| | 159 | else |
| | 160 | return value |
| | 161 | end |
| | 162 | end |
| | 163 | |
| | 164 | -- Write only valid extensions into the config file. |
| | 165 | function patterns.write(self, section, value) |
| | 166 | newvalue = {} |
| | 167 | nindex = 1 |
| | 168 | for index, field in ipairs(value) do |
| | 169 | val = luci.util.trim(value[index]) |
| | 170 | if is_valid_extension(val) == true then |
| | 171 | newvalue[nindex] = val |
| | 172 | nindex = nindex + 1 |
| | 173 | end |
| | 174 | end |
| | 175 | DynamicList.write(self, section, newvalue) |
| | 176 | end |
| | 177 | end |
| | 178 | |
| | 179 | ---------------------------------------------------------------------------------------------------- |
| | 180 | -- If there are no accounts configured, or no accounts enabled for incoming calls, display a warning. |
| | 181 | -- Otherwise, display the usual help text within the section. |
| | 182 | if nallvalidaccounts == 0 then |
| | 183 | text = translate("NOTE: There are no Google or SIP provider accounts configured.") |
| | 184 | elseif nvalidinaccounts == 0 then |
| | 185 | text = translate("NOTE: There are no Google or SIP provider accounts enabled for incoming calls.") |
| | 186 | else |
| | 187 | text = translate("For each provider that receives calls, here you can restrict which users to ring \ |
| 208 | | incoming calls, so this way, you can make users ring only for select providers. \ |
| 209 | | Entries can be made in a space-separated list, and/or one per \ |
| 210 | | line by hitting enter after every one.")) |
| 211 | | s.anonymous = true |
| 212 | | |
| 213 | | m.uci:foreach(googlemodulename, "gtalk_jabber", |
| 214 | | function(s1) |
| 215 | | if s1.username ~= nil and s1.register == "yes" then |
| 216 | | field_name=string.gsub(s1.username, "%W", "_") |
| 217 | | gtalkaccts = s:option(DynamicList, field_name, s1.username) |
| 218 | | |
| 219 | | -- If the saved field is empty, we return a string |
| 220 | | -- telling the user that this account would dial any exten. |
| 221 | | function gtalkaccts.cfgvalue(self, section) |
| 222 | | value = self.map:get(section, self.option) |
| 223 | | |
| 224 | | if value == nil then |
| 225 | | return {"Rings all users"} |
| 226 | | else |
| 227 | | return value |
| 228 | | end |
| 229 | | end |
| 230 | | |
| 231 | | -- Write only valid user names. |
| 232 | | function gtalkaccts.write(self, section, value) |
| 233 | | newvalue = {} |
| 234 | | nindex = 1 |
| 235 | | for index, field in ipairs(value) do |
| 236 | | trimuser = luci.util.trim(value[index]) |
| 237 | | if allvalidusers[trimuser] == true then |
| 238 | | newvalue[nindex] = trimuser |
| 239 | | nindex = nindex + 1 |
| 240 | | end |
| 241 | | end |
| 242 | | DynamicList.write(self, section, newvalue) |
| 243 | | end |
| 244 | | end |
| 245 | | end) |
| 246 | | |
| 247 | | |
| 248 | | m.uci:foreach(voipmodulename, "voip_provider", |
| 249 | | function(s1) |
| 250 | | if s1.defaultuser ~= nil and s1.host ~= nil and s1.register == "yes" then |
| 251 | | field_name=string.gsub(s1.defaultuser .. "_" .. s1.host, "%W", "_") |
| 252 | | voipaccts = s:option(DynamicList, field_name, s1.defaultuser .. "@" .. s1.host) |
| 253 | | |
| 254 | | -- If the saved field is empty, we return a string |
| 255 | | -- telling the user that this account would dial any exten. |
| 256 | | function voipaccts.cfgvalue(self, section) |
| 257 | | value = self.map:get(section, self.option) |
| 258 | | |
| 259 | | if value == nil then |
| 260 | | return {"Rings all users"} |
| 261 | | else |
| 262 | | return value |
| 263 | | end |
| 264 | | end |
| 265 | | |
| 266 | | -- Write only valid user names. |
| 267 | | function voipaccts.write(self, section, value) |
| 268 | | newvalue = {} |
| 269 | | nindex = 1 |
| 270 | | for index, field in ipairs(value) do |
| 271 | | trimuser = luci.util.trim(value[index]) |
| 272 | | if allvalidusers[trimuser] == true then |
| 273 | | newvalue[nindex] = trimuser |
| 274 | | nindex = nindex + 1 |
| 275 | | end |
| 276 | | end |
| 277 | | DynamicList.write(self, section, newvalue) |
| 278 | | end |
| 279 | | end |
| 280 | | end) |
| 281 | | |
| 282 | | |
| 283 | | ---------------------------------------------------------------------------------------------------- |
| | 191 | incoming calls. This way, you can make certain users ring only for specific providers. \ |
| | 192 | Entries can be made in a space-separated list, and/or one per line by hitting enter after \ |
| | 193 | every one.") |
| | 194 | end |
| | 195 | |
| | 196 | |
| | 197 | s = m:section(NamedSection, "incoming_calls", "call_routing", translate("Incoming Calls"), text) |
| | 198 | s.anonymous = true |
| | 199 | |
| | 200 | for k,v in pairs(validinaccounts) do |
| | 201 | users = s:option(DynamicList, k, v) |
| | 202 | |
| | 203 | -- If the saved field is empty, we return a string |
| | 204 | -- telling the user that this account would dial any exten. |
| | 205 | function users.cfgvalue(self, section) |
| | 206 | value = self.map:get(section, self.option) |
| | 207 | |
| | 208 | if value == nil then |
| | 209 | return {translate("Rings all users enabled for incoming calls")} |
| | 210 | else |
| | 211 | return value |
| | 212 | end |
| | 213 | end |
| | 214 | |
| | 215 | -- Write only valid user names. |
| | 216 | function users.write(self, section, value) |
| | 217 | newvalue = {} |
| | 218 | nindex = 1 |
| | 219 | for index, field in ipairs(value) do |
| | 220 | trimuser = luci.util.trim(value[index]) |
| | 221 | if allvalidusers[trimuser] == true then |
| | 222 | newvalue[nindex] = trimuser |
| | 223 | nindex = nindex + 1 |
| | 224 | end |
| | 225 | end |
| | 226 | DynamicList.write(self, section, newvalue) |
| | 227 | end |
| | 228 | end |
| | 229 | |
| | 230 | |
| | 231 | ---------------------------------------------------------------------------------------------------- |
| | 232 | -- If there are no user accounts configured, no user accounts enabled for outgoing calls, |
| | 233 | -- display a warning. Otherwise, display the usual help text within the section. |
| | 234 | if nallvalidusers == 0 then |
| | 235 | text = translate("NOTE: There are no local user accounts configured.") |
| | 236 | elseif nvalidoutusers == 0 then |
| | 237 | text = translate("NOTE: There are no local user accounts enabled for outgoing calls.") |
| | 238 | else |
| | 239 | text = translate("If you would like, you could restrict which providers users are allowed to use for \ |
| | 240 | outgoing calls. By default all users can use all providers. To show up in the list below the user \ |
| | 241 | should be allowed to make outgoing calls in the \"User Accounts\" page. Enter VoIP providers in the \ |
| | 242 | format username@some.host.name, as listed in \"Outgoing Calls\" above. It's easiest to copy and \ |
| | 243 | paste the providers from above. Invalid entries, including providers not enabled for outgoing \ |
| | 244 | calls, will be rejected silently. Entries can be made in a space-separated list, and/or one per \ |
| | 245 | line by hitting enter after every one.") |
| | 246 | end |
| | 247 | |
| | 248 | |
| 285 | | translate("Providers Used for Outgoing Calls"), |
| 286 | | translate("If you would like, you could restrict which providers users are allowed to use for outgoing \ |
| 287 | | calls. By default all users can use all providers. To show up in the list below the user should \ |
| 288 | | be allowed to make outgoing calls in the \"User Accounts\" page. Enter VoIP providers in the format \ |
| 289 | | username@some.host.name, as listed in \"Outgoing Calls\" above. It's easiest to copy and paste \ |
| 290 | | the providers from above. Invalid entries will be rejected silently. Entries can be made in a \ |
| 291 | | space-separated list, and/or one per line by hitting enter after every one.")) |
| 292 | | s.anonymous = true |
| 293 | | |
| 294 | | m.uci:foreach(usersmodulename, "local_user", |
| 295 | | function(s1) |
| 296 | | -- Add user to list of all valid users. |
| 297 | | if s1.defaultuser ~= nil then allvalidusers[s1.defaultuser] = true end |
| 298 | | |
| 299 | | if s1.defaultuser ~= nil and s1.can_call == "yes" then |
| 300 | | providers = s:option(DynamicList, s1.defaultuser, s1.defaultuser) |
| 301 | | |
| 302 | | -- If the saved field is empty, we return a string |
| 303 | | -- telling the user that this account would dial any exten. |
| 304 | | function providers.cfgvalue(self, section) |
| 305 | | value = self.map:get(section, self.option) |
| 306 | | |
| 307 | | if value == nil then |
| 308 | | return {"Uses all provider accounts"} |
| 309 | | else |
| 310 | | newvalue = {} |
| 311 | | -- Convert internal names to user@host values. |
| 312 | | for i,v in ipairs(value) do |
| 313 | | newvalue[i] = validoutaccounts[v] |
| 314 | | end |
| 315 | | return newvalue |
| 316 | | end |
| 317 | | end |
| 318 | | |
| 319 | | -- Cook the new values prior to entering them into the config file. |
| 320 | | -- Also, enter them only if they are valid. |
| 321 | | function providers.write(self, section, value) |
| 322 | | cookedvalue = {} |
| 323 | | cindex = 1 |
| 324 | | for index, field in ipairs(value) do |
| 325 | | cooked = string.gsub(luci.util.trim(value[index]), "%W", "_") |
| 326 | | if validoutaccounts[cooked] ~= nil then |
| 327 | | cookedvalue[cindex] = cooked |
| 328 | | cindex = cindex + 1 |
| 329 | | end |
| 330 | | end |
| 331 | | DynamicList.write(self, section, cookedvalue) |
| 332 | | end |
| 333 | | end |
| 334 | | end) |
| | 250 | translate("Providers Used for Outgoing Calls"), text) |
| | 251 | s.anonymous = true |
| | 252 | |
| | 253 | for k,v in pairs(validoutusers) do |
| | 254 | providers = s:option(DynamicList, k, k) |
| | 255 | |
| | 256 | -- If the saved field is empty, we return a string |
| | 257 | -- telling the user that this account would dial any exten. |
| | 258 | function providers.cfgvalue(self, section) |
| | 259 | value = self.map:get(section, self.option) |
| | 260 | |
| | 261 | if value == nil then |
| | 262 | return {translate("Uses all providers enabled for outgoing calls")} |
| | 263 | else |
| | 264 | newvalue = {} |
| | 265 | -- Convert internal names to user@host values. |
| | 266 | for i,v in ipairs(value) do |
| | 267 | newvalue[i] = validoutaccounts[v] |
| | 268 | end |
| | 269 | return newvalue |
| | 270 | end |
| | 271 | end |
| | 272 | |
| | 273 | -- Cook the new values prior to entering them into the config file. |
| | 274 | -- Also, enter them only if they are valid. |
| | 275 | function providers.write(self, section, value) |
| | 276 | cookedvalue = {} |
| | 277 | cindex = 1 |
| | 278 | for index, field in ipairs(value) do |
| | 279 | cooked = string.gsub(luci.util.trim(value[index]), "%W", "_") |
| | 280 | if validoutaccounts[cooked] ~= nil then |
| | 281 | cookedvalue[cindex] = cooked |
| | 282 | cindex = cindex + 1 |
| | 283 | end |
| | 284 | end |
| | 285 | DynamicList.write(self, section, cookedvalue) |
| | 286 | end |
| | 287 | end |