CentOS 7, VestaCP and the Irritating clamd

July 9, 2016 Leave a comment

Here is the step by step guide in getting clamav to work in CentOS 7 for a VestaCP setup

Install Updated ClamAV components
yum install clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd -y

Link scan.conf to the default VestaCP clamd config file
rm -f /etc/clamd.d/scan.conf
ln -s /etc/clamd.conf /etc/clamd.d/scan.conf

Create freshclam service (Running it as a service will automatically update your AV definitions)
vi /usr/lib/systemd/system/clam-freshclam.service

[Unit]
Description = freshclam scanner
After = network.target
[Service]
Type = forking
ExecStartPre=/usr/bin/mkdir -p /var/lib/clamav/
ExecStartPre=/usr/bin/chown -R clam.clam /var/lib/clamav
ExecStartPre=/usr/bin/chmod 755 /var/lib/clamav
ExecStart = /usr/bin/freshclam -d -c 4
Restart = on-failure
PrivateTmp = true
[Install]
WantedBy=multi-user.target

Register and start freshclam service
systemctl enable clam-freshclam.service
systemctl restart clam-freshclam.service
systemctl status clam-freshclam.service -l

Update clamd@ service to create the neccessary folders
vi /usr/lib/systemd/system/clamd@.service
[Unit]
Description = clamd scanner (%i) daemon
After = syslog.target nss-lookup.target network.target

[Service]
Type = simple
***ADD these 2 lines below, they must be before ExecStart
ExecStartPre = /usr/bin/mkdir -p /var/log/clamav/
ExecStartPre = /usr/bin/chown -R clam:clam /var/log/clamav/
ExecStart = …

Update startup to use the new clamd service
cd /usr/lib/systemd/system

systemctl disable clamd.service

systemctl enable clamd@scan.service
systemctl restart clamd@scan.service
systemctl status clamd@scan.service
image

Test scan, make sure it is successful
clamdscan -c /etc/clamd.d/scan.conf –fdpass

image

Categories: CentOS, Vesta

.net Core RC2–EntityFramework Database First

June 1, 2016 Leave a comment

This is the updated version using RC2 for https://jefferytay.wordpress.com/2016/02/02/asp-net-vnext-entityframework-7-0-database-first-rc1/

You can refer to the full documentation at https://docs.efproject.net/en/latest/miscellaneous/configuring-dbcontext.html

Step by step guide:

  1. Starting with a blank project, add the following dependencies inside project.json

    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview1-final",

    image
    If you are upgrading from RC1, I would suggest you create a brand new project and migrate the files rather than attempt to migrate the entire project

  2. Add the following inside tools
    "Microsoft.EntityFrameworkCore.Tools": {
         "version": "1.0.0-preview1-final",
         "imports": [
           "portable-net45+win8+dnxcore50",
           "portable-net45+win8"
         ]
       }
    image
  3. ef command now no longer exists, you need to use dotnet ef

dotnet ef dbcontext scaffold -c UserDbContext -o Models -f "Data Source=.; Initial Catalog=user;User ID=user;Password=password" Microsoft.EntityFrameworkCore.SqlServer

Usage: dotnet ef dbcontext scaffold [arguments] [options]
Arguments:
  [connection]  The connection string of the database
  [provider]    The provider to use. For example, EntityFramework.MicrosoftSqlServer
Options:
  -a|–data-annotations           Use DataAnnotation attributes to configure the model where possible. If omitted, the output code will use only the fluent API.
  -c|–context <name>             Name of the generated DbContext class.
  -f|–force                      Force scaffolding to overwrite existing files. Otherwise, the code will only proceed if no output files would be overwritten.
  -o|–output-dir <path>          Directory of the project where the classes should be output. If omitted, the top-level project directory is used.
  –schema <schema>               Selects a schema for which to generate classes.
  -t|–table <schema.table>       Selects a table for which to generate classes.
  -e|–environment <environment>  The environment to use. If omitted, "Development" is used.
  -h|–help                       Show help information
  -v|–verbose                    Enable verbose output

Universal SMS Archiver

May 13, 2016 Leave a comment

Users who have been using Android devices will swear by SMS Backup and Restore to backup their SMS, while iOS users have iTunes backup. While these works, one issue with such software is that you generally do not want to keep or transfer all of your old SMS into the new device.

Introducing Universal SMS Archiver!

  • It is a desktop app that runs on Windows, and has the ability to automatically import your SMS from iTunes and SMS Backup and Restore files.
  • You can also manage the entire list of SMS into a current as well as archived list.
  • It has the ability to export your current sms list into Excel for further processing

image

The latest executable can be downloaded at https://onedrive.live.com/redir?resid=895931B65435BB3D!30467&authkey=!AG-VaHLPBh10qLg&ithint=file%2czip

Source code can be found at https://github.com/kwanann/Hobbies/tree/master/Universal%20SMS%20Archiver

InvoicePlane–Enabling Date Parameters

February 25, 2016 Leave a comment

Sometimes it is necessary to include some form of dates in either the item or the item description for InvoicePlane.

In order to do so, you will need to edit 3 files

application\helpers\pdf_helper.php

search for function generate_invoice_pdf

and replace

$data = array(
        ‘invoice’ => $invoice,
        ‘invoice_tax_rates’ => $CI->mdl_invoice_tax_rates->where(‘invoice_id’, $invoice_id)->get()->result(),
          ‘items’ => $CI->mdl_items->get_items_and_replace_vars($invoice_id, $invoice->invoice_date_due),
        ‘payment_method’ => $payment_method,
        ‘output_type’ => ‘pdf’
    );

 

application\modules\guest\controllers\view.php

search for  public function invoice

$data = array(
                ‘invoice’ => $invoice,
                     ‘items’ => $this->mdl_items->get_items_and_replace_vars($invoice->invoice_id, $invoice->invoice_date_due),
                ‘invoice_tax_rates’ => $this->mdl_invoice_tax_rates->where(‘invoice_id’, $invoice->invoice_id)->get()->result(),
                ‘invoice_url_key’ => $invoice_url_key,
                ‘flash_message’ => $this->session->flashdata(‘flash_message’),
                ‘payment_method’ => $payment_method
            );

 

application\modules\invoices\models\mdl_items.php

add the following function to Mdl_Items class

public function get_items_and_replace_vars($invoice_id, $invoice_date_created = ‘now’)
     {
         $items = array();
         $query = $this->where(‘invoice_id’, $invoice_id)->get();

         foreach($query->result() as $item) {
             $item->item_name = $this->parse_item($item->item_name, $invoice_date_created);
             $item->item_description = $this->parse_item($item->item_description, $invoice_date_created);
             $items[] = $item;
         }
         return $items;
     }

 

 

Now you can do things like

Support and maintenance for {{{Month}}} {{{Year}}}

 

which will then appear as

image

Categories: Invoice Plane

Dependency Injection in ASPNET VNext (RC1)

February 23, 2016 Leave a comment

This article will document how to do dependency injection for vNext

1. Create the class to be injected (https://gist.github.com/kwanann/a0363add23870a949334)

image

2. Configure startup.cs (https://gist.github.com/kwanann/7bced8e22fec229bd0be)

image

There are 4 methods of adding to services

AddTransient: It will create a new instance each time it is accessed. e.g when I call it from the MVC Controller and from frontend MVC code, I will get 2 independent instances

AddScoped: It will create a new instance for the particular request, e.g when I call it from MVC Controller and frontend MVC Code, it’s the same instance. However it does not survive across different OWIN middleware

AddSingleton: Creates a single instance for all requests

AddInstance: Creates a single instance for all requests, but the constructor is left to the developer

3. If you need to call it from within the MVC Controller (https://gist.github.com/kwanann/c987314e0eecdab20a7b)

image

Inject the interface you need into the constructor and then assign it to a local variable. You may then use it however you wish

Categories: 5.0, ASP.NET, vNext

Microsoft Team Foundation Server–Undoing checkout for a workspace that no longer exists

February 2, 2016 1 comment

Every once in a while, you get a request from your developer telling you that they have reformatted their machine and unfortunately there is still one or 2 files inside that workspace that they forgot to checkout

Visual studio comes with tools that allows you to undo checkout. Unfortunately it runs from the CLI

  1. Goto the visual studio folder
    cd “C:\Program Files (x86)\Microsoft Visual Studio 14.0”
  2. List workspaces of the user
    tf workspaces /collection:http://mytfsserver:8080/tfs/defaultcollection /owner:JohnDoe

    Collection: http://mytfsserver:8080/tfs/defaultcollection
    Workspace Owner          Computer  Comment
    ——— ————– ——— ————————————————————————————
    JD-PC JohnDoe JD-PC
    JD-PC2     JohnDoe JD-PC2
    JD-PC3    JohnDoe JD-PC3

  3. Figure out which workspace contains the file to undo and fire up the undo command

    tf undo /workspace:JD-PC2;JohnDoe /s:http://mytfsserver:8080/tfs $/Path/To/The/File.cs

if it works, you will get the following reply:

The operation completed successfully.  Because the workspace JD-PC2;JohnDoe is not on this computer, you must perform a separate get operation in that workspace to update it with the changes that have been made on the server.

Easy way to IMAP sync 2 mailboxes

February 2, 2016 Leave a comment

Linux has a great tool to sync 2 different mailboxes, this is especially useful when you need to migrate from one mailbox to another

  1. First install imapsync
  2. Then run the following command

imapsync –host1 –user1 –password1 –host2 [destination server] –user2 [destination email] –password2 [destination password]

Categories: CentOS, Open Source, Ubuntu
Follow

Get every new post delivered to your Inbox.