Server

Net Share Commands

We can use net share command to create, configure and delete network shares from command line . Below you can find syntax and examples for net share command.

Create a network share from command line

The syntax for creating a share is as follows.

net share sharename=folderpath /grant:username,permissions

sharename: You can assign name to the share you are going to create
username : Login id of the user whom you want to share the folder with
permission: Read, Change or Full

For example to share the folder E:\Docs with everyone in the domain and to give full permissions

net share Docs=E:\Documents /grant:everyone,FULL

If you are allowing multiple users to access the share, you can limit the number of users accessing the share simultaneously. This will prevent performance impact on your system. The below command will set the limit to 10 users.

net share Docs=E:\Documents /grant:everyone,FULL  /users:10

Command to share with a specific user and to grant only read rights:

net share Docs=E:\Documents /grant:username,READ

Delete network share(i.e to disable sharing of the folder) from command line

net share sharename /delete

For example, to delete the share created above, the command would be as below.

net share docs /delete

Alternatively, we can use the folder physical location also to disable sharing

 net share E:\Docs /delete

List the shared created on the local computer

net share

Delete the share on a remote computer

net share sharename \\remotepc /delete

check time with powershell


function Get-MyDate{
[CmdletBinding()]
param(
[Parameter(Mandatory=$True,
ValueFromPipeLine=$True,
ValueFromPipeLineByPropertyName=$True,
HelpMessage="ComputerName or IP Address to query via WMI")]
[string[]]$ComputerName
)

foreach($computer in $computerName){
$timeZone=Get-WmiObject -Class win32_timezone -ComputerName $computer
$localTime = Get-WmiObject -Class win32_localtime -ComputerName $computer
$output =@{'ComputerName' = $localTime.__SERVER;
'Current Time' = (Get-Date -Day $localTime.Day -Month $localTime.Month);
}
$object = New-Object -TypeName PSObject -Property $output
Write-Output $object
}
}

get-mydate -ComputerName MyComputerName

Debian 9 as a Veeam backup destination over SSH

Clean installation of a Debian 9.
install required packages:
– openssh-server
– libsoap-lite-perl

How to mount a physical crypted disk on another debian 9 system:

apt-get install cryptsetup
apt-get install lvm2
--
lvscan
lvscan vgchange -ay
lvscan --help
lvscan
mount /dev/mapper/luks-9a9a7076-a9e3-4393-8132-bd0ee666d171 /mnt
sudo fdisk -l
fdisk -l
udisksctl unlock -b /dev/sdb5
mount /dev/dm-0 /mnt
vgchange -ay
lvscan
mount /dev/backup2-vg/root /mnt
cd /mnt/veeam_backup/
--
fdisk -l
lvscan
udisksctl unlock -b /dev/sdb5
vgchange -ay
mount /dev/dm-0 /mnt
mount /dev/backup2-vg/root /mnt
cd /mnt/veeam_backup/

How to mount a VMDK (crypted) disk on another debian 9 system:

kpartx -av .vmdk --> crea /dev/mapper/loop0p1 
lvscan
vgchange -ay
udisksctl unlock -b /dev/mapper/loop0p5
lvscan
mount /dev/backup3-vg/root /mnt   ---(o il nome della partizione /root cifrata)---

how to send html e-mails with php

This is a simple script for sending an html formatted e-mail:

$subject = "My Subject";

$headers = "From: paolo@pizzolongo.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = <<< EOT
< html >
< head >
< style >
body{background-color:#eee;margin:0;padding:0;border:0;}
h1{background-color:black;color:white;border-bottom:2px solid red;
font-size:16px; font-family:Arial;height:30px;line-height:30px;
text-indent:10px;vertical-align:middle;}
p{font-size:13px;font-family:Arial;line-height:1.2em;}


< body >
< h1 >Example Text< /h1 >
 

Hello,
this is a little text example.
Paolo's web site
regards


EOT;

mail($send_to,$subject,$message,$headers);


Hot to get shared folders permissions with a powershell script

with this powershell script we’ll be able to get share permissions and ntfs permissions form all the shares of our servers list.

Function GetSharedFolderPermission($ComputerName)
{
	#test server connectivity
	$PingResult = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet
	if($PingResult)
	{
		#check the credential whether trigger
		if($Credential)
		{
			$SharedFolderSecs = Get-WmiObject -Class Win32_LogicalShareSecuritySetting `
			-ComputerName $ComputerName -Credential $Credential -ErrorAction SilentlyContinue
		}
		else
		{
			$SharedFolderSecs = Get-WmiObject -Class Win32_LogicalShareSecuritySetting `
			-ComputerName $ComputerName -ErrorAction SilentlyContinue
		}
		
		foreach ($SharedFolderSec in $SharedFolderSecs) 
		{ 
		    $Objs = @() #define the empty array
			
	        $SecDescriptor = $SharedFolderSec.GetSecurityDescriptor()
	        foreach($DACL in $SecDescriptor.Descriptor.DACL)
			{  
				$DACLDomain = $DACL.Trustee.Domain
				$DACLName = $DACL.Trustee.Name
				if($DACLDomain -ne $null)
				{
	           		$UserName = "$DACLDomain\$DACLName"
				}
				else
				{
					$UserName = "$DACLName"
				}
				
				#customize the property
				$Properties = @{'ComputerName' = $ComputerName
								'SharedFolderName' = $SharedFolderSec.Name
								'SecurityPrincipal' = $UserName
								'FileSystemRights' = [Security.AccessControl.FileSystemRights]`
								$($DACL.AccessMask -as [Security.AccessControl.FileSystemRights])
                                'NTFS' = 0}
				$SharedACLs = New-Object -TypeName PSObject -Property $Properties
				$Objs += $SharedACLs

	        }
			$Objs|Select-Object ComputerName,SharedFolderName,SecurityPrincipal,FileSystemRights,NTFS
	    }  
	}
	else
	{
		$Properties = @{'ComputerName' = $ComputerName
						'SharedFolderName' = "Not Available"
						'SecurityPrincipal' = "Not Available"
						'FileSystemRights' = "Not Available"
                        'NTFS' = 0}
		$SharedACLs = New-Object -TypeName PSObject -Property $Properties
		$Objs += $SharedACLs
		$Objs|Select-Object ComputerName,SharedFolderName,SecurityPrincipal,FileSystemRights,NTFS
	}
}

Function GetSharedFolderNTFSPermission($ComputerName)
{
	#test server connectivity
	$PingResult = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet
	if($PingResult)
	{
		#check the credential whether trigger
		if($Credential)
		{
			$SharedFolders = Get-WmiObject -Class Win32_Share `
			-ComputerName $ComputerName -Credential $Credential -ErrorAction SilentlyContinue
		}
		else
		{
			$SharedFolders = Get-WmiObject -Class Win32_Share `
			-ComputerName $ComputerName -ErrorAction SilentlyContinue
		}

		foreach($SharedFolder in $SharedFolders)
		{
			$Objs = @()
			
			$SharedFolderPath = [regex]::Escape($SharedFolder.Path)
			if($Credential)
			{	
				$SharedNTFSSecs = Get-WmiObject -Class Win32_LogicalFileSecuritySetting `
				-Filter "Path='$SharedFolderPath'" -ComputerName $ComputerName  -Credential $Credential
			}
			else
			{
				$SharedNTFSSecs = Get-WmiObject -Class Win32_LogicalFileSecuritySetting `
				-Filter "Path='$SharedFolderPath'" -ComputerName $ComputerName
			}
			
			$SecDescriptor = $SharedNTFSSecs.GetSecurityDescriptor()
			foreach($DACL in $SecDescriptor.Descriptor.DACL)
			{  
				$DACLDomain = $DACL.Trustee.Domain
				$DACLName = $DACL.Trustee.Name
				if($DACLDomain -ne $null)
				{
	           		$UserName = "$DACLDomain\$DACLName"
				}
				else
				{
					$UserName = "$DACLName"
				}
				
				#customize the property
				$Properties = @{'ComputerName' = $ComputerName
								'SharedFolderName' = $SharedFolder.Name
								'SecurityPrincipal' = $UserName
								'FileSystemRights' = [Security.AccessControl.FileSystemRights]`
								$($DACL.AccessMask -as [Security.AccessControl.FileSystemRights])
								'NTFS' = 1}
								
				$SharedNTFSACL = New-Object -TypeName PSObject -Property $Properties
	            $Objs += $SharedNTFSACL
	        }
			$Objs |Select-Object ComputerName,SharedFolderName,SecurityPrincipal,FileSystemRights,NTFS -Unique
		}
	}
	else
	{
		$Properties = @{'ComputerName' = $ComputerName
						'SharedFolderName' = "Not Available"
						'SecurityPrincipal' = "Not Available"
						'FileSystemRights' = "Not Available"
						'NTFS' = "1"}
					
		$SharedNTFSACL = New-Object -TypeName PSObject -Property $Properties
	    $Objs += $SharedNTFSACL
		$Objs |Select-Object ComputerName,SharedFolderName,SecurityPrincipal,FileSystemRights,NTFS -Unique
	}
} 

Function LetsStart($ComputerName){
	foreach($CN in $ComputerName){
			GetSharedFolderNTFSPermission -ComputerName $CN
			GetSharedFolderPermission -ComputerName $CN
	}
}

$ComputerName="server01","server02","server03"
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('yyyy-MM-dd_HH-mm')

LetsStart($ComputerName) | Export-Csv “c:\path\to\file\$CurrentDate.csv" -NoTypeInformation

Conquest Dicom Server Mysql on Debian (dgate)

This is a quick guide to install ConQuest DICOM server on Debian 8 (Jessie) using MySQL as ConQuest database.

BEFORE PROCEEDING
I assume that you’re logged in as “root” and the image files will be stored into the directory “/data” and you’ve already installed your debian server with a standard configuration.
I’m used with “nano” to edit files, if you’re not familiar with “nano”, please use another editor (eg: “vim”).

If you’re updating your ConQuest version, backup these files before proceeding:

/etc/conquest-dicom-server/acrnema.map
/etc/conquest-dicom-server/dicom.ini

Don’t restore the above files to your new version of ConQuest. Use them just to check the information you need to change at the new files. Overwriting files from a newer version of ConQuest with files from an older version may cause ConQuest malfunctioning.

INSTALLING
First of all, we want to install the latest version of each needed package, so we call:
# apt-get update

And then install the recommended packages:
# apt-get install apache2 mysql-server openssh-server conquest-mysql

Optionally i install too:
#phpmyadmin dcmtk apache2-mpm-itk

Now we create the database that ConQuest will use:
# mysql -u root -p
create database conquest;
quit;

The directory for ConQuest files is:
# /etc/conquest-dicom-server

Enter the ConQuest directory:
# cd /etc/conquest-dicom-server

Edit the file dicom.ini to set up your server, now you define the server Application Entity Title (AET), its communication port, the user and the password that ConQuest will use to connect to MySQL
The lines that aren’t listed here are the lines that I don’t make any changes, so leave them alone:
# nano dicom.ini
MyACRNema = SERVER_AET
TCPPort = 104 # the server communication port
Password =
FixPhilips = 1 # avoids problems with Patient ID from some Philips systems
FixKodak = 1 # avoids problems with Patient ID from some Kodak/Carestream systems
IgnoreOutOfMemoryErrors = 1 # avoids ConQuest interruptions when out of memory errors occurs
FileNameSyntax = 8 # determines the name of stored files (see page 52 of windowsmanual.pdf)
DroppedFileCompression = jk # store dropped files using Lossless JPEG2000
IncomingCompression = jk # store image files through DICOM communication using Lossless JPEG2000
PACSName = # for banner and debug information
MAGDevice0 /data/ # where the images will be stored

Create the directory to store the images:
# mkdir /data

Edit the the file that contain associated remote DICOM nodes that will communicate with this server:
# nano acrnema.map

(Re)build the database verbosely:
# dgate -v -r

SCRIPTS
I’ve developed some simple scripts to make my life easier. Here they are:

(Re)start Conquest
(Re)start script for ConQuest saving logs into “serverstatus.log” file:
# nano /usr/local/bin/start

#!/bin/bash
pkill -9 dgate
dgate -^logfilename.log &

Keep Server Alive
This script checks if “dgate” proccess is running, if not (server crashed), the script restarts it:
# nano /usr/local/bin/keepalive

#!/bin/bash
pgrep dgate
if [ $? -ne 0 ]
then /usr/local/bin/start
fi

Send Yesterday’s Studies To Another Server
This script sends every yesterday’s studies to another server
# nano /usr/local/bin/dgateyesterday

#!/bin/bash
DATE=$(date -d 'yesterday' + %Y%m%d)
dgate --movestudies:SRC_AET,DEST_AET,$DATE
wait

Make all scripts executables:
# chmod a+x /usr/local/bin/*

Schedule the execution of scripts:
# crontab -e

Reload cron to activate the new entries at “/etc/crontab”:
# /etc/init.d/cron restart

Some Useful Commands

Load new DICOM nodes after editing acrnema.map:
# dgate –read_amap:
List of loaded DICOM nodes:
# dgate –get_amaps:
Transferring studies from one server to another:
# dgate –movestudy:patientID:studyuid

How to connect PHP to Microsoft SQL Server on Linux Debian

Here is how to get PHP 5.6 on Linux (specifically Debian) talking to a Microsoft SQL Server database:

1. Install FreeTDS and the PHP MSSQL extension

apt-get install freetds-common freetds-bin unixodbc php5-sybase

Note: That is correct, the MS SQL extension is in the “php5-sybase” package.

2. Restart Apache

/etc/init.d/apache2 restart

3. Test FreeTDS

tsql -H your.server.name -p 1433 -U yourusername -P yourpassword -D yourdatabasename

If it connects, it’s working. Note: If you try to SELECT an NTEXT or NVARCHAR column you may get an error saying “Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier”. That is expected and will be fixed in the next step.

4. Configure FreeTDS

nano /etc/freetds/freetds.conf

Add this at the end of the file:

[yourserver]
host = your.server.name
port = 1433
tds version = 8.0

5. Test FreeTDS using server name

tsql -S yourserver -U yourusername -P yourpassword -D yourdatabasename

If you try to select something, you shouldn’t get the Unicode error now – because you specified “tds version = 8.0”.

6. Test in PHP

$link = mssql_connect('yourserver', 'yourusername', 'yourpassword');

if (!$link)
die('Unable to connect!');

if (!mssql_select_db('yourdatabasename', $link))
die('Unable to select database!');

$result = mssql_query('SELECT * FROM yourtable');

while ($row = mssql_fetch_array($result)) {
var_dump($row);
}

mssql_free_result($result);