Commit ec4d457e by Javier

Commit Inicial

parent 548a2151
venv/ venv/
__pycache__
vendor/
\ No newline at end of file
# Requisitos
El campo destination de la tabla did_destination debe tener un valor por defecto, se ha de ejecutar el comando:
ALTER TABLE mbilling.pkg_did_destination ALTER destination SET default '';
This source diff could not be displayed because it is too large. You can view the blob instead.
MAGNUS_HOST = 'http://192.168.2.56/mbilling'
API_KEY = 'VZvFS9QBDa4WqsIHF1IKChDKOVuy8uzo'
API_SECRET = 'eBy8Cuwc29z490gvmU7BZmpvUWdfehFl'
\ No newline at end of file
<?php
require_once "vendor/autoload.php";
use magnusbilling\api\magnusBilling;
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$magnusBilling = new MagnusBilling($_ENV['API_KEY'], $_ENV['API_SECRET']);
$magnusBilling->public_url = $_ENV['MAGNUS_HOST'];
<?php
include 'api.php';
// ARGUMENTOS : SIP DID
if (isset($argv[1]) && isset($argv[2])) {
$result = $magnusBilling->create('diddestination', [
'id_user' => $magnusBilling->getId('user', 'username', $argv[1]),
'id_sip' => $magnusBilling->getId('sip', 'name', $argv[1]),
'id_did' => $magnusBilling->getId('did', 'DID', $argv[2]),
'voip_call' => '1'
]);
if ($result['success'] == 1) {
print("[201] OK id=" . $result['rows'][0]['id']);
} else {
print_r($result);
print("[409] ERROR Ya existe una cuenta con mismo usuario.");
}
} else {
print("[404] ERROR No se han introducido todos los parámetros necesarios.");
}
{
"require": {
"magnussolution/magnusbilling-api": "^1.3",
"vlucas/phpdotenv": "^5.4"
}
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "0163704399e6cbe10e6f18b5d2dde753",
"packages": [
{
"name": "graham-campbell/result-type",
"version": "v1.0.4",
"source": {
"type": "git",
"url": "https://github.com/GrahamCampbell/Result-Type.git",
"reference": "0690bde05318336c7221785f2a932467f98b64ca"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/0690bde05318336c7221785f2a932467f98b64ca",
"reference": "0690bde05318336c7221785f2a932467f98b64ca",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0",
"phpoption/phpoption": "^1.8"
},
"require-dev": {
"phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.19 || ^9.5.8"
},
"type": "library",
"autoload": {
"psr-4": {
"GrahamCampbell\\ResultType\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
}
],
"description": "An Implementation Of The Result Type",
"keywords": [
"Graham Campbell",
"GrahamCampbell",
"Result Type",
"Result-Type",
"result"
],
"support": {
"issues": "https://github.com/GrahamCampbell/Result-Type/issues",
"source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.0.4"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type",
"type": "tidelift"
}
],
"time": "2021-11-21T21:41:47+00:00"
},
{
"name": "magnussolution/magnusbilling-api",
"version": "1.3",
"source": {
"type": "git",
"url": "https://github.com/magnussolution/magnusbilling-api-php.git",
"reference": "ee820c8696ea1c547db8ab6c79d97433df54e307"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/magnussolution/magnusbilling-api-php/zipball/ee820c8696ea1c547db8ab6c79d97433df54e307",
"reference": "ee820c8696ea1c547db8ab6c79d97433df54e307",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"type": "library",
"autoload": {
"psr-4": {
"magnusbilling\\api\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Adilson Magnus",
"email": "info@magnussolution.com",
"homepage": "https://magnussolution.com",
"role": "Development"
}
],
"description": "PHP wrapper for the MagnusBilling API.",
"support": {
"issues": "https://github.com/magnussolution/magnusbilling-api-php/issues",
"source": "https://github.com/magnussolution/magnusbilling-api-php/tree/1.3"
},
"time": "2021-12-09T20:47:16+00:00"
},
{
"name": "phpoption/phpoption",
"version": "1.8.1",
"source": {
"type": "git",
"url": "https://github.com/schmittjoh/php-option.git",
"reference": "eab7a0df01fe2344d172bff4cd6dbd3f8b84ad15"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/schmittjoh/php-option/zipball/eab7a0df01fe2344d172bff4cd6dbd3f8b84ad15",
"reference": "eab7a0df01fe2344d172bff4cd6dbd3f8b84ad15",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.19 || ^9.5.8"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.8-dev"
}
},
"autoload": {
"psr-4": {
"PhpOption\\": "src/PhpOption/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Johannes M. Schmitt",
"email": "schmittjoh@gmail.com",
"homepage": "https://github.com/schmittjoh"
},
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
}
],
"description": "Option Type for PHP",
"keywords": [
"language",
"option",
"php",
"type"
],
"support": {
"issues": "https://github.com/schmittjoh/php-option/issues",
"source": "https://github.com/schmittjoh/php-option/tree/1.8.1"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption",
"type": "tidelift"
}
],
"time": "2021-12-04T23:24:31+00:00"
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "30885182c981ab175d4d034db0f6f469898070ab"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab",
"reference": "30885182c981ab175d4d034db0f6f469898070ab",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"provide": {
"ext-ctype": "*"
},
"suggest": {
"ext-ctype": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.23-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Ctype\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Gert de Pagter",
"email": "BackEndTea@gmail.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for ctype functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"ctype",
"polyfill",
"portable"
],
"support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.24.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-10-20T20:35:02+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825",
"reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"provide": {
"ext-mbstring": "*"
},
"suggest": {
"ext-mbstring": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.23-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Mbstring\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for the Mbstring extension",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"mbstring",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.24.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-11-30T18:21:41+00:00"
},
{
"name": "symfony/polyfill-php80",
"version": "v1.24.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php80.git",
"reference": "57b712b08eddb97c762a8caa32c84e037892d2e9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/57b712b08eddb97c762a8caa32c84e037892d2e9",
"reference": "57b712b08eddb97c762a8caa32c84e037892d2e9",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.23-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Php80\\": ""
},
"files": [
"bootstrap.php"
],
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ion Bazan",
"email": "ion.bazan@gmail.com"
},
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php80/tree/v1.24.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-09-13T13:58:33+00:00"
},
{
"name": "vlucas/phpdotenv",
"version": "v5.4.1",
"source": {
"type": "git",
"url": "https://github.com/vlucas/phpdotenv.git",
"reference": "264dce589e7ce37a7ba99cb901eed8249fbec92f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/264dce589e7ce37a7ba99cb901eed8249fbec92f",
"reference": "264dce589e7ce37a7ba99cb901eed8249fbec92f",
"shasum": ""
},
"require": {
"ext-pcre": "*",
"graham-campbell/result-type": "^1.0.2",
"php": "^7.1.3 || ^8.0",
"phpoption/phpoption": "^1.8",
"symfony/polyfill-ctype": "^1.23",
"symfony/polyfill-mbstring": "^1.23.1",
"symfony/polyfill-php80": "^1.23.1"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"ext-filter": "*",
"phpunit/phpunit": "^7.5.20 || ^8.5.21 || ^9.5.10"
},
"suggest": {
"ext-filter": "Required to use the boolean validator."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.4-dev"
}
},
"autoload": {
"psr-4": {
"Dotenv\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk",
"homepage": "https://github.com/GrahamCampbell"
},
{
"name": "Vance Lucas",
"email": "vance@vancelucas.com",
"homepage": "https://github.com/vlucas"
}
],
"description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.",
"keywords": [
"dotenv",
"env",
"environment"
],
"support": {
"issues": "https://github.com/vlucas/phpdotenv/issues",
"source": "https://github.com/vlucas/phpdotenv/tree/v5.4.1"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv",
"type": "tidelift"
}
],
"time": "2021-12-12T23:22:04+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.2.0"
}
<?php
include 'api.php';
// ARGUMENTOS: DID
if (isset($argv[1])) {
$result = $magnusBilling->create('did', [
"did" => $argv[1],
]);
if ($result['success'] == 1) {
print("[201] OK id=" . $result['rows'][0]['id']);
} else {
print("[409] ERROR Ya existe una cuenta con mismo usuario.");
}
} else {
print("[404] ERROR No se han introducido todos los parámetros necesarios.");
}
<?php
include 'api.php';
// ARGUMENTOS : USERNAME PASSWORD NOMBRE APELLIDOS
if (isset($argv[1]) && isset($argv[2]) && isset($argv[3]) && isset($argv[4])) {
$result = $magnusBilling->create('user', [
'username' => $argv[1],
'password' => $argv[2] . strval(rand(100, 999)),
'active' => '1',
'firstname' => strtoupper($argv[3]),
'lastname' => strtoupper($argv[4]),
'callingcard_pin' => strval(rand(1000, 9999)),
'id_group' => 3,
'id_plan' => 1,
'credit' => 0,
]);
if ($result['success'] == 1) {
print("[201] OK id=". $result['rows'][0]['id']);
} else {
print("[409] ERROR Ya existe una cuenta con mismo usuario.");
}
} else {
print("[404] ERROR No se han introducido todos los parámetros necesarios.");
}
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
rows: {"id":0,"id_user":14,"name":"","accountcode":"","regexten":"","amaflags":"","callgroup":"","callerid":"564123789","directmedia":"no","context":"billing","DEFAULTip":"","dtmfmode":"RFC2833","fromuser":"","fromdomain":"","host":"dynamic","sip_group":"","insecure":"no","language":"","mailbox":"","md5secret":"","nat":"force_rport,comedia","deny":"","permit":"","pickupgroup":"","port":"","qualify":"no","rtptimeout":"","rtpholdtimeout":"","secret":"rentel123","type":"friend","disallow":"all","allow":"g729,gsm,opus,alaw,ulaw","regseconds":null,"ipaddr":"","fullcontact":"","setvar":"","regserver":"","lastms":"","defaultuser":"564123789","auth":"","subscribemwi":"","vmexten":"","cid_number":"","callingpres":"","usereqphone":"","mohsuggest":"","allowtransfer":"no","autoframing":"","maxcallbitrate":"","outboundproxy":"","rtpkeepalive":"","useragent":"","calllimit":0,"lineStatus":"","url_events":"","ringfalse":0,"record_call":0,"voicemail":0,"forward":"","block_call_reg":"","dial_timeout":60,"techprefix":0,"alias":"","addparameter":"","amd":0,"videosupport":"no","type_forward":"","id_ivr":"","id_queue":"","id_sip":"","extension":"","voicemail_email":"","voicemail_password":692889,"sipshowpeer":""}
\ No newline at end of file
...@@ -3,62 +3,236 @@ from selenium.webdriver.firefox.options import Options as FirefoxOptions ...@@ -3,62 +3,236 @@ from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException from selenium.common.exceptions import TimeoutException, ElementNotInteractableException
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.action_chains import ActionChains
import mariadb
from enum import Enum from enum import Enum
import time import time
magnus = "http://192.168.2.56/mbilling/" magnus = "http://192.168.2.56/mbilling/"
login = { login = {
'user' : 'root', 'user': 'root',
'password' : 'NgtAtONgeRaFtsbu', 'password': 'NgtAtONgeRaFtsbu',
}
db_login = {
"user": "scripts",
"password": "scripts",
"host": "192.168.2.84",
"port": 3306,
"database": "mbilling"
} }
class DuplicateNumberError(Exception):
pass
class MagnusBillingError(Exception):
pass
class UserNotFoundError(Exception):
pass
class Tarifa(Enum): class Tarifa(Enum):
ESTANDAR = 'Tarifa Estándar' ESTANDAR = 'Tarifa Estándar'
EMPRESA = 'Tarifa Empresas' EMPRESA = 'Tarifa Empresas'
PLANA1000 = 'Bono PTV' PLANA1000 = 'Bono PTV'
PLANA2000 = 'Bono PTV' PLANA2000 = 'Bono PTV'
def authenticate(driver : webdriver.Firefox):
def authenticate(driver: webdriver.Firefox):
driver.get(magnus) driver.get(magnus)
WebDriverWait(driver,3).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="textfield-1013-inputEl"]'))).send_keys(login['user']) WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
driver.find_element(By.XPATH,'//*[@id="textfield-1014-inputEl"]').send_keys(login['password'], Keys.ENTER) (By.XPATH, '//*[@id="textfield-1013-inputEl"]'))).send_keys(login['user'])
driver.find_element(
By.XPATH, '//*[@id="textfield-1014-inputEl"]').send_keys(login['password'], Keys.ENTER)
try: try:
WebDriverWait(driver,5).until(EC.element_to_be_clickable((By.XPATH, ' //*[@id="tool-1031-toolEl"]'))).click() WebDriverWait(driver, 5).until(EC.element_to_be_clickable(
(By.XPATH, ' //*[@id="tool-1031-toolEl"]'))).click()
except TimeoutException: except TimeoutException:
pass pass
def add_new_user(driver : webdriver.Firefox, telefono : str, tarifa : Tarifa = Tarifa.ESTANDAR):
def new_user(driver: webdriver.Firefox, telefono: str, titular: str, password: str = None, tarifa: Tarifa = Tarifa.ESTANDAR):
# Acceso a Panel # Acceso a Panel
WebDriverWait(driver,3).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="treeview-1176-record-10"]'))).click() WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
WebDriverWait(driver,3).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="button-1270"]'))).click() (By.XPATH, '//*[@id="treeview-1176-record-10"]'))).click()
WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH, '//*[@id="button-1270"]'))).click()
# Usuario # Usuario y Comntraseña
username = WebDriverWait(driver,3).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="textfield-1291-inputEl"]'))) username = WebDriverWait(driver, 3).until(
EC.element_to_be_clickable((By.XPATH, '//input[@name="username"]')))
username.clear() username.clear()
username.send_keys(telefono) username.send_keys(telefono)
driver.find_element(By.XPATH, '//*[@id="groupusercombo-1293-trigger-picker"]').click()
driver.find_element(By.XPATH, '//ul[@data-ref="listEl"]/li[text()="Cliente"]').click() if password:
password_field = driver.find_element(
By.XPATH, '//input[@name="password"]')
password_field.clear()
password_field.send_keys(password)
# Cambio de Panel
driver.find_element(
By.XPATH, '//*[@id="groupusercombo-1293-trigger-picker"]').click()
driver.find_element(
By.XPATH, '//ul[@data-ref="listEl"]/li[text()="Cliente"]').click()
# Tarifa # Tarifa
driver.find_element(By.XPATH, '//*[@id="button-1297"]').click() driver.find_element(By.XPATH, '//*[@id="button-1297"]').click()
tarifa = WebDriverWait(driver,3).until(EC.element_to_be_clickable( tarifa = WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH, f'//*[contains(@id,"tableview")]//table//div[text()="{tarifa.value}"]')) (By.XPATH, f'/html/body/div/div/div/div/div/div/div/div/table/tbody/tr/td/div[text()="{tarifa.value}"]'))
) )
ActionChains(driver).double_click(tarifa).perform() ActionChains(driver).double_click(tarifa).perform()
driver.find_element(By.XPATH, '//*[@id="button-1403"]').click()
# Datos Personales # Datos Personales
driver.find_element(By.XPATH, '//*[@id="tab-1357-btnInnerEl"]').click() driver.find_element(
By.XPATH, ' //span[text()="Información personal"]').click()
WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH, '//input[@name="lastname"]'))).send_keys(titular)
WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH, '//input[@name="firstname"]'))).send_keys(titular)
# Guardar Datos
driver.find_element(By.XPATH, '//span[text()="Salvar"]').click()
try:
driver.find_element(By.XPATH, '//span[text()="Cancelar"]').click()
except ElementNotInteractableException:
pass
# Comprobar Mensaje de Error
try:
error = WebDriverWait(driver, 2).until(EC.element_to_be_clickable(
(By.XPATH, '//table[@class="alert-error"]//p[@style="font-size: 13px;"]')))
raise DuplicateNumberError(error.text)
except TimeoutException:
pass
def balance_recharge(driver: webdriver.Firefox, phone: str, recharge: float = 10.00, tax_include: bool = False):
"""Recarga la Cantidad de Saldo
"""
try:
WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH, '//span[contains(text(), "Recargas")]')
)).click()
except TimeoutException:
WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH, '//div[contains(text(), "Financiero")]')
)).click()
return balance_recharge(driver, phone, recharge, tax_include)
WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH, '//span[contains(text(), "Nuevo")]')
)).click()
WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH, '//span[contains(text(), "Buscar")]')
)).click()
search = WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH,
'//div[@role="dialog"]//input[@placeholder="Buscar username"]')
))
ActionChains(driver).click(search).send_keys(
phone).send_keys(Keys.ENTER).perform()
WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH,
'//div[@role="dialog"]//div[@class="x-grid-cell-inner "]')
)).click()
def create_sip_account(driver: webdriver.Firefox, username: str, phone: str, pbx_address: str = None):
"""Genera las cuentas SIP del Usuario
"""
try:
WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH, '//span[contains(text(), "Cuentas SIP")]')
)).click()
except TimeoutException:
WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH, '//div[contains(text(), "Clientes")]')
)).click()
return balance_recharge(driver, phone, pbx_address)
WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(By.XPATH, '//input[@placeholder="Buscar name"]')
)).send_keys(phone, Keys.ENTER)
try:
WebDriverWait(driver, 1).until(EC.element_to_be_clickable(
(By.XPATH, f'//div[text() = "{phone}"]')
)).click()
except TimeoutException:
WebDriverWait(driver, 1).until(EC.element_to_be_clickable(
(By.XPATH, f'//span[text() = "Nuevo"]')
)).click()
# Selección de Usuario
driver.find_element(By.XPATH, '//span[text()="Buscar"]').click()
driver.find_element(
By.XPATH, '//div[@role="dialog"]//input[@placeholder="Buscar username"]').send_keys(
username, Keys.ENTER
)
try:
user = WebDriverWait(driver, 1).until(EC.element_to_be_clickable(
(By.XPATH, f'//div[@role="dialog"]//tr[@class=" x-grid-row"]')
))
ActionChains(driver).move_to_element(user).double_click().perform()
except TimeoutException:
raise UserNotFoundError()
# SIP User
# Caller ID
caller_id = driver.find_element(By.XPATH, '//input[@name="callerid"]')
if len(caller_id.text) == 0:
caller_id.send_keys(phone, Keys.ENTER)
# Secret
secret = driver.find_element(By.XPATH, '//input[@name="callerid"]')
if len(secret.text) == 0:
secret.send_keys(username, Keys.ENTER)
def user_exists(telefono: str) -> dict:
with mariadb.connect(**db_login) as cnx:
with cnx.cursor() as cursor:
cursor.execute(
'SELECT * FROM mbilling.pkg_sip WHERE name=?;',
(telefono,)
)
exists = cursor.fetchone() is not None
return exists
if __name__ == '__main__': if __name__ == '__main__':
options = FirefoxOptions() options = FirefoxOptions()
#options.add_argument("--headless") # options.add_argument("--headless")
driver = webdriver.Firefox(options=options) driver = webdriver.Firefox(options=options)
authenticate(driver) authenticate(driver)
add_new_user(driver, '956367300') create_sip_account(driver, '856135158', '856135158')
\ No newline at end of file
rows=%7B%22id%22%3A0%2C%22id_group%22%3A3%2C%22id_plan%22%3A1%2C%22id_user%22%3A0%2C%22id_offer%22%3A0%2C%22username%22%3A%22test%22%2C%22password%22%3A%222uQqJH8F%22%2C%22active%22%3A1%2C%22credit%22%3A0%2C%22enableexpire%22%3A0%2C%22expiredays%22%3A0%2C%22status%22%3A0%2C%22typepaid%22%3A0%2C%22creditlimit%22%3A0%2C%22credit_notification%22%3A-1%2C%22restriction%22%3A0%2C%22callingcard_pin%22%3A891457%2C%22callshop%22%3A0%2C%22plan_day%22%3A0%2C%22active_paypal%22%3A0%2C%22boleto%22%3A0%2C%22lastname%22%3A%22TEST%22%2C%22firstname%22%3A%22TEST%22%2C%22redial%22%3A%22%22%2C%22tag%22%3A%22%22%2C%22company_name%22%3A%22%22%2C%22commercial_name%22%3A%22%22%2C%22address%22%3A%22%22%2C%22city%22%3A%22%22%2C%22state%22%3A%22%22%2C%22country%22%3A%221%22%2C%22loginkey%22%3A%22%22%2C%22zipcode%22%3A%22%22%2C%22phone%22%3A%22%22%2C%22mobile%22%3A%22%22%2C%22email%22%3A%22%22%2C%22doc%22%3A%22%22%2C%22vat%22%3A%22%22%2C%22language%22%3A%22es%22%2C%22company_website%22%3A%22%22%2C%22prefix_local%22%3A%22%22%2C%22boleto_day%22%3A0%2C%22firstusedate%22%3Anull%2C%22expirationdate%22%3Anull%2C%22lastuse%22%3Anull%2C%22description%22%3A%22%22%2C%22creationdate%22%3Anull%2C%22id_group_agent%22%3A0%2C%22calllimit%22%3A-1%2C%22mix_monitor_format%22%3A%22gsm%22%2C%22disk_space%22%3A-1%2C%22sipaccountlimit%22%3A-1%2C%22cpslimit%22%3A-1%2C%22state_number%22%3A%22%22%2C%22neighborhood%22%3A%22%22%2C%22calllimit_error%22%3A%22503%22%2C%22transfer_international%22%3A0%2C%22transfer_international_profit%22%3Anull%2C%22transfer_flexiload%22%3A0%2C%22transfer_flexiload_profit%22%3Anull%2C%22transfer_bkash%22%3A0%2C%22transfer_bkash_profit%22%3Anull%2C%22transfer_dbbl_rocket%22%3A0%2C%22transfer_dbbl_rocket_profit%22%3Anull%2C%22transfer_bdservice_rate%22%3Anull%2C%22transfer_show_selling_price%22%3Anull%7D
\ No newline at end of file
Access denied to canCreate in module: user
\ No newline at end of file
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