Blog

Dell EMC Conference 15 Febbraio 2018

Thursday 15 February 2018, 20:00
Tematiche conferenza:
-Approfondimento sulla strategia di canale Dell EMC  e soluzioni in ambito Enterprise
-Portafoglio server Dell PowerEdge ™14ma generazione
-Dell Networking – Approfondimento gamma prodotti
-Introduzione normativa GDPR – Microsoft Windows Server 2016 e SQL Server 2017

img-5686

 

img-5688

 

img-5693

img-5695

 

img-5696

Delphi FMX – Run APK Installation programmatically

Tuesday 30 January 2018, 17:29

Configure RaspAP over Ubuntu 16.04 Server and Apache2

Friday 24 November 2017, 18:23

Configure RaspAP over Ubuntu 16.04 Server and Apache2

Android App Version with Delphi

Wednesday 8 November 2017, 19:44

Using the JPackageInfo class is simple to retrive the version of your Android application.

This class is already wrapped by Embarcadero in the following unit:
Androidapi.JNI.GraphicsContentViewText

{code}

{$IFDEF ANDROID}

var
PackageManager: JPackageManager;
PackageInfo: JPackageInfo;
begin
PackageManager := SharedActivityContext.getPackageManager;
PackageInfo := PackageManager.getPackageInfo
(SharedActivityContext.getPackageName, 0);
result := JStringToString(PackageInfo.versionName);
End;
{$ENDIF}

Delphi Android WiFi Manager

Friday 29 September 2017, 18:34

L’obiettivo era quello di connettersi a livello programmatico ad una specifica WiFi da qui è sorta l’esigenza di gestire in modo completo la classe Java WifiManager.

Nei tre metodi principali riportati di seguito avremo:

  1. riconoscimento dell’IP Address assegnato alla porta wifi
  2. Elenco delle Wifi disponibili (quelle che il dispositivo riconosce)
  3. Elenco delle configurazioni WiFi salvate sul dispositivo
  4. Possibilità di connettersi ad una specifica Wifi creandone la configurazione se la stessa non esiste

 



function IntToInetAddr(ipInt : Integer) : String;
var
 b : TBytes;
Begin
    SetLength(b,4);
    b[3] := ((ipInt and $FF000000) shr 24);
    b[2] := ((ipInt and $00FF0000) shr 16);
    b[1] := ((ipInt and $0000FF00) shr 8);
    b[0] := (ipInt and $000000FF);
    result := b[0].ToString() + '.' +
              b[1].ToString() + '.' +
              b[2].ToString() + '.' +
              b[3].ToString();

End;

(*
https://stackoverflow.com/questions/36098871/how-to-search-and-connect-to-a-specific-wifi-network-in-android-programmatically

http://blog.csdn.net/cmdasm/article/details/38357613
*)

procedure TForm4.Button1Click(Sender: TObject);
Var
  networkSSID : String;
  networkPass : String;
  WifiManagerObj: JObject;
  WifiManager: JWifiManager;
  AWifiConfiguration: JList;
  WifiInfo: JWifiInfo;
  WifiConfiguration,WinConf :  JWifiConfiguration;
  networkId: Integer;
  Done: Boolean;
  iter: JIterator;

begin
//  https://geekori.com/details.php?que_id=26676
  WifiManagerObj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
  WifiManager := TJWifiManager.Wrap((WifiManagerObj as ILocalObject).GetObjectID);
  WifiInfo := WifiManager.getConnectionInfo();

 if CheckBox1.IsChecked then
  Begin
    networkSSID := '"' + edSid.Text + '"';
    networkPass := '"' + edPwd.Text + '"';
  End
 Else
  Begin
    networkSSID := edSid.Text;
    networkPass := edPwd.Text;
  End;

 WifiConfiguration := nil;
 networkId := -1;

 iter := WifiManager.getConfiguredNetworks().iterator;
 while iter.hasNext do
     Begin
       WinConf := TJWifiConfiguration.Wrap((iter.next as ILocalObject).GetObjectID);
       //Memo1.lines.add(WinConf.networkId.ToString + ' --> ' + JStringToString(WinConf.SSID));
       if JStringToString(WinConf.SSID) = networkSSID then
        Begin
         WifiConfiguration := WinConf;
         networkId := WinConf.networkId;
        End;

     End;

 if WifiConfiguration = nil then
  Begin
    Memo1.lines.add('Network not found try to create configuration');
    //WifiConfiguration := TJWifiConfiguration.Create;
    WifiConfiguration := TJWifiConfiguration.JavaClass.init;

    WifiConfiguration.SSID := StringToJString(networkSSID);

    WifiConfiguration.preSharedKey := StringToJString(networkPass);

     WifiConfiguration.hiddenSSID := true;


    WifiConfiguration.allowedAuthAlgorithms.&set(TJWifiConfiguration_AuthAlgorithm.JavaClass.OPEN);
    WifiConfiguration.allowedGroupCiphers.&set(TJWifiConfiguration_GroupCipher.JavaClass.TKIP);
    WifiConfiguration.allowedGroupCiphers.&set(TJWifiConfiguration_GroupCipher.JavaClass.CCMP);
    WifiConfiguration.allowedKeyManagement.&set(TJWifiConfiguration_KeyMgmt.JavaClass.WPA_PSK);
    WifiConfiguration.allowedPairwiseCiphers.&set(TJWifiConfiguration_GroupCipher.JavaClass.TKIP);
    WifiConfiguration.allowedPairwiseCiphers.&set(TJWifiConfiguration_GroupCipher.JavaClass.CCMP);
    WifiConfiguration.status := TJNsdManager.JavaClass.NSD_STATE_ENABLED;

    networkId := WifiManager.addNetwork(WifiConfiguration);
  End;



  if networkId = -1 then
  begin
    Done := False;
    Memo1.lines.add('ERROR: networkId = -1');
  end
  Else
   Memo1.lines.add('networkId = ' + networkId.ToString());

  if WifiManager.disconnect = False then
  begin
    Done := False;
    Memo1.lines.add('ERROR: not disconnected');
  end;


  if done then
   Begin
    AWifiConfiguration := WifiManager.getConfiguredNetworks();
    done := False;
    Memo1.lines.add(' Configured network size: ' +  AWifiConfiguration.size.ToString());
    iter := AWifiConfiguration.iterator;
    while iter.hasNext do
     Begin
       WinConf := TJWifiConfiguration.Wrap((iter.next as ILocalObject).GetObjectID);
       Memo1.lines.add(WinConf.networkId.ToString + ' --> ' + JStringToString(WinConf.SSID));
       if WinConf.networkId = networkId then
         done := WifiManager.enableNetwork(networkId, true)
       Else
         WifiManager.disableNetwork(WinConf.networkId);

     End;


//    done := WifiManager.enableNetwork(networkId, true);

   WifiManager.reconnect;
//    done := WifiManager.enableNetwork(AWifiConfiguration.get(networkId).hashCode, true);
   End;

  if Done then
   Begin
     Memo1.lines.add('Connected');
   End
  Else
   Begin
     Memo1.lines.add('Not Connected to selected network');

   End;

  GetIpAddress;


end;

procedure TForm4.Button2Click(Sender: TObject);
 var
  WifiManagerObj: JObject;
  WifiManager: JWifiManager;
  WifiInfo: JWifiInfo;
begin
  WifiManagerObj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
  WifiManager := TJWifiManager.Wrap((WifiManagerObj as ILocalObject).GetObjectID);
  WifiInfo := WifiManager.getConnectionInfo();


  Memo1.Lines.Clear;
  Memo1.Lines.Add('Wifi Enabled: ' + WifiManager.isWifiEnabled.ToString);
  Memo1.Lines.Add('Wifi State: ' + WifiManager.getWifiState.ToString);
  Memo1.Lines.Add('Ping Supplicant: ' + WifiManager.pingSupplicant.ToString);


  Memo1.Lines.Add('BSSID: ' + JStringToString(WifiInfo.getBSSID));
  Memo1.Lines.Add('HiddenSSID: ' + WifiInfo.getHiddenSSID.ToString);
  Memo1.Lines.Add('IpAddress: ' + WifiInfo.getIpAddress.ToString);
  Memo1.Lines.Add('LinkSpeed: ' + WifiInfo.getLinkSpeed.ToString + 'Mbps');
  Memo1.Lines.Add('MacAddress: ' + JStringToString(WifiInfo.getMacAddress));
  Memo1.Lines.Add('NetworkId: ' + WifiInfo.getNetworkId.ToString);
  Memo1.Lines.Add('Rssi: ' + WifiInfo.getRssi.ToString + 'dBm');
  Memo1.Lines.Add('SSID: ' + JStringToString(WifiInfo.getSSID));
  Memo1.Lines.Add('SupplicantState: ' + JStringToString(WifiInfo.getSupplicantState.toString));
  GetIpAddress;

end;

procedure TForm4.Button3Click(Sender: TObject);
var
  WifiManagerObj: JObject;
  WifiManager: JWifiManager;
  ScanResult: JScanResult;
  i: Integer;
begin
  WifiManagerObj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
  WifiManager := TJWifiManager.Wrap((WifiManagerObj as ILocalObject).GetObjectID);

  Memo1.Lines.Clear;

  for i := 0 to WifiManager.getScanResults.size - 1 do
  begin
    ScanResult := TJScanResult.Wrap((WifiManager.getScanResults.get(i) as ILocalObject).GetObjectID);



    memo1.Lines.Add( 'SSID: ' + JStringToString(ScanResult.SSID));
    memo1.Lines.Add( 'frequency: ' + ScanResult.frequency.ToString +
    'MHz' + '  level: ' + ScanResult.level.ToString + 'dBm)');





//    ListBox1.AddObject(ListBoxItem);
  end;

//  ListBox1.EndUpdate;
end;

procedure TForm4.Button4Click(Sender: TObject);
begin

// networkSSID := '"WiTmm3"';
// networkPass := '"simona1987"';
  edSid.Text := 'WiTmm3';
  edPwd.Text := 'simona1987';
end;

procedure TForm4.Button5Click(Sender: TObject);
begin
 Memo1.Lines.Clear;
end;

procedure TForm4.GetIpAddress;
var
  WifiManagerObj: JObject;
  WifiManager: JWifiManager;
  WifiInfo: JWifiInfo;
begin
  label1.text := '127.0.0.1';
  { TODO : Trovare il modo di leggere il corrente ipaddress del dispositivo }
  try
    WifiManagerObj := SharedActivityContext.getSystemService(TJContext.JavaClass.WIFI_SERVICE);
    WifiManager := TJWifiManager.Wrap((WifiManagerObj as ILocalObject).GetObjectID);
    WifiInfo := WifiManager.getConnectionInfo;
    label1.text := IntToInetAddr(WifiInfo.getIpAddress);
    if label1.text = '0.0.0.0' then
      label1.text := '127.0.0.1';
  except
    on e: exception do
    begin
      label1.text := '127.0.0.1';
      raise Exception.Create(e.Message);
    end;
  end;
end;

procedure TForm4.FormCreate(Sender: TObject);
Begin
  GetIpAddress;
End;

Turn Raspberry PI3 into WI-FI router with HOSTAPD

Wednesday 20 September 2017, 13:13

Following this tutorial you’ll be able to configure your RaspBerryPi model 3 to accept incoming connections using its built-it WiFi antenna and to forward the requests to the Ethernet port.

Requirements

  • 1x RaspBerryPi model 3 (earlier versions will not work unless you have a WiFi dongle. In that case, just follow this Adafruit tutorial)
  • 1x Ethernet cable
  • Ethernet access

Context

My current ISP provided me with an old, locked WiFi router that is only capable to broadcast 20mb/s, which is not great for my nominal 100mb/s connection. Furthermore, it messes up my home devices assigning them to different subnets (and sometimes, it mixes local devices with ipv4 and ipv6). Using a Chromecast or a simple Plex server is therefore becoming a bit of an hassle and I thought for a moment that I needed a new WiFi router. Then I realised that most WiFi routers are basically tiny Linux computers with firmware sugar on top of them: so why not turning my RPI into a more useful WiFi router? Please note that this project is basically a proof of concept: the on-board WiFi antenna hasn’t a great range and the top-speed goes barely over 30mb/s. However, seen that this method works, I’ll try to run it with a powerful WiFi USB dongle with AP support to see if the PI can be converted to a more serious 300mb/s router.

Also, this tutorial is a slight modification from this Adafruit tutorial that is meant for RaspBerryPi < v3 and requires a WiFi dongle.

Let’s get on with it, shall we?

Initial checks

Once logged in to your Pi (via Terminal, on another computer), check that everything is setup:

ifconfig -a
# You should see something like this:
#eth0      Link encap:Ethernet  HWaddr b8:27:eb:77:8a:b2
#          inet addr:192.168.2.3  Bcast:192.168.2.255  Mask:255.255.255.0
#          inet6 addr: fe80::395:c29a:6e8:3756/64 Scope:Link
#          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
#          RX packets:1257 errors:0 dropped:0 overruns:0 frame:0
#          TX packets:932 errors:0 dropped:0 overruns:0 carrier:0
#          collisions:0 txqueuelen:1000
#          RX bytes:417879 (408.0 KiB)  TX bytes:165808 (161.9 KiB)
#
#lo        Link encap:Local Loopback
#          inet addr:127.0.0.1  Mask:255.0.0.0
#          inet6 addr: ::1/128 Scope:Host
#          UP LOOPBACK RUNNING  MTU:65536  Metric:1
#          RX packets:325 errors:0 dropped:0 overruns:0 frame:0
#          TX packets:325 errors:0 dropped:0 overruns:0 carrier:0
#          collisions:0 txqueuelen:1
#          RX bytes:26584 (25.9 KiB)  TX bytes:26584 (25.9 KiB)
#
#wlan0     Link encap:Ethernet  HWaddr b8:27:eb:22:df:e7
#          inet addr:192.168.42.1  Bcast:192.168.42.255  Mask:255.255.255.0
#          inet6 addr: fe80::6b78:7810:9062:550a/64 Scope:Link
#          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
#          RX packets:24737 errors:0 dropped:25 overruns:0 frame:0
#          TX packets:841 errors:0 dropped:0 overruns:0 carrier:0
#          collisions:0 txqueuelen:1000
#          RX bytes:4045148 (3.8 MiB)  TX bytes:360850 (352.3 KiB)

Generally, eth0 is the ethernet connection and wlan0 the WiFi connection. If both are there, we’re good to go.

Software setup

We’ll install and configure 2 programs:

  • hostapd
  • isc-dhcp-server
sudo apt-get update
sudo apt-get install hostapd isc-dhcp-server

DHCP server

# Be wise and always make a backup of the default config
sudo cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.default
# Edit the defult config file
sudo nano /etc/dhcp/dhcpd.conf
# Comment the following lines...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
# ...to read:
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
# ...and un-comment this line
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# ... to read:
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
# ... scroll down at the bottom of the file (CTRL + V) and paste:
subnet 192.168.42.0 netmask 255.255.255.0 {
    range 192.168.42.10 192.168.42.50;
    option broadcast-address 192.168.42.255;
    option routers 192.168.42.1;
    default-lease-time 600;
    max-lease-time 7200;
    option domain-name "local";
    option domain-name-servers 8.8.8.8, 8.8.4.4;
}

Now, with this configuration we are assigning the subnet192.168.42.10–50(40 devices in total) and we are configuring our WiFi local IP address to be 192.168.42.1. While we’re at it, we’re assigning Google’s public DNS: 8.8.8.8, 8.8.4.4.

Next, let’s specify on what interface should the DHCP server servce DHCP requests (wlan0 in this case):

sudo nano /etc/default/isc-dhcp-server
# Edit this line:
INTERFACES=""
# ...to read
INTERFACES="wlan0"

Let’s setup wlan0 for static IP:

# First, shut it down...
sudo ifdown wlan0
# ...keep it safe and make a backup file:
sudo cp /etc/network/interfaces /etc/network/interfaces.backup
# ...edit the network interfaces file:
sudo nano /etc/network/interfaces
# ... edit accordingly to read:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static
  address 192.168.42.1
  netmask 255.255.255.0
  post-up iw dev $IFACE set power_save off
# ...close the file and assign a static IP now
sudo ifconfig wlan0 192.168.42.1

Hostapd

# Create a file and edit it:
sudo nano /etc/hostapd/hostapd.conf
# ...modify ssid with a name of your choice and wpa_passphrase to a WiFi authen
interface=wlan0
ssid=WiPi
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=xyz
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Some tutorials requires you to set a driver ID. If you need to do that, in order to check what is your current driver ID, run:

basename $( readlink /sys/class/net/wlan0/device/driver )

…but even though my driver ID reads brcmfmac_sdio, if I put it into the hostapd.conf file I still got an error, but commenting out does the trick.

We aren’t quite done yet, because we also need to tell hostapd where to look for the config file when it starts up on boot. Open up the default configuration file with sudo nano /etc/default/hostapd and find the line #DAEMON_CONF="" and replace it with DAEMON_CONF="/etc/hostapd/hostapd.conf".

Next, let’s configure the network address translation:

# Create a backup file
sudo cp /etc/sysctl.conf /etc/sysctl.conf.backup
# ...edit the config file
sudo nano /etc/sysctl.conf
# ...un-comment or add to the bottom:
net.ipv4.ip_forward=1
# ...and activate it immediately:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
# ...modify the iptables to create a network translation between eth0 and the wifi port wlan0
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
# ...make this happen on reboot by runnig
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
# ...and editing again
sudo nano /etc/network/interfaces
# ...appending at then end:
up iptables-restore < /etc/iptables.ipv4.nat
# Our /etc/network/interfaces file will now look like this:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static
  address 192.168.42.1
  netmask 255.255.255.0
source-directory /etc/network/interfaces.d

Let’s test our access point by running:

sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf
 # Your hotspot is up and running: try to connect to it from a computer or a smartphone. When you do so, you should also see some log activity on your terminal. If you're satisfied, stop it with CTRL+D
 # Let's clean everything:
 sudo service hostapd start
 sudo service isc-dhcp-server start
 # ...and make sure that we're up and running:
 sudo service hostapd status
 sudo service isc-dhcp-server status
 # ...let's configure our daemons to start at boot time:
 sudo update-rc.d hostapd enable
 sudo update-rc.d isc-dhcp-server enable
 # ...reboot the pi.
 sudo reboot

You should now be able to see your pi WiFi, connect to it and access internet to it. As a quick comparison, streaming 4k videos will consume about 10% of the pi CPU so… use it accordingly.

As a bonus, if you want to check what’s happening on your WiFi hotspot, check the log file:

tail -f /var/log/syslog

If you really feel naughty, (or if you want to prevent naughty behaviour from your connected devices…) let me know in the comments below if you’re interested in a tutorial on how to configure a honeypot with your pi.

ADB Android Shell Find Files

Tuesday 11 July 2017, 18:12

To find a file in the Android Shell “ADB” you can use this command:

# busybox find "filetosearch"

you can do the same with

# ls -R | grep "filetosearch"

but you can’t see the directory where is the file

DKLang for Delphi

Tuesday 2 May 2017, 16:24

DKLang è un package per Delphi relativo alla gestione dell’internazionalizzazione delle applicazioni.

E’ composto da un insieme di componenti, classi e tools veramente ridotto ma efficace, il tool è open source e compatibile con tutte le piattaforme di sviluppo di Delphi (Windows,MacOSX,iOS,Android e Linux) sia per Firemonkey che VCL.

Le versioni del tool sono scaricabile da github all’indirizzo: https://github.com/yktoo/dklang
Home page del progetto: https://yktoo.com/en/software/dklang
Documentazione: https://github.com/yktoo/dklang/wiki

qualche accortezza nell’uso:

1) nel file di progetto deve essere compresa la direttiva {$R *.dkl_const.res} come da esempio:


program TeamLab;

{$R *.dres}

uses
System.StartUpCopy,
FMX.MobilePreview,
FMX.Forms,
….;

{$R *.res}
{$R *.dkl_const.res}

begin
Application.Initialize;
Application.CreateForm(TfrmMain, frmMain);
Application.Run;
end.

Change TextSettings to TTreeVievItem in Firemonkey

Monday 3 April 2017, 22:23

Changing the text property of a tree item in Firemonkey is really simple, you only need to do this:


tiC := TTreeViewItem.Create();
tiC.Text := ‘BLA BLA’;
tiC.StyledSettings := [];
tiC.TextSettings.FontColor := TAlphaColorRec.Blue;
tiC.Parent := ParentItem;
tiC.TagString := ;
tiC.Tag := ;

Discover what we can do for your business
Our languages