From 60028763431a3d89e8e515c20a3a9102c25f56e2 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Mon, 6 May 2024 13:24:25 +0200 Subject: [PATCH] WIP Ivt Import 2024-05-02 --- Layout/default/Admin/IvtContractImport.php | 154 ++-- application/Address/Address.php | 8 +- application/Admin/AdminController.php | 6 +- .../Admin/functions/IvtContractImport.php | 762 +++++++++++------- application/Contract/Contract.php | 57 +- .../ContractconfigItem/ContractconfigItem.php | 2 +- .../IvtCustomerProductModel.php | 18 +- .../IvtCustomerTelephoneNr.php | 67 ++ .../IvtCustomerTelephoneNrModel.php | 115 +++ application/Order/Order.php | 2 +- application/Order/OrderController.php | 1 - .../Voicenumberblock/Voicenumberblock.php | 18 +- .../XinonFibuMerge/XinonFibuMergeModel.php | 27 +- lib/RadiusDB/Client.php | 78 ++ lib/RadiusDB/Nas.php | 69 ++ lib/RadiusDB/User.php | 275 +++++++ lib/RadiusDB/UserInfo.php | 43 + 17 files changed, 1298 insertions(+), 404 deletions(-) create mode 100644 application/IvtCustomerTelephoneNr/IvtCustomerTelephoneNr.php create mode 100644 application/IvtCustomerTelephoneNr/IvtCustomerTelephoneNrModel.php create mode 100644 lib/RadiusDB/Client.php create mode 100644 lib/RadiusDB/Nas.php create mode 100644 lib/RadiusDB/User.php create mode 100644 lib/RadiusDB/UserInfo.php diff --git a/Layout/default/Admin/IvtContractImport.php b/Layout/default/Admin/IvtContractImport.php index 1e69bbcc2..2e9a31d08 100644 --- a/Layout/default/Admin/IvtContractImport.php +++ b/Layout/default/Admin/IvtContractImport.php @@ -1,79 +1,103 @@ - - +
-
-
-
- -
-

IVT Import

+
+
+
+ +
+

IVT Import

+
-
- +
-
- - -
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
KundeIVT ProduktProduktPreis SetupPreisRech. IntervalAktion
getCompanyOrName()?>name?>name?>price_setup?>price?> - billing_period?> (billing_period == 1) ? "Monatlich" : ""?>billing_period == 12) ? "Jährlich" : ""?>billing_period == 24) ? "Zweijährlich" : ""?>billing_period == 36) ? "Dreijährlich" : ""?>) -
- -
- 1])?>"> +
+ + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
KundeIVT KundeIVT ProduktProduktPreis SetupPreisRech. IntervalHerstellungsd.AktionBestellung
getCompanyOrName()?> + (customer_number?>) + id?>name?>name?>price_setup?>price?> + billing_period?> + ( + billing_period == 1) ? "Monatlich" : ""?> + billing_period == 12) ? "Jährlich" : ""?> + billing_period == 24) ? "Zweijährlich" : ""?> + billing_period == 36) ? "Dreijährlich" : ""?> + ) + finish_date)?> + order_id): ?> + $d["orderproduct"]->order_id])?>" target="_blank">order_id?> + +
+ + + +
+
- -
-
-
- + - \ No newline at end of file + \ No newline at end of file diff --git a/application/Address/Address.php b/application/Address/Address.php index ea834c6ae..2d612b4d5 100644 --- a/application/Address/Address.php +++ b/application/Address/Address.php @@ -78,7 +78,12 @@ class Address extends mfBaseModel { $name_search = []; if($this->company) $name_search[] = $this->company; if($this->lastname) $name_search[] = $this->lastname; - + + $country = new Country($this->country_id); + if(!$country) { + return false; + } + $fibumerge = XinonFibuMergeModel::getFirst(["old_custnum" => $old_custnum, "name" => $name_search]); if(!$fibumerge) { // create fibu merge @@ -91,6 +96,7 @@ class Address extends mfBaseModel { "strasse" => $this->street, "plz" => $this->zip, "ort" => $this->city, + "land" => $country->isocode, "create_by" => 1, "edit_by" => 1 ]); diff --git a/application/Admin/AdminController.php b/application/Admin/AdminController.php index 7d9acd6bb..65cac0c1b 100644 --- a/application/Admin/AdminController.php +++ b/application/Admin/AdminController.php @@ -127,7 +127,7 @@ class AdminController extends mfBaseController { $products = []; foreach($ivtproducts as $product) { - $active_count = IvtCustomerProductModel::count(['pid' => $product->id]); + $active_count = IvtCustomerTelephoneNrModel::count(['pid' => $product->id]); if(!$active_count) continue; $new_product = []; @@ -136,7 +136,7 @@ class AdminController extends mfBaseController { $new_product["customer"] = false; if($active_count == 1) { - $cp = IvtCustomerProductModel::getFirst(["pid" => $product->id]); + $cp = IvtCustomerTelephoneNrModel::getFirst(["pid" => $product->id]); //var_dump($cp);exit; $customer = $cp->customer; //var_dump($customer);exit; @@ -151,7 +151,7 @@ class AdminController extends mfBaseController { } protected function ivtContractImportAction() { - exit; + //exit; $doit = false; if($this->request->doit == 1) { $doit = true; diff --git a/application/Admin/functions/IvtContractImport.php b/application/Admin/functions/IvtContractImport.php index 5cf184fec..f95854e7b 100644 --- a/application/Admin/functions/IvtContractImport.php +++ b/application/Admin/functions/IvtContractImport.php @@ -1,305 +1,485 @@ request = $request; - } - - public function run($doit = false) { - echo "running...
\n"; - $data = []; - $data['ignore'] = 0; - $data["contracts"] = []; - foreach(IvtCustomerProductModel::getAll() as $ivt_contract) { - $ivt_customer = $ivt_contract->customer; - $ivt_product = $ivt_contract->product; - - if(!$this->checkIvtCustomer($ivt_customer)) { - echo "IVT Customer ".$ivt_contract->cid." nicht im tool
\n"; + private $request; + private $log; + + public function __construct($request) { + $this->request = $request; + $this->log = mfLoghandler::singleton(); + } + + public function run($doit = false) { + echo "running...
\n"; + $data = []; + $data['ignore'] = 0; + $data["contracts"] = []; + $i = 0; + foreach(IvtCustomerTelephoneNrModel::getAll("cid") as $ivt_contract) { + if($i > 100) break; + $i++; + $neu = []; + $orderproduct = false; + $orderproduct_id = false; + + $ivt_customer = $ivt_contract->customer; + $ivt_product = $ivt_contract->product; + + if(!$this->checkIvtCustomer($ivt_customer)) { + echo "IVT Customer " . $ivt_contract->cid . " nicht im tool
\n"; + exit; + } + + $productMatch = IvtProductMatchModel::getFirst(["ivt_product_id" => $ivt_contract->pid]); + if(!$productMatch) { + echo "Kein Match zu IVT Product " . $ivt_contract->pid . " gefunden.
\n"; + exit; + } + + + if(!$this->checkIvtProduct($productMatch->ivtproduct, $doit)) { + exit; + } + + $customer = AddressModel::getFirst(["customer_number" => $ivt_contract->cid]); + /*if($ivt_contract->id == 3035) { + var_dump($ivt_contract->cid, $customer); + }*/ + + if(!$customer) { + $this->log->debug("Kein thetool Kunde zu IVT customer " . $ivt_contract->cid . " gefunden -> wird angelegt"); + $customer = $this->createAddressFromIvtCustomer($ivt_contract->customer); + if(!$customer) { + echo "Fehler beim anlegen der Adresse
\n"; + exit; + } + } + + $ip = $productMatch->ivtproduct; + $product = $productMatch->product; + /* + // check if contract was imported already + $existing_contract = ContractModel::getFirst(["imported_from" => "ivt", "imported_data" => $ivt_contract->id]); + if($existing_contract) { + //echo "Contract gibts schon ".$existing_contract->id."
\n"; + continue; + } + */ + + + + $finish_date = new DateTime($ivt_contract->created); + $finish_date->modify("+2 hours"); + + + $contract_data = []; + $contract_data['owner_id'] = $customer->id; + $contract_data['billingaddress_id'] = $customer->id; + $contract_data['product_id'] = $product->id; + $contract_data['product_name'] = $ip->name; + $contract_data['amount'] = 1; + $contract_data['price'] = $ip->price; + $contract_data['price_setup'] = 0; + $contract_data['price_nne'] = 0; + $contract_data['price_nbe'] = 0; + $contract_data['finish_date'] = $finish_date->getTimestamp(); + $contract_data['finish_date_by'] = 1; + $contract_data['imported_from'] = "ivt"; + $contract_data['imported_data'] = $ivt_contract->id; + + switch($ip->interval) { + case 0: + $contract_data['billing_period'] = 1; + break; + case 1: + $contract_data['billing_period'] = 12; + break; + } + + + $neu["customer"] = $customer; + $neu["ivtcustomer"] = $ivt_customer; + $neu["ivtproduct"] = $ip; + $neu["product"] = $product; + $neu["orderproduct"] = false; + $neu['action'] = "import"; + $ignore = false; + + if($product->price <= 0) { + $contract_data['price'] = 0; + $contract_data['price_setup'] = $ip->price; + $contract_data['billing_period'] = 0; + $neu['action'] = "ignore"; + $ignore = true; + } + + // find thetool Order + $order = OrderModel::getFirst(["owner_id" => $customer->id]); + /*if($ivt_contract->id == 3035) { + var_dump($order); + }*/ + + /*if($ivt_contract->id == 3035) { + var_dump($order);exit; + }*/ + + if($order) { + foreach($order->products as $orderproduct) { + if($orderproduct->product_id == $product->id) { + $orderproduct_id = $orderproduct->id; + } + } + if($orderproduct_id) { + $contract_data["orderproduct_id"] = $orderproduct->id; + $neu["orderproduct"] = $orderproduct; + } else { + $this->log->debug("Kein Orderproduct gefunden in Order ".$order->id." für Ivt customer_product ".$ivt_contract->id); + } + } else { + //$this->log->debug("Keine thetool order für ivt customer_product ".$ivt_contract->id); + } + /*if($ivt_contract->id == 3035) { + var_dump($order, $orderproduct); + }*/ + $contract = ContractModel::create($contract_data); + $contract->matchcode = $contract->generateMatchcode(); + /*if($ivt_contract->id == 3035) { + var_dump($contract); + }*/ + $neu["contract"] = $contract; + + if($doit && !$ignore) { + $contract_id = $contract->save(); + if(!$contract_id) { + echo "Fehler beim Contract speichern!
\n"; + exit; + } + + + // create journal entry + $journal = ContractjournalModel::create([ + 'contract_id' => $contract_id, + 'type' => "created_from", + 'value' => "import", + 'text' => "IVT" + ]); + $journal_id = $journal->save(); + if(!$journal_id) { + echo "Fehler beim Journal erstellen.
\n"; + exit; + } + + // import Contractconfig + + } + $contractconfig = $this->importContractconfig($ivt_customer, $ivt_product, $contract, ($doit && !$ignore)); + var_dump($contractconfig);exit; + + $data["contracts"][] = $neu; + if($neu['action'] == "ignore") { + $data['ignore']++; + } + + /*if($ivt_contract->id == 3035) { + var_dump($neu);exit; + }*/ + } + return $data; + } + + private function checkIvtCustomer($ivt_customer, $doit = false) { + $return = []; + // create customer if not exists + $ivt_custnum = $ivt_customer->id; + if(!$ivt_custnum) return false; + + // sync billing address + $owner = AddressModel::getFirst(["customer_number" => $ivt_custnum]); + if(!$owner) { + die("Address $ivt_custnum not found!"); + } + + // find order + $order_count = OrderModel::count(["owner_id" => $owner->id, "finish_date" => true]); + if($order_count > 1) { + die("Mehr als eine Bestellung für ivt_customer $ivt_custnum gefunden.\n".print_r($owner, true)); + } + $order = OrderModel::getFirst(["owner_id" => $owner->id, "finish_date" => true]); + if(!$order) { + $this->log->debug(__METHOD__.": No order for ivt customer $ivt_custnum"); + return true; + } + + // look for billingaddress_id in order and use it + if($order->billingaddress_id) { + if($order->billingaddress_id == $ivt_custnum) { + $return["billingaddress_id"] = $order->billingaddress_id; + } else { + $billingaddress = new Address($order->billingaddress_id); + if(!$billingaddress->id) { + die("Billingaddress " . $order->billingaddress_id . " does not exist (order " . $order->id . "; ivt customer $ivt_custnum)"); + } + $return["billingaddress_id"] = $billingaddress->id; + } + } + + // if no billingaddress_id in order, compare address of Address and ivt_customer and + // create new billingaddress if nessecary + + $new_billing = []; + foreach(["company", "firstname", "lastname", "street", "zip", "city", "phone", "email", "uid", "billing_type", "billing_delivery", + "bank_account_bank", "bank_account_owner", "bank_account_iban", "bank_account_bic"] as $field) { + $new_billing[$field] = $owner->$field; + } + + if($ivt_customer->company) { + if($ivt_customer->company != $owner->company) $new_billing["company"] = $ivt_customer->company; + } else { + if($ivt_customer->firstname != $owner->firstname) $new_billing["firstname"] = $ivt_customer->firstname; + if($ivt_customer->surname != $owner->lastname) $new_billing["lastname"] = $ivt_customer->surname; + } + + if($ivt_customer->UID != $owner->uid) $new_billing["uid"] = $ivt_customer->UID; + if($ivt_customer->zip != $owner->zip) $new_billing["zip"] = $ivt_customer->zip; + if($ivt_customer->location != $owner->city) $new_billing["city"] = $ivt_customer->location; + if($ivt_customer->street." ".$ivt_customer->housenumber != $owner->street) $new_billing["street"] = $ivt_customer->street." ".$ivt_customer->housenumber; + if($ivt_customer->phone != $owner->phone) $new_billing["phone"] = $ivt_customer->phone; + if($ivt_customer->email != $owner->email) $new_billing["email"] = $ivt_customer->email; + + $new_billing["billing_type"] = ($ivt_customer->payment == 1) ? "invoice" : "sepa"; + $new_billing["billing_delivery"] = ($ivt_customer->paper_invoice == 1) ? "paper" : "email"; + + if($ivt_customer->bank_account_bank != $owner->bank_account_bank) $new_billing["bank_account_bank"] = $ivt_customer->bank_account_bank; + if($ivt_customer->bank_account_owner != $owner->bank_account_owner) $new_billing["bank_account_owner"] = $ivt_customer->bank_account_owner; + if($ivt_customer->bank_account_iban != $owner->bank_account_iban) $new_billing["bank_account_iban"] = $ivt_customer->bank_account_iban; + if($ivt_customer->bank_account_bic != $owner->bank_account_bic) $new_billing["bank_account_bic"] = $ivt_customer->bank_account_bic; + + $billingaddress = AddressModel::create($new_billing); + + + + // TODO: sync bank data + + + return $return; + } + + private function checkIvtProduct($product) { + if(!$product->id) { + echo __METHOD__ . ": Keine Produkt id
\n"; + return false; + } + if(!$product->name) { + echo __METHOD__ . ": Keine Produkt id
\n"; + return false; + } + return true; + } + + private function importContractconfig($ivt_customer, $ivt_product, &$contract, $doit = false) { + //return true; + //var_dump($contract, $contract->product, $contract->configgroups); + + + if(!is_array($contract->configgroups) || !count($contract->configgroups)) { + echo "no contract config"; + return true; + } + + $product = $contract->product; + if(!$product->id) { + echo "Produkt nicht gefunden für Contract " . $contract->id . "
\n"; + exit; + } + + // lookup radius data + $ruser = $this->getRadiusUser($ivt_customer, $ivt_product, $contract); + // lookup voip data + $voip_data = $this->getVoipData($ivt_customer, $ivt_product, $contract); + + foreach($contract->configgroups as $cgroup) { + + $items = $cgroup->items; + /*var_dump($cgroup); + var_dump($items); + exit;*/ + + foreach($items as $i) { + /** @var ContractconfigItem $i */ + if(!$i->contract_id) { + $i->setContractId($contract->id); + } + //var_dump($i, $i->value);exit; + switch($i->name) { + case "bandwidth_down": + $i->value->set($product->attributes["bw_down"]->value); + $i->value->save(); + break; + case "bandwidth_up": + $i->value->set($product->attributes["bw_up"]->value); + $i->value->save(); + break; + + case "radiususer_username": + $i->value->set($ruser->username); + $i->value->save(); + break; + case "radiususer_password": + $i->value->set($ruser->getPassword()); + $i->value->save(); + break; + case "radiususer_ipaddress": + $i->value->set($ruser->getAttribute("Framed-IP-Address")); + $i->value->save(); + break; + case "radiususer_netmask": + $i->value->set($ruser->getAttribute("Framed-IP-Netmask")); + $i->value->save(); + break; + case "radiususer_iproute": + $i->value->set($ruser->getAttribute("Framed-Route")); + $i->value->save(); + break; + case "radiususer_dns1": + $i->value->set($ruser->getAttribute("MS-Primary-DNS-Server")); + $i->value->save(); + break; + case "radiususer_dns2": + $i->value->set($ruser->getAttribute("MS-Secondary-DNS-Server")); + $i->value->save(); + break; + default: + $this->log->debug(__METHOD__.": ".$ivt_customer->id.": Kein Wert für Configgroupitem ".$i->name." gefunden"); + } + //var_dump($i, $i->value); + + } + + + } + + var_dump($contract->configgroups); exit; - } - - $productMatch = IvtProductMatchModel::getFirst(["ivt_product_id" => $ivt_contract->pid]); - if(!$productMatch) { - echo "Kein Match zu IVT Product ".$ivt_contract->pid." gefunden.
\n"; - exit; - } - - - if(!$this->checkIvtProduct($productMatch->ivtproduct)) { - exit; - } - - $customer = AddressModel::getFirst(["customer_number" => $ivt_contract->cid]); - $ip = $productMatch->ivtproduct; - $product = $productMatch->product; - - if(!$customer->id) { - echo "Kein thetool Kunde zu IVT customer ".$ivt_contract->cid." gefunden -> wird angelegt
\n"; - $customer = $this->createAddressFromIvtCustomer($ivt_contract->customer); - if(!$customer) { - echo "Fehler beim anlegen der Adresse
\n"; - exit; + + /* + * backbone (vlan) + * Radiususer + * Bandbreite + * IPv4 + * SIP daten + * Voip + * Rufnummer + * Webhosting + * + */ + } + + private function getRadiusUser($ivt_customer, $ivt_product, $contract) { + // find radius user (kundennummer in radius info feld + $radius = new RadiusDB_Client(); + + $user_count = 0; + $user = $radius->getUserByCustnum($ivt_customer->id); + if(!$user) { + $this->log->debug("User in Radius nicht gefunden Kundennummer ".$ivt_customer->id); + return false; } - } - /* - // check if contract was imported already - $existing_contract = ContractModel::getFirst(["imported_from" => "ivt", "imported_data" => $ivt_contract->id]); - if($existing_contract) { - //echo "Contract gibts schon ".$existing_contract->id."
\n"; - continue; - } - */ - - - $contract_data = []; - $contract_data['owner_id'] = $customer->id; - //$contract_data['billingaddress_id'] = $customer->id; - $contract_data['product_id'] = $product->id; - $contract_data['product_name'] = $ip->name; - $contract_data['matchcode'] = ""; - $contract_data['amount'] = 1; - $contract_data['price'] = $ip->price; - $contract_data['price_setup'] = 0; - $contract_data['finish_date'] = mktime(2,0,0,date("m"),1,date("Y")); - $contract_data['finish_date_by'] = 1; - $contract_data['imported_from'] = "ivt"; - $contract_data['imported_data'] = $ivt_contract->id; - - switch($ip->interval) { - case 0: - $contract_data['billing_period'] = 1; - break; - case 1: - $contract_data['billing_period'] = 12; - break; - } - - - $neu["customer"] = $customer; - $neu["ivtproduct"] = $ip; - $neu["product"] = $product; - $neu['action'] = "import"; - $ignore = false; - - if($product->price <= 0) { - $contract_data['price'] = 0; - $contract_data['price_setup'] = $ip->price; - $contract_data['billing_period'] = 0; - $neu['action'] = "ignore"; - $ignore = true; - } - - $contract = ContractModel::create($contract_data); - $neu["contract"] = $contract; - - if($doit && !$ignore) { - $contract_id = $contract->save(); - if(!$contract_id) { - echo "Fehler beim Contract speichern!
\n"; - exit; + + return $user; + + // return data + } + + private function getVoipData($ivt_customer, $ivt_product, $contract) { + // find voice number in ivt + $ivtnum = IvtCustomerTelephoneNrModel::getFirst(["cid" => $ivt_customer->id]); + if(!$ivtnum) return true; + + $number = preg_replace('/^0043/', '43', $ivtnum->number); + if(!$number) return true; + + // find number in block + $voicenumberblock = Voicenumberblock::findBlock($number); + if(!$voicenumberblock) return false; + + if(!$voicenumberblock->isNumberInBlock($number)) { + die("Block für Nummer $number enthält nummer nicht."); } - - // create journal entry - $journal = ContractjournalModel::create([ - 'contract_id' => $contract_id, - 'type' => "created_from", - 'value' => "import", - 'text' => "IVT" - ]); - $journal_id = $journal->save(); - if(!$journal_id) { - echo "Fehler beim Journal erstellen.
\n"; - exit; + + $voicenumber = $voicenumberblock->getVoicenumber($number); + if(!$voicenumber) { + die("Nummer $number gehört nicht in Block ".$voicenumberblock->id); } - - // import Contractconfig - $this->importContractconfig($ivt_customer, $ivt_product, $contract); - - - } - - $data["contracts"][] = $neu; - if($neu['action'] == "ignore") { - $data['ignore']++; - } + + // return voicenumber object + return $voicenumber; } - return $data; - } - - private function checkIvtCustomer($customer) { - // create customer if not exists - $old_custnum = $customer->id; - if(!$old_custnum) return false; - - // TODO: sync bank data - - return true; - } - - private function checkIvtProduct($product) { - if(!$product->id) { - echo __METHOD__.": Keine Produkt id
\n"; - return false; - } - if(!$product->name) { - echo __METHOD__.": Keine Produkt id
\n"; - return false; - } - return true; - } - - private function importContractconfig($ivt_customer, $ivt_product, $contract) { - var_dump($contract, $contract->product, $contract->configgroups); - - - if(!is_array($contract->configgroups) || !count($contract->configgroups)) { - return true; - } - - $product = $contract->product; - if(!$product->id) { - echo "Produkt nicht gefunden für Contract ".$contract->id."
\n"; - exit; - } - - // lookup radius data - $radius_data = $this->getRadiusUser($ivt_customer, $ivt_product, $contract); - // lookup voip data - $voip_data = $this->getVoipData($ivt_customer, $ivt_product, $contract); - - foreach($contract->configgroups as $cgroup) { - - $items = $cgroup->items; - var_dump($cgroup); - var_dump($items); - - foreach($items as $i) { - switch($i->name) { - case "bandwidth_down": - $i->value->set($product->attributes["bw_down"]->value); - $i->value->save(); - break; - case "bandwidth_up": - $i->value->set($product->attributes["bw_up"]->value); - $i->value->save(); - break; - - case "radiususer_username": - $i->value->set($radius_data["username"]); - $i->value->sav(); - break; - case "radiususer_password": - $i->value->set($radius_data["username"]); - $i->value->sav(); - break; - case "radiususer_ipaddress": - $i->value->set($radius_data["ipaddress"]); - $i->value->sav(); - break; - case "radiususer_ipprefix": - $i->value->set($radius_data["subnetmask"]); - $i->value->sav(); - break; - - + + private function createAddressFromIvtCustomer(IvtCustomer $cust) { + $address_data['customer_number'] = $cust->id; + $address_data['spin'] = $cust->MandatID; + $address_data['company'] = $cust->company; + $address_data['firstname'] = $cust->firstname; + $address_data['lastname'] = $cust->surname; + + if($cust->company && !$cust->firstname && $cust->company == $cust->surname) { + $address_data["firstname"] = ""; + $address_data["lastname"] = ""; } - } - - - } - exit; - - /* - * backbone (vlan) - * Radiususer - * Bandbreite - * IPv4 - * SIP daten - * Voip - * Rufnummer - * Webhosting - * - */ - } - - private function getRadiusUser($ivt_customer, $ivt_product, $contract) { - // find radius user - - // return data - } - - private function getVoipData($ivt_customer, $ivt_product, $contract) { - - } - - private function createAddressFromIvtCustomer(IvtCustomer $cust) { - $address_data['customer_number'] = $cust->id; - $address_data['spin'] = $cust->MandatID; - $address_data['company'] = $cust->company; - $address_data['firstname'] = $cust->firstname; - $address_data['lastname'] = $cust->surname; - - if($cust->company && !$cust->firstname && $cust->company == $cust->surname) { - $address_data["firstname"] = ""; - $address_data["lastname"] = ""; - } - - $address_data['street'] = $cust->street; - if(strlen($cust->housenumber)) { - $address_data['street'] .= " ".$cust->housenumber; - } - $address_data['zip'] = $cust->zip; - $address_data['city'] = $cust->location; - $address_data['country'] = ""; - $address_data['phone'] = $cust->phone; - $address_data['fax'] = ""; - $address_data['mobile'] = ""; - $address_data['email'] = $cust->email; - $address_data['note'] = $cust->extrainfo; - $address_data['uid'] = ($cust->UID) ? $cust->UID : null; - $address_data["bank_account_bank"] = ""; - $address_data["bank_account_owner"] = ($cust->company) ? $cust->company : $cust->firstname . " " . $cust->surname; - $address_data["bank_account_iban"] = $cust->IBAN; - $address_data["bank_account_bic"] = $cust->BIC; + $address_data['street'] = $cust->street; + if(strlen($cust->housenumber)) { + $address_data['street'] .= " " . $cust->housenumber; + } + $address_data['zip'] = $cust->zip; + $address_data['city'] = $cust->location; + $address_data['country'] = ""; + $address_data['phone'] = $cust->phone; + $address_data['fax'] = ""; + $address_data['mobile'] = ""; + $address_data['email'] = $cust->email; + $address_data['note'] = $cust->extrainfo; - if($cust->payment == 0 ) { // 0 = sepa / 1 = rechnung - $address_data['billing_type'] = "sepa"; - } else { - $address_data['billing_type'] = "invoice"; + $address_data['uid'] = ($cust->UID) ? $cust->UID : null; + $address_data["bank_account_bank"] = ""; + $address_data["bank_account_owner"] = ($cust->company) ? $cust->company : $cust->firstname . " " . $cust->surname; + $address_data["bank_account_iban"] = $cust->IBAN; + $address_data["bank_account_bic"] = $cust->BIC; + + if($cust->payment == 0) { // 0 = sepa / 1 = rechnung + $address_data['billing_type'] = "sepa"; + } else { + $address_data['billing_type'] = "invoice"; + } + + if($cust->paper_invoice == 1) { + $address_data["billing_delivery"] = "paper"; + } else { + $address_data["billing_delivery"] = "email"; + } + + if($cust->accept_adver == 2) { + $address_data["allow_contact"] = 1; + } else { + $address_data["allow_contact"] = 0; + } + + if($cust->accept_info == 2) { + $address_data["allow_spin"] = 1; + } else { + $address_data["allow_spin"] = 0; + } + + $address_data['create_by'] = 1; + $address_data['edit_by'] = 1; + + $address = AddressModel::create($address_data); + + if(!$address->save()) { + var_dump($address); + return false; + } + return $address; } - - if($cust->paper_invoice == 1) { - $address_data["billing_delivery"] = "paper"; - } else { - $address_data["billing_delivery"] = "email"; - } - - if($cust->accept_adver == 2) { - $address_data["allow_contact"] = 1; - } else { - $address_data["allow_contact"] = 0; - } - - if($cust->accept_info == 2) { - $address_data["allow_spin"] = 1; - } else { - $address_data["allow_spin"] = 0; - } - - $address_data['create_by'] = 1; - $address_data['edit_by'] = 1; - - $address = AddressModel::create($address_data); - - if(!$address->save()) { - var_dump($address); - return false; - } - return $address; - } } diff --git a/application/Contract/Contract.php b/application/Contract/Contract.php index 527395e4c..5f1b81386 100644 --- a/application/Contract/Contract.php +++ b/application/Contract/Contract.php @@ -231,8 +231,34 @@ class Contract extends mfBaseModel { } return $this->orderproduct; } - - + + /*if($name == "contractConfigGroups") { + $product = $this->getProperty("product"); + $this->contractConfigGroups = ContractconfigGroupModel::search(['producttech_id' => $product->producttech_id]); + return $this->contractConfigGroups; + }*/ + + if($name == "configgroups") { + $product = $this->getProperty("product"); + $this->configgroups = []; + foreach(ContractconfiggroupProductgroupModel::search(['productgroup_id' => $product->productgroup_id]) as $ccpg) { + $ccpg->contractconfiggroup->setContractId($this->id); + $this->configgroups[] = $ccpg->contractconfiggroup; + } + + return $this->configgroups; + } + + if($name == "configvalues") { + foreach($this->getProperty("configgroups") as $group) { + foreach($group->items as $item) { + $this->configvalues[$item->name] = $item; + } + } + + return $this->configvalues; + } + if(!$this->id) { return null; } @@ -240,32 +266,11 @@ class Contract extends mfBaseModel { - /*if($name == "contractConfigGroups") { - $product = $this->getProperty("product"); - $this->contractConfigGroups = ContractconfigGroupModel::search(['producttech_id' => $product->producttech_id]); - return $this->contractConfigGroups; - }*/ + - if($name == "configgroups") { - $product = $this->getProperty("product"); - $this->configgroups = []; - foreach(ContractconfiggroupProductgroupModel::search(['productgroup_id' => $product->productgroup_id]) as $ccpg) { - $ccpg->contractconfiggroup->setContractId($this->id); - $this->configgroups[] = $ccpg->contractconfiggroup; - } - - return $this->configgroups; - } + - if($name == "configvalues") { - foreach($this->getProperty("configgroups") as $group) { - foreach($group->items as $item) { - $this->configvalues[$item->name] = $item; - } - } - - return $this->configvalues; - } + /*if($name == "contractConfigItems") { $product = $this->getProperty("product"); diff --git a/application/ContractconfigItem/ContractconfigItem.php b/application/ContractconfigItem/ContractconfigItem.php index a43ea5613..a60925903 100644 --- a/application/ContractconfigItem/ContractconfigItem.php +++ b/application/ContractconfigItem/ContractconfigItem.php @@ -2,7 +2,7 @@ class ContractconfigItem extends mfBaseModel { private $value; - private $contract_id; + public $contract_id; public function setContractId($contract_id) { if(!is_numeric($contract_id)) { diff --git a/application/IvtCustomerProduct/IvtCustomerProductModel.php b/application/IvtCustomerProduct/IvtCustomerProductModel.php index 4e09975b6..42819bcc4 100644 --- a/application/IvtCustomerProduct/IvtCustomerProductModel.php +++ b/application/IvtCustomerProduct/IvtCustomerProductModel.php @@ -3,15 +3,19 @@ class IvtCustomerProductModel { - public static function getAll() { + public static function getAll($order = false) { $items = []; - + $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); - - $res = $db->select("customer_product", "*", "1=1 ORDER BY id"); + + if(!$order) { + $order = "id"; + } + + $res = $db->select("customer_product", "*", "1=1 ORDER BY $order"); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { - $items[] = new IvtCustomerProduct($data); + $items[] = new IvtCustomerTelephoneNr($data); } } return $items; @@ -24,7 +28,7 @@ class IvtCustomerProductModel { $res = $db->select("customer_product", "*", "$where ORDER BY id LIMIT 1"); if($db->num_rows($res)) { $data = $db->fetch_object($res); - $item = new IvtCustomerProduct($data); + $item = new IvtCustomerTelephoneNr($data); if($item->id) { return $item; } else { @@ -67,7 +71,7 @@ class IvtCustomerProductModel { $res = $db->query($sql); if($db->num_rows($res)) { while($data = $db->fetch_object($res)) { - $items[] = new IvtCustomerProduct($data); + $items[] = new IvtCustomerTelephoneNr($data); } } return $items; diff --git a/application/IvtCustomerTelephoneNr/IvtCustomerTelephoneNr.php b/application/IvtCustomerTelephoneNr/IvtCustomerTelephoneNr.php new file mode 100644 index 000000000..b6bfa7ec7 --- /dev/null +++ b/application/IvtCustomerTelephoneNr/IvtCustomerTelephoneNr.php @@ -0,0 +1,67 @@ +log = mfLoghandler::singleton(); + $this->data = new stdClass(); + $this->table = "products"; + + $this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + if(is_numeric($_)) { + $this->fetch($_); + } elseif(is_object($_)) { + $this->load($_); + } + } + + public function save() { + return true; + } + + public function getProperty($name) { + if($this->$name == null) { + + if($name == "customer") { + $ivtcustomer = new IvtCustomer($this->cid); + if($ivtcustomer->id) { + $this->ivtcustomer = $ivtcustomer; + } + return $this->ivtcustomer; + } + + $classname = ucfirst($name); + $idfield = $name . "_id"; + $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield); + if(!$this->$name) { + $this->$name = new $classname($this->$idfield); + } + + if($this->$name->id) { + mfValuecache::singleton()->set("mfObjectmodel-$name-" . $this->$name->id, $this->$name); + return $this->$name; + } else { + return null; + } + + } + + return $this->$name; + } + + + public function __debugInfo() { + $vars = get_object_vars($this); + if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)"; + if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)'; + return $vars; + } + +} \ No newline at end of file diff --git a/application/IvtCustomerTelephoneNr/IvtCustomerTelephoneNrModel.php b/application/IvtCustomerTelephoneNr/IvtCustomerTelephoneNrModel.php new file mode 100644 index 000000000..2a1ee3b18 --- /dev/null +++ b/application/IvtCustomerTelephoneNr/IvtCustomerTelephoneNrModel.php @@ -0,0 +1,115 @@ +select("customer_telephone_nr", "*", "1=1 ORDER BY $order"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new IvtCustomerTelephoneNr($data); + } + } + return $items; + } + + public static function getFirst($filter = []) { + $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + $where = self::getSqlFilter($filter); + $res = $db->select("customer_telephone_nr", "*", "$where ORDER BY id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new IvtCustomerTelephoneNr($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function count($filter) { + $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + $where = self::getSqlFilter($filter); + $sql = "SELECT COUNT(*) cnt FROM customer_telephone_nr WHERE $where ORDER by id"; + + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + return $data->cnt; + } + return 0; + } + + public static function search($filter, $limit = false) { + $items = []; + $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + $where = self::getSqlFilter($filter); + $sql = "SELECT * FROM customer_telephone_nr WHERE $where ORDER by cid,pid,sid,id"; + + mfLoghandler::singleton()->debug($sql); + if(is_array($limit) && count($limit)) { + if(is_numeric($limit['start']) && is_numeric($limit['count'])) { + $sql .= " LIMIT ".$limit['start'].", ".$limit['count']; + } elseif(is_numeric($limit['count'])) { + $sql .= " LIMIT ".$limit['count']; + } + } + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new IvtCustomerTelephoneNr($data); + } + } + return $items; + } + + private static function getSqlFilter($filter) { + $where = "1=1 "; + + if(array_key_exists("cid", $filter)) { + $cid = $filter['cid']; + if(is_numeric($cid)) { + $where .= " AND cid=$cid"; + } + } + + if(array_key_exists("pid", $filter)) { + $pid = $filter['pid']; + if(is_numeric($pid)) { + $where .= " AND pid=$pid"; + } + } + + if(array_key_exists("number", $filter)) { + $number = (string)FronkDB::singleton()->escape($filter['number']); + if($number) { + $where .= " AND number='$number'"; + } + } + + if(array_key_exists("number%", $filter)) { + $number = (string)FronkDB::singleton()->escape($filter['number']); + if($number) { + $where .= " AND number LIKE '%$number%'"; + } + } + + //var_dump($filter, $where);exit; + return $where; + } + +} diff --git a/application/Order/Order.php b/application/Order/Order.php index 97f2ebad0..15637e98c 100644 --- a/application/Order/Order.php +++ b/application/Order/Order.php @@ -288,7 +288,7 @@ class Order extends mfBaseModel { $to = $values['to']; if(!$subject || !$from || !$from_name || !$to) { - $this->log->warn("Order Fileupload Email not sent. (subject: '$subject', from: '$from', from_email: '$from_email', to: '$to')"); + $this->log->warn("Order Fileupload Email not sent. (subject: '$subject', from: '$from_name', from_email: '$from', to: '$to')"); } else { $filepath = MFUPLOAD_FILE_SAVE_PATH; if($file->file->subfolder) { diff --git a/application/Order/OrderController.php b/application/Order/OrderController.php index 050ff4770..2e8e1e52e 100644 --- a/application/Order/OrderController.php +++ b/application/Order/OrderController.php @@ -1236,7 +1236,6 @@ class OrderController extends mfBaseController { $order->deletePositions(); - // TODO: check if Product is unused $order->delete(); $this->layout()->setFlash("Bestellung gelöscht", "success"); $this->redirect("Order"); diff --git a/application/Voicenumberblock/Voicenumberblock.php b/application/Voicenumberblock/Voicenumberblock.php index b40c60cba..a343d8473 100644 --- a/application/Voicenumberblock/Voicenumberblock.php +++ b/application/Voicenumberblock/Voicenumberblock.php @@ -34,7 +34,23 @@ class Voicenumberblock extends mfBaseModel { return $block; } - + + public function getVoicenumber($number) { + if(!$this->isNumberInBlock($number)) return false; + + $vn = VoicenumberModel::getFirst(["number" => $number]); + if(!$vn) { + $vn = VoicenumberModel::create([ + "voicenumberblock_id" => $this->id, + "active" => 1, + "activated_date" => date("U"), + "number" => $number + ]); + } + + return $vn; + } + public function getFreeNumbers() { if(!$this->id) return false; diff --git a/application/XinonFibuMerge/XinonFibuMergeModel.php b/application/XinonFibuMerge/XinonFibuMergeModel.php index d0565b02e..736c1e7a6 100644 --- a/application/XinonFibuMerge/XinonFibuMergeModel.php +++ b/application/XinonFibuMerge/XinonFibuMergeModel.php @@ -9,6 +9,7 @@ class XinonFibuMergeModel { public $strasse; public $plz; public $ort; + public $land; public $create_by = null; public $edit_by = null; @@ -41,11 +42,14 @@ class XinonFibuMergeModel { return $model; } - public static function getFirst($filter = []) { + public static function getFirst($filter = [], $order = false) { $db = FronkDB::singleton(); + if(!$order) { + $order = "old_custnum"; + } $where = self::getSqlFilter($filter); - $res = $db->select("XinonFibuMerge", "*", "$where ORDER BY old_custnum LIMIT 1"); + $res = $db->select("XinonFibuMerge", "*", "$where ORDER BY $order LIMIT 1"); if ($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new XinonFibuMerge($data); @@ -58,12 +62,16 @@ class XinonFibuMergeModel { return null; } - public static function getAll() { + public static function getAll($order = false) { $items = []; + if(!$order) { + $order = "old_custnum"; + } + $db = FronkDB::singleton(); - $res = $db->select("XinonFibuMerge", "*", "1=1 ORDER BY old_custnum"); + $res = $db->select("XinonFibuMerge", "*", "1=1 ORDER BY $order"); if ($db->num_rows($res)) { while ($data = $db->fetch_object($res)) { $items[] = new XinonFibuMerge($data); @@ -88,20 +96,25 @@ class XinonFibuMergeModel { return 0; } - public static function search($filter = [], $limit = false) { + public static function search($filter = [], $limit = false, $order = false) { $items = []; $db = FronkDB::singleton(); + if(!$order) { + $order = "old_custnum"; + } + $where = self::getSqlFilter($filter); $sql = "SELECT * FROM XinonFibuMerge WHERE $where - ORDER BY old_custnum"; + ORDER BY $order"; + mfLoghandler::singleton()->debug($sql); if (is_array($limit) && count($limit)) { if (is_numeric($limit['start']) && is_numeric($limit['count'])) { $sql .= " LIMIT " . $limit['start'] . ", " . $limit['count']; - } elseif (is_numeric($count)) { + } elseif (is_numeric($limit['count'])) { $sql .= " LIMIT " . $limit['count']; } } diff --git a/lib/RadiusDB/Client.php b/lib/RadiusDB/Client.php new file mode 100644 index 000000000..9fac1c4a7 --- /dev/null +++ b/lib/RadiusDB/Client.php @@ -0,0 +1,78 @@ +db = new FronkDB($host,$user,$pass,$dbname); + } + + public function getUser($username) { + $user = new RadiusDB_User($this->db); + $user->load($username); + return $user; + } + + public function searchUsers($search, $exact=false) { + $users = array(); + $search = $this->db->escape($search); + if($exact) { + $res = $this->db->select("radcheck", "username", "username='$search' GROUP BY username ORDER BY LENGTH(username), username"); + } else { + $res = $this->db->select("radcheck", "username", "username like '$search' GROUP BY username ORDER BY LENGTH(username), username"); + } + if($this->db->num_rows($res)) { + while($data = $this->db->fetch_object($res)) { + $users[] = $data->username; + } + } + return $users; + } + + public function searchUsersByIp($ip) { + $users = array(); + $ip = $this->db->escape($ip); + $res = $this->db->select("radreply", "username", "attribute='Framed-IP-Address' AND value='$ip' GROUP BY username ORDER BY username"); + if($this->db->num_rows($res)) { + while($data = $this->db->fetch_object($res)) { + $users[] = $data->username; + } + } + return $users; + } + + public function getUserByCustnum($custnum, $e = false) { + $users = array(); + $search = $this->db->escape($custnum); + $field = "Custnum"; + if($e) { + $field = "Custnume"; + } + $res = $this->db->select("Hotspot_Usersettings", "Username", "$field = '$custnum' GROUP BY Username ORDER BY Username LIMIT 1"); + if($this->db->num_rows($res)) { + $data = $this->db->fetch_object($res); + $user = $this->getUser($data->Username); + if($user->username) { + return $user; + } + + } + return false; + } + + public function getNas($nasname) { + $nas = new RadiusDB_Nas($this->db); + $nas->load($nasname); + return $nas; + } + + public function restartRadiusServer() { + exec("/usr/bin/sudo /usr/sbin/service freeradius restart"); + return true; + } +} \ No newline at end of file diff --git a/lib/RadiusDB/Nas.php b/lib/RadiusDB/Nas.php new file mode 100644 index 000000000..ba458a48f --- /dev/null +++ b/lib/RadiusDB/Nas.php @@ -0,0 +1,69 @@ +db = $db; + } + + public function load($nasname) { + //var_dump($this->db); + $nasname = $this->db->escape($nasname); + + $res = $this->db->select("nas", "*", "nasname='$nasname'"); + if(!$this->db->num_rows($res)) { + $this->type = "other"; + $this->secret = Helper::getNewPassword(24); + return true; + } + $nas = $this->db->fetch_object($res); + + $this->id = $nas->id; + $this->nasname = $nas->nasname; + $this->intaddress = $nas->intaddress; + $this->shortname = $nas->shortname; + $this->type = $nas->type; + $this->secret = $nas->secret; + $this->description = $nas->description; + return true; + } + + public function save() { + if(!$this->nasname) { + return false; + } + if(!$this->secret) { + return false; + } + + if($this->id) { + $id = $this->id; + } + $values['nasname'] = $this->nasname; + $values['intaddress'] = $this->nasname; // is supposed to be the same as nasname + $values['shortname'] = $this->shortname; + $values['type'] = $this->type; + $values['secret'] = $this->secret; + $values['description'] = $this->description; + + if($id) { + if(!$this->db->update("nas", $values, "id=$id")) { + return false; + } + } else { + if(!$id = $this->db->insert("nas", $values)) { + return false; + } + } + + return $id; + } +} \ No newline at end of file diff --git a/lib/RadiusDB/User.php b/lib/RadiusDB/User.php new file mode 100644 index 000000000..f1dff6eb3 --- /dev/null +++ b/lib/RadiusDB/User.php @@ -0,0 +1,275 @@ +db = $db; + $this->Checks = array(); + $this->Attributes = array(); + $this->AllowedNas = array(); + $this->Info = false; + $this->_oldChecks = array(); + $this->_oldAttributes = array(); + $this->_oldAllowedNas = array(); + $this->_oldInfo = false; + } + + public function load($username) { + if(!$username) { + return false; + } + + $this->username = $username; + + $res = $this->db->select("radcheck","*","username='$username'"); + if($this->db->num_rows($res)) { + while($radcheck = $this->db->fetch_object($res)) { + $this->Checks[$radcheck->attribute] = $radcheck->value; + } + } else { + $this->setPassword(""); + return false; + } + + $res = $this->db->select("radreply","*","username='$username'"); + if($this->db->num_rows($res)) { + while($radreply = $this->db->fetch_object($res)) { + $this->Attributes[$radreply->attribute] = $radreply->value; + } + } + + $res = $this->db->select("radusergroup", "*", "username='$username'"); + if($this->db->num_rows($res)) { + $radusergroup = $this->db->fetch_object($res); + $this->Usergroup = $radusergroup->groupname; + } + + $res = $this->db->select("radnascheck", "*", "username='$username'"); + if($this->db->num_rows($res)) { + while($nascheck = $this->db->fetch_object($res)) { + $this->AllowedNas[] = $nascheck->nasname; + } + } + + $this->Info = new RadiusDB_UserInfo($username); + + $this->_oldUsergroup = $this->Usergroup; + $this->_oldChecks = $this->Checks; + $this->_oldAttributes = $this->Attributes; + $this->_oldAllowedNas = $this->AllowedNas; + + return true; + } + + public function getCheck($name) { + if(isset($this->Checks[$name])) { + return $this->Checks[$name]; + } + return null; + } + + public function getAttribute($name) { + if(isset($this->Attributes[$name])) { + return $this->Attributes[$name]; + } + return null; + } + + public function setCheck($name, $value) { + $this->Checks[$name] = $value; + } + + public function setAttribute($name, $value) { + $this->Attributes[$name] = $value; + } + + public function getPassword() { + return $this->getCheck("Cleartext-Password"); + } + public function setPassword($password) { + $this->setCheck("Cleartext-Password", $password); + } + public function getUsergroup() { + return $this->Usergroup; + } + public function setUsergroup($groupname) { + $this->Usergroup = $groupname; + } + + public function isNasAllowed($nas_ip) { + if(in_array($nas_ip, $this->AllowedNas)) { + return true; + } + return false; + } + + public function addAllowedNas($nas_ip) { + if(!in_array($nas_ip, $this->AllowedNas,true)) { + $this->AllowedNas[] = $nas_ip; + } + } + + public function removeAllowedNas($nas_ip) { + if(in_array($nas_ip, $this->AllowedNas, true) !== false) { + unset($this->AllowedNas[array_search($nas_ip, $this->AllowedNas)]); + } + } + + + public function unset($name) { + if($name == "usergroup") { + $this->Usergroup = false; + } + + if(isset($this->Checks[$name])) { + unset($this->Checks[$name]); + return true; + } + if(isset($this->Attributes[$name])) { + unset($this->Attributes[$name]); + return true; + } + return false; + } + + public function save() { + if(!$this->username) { + return false; + } + + $username = $this->username; + + $error = false; + + $this->db->query("START TRANSACTION"); // XXX should be put moved to a FronkDB function + // check queries + foreach($this->Checks as $attribute => $value) { + if(isset($this->_oldChecks[$attribute])) { + if(!$this->db->update("radcheck", ['value' => $value], "username='$username' AND attribute='$attribute'")) { + $error = true; + } + } else { + if(!$this->db->insert("radcheck", ['username' => $username, 'attribute' => $attribute, 'op' => $this->checkop, 'value' => $value])) { + $error = true; + } + } + } + // attribute queries + foreach($this->Attributes as $attribute => $value) { + if(isset($this->_oldAttributes[$attribute])) { + if(!$this->db->update("radreply", ['value' => $value], "username='$username' AND attribute='$attribute'")) { + $error = true; + } + } else { + if(!$this->db->insert("radreply", ['username' => $username, 'attribute' => $attribute, 'op' => $this->attribop, 'value' => $value])) { + $error = true; + } + } + } + + // update usergroup + if($this->Usergroup) { + if($this->_oldUsergroup) { + if(!$this->db->update("radusergroup", ['groupname' => $this->Usergroup], "username='$username'")) { + $error = true; + } + } else { + if(!$this->db->insert("radusergroup", ['username' => $username, 'groupname' => $this->Usergroup, 'priority' => 1])) { + $error = true; + } + } + } + + // update Nascheck + foreach($this->AllowedNas as $nas) { + if(!in_array($nas, $this->_oldAllowedNas, true)) { + + if(!$this->db->insert("radnascheck", ['username' => $username, 'nasname' => $nas])) { + $error = true; + } + } + } + + + // delete attributes + + foreach($this->_oldChecks as $attribute => $value) { + if(!isset($this->Checks[$attribute])) { + if(!$this->db->delete("radcheck", "username='$username' AND attribute='$attribute'")) { + $error = true; + } + } + } + + foreach($this->_oldAttributes as $attribute => $old) { + if(!isset($this->Attributes[$attribute])) { + if(!$this->db->delete("radreply", "username='$username' AND attribute='$attribute'")) { + $error = true; + } + } + } + + if($this->_oldUsergroup && !$this->Usergroup) { + if(!$this->db->delete("radusergroup", "username='$username'")) { + $error = true; + } + } + + foreach($this->_oldAllowedNas as $oldnas) { + if(!in_array($oldnas, $this->AllowedNas, true)) { + if(!$this->db->delete("radnascheck", "username='$username' AND nasname='$oldnas'")) { + $error = true; + } + } + } + + if($error) { + $this->db->query("ROLLBACK"); + return false; + } else { + $this->db->query("COMMIT"); + } + + // reinitialize _old* values + $this->_oldUsergroup = $this->Usergroup; + $this->_oldChecks = $this->Checks; + $this->_oldAttributes = $this->Attributes; + $this->_oldAllowedNas = $this->AllowedNas; + + return true; + } + + + public function __get($name) { + if($name === "username") { + return $this->username; + } + if(in_array($name, array_keys($this->Checks))) { + return $this->getCheck($name); + } + if(in_array($name, array_keys($this->Attributes))) { + return $this->getAttribute($name); + } + } + + public function __toString() { + return (string) $this->username; + } +} \ No newline at end of file diff --git a/lib/RadiusDB/UserInfo.php b/lib/RadiusDB/UserInfo.php new file mode 100644 index 000000000..1399d7249 --- /dev/null +++ b/lib/RadiusDB/UserInfo.php @@ -0,0 +1,43 @@ +db = $db; + } + + public function load($username) { + if(!$username) { + return false; + } + + $this->username = $username; + + $res = $this->db->select("Hotspot_Usersettings", "*", "Username='$username'"); + if($this->db->num_rows($res)) { + $rad = $this->db->fetch_object($res); + + $this->id = $rad->id; + $this->Username = $rad->Username; + $this->Custnum = $rad->Custnum; + $this->Custnume = $rad->Custnume; + $this->ContractUp = $rad->ContratUp; + $this->ContractDown = $rad->ContractDown; + $this->Duration = $rad->Duration; + $this->Info = $rad->Info; + $this->Wifikey = $rad->Wifikey; + $this->ont_sn = $rad->ont_sn; + + } + } +} \ No newline at end of file