Esempio n. 1
0
 function execute()
 {
     // establish a new table object
     $this->obj_table = new table();
     $this->obj_table->language = $_SESSION["user"]["lang"];
     $this->obj_table->tablename = "name_servers_groups";
     // define all the columns and structure
     $this->obj_table->add_column("standard", "group_name", "");
     $this->obj_table->add_column("standard", "group_description", "");
     $this->obj_table->add_column("standard", "group_members", "NONE");
     // defaults
     $this->obj_table->columns = array("group_name", "group_description", "group_members");
     $this->obj_table->columns_order = array("group_name");
     $this->obj_table->columns_order_options = array("group_name");
     $this->obj_table->sql_obj->prepare_sql_settable("name_servers_groups");
     $this->obj_table->sql_obj->prepare_sql_addfield("id", "");
     // load data
     $this->obj_table->generate_sql();
     $this->obj_table->load_data_sql();
     // fetch member list
     for ($i = 0; $i < $this->obj_table->data_num_rows; $i++) {
         $members = sql_get_singlecol("SELECT server_name AS value FROM name_servers WHERE id_group='" . $this->obj_table->data[$i]["id"] . "'");
         $this->obj_table->data[$i]["group_members"] = format_arraytocommastring($members);
     }
 }
Esempio n. 2
0
 function execute()
 {
     /*
      * Validate a POST (page navigation move will prompt this)
      */
     if (isset($_POST['record_custom_page'])) {
         // fetch data from POST and validate - we then return values
         $data = stripslashes_deep($this->obj_domain->validate_custom_records());
         // validate the record_custom_page for returning the user to their page, default to page 1 if any errors in validating...
         $data['record_custom_page'] = @security_form_input_predefined("int", "record_custom_page", 1, "");
         /*
         			echo '<tr><td colspan="100%">post-validation POST data<pre>'; 
         			echo '<pre>';
         			print_R($data);
         			echo '</pre>';
         			echo '</td></tr>';
         			die("debug");
         */
         if (error_check()) {
             log_write("debug", "records-ajax", "POST records provided but error encountered, failing");
             $_SESSION["error"]["form"]["domain_records"] = "failed";
             $this->page = $data['record_custom_page'];
         } else {
             // no errors... set the records to the session
             $_SESSION['form']['domain_records'][$this->obj_domain->id][$data['record_custom_page']] = $data['records'];
         }
     }
     /*
     	Load domain data & records
     */
     $this->num_records_custom_total = $this->obj_domain->data_record_custom_count();
     $this->obj_domain->load_data();
     // if the data is present in the session then it has either changed and is awaiting submission
     // or the user has visited that page before during this edit session
     if (isset($_SESSION['form']['domain_records'][$this->obj_domain->id][$this->page]) && count($_SESSION['form']['domain_records'][$this->obj_domain->id][$this->page])) {
         log_debug("execute", 'Loading records from session as previous load or edit detected');
         $this->obj_domain->data['records'] = $_SESSION['form']['domain_records'][$this->obj_domain->id][$this->page];
         /*
         echo '<tr><td colspan="100%">from sesssion<pre>';
         print_R($this->obj_domain->data['records']);
         echo '</td></tr>';
         */
     } else {
         log_debug("execute", 'Loading records from db for page: ' . $this->page);
         $this->obj_domain->load_data_record_custom($this->offset, $GLOBALS["config"]['PAGINATION_DOMAIN_RECORDS']);
         /*
         echo '<tr><td colspan="100%">from db<pre>';
         print_R($this->obj_domain->data['records']);
         echo '</td></tr>';
         */
     }
     // work out the IP for reverse domains
     if (strpos($this->obj_domain->data["domain_name"], "in-addr.arpa")) {
         // IPv4
         $ip = explode(".", $this->obj_domain->data["domain_name"]);
         $this->obj_domain->data["domain_ip_prefix"] = $ip[2] . "." . $ip[1] . "." . $ip[0];
     } elseif (strpos($this->obj_domain->data["domain_name"], "ip6.arpa")) {
         // IPv6
         $ip_reverse = substr($this->obj_domain->data["domain_name"], 0, strlen($this->obj_domain->data["domain_name"]) - 9);
         $ip_array = array();
         $i = 0;
         foreach (array_reverse(explode(".", $ip_reverse)) as $ip) {
             $i++;
             $ip_array[] = $ip;
             if ($i == 4) {
                 $i = 0;
                 $ip_array[] = ":";
             }
         }
         $this->obj_domain->data["domain_ip_prefix"] = implode("", $ip_array);
     }
     /*
     	Define form structure
     */
     $this->obj_form = new form_input();
     $this->obj_form->formname = "domain_records";
     $this->obj_form->language = $_SESSION["user"]["lang"];
     $this->obj_form->action = "domains/records-process.php";
     $this->obj_form->method = "post";
     /*
     	General Domain Info
     */
     $structure = NULL;
     $structure["fieldname"] = "domain_name";
     $structure["type"] = "message";
     $structure["options"]["css_row_class"] = "table_highlight";
     $structure["defaultvalue"] = "<p><b>Domain " . $this->obj_domain->data["domain_name"] . " selected for adjustment</b></p>";
     $this->obj_form->add_input($structure);
     /*
     	Define stucture for all other record types
     
     	This includes A, AAAA, PTR and other record types.
     */
     // fetch all the known record types from the database
     $dns_record_types = sql_get_singlecol("SELECT type as value FROM `dns_record_types` WHERE user_selectable='1'");
     // unless there has been error data returned, fetch all the records
     // and work out the number of rows
     if (!isset($_SESSION["error"]["form"][$this->obj_form->formname])) {
         $this->num_records_custom = 1;
         foreach ($this->obj_domain->data["records"] as $record) {
             if (in_array($record["type"], $dns_record_types)) {
                 $this->num_records_custom++;
             }
         }
     } else {
         $this->num_records_custom = @security_script_input('/^[0-9]*$/', $_SESSION["error"]["num_records_custom"]);
     }
     // ensure there are at least two rows, if more are needed when entering information,
     // then the javascript functions will provide.
     if ($this->num_records_custom < 2) {
         $this->num_records_custom = 2;
     }
     // custom domain records
     for ($i = 0; $i < $this->num_records_custom; $i++) {
         // values
         $structure = NULL;
         $structure["fieldname"] = "record_custom_" . $i . "_id";
         $structure["type"] = "hidden";
         $this->obj_form->add_input($structure);
         if (strpos($this->obj_domain->data["domain_name"], "arpa")) {
             $structure = NULL;
             $structure["fieldname"] = "record_custom_" . $i . "_type";
             $structure["type"] = "text";
             $structure["defaultvalue"] = "PTR";
             $this->obj_form->add_input($structure);
         } else {
             $structure = form_helper_prepare_dropdownfromdb("record_custom_" . $i . "_type", "SELECT type as label, type as id FROM `dns_record_types` WHERE user_selectable='1' AND is_standard='1'");
             $structure["defaultvalue"] = "A";
             $structure["options"]["width"] = "100";
             $this->obj_form->add_input($structure);
         }
         $structure = NULL;
         $structure["fieldname"] = "record_custom_" . $i . "_name";
         $structure["type"] = "input";
         if (strpos($this->obj_domain->data["domain_name"], "in-addr.arpa")) {
             $structure["options"]["width"] = "50";
             $structure["options"]["max_length"] = "3";
             $structure["options"]["prelabel"] = $this->obj_domain->data["domain_ip_prefix"] . ". ";
             $structure["options"]["help"] = "?";
         } elseif (strpos($this->obj_domain->data["domain_name"], "ip6.arpa")) {
             $structure["options"]["width"] = "300";
             $structure["options"]["prelabel"] = " ";
             $structure["options"]["help"] = $this->obj_domain->data["domain_ip_prefix"] . "....";
             $structure["options"]["autofill"] = $this->obj_domain->data["domain_ip_prefix"];
         } else {
             $structure["options"]["width"] = "300";
             $structure["options"]["help"] = "Record name, eg www";
         }
         $this->obj_form->add_input($structure);
         $structure = NULL;
         $structure["fieldname"] = "record_custom_" . $i . "_content";
         $structure["type"] = "input";
         $structure["options"]["width"] = "300";
         if (strpos($this->obj_domain->data["domain_name"], "arpa")) {
             // both IPv4 and IPv6
             $structure["options"]["help"] = "Reverse record name, eg www.example.com";
         } else {
             $structure["options"]["help"] = "Target IP, eg 192.168.0.1";
         }
         $this->obj_form->add_input($structure);
         $structure = NULL;
         $structure["fieldname"] = "record_custom_" . $i . "_ttl";
         $structure["type"] = "input";
         $structure["options"]["width"] = "80";
         $structure["defaultvalue"] = $this->obj_domain->data["soa_default_ttl"];
         $this->obj_form->add_input($structure);
         $structure = NULL;
         $structure["fieldname"] = "record_custom_" . $i . "_delete_undo";
         $structure["type"] = "hidden";
         $structure["defaultvalue"] = "false";
         $this->obj_form->add_input($structure);
         if (!strpos($this->obj_domain->data["domain_name"], "arpa")) {
             $structure = NULL;
             $structure["fieldname"] = "record_custom_" . $i . "_reverse_ptr";
             $structure["type"] = "checkbox";
             $structure["options"]["label"] = "";
             $this->obj_form->add_input($structure);
             $structure = NULL;
             $structure["fieldname"] = "record_custom_" . $i . "_reverse_ptr_orig";
             $structure["type"] = "hidden";
             $this->obj_form->add_input($structure);
         }
     }
     // load in what data we have
     //disable invalid fields
     $i = 0;
     foreach ($this->obj_domain->data["records"] as $record) {
         if (in_array($record["type"], $dns_record_types)) {
             // special ID rules
             if ($record["id"]) {
                 $this->obj_form->structure["record_custom_" . $i . "_id"]["defaultvalue"] = $record["id"];
             } else {
                 $this->obj_form->structure["record_custom_" . $i . "_id"]["defaultvalue"] = $record["id_record"];
             }
             // fetch data
             $this->obj_form->structure["record_custom_" . $i . "_type"]["defaultvalue"] = $record["type"];
             $this->obj_form->structure["record_custom_" . $i . "_prio"]["defaultvalue"] = $record["prio"];
             $this->obj_form->structure["record_custom_" . $i . "_name"]["defaultvalue"] = $record["name"];
             $this->obj_form->structure["record_custom_" . $i . "_content"]["defaultvalue"] = $record["content"];
             $this->obj_form->structure["record_custom_" . $i . "_ttl"]["defaultvalue"] = $record["ttl"];
             if ($record["type"] == "CNAME") {
                 // disable inappropate values for CNAME fields
                 $this->obj_form->structure["record_custom_" . $i . "_reverse_ptr"]["options"]["disabled"] = "yes";
                 $this->obj_form->structure["record_custom_" . $i . "_reverse_ptr_orig"]["options"]["disabled"] = "yes";
             } elseif ($record["type"] == "PTR") {
                 if (strpos($this->obj_domain->data["domain_name"], "ip6.arpa")) {
                     // IPv6 PTR records are in ARPA format, we should convert it to something human readable
                     $this->obj_form->structure["record_custom_" . $i . "_name"]["defaultvalue"] = ipv6_convert_fromarpa($record["name"]);
                 }
             } elseif ($record["type"] != "PTR") {
                 if ($record["type"] == "A" || $record["type"] == "AAAA") {
                     // check if this record has a reverse PTR value
                     $obj_ptr = new domain_records();
                     $obj_ptr->find_reverse_domain($record["content"]);
                     if ($obj_ptr->id_record) {
                         $obj_ptr->load_data_record();
                         if ($record["name"] == "@" || $record["name"] == "*" || preg_match("/^\\*\\.[A-Za-z0-9:._-]+\$/", $record["name"])) {
                             $record["name"] = $this->obj_domain->data["domain_name"];
                         }
                         if ($obj_ptr->data_record["content"] == $record["name"] || $obj_ptr->data_record["content"] == $record["name"] . "." . $this->obj_domain->data["domain_name"]) {
                             $this->obj_form->structure["record_custom_" . $i . "_reverse_ptr"]["defaultvalue"] = "on";
                             $this->obj_form->structure["record_custom_" . $i . "_reverse_ptr_orig"]["defaultvalue"] = "on";
                         }
                     }
                     unset($obj_ptr);
                 } else {
                     // reverse PTR not valid for this record type
                     $this->obj_form->structure["record_custom_" . $i . "_reverse_ptr"]["options"]["disabled"] = "yes";
                 }
             }
             $i++;
         }
     }
     // hidden
     $structure = NULL;
     $structure["fieldname"] = "id_domain";
     $structure["type"] = "hidden";
     $structure["defaultvalue"] = $this->obj_domain->id;
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "record_custom_page";
     $structure["type"] = "hidden";
     $structure["defaultvalue"] = "{$this->page}";
     $this->obj_form->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "num_records_custom";
     $structure["type"] = "hidden";
     $structure["defaultvalue"] = "{$this->num_records_custom}";
     $this->obj_form->add_input($structure);
     // a record that can be set to determine the form status for final submit
     $structure = NULL;
     $structure["fieldname"] = "record_custom_status";
     $structure["type"] = "hidden";
     // fetch data in event of an error
     if (error_check()) {
         $this->obj_form->load_data_error();
         $structure["defaultvalue"] = "0";
     } else {
         $structure["defaultvalue"] = "1";
     }
     $this->obj_form->add_input($structure);
 }
Esempio n. 3
0
 function load_data_record_custom($offset = 0, $limit = 0)
 {
     log_debug("domains", "Executing load_data_record_custom({$offset}, {$limit})");
     // need actual range
     $limit = $offset + $limit;
     // load array of custom types
     $custom_types = sql_get_singlecol("SELECT type as value FROM dns_record_types WHERE user_selectable = 1");
     // load all records - we can't do a partial limit select, since the sorting in SQL
     // is not suitable for correct domain ordering
     if ($this->load_data_record_all(1)) {
         log_write("debug", "domains", "Loaded all records, selecting limited set of custom records.");
         $data_new = array();
         $j = 0;
         for ($i = 0; $i < count(array_keys($this->data["records"])); $i++) {
             if (in_array($this->data["records"][$i]["type"], $custom_types)) {
                 // custom record selected
                 if ($j >= $offset && $j <= $limit) {
                     $data_new[] = $this->data["records"][$i];
                 }
                 $j++;
             }
         }
         $this->data["records"] = $data_new;
         unset($data_new);
         return 1;
     }
     // end of record load
     // failure
     return 0;
 }
 function fetch_usage_traffic()
 {
     log_write("debug", "service_usage_traffic", "Executing fetch_usage_traffic()");
     /*
     	Fetch data traffic types
     
     	Note that this doesn't query overrides, since the override options will never impact which traffic types that exist,
     	only how they are billed by include/services/inc_services_invoicegen.php
     */
     $traffic_types = sql_get_singlecol("SELECT traffic_types.type_label as col FROM `traffic_caps` LEFT JOIN traffic_types ON traffic_types.id = traffic_caps.id_traffic_type WHERE traffic_caps.id_service='" . $this->obj_service->id . "'");
     /*
     	Fetch raw usage data from DB
     */
     if ($GLOBALS["config"]["SERVICE_TRAFFIC_MODE"] == "internal") {
         /*
         	Internal Database
         
         	Use the internal database - this stores the usage information for upload/download mapped against the customer's
         	IP address.
         
         	TODO:	Currently all traffic is just assigned against type any/*, this should be upgraded to properly support
         		the different traffic types.
         */
         log_write("debug", "service_usage_traffic", "Fetching traffic records from internal database");
         // fetch upload/download stats
         $sql_obj = new sql_query();
         $sql_obj->string = "SELECT SUM(usage1) as usage1, SUM(usage2) as usage2 FROM service_usage_records WHERE id_service_customer='" . $this->id_service_customer . "' AND date>='" . $this->date_start . "' AND date<='" . $this->date_end . "'";
         $sql_obj->execute();
         $sql_obj->fetch_array();
         $this->data["usage1"] = $sql_obj->data[0]["usage1"];
         $this->data["usage2"] = $sql_obj->data[0]["usage2"];
         unset($sql_obj);
         // create a total of both usage columns
         $sql_obj = new sql_query();
         $sql_obj->string = "SELECT '" . $this->data["usage1"] . "' + '" . $this->data["usage2"] . "' as totalusage";
         $sql_obj->execute();
         $sql_obj->fetch_array();
         $this->data["total"]["*"] = $sql_obj->data[0]["totalusage"];
         $this->data["total"]["total"] = $sql_obj->data[0]["totalusage"];
         unset($sql_obj);
         // we now have the raw usage
         log_write("debug", "service_usage_traffic", "Total raw traffic usage for " . $this->date_start . " until " . $this->date_end . " is " . $this->data["total"]["total"] . " bytes");
     } else {
         /*
         	Connect to External SQL database
         
         	External DBs are common with larger teleco providers since it allows easier storage, splicing and archiving of usage information
         	for data traffic services.
         */
         switch ($GLOBALS["config"]["SERVICE_TRAFFIC_DB_TYPE"]) {
             case "mysql_netflow_daily":
                 /*
                 	MODE: mysql_netflow_daily
                 
                 	In this mode, there are netflow tables for each day which we need to read through and aggregate data from, typically
                 	this is done so that busy ISPs don't end up with massive monthly/yearly tables.
                 
                 	eg:
                 	traffic_20110420
                 	traffic_20110421
                 	traffic_20110422
                 
                 	TODO:	Currently all traffic is just assigned against type any/*, this should be upgraded to properly support
                 		the different traffic types.
                 */
                 log_write("debug", "service_usage_traffic", "Processing external database mysql_netflow_daily");
                 /*
                 	Connect to external database
                 */
                 $obj_traffic_db_sql = new sql_query();
                 if (!$obj_traffic_db_sql->session_init("mysql", $GLOBALS["config"]["SERVICE_TRAFFIC_DB_HOST"], $GLOBALS["config"]["SERVICE_TRAFFIC_DB_NAME"], $GLOBALS["config"]["SERVICE_TRAFFIC_DB_USERNAME"], $GLOBALS["config"]["SERVICE_TRAFFIC_DB_PASSWORD"])) {
                     log_write("error", "service_usage_traffic", "Unable to establish a connection to the external traffic DB, unable to run data usage processing.");
                     return 0;
                 }
                 /*
                 	Workout the date range, since we need to query a different table for each day
                 
                 	TODO: this would be nice as a generic function?
                 */
                 $tmp_date = $this->date_start;
                 $date_range = array();
                 $date_range[] = $this->date_start;
                 while ($tmp_date != $this->date_end) {
                     $tmp_date = explode("-", $tmp_date);
                     $tmp_date = date("Y-m-d", mktime(0, 0, 0, $tmp_date[1], $tmp_date[2] + 1, $tmp_date[0]));
                     $date_range[] = $tmp_date;
                 }
                 for ($i = 0; $i < count($date_range); $i++) {
                     // strip "-" charactor
                     $date_range[$i] = str_replace("-", "", $date_range[$i]);
                 }
                 /*
                 	We work out the usage by fetching the totals for each IPv4 address belonging to this
                 	service and aggregating the total.
                 */
                 // make sure we have the array of IPv4 addresses
                 if (!$this->data_ipv4) {
                     $this->load_data_ipv4();
                 }
                 // blank current total
                 $this->data["total"]["total"] = 0;
                 // verify IPv4 address have been configured
                 if (!is_array($this->data_ipv4)) {
                     log_write("warning", "service_usage_traffic", "Note: No IPv4 addresses have been configured for this customer");
                     return 0;
                 }
                 // run through each IP
                 foreach ($this->data_ipv4 as $ipv4) {
                     /*
                     	Fetch Data
                     
                     	We run through each IP and for each IP, we fetch the total from all the daily tables. Note that
                     	we make the assumption that daily tables might not exist if there's nothing to be processed for that
                     	day, so the code is written accordingly.
                     
                     	Note that we use the SQL database for *ALL* calculations, this is due to the SQL DB being able
                     	to handle 64bit integers, whereas PHP will vary depending on the host platform.
                     */
                     log_write("debug", "service_usage_traffic", "Fetching usage records FOR address {$ipv4} FOR date " . $this->date_start . " to " . $this->date_end . "");
                     // run through the dates
                     foreach ($date_range as $date) {
                         // check that the table exists
                         $obj_traffic_db_sql->string = "SHOW TABLES LIKE 'traffic_{$date}'";
                         $obj_traffic_db_sql->execute();
                         if ($obj_traffic_db_sql->num_rows()) {
                             // query the current date for the current IP
                             $obj_traffic_db_sql->string = "SELECT SUM(bytes) as total FROM traffic_{$date} WHERE ip_src='{$ipv4}' OR ip_dst='{$ipv4}'";
                             $obj_traffic_db_sql->execute();
                             $obj_traffic_db_sql->fetch_array();
                             if (!empty($obj_traffic_db_sql->data[0]["total"])) {
                                 // add to running total
                                 $sql_obj = new sql_query();
                                 $sql_obj->string = "SELECT '" . $this->data["total"]["total"] . "' + '" . $obj_traffic_db_sql->data[0]["total"] . "' as totalusage";
                                 $sql_obj->execute();
                                 $sql_obj->fetch_array();
                                 $this->data["total"]["total"] = $sql_obj->data[0]["totalusage"];
                             }
                             // end if traffic exists
                         } else {
                             log_write("warning", "service_usage_traffic", "SQL database table traffic_{$date} does not exist");
                         }
                     }
                     // end foreach date
                     log_write("debug", "service_usage_traffic", "Completed usage query for address {$ipv4}.");
                 }
                 // end foreach ipv4
                 log_write("debug", "service_usage_traffic", "Total usage for all addresses in the date range is " . $this->data["total"]["total"] . " bytes");
                 /*
                 	Disconnect from database
                 */
                 $obj_traffic_db_sql->session_terminate();
                 unset($obj_traffic_db_sql);
                 break;
             case "mysql_traffic_summary":
                 /*
                 	MODE: mysql_traffic_summary
                 
                 	In this mode, the database contains a single table "traffic_summary" which includes the following key fields:
                 	* ip_address			IPv4 Address
                 	* traffic_datetime		Date/Time Field
                 	* traffic_type			Type of traffic
                 	* total				Total Bytes transfered
                 
                 	Ideally this table should contain one row per IP address, per day, to enable billing to occur.
                 
                 	TODO: update to support traffic types
                 */
                 log_write("debug", "service_usage_traffic", "Processing external database mysql_traffic_summary");
                 /*
                 	Connect to external database
                 */
                 $obj_traffic_db_sql = new sql_query();
                 if (!$obj_traffic_db_sql->session_init("mysql", $GLOBALS["config"]["SERVICE_TRAFFIC_DB_HOST"], $GLOBALS["config"]["SERVICE_TRAFFIC_DB_NAME"], $GLOBALS["config"]["SERVICE_TRAFFIC_DB_USERNAME"], $GLOBALS["config"]["SERVICE_TRAFFIC_DB_PASSWORD"])) {
                     log_write("error", "service_usage_traffic", "Unable to establish a connection to the external traffic DB, unable to run data usage processing.");
                     return 0;
                 }
                 /*
                 	Loop through each IP and fetch usage for that IP.
                 */
                 // make sure we have the array of IPv4 addresses
                 if (!$this->data_ipv4) {
                     $this->load_data_ipv4();
                 }
                 // blank current overall and per-type totals
                 $this->data["total"]["total"] = 0;
                 $this->data["total_byunits"]["total"] = 0;
                 foreach ($traffic_types as $type) {
                     $this->data["total"][$type] = 0;
                     $this->data["total_byunits"][$type] = 0;
                 }
                 // verify IPv4 address have been configured
                 if (!is_array($this->data_ipv4)) {
                     log_write("warning", "service_usage_traffic", "Note: No IPv4 addresses have been configured for this customer");
                     return 0;
                 }
                 // run through each IP
                 foreach ($this->data_ipv4 as $ipv4) {
                     /*
                     	Fetch Data
                     
                     	We run through each IP and for each IP, we fetch the total for the date range.
                     
                     	Note that we use the SQL database for *ALL* calculations, this is due to the SQL DB being able
                     	to handle 64bit integers, whereas PHP will vary depending on the host platform.
                     */
                     log_write("debug", "service_usage_traffic", "Fetching usage records FOR address {$ipv4} FOR date " . $this->date_start . " to " . $this->date_end . "");
                     // check that the table exists
                     $obj_traffic_db_sql->string = "SHOW TABLES LIKE 'traffic_summary'";
                     $obj_traffic_db_sql->execute();
                     if ($obj_traffic_db_sql->num_rows()) {
                         // query the current date for the current IP
                         $obj_traffic_db_sql->string = "SELECT SUM(total) as total, traffic_type FROM traffic_summary WHERE ip_address='{$ipv4}' AND traffic_datetime >= '" . $this->date_start . "' AND traffic_datetime <= '" . $this->date_end . "' GROUP BY traffic_type";
                         $obj_traffic_db_sql->execute();
                         if ($obj_traffic_db_sql->num_rows()) {
                             $obj_traffic_db_sql->fetch_array();
                             foreach ($obj_traffic_db_sql->data as $data_traffic) {
                                 if (in_array($data_traffic["traffic_type"], $traffic_types)) {
                                     $type = $data_traffic["traffic_type"];
                                 } else {
                                     // unmatched type, assign to any
                                     $type = "*";
                                 }
                                 // add to running total
                                 $sql_obj = new sql_query();
                                 $sql_obj->string = "SELECT '" . $this->data["total"][$type] . "' + '" . $data_traffic["total"] . "' as totalusage";
                                 $sql_obj->execute();
                                 $sql_obj->fetch_array();
                                 $this->data["total"][$type] = $sql_obj->data[0]["totalusage"];
                                 unset($sql_obj);
                             }
                         }
                         // end if traffic exists
                     } else {
                         log_write("error", "service_usage_traffic", "SQL database table traffic_summary does not exist");
                     }
                     log_write("debug", "service_usage_traffic", "Total usage for address {$ipv4} is " . $this->data["total"] . " bytes");
                 }
                 // end foreach ipv4
                 // produce overall total
                 $sql_obj = new sql_query();
                 foreach ($traffic_types as $type) {
                     $sql_obj->string = "SELECT '" . $this->data["total"]["total"] . "' + '" . $this->data["total"][$type] . "' as totalusage";
                     $sql_obj->execute();
                     $sql_obj->fetch_array();
                     $this->data["total"]["total"] = $sql_obj->data[0]["totalusage"];
                 }
                 unset($sql_obj);
                 log_write("debug", "service_usage_traffic", "Total usage for all addresses in the date range is " . $this->data["total"] . " bytes");
                 /*
                 	Disconnect from database
                 */
                 $obj_traffic_db_sql->session_terminate();
                 unset($obj_traffic_db_sql);
                 break;
             default:
                 /*
                 	Unknown DB type, we should fail.
                 */
                 log_write("error", "debug", "External DB type " . $GLOBALS["config"]["SERVICE_TRAFFIC_DB_TYPE"] . " is not supported.");
                 return 0;
                 break;
         }
         // end of switch between DB types
     }
     // end of external data source
     /*
     	Generate formatted usage
     
     	We have the number of raw units, we now need to generate the number of human readable/formatted units
     	from this figure.
     */
     log_write("debug", "service_usage_traffic", "Generating formatted usage totals");
     $this->data["numrawunits"] = sql_get_singlevalue("SELECT numrawunits as value FROM service_units WHERE id='" . $this->obj_service->data["units"] . "' LIMIT 1");
     if (!$this->data["numrawunits"]) {
         log_debug("service_usage_traffic", "Error: Unable to fetch number of raw units for the units type");
         return 0;
     }
     foreach (array_keys($this->data["total"]) as $type) {
         // calculate
         $sql_obj = new sql_query();
         $sql_obj->string = "SELECT '" . $this->data["total"][$type] . "' / '" . $this->data["numrawunits"] . "' as value";
         $sql_obj->execute();
         $sql_obj->fetch_array();
         // format & return
         $this->data["total_byunits"][$type] = round($sql_obj->data[0]["value"], 2);
     }
     log_write("debug", "service_usage_traffic", "Total traffic usage for period is " . $this->data["total_byunits"]["total"] . "");
     /*
     	Complete
     */
     return 1;
 }
Esempio n. 5
0
 */
 if (error_check()) {
     header("Location: ../index.php?page=domains/import.php&mode=1");
     exit(0);
 }
 /*
 	Import the data
 */
 // store all the domain information in the data array to be
 // passed back to the user form.
 $data = array();
 // valid record rows
 $data["unmatched"] = array();
 // unmatched record rows
 // pre-load dns record types
 $domain_record_types = sql_get_singlecol("SELECT type as value FROM dns_record_types");
 switch ($import_upload_type) {
     case "file_bind_8":
         /*
         	Bind 8/9 Zonefile
         
         	The following code reads in bind 8/9 zonefiles and pulls all the data that we can interpate
         	into an array structure that is then returned to a form page.
         
         	For more information about the file format, refer to RFC 1035
         	http://tools.ietf.org/html/rfc1035
         */
         // open the file and read data
         if ($zonefile = file($_FILES["import_upload_file"]["tmp_name"])) {
             log_write("debug", "process", "Processing file " . $_FILES["import_upload_file"]["name"] . "");
             foreach ($zonefile as $line) {
 function action_delete()
 {
     log_debug("service_groups", "Executing action_delete()");
     $id_parent = sql_get_singlevalue("SELECT id_parent AS value FROM service_groups WHERE id='{$this->id}' LIMIT 1");
     $child_groups = sql_get_singlecol("SELECT id AS col FROM service_groups WHERE id_parent='{$this->id}'");
     //exit("<pre>".print_r($child_groups,true)."</pre>");
     /*
     	Start Transaction
     */
     $sql_obj = new sql_query();
     $sql_obj->trans_begin();
     /*
     	Delete service group
     */
     $sql_obj->string = "DELETE FROM service_groups WHERE id='" . $this->id . "' LIMIT 1";
     $sql_obj->execute();
     $child_count = count($child_groups);
     if ($child_count > 0) {
         $sql_obj->string = "UPDATE `service_groups` SET `id_parent` = '{$id_parent}' WHERE `id` IN('" . implode("', '", $child_groups) . "') LIMIT {$child_count};";
         $sql_obj->execute();
     }
     /*
     	Commit
     */
     if (error_check()) {
         $sql_obj->trans_rollback();
         log_write("error", "service_groups", "An error occured whilst trying to delete the service group.");
         return 0;
     } else {
         $sql_obj->trans_commit();
         log_write("notification", "service_groups", "Service group has been successfully deleted.");
         return 1;
     }
 }
Esempio n. 7
0
 function invoice_date_calc()
 {
     log_write("debug", "inc_customers", "Executing invoice_date_calc()");
     // we add all the dates to the array and choose the latest date
     $dates = array();
     // next service billing date
     if ($GLOBALS["config"]["ORDERS_BILL_ONSERVICE"] == 1) {
         log_write("debug", "inc_customers", "Fetching latest service billing dates for  customer " . $this->id . "");
         // check the next service billing date
         $service_ids = sql_get_singlecol("SELECT id as value FROM services_customers WHERE customerid='" . $this->id . "'");
         if (is_array($service_ids)) {
             foreach ($service_ids as $serviceid) {
                 $obj_sql = new sql_query();
                 $obj_sql->string = "SELECT date_billed FROM services_customers_periods WHERE id_service_customer='" . $serviceid . "' ORDER BY id DESC LIMIT 1";
                 $obj_sql->execute();
                 if ($obj_sql->num_rows()) {
                     $obj_sql->fetch_array();
                     $dates[] = $obj_sql->data[0]["date_billed"];
                 }
                 log_write("debug", "inc_customers", "No periods exist for id_service_customer of " . $serviceid . ", perhaps this service has yet to be activated");
             }
         }
     }
     // end of month date
     if ($GLOBALS["config"]["ORDERS_BILL_ENDOFMONTH"] == 1) {
         log_write("debug", "inc_customers", "Fetching end of month date");
         $dates[] = time_calculate_monthdate_last(date("Y-m-d"));
     }
     // determine the latest date
     $timestamp_today = time_date_to_timestamp(date("Y-m-d"));
     // we use this to avoid hours/mins
     $timestamp_nextbill;
     foreach ($dates as $date) {
         $date_t = explode("-", $date);
         $date_t = mktime(0, 0, 0, $date_t[1], $date_t[2], $date_t[0]);
         if ($date_t >= $timestamp_today) {
             // future date
             if (empty($timestamp_nextbill)) {
                 $timestamp_nextbill = $date_t;
             } else {
                 if ($date_t < $timestamp_nextbill) {
                     // closer than current date
                     $timestamp_nextbill = $date_t;
                 }
             }
         }
     }
     if (empty($timestamp_nextbill)) {
         $date = "Manual Invoice Only";
     } else {
         $date = date("Y-m-d", $timestamp_nextbill);
     }
     log_write("debug", "inc_customers", "Calculated next billing date for customer orders to be \"{$date}\"");
     return $date;
 }