Revize 899
Přidáno uživatelem Jiří Sviták před více než 13 roky(ů)
freenetis/branches/redirection/application/i18n/cs_CZ/texts.php | ||
---|---|---|
'generate address book' => 'Vytvořit telefonní adresář',
|
||
'generate dhcp files' => 'Generovat soubory DHCP',
|
||
'generate forward dns files' => 'Generovat dopředné soubory DNS',
|
||
'generate htaccess' => 'Vygenerovat htaccess',
|
||
'generate mac restriction files' => 'Generovat soubory MAC restrikcí',
|
||
'generate reverse dns files' => 'Generovat zpětné soubory DNS',
|
||
'generate smokeping configuration file' => 'Generovat konfigurační soubor smokepingu',
|
freenetis/branches/redirection/application/vendors/redirection/freenetis.cfg | ||
---|---|---|
#! /bin/bash
|
||
##################################################################################
|
||
# #
|
||
# This script serves for redirection ip policy of IS FreeNetIS #
|
||
# #
|
||
# auhtor Sevcik Roman 2011 #
|
||
# email sevcik.roman@slfree.net #
|
||
# #
|
||
# name frnts_synchronization.sh #
|
||
# version 1.9 #
|
||
# #
|
||
##################################################################################
|
||
|
||
|
||
#Local variable contains ip address useful for self-canceling. More infos in doc
|
||
IP_TARGET=192.168.1.1
|
||
|
||
#Local variable contains port number to be redirect from - mandatory
|
||
PORT_WEB=80
|
||
|
||
#Local variable contains port number to be redirect to - mandatory
|
||
PORT_REDIRECT=36000
|
||
|
||
#Delay in seconds between next update cycle
|
||
DELAY=10
|
||
|
||
#Input interface on which will be rules aplicated
|
||
INPUT_INTERFACE=eth0
|
||
|
||
#URL of pages which we need to dowload from freenetis.
|
||
#SET_URL_RANGES - contains list of CIDR networks (e.g. 192.160.0/23) which we can regirect
|
||
#SET_URL_WHITELIST - contains list of "whitelisted" IP addresses of members will not be redirect. Never
|
||
#SET_URL_ALLOWED - contains list of IP allowed adresses will not be redirect
|
||
#SET_URL_SELF_CANCEL - contains list of IP adresses which can disable redirection itself
|
||
#SET_URL_SEEN - ulpoads list of IP adresses which have already disabled redirection itsef
|
||
|
||
SET_URL_RANGES=http://<hostname>/cs/web_interface/redirected_ranges
|
||
SET_URL_WHITELIST=http://<hostname>/cs/web_interface/whitelist
|
||
SET_URL_ALLOWED=http://<hostname>/cs/web_interface/allowed_ip_addresses
|
||
SET_URL_SELF_CANCEL=http://<hostname>/cs/web_interface/self_cancelable_ip_addresses
|
||
SET_URL_SEEN=http://<hostname>/cs/web_interface/already_seen
|
||
#! /bin/bash
|
||
##################################################################################
|
||
# #
|
||
# This script serves for redirection ip policy of IS FreeNetIS #
|
||
# #
|
||
# auhtor Sevcik Roman 2011 #
|
||
# email sevcik.roman@slfree.net #
|
||
# #
|
||
# name frnts_synchronization.sh #
|
||
# version 1.9 #
|
||
# #
|
||
##################################################################################
|
||
|
||
|
||
#Local variable contains ip address useful for self-canceling. More infos in doc
|
||
IP_TARGET=192.168.1.1
|
||
|
||
#Local variable contains port number to be redirect from - mandatory
|
||
PORT_WEB=80
|
||
|
||
#Local variable contains port number to be redirect to - mandatory
|
||
PORT_REDIRECT=36000
|
||
|
||
#Delay in seconds between next update cycle
|
||
DELAY=10
|
||
|
||
#Input interface on which will be rules aplicated
|
||
INPUT_INTERFACE=eth0
|
||
|
||
#URL of pages which we need to dowload from freenetis.
|
||
#SET_URL_RANGES - contains list of CIDR networks (e.g. 192.160.0/23) which we can regirect
|
||
#SET_URL_WHITELIST - contains list of "whitelisted" IP addresses of members will not be redirect. Never
|
||
#SET_URL_ALLOWED - contains list of IP allowed adresses will not be redirect
|
||
#SET_URL_SELF_CANCEL - contains list of IP adresses which can disable redirection itself
|
||
#SET_URL_SEEN - uploads list of IP adresses which have already disabled redirection itsef
|
||
|
||
SET_URL_RANGES=http://<hostname>/cs/web_interface/redirected_ranges
|
||
SET_URL_WHITELIST=http://<hostname>/cs/web_interface/whitelist
|
||
SET_URL_ALLOWED=http://<hostname>/cs/web_interface/allowed_ip_addresses
|
||
SET_URL_SELF_CANCEL=http://<hostname>/cs/web_interface/self_cancelable_ip_addresses
|
||
SET_URL_SEEN=http://<hostname>/cs/web_interface/already_seen
|
freenetis/branches/redirection/application/vendors/redirection/freenetis | ||
---|---|---|
echo "Killing process."
|
||
cat $PIDFILE | xargs kill
|
||
|
||
#Detete pid file
|
||
rm $PIDFILE
|
||
#Delete pid file
|
||
rm -f $PIDFILE
|
||
|
||
echo "Deleting firewall rules.";
|
||
|
freenetis/branches/redirection/application/vendors/redirection/README | ||
---|---|---|
For more info how to install see http://wiki.freenetis.org/index.php/P%C5%99esm%C4%9Brov%C3%A1n%C3%AD
|
||
Freenetis redirection system (last update 2011-03-25)
|
||
-----------------------------------------------------
|
||
author: Jiri Svitak (jsvitak@unart.cz)
|
||
|
||
It is necesarry to have installed ipset kernel module and lightweight http
|
||
server on central netowrk gateway. Recomended system is Linux, we use Debian.
|
||
|
||
In Debian 6 is ipset already in repository.
|
||
apt-get install ipset ipset-source
|
||
m-a a-i ipset
|
||
|
||
We use lighttpd server daemon, which contains only temporary http redirection
|
||
to freenetis server. We use port 36000 for this.
|
||
apt-get install lighttpd
|
||
|
||
We use lighttpd with following configuration in /etc/lighttpd/lighttpd.conf
|
||
server.port = 36000
|
||
url.redirect = ( "." => "http://freenetis.domain.ltd" )
|
||
url.redirect-code = 307
|
||
|
||
We do not need ipv6 yet, so we can comment out this
|
||
#include_shell "/usr/share/lighttpd/use-ipv6.pl"
|
||
|
||
All three files - freenetis, freenetis.cfg, freenetis_synchronization.sh should
|
||
be placed in locations specified in their headers. Proper access rights should
|
||
have been set.
|
||
|
||
chmod 755 /etc/init.d/freenetis
|
||
chmod "a+x" /usr/local/sbin/freenetis_synchronization.sh
|
||
|
||
Script freenetis should be launched on the system start. We use
|
||
update-rc.d freenetis defaults
|
||
|
||
We can control this synchronization system by
|
||
/etc/init.d/freenetis start|stop|restart
|
||
|
||
System does not need cron, after starting system, freenetis_synchronization.sh
|
||
runs in infinite loop.
|
freenetis/branches/redirection/application/vendors/redirection/freenetis_synchronization.sh | ||
---|---|---|
#!/bin/bash
|
||
##################################################################################
|
||
# #
|
||
# This script serves for redirection ip policy of IS FreeNetIS #
|
||
# #
|
||
# auhtor Sevcik Roman 2011 #
|
||
# email sevcik.roman@slfree.net #
|
||
# #
|
||
# name frnts_synchronization.sh #
|
||
# version 1.9 #
|
||
# #
|
||
##################################################################################
|
||
|
||
#Load variables from config file
|
||
CONFIG=/etc/freenetis.cfg
|
||
|
||
#Paths where temporary data will be saved.
|
||
PATH_RANGES=/tmp/ranges
|
||
PATH_WHITELIST=/tmp/whitelist
|
||
PATH_ALLOWED=/tmp/allowed
|
||
PATH_SELF_CANCEL=/tmp/self_cancel
|
||
|
||
|
||
#Load variables
|
||
if [ -f ${CONFIG} ]; then
|
||
. $CONFIG;
|
||
else
|
||
echo "No config file - giving up :-(";
|
||
exit 0
|
||
fi
|
||
|
||
# Function returns 1 if is ip valid
|
||
# @param ip adresa
|
||
# return 1 if is ip valid
|
||
valid_ip ()
|
||
{
|
||
local ip=$1
|
||
local stat=1
|
||
|
||
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||
OIFS=$IFS
|
||
IFS='.'
|
||
ip=($ip)
|
||
IFS=$OIFS
|
||
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
|
||
stat=$?
|
||
fi;
|
||
return $stat
|
||
}
|
||
|
||
update ()
|
||
{
|
||
echo "Updating..."
|
||
|
||
#Erase content of all sets
|
||
echo "Cleaning sets...";
|
||
ipset -F whitelist
|
||
ipset -F allowed
|
||
ipset -F self_cancel
|
||
ipset -F ranges
|
||
|
||
#Send data from seen set to server
|
||
|
||
oount=0
|
||
for i in $(ipset -L seen);
|
||
do
|
||
if valid_ip $i; then
|
||
seen[count]=$i
|
||
((count++))
|
||
fi
|
||
done
|
||
|
||
OIFS=$IFS
|
||
export IFS=";"
|
||
|
||
echo "Sending seen set data...";
|
||
wget -q -O /tmp/out.txt $SET_URL_SEEN --no-check-certificate --post-data "seen=${seen[*]}"
|
||
|
||
IFS=$OIFS
|
||
|
||
unset seen
|
||
|
||
echo "Downloading data...";
|
||
wget -q -O $PATH_WHITELIST $SET_URL_WHITELIST --no-check-certificate
|
||
wget -q -O $PATH_ALLOWED $SET_URL_ALLOWED --no-check-certificate
|
||
wget -q -O $PATH_SELF_CANCEL $SET_URL_SELF_CANCEL --no-check-certificate
|
||
wget -q -O $PATH_RANGES $SET_URL_RANGES --no-check-certificate
|
||
|
||
echo "Downloading data...";
|
||
wget -q -O $PATH_WHITELIST $SET_URL_WHITELIST --no-check-certificate
|
||
wget -q -O $PATH_ALLOWED $SET_URL_ALLOWED --no-check-certificate
|
||
wget -q -O $PATH_SELF_CANCEL $SET_URL_SELF_CANCEL --no-check-certificate
|
||
wget -q -O $PATH_RANGES $SET_URL_RANGES --no-check-certificate
|
||
|
||
|
||
#Filling sets
|
||
|
||
for i in $(cat $PATH_WHITELIST);
|
||
do
|
||
echo "$i - added to set whitelist"
|
||
ipset -A whitelist $i
|
||
done
|
||
|
||
for i in $(cat $PATH_ALLOWED);
|
||
do
|
||
echo "$i - added to set allowed"
|
||
ipset -A allowed $i
|
||
done
|
||
|
||
for i in $(cat $PATH_SELF_CANCEL);
|
||
do
|
||
echo "$i - added to set self_cancel"
|
||
ipset -A self_cancel $i
|
||
done
|
||
|
||
for i in $(cat $PATH_RANGES);
|
||
do
|
||
echo "$i - added to set ranges"
|
||
ipset -A ranges $i
|
||
done
|
||
|
||
#Erase content of seen set
|
||
echo "Cleaning seen set...";
|
||
ipset -F seen
|
||
|
||
#Cleaning up...
|
||
rm $PATH_RANGES
|
||
rm $PATH_WHITELIST
|
||
rm $PATH_ALLOWED
|
||
rm $PATH_SELF_CANCEL
|
||
|
||
echo "Sleeping..."
|
||
sleep $DELAY;
|
||
}
|
||
|
||
while (true);
|
||
do
|
||
update
|
||
done
|
||
#!/bin/bash
|
||
##################################################################################
|
||
# #
|
||
# This script serves for redirection ip policy of IS FreeNetIS #
|
||
# #
|
||
# auhtor Sevcik Roman 2011 #
|
||
# email sevcik.roman@slfree.net #
|
||
# #
|
||
# name frnts_synchronization.sh #
|
||
# version 1.9 #
|
||
# #
|
||
##################################################################################
|
||
|
||
#Load variables from config file
|
||
CONFIG=/etc/freenetis.cfg
|
||
|
||
#Paths where temporary data will be saved.
|
||
PATH_RANGES=/tmp/ranges
|
||
PATH_WHITELIST=/tmp/whitelist
|
||
PATH_ALLOWED=/tmp/allowed
|
||
PATH_SELF_CANCEL=/tmp/self_cancel
|
||
|
||
|
||
#Load variables
|
||
if [ -f ${CONFIG} ]; then
|
||
. $CONFIG;
|
||
else
|
||
echo "No config file - giving up :-(";
|
||
exit 0
|
||
fi
|
||
|
||
# Function returns 1 if is ip valid
|
||
# @param ip adresa
|
||
# return 1 if is ip valid
|
||
valid_ip ()
|
||
{
|
||
local ip=$1
|
||
local stat=1
|
||
|
||
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||
OIFS=$IFS
|
||
IFS='.'
|
||
ip=($ip)
|
||
IFS=$OIFS
|
||
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
|
||
stat=$?
|
||
fi;
|
||
return $stat
|
||
}
|
||
|
||
update ()
|
||
{
|
||
echo "Updating..."
|
||
|
||
#Erase content of all sets
|
||
echo "Cleaning sets...";
|
||
ipset -F whitelist
|
||
ipset -F allowed
|
||
ipset -F self_cancel
|
||
ipset -F ranges
|
||
|
||
#Send data from seen set to server
|
||
|
||
oount=0
|
||
for i in $(ipset -L seen);
|
||
do
|
||
if valid_ip $i; then
|
||
seen[count]=$i
|
||
((count++))
|
||
fi
|
||
done
|
||
|
||
OIFS=$IFS
|
||
export IFS=";"
|
||
|
||
echo "Sending seen set data...";
|
||
wget -q -O /tmp/out.txt $SET_URL_SEEN --no-check-certificate --post-data "seen=${seen[*]}"
|
||
|
||
IFS=$OIFS
|
||
|
||
unset seen
|
||
|
||
echo "Downloading data...";
|
||
wget -q -O $PATH_WHITELIST $SET_URL_WHITELIST --no-check-certificate
|
||
wget -q -O $PATH_ALLOWED $SET_URL_ALLOWED --no-check-certificate
|
||
wget -q -O $PATH_SELF_CANCEL $SET_URL_SELF_CANCEL --no-check-certificate
|
||
wget -q -O $PATH_RANGES $SET_URL_RANGES --no-check-certificate
|
||
|
||
#Filling sets
|
||
|
||
for i in $(cat $PATH_WHITELIST);
|
||
do
|
||
echo "$i - added to set whitelist"
|
||
ipset -A whitelist $i
|
||
done
|
||
|
||
for i in $(cat $PATH_ALLOWED);
|
||
do
|
||
echo "$i - added to set allowed"
|
||
ipset -A allowed $i
|
||
done
|
||
|
||
for i in $(cat $PATH_SELF_CANCEL);
|
||
do
|
||
echo "$i - added to set self_cancel"
|
||
ipset -A self_cancel $i
|
||
done
|
||
|
||
for i in $(cat $PATH_RANGES);
|
||
do
|
||
echo "$i - added to set ranges"
|
||
ipset -A ranges $i
|
||
done
|
||
|
||
#Erase content of seen set
|
||
echo "Cleaning seen set...";
|
||
ipset -F seen
|
||
|
||
#Cleaning up...
|
||
rm -f $PATH_RANGES
|
||
rm -f $PATH_WHITELIST
|
||
rm -f $PATH_ALLOWED
|
||
rm -f $PATH_SELF_CANCEL
|
||
|
||
echo "Sleeping..."
|
||
sleep $DELAY;
|
||
}
|
||
|
||
while (true);
|
||
do
|
||
update
|
||
done
|
freenetis/branches/redirection/application/helpers/callback.php | ||
---|---|---|
}
|
||
|
||
/**
|
||
* Callback field for redirection.
|
||
* @param unknown_type $item
|
||
* @param unknown_type $name
|
||
*/
|
||
static function redirect_field($item, $name)
|
||
{
|
||
$redirstr = '';
|
||
// membership Interrupt redirection - letter I
|
||
if ($item->redirect & 1)
|
||
$redirstr .= url_lang::lang('texts.I');
|
||
// Debtor redirection - letter D
|
||
elseif ($item->redirect & 2)
|
||
$redirstr .= url_lang::lang('texts.D');
|
||
// payment Notice redirection - letter N
|
||
elseif ($item->redirect & 4)
|
||
$redirstr .= url_lang::lang('texts.N');
|
||
// Optional message redirection - letter O
|
||
elseif ($item->redirect & 8)
|
||
$redirstr .= url_lang::lang('texts.O');
|
||
// no redirection set?
|
||
if ($redirstr == '')
|
||
echo ' ';
|
||
else
|
||
echo $redirstr;
|
||
}
|
||
|
||
/**
|
||
* Callback field for member name. Leaves blank name if needed.
|
||
* @author Jiri Svitak
|
||
* @param unknown_type $item
|
||
... | ... | |
static function message_update_field($item, $name)
|
||
{
|
||
$message = new Message_Model($item->id);
|
||
if ($message->type == Message_Model::$interrupted_membership_message ||
|
||
$message->type == Message_Model::$debtor_message ||
|
||
$message->type == Message_Model::$payment_notice_message
|
||
)
|
||
if ($message->type == Message_Model::$contact_information)
|
||
{
|
||
echo html::anchor(url_lang::base().'messages/update/'.$message->id, url_lang::lang('texts.Update'));
|
||
echo ' ';
|
||
}
|
||
else
|
||
{
|
||
echo ' ';
|
||
echo html::anchor(url_lang::base().'messages/update/'.$message->id, url_lang::lang('texts.Update'));
|
||
}
|
||
}
|
||
|
freenetis/branches/redirection/application/helpers/redirect.php | ||
---|---|---|
*/
|
||
class redirect_Core
|
||
{
|
||
|
||
/**
|
||
* Replaces special tags in curly brackets {tag} by value associated to target's member IP address.
|
||
* Unknown values for tags are replaced by question mark ?.
|
||
* @author Jiri Svitak
|
||
* @param $text Input HTML stream.
|
||
* @param $ip_address Based on given IP address, dependent information in database is searched.
|
||
* @return unknown_type Output HTML stream.
|
||
*/
|
||
static function replace($text, $ip_address)
|
||
{
|
||
$ip = ORM::factory('ip_address')->where('ip_address', $ip_address)->find();
|
||
// other information dependent on IP address registered in database
|
||
if (!$ip->id)
|
||
{
|
||
$member_name = '???';
|
||
$variable_symbol = '???';
|
||
$current_credit = '???';
|
||
}
|
||
else
|
||
{
|
||
// member properties
|
||
$member_name = $ip->iface->device->user->member->name;
|
||
$variable_symbol = $ip->iface->device->user->member->variable_symbol;
|
||
// current credit
|
||
$account_balance = ORM::factory('account_balance')->where('member_id', $ip->iface->device->user->member_id)->find();
|
||
$current_credit = $account_balance->balance;
|
||
// count payment amount to end of year
|
||
|
||
}
|
||
// subnet name
|
||
$subnet_model = new Subnet_Model();
|
||
$subnet = $subnet_model->get_subnet_of_ip_address($ip_address);
|
||
if (!$subnet->id)
|
||
{
|
||
$subnet_name = '???';
|
||
}
|
||
else
|
||
{
|
||
$subnet_name = $subnet->name;
|
||
}
|
||
// ip address
|
||
$text = str_replace('{ip_address}', $ip_address, $text);
|
||
// subnet name
|
||
$text = str_replace('{subnet_name}', $subnet_name, $text);
|
||
// member name
|
||
$text = str_replace('{member_name}', $member_name, $text);
|
||
// variable symbol of member
|
||
$text = str_replace('{variable_symbol}', $variable_symbol, $text);
|
||
// current credit
|
||
$text = str_replace('{current_credit}', $current_credit, $text);
|
||
return $text;
|
||
}
|
||
|
||
|
||
/**
|
||
* Updates static html file with redirection message.
|
||
* @param $ip_address
|
||
* @return unknown_type
|
||
... | ... | |
static function update($ip_address, $contact, $content, $footer)
|
||
{
|
||
|
||
|
||
// html code to contact
|
||
$to_contact =
|
||
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
... | ... | |
fclose($file);
|
||
}
|
||
|
||
static function generate_htaccess()
|
||
{
|
||
$htaccess =
|
||
"
|
||
Order deny,allow
|
||
# access from internet is denied
|
||
Deny from all
|
||
# allow access from localhost through IPv6 and IPv4, useful for development
|
||
#Allow from ::1
|
||
Allow from 127.0.0.1
|
||
# allow access from your local network, for example network 10.0.0.0/8
|
||
Allow from 10.0.0.0/8
|
||
|
||
RewriteEngine On
|
||
|
||
# condition if requested URL contains at the end string 'static'
|
||
RewriteCond %{REQUEST_URI} static/$
|
||
# this rule causes opening of html file with name of visitor's IP address
|
||
# visitor is shown his personalised redirection message (static html page)
|
||
RewriteRule .* /freenetis/static/%{REMOTE_ADDR}.html [L]
|
||
|
||
|
||
# if visitor's IP address has not file with its name, then document is not found
|
||
# in this case not found page has the meaning that IP address is unidentified
|
||
ErrorDocument 404 /freenetis/static/unknown_device_message.html
|
||
";
|
||
$page = $htaccess;
|
||
// save page to file
|
||
$file = fopen('static/.htaccess', 'w+');
|
||
fputs($file, $page);
|
||
fclose($file);
|
||
|
||
}
|
||
|
||
}
|
freenetis/branches/redirection/application/models/message.php | ||
---|---|---|
if ($order_by == 'ip_address')
|
||
$order_by = 'inet_aton(ip_address)';
|
||
return $this->db->query("
|
||
SELECT mip.ip_address_id, ip.ip_address, m.name, mip.datetime
|
||
SELECT mip.ip_address_id, ip.ip_address, m.name AS message, mip.datetime, mip.comment, m.type
|
||
FROM messages_ip_addresses mip
|
||
LEFT JOIN ip_addresses ip ON ip.id = mip.ip_address_id
|
||
LEFT JOIN messages m ON m.id = mip.message_id
|
freenetis/branches/redirection/application/models/member.php | ||
---|---|---|
}
|
||
|
||
/**
|
||
* Function sets redirection to members, who have to pay their member fee soon
|
||
* or their's credit account will be negative. Used in scheduler/run.
|
||
* @author Jiri Svitak
|
||
* @param $low_amount low boundary of interval
|
||
* @param $high_amount high boundary of interval
|
||
* @return unknown_type
|
||
*/
|
||
public function update_payment_notice($low_amount, $high_amount)
|
||
{
|
||
// preparation
|
||
$this->db->query("UPDATE members SET redirect = redirect & ~4;");
|
||
// setting redirection
|
||
$this->db->query("
|
||
UPDATE members m,
|
||
(
|
||
SELECT IFNULL(SUM(t.amount), 0) AS outbound, q2.inbound, q2.mid
|
||
FROM
|
||
(
|
||
SELECT IFNULL(SUM(t.amount), 0) AS inbound, q1.aid, q1.mid
|
||
FROM
|
||
(
|
||
SELECT a.id AS aid, m.id AS mid
|
||
FROM accounts a
|
||
JOIN members m ON m.id = a.member_id
|
||
LEFT JOIN enum_types e ON e.id = m.type
|
||
WHERE member_id <> 1 AND account_attribute_id = ".Account_attribute_Model::$credit."
|
||
AND (e.value = 'Regular member' OR e.value = 'Former member')
|
||
) q1
|
||
LEFT JOIN transfers t ON t.destination_id = q1.aid
|
||
GROUP BY q1.aid
|
||
) q2
|
||
LEFT JOIN transfers t ON t.origin_id = q2.aid
|
||
GROUP BY q2.aid
|
||
) q3
|
||
SET m.redirect = m.redirect | 4
|
||
WHERE m.id = q3.mid AND $low_amount < (q3.inbound - q3.outbound) AND (q3.inbound - q3.outbound) < $high_amount
|
||
");
|
||
}
|
||
|
||
/**
|
||
* Function sets debtor redirection to members who have their current credit is negative.
|
||
* @author Jiri Svitak
|
||
* @return unknown_type
|
||
*/
|
||
public function update_debtors()
|
||
{
|
||
// preparation
|
||
$this->db->query("UPDATE members SET redirect = redirect & ~2;");
|
||
// setting redirection
|
||
$this->db->query("
|
||
UPDATE members m,
|
||
(
|
||
SELECT IFNULL(SUM(t.amount), 0) AS outbound, q2.inbound, q2.mid
|
||
FROM
|
||
(
|
||
SELECT IFNULL(SUM(t.amount), 0) AS inbound, q1.aid, q1.mid
|
||
FROM
|
||
(
|
||
SELECT a.id AS aid, m.id AS mid
|
||
FROM accounts a
|
||
JOIN members m ON m.id = a.member_id
|
||
LEFT JOIN enum_types e ON e.id = m.type
|
||
WHERE member_id <> 1 AND account_attribute_id = ".Account_attribute_Model::$credit."
|
||
AND (e.value = 'Regular member' OR e.value = 'Former member')
|
||
) q1
|
||
LEFT JOIN transfers t ON t.destination_id = q1.aid
|
||
GROUP BY q1.aid
|
||
) q2
|
||
LEFT JOIN transfers t ON t.origin_id = q2.aid
|
||
GROUP BY q2.aid
|
||
) q3
|
||
SET m.redirect = m.redirect | 2
|
||
WHERE m.id = q3.mid AND (q3.inbound - q3.outbound) < 0
|
||
");
|
||
}
|
||
|
||
/**
|
||
* Function sets membership interrupt redirection to all members who interrupted their membership.
|
||
* @author Jiri Svitak
|
||
* @return unknown_type
|
||
*/
|
||
public function update_membership_interrupts()
|
||
{
|
||
// preparation
|
||
$this->db->query("UPDATE members SET redirect = redirect & ~1;");
|
||
// setting redirection
|
||
$this->db->query("
|
||
UPDATE members m,
|
||
(
|
||
SELECT m.id as mid
|
||
FROM members m
|
||
JOIN membership_interrupts mi ON mi.member_id = m.id
|
||
JOIN members_fees mf ON mi.members_fee_id = mf.id
|
||
WHERE mf.activation_date <= CURDATE() AND CURDATE() <= mf.deactivation_date
|
||
) mi
|
||
SET m.redirect = m.redirect | 1
|
||
WHERE m.id = mi.mid
|
||
");
|
||
}
|
||
|
||
/**
|
||
* Function sets optional message to all members.
|
||
* @author Jiri Svitak
|
||
* @return unknown_type
|
||
*/
|
||
public function update_optional_message()
|
||
{
|
||
// setting redirection
|
||
$this->db->query("UPDATE members SET redirect = redirect | 8;");
|
||
}
|
||
|
||
/**
|
||
* Function cancels redirection of given number.
|
||
* @author Jiri Svitak
|
||
* @param $number
|
||
* @return unknown_type
|
||
*/
|
||
public function cancel_redirection($number)
|
||
{
|
||
$this->db->query("UPDATE members SET redirect = redirect & ~$number");
|
||
}
|
||
|
||
/**
|
||
* Function updates lock status.
|
||
* @author Roman Sevcik
|
||
*/
|
freenetis/branches/redirection/application/controllers/redirection.php | ||
---|---|---|
<?php
|
||
/**
|
||
* @author Lubomir Buben
|
||
*/
|
||
class Redirection_Controller extends Controller{
|
||
function index(){
|
||
url::redirect(url_lang::base().'redirection/show_all');
|
||
}
|
||
|
||
function addip($ip_address_id = NULL){
|
||
if (!$this->acl_check_new(get_class($this),'redirection'))
|
||
Controller::error(ACCESS);
|
||
|
||
if ($ip_address_id != NULL){
|
||
$ip_address_model = new ip_address_Model($ip_address_id);
|
||
$ip_address = $ip_address_model->ip_address;
|
||
}
|
||
|
||
//duration type
|
||
$redirection_duration_model = new Redirection_duration_Model();
|
||
$result = $redirection_duration_model->get_select_list();
|
||
$types_duration[0] = '----- '.url_lang::lang('texts.Select duration').' -----';
|
||
foreach($result as $row){
|
||
$types_duration[$row->id]=$row->translation;
|
||
}
|
||
asort($types_duration);
|
||
|
||
//destination type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_destination = $enum_type_model->get_values(Enum_type_Model::$redirect_destination_id);
|
||
$types_destination[0] = '----- '.url_lang::lang('texts.Select destination web').' -----';
|
||
asort($types_destination);
|
||
|
||
//username + email
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($user_model->id == 0)
|
||
Controller::error(RECORD);
|
||
|
||
$this->form = new Forge(url_lang::base()."redirection/addip", '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$this->form->group('')->label(url_lang::lang('texts.Basic information'));
|
||
|
||
if ($ip_address_id != NULL){
|
||
$this->form->input('ip_address')->label(url_lang::lang('texts.IP address').':')->rules('required|length[7,15]')->value($ip_address)->callback(array($this, 'callback_valid_ip'));
|
||
}else{
|
||
$this->form->input('ip_address')->label(url_lang::lang('texts.IP address').':')->rules('required|length[7,15]')->callback(array($this, 'callback_valid_ip'));
|
||
}
|
||
$this->form->dropdown('dur')->label(url_lang::lang('texts.Duration').':')->options($types_duration)->rules('required');
|
||
$this->form->checkbox('selfaccess')->label(url_lang::lang('texts.User can disable redirection'))->value('1')->checked(TRUE);
|
||
$this->form->dropdown('dest')->label(url_lang::lang('texts.Destination website').':')->options($types_destination)->rules('required');
|
||
$this->form->group('')->label(url_lang::lang('texts.Advanced configuration'));
|
||
$this->form->textarea('message')->label(url_lang::lang('texts.Message for user'))->rules('length[0,1023]')->value('');
|
||
$this->form->textarea('comment')->label(url_lang::lang('texts.Comment'))->rules('length[0,1023]')->value('');
|
||
$this->form->checkbox('lock')->label(url_lang::lang('texts.Lock for others'))->value('1')->checked(FALSE);
|
||
$this->form->checkbox('sendmail')->label(url_lang::lang('texts.Send e-mail notification after expiration'))->value('1')->checked(FALSE);
|
||
|
||
$this->form->submit('submit')->value(url_lang::lang('texts.Insert'));
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($this->form->validate()){
|
||
$form_data = $this->form->as_array();
|
||
foreach($form_data as $key => $value){
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
//getting ip address' id from database
|
||
$ip_address = $form_data['ip_address'];
|
||
$ip_address_model2 = new Ip_address_Model();
|
||
$result = $ip_address_model2->find_ip_address($ip_address);
|
||
if(count($result)>0){
|
||
foreach ($result as $row){
|
||
$ip_address_id = $row->id;
|
||
}
|
||
}else{
|
||
//ip address was not found in freenetis databases
|
||
$this->session->set_flash('message', url_lang::lang('texts.Cannot redirect unknown IP address.'));
|
||
url::redirect(url_lang::base().'redirection/show_all/');
|
||
exit;
|
||
}
|
||
|
||
$redirection = new Redirection_Model();
|
||
$redirection->ip_address_id = $ip_address_id;
|
||
$redirection->duration = $form_data['dur'];
|
||
$redirection->destination = $form_data['dest'];
|
||
$redirection->message = $form_data['message'];
|
||
$redirection->note = $form_data['comment'];
|
||
//LOCK
|
||
if($form_data['lock']==1)
|
||
$redirection->locksign = '1';
|
||
else
|
||
$redirection->locksign = '0';
|
||
//SELFACCESS
|
||
if($form_data['selfaccess']==1)
|
||
$redirection->selfaccess = '1';
|
||
else
|
||
$redirection->selfaccess = '0';
|
||
//SENDMAIL
|
||
if($form_data['sendmail']==1)
|
||
$redirection->sendmail = '1';
|
||
else
|
||
$redirection->sendmail = '0';
|
||
|
||
$redirection->admin = $user_id;
|
||
|
||
|
||
unset($form_data);
|
||
if ($redirection->save()) {
|
||
redirection_log::log($user_model->login, 76, $ip_address_id);
|
||
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
|
||
url::redirect(url_lang::base().'redirection/show_all/');
|
||
exit;
|
||
}
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.Redirect IP address');
|
||
$view->content = new View('form');
|
||
$view->content->link_back = html::anchor(url_lang::base().'redirection/show_all', url_lang::lang('texts.Back to the redirection list'));
|
||
$view->content->headline = url_lang::lang('texts.Redirect IP address');
|
||
$view->content->form = $this->form->html();
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
function addrange(){
|
||
if (!$this->acl_check_new(get_class($this),'redirection'))
|
||
Controller::error(ACCESS);
|
||
|
||
//duration type
|
||
$redirection_duration_model = new Redirection_duration_Model();
|
||
$result = $redirection_duration_model->get_select_list();
|
||
$types_duration[0] = '----- '.url_lang::lang('texts.Select duration').' -----';
|
||
foreach($result as $row){
|
||
$types_duration[$row->id]=$row->translation;
|
||
}
|
||
asort($types_duration);
|
||
|
||
//destination type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_destination = $enum_type_model->get_values(Enum_type_Model::$redirect_destination_id);
|
||
$types_destination[0] = '----- '.url_lang::lang('texts.Select destination web').' -----';
|
||
asort($types_destination);
|
||
|
||
//username + email
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($user_model->id == 0)
|
||
Controller::error(RECORD);
|
||
|
||
$this->form = new Forge(url_lang::base()."redirection/addrange", '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$this->form->group('')->label(url_lang::lang('texts.Basic information'));
|
||
$this->form->input('ip_range1')->label(url_lang::lang('texts.Range of IP addresses - first host').':')->rules('required|length[7,15]')->callback(array($this, 'callback_valid_ip'));
|
||
$this->form->input('ip_range2')->label(url_lang::lang('texts.Range of IP addresses - last host').':')->rules('required|length[7,15]')->callback(array($this, 'callback_valid_ip2'));
|
||
$this->form->dropdown('dur')->label(url_lang::lang('texts.Duration').':')->options($types_duration)->rules('required');
|
||
$this->form->checkbox('selfaccess')->label(url_lang::lang('texts.User can disable redirection'))->value('1')->checked(TRUE);
|
||
$this->form->dropdown('dest')->label(url_lang::lang('texts.Destination website').':')->options($types_destination)->rules('required');
|
||
$this->form->group('')->label(url_lang::lang('texts.Advanced configuration'));
|
||
$this->form->textarea('message')->label(url_lang::lang('texts.Message for user'))->rules('length[0,1023]')->value('');
|
||
$this->form->textarea('comment')->label(url_lang::lang('texts.Comment'))->rules('length[0,1023]')->value('');
|
||
$this->form->checkbox('lock')->label(url_lang::lang('texts.Lock for others'))->value('1')->checked(FALSE);
|
||
$this->form->checkbox('sendmail')->label(url_lang::lang('texts.Send e-mail notification after expiration'))->value('1')->checked(FALSE);
|
||
|
||
$this->form->submit('submit')->value(url_lang::lang('texts.Insert'));
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($this->form->validate()){
|
||
$form_data = $this->form->as_array();
|
||
foreach($form_data as $key => $value){
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
list($ip1p1, $ip1p2, $ip1p3, $ip1p4) = split('[.]', $form_data['ip_range1']);
|
||
list($ip2p1, $ip2p2, $ip2p3, $ip2p4) = split('[.]', $form_data['ip_range2']);
|
||
$range_length=$ip2p4 - $ip1p4 + 1;
|
||
|
||
//counting the range of ip addresses
|
||
$ip_address_model2 = new Ip_address_Model();
|
||
for ($i=0; $i<$range_length; $i++){
|
||
$redirected_ip = $ip1p1.".".$ip1p2.".".$ip1p3.".".($ip1p4+$i);
|
||
|
||
//getting redirected ip address' id from database
|
||
$result = $ip_address_model2->find_ip_address($redirected_ip);
|
||
if(count($result)>0){
|
||
foreach ($result as $row){
|
||
$ip_address_id = $row->id;
|
||
}
|
||
}else{
|
||
//didn't find ip address in database
|
||
continue;
|
||
}
|
||
|
||
$redirection = new Redirection_Model();
|
||
$redirection->ip_address_id = $ip_address_id;
|
||
$redirection->duration = $form_data['dur'];
|
||
$redirection->destination = $form_data['dest'];
|
||
$redirection->message = $form_data['message'];
|
||
$redirection->note = $form_data['comment'];
|
||
|
||
//LOCK
|
||
if($form_data['lock']==1)
|
||
$redirection->locksign = '1';
|
||
else
|
||
$redirection->locksign = '0';
|
||
//SELFACCESS
|
||
if($form_data['selfaccess']==1)
|
||
$redirection->selfaccess = '1';
|
||
else
|
||
$redirection->selfaccess = '0';
|
||
//SENDMAIL
|
||
if($form_data['sendmail']==1)
|
||
$redirection->sendmail = '1';
|
||
else
|
||
$redirection->sendmail = '0';
|
||
|
||
$redirection->admin = $user_id;
|
||
|
||
$redirection->save();
|
||
redirection_log::log($user_model->login, 76, $ip_address_id);
|
||
}
|
||
|
||
unset($form_data);
|
||
if (true) {
|
||
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
|
||
url::redirect(url_lang::base().'redirection/show_all/');
|
||
exit;
|
||
}
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.Redirect range of ip addresses');
|
||
$view->content = new View('form');
|
||
$view->content->link_back = html::anchor(url_lang::base().'redirection/show_all', url_lang::lang('texts.Back to the redirection list'));
|
||
$view->content->headline = url_lang::lang('texts.Redirect range of ip addresses');
|
||
$view->content->form = $this->form->html();
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
function addsubnet($subnet_id = NULL){
|
||
if (!$this->acl_check_new(get_class($this),'redirection'))
|
||
Controller::error(ACCESS);
|
||
|
||
//duration type
|
||
$redirection_duration_model = new Redirection_duration_Model();
|
||
$result = $redirection_duration_model->get_select_list();
|
||
$types_duration[0] = '----- '.url_lang::lang('texts.Select duration').' -----';
|
||
foreach($result as $row){
|
||
$types_duration[$row->id]=$row->translation;
|
||
}
|
||
asort($types_duration);
|
||
|
||
//destination type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_destination = $enum_type_model->get_values(Enum_type_Model::$redirect_destination_id);
|
||
$types_destination[0] = '----- '.url_lang::lang('texts.Select destination web').' -----';
|
||
asort($types_destination);
|
||
|
||
//username + email
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($user_model->id == 0)
|
||
Controller::error(RECORD);
|
||
|
||
//getting the list of subnets
|
||
$subnet_model = new Subnet_Model();
|
||
$subnets = $subnet_model->select("id","name","network_address as net_str",
|
||
"inet_aton(network_address) as net",
|
||
"32-log2((~inet_aton(netmask) & 0xffffffff) + 1) as mask")->orderby('name')->find_all();
|
||
$arr_subnets_netnames[]=$arr_subnets_names[] = '----- '.url_lang::lang('texts.select subnet').' -----';
|
||
$arr_subnets_ids[]=$arr_subnets_masks[]=$arr_subnets_nets[]=0;
|
||
foreach ($subnets as $subnet){
|
||
$arr_subnets_names[$subnet->id] = $subnet->name . ": ". $subnet->net_str."/".$subnet->mask;
|
||
$this->arr_mask_by_id[$subnet->id]=$subnet->mask;
|
||
$this->arr_net_by_id[$subnet->id]=$subnet->net;
|
||
$arr_subnets_nets[] = $subnet->net;
|
||
$arr_subnets_masks[] = $subnet->mask;
|
||
$arr_subnets_netnames[] = $subnet->net_str."/".$subnet->mask.": ".$subnet->name ;
|
||
$arr_subnets_ids[]=$subnet->id;
|
||
}
|
||
|
||
$this->form = new Forge(url_lang::base()."redirection/addsubnet", '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$this->form->group('')->label(url_lang::lang('texts.Basic information'));
|
||
//$this->form->input('ip_subnet')->label(url_lang::lang('texts.Subnet').':')->rules('required|length[7,15]')->callback(array($this, 'callback_valid_ip'));
|
||
//$this->form->input('ip_subnet_mask')->label(url_lang::lang('texts.Subnet netmask').':')->rules('required|length[1,2]')->callback(array($this, 'callback_valid_mask'));
|
||
if($subnet_id != NULL){
|
||
$this->form->dropdown('subnet_id')->label(url_lang::lang('texts.Select subnet').':')->rules('required')->options($arr_subnets_names)->selected($subnet_id);
|
||
}else{
|
||
$this->form->dropdown('subnet_id')->label(url_lang::lang('texts.Select subnet').':')->rules('required')->options($arr_subnets_names)->selected(0);
|
||
}
|
||
//$this->form->checkbox('remove_network')->label(url_lang::lang('texts.Remove network IP address'))->value('1')->checked(TRUE);
|
||
//$this->form->checkbox('remove_broadcast')->label(url_lang::lang('texts.Remove broadcast IP address'))->value('1')->checked(TRUE);
|
||
$this->form->dropdown('dur')->label(url_lang::lang('texts.Duration').':')->options($types_duration)->rules('required');
|
||
$this->form->checkbox('selfaccess')->label(url_lang::lang('texts.User can disable redirection'))->value('1')->checked(TRUE);
|
||
$this->form->dropdown('dest')->label(url_lang::lang('texts.Destination website').':')->options($types_destination)->rules('required');
|
||
$this->form->group('')->label(url_lang::lang('texts.Advanced configuration'));
|
||
$this->form->textarea('message')->label(url_lang::lang('texts.Message for user'))->rules('length[0,1023]')->value('');
|
||
$this->form->textarea('comment')->label(url_lang::lang('texts.Comment'))->rules('length[0,1023]')->value('');
|
||
$this->form->checkbox('lock')->label(url_lang::lang('texts.Lock for others'))->value('1')->checked(FALSE);
|
||
$this->form->checkbox('sendmail')->label(url_lang::lang('texts.Send e-mail notification after expiration'))->value('1')->checked(FALSE);
|
||
|
||
$this->form->submit('submit')->value(url_lang::lang('texts.Insert'));
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($this->form->validate()){
|
||
$form_data = $this->form->as_array();
|
||
foreach($form_data as $key => $value){
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
//getting ip addresses of subnet
|
||
$ip_address_model = new Ip_address_Model();
|
||
$result = $ip_address_model->get_ip_addresses_of_subnet($form_data['subnet_id']);
|
||
foreach($result as $row){
|
||
if($row->gateway!=1){
|
||
$redirected_ip = $row->ip_address;
|
||
|
||
$redirection = new Redirection_Model();
|
||
$redirection->ip_address_id = $row->id;
|
||
$redirection->duration = $form_data['dur'];
|
||
$redirection->destination = $form_data['dest'];
|
||
$redirection->message = $form_data['message'];
|
||
$redirection->note = $form_data['comment'];
|
||
//LOCK
|
||
if($form_data['lock']==1)
|
||
$redirection->locksign = '1';
|
||
else
|
||
$redirection->locksign = '0';
|
||
//SELFACCESS
|
||
if($form_data['selfaccess']==1)
|
||
$redirection->selfaccess = '1';
|
||
else
|
||
$redirection->selfaccess = '0';
|
||
//SENDMAIL
|
||
if($form_data['sendmail']==1)
|
||
$redirection->sendmail = '1';
|
||
else
|
||
$redirection->sendmail = '0';
|
||
|
||
$redirection->admin = $user_id;
|
||
|
||
$redirection->save();
|
||
redirection_log::log($user_model->login, 76, $row->id);
|
||
}
|
||
}
|
||
|
||
unset($form_data);
|
||
if (true){
|
||
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
|
||
url::redirect(url_lang::base().'redirection/show_all/');
|
||
exit;
|
||
}
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.Redirect ip subnet');
|
||
$view->content = new View('form');
|
||
$view->content->link_back = html::anchor(url_lang::base().'redirection/show_all', url_lang::lang('texts.Back to the redirection list'));
|
||
$view->content->headline = url_lang::lang('texts.Redirect ip subnet');
|
||
$view->content->form = $this->form->html();
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
function adduser($member_id=null){
|
||
if (!$this->acl_check_new(get_class($this),'redirection'))
|
||
Controller::error(ACCESS);
|
||
|
||
//duration type
|
||
$redirection_duration_model = new Redirection_duration_Model();
|
||
$result = $redirection_duration_model->get_select_list();
|
||
$types_duration[0] = '----- '.url_lang::lang('texts.Select duration').' -----';
|
||
foreach($result as $row){
|
||
$types_duration[$row->id]=$row->translation;
|
||
}
|
||
asort($types_duration);
|
||
|
||
//destination type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_destination = $enum_type_model->get_values(Enum_type_Model::$redirect_destination_id);
|
||
$types_destination[0] = '----- '.url_lang::lang('texts.Select destination web').' -----';
|
||
asort($types_destination);
|
||
|
||
//username + email
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($user_model->id == 0)
|
||
Controller::error(RECORD);
|
||
|
||
$this->form = new Forge(url_lang::base().'redirection/adduser/'.$member_id, '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$this->form->group('')->label(url_lang::lang('texts.Basic information'));
|
||
|
||
//$this->form->input('ip_address')->label(url_lang::lang('texts.IP address').':')->rules('required|length[7,15]')->callback(array($this, 'callback_valid_ip'));
|
||
$this->form->input('userid')->label(url_lang::lang('texts.User ID').':')->rules('required');
|
||
$this->form->dropdown('dur')->label(url_lang::lang('texts.Duration').':')->options($types_duration)->rules('required');
|
||
$this->form->checkbox('selfaccess')->label(url_lang::lang('texts.User can disable redirection'))->value('1')->checked(TRUE);
|
||
$this->form->dropdown('dest')->label(url_lang::lang('texts.Destination website').':')->options($types_destination)->rules('required');
|
||
$this->form->group('')->label(url_lang::lang('texts.Advanced configuration'));
|
||
$this->form->textarea('message')->label(url_lang::lang('texts.Message for user'))->rules('length[0,1023]')->value('');
|
||
$this->form->textarea('comment')->label(url_lang::lang('texts.Comment'))->rules('length[0,1023]')->value('');
|
||
$this->form->checkbox('lock')->label(url_lang::lang('texts.Lock for others'))->value('1')->checked(FALSE);
|
||
$this->form->checkbox('sendmail')->label(url_lang::lang('texts.Send e-mail notification after expiration'))->value('1')->checked(FALSE);
|
||
|
||
$this->form->submit('submit')->value(url_lang::lang('texts.Insert'));
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($this->form->validate()){
|
||
$form_data = $this->form->as_array();
|
||
foreach($form_data as $key => $value){
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
//retrieving IP from user ID
|
||
$userid = $form_data['userid'];
|
||
$usermodel = new User_Model();
|
||
$usermodel->find($userid);
|
||
if ($usermodel->id == 0){
|
||
Controller::error(RECORD);
|
||
exit;
|
||
}
|
||
$redirection = new Redirection_Model();
|
||
$total_addresses = $redirection->count_member_ips($userid);
|
||
$result = $redirection->select_member_ips($userid);
|
||
$counter=0;
|
||
foreach ($result as $row){
|
||
$ip_address_ids[$counter]=$row->id;
|
||
$counter++;
|
||
}
|
||
|
||
for ($i=0; $i<$total_addresses; $i++){
|
||
$redirected_ip = $ip_address_ids[$i];
|
||
$redirection = new Redirection_Model();
|
||
$redirection->ip_address_id = $redirected_ip;
|
||
$redirection->duration = $form_data['dur'];
|
||
$redirection->destination = $form_data['dest'];
|
||
$redirection->message = $form_data['message'];
|
||
$redirection->note = $form_data['comment'];
|
||
|
||
//LOCK
|
||
if($form_data['lock']==1)
|
||
$redirection->locksign = '1';
|
||
else
|
||
$redirection->locksign = '0';
|
||
//SELFACCESS
|
||
if($form_data['selfaccess']==1)
|
||
$redirection->selfaccess = '1';
|
||
else
|
||
$redirection->selfaccess = '0';
|
||
//SENDMAIL
|
||
if($form_data['sendmail']==1)
|
||
$redirection->sendmail = '1';
|
||
else
|
||
$redirection->sendmail = '0';
|
||
|
||
$redirection->admin = $user_id;
|
||
|
||
if($i!=$total_addresses-1)
|
||
$redirection->save();
|
||
redirection_log::log($user_model->login, 76, $redirected_ip);
|
||
}
|
||
|
||
unset($form_data);
|
||
if ($redirection->save()) {
|
||
$this->session->set_flash('message', url_lang::lang('texts.Redirection has been successfully set.'));
|
||
url::redirect(url_lang::base().'redirection/show_all/');
|
||
exit;
|
||
}
|
||
}
|
||
//----- end validate --------------------------------------------------
|
||
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.Redirect the user');
|
||
$view->content = new View('form');
|
||
$view->content->link_back = html::anchor(url_lang::base().'redirection/show_all', url_lang::lang('texts.Back to the redirection list'));
|
||
$view->content->headline = url_lang::lang('texts.Redirect the user');
|
||
$view->content->form = $this->form->html();
|
||
$view->render(TRUE);
|
||
|
||
}
|
||
|
||
function show_all($limit_results = 20, $order_by = 'id', $order_by_direction = 'ASC', $page_word = null, $page = 1){
|
||
if (!$this->acl_check_view(get_class($this),'redirection'))
|
||
Controller::error(ACCESS);
|
||
|
||
//duration type
|
||
$redirection_duration_model = new Redirection_duration_Model();
|
||
$result = $redirection_duration_model->get_select_list();
|
||
$types_duration[0] = '----- '.url_lang::lang('texts.Select duration').' -----';
|
||
foreach($result as $row){
|
||
$types_duration[$row->id]=$row->translation;
|
||
}
|
||
asort($types_duration);
|
||
|
||
//destination type
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_destination = $enum_type_model->get_values(Enum_type_Model::$redirect_destination_id);
|
||
$types_destination[0] = '----- '.url_lang::lang('texts.Select destination web').' -----';
|
||
asort($types_destination);
|
||
|
||
$filter=new Table_Form(url_lang::base()."redirection/show_all", "get", array(
|
||
new Table_Form_Item('text','ip_address','IP address'),
|
||
new Table_Form_Item('text','admin','Admin'),
|
||
"tr",
|
||
new Table_Form_Item('select','duration','Duration',$types_duration),
|
||
new Table_Form_Item('select','destination','Destination',$types_destination),
|
||
"tr",
|
||
"td",
|
||
new Table_Form_Item('submit','submit','Filter')
|
||
)
|
||
);
|
||
$filter_values = $filter->values();
|
||
|
||
// get new selector
|
||
if (is_numeric($this->input->get('record_per_page')))
|
||
$limit_results = (int) $this->input->get('record_per_page');
|
||
|
||
$redirection_model = new Redirection_Model();
|
||
$total_redirections = $redirection_model->count_all_records($filter_values);
|
||
|
||
if (($sql_offset = ($page - 1) * $limit_results) > $total_redirections)
|
||
$sql_offset = 0;
|
||
|
||
$query = $redirection_model->get_all_redirections($sql_offset, (int)$limit_results, $order_by, $order_by_direction, NULL, $filter_values);
|
||
|
||
$grid = new Grid(url_lang::base().'redirection', null,array(
|
||
//'separator' => '<br />-----------',
|
||
'use_paginator' => true,
|
||
'use_selector' => true,
|
||
'current' => $limit_results, // current selected 'records_per_page' value
|
||
'selector_increace' => 20, // increace
|
||
'selector_min' => 20, // minimum where selector start
|
||
'selector_max_multiplier' => 10,
|
||
'base_url' => Config::get('lang').'/redirection/show_all/'.$limit_results.'/'.$order_by.'/'.$order_by_direction ,
|
||
'uri_vlan' => 'page', // pass a string as uri_vlan to trigger former 'label' functionality
|
||
'total_items' => $total_redirections, // use db count query here of course
|
||
'items_per_page' => $limit_results, // it may be handy to set defaults for stuff like this in config/pagination.php
|
||
'style' => 'classic',
|
||
'order_by' => $order_by,
|
||
'order_by_direction' => $order_by_direction,
|
||
'limit_results' => $limit_results,
|
||
//'query_string' => $query_string,
|
||
'filter' => $filter->view
|
||
));
|
||
|
||
//if ($this->acl_check_new('Devices_Controller','vlan')){
|
||
$grid->add_new_button(url_lang::base().'redirection/addip', url_lang::lang('texts.Redirect IP address'));
|
||
$grid->add_new_button(url_lang::base().'redirection/addrange', url_lang::lang('texts.Redirect range of IP addresses'));
|
||
$grid->add_new_button(url_lang::base().'redirection/addsubnet', url_lang::lang('texts.Redirect IP subnet'));
|
||
$grid->add_new_button(url_lang::base().'redirection/adduser', url_lang::lang('texts.Redirect the user'));
|
||
if (isset($_REQUEST["submit"])){
|
||
if($_GET['ip_address']!=null) $ip_address = $_GET['ip_address'];
|
||
else $ip_address = 0;
|
||
if($_GET['admin']!=null) $admin = $_GET['admin'];
|
||
else $admin = 0;
|
||
if($_GET['duration']!=null) $duration = $_GET['duration'];
|
||
else $duration = 0;
|
||
if($_GET['destination']!=null) $destination = $_GET['destination'];
|
||
else $destination = 0;
|
||
$grid->add_new_button(url_lang::base().'redirection/delete_list/'.$limit_results.'/'.$ip_address.'/'.$admin.'/'.$duration.'/'.$destination, url_lang::lang('texts.Delete selection'));
|
||
}
|
||
//}
|
||
|
||
//$grid->order_field('id')->label('ID')->class('center');
|
||
$grid->order_field('ip_address')->label(url_lang::lang('texts.IP address'));
|
||
$grid->order_field('dur')->label(url_lang::lang('texts.Duration'))->class('center');
|
||
$grid->order_field('dest')->label(url_lang::lang('texts.Destination website'))->class('center');
|
||
$grid->order_field('admin')->label(url_lang::lang('texts.Admin'))->class('center');
|
||
$grid->order_field('message')->label(url_lang::lang('texts.Message'))->class('center');
|
||
$grid->order_field('note')->label(url_lang::lang('texts.Comment'))->class('center');
|
||
$grid->order_field('locksign')->label(url_lang::lang('texts.Lock'))->class('center');
|
||
//if ($this->acl_check_view('Devices_Controller','vlan'))
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Show')) ->url(url_lang::base().'redirection/show') ->action(url_lang::lang('texts.Show'))->class('center');
|
||
//if ($this->acl_check_edit('Devices_Controller','vlan'))
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Edit')) ->url(url_lang::base().'redirection/edit') ->action(url_lang::lang('texts.Edit'))->class('center');
|
||
//if ($this->acl_check_edit('Devices_Controller','vlan'))
|
||
$grid->action_field('id')->label(url_lang::lang('texts.Delete'))->url(url_lang::base().'redirection/delete')->action(url_lang::lang('texts.Delete'))->class('center')->script('onclick="return potvrd(\''.url_lang::lang('texts.Do you want to cancel this redirection').'\');"');
|
||
// $grid->action_field('id')->label(url_lang::lang('texts.Delete'))->url(url_lang::base().'redirection/delete')->action(url_lang::lang('texts.Delete'))->script('onclick="return potvrd(\''.url_lang::lang('texts.Do you want to delete this user').'\');"');
|
||
$grid->datasource( $query );
|
||
$this->template->content = $grid;
|
||
|
||
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.List of all redirected records');
|
||
$view->content = new View('show_all');
|
||
$view->content->headline = url_lang::lang('texts.List of all redirected records');
|
||
$view->content->table = $grid;
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
function show($redirection_id = NULL){
|
||
if (!$this->acl_check_view(get_class($this),'redirection'))
|
||
Controller::error(ACCESS);
|
||
|
||
$redirection = new Redirection_Model($redirection_id);
|
||
if (!$redirection_id || !$redirection->id){
|
||
Controller::error(RECORD);
|
||
url::redirect(url_lang::base().'redirection/show_all');
|
||
}
|
||
$enum_type_model = new Enum_type_Model();
|
||
$destination = $enum_type_model->get_value($redirection->destination);
|
||
$redirection_duration_model = new Redirection_duration_Model($redirection->duration);
|
||
$duration = $redirection_duration_model->translation;
|
||
$ip_address_model = new Ip_address_Model($redirection->ip_address_id);
|
||
$ip_address = $ip_address_model->ip_address;
|
||
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($redirection->locksign && $redirection->admin != $user_id){
|
||
$this->session->set_flash('message', url_lang::lang('texts.You have no permission to access redirection'));
|
||
$linkback = url_lang::base()."redirection/show_all/";
|
||
url::redirect($linkback);
|
||
}
|
||
|
||
// access control
|
||
//if (!$this->acl_check_view('Users_Controller','work',$work->user->member_id))
|
||
// Controller::error(ACCESS);
|
||
|
||
$link_back = html::anchor(url_lang::base().'redirection/show_all', url_lang::lang('texts.Back to the redirection list'));
|
||
|
||
$view = new View('main');
|
||
$view->title = url_lang::lang('texts.Show redirection');
|
||
$view->content = new View('redirection/show');
|
||
$view->content->ip_address = $ip_address;
|
||
$view->content->duration = $duration;
|
||
$view->content->destination = $destination;
|
||
$view->content->redirection = $redirection;
|
||
$view->content->link_back = $link_back;
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
function edit($redirection_id = null) {
|
||
if (!$this->acl_check_edit(get_class($this),'redirection'))
|
||
Controller::error(ACCESS);
|
||
|
||
if (!isset($redirection_id))
|
||
Controller::warning(PARAMETER);
|
||
$redirection = new Redirection_Model($redirection_id);
|
||
if ($redirection->id == 0)
|
||
Controller::error(RECORD);
|
||
|
||
//getting ip address
|
||
$ip_address_model = new Ip_address_Model($redirection->ip_address_id);
|
||
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($redirection->locksign && $redirection->admin != $user_id){
|
||
$this->session->set_flash('message', url_lang::lang('texts.You have no permission to edit redirection'));
|
||
$linkback = url_lang::base()."redirection/show_all/";
|
||
url::redirect($linkback);
|
||
}
|
||
|
||
//if (!$this->acl_check_edit(get_class($this),'devices',$redirection->user->member_id))
|
||
// Controller::error(ACCESS);
|
||
|
||
//duration
|
||
//$enum_type_model = new Enum_type_Model();
|
||
//$types_duration = $enum_type_model->get_values(Enum_type_Model::$redirect_duration_id);
|
||
$redirection_duration_model = new Redirection_duration_Model();
|
||
$result = $redirection_duration_model->get_select_list();
|
||
foreach($result as $row){
|
||
$types_duration[$row->id]=$row->translation;
|
||
}
|
||
asort($types_duration);
|
||
//destination
|
||
$enum_type_model = new Enum_type_Model();
|
||
$types_destination = $enum_type_model->get_values(Enum_type_Model::$redirect_destination_id);
|
||
//username + email
|
||
$user_id=$this->session->get('member_id');
|
||
$user_model = new User_Model();
|
||
$user_model->find($user_id);
|
||
if ($user_model->id == 0)
|
||
Controller::error(RECORD);
|
||
$this->user_id = $user_id;
|
||
|
||
$this->form = new Forge(url_lang::base()."redirection/edit/".$redirection_id, '', 'POST', array('id' => 'article_form'));
|
||
$this->form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$this->form->group('')->label(url_lang::lang('texts.Basic data'));
|
||
$this->form->input('ip_address')->label(url_lang::lang('texts.IP address').':')->rules('required|length[7,15]')->callback(array($this, 'callback_valid_ip'))->value($ip_address_model->ip_address);
|
||
$this->form->dropdown('dur')->label(url_lang::lang('texts.Duration').':')->options($types_duration)->rules('required')->selected($redirection->duration);
|
||
$this->form->checkbox('selfaccess')->label(url_lang::lang('texts.User can disable redirection'))->value('1')->checked($redirection->selfaccess);
|
||
$this->form->dropdown('dest')->label(url_lang::lang('texts.Destination website').':')->options($types_destination)->rules('required')->selected($redirection->destination);
|
||
$this->form->group('')->label(url_lang::lang('texts.Advanced configuration'));
|
||
$this->form->textarea('message')->label(url_lang::lang('texts.Message for user'))->rules('length[0,1023]')->value($redirection->message);
|
||
$this->form->textarea('comment')->label(url_lang::lang('texts.Comment'))->rules('length[0,1023]')->value($redirection->note);
|
||
$this->form->checkbox('lock')->label(url_lang::lang('texts.Lock for others'))->value('1')->checked($redirection->locksign);
|
||
$this->form->checkbox('sendmail')->label(url_lang::lang('texts.Send e-mail notification after expiration'))->value('1')->checked($redirection->sendmail);
|
||
$this->form->submit('submit')->value(url_lang::lang('texts.Update'));
|
||
|
||
special::required_forge_style($this->form, ' *', 'required');
|
||
|
||
|
||
//----- validate form and save data -----------------------------------
|
||
if($this->form->validate()){
|
||
$form_data = $this->form->as_array();
|
||
$redirection = new Redirection_Model($redirection_id);
|
||
foreach($form_data as $key => $value){
|
||
$form_data[$key] = htmlspecialchars($value);
|
||
}
|
||
|
||
//getting ip address' id from database
|
||
$ip_address = $form_data['ip_address'];
|
||
$ip_address_model2 = new Ip_address_Model();
|
||
$result = $ip_address_model2->find_ip_address($ip_address);
|
||
if(count($result)>0){
|
||
foreach ($result as $row){
|
||
$ip_address_id = $row->id;
|
||
}
|
||
}else{
|
||
//ip address was not found in freenetis databases
|
||
$this->session->set_flash('message', url_lang::lang('texts.Cannot redirect unknown IP address.'));
|
||
url::redirect(url_lang::base().'redirection/show_all/');
|
||
exit;
|
||
}
|
||
|
||
$redirection->ip_address_id = $ip_address_id;
|
||
$redirection->duration = $form_data['dur'];
|
||
$redirection->destination = $form_data['dest'];
|
||
$redirection->message = $form_data['message'];
|
||
$redirection->note = $form_data['comment'];
|
||
//LOCK
|
||
if($form_data['lock']==1)
|
||
$redirection->locksign = '1';
|
||
else
|
Také k dispozici: Unified diff
Drobne upravy backend skriptu pro presmerovani. Dopsano anglicke README k temto skriptum. Pridano generovani .htaccess pro slozku static. Smazany zdrojaky stareho presmerovani, i presmerovani od L. Bubna, ktere nikdo netestoval a ktere stejne neresi problemy vykonu. V dalsi fazi budou smazany i db tabulky. Pridana moznost pristupu na web_interface, zrusena pro redirect. Pridani aktualizaci zprav pro nezname zarizeni a pro stranku pro presmerovani.