BRAS на FreeBSD 7.2-RELEASE-p4 + freeNIBS

BRAS на FreeBSD 7.2 + freeNIBS

Мой Брас слушает 10.2.5.2 и 10.2.6.1

/usr/local/etc/mpd5/mpd.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
startup:
#    set user foo bar admin
# не забываем в конце admin, иначе пользователь не сможет завершать сессию
    set user mpd mpd_password admin
#10.2.5.2 ip на который консолькой ципляемся
    set console self 10.2.5.2 5005
    set console open
    set web self 127.0.0.1 5006
    set web open
#   set netflow peer 10.2.5.2 8787
#   set netflow self 10.2.5.2 8788
#    set netflow timeouts 60 120
default:
     load pptp_server
     load pptp_server_lan2
 
pptp_server:
    create bundle template B
    set iface disable proxy-arp
    set iface enable netflow-in netflow-out
    set iface idle 1800
    set iface enable tcpmssfix
    set ipcp yes vjcomp
    #скрипт отрабатывается при подключении
    set iface up-script /usr/local/etc/mpd5/link-up
    #скрипт отрабатывается при отключении
    set iface down-script /usr/local/etc/mpd5/link-down
# Specify IP address pool for dynamic assigment.
    set ipcp ranges 10.255.255.1/32 172.16.0.0/16
#dns сервер
    set ipcp dns 8.8.8.8
    set bundle disable compression
#15.05.09 #    set iface enable proxy-arp
    set ccp yes mppc
    set mppc yes e40
    set mppc yes e128
    set mppc yes stateless
    create link template L pptp
# Set bundle template to use
    set link action bundle B
# Multilink adds some overhead, but gives full 1500 MTU.
    set link disable multilink
    set link yes acfcomp protocomp
    set link no pap chap
    set link enable chap
    set link keep-alive 10 60
# We reducing link mtu to avoid GRE packet fragmentation
    set link mtu 1400
    set link enable peer-as-calling
    set link enable report-mac
    set pptp self 10.2.5.2
# Allow to accept calls
    set link enable incoming
 
# another config section with label 'radius'.
#       load radius
 log +radius2
        load radius
pptp_server_lan2:
    create bundle template B1
    set iface disable proxy-arp
    set iface enable netflow-in netflow-out
    set iface idle 1800
    set iface enable tcpmssfix
    set ipcp yes vjcomp
    set iface up-script /usr/local/etc/mpd5/link-up
    set iface down-script /usr/local/etc/mpd5/link-down
# Specify IP address pool for dynamic assigment.
    set ipcp ranges 172.16.254.1/32 172.16.0.0/16
    set ipcp dns 8.8.8.8
    set bundle disable compression
#15.05.09 #    set iface enable proxy-arp
    set ccp yes mppc
    set mppc yes e40
    set mppc yes e128
    set mppc yes stateless
    create link template L1 pptp
# Set bundle template to use
    set link action bundle B
# Multilink adds some overhead, but gives full 1500 MTU.
    set link disable multilink
    set link yes acfcomp protocomp
    set link no pap chap
    set link enable chap
    set link keep-alive 10 60
# We reducing link mtu to avoid GRE packet fragmentation
    set link mtu 1400
    set link enable peer-as-calling
    set link enable report-mac
    set pptp self 10.2.6.1
# Allow to accept calls
    set link enable incoming
 
# another config section with label 'radius'.
#       load radius
 log +radius2
        load radius
 
 
radius:
# You can use radius.conf(5), its useful, because you can share the
#       set radius config /etc/radius.conf
        set radius server 10.1.1.1 пароль 1812 1813
        set radius retries 3
        set radius timeout 40
        set radius me 10.2.5.2
        set auth enable radius-auth
        set auth enable radius-acct
        set auth disable internal
        set radius enable message-authentic
        set auth acct-update 60
        # enable RADIUS accounting
        set auth enable radius-acct

dmesg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Copyright (c) 1992-2009 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
        The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 7.2-RELEASE-p4 #3: Thu Nov 12 23:35:46 EET 2009
    wel@nas1:/usr/obj/usr/src/sys/NAS
Timecounter "i8254" frequency 1193182 Hz quality 0
CPU: AMD Athlon(tm) 64 X2 Dual Core Processor 5400+ (2785.83-MHz K8-class CPU)
  Origin = "AuthenticAMD"  Id = 0x60fb2  Stepping = 2
  Features=0x178bfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,MMX,FXSR,SSE,SSE2,HTT>
  Features2=0x2001<SSE3,CX16>
  AMD Features=0xea500800<SYSCALL,NX,MMX+,FFXSR,RDTSCP,LM,3DNow!+,3DNow!>
  AMD Features2=0x11f<LAHF,CMP,SVM,ExtAPIC,CR8,Prefetch>
  TSC: P-state invariant
  Cores per package: 2
usable memory = 2134564864 (2035 MB)
avail memory  = 2057388032 (1962 MB)
ACPI APIC Table: <031108 APIC1839>
FreeBSD/SMP: Multiprocessor System Detected: 2 CPUs
 cpu0 (BSP): APIC ID:  0
 cpu1 (AP): APIC ID:  1
ioapic0 <Version 1.1> irqs 0-23 on motherboard
kbd1 at kbdmux0
acpi0: <031108 RSDT1839> on motherboard
acpi0: [ITHREAD]
acpi0: Power Button (fixed)
acpi0: reservation of fec00000, 1000 (3) failed
acpi0: reservation of 0, a0000 (3) failed
acpi0: reservation of 100000, 7ff00000 (3) failed
Timecounter "ACPI-fast" frequency 3579545 Hz quality 1000
acpi_timer0: <24-bit timer at 3.579545MHz> port 0x2008-0x200b on acpi0
pcib0: <ACPI Host-PCI bridge> port 0xcf8-0xcff on acpi0
pci0: <ACPI PCI bus> on pcib0
pci0: <memory, RAM> at device 0.0 (no driver attached)
isab0: <PCI-ISA bridge> port 0x2f00-0x2fff at device 1.0 on pci0
isa0: <ISA bus> on isab0
pci0: <serial bus, SMBus> at device 1.1 (no driver attached)
pci0: <memory, RAM> at device 1.2 (no driver attached)
ohci0: <OHCI (generic) USB controller> mem 0xf7fff000-0xf7ffffff irq 21 at device 2.0 on pci0
ohci0: [GIANT-LOCKED]
ohci0: [ITHREAD]
usb0: OHCI version 1.0, legacy support
usb0: <OHCI (generic) USB controller> on ohci0
usb0: USB revision 1.0
uhub0: <nVidia OHCI root hub, class 9/0, rev 1.00/1.00, addr 1> on usb0
uhub0: 10 ports with 10 removable, self powered
ehci0: <EHCI (generic) USB 2.0 controller> mem 0xf7ffec00-0xf7ffecff irq 22 at device 2.1 on pci0
ehci0: [GIANT-LOCKED]
ehci0: [ITHREAD]
usb1: EHCI version 1.0
usb1: companion controller, 10 ports each: usb0
usb1: <EHCI (generic) USB 2.0 controller> on ehci0
usb1: USB revision 2.0
uhub1: <nVidia EHCI root hub, class 9/0, rev 2.00/1.00, addr 1> on usb1
uhub1: 10 ports with 10 removable, self powered
pci0: <multimedia, HDA> at device 7.0 (no driver attached)
pcib1: <ACPI PCI-PCI bridge> at device 8.0 on pci0
pci1: <ACPI PCI bus> on pcib1
vgapci0: <VGA-compatible display> mem 0xf8000000-0xfbffffff irq 16 at device 8.0 on pci1
em0: <Intel(R) PRO/1000 Network Connection 6.9.6> port 0xdc00-0xdc1f mem 0xfeac0000-0xfeadffff,0xfeaa0000-0xfeabffff irq 17 at device 9.0 on pci1
em0: [FILTER]

/etc/sysctl.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# $FreeBSD: src/etc/sysctl.conf,v 1.8 2003/03/13 18:43:50 mux Exp $
#
#  This file is read when going to multi-user and its contents piped thru
#  ``sysctl'' to adjust kernel values.  ``man 5 sysctl.conf'' for details.
#
 
# Uncomment this to prevent users from seeing information about processes that
# are being run under another UID.
security.bsd.see_other_uids=0
security.bsd.see_other_gids=0
 
#kern.ipc.somaxconn=1024
net.inet.tcp.blackhole=2
net.inet.udp.blackhole=1
net.inet.icmp.drop_redirect=1
net.inet.icmp.log_redirect=1
 
net.inet.tcp.sendspace=65536
net.inet.tcp.recvspace=65536
net.link.ether.inet.max_age=1200
net.inet.ip.sourceroute=0
net.inet.ip.accept_sourceroute=0
net.inet.icmp.bmcastecho=0
net.inet.icmp.maskrepl=0
net.inet.icmp.icmplim=10000
net.inet.tcp.msl=7500
 
 
 
kern.ipc.somaxconn=32768
#net.inet.icmp.icmplim=1000
#net.inet.tcp.msl=7500
 
net.inet.ip.ttl=128
#net.graph.recvspace=524288
#net.graph.maxdgram=524288
#net.inet.ip.fw.autoinc_step=1
#net.inet.ip.random_id=1
security.bsd.see_other_uids=0
security.bsd.see_other_gids=0
 
net.inet.ip.ttl=128
 
net.inet.icmp.bmcastecho=0
 
#22 02 09
kern.maxfiles=128000
kern.maxfilesperproc=65000
kern.ipc.maxsockets=204800
kern.ipc.nmbclusters=65536
net.inet.ip.portrange.first=1024
net.inet.ip.portrange.last=65534
net.inet.ip.portrange.randomized=0
 
#17 03 09
net.inet.ip.fastforwarding=1
 
#23 03 09
net.inet6.ip6.forwarding=1
net.inet.ip.redirect=1
 
#24 03 09
net.inet.ip.fw.one_pass=0
net.inet.ip.dummynet.io_fast=1
 
net.inet.ip.dummynet.hash_size=10240
net.inet.ip.dummynet.max_chain_len=32
 
#2.10.2009
net.graph.recvspace=128000
net.graph.maxdgram=128000
 
#19.10.2009
#solv ipfw: install_state: Too many dynamic rules
net.inet.ip.fw.dyn_buckets=2048
 
net.inet.ip.fw.dyn_max=16384

скрипт подключения пользователя

Вот скрипт который Я использовал, при подключении пользователя.
Он создаёт pipe, если для пользователя стоит ограничение скорости `bw1`, `bw2` в таблице `all` больше нуля.
Если ИП реальный: У Меня начинается с 91. в примере, то он не натиться, иначе натиться.
ipfw table 1 содержит ИП, которые должны натиться.
`freenibs`.`pipes` — тут содержаться номера и значения скоростей для пайпов.
Смысл в том, что если кому-то выставили скорость, и для этой скорости не присвоен номер пайпа — создаётся новая запись и присваивается новый номер пайпа
Я использовал ipfw, можно и pf использовать ;)
>cat link-up/main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
 
#include <QtCore>
#include <QCoreApplication>
#include <QtSql>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
using namespace std;
 
#define SQLDRIVER "QMYSQL"
#define HOST "10.2.2.1"
#define DBNAME "bezlim"
#define USER "bezlim"
#define PASSWORD "123456"
 
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
 
    QTextCodec *codec = QTextCodec::codecForName("CP1251");
    QTextCodec::setCodecForTr(codec);
    QTextCodec::setCodecForCStrings(codec);
 
    QSqlDatabase db = QSqlDatabase::addDatabase(SQLDRIVER);
 
    if( !db.isDriverAvailable(SQLDRIVER))
    {
 
    }
 
 
    db.setHostName(HOST);
    db.setDatabaseName(DBNAME);
    db.setUserName(USER);
    db.setPassword(PASSWORD);
    //db.setPort(3306);
    bool ok=db.open();
    if(ok!=true){
        std::cout<<"unable connec't";
        exit(1);
    }
     QString exec_this;
     int bw1;
 
     QString ip_argv;
     ip_argv=argv[4];
 
     QSqlQuery query("SELECT * FROM `all` WHERE `ip` not LIKE '91.%' AND `activ`='y' AND `ip`='"+ip_argv+"' LIMIT 1");
     while (query.next()) {
         QString id = query.value(5).toString();
 
         QString ip = query.value(0).toString();
         QString in = query.value(3).toString();
         QString out = query.value(4).toString();
         QString n = query.value(1).toString();
         bw1 =query.value(3).toInt();
         QString bw2 =query.value(3).toString();
//pfctl
//      exec_this="/sbin/pfctl -tinat -Tadd ";
//      exec_this +=ip;
 
        exec_this ="/sbin/ipfw table 1 add ";
        exec_this +=ip;
// посмотреть дебаг
//      qDebug()<<exec_this<<endl;
 
        system(exec_this.toStdString().c_str());
 
 
    }
        qDebug()<<ip_argv<<endl;
 
        qDebug()<<exec_this<<endl;
 
     QSqlQuery query11("SELECT * FROM `all` WHERE `activ`='y' AND `ip`='"+ip_argv+"' LIMIT 1");
     while (query11.next()) {
 
         QString id = query11.value(5).toString();
 
         QString ip = query11.value(0).toString();
         QString in = query11.value(3).toString();
         QString out = query11.value(4).toString();
         QString n = query11.value(1).toString();
         bw1 =query11.value(3).toInt();
         QString bw2 =query11.value(3).toString();
 
        if(bw1>0)
        {
            qint64 num = 0;
            QString num1;
            query.clear();
             QSqlQuery query("SELECT * FROM `freenibs`.`pipes` WHERE `freenibs`.`pipes`.`bw`='"+bw2+"' LIMIT 1");
            //qDebug()<<"SELECT `freenibs`.`pipes`.`n` FROM `freenibs`.`pipes` WHERE `freenibs`.`pipes`.`bw`='"+bw2+"' LIMIT 1"<<endl;
             while (query.next()) {
                    num = query.value(1).toInt();
                    num1 = query.value(1).toString();
                }
            query.clear();
            if(num>0)
            {
                    exec_this ="/sbin/ipfw pipe ";
                    exec_this +=num1;
                    exec_this +=" config mask dst-ip 0x000000ff bw ";
                    exec_this +=bw2;
                    exec_this +="Kbit/s";
                    system(exec_this.toStdString().c_str());
                    //qDebug()<<exec_this<<endl;
 
                    exec_this ="/sbin/ipfw table ";
                    exec_this +=num1;
                    exec_this +=" add ";
                    exec_this +=ip;
                    system(exec_this.toStdString().c_str());
                    //qDebug()<<exec_this<<endl;
 
 
 
            }
            else
            {
 
                    QSqlQuery query1(" SELECT MAX(`n`)+1  FROM `freenibs`.`pipes` ");
                    //qDebug()<<query1.lastError()<<endl;
                     while (query1.next()) {
                            num1 = query1.value(0).toString();
                        }
                    //qDebug()<<"NUM:"<<num1<<endl;
 
                     //QSqlQuery
                     query.prepare("INSERT INTO `freenibs`.`pipes`  ( `bw`,`n`) values( '" +bw2+ "','"+num1+"')");
                    // qDebug()<<query.lastError()<<endl;
                     query.exec();
 
                    exec_this ="/sbin/ipfw delete ";
                    exec_this +=num1;
                    system(exec_this.toStdString().c_str());
                    //qDebug()<<exec_this<<endl;
 
                    exec_this ="/sbin/ipfw pipe ";
                    exec_this +=num1;
                    exec_this +=" config mask dst-ip 0x000000ff bw ";
                    exec_this +=bw2;
                    exec_this +="Kbit/s";
                    system(exec_this.toStdString().c_str());
                    //qDebug()<<exec_this<<endl;
 
                    exec_this ="/sbin/ipfw -q add ";
                    exec_this +=num1;
                    exec_this +=" pipe ";
                    exec_this +=num1;
                    exec_this +=" all from table\\(";
                    exec_this +=num1;
                    exec_this +="\\) to not 10.0.0.0/8 out";
                    system(exec_this.toStdString().c_str());
                    //qDebug()<<exec_this<<endl;
 
 
                    exec_this ="/sbin/ipfw -q add ";
                    exec_this +=num1;
                    exec_this +=" pipe ";
                    exec_this +=num1;
                    exec_this +=" all from not 10.0.0.0/8 to table\\(";
                    exec_this +=num1;
                    exec_this +="\\) in ";
                    system(exec_this.toStdString().c_str());
                    //qDebug()<<exec_this<<endl;
 
 
                    exec_this ="/sbin/ipfw table ";
                    exec_this +=num1;
                    exec_this += " add ";
                    exec_this +=ip;
                    system(exec_this.toStdString().c_str());
                    //qDebug()<<exec_this<<endl;
            }
        }
        QSqlQuery query("INSERT INTO `freenibs`.`updown` (`ip` ,`time` ,`status`) VALUES ( '"+ip_argv+"',CURRENT_TIMESTAMP , 'up');");
        query.clear();
    }
     db.close();
}

дампы

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
-- phpMyAdmin SQL Dump
-- Хост: localhost
-- Час створення: Вер 04 2010 р., 13:38
 
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
 
--
-- БД: `bezlim`
--
 
-- --------------------------------------------------------
 
--
-- Структура таблиці `all`
--
 
DROP TABLE IF EXISTS `all`;
CREATE TABLE IF NOT EXISTS `all` (
  `ip` VARCHAR(48) NOT NULL DEFAULT '192.168.0.1',
  `rule` INT(32) NOT NULL DEFAULT '500',
  `bw1` VARCHAR(12) NOT NULL DEFAULT '0',
  `bw2` VARCHAR(12) NOT NULL DEFAULT '0',
  `activ` CHAR(1) NOT NULL DEFAULT 'y',
  `id` INT(32) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `ip` (`ip`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
 
--
-- Дамп даних таблиці `all`
--
 
INSERT INTO `all` (`ip`, `rule`, `bw1`, `bw2`, `activ`, `id`) VALUES('91.1.1.32', 116, '2048', '2048', 'y', 580);
INSERT INTO `all` (`ip`, `rule`, `bw1`, `bw2`, `activ`, `id`) VALUES('10.2.255.23', 4006, '1024', '1024', 'y', 3028);
--
-- Структура таблиці `pipes`
--
 
DROP TABLE IF EXISTS `pipes`;
CREATE TABLE IF NOT EXISTS `pipes` (
  `id` INT(255) NOT NULL AUTO_INCREMENT,
  `n` INT(255) NOT NULL DEFAULT '11',
  `bw` INT(255) DEFAULT '0',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `bw` (`bw`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=63 ;
 
--
-- Дамп даних таблиці `pipes`
--
 
INSERT INTO `pipes` VALUES
(27, 27, 512),
(48, 48, 256),
(61, 58, 2148),
(62, 59, 1024);
 
 
--
-- Структура таблиці `updown`
--
 
DROP TABLE IF EXISTS `updown`;
CREATE TABLE IF NOT EXISTS `updown` (
  `id` BIGINT(255) NOT NULL AUTO_INCREMENT,
  `ip` VARCHAR(100) NOT NULL DEFAULT '0.0.0.0',
  `time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `status` enum('up','down') NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1569040 ;
 
--
-- Дамп даних таблиці `updown`
--
 
INSERT INTO `updown` (`id`, `ip`, `time`, `status`) VALUES
(1369059, '10.200.253.15', '2010-06-01 00:00:29', 'up');

TRIGGER, который позволяет изменять переменную `up_n` в таблице `users`, увеличивая её при подключении.
Я его обнуляю раз в день, тогда видно кто часто пере подключался :)

1
2
3
4
5
6
7
8
9
10
11
--
-- --  Triggers `updown`
--
DROP TRIGGER IF EXISTS `freenibs`.`inserttest`;
DELIMITER //
CREATE TRIGGER `freenibs`.`inserttest` BEFORE INSERT ON `freenibs`.`updown`
 FOR EACH ROW BEGIN
UPDATE `users` SET `users`.`up_n`=`users`.`up_n`+1 WHERE `users`.`framed_ip`=NEW.ip;
END
//
DELIMITER ;

link-up/Makefile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
 
#############################################################################
# Makefile for building: link-up
# Generated by qmake (2.01a) (Qt 4.4.3) on: Thu Jul 23 00:40:54 2009
# Project:  pro.pro
# Template: app
# Command: /usr/local/bin/qmake-qt4 -unix -o Makefile pro.pro
#############################################################################
 
####### Compiler, tools and options
 
CC            = cc
CXX           = c++
DEFINES       = -DQT_NO_DEBUG -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS        = -pipe -O2 -fno-strict-aliasing -pipe -Wall -W $(DEFINES)
CXXFLAGS      = -pipe -O2 -fno-strict-aliasing -pipe -Wall -W $(DEFINES)
INCPATH       = -I/usr/local/share/qt4/mkspecs/freebsd-g++ -I. -I/usr/local/include/qt4/QtCore -I/usr/local/include/qt4/QtCore -I/usr/local/include/qt4/QtGui -I/usr/local/include/qt4/QtGui -I/usr/local/include/qt4/QtSql -I/usr/local/include/qt4/QtSql -I/usr/local/include/qt4 -I. -I. -I/usr/local/include
LINK          = c++
LFLAGS        = -pthread -Wl,-rpath,/usr/local/lib/qt4
LIBS          = $(SUBLIBS)  -L/usr/local/lib -L/usr/local/lib/qt4 -lQtSql -L/usr/local/lib/qt4 -L/usr/local/lib -pthread -pthread -lQtGui -pthread -lpng -lSM -lICE -pthread -pthread -lXi -lXrender -lXrandr -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -pthread -lgthread-2.0 -lglib-2.0 -liconv
AR            = ar cqs
RANLIB        =
QMAKE         = /usr/local/bin/qmake-qt4
TAR           = tar -cf
COMPRESS      = gzip -9f
COPY          = cp -f
SED           = sed
COPY_FILE     = $(COPY)
COPY_DIR      = $(COPY) -R
INSTALL_FILE  = $(COPY_FILE)
INSTALL_DIR   = $(COPY_DIR)
INSTALL_PROGRAM = $(COPY_FILE)
DEL_FILE      = rm -f
SYMLINK       = ln -sf
DEL_DIR       = rmdir
MOVE          = mv -f
CHK_DIR_EXISTS= test -d
MKDIR         = mkdir -p
 
####### Output directory
 
OBJECTS_DIR   = ./
 
####### Files
 
SOURCES       = main.cpp
OBJECTS       = main.o
DIST          = /usr/local/share/qt4/mkspecs/common/unix.conf \
                /usr/local/share/qt4/mkspecs/qconfig.pri \
                /usr/local/share/qt4/mkspecs/features/qt_functions.prf \
                /usr/local/share/qt4/mkspecs/features/qt_config.prf \
                /usr/local/share/qt4/mkspecs/features/exclusive_builds.prf \
                /usr/local/share/qt4/mkspecs/features/default_pre.prf \
                /usr/local/share/qt4/mkspecs/features/release.prf \
                /usr/local/share/qt4/mkspecs/features/default_post.prf \
                /usr/local/share/qt4/mkspecs/features/unix/thread.prf \
                /usr/local/share/qt4/mkspecs/features/warn_on.prf \
                /usr/local/share/qt4/mkspecs/features/qt.prf \
                /usr/local/share/qt4/mkspecs/features/moc.prf \
                /usr/local/share/qt4/mkspecs/features/resources.prf \
                /usr/local/share/qt4/mkspecs/features/uic.prf \
                /usr/local/share/qt4/mkspecs/features/yacc.prf \
                /usr/local/share/qt4/mkspecs/features/lex.prf \
                pro.pro
QMAKE_TARGET  = link-up
DESTDIR       =
TARGET        = link-up
 
first: all
####### Implicit rules
 
.SUFFIXES: .o .c .cpp .cc .cxx .C
 
.cpp.o:
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
 
.cc.o:
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
 
.cxx.o:
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
 
.C.o:
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
 
.c.o:
        $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
 
####### Build rules
 
all: Makefile $(TARGET)
 
$(TARGET):  $(OBJECTS)
        $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
 
Makefile: pro.pro  /usr/local/share/qt4/mkspecs/freebsd-g++/qmake.conf /usr/local/share/qt4/mkspecs/common/unix.conf \
                /usr/local/share/qt4/mkspecs/qconfig.pri \
                /usr/local/share/qt4/mkspecs/features/qt_functions.prf \
                /usr/local/share/qt4/mkspecs/features/qt_config.prf \
                /usr/local/share/qt4/mkspecs/features/exclusive_builds.prf \
                /usr/local/share/qt4/mkspecs/features/default_pre.prf \
                /usr/local/share/qt4/mkspecs/features/release.prf \
                /usr/local/share/qt4/mkspecs/features/default_post.prf \
                /usr/local/share/qt4/mkspecs/features/unix/thread.prf \
                /usr/local/share/qt4/mkspecs/features/warn_on.prf \
                /usr/local/share/qt4/mkspecs/features/qt.prf \
                /usr/local/share/qt4/mkspecs/features/moc.prf \
                /usr/local/share/qt4/mkspecs/features/resources.prf \
                /usr/local/share/qt4/mkspecs/features/uic.prf \
                /usr/local/share/qt4/mkspecs/features/yacc.prf \
                /usr/local/share/qt4/mkspecs/features/lex.prf \
                /usr/local/lib/qt4/libQtSql.prl \
                /usr/local/lib/qt4/libQtCore.prl \
                /usr/local/lib/qt4/libQtGui.prl
        $(QMAKE) -unix -o Makefile pro.pro
/usr/local/share/qt4/mkspecs/common/unix.conf:
/usr/local/share/qt4/mkspecs/qconfig.pri:
/usr/local/share/qt4/mkspecs/features/qt_functions.prf:
/usr/local/share/qt4/mkspecs/features/qt_config.prf:
/usr/local/share/qt4/mkspecs/features/exclusive_builds.prf:
/usr/local/share/qt4/mkspecs/features/default_pre.prf:
/usr/local/share/qt4/mkspecs/features/release.prf:
/usr/local/share/qt4/mkspecs/features/default_post.prf:
/usr/local/share/qt4/mkspecs/features/unix/thread.prf:
/usr/local/share/qt4/mkspecs/features/warn_on.prf:
/usr/local/share/qt4/mkspecs/features/qt.prf:
/usr/local/share/qt4/mkspecs/features/moc.prf:
/usr/local/share/qt4/mkspecs/features/resources.prf:
/usr/local/share/qt4/mkspecs/features/uic.prf:
/usr/local/share/qt4/mkspecs/features/yacc.prf:
/usr/local/share/qt4/mkspecs/features/lex.prf:
/usr/local/lib/qt4/libQtSql.prl:
/usr/local/lib/qt4/libQtCore.prl:
/usr/local/lib/qt4/libQtGui.prl:
qmake:  FORCE
        @$(QMAKE) -unix -o Makefile pro.pro
 
dist:
        @$(CHK_DIR_EXISTS) .tmp/link-up1.0.0 || $(MKDIR) .tmp/link-up1.0.0
        $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/link-up1.0.0/ && $(COPY_FILE) --parents main.cpp .tmp/link-up1.0.0/ && (cd `dirname .tmp/link-up1.0.0` && $(TAR) link-up1.0.0.tar link-up1.0.0 && $(COMPRESS) link-up1.0.0.tar) && $(MOVE) `dirname .tmp/link-up1.0.0`/link-up1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/link-up1.0.0
 
 
clean:compiler_clean
        -$(DEL_FILE) $(OBJECTS)
        -$(DEL_FILE) *~ core *.core
 
 
####### Sub-libraries
 
distclean: clean
        -$(DEL_FILE) $(TARGET)
        -$(DEL_FILE) Makefile
 
 
mocclean: compiler_moc_header_clean compiler_moc_source_clean
 
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
 
compiler_moc_header_make_all:
compiler_moc_header_clean:
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
        -$(DEL_FILE) qmake_image_collection.cpp
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean:
 
####### Compile
 
main.o: main.cpp
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
 
####### Install
 
install:   FORCE
 
uninstall:   FORCE
 
FORCE:

Скрипт вызывающийся при отключении пользователя.

Заносим запись в базу, о том что ‘down’, так же удаляем из таблиц: нат и с пайпом
>cat link-down/main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
 
#include <QtCore>
#include <QCoreApplication>
#include <QtSql>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
using namespace std;
 
 
#define SQLDRIVER "QMYSQL"
#define HOST "10.2.2.1"
#define DBNAME "bezlim"
#define USER "bezlim"
#define PASSWORD "123456"
 
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
 
    QTextCodec *codec = QTextCodec::codecForName("CP1251");
    QTextCodec::setCodecForTr(codec);
    QTextCodec::setCodecForCStrings(codec);
 
    QSqlDatabase db = QSqlDatabase::addDatabase(SQLDRIVER);
 
    if( !db.isDriverAvailable(SQLDRIVER))
    {
 
    }
 
 
    db.setHostName(HOST);
    db.setDatabaseName(DBNAME);
    db.setUserName(USER);
    db.setPassword(PASSWORD);
    //db.setPort(3306);
    bool ok=db.open();
    if(ok!=true){
        std::cout<<"unable connec't";
        exit(1);
    }
     QString exec_this;
     int bw1;
 
     QString ip_argv;
     ip_argv=argv[4];
 
     //qDebug()<<ip_argv;
 
     QSqlQuery query("SELECT * FROM `all` WHERE `activ`='y' AND `ip`='"+ip_argv+"'");
     while (query.next()) {
         QString id = query.value(5).toString();
         QString ip = query.value(0).toString();
         QString in = query.value(3).toString();
         QString out = query.value(4).toString();
         QString n = query.value(1).toString();
         bw1 =query.value(3).toInt();
         QString bw2 =query.value(3).toString();
//pf
//      exec_this="/sbin/pfctl -tinat -Tdel ";
//      exec_this +=ip;
//      qDebug()<<exec_this<<endl;
            exec_this ="/sbin/ipfw table 1 delete ";
            exec_this +=ip;
 
 
        system(exec_this.toStdString().c_str());
 
        if(bw1>0)
        {
            qint64 num = 0;
            QString num1;
            query.clear();
             QSqlQuery query("SELECT * FROM `freenibs`.`pipes` WHERE `freenibs`.`pipes`.`bw`='"+bw2+"' LIMIT 1");
            //qDebug()<<"SELECT `freenibs`.`pipes`.`n` FROM `freenibs`.`pipes` WHERE `freenibs`.`pipes`.`bw`='"+bw2+"' LIMIT 1"<<endl;
             while (query.next()) {
                    num = query.value(1).toInt();
                    num1 = query.value(1).toString();
                }
            query.clear();
            if(num>0)
            {
 
                    exec_this ="/sbin/ipfw table ";
                    exec_this +=num1;
                    exec_this +=" delete ";
                    exec_this +=ip;
                    system(exec_this.toStdString().c_str());
                    //qDebug()<<exec_this<<endl;
 
 
 
            }
        }
        QSqlQuery query("INSERT INTO `freenibs`.`updown` (`ip` ,`time` ,`status`) VALUES ( '"+ip+"',CURRENT_TIMESTAMP , 'down');");
        query.clear();
     }
     db.close();
}

link-down/Makefile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#############################################################################
# Makefile for building: link-down
# Generated by qmake (2.01a) (Qt 4.4.3) on: Thu Jul 23 00:40:16 2009
# Project:  pro.pro
# Template: app
# Command: /usr/local/bin/qmake-qt4 -unix -o Makefile pro.pro
#############################################################################
 
####### Compiler, tools and options
 
CC            = cc
CXX           = c++
DEFINES       = -DQT_NO_DEBUG -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS        = -pipe -O2 -fno-strict-aliasing -pipe -Wall -W $(DEFINES)
CXXFLAGS      = -pipe -O2 -fno-strict-aliasing -pipe -Wall -W $(DEFINES)
INCPATH       = -I/usr/local/share/qt4/mkspecs/freebsd-g++ -I. -I/usr/local/include/qt4/QtCore -I/usr/local/include/qt4/QtCore -I/usr/local/include/qt4/QtGui -I/usr/local/include/qt4/QtGui -I/usr/local/include/qt4/QtSql -I/usr/local/include/qt4/QtSql -I/usr/local/include/qt4 -I. -I. -I/usr/local/include
LINK          = c++
LFLAGS        = -pthread -Wl,-rpath,/usr/local/lib/qt4
LIBS          = $(SUBLIBS)  -L/usr/local/lib -L/usr/local/lib/qt4 -lQtSql -L/usr/local/lib/qt4 -L/usr/local/lib -pthread -pthread -lQtGui -pthread -lpng -lSM -lICE -pthread -pthread -lXi -lXrender -lXrandr -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -pthread -lgthread-2.0 -lglib-2.0 -liconv
AR            = ar cqs
RANLIB        =
QMAKE         = /usr/local/bin/qmake-qt4
TAR           = tar -cf
COMPRESS      = gzip -9f
COPY          = cp -f
SED           = sed
COPY_FILE     = $(COPY)
COPY_DIR      = $(COPY) -R
INSTALL_FILE  = $(COPY_FILE)
INSTALL_DIR   = $(COPY_DIR)
INSTALL_PROGRAM = $(COPY_FILE)
DEL_FILE      = rm -f
SYMLINK       = ln -sf
DEL_DIR       = rmdir
MOVE          = mv -f
CHK_DIR_EXISTS= test -d
MKDIR         = mkdir -p
 
####### Output directory
 
OBJECTS_DIR   = ./
 
####### Files
 
SOURCES       = main.cpp
OBJECTS       = main.o
DIST          = /usr/local/share/qt4/mkspecs/common/unix.conf \
                /usr/local/share/qt4/mkspecs/qconfig.pri \
                /usr/local/share/qt4/mkspecs/features/qt_functions.prf \
                /usr/local/share/qt4/mkspecs/features/qt_config.prf \
                /usr/local/share/qt4/mkspecs/features/exclusive_builds.prf \
                /usr/local/share/qt4/mkspecs/features/default_pre.prf \
                /usr/local/share/qt4/mkspecs/features/release.prf \
                /usr/local/share/qt4/mkspecs/features/default_post.prf \
                /usr/local/share/qt4/mkspecs/features/unix/thread.prf \
                /usr/local/share/qt4/mkspecs/features/warn_on.prf \
                /usr/local/share/qt4/mkspecs/features/qt.prf \
                /usr/local/share/qt4/mkspecs/features/moc.prf \
                /usr/local/share/qt4/mkspecs/features/resources.prf \
                /usr/local/share/qt4/mkspecs/features/uic.prf \
                /usr/local/share/qt4/mkspecs/features/yacc.prf \
                /usr/local/share/qt4/mkspecs/features/lex.prf \
                pro.pro
QMAKE_TARGET  = link-down
DESTDIR       =
TARGET        = link-down
 
first: all
####### Implicit rules
 
.SUFFIXES: .o .c .cpp .cc .cxx .C
 
.cpp.o:
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
 
.cc.o:
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
 
.cxx.o:
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
 
.C.o:
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
 
.c.o:
        $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
 
####### Build rules
 
all: Makefile $(TARGET)
 
$(TARGET):  $(OBJECTS)
        $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
 
Makefile: pro.pro  /usr/local/share/qt4/mkspecs/freebsd-g++/qmake.conf /usr/local/share/qt4/mkspecs/common/unix.conf \
                /usr/local/share/qt4/mkspecs/qconfig.pri \
                /usr/local/share/qt4/mkspecs/features/qt_functions.prf \
                /usr/local/share/qt4/mkspecs/features/qt_config.prf \
                /usr/local/share/qt4/mkspecs/features/exclusive_builds.prf \
                /usr/local/share/qt4/mkspecs/features/default_pre.prf \
                /usr/local/share/qt4/mkspecs/features/release.prf \
                /usr/local/share/qt4/mkspecs/features/default_post.prf \
                /usr/local/share/qt4/mkspecs/features/unix/thread.prf \
                /usr/local/share/qt4/mkspecs/features/warn_on.prf \
                /usr/local/share/qt4/mkspecs/features/qt.prf \
                /usr/local/share/qt4/mkspecs/features/moc.prf \
                /usr/local/share/qt4/mkspecs/features/resources.prf \
                /usr/local/share/qt4/mkspecs/features/uic.prf \
                /usr/local/share/qt4/mkspecs/features/yacc.prf \
                /usr/local/share/qt4/mkspecs/features/lex.prf \
                /usr/local/lib/qt4/libQtSql.prl \
                /usr/local/lib/qt4/libQtCore.prl \
                /usr/local/lib/qt4/libQtGui.prl
        $(QMAKE) -unix -o Makefile pro.pro
/usr/local/share/qt4/mkspecs/common/unix.conf:
/usr/local/share/qt4/mkspecs/qconfig.pri:
/usr/local/share/qt4/mkspecs/features/qt_functions.prf:
/usr/local/share/qt4/mkspecs/features/qt_config.prf:
/usr/local/share/qt4/mkspecs/features/exclusive_builds.prf:
/usr/local/share/qt4/mkspecs/features/default_pre.prf:
/usr/local/share/qt4/mkspecs/features/release.prf:
/usr/local/share/qt4/mkspecs/features/default_post.prf:
/usr/local/share/qt4/mkspecs/features/unix/thread.prf:
/usr/local/share/qt4/mkspecs/features/warn_on.prf:
/usr/local/share/qt4/mkspecs/features/qt.prf:
/usr/local/share/qt4/mkspecs/features/moc.prf:
/usr/local/share/qt4/mkspecs/features/resources.prf:
/usr/local/share/qt4/mkspecs/features/uic.prf:
/usr/local/share/qt4/mkspecs/features/yacc.prf:
/usr/local/share/qt4/mkspecs/features/lex.prf:
/usr/local/lib/qt4/libQtSql.prl:
/usr/local/lib/qt4/libQtCore.prl:
/usr/local/lib/qt4/libQtGui.prl:
qmake:  FORCE
        @$(QMAKE) -unix -o Makefile pro.pro
 
dist:
        @$(CHK_DIR_EXISTS) .tmp/link-down1.0.0 || $(MKDIR) .tmp/link-down1.0.0
        $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/link-down1.0.0/ && $(COPY_FILE) --parents main.cpp .tmp/link-down1.0.0/ && (cd `dirname .tmp/link-down1.0.0` && $(TAR) link-down1.0.0.tar link-down1.0.0 && $(COMPRESS) link-down1.0.0.tar) && $(MOVE) `dirname .tmp/link-down1.0.0`/link-down1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/link-down1.0.0
 
 
clean:compiler_clean
        -$(DEL_FILE) $(OBJECTS)
        -$(DEL_FILE) *~ core *.core
 
 
####### Sub-libraries
 
distclean: clean
        -$(DEL_FILE) $(TARGET)
        -$(DEL_FILE) Makefile
 
 
mocclean: compiler_moc_header_clean compiler_moc_source_clean
 
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
 
compiler_moc_header_make_all:
compiler_moc_header_clean:
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
        -$(DEL_FILE) qmake_image_collection.cpp
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean:
 
####### Compile
 
main.o: main.cpp
        $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
 
####### Install
 
install:   FORCE
 
uninstall:   FORCE
 
FORCE:

Хостинг на моем Сервере с FreeBSD

Случалась и такая задача — совмещать мой сервер с возможность хостинга. Поначалу Я использовал apache, потом apache2. lighttp Я не юзал. Зачем? если есть отечественная разработка? Дальше Я подключил nginx — как риверс-прокси. Сейчас сложно переоценить результаты работы Игоря над маленьким, но удаленьким веб-сервером nginx! Многие хостинг провайдеры используют его в качестве оплота. Тысячи пользователей хостятся на нём. Конечно же в условиях наличия более 4-х веб-серверов нужен сайт, где бы был обзор хостинга, что бы помогло несведущим.


Leave a Comment

Ваш e-mail не будет опубликован. Обязательные поля помечены *

Загрузка...
Menu Title