Categories
Uncategorized

Debugging Issues With cert-manager

If you’re using cert-manager to get a Let’s Encrypt certificate for your Kubernetes cluster and running into issues, you can do the following to see what might be going on:

Check Status of Challenge

First, check the status of the certificate:

kubectl describe certificate tls-secret --namespace ingress-nginx

You’ll see something that says something like Created new CertificateRequest resource “tls-secret-1764787185”. Run the following to get more information:

kubectl describe CertificateRequest tls-secret-1764787185 --namespace ingress-nginx

This command will provide the ID of an order, so use a similiar command:

kubectl describe Order tls-secret-1764787185-845386587 --namespace ingress-nginx

Finally, you will get a Challenge to view:

kubectl describe Challenge tls-secret-1764787185-845386587-4119551803 --namespace ingress-nginx

View Logs

If the above isn’t helping, you can view the logs:

kubectl logs -n cert-manager deploy/cert-manager -f
Categories
Uncategorized

Upgrading a NopCommerce Plugin from 3.80 To 4.00

When upgrading nopCommerce, you’ll need to also get the latest versions of plugins to go alongside the nopCommerce installation. Depending on the upgrade, you may need to make some minor changes to the plugin to get it working.

In particular, 3.80 -> 4.00 marks the transition to .NET Core, meaning there are some significant changes to make.

Upgrade the .csproj File

To start, you’ll want to upgrade the .csproj file of the project. Easiest option here is to copy an existing plugin that works with nopCommerce 4.00 and modify it accordingly. You can use the Description.txt file to get the information you need.

File Cleanup

First, create a plugin.json file.

Delete the following files:

  • web.config
  • app.config
  • Description.txt
  • Properties folder

Fix Build

Once you’ve done this, you’ll need to go through the file and make any kind of modifications to get a build to work successfully. If you’re working with VSCode, add the following file omnisharp.json to the plugin:

{
  "RoslynExtensionsOptions": {
    "enableAnalyzersSupport": true
  },
  "MsBuild": {
    "UseLegacySdkResolver": true
  }
}

There are a few specifics to consider:

  • When migrating GetConfigurationRoute, the route will be moved into a Infrastructure/RouteProvider.cs file (as an example).
  • BasePublicController becomes BasePluginController.
  • AdminAuthorize becomes AuthorizeAdmin.
  • Remove references to ChildActionOnly.

Validate Functionality

After getting the build to work successfully, the final step is running nopCommerce locally and installing/uninstalling the plugin. In addition, check the functionality to make sure everything is working.

Reminder: when installing/uninstalling plugins in nopCommerce locally, make sure to shut down and restart the application after installing applications to reflect plugin installation changes.

Categories
Uncategorized

Ripping DVDs using Handbrake

To rip DVDs, first do the following:

After the above is done, open Handbrake and open the DVD as a source. It’ll take a long time to load the data in place, and then you’ll have the ability to select different chapters to rip.

Select the desired title to rip and click ‘Encode’. After the process completes, you’ll be able to view the video.

Categories
Uncategorized

Setting up nopCommerce 4.00+ For Use With VSCode

To get started with using nopCommerce and VSCode together, you’ll need to have the following:

  1. VSCode installed.
  2. The C# extension installed alongside VSCode.
  3. .NET Core 3.0 SDK
  4. If running nopCommerce 4.00, .NET Framework v4.6.1 Developer Pack

Quick Start

  1. Download the nopCommerce source and copy the contents to a folder on your PC.
  2. Open the folder using VSCode.
  3. If you’re running nopCommerce 4.00, apply the changes from this commit.
  4. Run dotnet restore to get all dependencies required for running locally.
  5. In the directory /Presentation/Nop.Web, run dotnet run.
  6. Access http://localhost:55390 and run the installation process to get a database created.

Reference

https://www.jerriepelser.com/blog/using-vscode-for-csharp-development/

https://www.c-sharpcorner.com/article/getting-started-with-nopcommerce-using-visual-studio-code/

Categories
Uncategorized

Create An Admin in nopCommerce With Only Database Access

If you only have access to a database for nopCommerce (for example, if you’ve accidentally locked yourself out), here’s a way to create an administrator with access to the database and access to the frontend.

First, register a new user using the standard registration process. Once that’s done, run the following SQL query on the database to assign administrator rights:

INSERT INTO Customer_CustomerRole_Mapping
VALUES (
	(SELECT Id FROM Customer
	WHERE Email = 'YOUR_EMAIL'),
	(SELECT Id FROM CustomerRole
	WHERE SystemName = 'Administrators')
)

Categories
Uncategorized

Automatically Apply EF Core Database Migrations in Azure Function App on Startup

To apply database migrations to an Azure Function app on startup, you’ll need to have the following set up first:

Once the above is set up, you can set up the application to apply all migrations on startup, making for a link between the running application and the database it is dependent on. This is especially useful for local development – as you won’t run into cases where a local schema is outdated.

Add the following code to the Startup.cs file:

...

[assembly: FunctionsStartup(typeof(YOUR_NAMESPACE.Startup))]

namespace YOUR_NAMESPACE
{
  class Startup : FunctionsStartup
  {
    public override void Configure(IFunctionsHostBuilder builder)
    {
      ConfigureDatabase(builder);
      ...
    }

    private void ConfigureDatabase(IFunctionsHostBuilder builder)
    {
      string SqlConnection =
                    Environment.GetEnvironmentVariable(
                      Constants.ConnectionStringKey);

      if (SqlConnection == null)
      {
        throw new ArgumentNullException(
          $"Environment variable {Constants.ConnectionStringKey} not set.");
      }

      builder.Services.AddDbContext<Context>(
        options => options.UseSqlServer(SqlConnection));

      var optionsBuilder = new DbContextOptionsBuilder<Context>();
      optionsBuilder.UseSqlServer(SqlConnection);

      using (var context = new Context(optionsBuilder.Options))
      {
        try
        {
          context.Database.Migrate();
        }
        catch (Exception e)
        {
          throw new Exception(
            $"Error when migrating database: {e.Message}");
        }
      }
    }
  }
}
Categories
Uncategorized

Checking Validity of a Private Key, CSR and Certificate

If you’re working with a certificate and need a means to check if the combination of the private key, CSR and certificate are all matching, you can run the following OpenSSL commands:

To check the private key:

openssl rsa -modulus -noout -in YOUR_KEY.pem | openssl md5

To check the CSR:

openssl req -noout -modulus -in YOUR_CSR.csr | openssl md5

To check the certificate:

openssl x509 -modulus -noout -in CERTIFICATE.crt | openssl md5

With each of these commands, you will have a value generated besides the (stdin) declaration, which needs to match across all of the different types to show compatibility.

Categories
Uncategorized

Copying a nopCommerce Environment

Copying a nopCommerce environment to a destination such as your local machine or to another environment requires two major steps:

  • Copying the database
  • Cloning the source code and configuring to use the copied database

Copy The Database

  1. Using SSMS, log in to the source database server using administrative credentials (usually the remote environment).
  2. On source database server, right-click on database and click Tasks -> Export Data-tier Application
  3. Save the .bacpac file to the destination machine.
  4. Connect to the destination database server (usually local).
  5. Right-click ‘Databases’ on the destination server and click ‘Import Data-tier Application’.
  6. Use the .bacpac file created from the source database.

Copy and Configure the Source Code

  1. Clone the source code to the destination machine.
  2. Create the /Presentation/Nop.Web/App_Data/dataSettings.json file with the following content:
{
  "DataProvider": "sqlserver",
  "DataConnectionString": "Data Source=<YOUR_DB_SERVER_NAME>;Initial Catalog=<YOUR_DB_NAME>;Integrated Security=True;",
  "RawDataSettings": {}
}

Example:

{
  "DataProvider": "sqlserver",
  "DataConnectionString": "Data Source=localhost\\SQLEXPRESS;Initial Catalog=uesaka;Integrated Security=True;",
  "RawDataSettings": {}
}

Next, verify the site can be accessed.

Finally, make sure to change the store URL to the new URL being used.

Troubleshooting with Nop-templates

If you’re using nop-templates, you’ll run into some issues when trying to copy.

I had to delete all contents from the following SQL table:

delete from SS_C_Condition

Of course, this currently disables all HTML Widgets – so there must be a better way to do this. Take a look at https://www.nopcommerce.com/boards/t/50457/adding-or-editing-quick-tab-item-with-same-key-already-added.aspx

Categories
Uncategorized

Converting nopCommerce to Store Images In Filesystem Instead of Database

By default, nopCommerce stores all of the images in the database, making for simple access. However, with a lot of images, this puts a lot of load on the database, alongside making for a larger database to maintain.

Some research shows that the performance doesnt differ greatly between the two options, but here’s a few reasons you might use either:

Storing in Database

  • Allows for easier backups & environment clones (only need to clone codebase and DB)
  • Single place for image storage (useful with multiple systems)

Storing on Fileserver

  • Separates large portion of data from DB (allows for smaller DB)
  • Lowers load on DB server.

First, back up your database – since this is a process that can cause major issues if something were to go wrong (or if you decide to revert back to storing images in the database).

To convert from storing images in the database to the file server, go to Admin -> Settings -> Media Settings. Click on ‘Change’:

After the conversion completes, nopCommerce will automatically convert all images into the /Content/Images folder. You’ll also notice the binaries no longer being stored in the Picture table.

Shrink Database

Once this is done, you have the potential to open a good amount of space on the database, since the binaries of the images are now stored on the fileserver themselves.

To reclaim this space, you’ll need to shrink the database. Run the following command in SQL:

DBCC SHRINKDATABASE (YOUR_DB, 10);
GO
Categories
Uncategorized

Set up Pi-Hole to Block Ads at the Network Level

You can use a Respberry Pi to block all ads coming in at a DNS level

Requirements:

  • CanaKit (provides Raspberry Pi, Power Supply)
  • Short ethernet cable
  • Monitor and keyboard for initial setup

Raspberry Pi Initial Installation and Configuration

Assemble and then plug in the Raspberry Pi, which should take you to the NOOBS setup window.

Install Raspbian, and work through until you get to the desktop screen for the Raspberry Pi.

Router Configuration

With the Raspberry Pi configured, connect to your router admin page and find the IP address of the Raspberry Pi. Assign a static IP to the Raspberry Pi.

Pi-Hole Installation

On the Raspberry Pi, run the following commands to start installation:

wget -O basic-install.sh https://install.pi-hole.net
sudo bash basic-install.sh

When asked for Upstream DNS Provider, select Cloudflare.

For everything else, just select the default options.

After installation finishes, you’ll be able to log into the web admin with the password provided at the end of installation.

You may want to change the password used to login, you can run the following command on the Raspberry Pi:

pihole -a -p

Pi-Hole Configuration

Access the web interface using http://<IP_ADDRESS>/admin, and log in using the password above.

Change the DNS server on your router to the IP address above.

Verification

An easy way to verify is to check a page that uses ads (here’s a good example). See if any ads appear, and then check the Pi-Hole admin:

Reference

https://kb.netgear.com/25722/How-do-I-reserve-an-IP-address-on-my-NETGEAR-router

https://cleanbrowsing.org/guides/cleanbrowsing-netgear-orbi-dns-configuration