Archive

Archive for November, 2015

Enable Roundcube filters in Vesta 0.98 on CentOS 6.6

November 23, 2015 2 comments

#Install Dovecot Manage Sieve
yum install dovecot-pigeonhole

#edit 20-managesieve.conf
vi /etc/dovecot/conf.d/20-managesieve.conf

#Uncomment protocols
protocols = $protocols sieve

#Edit 10-master.conf
#add in section listed in blue

vi /etc/dovecot/conf.d/10-master.conf

service auth {
  unix_listener auth-client {
    group = mail
    mode = 0660
    user = dovecot
  }
  unix_listener auth-master {
    group = mail
    mode = 0660
    user = dovecot
  }

  user = dovecot
}

#Append this to the end of 10-master.conf
service managesieve-login {
  inet_listener sieve {
  port = 4190
  }
}
service managesieve {
}
protocol sieve {
    managesieve_max_line_length = 65536
    managesieve_implementation_string = dovecot
    log_path = /var/log/dovecot-sieve-errors.log
    info_log_path = /var/log/dovecot-sieve.log
}
plugin {
    sieve = ~/.dovecot.sieve
    sieve_global_path = /etc/dovecot/sieve/default.sieve
    sieve_dir = ~/sieve
    sieve_global_dir = /etc/dovecot/sieve/global/
}
lda_mailbox_autocreate = yes
lda_mailbox_autosubscribe = yes
protocol lda {
    mail_plugins = $mail_plugins autocreate sieve quota
    postmaster_address = postmaster@testdomain.com
    hostname = srv.testdomain.com
    auth_socket_path = /var/run/dovecot/auth-master
    log_path = /var/log/dovecot-lda-errors.log
    info_log_path = /var/log/dovecot-lda.log
}
protocol lmtp {
    mail_plugins = $mail_plugins autocreate sieve quota
    log_path = /var/log/dovecot-lmtp-errors.log
    info_log_path = /var/log/dovecot-lmtp.log
}

#touch and set the permissions on the log files, else you will get permission errors
touch /var/log/dovecot-lda-errors.log
chmod 660 /var/log/dovecot-lda-errors.log
chown dovecot.mail /var/log/dovecot-lda-errors.log

touch /var/log/dovecot-lda.log
chmod 660 /var/log/dovecot-lda.log
chown dovecot.mail /var/log/dovecot-lda.log

touch /var/log/dovecot-lmtp-errors.log
chmod 660 /var/log/dovecot-lmtp-errors.log
chown dovecot.mail /var/log/dovecot-lmtp-errors.log

touch /var/log/dovecot-lmtp.log
chmod 660 /var/log/dovecot-lmtp.log
chown dovecot.mail /var/log/dovecot-lmtp.log

#Create default sieve rule

mkdir /etc/dovecot/sieve
vi /etc/dovecot/sieve/default.sieve
require ["fileinto"];
# rule:[SPAM]
if header :contains "X-Spam-Flag" "YES" {
        fileinto "Spam";
}

touch /etc/dovecot/sieve/default.sieve
chmod +w /etc/dovecot/sieve/default.sieve
chown dovecot.mail /etc/dovecot/sieve/default.sieve

#Restart dovecot, if service starts, means configuration is successful
service dovecot restart

#Configure roundcube

vi /etc/roundcubemail/main.inc.php
$rcmail_config[‘plugins’] = array(‘managesieve’);

vi /usr/share/roundcubemail/plugins/managesieve/config.inc.php.dist

// default contents of filters script (eg. default spam filter)
$config[‘managesieve_default’] = ‘/etc/dovecot/sieve/default.sieve’;

#Configure Exim, modify part in purple
vi /etc/exim/exim.conf
localuser:
  driver = accept
  #transport = local_delivery
  transport = dovecot
  condition = ${lookup{$local_part}lsearch{/etc/exim/domains/$domain/passwd}{true}{false}}

 

######################################################################
#                      TRANSPORTS CONFIGURATION                      #
######################################################################
begin transports

dovecot:
    driver = pipe
    command = /usr/libexec/dovecot/dovecot-lda -e -d $local_part@$domain -f $sender_address -a $original_local_part@$original_domain
    return_path_add
    log_output = true
    delivery_date_add
    envelope_to_add
    user = ${extract{2}{:}{${lookup{$local_part}lsearch{/etc/exim/domains/$domain/passwd}}}}
    group = mail
    return_output

#Restart exim, if service starts, means configuration is successful
service exim restart

Categories: CentOS, Vesta

Vesta Control Panel 0.9x, WordPress and Allowed memory size of 33554432 bytes exhausted

November 20, 2015 Leave a comment

PHP has a memory limit of 128MB in a default install of Vesta Control Panel.

However should you run wordpress in HTTPS, you will find yourself at the mercy of the allowed memory size error and all the fixes in the world does not fix this.

These solutions include

  • Create a php.ini in the public_html folder and add memory_limit = 128M
  • Edit wp-settings.php and add define("WP_MEMORY_LIMIT", “128M”);
  • Create a .htaccess file in the public_html folder and add php_value memory_limit 128M

This is because for HTTPS, vesta uses another file which overrides all of these settings.

You can find this file inside /home/[user]/conf/web/shttpd.conf

Inside this file, search for php_admin_value memory_limit 32M and either remove it or put it a value that is acceptable to you.

Categories: Vesta

Quick and dirty way to generate a self signed cert that lasts 10 years

November 17, 2015 Leave a comment

While I love IIS’s and most program’s ability to generate a self signed cert, my gripe with those is that they last only a year. While a year is generally sufficient for development purposes, sometimes you want one that lasts a whole lot longer.

 

In order to get one that lasts longer, you will need to turn to openssl.

 

Here are the steps

openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3650 -nodes -config ..\share\openssl.cnf

openssl pkcs12 -export -out localhost.pfx -inkey key.pem -in cert.pem

 

Parameters

– newkey: Generate a RSA 2048 bit encryption key

– keyout: the file containing the private key

– out: the file containing the certificate details

– days: how many days is this certificate valid for

– nodes: needed for pfx

– config: for windows, to specific the configuration file location

 

image

Categories: Development, General, IIS, SSL

Nuget quick references

November 11, 2015 Leave a comment

Update-Package –reinstall

Use this to quickly reinstall all of your packages, especially useful when things go wrong

 

Nuget Sources

When you need to add more nuget sources in Visual studio, put a nuget.config file in the same folder as the solution file

the content of the nuget.config file should be

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="Identity* Dev Feed" value="https://www.myget.org/F/identity/" />
    <add key="Nuget" value="https://www.nuget.org/api/v2/" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
</configuration>

Categories: Visual Studio

ASP.NET vNext – EntityFramework 7.0 Database First

November 4, 2015 1 comment

This sample is based off Beta8, but it should work with the older vNext Beta’s as well

EF 7.0 supports both code first aka POCO as well as database first. However you do need a bit of tweaking in order to get EF to generate the classes for you. Take note that edmx files are no longer used for EF 7.0.

 

Step by step guide

  • Starting with a blank project, add the following dependencies

"EntityFramework.Commands": "7.0.0-beta8",
"EntityFramework.SqlServer": "7.0.0-beta8",
"EntityFramework.Core": "7.0.0-beta8",
"EntityFramework.SqlServer.Design": "7.0.0-beta8",

Which should make your dependencies look like this

image

  • Visual Studio 2015 should then run nuget in the background to obtain the new libraries. Once that is done, your dependencies list in VS should show the following libraries

image

  • You will also need to add the following item into your list of commands

    "ef": "EntityFramework.Commands"

Which will then make your commands list look like

image

  • Now you need to run a command prompt and browse to the project directory, and then run the following command, replacing the brackets with actual data

dnx ef dbcontext scaffold –c [DBContextName] –o [Output folder] [SQLConnection string] EntityFramework.SqlServer

e.g

dnx ef dbcontext scaffold -c TestDbContext -o Models "Data Source=.; Initial Catalog=Test;User ID=myusername;Password=P@ssw0rd"  EntityFramework.SqlServer

image

 

Common errors that you will typically encounter when you see “One or more errors occurred.”:

Take note that the stack trace is VERY long, so you will need to scroll right to the front to see the error message

System.AggregateException: One or more errors occurred. —> Microsoft.Data.Entity.Design.OperationException: Unable to find design-time provider assembly. Please install the EntityFramework.SqlServer.Design NuGet package and ensure that the package is referenced by the project. —> System.IO.FileNotFoundException: Could not load file or assembly ‘EntityFramework.SqlServer.Design’ or one of its dependencies. The system cannot find the file specified.

-> this means project.json does not have the EntityFramework.SqlServer.Design, save the project file and do a dnu restore to ensure that all the packages are restored

System.AggregateException: One or more errors occurred. —> System.Data.SqlClient.SqlException: Login failed for user ‘myusername’.

-> obvious, means you entered the wrong password or are connecting to the wrong database server

Categories: 5.0, Entity Framework 7.0

How to run ASP.NET 5.0 from Visual Studio 2015

November 2, 2015 Leave a comment

While it might be strange, if you have not upgraded to RC1, you might encounter issues running ASP.NET 5 websites because its now in beta8 whereas the default template on VS 2015 assumes you only have beta5 installed.

 

ASP.NET 5.0 on BETA 5

  1. Goto File –> New –> Web Application
  2. Create a Preview ASP.NET 5.0 WebAPI project
    image
  3. Once VS loads up, you still see a whole bunch of errors (look at the circled portion)
    image
  4. In order to make it work, you need to enable beta5 clr. To do so, use the following commands

    dnvm use 1.0.0-beta5 -arch x64 -r coreclr –p
    dnvm alias default 1.0.0-beta5 x64 coreclr

    image

  5. Then run dnu restore
    image
  6. You will also need to modify globals.json just to be sure it runs the correct CLR
    image
  7. Once all is done, just run dnx . web to start the webserver
  8. clip_image001

    clip_image002

 

ASP.NET 5.0 on BETA 8

There are a breaking changes between BETA5 and BETA8 e.g AspNet.Hosting has been replaced with IISPlatformHandler

  1. Make sure you set Beta8 as the new default

    dnvm use 1.0.0-beta8 -arch x64 -r coreclr –p
    dnvm alias default 1.0.0-beta8 x64 coreclr

  2. Modify project.json to reflect the breaking changes in beta8

    "dependencies": {
    "Microsoft.AspNet.Mvc": "6.0.0-*",
    "Microsoft.AspNet.StaticFiles": "1.0.0-*",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta8",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
    },

    "commands": {
    "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener –server.urls http://localhost:5000&quot;,
    "kestrel": "Microsoft.AspNet.Server.Kestrel",
    },

  3. Now run dnu restore to restore all the nuget packages
  4. You can now run either IIS Express or Kestrel for DNX projects
    image
  5. For the difference between the web servers, you can refer to https://github.com/aspnet/Home/wiki/Servers

Categories: 5.0