Malform encoding when connect printer with dll

Background

Recently, our company received a project, to help scenic sell tickets. I have to develop ticket print function.

Progress

Any Problem?

Our client have an existing system, they do this using preview, and call system print by browser.

WTF

Our client make a decision, when they click “print” button, there is no preview and other, just print it directly, and, we have to make it as a B/S arch. Therefore, I can only use IE to call dll.

At this moment, our leader tell me: there’s no problem, this framework support IE perfectly.

WTF x2

Yep, just like your think, it’s hardly to find a modern framework that support IE. I can just change my Implementation, run a server on local machine, there have some algorithm to calculate height, it’s annoying to rewrite, so I use a shortcut : all calculation use js on browser but just output printer commands, then local server can forward it to printer.

Problem Raised

It looks like the printer dll provided method have decode Unicode Character as GBK, so we have to convert the coding before send it to printer.

Solution

iconv, a library to convert between codings, this time we convert ‘UTF-8’ to ‘GBK’.

How to connect MySQL Server in wampserver

Open port will cause a security issue, so do that ONLY for dev or debug

I trust we all know that we should set an account for remote access in MySQL, such as


grant all on example_db.* on "example_user"@"%" identified by "your password";
flush privileges;

So, the reason is not misconfig of MySQL, it’s windows firewall, we have to open port by follow actions.

Search(win+Q)->Firewall-> Windows Defender Firewall-> inbound rule

create rule -> port -> release 3306 (sorry I don’t know what is it in English version)

[SOLVED]using dkms to install driver with errors

0X01 Cause

The standby time of my lapta\op (ThinkPad X1C 2014) when running linux is sooo short, but when running windows, the time is OK. So I searched on web: what can I do, and find TLP, it’s easy to use, basically, we can use default configuration. As we now, Lenovo have a threshold config for battery, I do care about it, because each of my laptop, the battery damage fist, TLP support this config (ThinkPad only), location at /etc/default/tlp, we need the module called acpi-call.

The installation is smoothly.


sudo apt-get update && sudo apt-get install acpi-call-dkms
# OK, let's check if we success 

sudo tlp-stat
# unfortunately, it still inactive

sudo dpkg -l | grep dkms # first, we have to check if we installed this package

sudo dkms install # I guess we should use like this.

# we will get a tip, tell us should not use like this, use help subcommand 

sudo dkms help # oh, this autoinstall is OK

Usage: /usr/sbin/dkms [action] [options]
[action] = { add | remove | build | install | uninstall | match | autoinstall
| mkdriverdisk | mktarball | ldtarball | mkrpm | mkkmp | mkdeb | mkbmdeb | status }
[options] = [-m module] [-v module-version] [-k kernel-version] [-a arch]
[-d distro] [-c dkms.conf-location] [-q] [--force] [--all]
[--templatekernel=kernel] [--directive='cli-directive=cli-value']
[--config=kernel-.config-location] [--archive=tarball-location]
[--kernelsourcedir=source-location] [--no-prepare-kernel] [--no-initrd]
[--binaries-only] [--source-only] [-r release (SuSE)] [--verbose]
[--size] [--spec=specfile] [--media=floppy|iso|tar] [--legacy-postinst=0|1]
[--no-depmod]
[-j number]
Error! No action was specified.
sudo dkms autoinstall

0X02 What happened

I find the error message below. It said we don’t have the function copy_from_user.

DKMS make.log for acpi_call-1.2.0 for kernel 4.12.1-chrysalis (x8664)
Thu Jul 13 19:31:39 CEST 2017
make -C /lib/modules/4.12.1-chrysalis/build M=/var/lib/dkms/acpi_call/1.2.0/build modules
make[1]: Entering directory ‘/tmp/linux-4.12.1’
CC [M] /var/lib/dkms/acpi_call/1.2.0/build/acpi_call.o
/var/lib/dkms/acpi_call/1.2.0/build/acpi_call.c: In function ‘acpi_proc_write’:
/var/lib/dkms/acpi_call/1.2.0/build/acpi_call.c:307:9: error: implicit declaration of function ‘copy_from_user’ [-Werror=implicit-function-declaration]
if (copy_from_user( input, buff, len )) {
^~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:309: /var/lib/dkms/acpi_call/1.2.0/build/acpi_call.o] Error 1
make[1]: *** [Makefile:1512: _module/var/lib/dkms/acpi_call/1.2.0/build] Error 2
make[1]: Leaving directory ‘/tmp/linux-4.12.1’
make: *** [Makefile:7: default] Error 2

I find several possibly solution:

  • Add -Werror=implicit-function-declaration compile option
  • use define to declare ( not suitable, I haven’t try it)
  • we have not import right header (at first, I think it should not have this error, it’s system official package)

And when I read the web page above, I find the function copy_from_user may locate at two location: <asm/uaccess.h> or <linux/uaccess.h>, use locate command to finde the source code, it import <asm/uaccess.h>, I changed asm to linux, then run command below, I success.


sudo dkms autoinstall

A commemorative post for build local site with docker

At the first line, I wanna say: docker is the best tool to improve the production efficiency.

I want to build my own site for a long time, and today, succeed. I depley the three site at one server (my laptop, ThinkPad X1C 2014), the site works very smoothly. So I record my action below.

MySql


sudo apt-get update && sudo apt-get install mysql-server

WordPress


docker run -itd --name wordpress \

-v /opt/wordpress/html:/var/www/html \

-p 12080:80 \

wordpress

OpenProject


docker run -itd --name openproject \

-v /opt/openproject/pgdata:/var/lib/postgresql/9.6/main \

-v /opt/openproject/logs:/var/log/supervisor \

-v /opt/openproject/static:/var/db/openproject \

-p 10080:80 \

openproject/community

Gitlab


docker run -itd --name gitlab \

--hostname gitlab.endercaster.lan \

-v /opt/gitlab/config:/etc/gitlab \

-v /opt/gitlab/logs:/var/log/gitlab \

-v /opt/gitlab/data:/var/opt/gitlab \

-p 11080:80 \

-p 11022:22 \

-p 11443:443 \

gitlab/gitlab-ce

Then, using nginx as reverse proxy, proxy by host.