/** * General function to receive * * @return array list of files received */ public function receive() { foreach (Billrun_Factory::config()->getConfigValue('ilds.providers', array()) as $type) { if (!file_exists($this->workspace . DIRECTORY_SEPARATOR . $type)) { Billrun_Factory::log()->log("NOTICE : SKIPPING {$type} !!! directory " . $this->workspace . DIRECTORY_SEPARATOR . $type . " not found!!", Zend_Log::NOTICE); continue; } $files = scandir($this->workspace . DIRECTORY_SEPARATOR . $type); $ret = array(); static::$type = $type; foreach ($files as $file) { $path = $this->workspace . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $file; if (is_dir($path) || $this->lockFileForReceive($file, $type) || !$this->isFileValid($file, $path)) { continue; } $fileData = $this->getFileLogData($file, $type); $fileData['path'] = $path; if (!empty($this->backupPaths)) { $backedTo = $this->backup($fileData['path'], $file, $this->backupPaths, FALSE, FALSE); Billrun_Factory::dispatcher()->trigger('beforeReceiverBackup', array($this, &$fileData['path'])); $fileData['backed_to'] = $backedTo; Billrun_Factory::dispatcher()->trigger('afterReceiverBackup', array($this, &$fileData['path'])); } $this->logDB($fileData); $ret[] = $fileData['path']; } $this->processType($type); } return $ret; }
protected function isOn() { if (Billrun_Factory::config()->getConfigValue($this->getRequest()->action)) { return true; } return false; }
public function indexAction() { $this->redirect('admin'); $this->getView()->title = "BillRun | The best open source billing system"; $this->getView()->content = "Open Source Last Forever!"; $this->getView()->favicon = Billrun_Factory::config()->getConfigValue('favicon'); }
public function __construct($options = array()) { parent::__construct($options); if (isset($options['filename_regex'])) { $this->filenameRegex = $options['filename_regex']; } if (isset($options['receiver']['limit']) && $options['receiver']['limit']) { $this->setLimit($options['receiver']['limit']); } if (isset($options['receiver']['preserve_timestamps'])) { $this->preserve_timestamps = $options['receiver']['preserve_timestamps']; } if (isset($options['backup_path'])) { $this->backupPaths = $options['backup_path']; } else { $this->backupPaths = Billrun_Factory::config()->getConfigValue($this->getType() . '.backup_path', array('./backups/' . $this->getType())); } if (isset($options['receiver']['backup_granularity']) && $options['receiver']['backup_granularity']) { $this->setGranularity((int) $options['receiver']['backup_granularity']); } if (Billrun_Util::getFieldVal($options['receiver']['backup_date_fromat'], false)) { $this->setBackupDateDirFromat($options['receiver']['backup_date_fromat']); } if (isset($options['receiver']['orphan_time']) && (int) $options['receiver']['orphan_time'] > 900) { $this->file_fetch_orphan_time = $options['receiver']['orphan_time']; } }
/** * Get the data resource * * @return Mongo Cursor */ public function getData($filter_query = array()) { $cursor = $this->collection->query($filter_query)->cursor()->setReadPreference(Billrun_Factory::config()->getConfigValue('read_only_db_pref')); $this->_count = $cursor->count(); $resource = $cursor->sort($this->sort)->skip($this->offset())->limit($this->size); return $resource; }
/** * * @param type $items * @param type $pluginName * @return array */ public function handlerMarkDown(&$items, $pluginName) { if ($pluginName != $this->getName() || !$items) { return; } $archive = Billrun_Factory::db(Billrun_Factory::config()->getConfigValue('archive.db'))->linesCollection(); Billrun_Factory::log()->log("Marking down archive lines For archive plugin", Zend_Log::INFO); $options = array(); $this->data = array(); foreach ($items as $item) { $current = $item->getRawData(); $options['w'] = 1; try { $insertResult = $archive->insert($current, $options); if ($insertResult['ok'] == 1) { Billrun_Factory::log()->log("line with the stamp: " . $current['stamp'] . " inserted to the archive", Zend_Log::DEBUG); $this->data[] = $current; } else { Billrun_Factory::log()->log("Failed insert line with the stamp: " . $current['stamp'] . " to the archive", Zend_Log::WARN); } } catch (Exception $e) { Billrun_Factory::log()->log("Failed insert line with the stamp: " . $current['stamp'] . " to the archive got Exception : " . $e->getCode() . " : " . $e->getMessage(), Zend_Log::ERR); if ($e->getCode() == "11000") { // duplicate => already exists $this->data[] = $current; } } } return TRUE; }
/** * method that outputs account, subscribers and usage of requested accounts and requested date usage * it's called automatically by the api main controller */ public function execute() { Billrun_Factory::log()->log("Execute data triggers", Zend_Log::INFO); $request = $this->getRequest()->getRequest(); // supports GET / POST requests $params = array('plan', 'data_usage', 'from_account_id', 'to_account_id', 'billrun'); foreach ($params as $param) { if (!isset($request[$param])) { $msg = 'Missing required parameter: ' . $param; Billrun_Factory::log()->log($msg, Zend_Log::ERR); $this->getController()->setOutput(array(array('status' => 0, 'desc' => 'failed', 'output' => $msg))); return; } } Billrun_Factory::log()->log("Request params Received: plan-" . $request['plan'] . ", data_usage-" . $request['data_usage'] . ", from_account_id-" . $request['from_account_id'] . ", to_account_id-" . $request['to_account_id'] . ", billrun-" . $request['billrun'], Zend_Log::INFO); $balances = new BalancesModel(array('size' => Billrun_Factory::config()->getConfigValue('balances.accounts.limit', 50000))); $results = $balances->getBalancesVolume($request['plan'], $request['data_usage'], $request['from_account_id'], $request['to_account_id'], $request['billrun']); if (empty($results)) { Billrun_Factory::log()->log('Some error happen, no result, received parameters: ' . print_r($request, true), Zend_Log::ERR); return; } $counter = 0; $accounts = array(); foreach ($results as $result) { $accounts['aid'][$result['aid']]['subs'][$result['sid']] = Billrun_Util::byteFormat($result['balance']['totals']['data']['usagev'], 'MB', 2, false, '.', ''); $counter++; } $this->getController()->setOutput(array(array('status' => 1, 'desc' => 'success', 'subscribers_count' => $counter, 'output' => $accounts))); return true; }
public function __construct() { $this->record_types = Billrun_Factory::config()->getConfigValue('016_one_way.identifications.record_types', array('30')); $this->filename = date('Ymd', time()) . '.TXT'; $this->output_path = Billrun_Factory::config()->getConfigValue('016_one_way.export.path', '/var/www/billrun/workspace/016_one_way/Treated/') . DIRECTORY_SEPARATOR . $this->filename; $this->access_price = round(Billrun_Factory::config()->getConfigValue('016_one_way.access_price', 1.0), 2); $this->lines_coll = Billrun_Factory::db()->linesCollection(); }
protected function initThings() { $config_path = Billrun_Factory::config()->getConfigValue('compare.config_path', '/var/www/billrun/conf/compare/config.ini'); $config = (new Yaf_Config_Ini($config_path))->toArray(); $this->included_accounts = array_unique(isset($config['include_accounts']) ? $config['include_accounts'] : array()); $this->excluded_accounts = array_unique(isset($config['exclude_accounts']) ? $config['exclude_accounts'] : array()); $this->excluded_ndcsns = array_unique(isset($config['exclude_ndcsns']) ? $config['exclude_ndcsns'] : array()); }
/** * Add data that is needed to use the event object/DB document later * @param Array|Object $event the event to add fields to. * @return Array|Object the event object with added fields */ protected function addAlertData(&$newEvent) { $newEvent['units'] = 'MIN'; $newEvent['value'] = $newEvent['total']; $newEvent['threshold'] = Billrun_Factory::config()->getConfigValue('ilds.threshold', 100); $newEvent['event_type'] = 'ILDS'; $newEvent['msisdn'] = $newEvent['caller_phone_no']; return $newEvent; }
/** * * @param \MongoDb $db * @param \Mongodloid_Connection $connection */ public function __construct(\MongoDb $db, \Mongodloid_Connection $connection) { parent::__construct($db, $connection); $this->collections = Billrun_Factory::config()->getConfigValue('db.collections', array()); $timeout = Billrun_Factory::config()->getConfigValue('db.timeout', 3600000); // default 60 minutes Billrun_Factory::log()->log('Set database cursor timeout to: ' . $timeout, Zend_Log::INFO); MongoCursor::$timeout = $timeout; }
public function __construct($options) { parent::__construct($options); $this->reportType = isset($options['report_type']) ? $options['report_type'] : $this->reportType; $this->reportBasePath = Billrun_Factory::config()->getConfigValue($this->reportType . '.reports.path', './'); $this->types = Billrun_Factory::config()->getConfigValue($this->reportType . '.reports.types', array('I' => 'International', 'M' => 'Mobile', 'N' => 'National', '4' => 'National', 'P' => 'National', 'Un' => 'Other')); $this->startDate = isset($options['start_date']) ? strtotime($options['start_date']) : (strlen($this->stamp) > 8 ? strtotime($this->stamp) : Billrun_Util::getLastChargeTime(true)); $this->endDate = isset($options['end_date']) ? strtotime($options['end_date']) : strtotime(date('Ymt', $this->startDate)); }
public function __construct($options) { parent::__construct($options); if (isset($options['export-path']) && true !== $options['export-path']) { $this->exportDir = $options['export-path']; } else { $this->exportDir = Billrun_Factory::config()->getConfigValue('response.export.path', './'); $this->exportFromConfig = true; } }
public function _initLayout(Yaf_Dispatcher $dispatcher) { // Enable template layout only on admin // TODO: make this more accurate if (strpos($dispatcher->getRequest()->getRequestUri(), "admin") !== FALSE && strpos($dispatcher->getRequest()->getRequestUri(), "edit") === FALSE && strpos($dispatcher->getRequest()->getRequestUri(), "confirm") === FALSE && strpos($dispatcher->getRequest()->getRequestUri(), "logDetails") === FALSE) { $path = Billrun_Factory::config()->getConfigValue('application.directory'); $view = new Yaf_View_Simple($path . '/views/layout'); $dispatcher->setView($view); } }
public function __construct(array $params = array()) { if (isset($params['collection'])) { unset($params['collection']); } parent::__construct($params); $this->collection = Billrun_Factory::db(Billrun_Factory::config()->getConfigValue('fraud.db'))->eventsCollection(); $this->collection_name = 'events'; $this->search_key = "stamp"; }
/** * method to receive the balances lines that over requested date usage * * @return Mongodloid_Cursor Mongo cursor for iteration */ public function getBalancesVolume($plan, $data_usage, $from_account_id, $to_account_id, $billrun) { $params = array('name' => $plan, 'time' => Billrun_Util::getStartTime($billrun)); $plan_id = Billrun_Factory::plan($params); $id = $plan_id->get('_id')->getMongoID(); $data_usage_bytes = Billrun_Util::megabytesToBytesFormat((int) $data_usage); $query = array('aid' => array('$gte' => (int) $from_account_id, '$lte' => (int) $to_account_id), 'billrun_month' => $billrun, 'balance.totals.data.usagev' => array('$gt' => (double) $data_usage_bytes), 'current_plan' => Billrun_Factory::db()->plansCollection()->createRef($id)); // print_R($query);die; return $this->collection->query($query)->cursor()->setReadPreference(Billrun_Factory::config()->getConfigValue('read_only_db_pref'))->hint(array('aid' => 1, 'billrun_month' => 1))->limit($this->size); }
protected function initPlans() { $plans_coll = Billrun_Factory::db()->plansCollection(); $plans = $plans_coll->query()->cursor()->setReadPreference(Billrun_Factory::config()->getConfigValue('read_only_db_pref')); foreach ($plans as $plan) { $plan->collection($plans_coll); self::$plans['by_id'][strval($plan->getId())] = $plan; self::$plans['by_name'][$plan['name']][] = array('plan' => $plan, 'from' => $plan['from'], 'to' => $plan['to']); } }
/** * load the ggsn rates to be used later. */ protected function loadRates() { $rates_coll = Billrun_Factory::db()->ratesCollection(); $rates = $rates_coll->query($this->rateKeyMapping)->cursor()->setReadPreference(Billrun_Factory::config()->getConfigValue('read_only_db_pref')); $this->rates = array(); foreach ($rates as $value) { $value->collection($rates_coll); $this->rates[] = $value; } }
/** * Caches the rates in the memory for fast computations */ protected function loadRates() { $rates_coll = Billrun_Factory::db()->ratesCollection(); $query = array('rates.service' => array('$exists' => 1)); $rates = $rates_coll->query($query)->cursor()->setReadPreference(Billrun_Factory::config()->getConfigValue('read_only_db_pref')); $this->rates = array(); foreach ($rates as $rate) { $rate->collection($rates_coll); $this->rates[] = $rate; } }
/** * Caches the rates in the memory for fast computations */ protected function loadRates() { $rates_coll = Billrun_Factory::db()->ratesCollection(); $query = array('key' => array('$in' => array('CREDIT_VATABLE', 'CREDIT_VAT_FREE'))); $rates = $rates_coll->query($query)->cursor()->setReadPreference(Billrun_Factory::config()->getConfigValue('read_only_db_pref')); $this->rates = array(); foreach ($rates as $rate) { $rate->collection($rates_coll); $this->rates[$rate['key']] = $rate; } }
public function __construct($options = array()) { parent::__construct($options); $configPath = Billrun_Factory::config()->getConfigValue($this->getType() . '.billrun.config_path'); if ($configPath) { $config = new Yaf_Config_Ini($configPath); if (isset($config->billrun->exclude)) { $this->excludes = $config->billrun->exclude->toArray(); } } }
protected static function initCollection($collection_name) { if (isset(self::$keys[$collection_name])) { $coll = Billrun_Factory::db()->{$collection_name . "Collection"}(); $resource = $coll->query()->cursor()->setReadPreference(Billrun_Factory::config()->getConfigValue('read_only_db_pref')); foreach ($resource as $entity) { $entity->collection($coll); self::$entities[$collection_name]['by_id'][strval($entity->getId())] = $entity; self::$entities[$collection_name]['by_key'][$entity[self::$keys[$collection_name]]][] = $entity; } } }
public function prev_calc($value) { $val = $value[0]; $names = Billrun_Factory::config()->getConfigValue('queue.calculators'); if ($val != $names[0]) { $key = array_search($val, $names); $prev = $names[$key - 1]; } else { $prev = false; } return array($prev); }
/** * for every rate who has ref to original plan add ref to new plan * @param type $source_id * @param type $new_id */ public function duplicate_rates($source_id, $new_id) { $rates_col = Billrun_Factory::db()->ratesCollection(); $source_ref = MongoDBRef::create("plans", $source_id); $dest_ref = MongoDBRef::create("plans", $new_id); $usage_types = Billrun_Factory::config()->getConfigValue('admin_panel.line_usages'); foreach ($usage_types as $type => $string) { $attribute = "rates." . $type . ".plans"; $query = array($attribute => $source_ref); $update = array('$push' => array($attribute => $dest_ref)); $params = array("multiple" => 1); $rates_col->update($query, $update, $params); } }
/** * method which run when the app running from command line. * @return void * @since 1.0 */ public function indexAction() { // add log to stdout when we are on cli Billrun_Log::getInstance()->addWriter(new Zend_Log_Writer_Stream('php://stdout')); $this->addOutput("Running Billrun from CLI!"); $this->addOutput("Running under : '" . Billrun_Factory::config()->getEnv() . "' configuration."); //Go through all actions and run the first one that was selected foreach (array_keys($this->actions) as $val) { if (isset($this->options->{$val})) { $this->addOutput(ucfirst($val) . "..."); $this->forward($val); } } }
public function __construct($options) { parent::__construct($options); if (isset($options['workspace'])) { $this->workspace = $options['workspace']; } else { $this->workspace = Billrun_Factory::config()->getConfigValue('response.workspace'); } if (isset($options['backup'])) { $this->workspace = $options['backup']; } else { $defBackup = Billrun_Factory::config()->getConfigValue('response.backup'); $this->workspace = Billrun_Factory::config()->getConfigValue(static::type . '.backup', $defBackup); } }
/** * filter the record row data fields from the records * (The required field can be written in the config using <type>.fields_filter) * @param Array $rawRow the full data record row. * @return Array the record row with filtered only the requierd fields in it * or if no filter is defined in the configuration the full data record. */ protected function filterFields($rawRow) { $row = array(); $requiredFields = Billrun_Factory::config()->getConfigValue(static::$type . '.fields_filter', array(), 'array'); if (!empty($requiredFields)) { foreach ($requiredFields as $field) { if (isset($rawRow[$field])) { $row[$field] = $rawRow[$field]; } } } else { return $rawRow; } return $row; }
/** * * @param \MongoDb $db * @param \Mongodloid_Connection $connection */ public function __construct(\MongoDb $db, \Mongodloid_Connection $connection) { parent::__construct($db, $connection); // TODO: refatoring the collections to factory (loose coupling) $this->collections = Billrun_Factory::config()->getConfigValue('db.collections', array()); $timeout = Billrun_Factory::config()->getConfigValue('db.timeout', 3600000); // default 60 minutes if ($this->compareClientVersion('1.5.3', '<')) { Billrun_Factory::log()->log('Set database cursor timeout to: ' . $timeout, Zend_Log::INFO); @(MongoCursor::$timeout = $timeout); } else { // see also bugs: // https://jira.mongodb.org/browse/PHP-1099 // https://jira.mongodb.org/browse/PHP-1080 $db->setWriteConcern($db->getWriteConcern()['w'], $timeout); } }
/** * back up retrived files that were processed to a third patry path. * @param \Billrun_Processor $processor the processor instace contain the current processed file data. */ public function afterProcessorStore(\Billrun_Processor $processor) { if ($processor->getType() != $this->getName()) { return; } $path = Billrun_Factory::config()->getConfigValue('ggsn.thirdparty.backup_path', false, 'string'); if (!$path) { return; } if ($processor->retrievedHostname) { $path = $path . DIRECTORY_SEPARATOR . $processor->retrievedHostname; } Billrun_Factory::log()->log("Saving file to third party at : {$path}", Zend_Log::INFO); if (!$processor->backupToPath($path, true)) { Billrun_Factory::log()->log("Couldn't save file to third patry path at : {$path}", Zend_Log::ERR); } }
/** * Check the received files sequence. * @param type $receiver * @param type $filepaths * @param type $hostname * @return type * @throws Exception */ public function afterFTPReceived($receiver, $filepaths, $hostname) { if ($receiver->getType() != 'smsc' && $receiver->getType() != "smpp" && $receiver->getType() != "mmsc") { return; } $this->checkFilesSeq($filepaths, $hostname); $path = Billrun_Factory::config()->getConfigValue($receiver->getType() . '.thirdparty.backup_path', false, 'string'); if (!$path) { return; } if ($hostname) { $path = $path . DIRECTORY_SEPARATOR . $hostname; } foreach ($filepaths as $filePath) { if (!$receiver->backupToPath($filePath, $path, true, true)) { Billrun_Factory::log()->log("Couldn't save file {$filePath} to third patry path at : {$path}", Zend_Log::ERR); } } }