Projekt

Obecné

Profil

<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is released under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/

/**
* Controller used for communication between Freenetis and other remote devices,
* for example network gateways, routers, access points etc.
*
* @author Jiri Svitak
* @package Controller
*/
class Web_interface_Controller extends Controller
{

/**
* Index prints about message
*/
public function index()
{
echo __('Interface for communication over http protocol with remote devices');
}

/**
* Prints to output all subnets which have enabled redirection.
* Any IP address belonging to these subnet ranges can be redirected.
*
* @author Jiri Svitak
* @return unknown_type
*/
public function redirected_ranges()
{
$ranges = ORM::factory('subnet')->get_redirected_ranges();
foreach ($ranges as $range)
{
echo "$range->subnet_range\n";
}
}

/**
* Prints all allowed IP addresses.
* These are registered IP addresses, which have no redirection set.
* Unknown IP addresses (not present in system) and
* IP addresses with a redirection set are not exported.
*
* @author Jiri Svitak
* @return unknown_type
*/
public function allowed_ip_addresses()
{
$ips = ORM::factory('ip_address')->get_allowed_ip_addresses();
foreach ($ips as $ip)
{
echo "$ip->ip_address\n";
}
}

public function self_cancelable_ip_addresses()
{
$ips = ORM::factory('ip_address')->get_ip_addresses_with_self_cancel();

foreach ($ips as $ip)
{
echo "$ip->ip_address\n";
}
}

/**
* Function is used for VoIP callback.
* @param integer $user
* @param string $pass
* @param integer $number
*/
public function callback($user = null, $pass = null, $number = null)
{

if ($user == null || $pass == null || $number == null)
{
echo 'No input data';
exit;
}

if (!valid::digit($user) || !valid::digit($number))
{
echo 'Not valid input data';
exit;
}

$voip = ORM::factory('voip_sip')->get_voip_sip_by_name($user);

if (count($voip) == 0 || $voip->current()->secret != $pass)
{
echo 'Bad user or password';
exit;
}
else
{
$this->settings = new Settings();

$asm = new AsteriskManager();

$ahostname = $this->settings->get('voip_asterisk_hostname');
$auser = $this->settings->get('voip_asterisk_user');
$apass = $this->settings->get('voip_asterisk_pass');

if ($ahostname == null ||
$ahostname == '' ||
$auser == null ||
$auser == '' ||
$apass == null ||
$apass == '')
{
echo 'Error. Check freenetis settings.';
exit;
}

if ($asm->connect($ahostname, $auser, $apass))
{
//http://www.voip-info.org/wiki/index.php?page=Asterisk+Manager+API+Action+Originate
$call = $asm->Originate(
'SIP/' . $user, $number, 'internal', 1,
$application = NULL, $data = NULL,
30000, $user, $variable = NULL,
$account = NULL, 'Async',
$actionid = NULL
);
$asm->disconnect();
echo 'Success';
}
else
{
echo 'Error. Could not connect to server.';
}
}
}

/**
* Returns IP addresses of the most traffic-active members
*
* @author Michal Kliment
*/
public function active_traffic_members_ip_addresses()
{
$ips = ORM::factory('member')->get_active_traffic_members_ip_addresses();

foreach ($ips as $ip)
{
echo "$ip->ip_address\n";
}
}

/**
* Generates authorized keys to device
*
* @author Michal Kliment
* @param integer $device_id
* @return mixed
*/
public function authorized_keys($device_id = NULL)
{
// device_id is set
if ($device_id && is_numeric($device_id))
{
// finds all keys by device
$keys = ORM::factory('users_key')->get_keys_by_device($device_id);
}
// prints all keys
else
{
// finds all keys
$keys = ORM::factory('users_key')->orderby('user_id')->find_all();
}

echo "#\n";
echo "# Generated by Freenetis at " . date("Y-m-d H:i:s") . "\n";
echo "#\n";

foreach ($keys as $key)
{
echo "$key->key\n";
}
}

/**
* Prints all user's keys
*
* @author Michal Kliment
* @param integer $user_id
* @return mixed
*/
public function key($user_id = NULL)
{
// bad parameter
if (!$user_id || !is_numeric($user_id))
return;

// finds all keys by user
$keys = ORM::factory('users_key')->where('user_id', $user_id)->find_all();

foreach ($keys as $key)
{
echo "$key->key\n";
}
}
public function members_qos_ceil_rate()
{
if (!Settings::get('qos_enabled'))
return;
$total = network::speed_size(Settings::get('qos_total_speed'),"M");
$members_upload_rate = $total['upload'];
$members_download_rate = $total['download'];
if (Settings::get('ulogd_enabled'))
{
$active = network::speed_size(Settings::get('qos_active_speed'),"M");
$members_upload_rate -= $active['upload'];
$members_download_rate -= $active['download'];
}
$rows = '';
$i = 4;
$total_upload_rate = 0;
$total_download_rate = 0;
$members = ORM::factory('member')->get_members_qos_ceil_rate();
foreach ($members as $member)
{
$qos_ceil = network::speed_size($member->qos_ceil,"M");
$qos_rate = network::speed_size($member->qos_rate,"M");
$total_upload_rate += $qos_rate['upload'];
$total_download_rate += $qos_rate['download'];
$rows .= "$i\t";
$rows .= num::decimal_point($qos_ceil['upload'])."M\t";
$rows .= num::decimal_point($qos_ceil['download'])."M\t";
$rows .= num::decimal_point($qos_rate['upload'])."M\t";
$rows .= num::decimal_point($qos_rate['download'])."M\t";
$rows .= "1\t";
$rows .= "member_".($i-3)."\n";
$i++;
}
if ($members_upload_rate > $total_upload_rate
&& $members_download_rate > $total_download_rate)
{
$members_upload_rate -= $total_upload_rate;
$members_download_rate -= $total_download_rate;
echo "1\t".$total['upload']."M\t".$total['download']."M\t".$total['upload']."M\t".$total['download']."M\n";
echo "2\t0M\t0M\t".num::decimal_point($members_upload_rate)."M\t".num::decimal_point($members_download_rate)."M\t1\n";
if (Settings::get('ulogd_enabled'))
echo "3\t0M\t0M\t".$active['upload']."M\t".$active['download']."M\t1\tactive\n";
echo $rows;
}
else
{
echo "1\t".$total['upload']."M\t".$total['download']."M\t".$total['upload']."M\t".$total['download']."M\n";
echo "2\t0M\t0M\t".num::decimal_point($members_upload_rate)."M\t".num::decimal_point($members_download_rate)."M\t1\n";
if (Settings::get('ulogd_enabled'))
echo "3\t0M\t0M\t".$active['upload']."M\t".$active['download']."M\t1\tactive\n";
}
}
public function ip_addresses_qos_ceil_rate()
{
if (!Settings::get('qos_enabled'))
return;
$ips = ORM::factory('member')->get_active_traffic_members_ip_addresses();

foreach ($ips as $ip)
{
echo "3\t$ip->ip_address\n";
}
$ip_addresses = ORM::factory('ip_address')->get_ip_addresses_qos_ceil_rate();
$i = 3;
$member_id = 0;
foreach ($ip_addresses as $ip_address)
{
if ($ip_address->member_id != $member_id)
{
$i++;
$member_id = $ip_address->member_id;
}
echo "$i\t$ip_address->ip_address\n";
}
}

}
(75-75/77)