Netgate SG-1000 microFirewall

Author Topic: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step  (Read 46000 times)

0 Members and 1 Guest are viewing this topic.

Offline rudat

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step
« Reply #135 on: November 01, 2017, 10:10:51 am »
I'm running the latest version of pfsense with freeradius3
I followed every detail in the guide but I still cant manage to make everything work.

I did try what user "srvrgt" suggested except changing the "==" to ";=" resulted in having an attribute error. ( I left the schema file as it was "==")
I've only changed the password value to cleartext-password in the php file.

Now I am facing 2 issues.

1. Whenever a client connects and fills in the form the user gets created in sql but somehow it is not showing up on radius clients tab.

2. When a client submits the form they first get redirected to the new captive portal after clicking the accept button the default pfsense captive portal comes on with the error code that username/password is wrong however
authentication for user testu:testp works because it is in the clients tab on radius

If someone could help me that would be great!
Thank you in advance


I used the version form v0.48 - 03 May 2017
download from  https://github.com/deajan/pfSense-cp-auth-onestep

Offline rudat

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step
« Reply #136 on: November 01, 2017, 04:34:12 pm »
heyy guys, first of all thank you Deajan for the amazing work, really, it helps alot, now to my problem, i am currently on pfsense 2.3.4, and everything seems to be working fine except for the radius login part, i can see the users in the MYSQL database but they are all Rejected, the configuration of the ports on the radius server is ok, i was able to find this in the logs

 "Invalid user (sql1: Failed to create the pair: Invalid vendor name in attribute name "Password"): [123] (from client tester port 2010 cli "

i believe from what ive read that there is no such thing as apassword atribute, it must be Cleartext-Password, the problem is that i cant seem to find where to change the value, could you please help me out?,   

FYI if i use the test user and test password i can log in no problem and the mysql database also reflects that, so im guessing its just some sintaxis problem.

thanks

Do you found a Solution?

Offline retestreak

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step
« Reply #137 on: November 02, 2017, 02:18:02 am »
heyy guys, first of all thank you Deajan for the amazing work, really, it helps alot, now to my problem, i am currently on pfsense 2.3.4, and everything seems to be working fine except for the radius login part, i can see the users in the MYSQL database but they are all Rejected, the configuration of the ports on the radius server is ok, i was able to find this in the logs

 "Invalid user (sql1: Failed to create the pair: Invalid vendor name in attribute name "Password"): [123] (from client tester port 2010 cli "

i believe from what ive read that there is no such thing as apassword atribute, it must be Cleartext-Password, the problem is that i cant seem to find where to change the value, could you please help me out?,   

FYI if i use the test user and test password i can log in no problem and the mysql database also reflects that, so im guessing its just some sintaxis problem.

thanks

Do you found a Solution?

Thanks for the help :)

I've changed the Cleartext-password atribute in the schema.sql to ":=" and I had to enter my database password in the captive portal setting. Now everything works great.

Offline doken1313

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step
« Reply #138 on: November 27, 2017, 03:49:22 am »
Absolutely amazing work! Congratulations to all of you that made this system.

However I had some issues from users registering with emails with no valid domains (no mx records at all) so I am posting an addon for all of you that  want to avoid this :

Add a new error message in captiveportal-config.php like
Code: [Select]
$novalidmail_string = "The input you provided is not a valid email.";
or whatever you want to appear there and make your ozy-captive.php look like this (lines 105 - 117)
Code: [Select]
if (isset($_POST['emailAddress']))
{
$emailAddress = cleanInput($_POST["emailAddress"]);
$record = 'MX';
list($user, $domain) = explode('@', $emailAddress);
}
else
$emailAddress = false;
if (!checkdnsrr($domain, $record)  && ($askForEmailAddress == true))
{
$checkMessage = t('novalidmail_string');
$badCheck = true;
}

Once again great work !

Offline darkiazz

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step
« Reply #139 on: December 08, 2017, 08:25:33 am »
Hi guys !

I've a problem with pfSense 2.4.1 and this solution..

I've 'Invalid creditential specified' and in the system logs 'failed retrieving values required to evaluate condition'.

Do anyone can help me ?

Thanks you

Offline Darlene

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step
« Reply #140 on: January 17, 2018, 06:21:41 pm »
03 May 2017:
- New version 0.48 has php-mysqli requirements
29 Nov 2016:
- Added watchdog install
26 May 2016:
- Added new pkg procedure for 2.3 final and post 2.3 releases


Hello,

I've written a captive portal wrapper that creates the FreeeRADIUS user account and logs in in one step, all with bootstrap responsive code and validation, with configurable language that suits for hotels and public wifi providers.
Here's the full howto:



1 Introduction

pfSense-cp-auth-onestep is a project that aims to provide a captive portal interface for pfSense 2.x (currently tested on 2.2.x and 2.3-beta) that doesn't require the creation of a user account.

In fact, when a user registers, it creates the RADIUS user account and then logs in with that account.

A demo can be found at the following address:http://pfcp.netpower.fr
The latest doc can be found here: http://netpower.fr/pfcp-pfSense-auth-onestep

Initial work based on the excellent work of khan: https://forum.pfsense.org/index.php?topic=57260.0

2 Preparation of pfSense

In order to work, pfSense needs the following packages: FreeRADIUS, Cron.

Also, some upstream packages are required in order to work.

First we need to fetch some upstream packages:

Additional steps for pfSense 2.3

The repository management has changed in pfSense 2.3, and by default the FreeBSD repository is disabled.

You must edit the file /usr/local/etc/pkg/repos/pfSense.conf and set the following value:

Code: [Select]
FreeBSD: { enabled: yes }
Additional steps after 2.3 final release

You must also edit file /usr/local/etc/pkg/repos/FreeBSD.conf and set the following value:

Code: [Select]
FreeBSD: { enabled: yes }
ATTENTION: Once the packages are installed with pkg command, please set this value to 'no' again so updates won't interfere with pfSense normal functionality.

Installation of packages:

Code: [Select]
pkg
pkg update
pkg install nano git

If your pkg doesn't find the packages, you may need to reinit the pkg database with

Code: [Select]
rm -f /var/db/pkg/*.sqlite
After this, pkg update should reinitialize the pkg database.

2.1 Installation of MySQL

Although MySQL should be installed on a separate machine, it's convenient to have a single pfSense box doing the whole authentication.

Installation of MySQL isn't supported by pfSense, so you'll have to redo the following steps after every update.

2.1.1 pfSense 2.2 steps

MySQL installation

Code: [Select]
pkg install mysql56-server
pkg install compat8x-amd64

PHP support

Code: [Select]
touch /etc/php_dynamodules/mysql
/etc/rc.php_ini_setup

The following command should output mysql and mysqlnd.

Code: [Select]
php -m | grep mysql
2.1.2 pfSense 2.3 steps

MySQL installation

Code: [Select]
pkg install mysql56-server
pkg install compat9x-amd64
pkg install php56-mysql

Since v0.48 of the captive portal version, mySQL queries are done via prepared statements using mysqli.
If using pfSense-cp-onestep-auth v0.48 or higher, please replace php56-mysql package with php56-mysqli.

PHP support

The following command should output mysql and mysqlnd.

Code: [Select]
php -m | grep mysql
2.1.3 Common steps

We need to allow the MySQL service to start.

Code: [Select]
echo 'mysql_enable="YES"' > /etc/rc.conf
Also, pfSense won't start services unless their name finishes by “.sh”

Code: [Select]
mv /usr/local/etc/rc.d/mysql-server /usr/local/etc/rc.d/mysql-server.sh
2.1.4 MySQL startup fix

For whatever, pfSense won't start MySQL sometimes. If you have a tip, please tell.

In order to fix this, create the following file /usr/local/bin/mysql_relaunch.sh

Code: [Select]
#!/usr/bin/env sh 

service /mysql-server.sh status > /dev/null
if [ $? != 0 ]; then
        service mysql-server.sh start
fi

Render the file executable

Code: [Select]
chmod +x /usr/local/bin/mysql_relaunch.sh
Install the cron package and add the following entry:

Code: [Select]
*/1 * * * * root /usr/local/bin/mysql_relaunch.sh
After this, we may launch the mysql service

Code: [Select]
service mysql-server.sh start
Also, as FreeRADIUS may start before mysql and fail, install watchdog service and set it up to restart FreeRADIUS.

Secure your installation by running the following command and change your root password

Code: [Select]
/usr/local/bin/mysql_secure_installation
Optionnaly, you may create the following password file /root/.my.cnf

Code: [Select]
[client]
password="YourMySQLrootPassword"

2.2 FreeRADIUS setup

2.2.1 FreeRADIUS installation

Install the FreeRADIUS2 package via System > Packages > Available

In Services > FreeRADIUS > Users

Add a user called: testu

Set it's password: testp

in Services > FreeRADIUS > NAS / Clients

Add a NAS user:

IP: 127.0.0.1

Client Shortname: tester

Shared Secret: SuperTest (replace this with a good password)

In Services > FreeRADIUS > Interface

Add the interface the RADIUS server should listen on: 127.0.0.1

You can now check in Status > System Logs that the server is active

Quote
Sep 29 14:54:50   radiusd[10330]: Loaded virtual server <default>
Sep 29 14:54:50   radiusd[13493]: Ready to process requests.

Connect to pfSense via ssh or console and check if FreeRADIUS authenticates (replace SuperTest with your Shared Secret):

Code: [Select]
radtest testu testp 127.0.0.1:1812 0 SuperTest
The answer should look like:

Quote
Sending Access-Request of id 108 to 127.0.0.1 port 1812
        User-Name = "testu"
        User-Password = "testp"
        NAS-IP-Address = 192.168.1.1
        NAS-Port = 0
        Message-Authenticator = 0x00000000000000000000000000000000
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=108, length=20

Check authentication in Status > System Logs

Code: [Select]
Sep 29 15:04:51 radiusd[22223]: Login OK: [testu] (from client pfSense port 0)
#TIP: See https://doc.pfsense.org/index.php/Testing_FreeRADIUS for tuning and troubleshooting

2.2.2 MySQL FreeRADIUS integration

First we need to create the RADIUS database. Launch the “mysql” program. If you didn't create the /root/.my.cnf password file, launch “mysql -p” and execute the following statements:

Code: [Select]
CREATE DATABASE  `radius`;
exit

We also have to get a copy of the sql files needed for the captive portal.

You can fetch them via wget at http://netpower.fr/sites/default/files/soft/bin/pfSense-cp-auth-onestep.gz or directly via git:

Code: [Select]
cd /root
git clone https://github.com/deajan/pfSense-cp-auth-onestep
cd /root/pfSense-cp-auth-onestep/sql

We need to integrate every .sql file into the radius database. Please execute the admin.sql file at last because it contains definitions for the other files. Add “-p” to myql if you don't have created the password file.

Before running those commands, modify the admin.sql file in order to replace the default password 'radpass'. (Use vi or nano if installed).

Code: [Select]
mysql radius < cui.sql
mysql radius < nas.sql
mysql radius < radippool.sql
mysql radius < schema.sql
mysql radius < wimax.sql
mysql radius < reg_users.sql
mysql radius < admin.sql

Activate SQL support in Services > FreeRADIUS > SQL:

Enable SQL Support: Enable

Enable SQL Authorization: Enable

Enable SQL Accounting: Enable

Enable SQL Session: Enable

Enable SQL Post-Auth: Enable

Server IP Address --> 127.0.0.1

Server Port --> 3306

Server Database -> radius

Server User -> radius

Server Password -> radpass (replace with your database password).

MySQL authentication test

Execute the following command (replace SuperTest with your Shared Secret):

Code: [Select]
radtest testu testp 127.0.0.1:1812 0 SuperTest
The radpostauth table should contain the authentication info:

Code: [Select]
mysql -p -e "SELECT * FROM radpostauth;" radius
Quote
+----+----------+-------+---------------+---------------------+
| id | username | pass  | reply         | authdate            |
+----+----------+-------+---------------+---------------------+
|  1 | testu    | testp | Access-Accept | 2015-09-29 15:13:24 |
+----+----------+-------+---------------+---------------------+

2.3 Enable captive portal

2.3.1 Setup

Grab a copy of the pfSense-pfcp-auth-onestep files via github or via the following link http://netpower.fr/sites/default/files/soft/bin/pfSense-cp-auth-onestep.gz

Uncompress the file and edit captiveportal-config.php to meet your settings, especially the database password.

Create a new zone in Services > Captive Portal . Example “PUBLICWIFI”

In Services > Captive Portal > File Manager, upload all the files from pfSense-pfcp-auth-onestep beginning with “captiveportal-*”

The following files need to be uploaded:

Quote
captiveportal-bootstrap.min.css
captiveportal-bootstrap.min.js
captiveprotal-jquery.validate.js
captiveportal-jquery-1.11.3.min.js
captiveportal-background.jpg
captiveportal-sidelogo.png
captiveportal-check_readio_sheet.png
captiveportal-termsofuse.html
captiveportal-config.php

#TIP: I had trouble with uploading the files in pfSense 2.2.6. After every 3 files, I had to restart WebConfigurator via ssh.

We Can now enable the captive portal on the LAN interface or whatever interface you need.

We also need to activate RADIUS authentication:

IP: 127.0.0.1

Port: 1812

Shared Secret: SuperTest (or your Shared Secret)

Radius Protocol: PAP

Account Check:

Send RADIUS accounting packets: Enable

Port: 1813

Accounting updates: stop/start accounting (FreeRADIUS if available)

RADIUS NAS IP attribue: LAN IP (or whatever interface you selected)

Portal page contesnts: Upload file ozy-captive.php

Redirection URL: Whatever you'd like, example: http://www.google.com

2.3.2 Testing

Once enabled, you can open a browser and enter any domain. You should end on the captive portal page.

You may access directly to the captive portal via http://[pfSenseIP]:8002

#TIP: Your computer should use DHCP and use the pfSense IP as DNS server or the redirection won't work.

If the redirection still doesn't work, check that the DNS Resolver service is running without the forwarding mode.

Also, if your computer already has the domain in DNS cache, you may have to flush dns cache.

On Linux:

Code: [Select]
service nscd restart
On Windows:

Code: [Select]
ipconfig /flushdns
At least, close and reopen your browser so it would make a new DNS query.

Fell free to help improve this howto.

Regards,
zy.

please how do u edit and enter the code?

Offline Gertjan

  • Hero Member
  • *****
  • Posts: 2421
  • Karma: +190/-9
    • View Profile
Re: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step
« Reply #141 on: January 17, 2018, 11:59:59 pm »
please how do u edit and enter the code?
Using a keyboad and your hands ?!

Of course, a more specific answer is possible as soon as we know what kind of device you use.

Offline mansoor.khan

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step
« Reply #142 on: January 19, 2018, 08:59:32 am »
Hello,

I am facing problem in login page from Captiveportal.


I am using the default login Form Html code with Form action 'action ="$PORTAL_ACTIONS"' and still I am continuously getting Access-Reject message in Mysql table 'radpostauth'.

I am using Pfsense 2.4.2 with freeRadius3 pakage and mysql Server 5.6.39.

When I create user from Captiveportal -> Users login page works fine then. Also with NO authentication login page is working.

But I need this with Mysql database authentication.


Did anyone face problem like this? If you have solution in mind please let me know.

Thanks in advance


Offline Ophion

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step
« Reply #143 on: February 08, 2018, 10:27:12 am »
Great work! Appreciated.

Offline Darlene

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step
« Reply #144 on: February 13, 2018, 04:26:43 am »
Please how do you edit those files you mentioned earlier

Offline Gertjan

  • Hero Member
  • *****
  • Posts: 2421
  • Karma: +190/-9
    • View Profile
Re: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step
« Reply #145 on: February 13, 2018, 05:25:33 am »
Please how do you edit those files you mentioned earlier
Who is you ?
What file ?

Offline pama

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
    • Pama billing and machine tools
Re: [HOWTO] Captive portal + FreeRADIUS + local MySQL user friendly single step
« Reply #146 on: February 15, 2018, 01:30:36 am »
Please help, I am not able to install mysql...how can you get it working? Thank you