Fixing Graphs for IPAudit on new Debian

This is mostly caused becasue the gnuplot and perl has changed.

 

sudo su ipaudit

cd /home/ipaudit/reports/30min/graphic

then run

./runcron

You should see some errors.

Edit every file in this director and remove “color” for gnuplot command

then navigate to ReportLog line 86 and remove defined from the line

It should be

if (@f) && f[0] ne “”;

Once this is done

./runcron

and you should see the graphs being displayed now.

Advertisements

How to replace non exsiting mssql_query and mssql_connection functions

If you moved your php application to version 7.0+ then your application may stop working if you are using MSSQL.

I have created the following library to fix my problem and replace the non-existing function with their replacement.

<?php
if (function_exists(‘mssql_connect’)){
}else{
require_once(“mssql_ovewrite.php”);
}
?>
mssql_overwrite.php
function mssql_connect($db_server, $db_user, $db_pass) {
global $link,$db_server,$db_user,$db_pass;
$connectionOptions = array(
“Database”=>”xx”,
“Uid”=> $db_user,
“PWD”=> $db_pass,
“TraceOn”=>”0”,
“CharacterSet”=>”UTF-8”,
“ConnectionPooling”=>”1”,
‘MultipleActiveResultSets’=>false
);
//Establishes the connection
$link = sqlsrv_connect($db_server, $connectionOptions);
if( $link ===false ) {
}else{
return $link;
}
}
function mssql_select_db($db_database, $link){
returntrue;
}
function mssql_query($query, $link = 0){
global $db_server,$db_user,$db_pass,$link;
if($link ==0){
$link = mssql_connect($db_server, $db_user, $db_pass);
}
$r = sqlsrv_query($link, $query,array(), array( “Scrollable” => ‘buffered’ ));
return $r;
}
function mssql_num_rows($r){
//return number of rows
returnsqlsrv_num_rows($r);
}
function mssql_fetch_object($r){
//return objects
returnsqlsrv_fetch_object($r);
}
function mssql_close(){
returntrue;
}
function mssql_fetch_array($r){
//return array
returnsqlsrv_fetch_array($r);
}

How to fix slow performing SqlSRV driver

I need to recently move one of application from Windows into Linux. The app was still using MSSQL so after fixing connection to the MSSQL I noticed that application was working very slow.

The below has fixed my problem.

Use “Scrollable” => ‘buffered’

function mssql_query($query, $link = 0){
global $db_server,$db_user,$db_pass,$link;
if($link ==0){
$link = mssql_connect($db_server, $db_user, $db_pass);
}
$r = sqlsrv_query($link, $query,array(), array( “Scrollable” => ‘buffered’ ));
return $r;
}
Then tweak the connection to MS SQL
$connectionOptions = array(
“Database”=>”CSS”,
“Uid”=> $db_user,
“PWD”=> $db_pass,
“TraceOn”=>”0”,
“CharacterSet”=>”UTF-8”,
“ConnectionPooling”=>”1”,
‘MultipleActiveResultSets’=>false
);
//Establishes the connection
$link = sqlsrv_connect($db_server, $connectionOptions);
You should notice huge improvement once completed.

Enabling PHP 7.0 communication to SQL Server

Install required packages

apt-get install php-dev

then

php7-mcrypt

then

apt-get install unixodbc-dev

then

pecl install sqlsrv-5.2.0

Once installed enable

extension=sqlsrv.so” to php.ini

 

php –init ( to check where the config files are)

touch 20-sqlsrv.ini

vim 20-sqlsrv.ini then add

extension=sqlsrv.so

Ref:

https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017

Ref:

https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-2017

 

sudo su apt-get install curl apt-transport-https wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg echo “deb https://packages.sury.org/php/ $(lsb_release -sc) main” > /etc/apt/sources.list.d/php.list apt-get update

Debian 8 and 9

Copy
sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -

#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version

#Debian 8
curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Debian 9
curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list

exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install unixodbc-dev