My standard Ubuntu setup command

sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install htop mc nano

Advertisements

Install Splunk on Ubuntu and hide behind Apache2 Proxy

Problem

  • Hide Splunk behind Apache2
  • Enable .htaccess
  • Ubuntu 16.04 LTS

Solution

Install Splunk

dpkg -i splunk_package_name.deb

/opt/splunk/bin/splunk start –accept-license

For enable this behavior, please set the following in /opt/splunk/etc/system/default/web.conf

root_endpoint=/NAME

Restart Splunk:

/opt/splunk/bin/splunk restart

Start at boot time:

opt/splunk/bin/splunk enable boot-start

Apache

Enable needed modules:

  • sudo a2enmod proxy
  • sudo a2enmod proxy_http

Edit /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
ProxyPreserveHost On

ProxyPass / http://127.0.0.1:8000/NAME
ProxyPassReverse / http://127.0.0.1:8000/NAME
</VirtualHost>

Add .htaccess to VirtualHost

<Location /NAME>
AuthType Basic
AuthName “Wrapper auth”
AuthBasicProvider file
AuthUserFile “/PATHTOHTPASSWD/htpasswd”
Require valid-user
</Location>

Restart

sudo systemctl restart apache2

Install Apache2 with SSL/HTTPs on Ubuntu

Problem

  • You need a Apache2 with HTTPs on Ubuntu

Solution

Prepare

sudo apt-get update && sudo apt-get upgrade -y

sudo apt-get install apache2

Create certificate

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt

You will be asked for some infomation. Just put in, what you want:

Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

Optional

Create strong Diffie-Hellman

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

SSL Params

SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder On
# Disable preloading HSTS for now. You can use the commented out header line that includes
# the “preload” directive if you understand the implications.
#Header always set Strict-Transport-Security “max-age=63072000; includeSubdomains; preload”
Header always set Strict-Transport-Security “max-age=63072000; includeSubdomains”
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff
# Requires Apache >= 2.4
SSLCompression off
SSLSessionTickets Off
SSLUseStapling on
SSLStaplingCache “shmcb:logs/stapling-cache(150000)”

Edit /etc/apache2/sites-available/default-ssl.conf

sudo nano /etc/apache2/sites-available/default-ssl.conf

Change to

SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key

Eanble everything

sudo a2enmod ssl
sudo a2enmod headers
sudo a2ensite default-ssl
sudo a2enconf ssl-params

Restart Apache2

sudo systemctl restart apache2

 

 

 

Install RabbitMQ on Ubuntu 16.04

Problem

  • Install RabbitMQ on Ubuntu Server

Solution

Install Repository

echo ‘deb http://www.rabbitmq.com/debian/ testing main’ | sudo tee /etc/apt/sources.list.d/rabbitmq.list

wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add –

Install RabbitMQ

sudo apt-get update

sudo apt-get install rabbitmq-server

Status

sudo systemctl status rabbitmq-server

Start RabbitMQ

sudo systemctl start rabbitmq-server

Stop RabbitMQ

sudo systemctl stop rabbitmq-server

Limits

sudo nano /etc/sysctl.conf

Add

fs.file-max = 65536

Run

sudo sysctl -p

Edit

sudo nano /etc/security/limits.conf

Add

* soft nproc 65536
* hard nproc 65536
* soft nofile 65536
* hard nofile 65536
root soft nproc 65536
root hard nproc 65536
root soft nofile 65536
root hard nofile 65536

Edit

sudo nano /etc/pam.d/common-session

Add

session required pam_limits.so

Restart

sudo reboot

Ports

Open Ports: 15672 (Mgmt), 5672 and 5671 (Messages)

Management Plugin

sudo rabbitmq-plugins enable rabbitmq_management

sudo systemctl restart rabbitmq-server

Add Admin

rabbitmqctl add_user admin <<password>>
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin “.*” “.*” “.*”

See Management Site

Open http://<<IP>>:15672

Simple HTTP GET with Node.JS

Problem

  • Need a simple HTTP GET call with return value

Solution

var http = require(“http”);
hget(“127.0.0.1”, “8086”,”/exampleCall”,
    function (data) {
        //process your data here
    });
function hget(url, port, path, callbackData) {
    var options = {
        host: url,
        port: port,
        path: path
    };
    callback = function (response) {
        var body = ”;
        response.on(‘data’, function (chunk) {
            body += chunk;
        });
        response.on(‘end’, function () {
            callbackData(body);
        });
    }
    var req = http.request(options, callback).end();
}

101 for REST API with Swagger, ASP.NET and C#

Short summary about my lessons learned for a REST API with Swagger, ASP.NET and C#.

Configuration

Open the file SwaggerConfig.cs. For the first demo, we name our app and enable the UI:

GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion(“v1”, “API Demonstration”);
})
.EnableSwaggerUi();

SwaggerUI

The SwaggerUI can be found under:

http://localhost:%5BPORT_NUM%5D/swagger

Documentation

If you need documentation for you methods, parameters or controller, you have to enable the XML documentation file:

swagger_doku

Remember the path, you will have to add it to your Swagger configuration. This all the other configurations it should look like this:

GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.SingleApiVersion(“v1”, “API Demonstration”);
c.IncludeXmlComments(string.Format(@”{0}\App_Data\API-Test.XML”, System.AppDomain.CurrentDomain.BaseDirectory));
})
.EnableSwaggerUi();

To use the documentation, you can commentary to every method. Remember, you can use HTML formatting.

swagger_docu2

Path Parameters

Path parameters are fixed elements of the URL and are not optional. They can be set by the Route element. Every parameter is configured via {} brackets and have to match with the method parameters:

[HttpGet]
[Route(“test/route/{para1}/{para2}”)]
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(String))]
[SwaggerResponse(HttpStatusCode.BadRequest, Description = “Bad Request”)]
[SwaggerResponse(HttpStatusCode.NotFound, Description = “Not found”)]

public string test(string para1, int para2)
{

The Request URL looks like this:

http://localhost:50283/test/route/Hello/7

Query Parameters

Query parameters are not part of the base URL. If tw want para2 to be a query parameter, just exclude it from the Route:

 

[HttpGet]
[Route(“test/route/{para1}”)]
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(String))]
[SwaggerResponse(HttpStatusCode.BadRequest, Description = “Bad Request”)]
[SwaggerResponse(HttpStatusCode.NotFound, Description = “Not found”)]

public string test(string para1, int para2)
{

The Request URL looks like this:

http://localhost:50283/test/route/Hello?para2=7

(This can also be done with para1)

Optional Parameters

If you want optional parameter, just add a default value for the parameter.

[HttpGet]
[Route(“test/route/{para1}”)]
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(String))]
[SwaggerResponse(HttpStatusCode.BadRequest, Description = “Bad Request”)]
[SwaggerResponse(HttpStatusCode.NotFound, Description = “Not found”)]

public string test(string para1, int para2=0)
{

Validating DateTime

You will get a 404 – Bad Request, if you use DateTime within a path parameter like this:

http://localhost:50283/test/route/2017-05-26T12:30:00

You have to options.

1. Use a query parameter like this: http://localhost:50283/test/route?time=2017-05-26T12:30:00

2. Change your web.config:

<configuration>

<system.web>

<httpRuntime requestPathInvalidCharacters=”” requestValidationMode=”2.0″ />
<pages validateRequest=”false” />
</system.web>
..
</configuration>

Tutorial – Using Oracle Managed Data Access in ASP.NET and C#

1. Install  Oracle.ManagedDataAccess via NuGet package managernuget.PNG

2. Define your data source

Open your Web.config and add to the configuration the following:

<oracle.manageddataaccess.client>
<version number=”*”>
<dataSources>
<dataSource alias=”EXAMPLE” descriptor=”(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=YOUR_HOST_NAME)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=YOUR_SERVICE_NAME)))” />
</dataSources>
</version>
</oracle.manageddataaccess.client>

Here you can read, how to get your HOST_NAME and SERVICE_NAME.

3. Connect to your Oracle

using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;

….

public OracleConnection connectOracle()
{
OracleConnection con = null;
OracleCommand cmd = null;
OracleDataReader reader = null;
try
{
string constr = “user id=YYYYYYY;password=XXXXXXX;data source=EXAMPLE”;
con = new OracleConnection(constr);
con.Open();
cmd = new OracleCommand(“select * from SOMETABLE t”, con);
cmd.CommandType = System.Data.CommandType.Text;

reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(reader.GetString(0)) //Just example
}
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace.ToString());
}
finally
{
if (reader != null && !reader.IsClosed)
reader.Close();
if (con != null && con.State == System.Data.ConnectionState.Open)
con.Close();
con.Dispose();
}
}

Fin.

Missing api-ms-win-crt-runtime-l1-1-0.dll

Problem

error

  • The api-ms-win-crt-runtime-l1-1-0.dll is missing
  • Sub problem: you can not install Visual C++ Redistributable for Visual Studio because Windows Update, especially on Windows Vista, doesn’t work. (it runs hour for hour and exits with an error)

Solution

Normally, you only have to install the VC++ Redistributable for your computer:

Visual C++ Redistributable for Visual Studio 2017 (64-bit)

Visual C++ Redistributable for Visual Studio 2017 (32-bit)

Windows Update

If you can not install VC++ it is most likely because of the broken Windows Update process:

Here is what i did:

  1. Uninstall VC++, by starting the installer and select Uninstall.
  2. Restart computer
  3. Open cmd as administrator
  4. Type: net stop wuauserv
  5. Install VC++

This installs VC++ without problems. You can restart Windows Update with net start wuauserv