Block IPs

Use this forum if you have installed hMailServer and want to ask a question related to a production release of hMailServer. Before posting, please read the troubleshooting guide. A large part of all reported issues are already described in detail here.
eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Block IPs

Post by eliassal » 2020-02-01 16:58

Hi, is it possible to block IPs in hMailServer server somewhere (I am not asking about DNS blacklist). Something like a flat list of IPs that should not be allowed to connect to hMailServer (similar to a firewall list).

Why I am asking this question is because I am blocking IPs that I discover in Hmailserver logs but the problem is that my router/firewall has a limit of 16 IPs of its blacklist

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-01 16:58

Firewall blacklist

User avatar
Dravion
Senior user
Senior user
Posts: 1688
Joined: 2015-09-26 11:50
Location: Germany
Contact:

Re: Block IPs

Post by Dravion » 2020-02-01 17:21

Maybe this is a good starting point
https://www.hmailserver.com/forum/viewt ... 21&t=32829

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-01 17:54

Thanks, I followed instructions in the thread you provided, added 5 IPs, letys see :D

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-01 18:57

eliassal wrote:
2020-02-01 16:58
Firewall blacklist
http://hmailserver.com/forum/viewtopic.php?f=9&t=34082

hMailServer Firewall Ban

Ban IPs to windows firewall. Complete with PHP admin/management.

If you care to try it out, wait a few hours before downloading it. I have an update in the works that I hope to upload within 3 hours from now. I finished the update, but I have something running now that needs to end before I can test it out for bugs.

User avatar
jim.bus
Senior user
Senior user
Posts: 452
Joined: 2011-05-28 11:49
Location: US

Re: Block IPs

Post by jim.bus » 2020-02-09 12:26

The other guys who have been responding are better at this than I am.

But I ban IPs too but I do it through hMailServer's IP Ranges function. You simply create this list in the set of IP Ranges which prevents the IP Address from processing in hMailServer. In the logs you will see the IP Address connect but then immediately the session will terminate because the IP Address has been banned. A problem with doing it this way is depending on how many IP Addresses you want to ban, your list could be quite lengthy. It could also probably add some processing time to hMailServer. I don't know the internals of hMailServer to say if this would be a performance hit. I have 40 IP Address bans set up in hMailServer. The Windows Firewall method of course though prevents the IP Addresses from ever reaching hMailServer as does your Router Firewall as well. The problem with using Windows Firewall is if you choose to use another Firewall such as McAfee, maybe Kaspersky, Norton, etc. then Windows Firewall is disabled.

You can find the IP Ranges by going to Settings>Advanced>IP Ranges. To make the entry, you specify a beginning and ending IP Range for each entry (if you have a sequential block of IPs then on one IP Range entry is needed). You uncheck (disable) all the Protocols (POP3, IMAP, SMTP) and uncheck all the other specifications disallowing any deliveries, etc. In short uncheck all the check boxes. Set a Priority higher than any other priority for the IP Range.

You should be aware that the IP Address you are blocking might actually be a legitimate IP Address and some hacker is using the IP Address which means you may be potentially blocking legitimate email from reaching hMailServer. This would be the same issue if you were using Wiondows Firewall, your Router Firewall, or any other Firewall as well.

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-12 16:13

Hello Palinka, sorry for my late come back

I went through the http://hmailserver.com/forum/viewtopic.php?f=9&t=34082 (half-way)
it is really what I am looking for, I was disappointed when I initially read that it was only compatible with mysql, then I understood that enhancements were done to be compatible with SQL server at
https://github.com/palinkas-jo-reggelt/ ... n/issues/1 ,
my server is sql, big discussions and a lot of efforts, great . Now couple of questions:
- what is the latest version that I should download for SQL server and the latest instructions as well as the nice web site you created ?
- 2nd, I did not figure out how hMailServer will ban email? Based on what info that it will add the ip to the DB?

Thanks in advance

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-12 23:51

eliassal wrote:
2020-02-12 16:13
Hello Palinka, sorry for my late come back

I went through the http://hmailserver.com/forum/viewtopic.php?f=9&t=34082 (half-way)
it is really what I am looking for, I was disappointed when I initially read that it was only compatible with mysql, then I understood that enhancements were done to be compatible with SQL server at
https://github.com/palinkas-jo-reggelt/ ... n/issues/1 ,
my server is sql, big discussions and a lot of efforts, great . Now couple of questions:
- what is the latest version that I should download for SQL server and the latest instructions as well as the nice web site you created ?
- 2nd, I did not figure out how hMailServer will ban email? Based on what info that it will add the ip to the DB?

Thanks in advance
I think it should be good now. I've reached out to the fellow helping me with the mssql queries and I'm waiting to hear back if the last changes are actually final or not. But its either done completely or 99.9% done. :D

You should give it a try as it is. The powershell stuff is very complete. If there are any bugs, they're in the PHP, which really won't have any effect on whether your system is actually working or not. If you have any issues, post in the firewall ban thread.

Also, bear in mind that unless a MSSQL-specific issue is very simple, I probably can't help you and you'd have to post an issue on the lcamilo's GitHub page. But the rest of it I'm good with. As with any software, the bugs are 99.9% typos that can be easily fixed if we know about them.

For me, everything is working great and I'm using the same code that's on GitHub except for the eventhandlers stuff, which I haven't (yet) bothered trying to setup on my system.

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-13 00:35

Don't worry Panilka, I am personally certified SQL server, I worked more than 15 years administring SQL. I did also T-SQL dev long time ago (when I was young :lol: ) between 2000-2005. But I still do some t-sql programming im my spare time so I dont forget.
In any case I saw on the github the discussion, you can ask me of course if you have any other issue

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-13 01:08

Yes, I like to try but you did not answer my 2 questions :D

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-13 02:46

eliassal wrote:
2020-02-13 01:08
Yes, I like to try but you did not answer my 2 questions :D
- what is the latest version that I should download for SQL server and the latest instructions as well as the nice web site you created ?
- 2nd, I did not figure out how hMailServer will ban email? Based on what info that it will add the ip to the DB?
First - version of firewall ban or version of sql? If you meant the firewall ban, use the latest. If you meant sql, I have no idea. I did not write the queries for mssql. Maybe you should have a look at a few queries if there are differences in syntax between versions.

Second - The way it works is like this:

1) You set up eventhandlers.vbs to trigger the firewall ban on criteria that you decide. I have some examples for geoip, spamhaus and others.
2) When the firewall ban is called by eventhandlers.vbs, it writes the IP and other information to the database.
3) Task scheduler launches a powershell script that retrieves the latest IPs and creates a firewall rule.

That's the basic concept. The PHP admin allows you to view and modify bans. You can search based on a number of different critera and release an IP (remove firewall rule), make an IP permanently safe from being banned in the future and some other things. Everything that happens with the PHP is manipulating the database. Then, based on flags created by the PHP, the powershell script does things like remove firewall rules, create new rules, etc.

Its grown into something fairly complex. Its working great for me. I'm almost up to 20k banned IPs. I don't really see any practical limit to the number of IPs you can ban. Its chugging along happily day after day.

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-13 20:38

Screenshot_20200213-133411_Brave.jpg
Here you go. Today's hits. The "FB" column is firewall blocks, counted from the firewall log. None of those ever presented themselves to hmailserver since they were dropped at the firewall. :mrgreen:

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-13 21:19

fantastic. I went again through Instructions section , are those the most up to date to follow? A lot of things to setup wow :D

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-13 21:46

eliassal wrote:
2020-02-13 21:19
fantastic. I went again through Instructions section , are those the most up to date to follow? A lot of things to setup wow :D
Yes. That's the latest, except I haven't changed it for the new functions in eventhandlers.vbs (for choice of mysql or mssql queries). Give it a shot and let me know if you run into errors.

Since you're adept at mssql, you may want to just dump the "choice" functions and go straight with mssql queries.

The worst of the setup is ther vbs side.

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-14 00:40

OK, I will backup my hmailserver tomorrow and start this endeavor

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-14 13:55

Palinka, while I started backup to prepare for using this stuff, I noticed that there was already a directory phpwebadmin in hmailserver directory, I was not aware of it. I decided to set it up.
My IIS is version 10.0 running on windows server 2016 (this is where hMailserver runs), I installed php 5.3, phpinfo.php runs fine, followed all instructions at
hmailserver.com/documentation/v5.3/?page=howto_install_phpwebadmin
hmailserver.com/documentation/v5.3/?page=ts_setup_phpwebadmin
hmailserver.com/documentation/latest/index.php?page=howto_dcom_permissions
still when i try to run

http://localhost/PHPWebAdmin/

I get
Fatal error: Class 'COM' not found in C:\inetpub\wwwroot\PHPWebAdmin\initialize.php on line 13
I played with application pools identity, even I tried Administrator credentials which has full privileges on DCOM hmailserver, no way always getting this error

User avatar
Dravion
Senior user
Senior user
Posts: 1688
Joined: 2015-09-26 11:50
Location: Germany
Contact:

Re: Block IPs

Post by Dravion » 2020-02-14 14:35

Try this

Open your loaded PHP.INI, assuming your PHP Path is something like this

C:\Program Files\PHP\php.ini

Lookup this section
"Dynamic Extensions "

Your will see a lot of PHP Extension listed ( if ; stand before, it means its not enabled)
Check the list of Extensions carefully and if you cannot find the php_com_dotnet Extension,
just add it like this

extension=php_com_dotnet

Save the PHP.INI file, close it and just reopen it in Notepad and check if it was really saved.
If you cant save your PHP.INI file because of a permission issue, just click your Windows Start Menue, type in Notepad,
right click it (if it was found) and select "run as Administrator". Now open your PHP.INI file.
After it, Restart Your Microsoft Internet Information Server (IIS) Webserver service and check if PHPWebAdmin works as expected.

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-14 15:01

I tried the suggestion at
https://serverfault.com/questions/42350 ... on-line-22

but it did not workm i will try yours now

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-14 15:08

Yeeees it workedm you are the man sirm I was able to access the server

User avatar
Dravion
Senior user
Senior user
Posts: 1688
Joined: 2015-09-26 11:50
Location: Germany
Contact:

Re: Block IPs

Post by Dravion » 2020-02-14 15:11

Glad you solved it :)

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-14 17:35

Palinka, I downloaded the files (master), there is no sql creation tables. I sa that there are 2 other branches AddSQL support and FixSqlquery, which one I should use between those 3 branches?
IN the setup instructions, you indicate in point
5 "Edit variables in hmsFirewallBan.ps1"
There are no variables in this ps file. I think you mean "Config.ps1"

3rd, all thos Powershell files where they should be copied? in which directory?

Last question, If I understand well, I should run hmsFirewallBan.ps1 at least one in order to create the tables in the database? of course once you confirm from which branch I should get it

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-14 17:43

As I copied all code in EventHandlers.vbs to my one on the server for the time being only to my hmailserver, I started to see the following error in the log

"ERROR" 5928 "2020-02-14 16:26:54.558" "Script Error: Source: hMailServer COM library - Error: 800403E9 - Description: You do not have access to this property / method. Ensure that hMailServer.Application.Authenticate() is called with proper login credentials. - Line: 186 Column: 4 - Code: (null)"

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-14 18:31

eliassal wrote:
2020-02-14 17:35
Palinka, I downloaded the files (master), there is no sql creation tables. I sa that there are 2 other branches AddSQL support and FixSqlquery, which one I should use between those 3 branches?
IN the setup instructions, you indicate in point
5 "Edit variables in hmsFirewallBan.ps1"
There are no variables in this ps file. I think you mean "Config.ps1"

3rd, all thos Powershell files where they should be copied? in which directory?

Last question, If I understand well, I should run hmsFirewallBan.ps1 at least one in order to create the tables in the database? of course once you confirm from which branch I should get it
First, use the current master. Always.

Second, I did not update the instructions yet since beginning the conversion to include mssql queries. Config.ps1 is correct for user variables. All of the functions for differentiating mysql/mssql are located in CommonCode.ps1.

Third, place the powershell in any folder you want - so long as the admin user or SYSTEM user that you define in task scheduler has access. All of the powershell files refer to $PSScriptRoot\ for folder locations so it doesn't matter where they go as long as they are together in the same folder. New folders for various things are created relationally like that as well (to keep things tidy so your main folder isn't clogged up with the various txt/csv files needed for running certain functions).

EventHandlers.vbs, of course, is your hmailserver one.

The files in the www folder need to go where your webserver can read and serve them out.

hMailServer's PHP webadmin has nothing to do with my project, although its a very handy thing to have working.

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-14 18:43

eliassal wrote:
2020-02-14 17:43
As I copied all code in EventHandlers.vbs to my one on the server for the time being only to my hmailserver, I started to see the following error in the log

"ERROR" 5928 "2020-02-14 16:26:54.558" "Script Error: Source: hMailServer COM library - Error: 800403E9 - Description: You do not have access to this property / method. Ensure that hMailServer.Application.Authenticate() is called with proper login credentials. - Line: 186 Column: 4 - Code: (null)"
Either you didn't put the correct password in the variables or you're missing a function.

The fellow helping me with the mssql queries also created an INI file for user variables. That just complicated things, IMO. Add the following to the top of your eventhandlers.vbs:

Code: Select all

Private Const ADMIN = "Administrator"
Private Const PASSWORD = "supersecretpassword"
Private Const EVENTDIR = "C:\Program Files (x86)\hMailServer\Events"
Private Const LOGDIR   = "C:\Program Files (x86)\hMailServer\Logs"
Private Const TEMPDIR  = "C:\Program Files (x86)\hMailServer\Temp"
Private Const idsTable = "hm_ids"
Private Const DatabaseType = "MSSQL"
Then copy the functions from CommonCode.vbs to EventHandlers.vbs.

When I have time, I'll go through his changes and move them all back into EventHandlers.vbs which is where everything should be all together. I don't see any reason to have multiple files for hmailserver (except VbsJson.vbs, which is quite long).

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-14 18:45

OK I will run then in a powershell terminal the hmsFirewallBan.ps1 script

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-14 18:47

but tell me what hmsFirewallBanDBSetup.ps1 does, who is calling it?

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-14 18:54

shouldnt I run hmsFirewallBanDBSetup.ps1 before schedueling hmsFirewallBan.ps1?

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-14 19:09

eliassal wrote:
2020-02-14 18:54
shouldnt I run hmsFirewallBanDBSetup.ps1 before schedueling hmsFirewallBan.ps1?
Yes. Otherwise you will have no database into which you place your data. That could also be the root of your vbs error: Error: 800403E9 - Description: You do not have access to this property / method. I was thinking it was an authentication issue, but is probably just no database at all. :D

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-14 19:10

eliassal wrote:
2020-02-14 18:45
OK I will run then in a powershell terminal the hmsFirewallBan.ps1 script
Run from task scheduler every 5 minutes.

Or any interval you want, but make sure the $Interval user variable matches whatever you put in the task scheduler.

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 12:13

Palinka, here is my 1st notes
1- Access to SQL can be done in 2 ways, either Trusted connection or user/password. In my environment, I updated the connection string as follows and it worked fine so the tool should allow to chose 1 of them

Code: Select all

$ConnectionString = "Server=" + $SQLHost + ";" + "Database=" + $SQLDatabase + ";Trusted_Connection=true"
2 - I managed to create the tables

3 - in the instructions for the web site, you mention "update cred.php", there is no cred.php, I think you mean config.php. For sql, we have this,

Code: Select all

$Database = array (
	'dbtype'      => 'MSSQL',
	'host'        => 'SQL\SC2K12',
	'username'    => 'myuser',
	'password'    => 'myuser',
	'dbname'      => 'hmailserver',
	'driver'      => 'mysql',
	'port'        => '3306',
	'dsn'         => 'MariaDB ODBC 3.0 Driver'
);
Today using ODBC is very rare for sql generally speaking, sometimes in specific cases.

Anyway, when I try to access the ban web site I get
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\inetpub\wwwroot\PHPBanAdmin\functions.php:6 Stack trace:
#0 C:\inetpub\wwwroot\PHPBanAdmin\functions.php(6): PDO->__construct('sqlsrv:Server=S...', 'myuser', 'myuser') #1
C:\inetpub\wwwroot\PHPBanAdmin\charthitsperdaycombined.php(2):
include_once('C:\inetpub\wwwr...')
#2 C:\inetpub\wwwroot\PHPBanAdmin\head-g.php(14):
include('C:\inetpub\wwwr...')
#3 C:\inetpub\wwwroot\PHPBanAdmin\index.php(1): include('C:\inetpub\wwwr...')
#4 {main} thrown in C:\inetpub\wwwroot\PHPBanAdmin\functions.php on line 6
4 - Errors disappeared in hMailServer but nothing is written to the table [hm_fwban], can you please remind me what are the rules so data can be written to this table?

5 - I agree with you, code should be cleaned somehow especially when talking to Database. In C#, I used Datafactory pattern in the past in order to be able to develop applications that you can plug whatever database, I am not sure if this can be done in vbs, last time I worked with VBS was 2000.

In any case nice efforts and we should continue to improve this tool and make it more robust as attacks are there 24x24 7x7. If any help needed I will be more than happy

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 12:23

Also if possible, whhile I am waiting my table gets populated, can you please share some records for blocked IPs from [hm_fwban] your so I can test the other functions of the powershell

User avatar
Dravion
Senior user
Senior user
Posts: 1688
Joined: 2015-09-26 11:50
Location: Germany
Contact:

Re: Block IPs

Post by Dravion » 2020-02-15 12:28

You need to install the MS-SQL Server Driver for the exact PHP Version you are running

https://docs.microsoft.com/en-us/sql/co ... rver-ver15

Then you need to follow this instructions to enable it in PHP.INI
https://docs.microsoft.com/en-us/sql/co ... rver-ver15

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 14:36

But why the phpwebadmin worked without this driver, it talks to sql as well, no?

User avatar
SorenR
Senior user
Senior user
Posts: 3743
Joined: 2006-08-21 15:38
Location: Denmark

Re: Block IPs

Post by SorenR » 2020-02-15 15:11

eliassal wrote:
2020-02-15 14:36
But why the phpwebadmin worked without this driver, it talks to sql as well, no?
No, it uses DCOM to the hMailServer application.
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 15:22

OK, but which version of the driver I shlould setup the 5.3 or 7.3?
Yesterday I configured my IIS to use 5.3 in order to make phpwebadmin works

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 15:25

VBS scripts seems working fine, I got 1 record in ids table now :lol:

Code: Select all

timestamp	ipaddress	hits	country	helo
2020-02-15 13:54:14.547	185.36.81.23	1	Republic of Lithuania	NULL

User avatar
Dravion
Senior user
Senior user
Posts: 1688
Joined: 2015-09-26 11:50
Location: Germany
Contact:

Re: Block IPs

Post by Dravion » 2020-02-15 15:28

According to Release info, you need atleast a PHP 7.x version.
PHP 5.3 isn't supported anymore.

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 15:48

OK, I have already downloaded 7.3

for the record I got, Powershell correctly created the firewall rule but was not able to insert the record in hwban table, after debugging I saw this error in sql, I will investigate, have you seen this?

Code: Select all

INSERT INTO hm_fwban 
  (timestamp,ipaddress,ban_reason,country,flag,ptr,rulename) 
  VALUES (GETDATE(),'185.36.81.23','IDS','Republic of Lithuania',NULL,'No.PTR.Record','185.36.81.23');

Msg 8152, Level 16, State 30, Line 13
String or binary data would be truncated.
The statement has been terminated.

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 16:15

I solved the sql truncation issue, I dont know why the field ipaddres was created with varchar(1)

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 17:12

for the web sit even after setting the driver, I am still getting the same error, here is what i have in my php.config
$Database = array (
'dbtype' => 'mssql',
'host' => 'SQL\SC2K12',
'username' => 'myuserrun',
'password' => 'myuserrun',
'dbname' => 'hmailserver',
'driver' => 'mssql',
'port' => '49207',
'dsn' => ''
);

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 18:05

well I added the foloowing 2 lines in the php.ini
extension=php_sqlsrv_7_ts.dll
extension=php_pdo_sqlsrv_7_ts.dll
error disappeared but I am getting a blank page

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 18:06

how can we debug this? I am not well versed with php

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-15 20:21

eliassal wrote:
2020-02-15 17:12
for the web sit even after setting the driver, I am still getting the same error, here is what i have in my php.config
$Database = array (
'dbtype' => 'mssql',
'host' => 'SQL\SC2K12',
'username' => 'myuserrun',
'password' => 'myuserrun',
'dbname' => 'hmailserver',
'driver' => 'mssql',
'port' => '49207',
'dsn' => ''
);
You sure this is right? Shouldn't it be just SC2K12?

Try changing that first. Then if that doesn't work try hard-coding the pdo connection statement in functions.php to make sure its not an issue with retrieving the variables.

$pdo = new PDO("sqlsrv:Server=SC2K12,49207;Database=hmailserver, myuserrun, mypassword");

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-15 20:24

Also, exactly what version of PHP are you running? This definitely seems to be something in your environment.

I'm on 5.6 so I know it works. I haven't tested with PHP 7 yet. That potentially could be an issue, but I think its unlikely.

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 20:40

yes, SQL\SC2K12, it is correct as this is not the default instance. IN sql world, you can have a default instance and as much as other instances, each instance is an independant sql server but running on the same server except that they use dynamic ports and not like th edefault which listens on port 1433. PS scripts abd VBS work well

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 20:41

my hMailsServer is 5.6.6-B2383

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 20:46

I hard coded the connection, same result, blank page. I triggered SQL profiler, the web site is not reaching the sql server

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-15 21:04

eliassal wrote:
2020-02-15 20:41
my hMailsServer is 5.6.6-B2383
I meant what version of PHP?

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 21:20

7.0.3. I started debugging with my little knowledge, in fact the site is not reaching rhe Functions.php.

I added this

Code: Select all

if( $pdo ) {
     echo "Connection established.<br />";
		}else{
		echo "Connection could not be established.<br />";
		die( print_r( sqlsrv_errors(), true));
	}
nothing happens, only blank page

I thought it was because of include in iis, I checked with very simple include files it works except I use quout instead of double quote, I will change your index file to use
include_once 'dddd'
when I dispaly the source of The blank page, I have only this

Code: Select all

<!DOCTYPE html> 
<html>
<head>
<title>hMailServer Firewall Ban</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="all" href="stylesheet.css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet"> 
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 21:20

do you want me to revert to version 5.0.3?

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 21:41

There is somthing strange, include files are not gettting executed. I did the fllowing
- Created a.php file
in this file I put

Code: Select all

<?php

echo "file <br />";

?>
I add an include in index.php can see it in the as follows

Code: Select all

include_once 'config.php';
include_once 'functions.php';
include_once 'a.php';
I see the output in the browser
<!DOCTYPE html>
<html>
<head>
<title>hMailServer Firewall Ban</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1">
........
.....
<script src="https://ajax.googleapis.com/ajax/libs/j ... "></script>
file <br />
In index I added the following just after after the variable $today

Code: Select all

$today = date('Y-m-d');
echo $today ;
nothing was echoed. I put the same thing in a.php, I get the echo correctly
<!DOCTYPE html>
<html>
<head>
<title>hMailServer Firewall Ban</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="all" href="stylesheet.css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/j ... "></script>
file <br />2020-02-15

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 21:43

what version of PHP you use, in my environment I have
7.0.30
and
5.3.28
In IIS I can switchbetween anyone of them

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-15 23:24

eliassal wrote:
2020-02-15 21:20
I thought it was because of include in iis, I checked with very simple include files it works except I use quout instead of double quote, I will change your index file to use
include_once 'dddd'
when I dispaly the source of The blank page, I have only this

Code: Select all

<!DOCTYPE html> 
<html>
<head>
<title>hMailServer Firewall Ban</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="all" href="stylesheet.css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet"> 
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
include is working because the html from head.php is shown in your source. :D

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-15 23:26

eliassal wrote:
2020-02-15 21:43
what version of PHP you use, in my environment I have
7.0.30
and
5.3.28
In IIS I can switchbetween anyone of them
Apache/2.4.26 (Win32)
PHP/5.6.31

I'm reasonably certain there are no non-backward-compatible PHP functions (everything *should* work with PHP 5.3).

I'm almost certain there are no deprecated PHP functions (everything REALLY *should* work with PHP 7).

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-15 23:37

OK, so I don't know what to do more than this, what do you think?

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-16 03:33

I'm out of ideas. Are you using the built in sql that comes with hmailserver? Or a standalone sql server?

What happens when you do phpinfo()?

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-16 11:37

No a standalone server. Palinka, I am thinking of creating your phpbam in ASP.Net/C#.

Can you provide me screenshots of the php ban pages, also if possible the rules to follow in the functions in a bullteted list

eliassal
Normal user
Normal user
Posts: 221
Joined: 2010-08-15 18:05
Contact:

Re: Block IPs

Post by eliassal » 2020-02-16 13:52

Palinka, I checked the php version on one of my desktops, I discovered it was 5.3.28.

I visited the download page at
https://docs.microsoft.com/en-us/sql/co ... rver-ver15
thers is
The following versions of the drivers for PHP on Windows are available for download:
•Microsoft Drivers 5.8 for PHP for SQL Server
•Microsoft Drivers 5.6 for PHP for SQL Server
•Microsoft Drivers 5.3 for PHP for SQL Server
•Microsoft Drivers 5.2 for PHP for SQL Server
•Microsoft Drivers 4.3 for PHP for SQL Server
•Microsoft Drivers 4.0, 3.2, 3.1, and 3.0 for PHP for SQL Server
Evene the last 1 is not compatible with PHP version 2.3 as indicated at the url


https://www.microsoft.com/en-us/downloa ... x?id=20098
Supported Operating System

Windows 7, Windows 8, Windows 8.1, Windows Server 2008 R2, Windows Server 2008 Service Pack 2, Windows Vista Service Pack 2
Operating Systems supported in this update:
Ubuntu 15.04, 16.04
RedHat 7

Requires PHP 7 or 5.x. For information about how to download and install the latest stable binaries, visit http://windows.php.net for more detail. Version support for PHP is as follows
•Version 4.0 supports PHP 7.0+ on Windows and Linux
•Version 3.2 supports PHP 5.6, 5.5, and 5.4 on Windows
•Version 3.1 supports PHP 5.5 and 5.4 on Windows
•Version 3.0 supports PHP 5.4 on Windows
So there is no driver for PHP 5.3 !!!!!

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-16 15:25

Can't you just upgrade php?

palinka
Senior user
Senior user
Posts: 2073
Joined: 2017-09-12 17:57

Re: Block IPs

Post by palinka » 2020-02-16 15:29

eliassal wrote:
2020-02-16 11:37
No a standalone server. Palinka, I am thinking of creating your phpbam in ASP.Net/C#.

Can you provide me screenshots of the php ban pages, also if possible the rules to follow in the functions in a bullteted list
I have a demo at http://hmsfirewallbandemo.ddns.net/

Everything works except for actual firewall rule changes. It runs on a database separate from my personal installation, so feel free to do whatever you want with it.

By the way, it runs very slow right now but by the end of the day it will be much faster thanks to a new strategy I'm putting together. Almost done. Big improvement on speed.

Post Reply