Commit ec4d457e by Javier

Commit Inicial

parent 548a2151
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"
}
}
<?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
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
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.action_chains import ActionChains
import mariadb
from enum import Enum
import time
magnus = "http://192.168.2.56/mbilling/"
login = {
'user' : 'root',
'password' : 'NgtAtONgeRaFtsbu',
'user': 'root',
'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):
ESTANDAR = 'Tarifa Estándar'
EMPRESA = 'Tarifa Empresas'
PLANA1000 = 'Bono PTV'
PLANA2000 = 'Bono PTV'
def authenticate(driver : webdriver.Firefox):
def authenticate(driver: webdriver.Firefox):
driver.get(magnus)
WebDriverWait(driver,3).until(EC.element_to_be_clickable((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)
WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(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:
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:
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
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((By.XPATH, '//*[@id="button-1270"]'))).click()
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(
(By.XPATH, '//*[@id="button-1270"]'))).click()
# Usuario
username = WebDriverWait(driver,3).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="textfield-1291-inputEl"]')))
# Usuario y Comntraseña
username = WebDriverWait(driver, 3).until(
EC.element_to_be_clickable((By.XPATH, '//input[@name="username"]')))
username.clear()
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
driver.find_element(By.XPATH, '//*[@id="button-1297"]').click()
tarifa = WebDriverWait(driver,3).until(EC.element_to_be_clickable(
(By.XPATH, f'//*[contains(@id,"tableview")]//table//div[text()="{tarifa.value}"]'))
tarifa = WebDriverWait(driver, 3).until(EC.element_to_be_clickable(
(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()
driver.find_element(By.XPATH, '//*[@id="button-1403"]').click()
# 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__':
options = FirefoxOptions()
#options.add_argument("--headless")
# options.add_argument("--headless")
driver = webdriver.Firefox(options=options)
authenticate(driver)
add_new_user(driver, '956367300')
\ No newline at end of file
create_sip_account(driver, '856135158', '856135158')
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