Showing posts with label debian. Show all posts
Showing posts with label debian. Show all posts

Saturday, November 14, 2026

Debian 13: troubleshooting HP 415 inktank scanner on wifi

symptom: not scan full image

install wifi scanner

# apt install sane-airscan

check you are in group scan and print

$ groups
... scanner lp lpadmin 

scan your hp 415 inktank 

$ airscan-discover
[devices]
  HP Ink Tank Wireless 410 series [1BAF5D] = http://[2404:8000:1012:60ae::1]:8080/eSCL/, eSCL
  HP Ink Tank Wireless 410 series [1BAF5D] = https://[2404:8000:1012:60ae::1]:443/eSCL/, eSCL
  HP Ink Tank Wireless 410 series [1BAF5D] = http://192.168.18.201:8080/eSCL/, eSCL
  HP Ink Tank Wireless 410 series [1BAF5D] = https://192.168.18.201:443/eSCL/, eSCL
  HP Ink Tank Wireless 410 series [1BAF5D] = http://192.168.18.201:53048, WSD
  HP Ink Tank Wireless 410 series [1BAF5D] = http://[FE80::E270:EAFF:FE1B:AF5D%253]:53048, WSD

rerun your xsane and select "eSCL HP Ink Tank Wire ip=...."

Follow these to install hplip

  1. https://dedetoknotes.blogspot.com/2023/07/debian-bookworm-configure-printer-and.html
  2. https://dedetoknotes.blogspot.com/2021/07/debian-buster-install-all-in-one-hp-ink.html 

Monday, November 9, 2026

Know your laptop hardware (advan heritage ai 7 255)

To find out manufacture model of your main board

windows PowerShell

C:\windows\system32> Get-CimInstance Win32_BaseBoard | Format-List Manufacturer, Product, Version


Manufacturer : SU
Product      : AKN79C-140P-IMR
Version      : Version 1.0

Debian

# cat /sys/devices/virtual/dmi/id/board_name
AKN79C-140P-IMR
# cat /sys/devices/virtual/dmi/id/board_vendor
SU

SU stands for Sixunited (Shanghai Sixunited Intelligent Technology Co.

To find out NVME model

Debian

# apt install nvme-cli
...
# nvme id-ctrl /dev/nvme0 | grep -E 'mn|fr'
mn        : HS-SSD-WAVE(P) 256G                     
fr        : SN17027 
frmw      : 0x1a
mntmt     : 373
mnan      : 0
mnsudmq   : 0

It is Hiksemi wave(p) 256GB, safe running temperature 70°C. NVMe SSD already has APST enabled and is configured to use its deepest power-saving state, PS4.

 

Saturday, November 7, 2026

Debian 13: installing mobile verification toolkit to trace pegasus malware for android devices

Mobile Verification Toolkit (MVT) is a tool to facilitate the consensual forensic analysis of Android and iOS devices, for the purpose of identifying traces of compromise. The Mobile Verification Toolkit (MVT) was developed by the Amnesty International Security Lab. Note: mvt is not removal tools.

Here are common known spyware can be trace by MVT:

  1. Pegasus: NSO Group spyware targeting iOS and Android
  2. Predator: Commercial spyware associated with Intellexa
  3. Reign: Sophisticated spyware associated with QuaDream
  4. Hermit: Commercial spyware associated with RCS Lab
  5. KingsPawn: Spyware associated with QuaDream investigations
  6. FinSpy / FinFisher: Commercial surveillance software
  7. DarkCaracal: Mobile surveillance campaign targeting Android devices

Install python 

# apt install python3 python3-venv sqlite3 libusb-1.0-0 libimobiledevice-utils usbmuxd pipx

Install adb for android

# apt install -y android-sdk-platform-tools android-sdk-platform-tools-common

Create virtual python 

$ pipx ensurepath
Success! Added /[home_user]/.local/bin to the PATH environment variable.

Consider adding shell completions for pipx. Run 'pipx completions' for
instructions.

You will need to open a new terminal or re-login for the PATH changes to take
effect. Alternatively, you can source your shell's config file with e.g.
'source ~/.bashrc'.

Otherwise pipx is ready to go!

Install mvt

$ pipx install mvt
  installed package mvt 2026.11.2, installed using Python 3.13.5
  These apps are now globally available
    - mvt
    - mvt-android
    - mvt-ios
⚠️  Note: '/[home_user]/.local/bin' is not on your PATH environment
    variable. These apps will not be globally accessible until your PATH is
    updated. Run `pipx ensurepath` to automatically add it, or manually modify
    your PATH in your shell's config file (e.g. ~/.bashrc).
done!
$ ls ./.local/bin/
mvt  mvt-android  mvt-ios

To update mvt

$ pip3 install --upgrade mvt

Add virtual python binary 

$ echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
$ source ~/.bashrc
$ mvt version


        MVT - Mobile Verification Toolkit

        https://mvt.re
        Version: 2026.11.2

        You have not yet downloaded any indicators, check the `download-iocs` 
command!

Download / Update spyware indicators

$ mvt download-iocs


        MVT - Mobile Verification Toolkit

        https://mvt.re
        Version: 2026.11.2

        You have not yet downloaded any indicators, check the `download-iocs` 
command!


               [mvt.common.updates] Downloaded indicators "NSO Group Pegasus 
Indicators of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_AmnestyTec
h_investigations_master_2021-07-18_nso_pegasus.stix2
               [mvt.common.updates] Downloaded indicators "Predator Spyware 
Indicators of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_intellexa_predator_predator.stix2
               [mvt.common.updates] Downloaded indicators "RCS Lab Spyware 
Indicators of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_2022-06-23_rcs_lab_rcs.stix2
               [mvt.common.updates] Downloaded indicators "Stalkerware 
Indicators of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_AssoEchap_
stalkerware-indicators_master_generated_stalkerware.stix2
               [mvt.common.updates] Downloaded indicators "Surveillance campaign
linked to mercenary spyware company" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_AmnestyTec
h_investigations_master_2023-03-29_android_campaign_malware.stix2
               [mvt.common.updates] Downloaded indicators "Quadream KingSpawn 
Indicators of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_2023-04-11_quadream_kingspawn.stix2
               [mvt.common.updates] Downloaded indicators "Operation 
Triangulation Indicators of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_2023-06_01_operation_triangulation_operation_triangulation
.stix2
               [mvt.common.updates] Downloaded indicators "WyrmSpy and DragonEgg
Indicators of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_2023-07-25_wyrmspy_dragonegg_wyrmspy_dragonegg.stix2
               [mvt.common.updates] Downloaded indicators "Wintego Helios 
Indicators of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_AmnestyTec
h_investigations_master_2024-05-02_wintego_helios_wintego_helios.stix2
               [mvt.common.updates] Downloaded indicators "NoviSpy (Serbia) 
Indicators of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_AmnestyTec
h_investigations_master_2024-12-16_serbia_novispy_novispy.stix2
               [mvt.common.updates] Downloaded indicators "EagleMsgSpy 
Indicators of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_2024-12-25_eaglemsgspy_eaglemsgspy.stix2
               [mvt.common.updates] Downloaded indicators "Candiru 
(DevilsTongue) Indicators of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_candiru_candiru.stix2
               [mvt.common.updates] Downloaded indicators "ResidentBat 
Indicators of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_ResidentBat_residentbat.stix2
               [mvt.common.updates] Downloaded indicators "Cellebrite Indicators
of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_cellebrite_cellebrite.stix2
               [mvt.common.updates] Downloaded indicators "DarkSword Indicators 
of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_2026-03-30_darksword_darksword.stix2
               [mvt.common.updates] Downloaded indicators "Coruna Indicators of 
Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_2026-03-03_coruna_cryptowaters_coruna.stix2
               [mvt.common.updates] Downloaded indicators "Morpheus Indicators 
of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_2026-04-23_ips_morpheus_morpheus.stix2
               [mvt.common.updates] Downloaded indicators "BTMOB Indicators of 
Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_2026-05-26_btmob_btmob.stix2
               [mvt.common.updates] Downloaded indicators "Spyrtacus Indicators 
of Compromise" to 
/[home_user]/.local/share/mvt/indicators/raw.githubusercontent.com_mvt-projec
t_mvt-indicators_main_2026-04-09_sio_spyrtacus_spyrtacus.stix2
$ mvt version
        MVT - Mobile Verification Toolkit

        https://mvt.re
        Version: 2026.11.2

        Indicators updates checked recently, next automatic check in 12 hours

MVT installation done.

NOTE: steps below does not tested, and may different output depends on your android phone. 

You MUST enable developer option and debug on your Android phone.  Connect your android phone using usb cable.

create directory for forensic

$ mkdir -p ~/forensics/{evidence/android,working/android,reports/android}

Pull your data from android phone

$ adb bugreport ~/forensics/evidence/android/bugreport.zip

Scan your data to find evidence of spying malware 

$ mvt-android check-bugreport -o ~/forensics/reports/android/ ~/forensics/evidence/android/bugreport.zip

Find out the result on folder ~/forensics/reports/android/ 

 

Monday, October 26, 2026

Debian 13: patching CVE-2026-109618 and CVE-2026-109619 php2shell

known CVE-2026-109618 and CVE-2026-109619

Description: PHP uses longjmp() for out-of-memory (OOM) errors to exit the current context and abort handling of the request. Some contexts may not properly account for this scenario and leave request memory in an uninitialized state before performing an allocation. The subsequent request cleanup procedure may read or branch on this memory. Multiple OOM strategies can consistently trigger this condition and lead to remote code execution (RCE).

Offical debian patch

  • debian 12 php 8.2 -> fix 8.2.35 
  • debian 13 php 8.4 -> fix 8.4.27

source: https://security-tracker.debian.org/tracker/CVE-2026-109618

The steps are

  1. check your php version# php -v
    PHP 8.4.26 (cli) (built: Sep 24 2026 17:16:18) (NTS)
    Copyright (c) The PHP Group
    Built by Debian
    Zend Engine v4.4.26, Copyright (c) Zend Technologies
        with Zend OPcache v8.4.26, Copyright (c), by Zend Technologies
  2. perform upgrade if patch require
    # apt update && apt upgrade -y
    ...
  3. check php version after upgradea
    < # php -v PHP 8.4.27 (cli) (built: Oct 21 2026 07:53:46) (NTS) Copyright (c) The PHP Group Built by Debian Zend Engine v4.4.27, Copyright (c) Zend Technologies with Zend OPcache v8.4.27, Copyright (c), by Zend Technologies
  4. Restart your apache 
    # systemctl restart apache2
  5. Restart PHP-FPM if you install it
    # systemctl restart php8.4-fpm

Warning: for server running Debian 11 24/7 and lower, please upgrade to Debian 12 to get patch! 

If you can not upgrade your os these are minimum php version had been patched:

  1. **PHP 8.2:** minimum 8.2.35
  2. **PHP 8.3:** minimum 8.3.36
  3. **PHP 8.4:** minimum 8.4.27
  4. **PHP 8.5:** minimum 8.5.12

If your php below those version e.g. php 7.4, these are configuration for emergency:

  1. apache include wamp

    # Limit request body size to 2MB (adjust based on your app's actual needs)
    LimitRequestBody 2097152
    # if you use php-fpm
    pm.max_requests = 1 if using PHP-FPM
  2. nginx

    http {
        client_max_body_size 2m;
    }
  3. lighttpd

    server.max-request-size = 2048
  4. iis with http

    <configuration>
        <system.webServer>
            <security>
                <requestFiltering>
                    <requestLimits maxAllowedContentLength="2097152" />
                </requestFiltering>
           </security>
       </system.webServer>
    </configuration>
  5. caddy

    example.com {
        route {
            request_body {
                max_size 2MB
            }
            php_fastcgi localhost:9000
        }
    }
  6. haproxy
    tune.http.maxrequest 

 

 

Tuesday, October 20, 2026

Debian 13: in dual boot, grub update can not fix debian boot

Go into windows and open cmd with administrator 

C:\Windows\System32>bcdedit /enum all

Firmware Boot Manager
---------------------
identifier              {fwbootmgr}
displayorder            {bootmgr}
                        {e074b9af-824b-11f1-806d-806e6f6e6963}
                        {3923b543-cc0a-11f1-9907-806e6f6e6963}
timeout                 1

Windows Boot Manager
--------------------
identifier              {bootmgr}
device                  partition=\Device\HarddiskVolume2
path                    \EFI\Microsoft\Boot\bootmgfw.efi
description             Windows Boot Manager
locale                  id-ID
inherit                 {globalsettings}
default                 {current}
resumeobject            {d5b4c214-c5eb-11f0-b9cc-bfd3f4d1aeed}
displayorder            {current}
toolsdisplayorder       {memdiag}
timeout                 30

Firmware Application (101fffff)
-------------------------------
identifier              {3923b543-cc0a-11f1-9907-806e6f6e6963}
device                  partition=\Device\HarddiskVolume2
path                    \EFI\debian\shimx64.efi
description             debian

Firmware Application (101fffff)
-------------------------------
identifier              {e074b9af-824b-11f1-806d-806e6f6e6963}
device                  partition=\Device\HarddiskVolume2
path                    \EFI\RECOVERY\BOOT\BOOTMGFW.EFI
description             Windows Boot Manager
....

run

C:\Windows\System32>bcdedit /set {fwbootmgr} displayorder {3923b543-cc0a-11f1-9907-806e6f6e6963} {bootmgr} {e074b9af-824b-11f1-806d-806e6f6e6963}
The operation completed successfully. 

confirm boot order

C:\Windows\System32>bcdedit /enum all

Firmware Boot Manager
---------------------
identifier              {fwbootmgr}
displayorder            {3923b543-cc0a-11f1-9907-806e6f6e6963}
                        {bootmgr}
                        {e074b9af-824b-11f1-806d-806e6f6e6963}
timeout                 1

Windows Boot Manager
--------------------
identifier              {bootmgr}
device                  partition=\Device\HarddiskVolume2
path                    \EFI\Microsoft\Boot\bootmgfw.efi
description             Windows Boot Manager
locale                  id-ID
inherit                 {globalsettings}
default                 {current}
resumeobject            {d5b4c214-c5eb-11f0-b9cc-bfd3f4d1aeed}
displayorder            {current}
toolsdisplayorder       {memdiag}
timeout                 30

Firmware Application (101fffff)
-------------------------------
identifier              {3923b543-cc0a-11f1-9907-806e6f6e6963}
device                  partition=\Device\HarddiskVolume2
path                    \EFI\debian\shimx64.efi
description             debian

Firmware Application (101fffff)
-------------------------------
identifier              {e074b9af-824b-11f1-806d-806e6f6e6963}
device                  partition=\Device\HarddiskVolume2
path                    \EFI\RECOVERY\BOOT\BOOTMGFW.EFI
description             Windows Boot Manager
... 

Restart your computer.

Last option, change boot order from Bios (depends on vendor) 

Bios -> Boot NVME Drive BBS Priorities  

Wednesday, October 14, 2026

Debian 13: jakarta tomcat create servlet using Netbeans

This steps use Netbeans version 31.

to create tomcat apache project in netbeans follow these steps:

  1. open your netbeans
  2. File -> New Project -> java with Maven -> Web Application
  3. fill "Project Name" e.g. My Servlet
  4. in New Web Application -> Server click Add
  5. select Apache Tomcat or TomEE
  6. select your jakarta tomcat directory
  7. fill username and password from tomcat-users.xml file which is has rule rolename="manager-gui"
  8. Finish will return to New Web Application, then Finish 

to create a new servlet

  1. From your project -> Source Packages -> <package_name>. MyServlet, right click and create New -> Servlet
  2. Class Name: HelloWorld, then next
  3. Servlet Name: My Servlet
  4. URL Pattern: /HelloWorkd
  5. This will create default response
  6. run from your netbeans, and your HelloWorld will appear in browser with url http://localhost:8080/MyServlet/HelloWorld

now, we add mariadb into our project, edit Project Files -> pom.xml

     <dependencies>
        ....
        <!-- MariaDB JDBC driver -->
        <dependency>
            <groupId>org.mariadb.jdbc</groupId>
            <artifactId>mariadb-java-client</artifactId>
            <version>3.5.10</version>
        </dependency>
    </dependencies>

now edit HelloWorld.java

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet HelloWorld </title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet HelloWorld at " + request.getContextPath() + " 0261015</h1>");
            
            // connect to db
            out.println("<p>connecting to mariadb</p>");
            
            try {
                Class.forName("org.mariadb.jdbc.Driver");
                out.println("<p>MariaDB JDBC driver FOUND</p>");
                
                try (java.sql.Connection conn =
                        java.sql.DriverManager.getConnection(
                            "jdbc:mariadb://localhost:3306/<db_name>",
                            "<db_user>",
                            "<db_password>")) {

                    out.println("<p>MariaDB CONNECTION SUCCESSFUL</p>");
                    out.println("<p>Database: "
                            + conn.getCatalog() + "</p>");
                } catch (SQLException ex) {
                    out.println("<p>Error"+ex.getMessage()+"</p>");
                }
                
            } catch (ClassNotFoundException e) {
                out.println("<p>MariaDB JDBC driver NOT FOUND</p>");
            }
            
            out.println("</body>");
            out.println("</html>");
        }
    }

run your servlet.

if no error found, you may start writing your application.  

hint: use any ai to find error in your code, copy paste code and error. but Do Not rely on it, use your instinct to fix your code, ai may made mistake.  

Thursday, September 24, 2026

Asus eee pc 1215b dual boot (debian and windows), downgrade windows 10 to windows 7 pro x64

the disk of system used mbr/dos partition. there are 2 option to install windows 7 pro:

  1. using usb and rufus in mbr mode
  2. using cd/dvd rom
for systen with mbr/dos partition, using cd/dvd is easier. 

the installation is straight forward. yoy format c:/ contains windows 10 , and select this disk as target your windows 7 pro x64. it takes 30 minutes to insta windows 7 pro x64 from dvd.

you need to install driver for vga, wifi and usb. my system uses broadcom bcm4313 combo bluetooth. drives is not exist in official website for asus eee pc 1215b, but exis asus support. alternative, downloas bcm4313 from windowa catalog. you can uses your existing debian to download driver after you repair grub boot.

to repair your existinf grub follow these steps:
  1. boot from any debian media 
  2. enter rescue mode, debian will load any components require.
  3. choose your root system 
  4. choose execute a shell 
  5. run 
# grub-install /dev/sda/
# update-grub

after you restart to your syatem and find no windows option at grub screen, enter into your debian. then at root shell execute 

# update-grub

microsoft has closed any support to windows 7, click on windows update will useless.

Note: your internet explorer will rejected by seach engine because it is too old. the option is using supermium browser.

open your internel explorer and type https://www.supermium.net/. download and install it. dont use internet to open or search supermium, the most search engine server will reject your internet explorer.

if you are not sure about supermium security, use your debian 13 with icewn to browse sensitive application like email or banking.  

Friday, September 18, 2026

Debian 13: jakarta tomcat create servlet manually

under directory WEB-INF create 2 folder

  1. src
  2. classes 

under src, we place servlet and java code.

for package com.dedetok, create folder ~/WEB-INF/src/com/dedetok/ and write 2 files

MyWorld.java

package com.dedetok;

public class MyWorld {

    public String getMessage() {
        return "hello world";
    }
}

HelloServlet.java 

package com.dedetok;

import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

public class HelloServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request,
                          HttpServletResponse response)
            throws IOException {

        MyWorld world = new MyWorld();

        response.setContentType("text/plain");
        response.getWriter().println(world.getMessage());
    }
} 

We map our servlet, edit ~/WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
                             https://jakarta.ee/xml/ns/jakartaee/web-app_6_1.xsd"
         version="6.1">

    <display-name>My Application</display-name>

    <servlet>
        <servlet-name>Hello Anything</servlet-name>
        <servlet-class>com.dedetok.HelloServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Hello Anything</servlet-name>
        <url-pattern>/hello</url-pattern>
    </servlet-mapping>
</web-app>

Note: <servlet-name> between <servlet> and <servlet-mapping> must match.

compile your java, go it ~/WEB-INF/ folder and run

$ javac   -cp <your_path_to_jakarta_tomcat>/apache-tomcat-11.0.26/lib/servlet-api.jar   -d ./classes   ./src/com/dedetok/*.java 

restart your jakarta tomcat and try servlet http://localhost:8080/myapp/hello. hello comes from <servlet-mapping>

It is not practicable to map every servlet, there is other way

now at directory ~/WEB-INF/src/com/dedetok/  create HelloServlet2.java

package com.dedetok;

import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import jakarta.servlet.annotation.WebServlet;

@WebServlet("/hello2")
public class HelloServlet2 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request,
                          HttpServletResponse response)
            throws IOException {

        MyWorld world = new MyWorld();

        response.setContentType("text/plain");
        response.getWriter().println(world.getMessage()+" 2");
    }
}  

we use  @WebServlet("/hello2") to map url. do not forget to import  jakarta.servlet.annotation.WebServlet.

compile it, and restart your jakarta tomcat. you can access it via http://localhost:8080/myapp/hello2.

To use MyWorld class into jsp, at directory ~/myapp/ (upper directory from WEB-INF) , create file callservlet.jsp

<%@ page import="com.dedetok.MyWorld" %>

<%
    MyWorld world = new MyWorld();
%>

<html>
<body>
    <h1><%= world.getMessage() %></h1>
</body>
</html> 

or use wildcard for import="com.dedetok.*"  

Now you can directly build your application. MVC model can be used if you like. happy coding.  

 

Thursday, September 17, 2026

Debian 13: jakarta tomcat add application myapp manually without war (part 2)

It this part, we will: 

  1. Add myapp
  2. Add mariadb library

Add myapp

  1. under folder <home>/webapps/ create folder myapp
  2. under folder <home>/webapps/myapp/  create folder WEB-INF
  3. optional, at folder <home>/webapp/myapp> write index.html e.g  
<!DOCTYPE html>
<html lang="en">
<body>
    <h1>Hello, World!</h1>
</body>
</html>

Restart your jakarta tomcat, and myapp appear in list of application. Test your index.html, url http://localhost:8080/myapp/.

Add mariadb 

  1. Under folder  <home>/webapps/myapp/WEB_INF, create folder lib.
  2. download jconnect from https://mariadb.org/connector-java/all-releases/, and put it in <home>/webapps/myapp/WEB_INF/lib, i.e. <home>/webapps/myapp/WEB-INF/lib/mariadb-java-client-3.5.3.jar

Under folder  <home>/webapps/myapp/ write test.jsp

<%
try {
    Class.forName("org.mariadb.jdbc.Driver");
    out.println("MariaDB JDBC driver FOUND");
} catch (ClassNotFoundException e) {
    out.println("MariaDB JDBC driver NOT FOUND");
}
%>

restart your jakarta tomcat and test it http://localhost:8080/myapp/test.jsp.

if you have mariadb running, you can extend test.jsp to this

<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>

<%
try {
    Class.forName("org.mariadb.jdbc.Driver");
    out.println("MariaDB JDBC driver FOUND<br>");

    Connection conn = DriverManager.getConnection(
        "jdbc:mariadb://localhost:3306/mydb", // change to your db name
        "admin", // change to your user
        "admin" // change to your password
    );

    out.println("Connected to MariaDB!<br>");

    conn.close();

} catch (ClassNotFoundException e) {
    out.println("MariaDB JDBC driver NOT FOUND<br>");
    out.println(e);

} catch (Exception e) {
    out.println("Database connection FAILED<br>");
    out.println(e);
}
%> 

 

 

 

Debian 13: jakarta tomcat & openjdk 21 installation (part 1)

Assume openjdk 21 installed, it is lts verssion.

Download latest jakarta tomcat from https://tomcat.apache.org/download-11.cgi, i.e. version 11.0.26 (currently).

extract it into your home (user) directory

change permission to start jakarta tomcat

$ cd apache-tomcat-11.0.26/bin/
$ chmod 744 *.sh

Directory structure is:

  • bin
  • conf
  • lob
  • logss
  • temps
  • webapps
  • work 

You must add user to manage your jakarta tomcat. User rules are:

  1. manager-gui - allows access to the HTML GUI and the status pages
  2. manager-script - allows access to the text interface and the status pages
  3. manager-jmx - allows access to the JMX proxy and the status pages
  4. manager-status - allows access to the status pages only 

Edit <tomcat_home>/conf/tomcat-users.xml

<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
...
  <role rolename="manager-gui"/>
  <user username="admin" password="admin" roles="manager-gui"/>
</tomcat-users> 

To run jakarta tomcat

$ ./startup.sh&
[1] 6430
~/apache-tomcat-11.0.26/bin$ Using CATALINA_BASE:   <home>/apache-tomcat-11.0.26
Using CATALINA_HOME:   <home>/apache-tomcat-11.0.26
Using CATALINA_TMPDIR: <home>/apache-tomcat-11.0.26/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       <home>/apache-tomcat-11.0.26/bin/bootstrap.jar:<home>/apache-tomcat-11.0.26/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.

[1]+  Done                    ./startup.sh

Open your browser and open url http://localhost:8080/. 

To shutdown, run $ ./shutdown.sh.

Your application will on <home>/webapps and root for http://localhost:8080 is on <home>/webapps/ROOT/

For production, go to "List Application", Undeploy any unused applications.  

 

Friday, July 10, 2026

Debian 13: installing mysql-workbench-community

Download apt configuration from https://dev.mysql.com/downloads/repo/apt/ , current version is mysql-apt-config_0.8.39-1_all.deb

here is configuration for non cluster only target to mysql workbench

  • MySql Server & Cluster: mysql 8.4 lts
  • MySql Connector: non/disable -> enable if you need MySql connector e.g. jConnector

# dpkg -i mysql-apt-config_0.8.39-1_all.deb 
Selecting previously unselected package mysql-apt-config.
(Reading database ... 232081 files and directories currently installed.)
Preparing to unpack mysql-apt-config_0.8.39-1_all.deb ...
Unpacking mysql-apt-config (0.8.39-1) ...
Setting up mysql-apt-config (0.8.39-1) ...

mysql-workbench-community is not available for Debian 13  

credit: online html escape https://www.freeformatter.com/html-escape.html#before-output 

Wednesday, June 10, 2026

Java: reading config.conf file

example config.conf


# http and https ports configuration
http_port = 48001
https_port = 48001

# printer port
printer_port=/dev/rfcomm0
# printer size
printer_size=80mm

java code


    // configuration file config.conf
    static final String linux_file_path = "/etc/dddtescpos/config.conf";
    static final String file_path = "./config.conf";

    public static String printer_port = null;
    public static String printer_size = null;
    
    public static int http_port = -1;
    public static int https_port = -1;
    
    public static void readConfig() {
        Path configFile = Paths.get(linux_file_path);
        
        if (Files.notExists(configFile)) {
            configFile = Paths.get(file_path);
        }
        
        // comment in config file will # or !
        Properties props = new Properties();

        try (InputStream input = Files.newInputStream(configFile)) {
            props.load(input);
        
            printer_port = props.getProperty("printer_port");
            printer_size = props.getProperty("printer_size");
            if (printer_size == null || printer_size.isBlank()) {
                printer_size = "80mm";   // default
            } else {
                printer_size = printer_size.trim().toLowerCase();

                if (!printer_size.equals("58mm")
                        && !printer_size.equals("80mm")) {
                    printer_size = "80mm";   // default for invalid value
                }
            }


            String tmpPort = props.getProperty("http_port","48001");
            try {
                int intTmpPort = Integer.parseInt(tmpPort); 
                if (intTmpPort<48000 || intTmpPort>65535)
                    intTmpPort = 48001;
                    http_port = intTmpPort;
            } catch (NumberFormatException ex) {
                http_port = 48001;
            }
            tmpPort = props.getProperty("https_port","48002");
            try {
                int intTmpPort = Integer.parseInt(tmpPort); 
                if (intTmpPort<48000 || intTmpPort>65535)
                    intTmpPort = 48002;
                https_port = intTmpPort;
            } catch (NumberFormatException ex) {
                https_port = 48002;
            }
            // if ports hava equal value, set default
            if (http_port == https_port) {
                http_port = 48001;
                https_port = 48002;
            }
        } catch (IOException ex) {
            System.out.println("No Configuration file found");
            http_port = 48001;
            https_port = 48002;            
        }
        
    }

 

Monday, June 8, 2026

Java: http and https (self sign certificate)

install mkcert


# apt install mkcert

go to root of netbeans project and create self sign certificate


$ mkcert localhost
Created a new local CA 💥
Note: the local CA is not installed in the system trust store.
Note: the local CA is not installed in the Firefox and/or Chrome/Chromium trust store.
Run "mkcert -install" for certificates to be trusted automatically ⚠️

Created a new certificate valid for the following names 📜
 - "localhost"

The certificate is at "./localhost.pem" and the key at "./localhost-key.pem" ✅

It will expire on 8 September 2028 🗓

Convert to PKCS 12


$ openssl pkcs12 -export \
  -in localhost.pem \
  -inkey localhost-key.pem \
  -out localhost.p12 \
  -name localhost
Enter Export Password:
Verifying - Enter Export Password:

main java code


/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 */

package com.dedetok.ddtescpos;

import com.alibaba.fastjson2.JSONObject;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsExchange;
import com.sun.net.httpserver.HttpsServer;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;


/**
 *
 * @author dedetok
 */
public class DdtEscPos {

    final static String serviceString = "DdtEscPos";
    final static String serviceVersion = "1.0";
    
    public static void main(String[] args) {
        System.out.println("DdtEscPos reading configuration file");
        MyController.readConfig(); // if configuration not available, use hard code config
        
        System.out.println(serviceString+" "+serviceVersion);
        
        // ================= 
        try {
            HttpServer httpServer = createHttpService(MyController.http_port);
            HttpsServer httpsServer = createHttpsService(MyController.https_port);
            
            Runtime.getRuntime().addShutdownHook(new Thread(() -> {
                System.out.println("Stopping HTTP & HTTPS server...");
                httpServer.stop(5); // stop 5 second
                System.out.println("HTTP server stopped");
                httpsServer.stop(5); // stop 5 second
                System.out.println("HTTPS server stopped");

            }));
            httpServer.start();
            System.out.println("HTTP server running on http://localhost:" + MyController.http_port);
            httpsServer.start();
            System.out.println("HTTPS server running on http://localhost:" + MyController.https_port);

        } catch (IOException | KeyStoreException | NoSuchAlgorithmException | CertificateException | UnrecoverableKeyException | KeyManagementException ex) {
            System.getLogger(DdtEscPos.class.getName()).log(System.Logger.Level.ERROR, (String) null, ex);
        }
    }

    /*
     * create http service in httpPort
     */
    static HttpsServer createHttpsService(int httpsPort) throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException, KeyManagementException {
        // Load PKCS12 keystore
        char[] password = "escpos".toCharArray();
        KeyStore ks = KeyStore.getInstance("PKCS12");
        try (FileInputStream fis = new FileInputStream("localhost.p12")) {
            ks.load(fis, password);
        }

        KeyManagerFactory kmf = KeyManagerFactory.getInstance(
                KeyManagerFactory.getDefaultAlgorithm());
        
        kmf.init(ks, password);

        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(kmf.getKeyManagers(), null, null);

        // Create HTTPS server
        HttpsServer httpsServer =
                HttpsServer.create(
                        new InetSocketAddress("localhost", httpsPort),
                        0);        
    
        httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
        
        // Register endpoints
        httpsServer.createContext("/", DdtEscPos::handleHttpRequest);
        httpsServer.createContext("/printjson", DdtEscPos::handlePrintJson);        
        
        return httpsServer;
    }
    
    /*
     * create http service in httpPort
     */
    static HttpServer createHttpService(int httpPort) throws IOException {
        HttpServer httpServer =
                HttpServer.create(new InetSocketAddress("localhost", httpPort), 0);
        
        httpServer.createContext("/", DdtEscPos::handleHttpRequest);
        httpServer.createContext("/printjson", DdtEscPos::handlePrintJson);
        return httpServer;
    }

    /*
     * handling /
     */
    static void handleHttpRequest(HttpExchange exchange) throws IOException {
        // CORS
        exchange.getResponseHeaders().add(
                "Access-Control-Allow-Origin", "*");

        exchange.getResponseHeaders().add(
                "Access-Control-Allow-Headers",
                "Content-Type, Authorization");

        exchange.getResponseHeaders().add(
        "Access-Control-Allow-Methods",
        "GET, POST, OPTIONS");

        if ("OPTIONS".equalsIgnoreCase(exchange.getRequestMethod())) {
            exchange.sendResponseHeaders(204, -1);
            return;
        }
        
        // UTF-8 text response
        exchange.getResponseHeaders().add(
                "Content-Type",
                "text/plain; charset=UTF-8");
        
        String response = infoService(exchange).toString();

        byte[] responseBytes = response.getBytes(StandardCharsets.UTF_8);

        exchange.sendResponseHeaders(200, responseBytes.length);

        
        try (OutputStream os = exchange.getResponseBody()) {
            os.write(responseBytes);
        }
        System.out.println("Servicing client done"); // debug
    }

    /*
     * handling /printjson
     */
    static void handlePrintJson(HttpExchange exchange) throws IOException {
        // CORS
        exchange.getResponseHeaders().add(
                "Access-Control-Allow-Origin", "*");

        exchange.getResponseHeaders().add(
                "Access-Control-Allow-Headers",
                "Content-Type, Authorization");

        exchange.getResponseHeaders().add(
        "Access-Control-Allow-Methods",
        "GET, POST, OPTIONS");

        if ("OPTIONS".equalsIgnoreCase(exchange.getRequestMethod())) {
            exchange.sendResponseHeaders(204, -1);
            return;
        }
        
        // UTF-8 text response
        exchange.getResponseHeaders().add(
                "Content-Type",
                "text/plain; charset=UTF-8");
        // get json from request
        // Read request body
        String requestBody;
        try (InputStream is = exchange.getRequestBody()) {
            requestBody = new String(is.readAllBytes(), StandardCharsets.UTF_8);
            // Parse JSON
            // Parse JSON and process
            JSONObject json = JSONObject.parseObject(requestBody);

            JSONObject responseJson = infoService(exchange);
            
            try {
                MyController.printJson(json.toString());


                responseJson.put("status", "printing done");
            } catch (IOException ex) {
                responseJson.put("status", "printing fail");
                responseJson.put("error", ex.getMessage());
                
            }
            
            byte[] bytes =
                responseJson.toString().getBytes(StandardCharsets.UTF_8);

            exchange.sendResponseHeaders(200, bytes.length);
            OutputStream os = exchange.getResponseBody();
            os.write(bytes);
            os.flush();

        }
    }
    
    /* 
     * standard info response 
     */
    static JSONObject infoService(HttpExchange exchange) {
        JSONObject jsonObj = new JSONObject();
        
        jsonObj.put("version", serviceVersion);
        jsonObj.put("service", serviceString);
        jsonObj.put("status", "running");
        String host = exchange.getLocalAddress().getHostString();
        int port = exchange.getLocalAddress().getPort();

        String scheme = (exchange instanceof HttpsExchange)
        ? "https://"
        : "http://";
        
        String baseUrl = scheme + host + ":" + port;
        jsonObj.put("endpoint",baseUrl+"/printjson");
        
        return jsonObj;
    }
}

to run service


$ java -jar target/DdtEscPos-1.0.jar 
Hello World!
HTTP server running on http://localhost:50001
HTTPS server running on https://localhost:50002
Serviing client done
Serviing client done

using curl to send json to print http


$ curl -H "Content-Type: application/json" \
     -d @exampleescpos.json \
     http://localhost:50001/printjson

https


$ curl -k \
  -H "Content-Type: application/json" \
  -d @exampleescpos.json \
  https://localhost:50002/printjson

or 


$ curl --insecure \
  -H "Content-Type: application/json" \
  -d @exampleescpos.json \
  https://localhost:50002/printjson

Credit: esc html using https://www.freeformatter.com/html-escape.html 

Saturday, June 6, 2026

Java: using thermal printer 6106 - 80mm esc/pos java in debian 13 bluetooth

Install bluetooth software


$ apt install firmware-misc-nonfree bluez bluez-tools blueman screen

linux user groups: bluetooth, lp, netdev, sudo, and plugdev

add linux user to group


# usermod -aG sudo username

check your bluetooth adapter has been recognize by debian


$ lsusb
...
Bus 001 Device 003: ID 0489:e0cd Foxconn / Hon Hai MediaTek Bluetooth Adapter
...

pair your device, if you don't hook it in boot, you need to rebind after boot. 


$ bluetoothctl pair 86:67:7A:1D:C2:E3
Attempting to pair with 86:67:7A:1D:C2:E3
[CHG] Device 86:67:7A:1D:C2:E3 Connected: yes
Failed to pair: org.bluez.Error.AuthenticationFailed

using bluetoothctl to handle bluetooth password


$ bluetoothctl
Agent registered
[bluetoothctl]> agent KeyboardOnly
Agent is already registered
[bluetoothctl]> default-agent
Default agent request successful
[bluetoothctl]> scan on
SetDiscoveryFilter success
Discovery started
[CHG] Controller BC:F4:D4:12:4C:28 Discovering: yes
[NEW] Device 4D:F9:CE:48:C4:1B 4D-F9-CE-48-C4-1B
[NEW] Device 62:FE:E1:08:CD:73 62-FE-E1-08-CD-73
[NEW] Device 6D:AC:09:7B:A7:F3 6D-AC-09-7B-A7-F3
[NEW] Device 86:67:7A:1D:C2:E3 RPP02N
[bluetoothctl]> pair 86:67:7A:1D:C2:E3
Attempting to pair with 86:67:7A:1D:C2:E3
[CHG] Device 86:67:7A:1D:C2:E3 Connected: yes
[CHG] Device 86:67:7A:1D:C2:E3 Bonded: yes
[CHG] Device 86:67:7A:1D:C2:E3 Modalias: usb:v05ACp0239d0644
[CHG] Device 86:67:7A:1D:C2:E3 ServicesResolved: yes
[CHG] Device 86:67:7A:1D:C2:E3 Paired: yes
Pairing successful
[DEL] Device 6D:AC:09:7B:A7:F3 6D-AC-09-7B-A7-F3
[CHG] Device 86:67:7A:1D:C2:E3 ServicesResolved: no
[CHG] Device 86:67:7A:1D:C2:E3 Connected: no
[DEL] Device 4D:F9:CE:48:C4:1B 4D-F9-CE-48-C4-1B
[DEL] Device 62:FE:E1:08:CD:73 62-FE-E1-08-CD-73
[bluetoothctl]> trust 86:67:7A:1D:C2:E3
[CHG] Device 86:67:7A:1D:C2:E3 Trusted: yes
Changing 86:67:7A:1D:C2:E3 trust succeeded

busctl output


$ busctl introspect org.bluez /org/bluez/hci0/dev_86_67_7A_1D_C2_E3
NAME                                TYPE      SIGNATURE RESULT/VALUE                             FLAGS
org.bluez.Device1                   interface -         -                                        -
.CancelPairing                      method    -         -                                        -
.Connect                            method    -         -                                        -
.ConnectProfile                     method    s         -                                        -
.Disconnect                         method    -         -                                        -
.DisconnectProfile                  method    s         -                                        -
.Pair                               method    -         -                                        -
.Adapter                            property  o         "/org/bluez/hci0"                        emits-change
.Address                            property  s         "86:67:7A:1D:C2:E3"                      emits-change
.AddressType                        property  s         "public"                                 emits-change
.AdvertisingData                    property  a{yv}     -                                        emits-change
.AdvertisingFlags                   property  ay        -                                        emits-change
.Alias                              property  s         "RPP02N"                                 emits-change writable
.Appearance                         property  q         -                                        emits-change
.Blocked                            property  b         false                                    emits-change writable
.Bonded                             property  b         true                                     emits-change
.Class                              property  u         263808                                   emits-change
.Connected                          property  b         false                                    emits-change
.Icon                               property  s         "printer"                                emits-change
.LegacyPairing                      property  b         false                                    emits-change
.ManufacturerData                   property  a{qv}     -                                        emits-change
.Modalias                           property  s         "usb:v05ACp0239d0644"                    emits-change
.Name                               property  s         "RPP02N"                                 emits-change
.Paired                             property  b         true                                     emits-change
.RSSI                               property  n         -                                        emits-change
.ServiceData                        property  a{sv}     -                                        emits-change
.ServicesResolved                   property  b         false                                    emits-change
.Sets                               property  a{oa{sv}} -                                        emits-change
.Trusted                            property  b         true                                     emits-change writable
.TxPower                            property  n         -                                        emits-change
.UUIDs                              property  as        7 "00000001-0000-1000-8000-00805f9b34fb… emits-change
.WakeAllowed                        property  b         -                                        emits-change writable
org.freedesktop.DBus.Introspectable interface -         -                                        -
.Introspect                         method    -         s                                        -
org.freedesktop.DBus.Properties     interface -         -                                        -
.Get                                method    ss        v                                        -
.GetAll                             method    s         a{sv}                                    -
.Set                                method    ssv       -                                        -
.PropertiesChanged                  signal    sa{sv}as  -                                        -

bind to rfcomm (sudo), if you don't hook it in boot, you need to rebind after boot. if you already trust the printer, just bind it.


  # rfcomm bind rfcomm0 86:67:7A:1D:C2:E3

or with sudo


  $ sudo  rfcomm bind rfcomm0 86:67:7A:1D:C2:E3

your dev access point


$ ls /dev/ | grep rfcomm
rfcomm0

get your bluetooth device info


$ bluetoothctl info 86:67:7A:1D:C2:E3
Device 86:67:7A:1D:C2:E3 (public)
	Name: RPP02N
	Alias: RPP02N
	Class: 0x00040680 (263808)
	Icon: printer
	Paired: yes
	Bonded: yes
	Trusted: yes
	Blocked: no
	Connected: no
	LegacyPairing: no
	UUID: SDP                       (00000001-0000-1000-8000-00805f9b34fb)
	UUID: RFCOMM                    (00000003-0000-1000-8000-00805f9b34fb)
	UUID: L2CAP                     (00000100-0000-1000-8000-00805f9b34fb)
	UUID: Serial Port               (00001101-0000-1000-8000-00805f9b34fb)
	UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
	UUID: Unknown                   (000018f0-0000-1000-8000-00805f9b34fb)
	UUID: Vendor specific           (e7810a71-73ae-499d-8c15-faa9aef0c3f2)
	Modalias: usb:v05ACp0239d0644

Optional: to let systemd handling pair device

create/edit bluetooth-printer.service (or any name you wish), at /etc/systemd/system/, e.g   /etc/systemd/system/bluetooth-printer.service.


[Unit]
Description=Bind Bluetooth Thermal Printer to rfcomm0
After=bluetooth.service
Requires=bluetooth.service

[Service]
Type=oneshot
ExecStart=/usr/bin/rfcomm bind rfcomm0 86:67:7A:1D:C2:E3
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

After that use systemd to handle pairing

  • sudo systemctl daemon-reload
  • sudo systemctl enable bluetooth-printer.service
  • sudo systemctl start bluetooth-printer.service
  • systemctl status bluetooth-printer.service 

you can try previous code https://dedetoknotes.blogspot.com/2026/06/java-using-thermal-printer-6106-80mm.html by change 

devicePath = "/dev/usb/lp1" 

to

devicePath = "/dev/rfcomm0" 

Credit: https://www.freeformatter.com/html-escape.html#before-output to esc html 

Monday, June 1, 2026

Java: using thermal printer 6106 - 80mm esc/pos java in debian 13 usb

insert your printer using usb cable


# lsusb
...
Bus 008 Device 002: ID 28e9:0289 GDMicroelectronics micro-printer
Bus 009 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
# dmesg
[   70.532011] usb 8-1: new full-speed USB device number 2 using xhci_hcd
[   70.688254] usb 8-1: New USB device found, idVendor=28e9, idProduct=0289, bcdDevice= 2.00
[   70.688270] usb 8-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   70.688276] usb 8-1: Product: micro-printer
[   70.688282] usb 8-1: Manufacturer: GEZHI
[   70.688286] usb 8-1: SerialNumber: 000000000004
[   70.730721] usblp 8-1:1.0: usblp1: USB Bidirectional printer dev 2 if 0 alt 0 proto 2 vid 0x28E9 pid 0x0289
[   70.730783] usbcore: registered new interface driver usblp
use nl80211
# ls -al /dev/usb/
total 0
drwxr-xr-x  2 root root     80 May 31 14:31 .
drwxr-xr-x 20 root root   3840 May 31 14:31 ..
crw-------  1 root root 180, 0 May 31 14:30 hiddev0
crw-rw----  1 root lp   180, 1 May 31 14:31 lp1
# ls -al /dev/usb/lp1
crw-rw---- 1 root lp 180, 1 May 31 14:31 /dev/usb/lp1

we found the device known as usb lp1 i.e. /dev/usb/lp1. test to print something.


# printf '\x1b\x40Hello World\n\n\n' > /dev/usb/lp1

your printer should print "Hello World"

add your account or linux user as lp group 


# usermod -aG lp [username]

you need to sign out and re sign in, then try to print as [username]


$ printf '\x1b\x40Hello World\n\n\n' > /dev/usb/lp1

if everything work, now you can work as [username]. this is simple netbeans 30 - maven, to test your printer.

This is pom.xml for your project.


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.dedetok</groupId>
    <artifactId>EnumComPort</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.release>21</maven.compiler.release>
        <exec.mainClass>com.dedetok.enumcomport.EnumComPort</exec.mainClass>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.fazecast</groupId>
            <artifactId>jSerialComm</artifactId>
            <version>2.11.0</version>
            <type>jar</type>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.5.0</version>

                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>

                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>

                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.dedetok.enumcomport.EnumComPort</mainClass>
                                </transformer>
                            </transformers>

                        </configuration>
                    </execution>
                </executions>

            </plugin>

        </plugins>
    </build>
</project>

This is the java code


package com.dedetok.enumcomport;

import com.fazecast.jSerialComm.SerialPort;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 *
 * @author dedetok
 */
public class EnumComPort {

    public static void main(String[] args) throws IOException {
        System.out.println("Hello World!");
        System.out.println(System.getProperty("user.name"));
        Process p = Runtime.getRuntime().exec("id");
        p.getInputStream().transferTo(System.out);
        
        SerialPort[] ports = SerialPort.getCommPorts();

        if (ports.length == 0) {
            System.out.println("No serial ports detected.");
        }

        System.out.println("Available Serial Ports:");
        System.out.println("------------------------");

        for (SerialPort port : ports) {

            System.out.println("System Port Name : " + port.getSystemPortName());
            System.out.println("Descriptive Name: " + port.getDescriptivePortName());
            System.out.println("Port Description: " + port.getPortDescription());
            System.out.println("System Location : " + port.getSystemPortPath());
            System.out.println("------------------------");
        }
        
        String devicePath = "/dev/usb/lp1";
        // Open file in read-write mode for raw bidirectional access
        RandomAccessFile deviceFile = new RandomAccessFile(devicePath, "rw");
        FileDescriptor fd = deviceFile.getFD();
        
        try (OutputStream out = new FileOutputStream(fd)) {
            // ESC @ (initialize)
            out.write(new byte[]{0x1B, 0x40});

            out.write("Hello World\n".getBytes());

            // Feed
            out.write("\n\n".getBytes());

            // Cut
            out.write(new byte[]{0x1D, 0x56, 0x00});

            out.flush();
            out.close(); // NO NEED
        } catch (FileNotFoundException ex) {
            System.getLogger(EnumComPort.class.getName()).log(System.Logger.Level.ERROR, (String) null, ex);
        }
        System.out.println("End");
    }
}

In my test, you can run inside your netbeans, Run -> Build Project or Run -> Clean and Run Project. to run the jar, you go to project root and run like this


$ java -jar ./target/EnumComPort-1.0.jar 
Hello World!
[username]
uid=1000([username]) gid=1000([username]) groups=1000([username]),7(lp),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),33(www-data),44(video),46(plugdev),100(users),106(netdev),111(bluetooth),113(lpadmin),116(scanner),124(libvirt)
No serial ports detected.
Available Serial Ports:
------------------------
End

your printer should print "Hello World". "No serial ports" means, you can use com.fazecast.jSerialComm library for lp printer.

Credit: https://www.freeformatter.com/html-escape.html for free html escape 

Saturday, May 30, 2026

Java: enumerate com serial using fazecast jSerialComm

Simple code to enumerate serial com port


/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 */

package com.dedetok.enumcomport;

import com.fazecast.jSerialComm.SerialPort;

/**
 *
 * @author dedetok
 */
public class EnumComPort {

    public static void main(String[] args) {
        System.out.println("Hello World!");

        SerialPort[] ports = SerialPort.getCommPorts();

        if (ports.length == 0) {
            System.out.println("No serial ports detected.");
            return;
        }

        System.out.println("Available Serial Ports:");
        System.out.println("------------------------");

        for (SerialPort port : ports) {

            System.out.println("System Port Name : " + port.getSystemPortName());
            System.out.println("Descriptive Name: " + port.getDescriptivePortName());
            System.out.println("Port Description: " + port.getPortDescription());
            System.out.println("System Location : " + port.getSystemPortPath());
            System.out.println("------------------------");
        }
        
    }
}

Note: lpx device (e.g /dev/usb/lp1) does not use serial com, you need to send hex code direct via OutputStream.

Java: Hook shutdown to run java application as systemd

This is minimum java code to hook shutdown


/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 */

package com.dedetok.javaservicetest;

/**
 *
 * @author dedetok
 */
public class JavaServiceTest {

    private static volatile boolean running = true;
        
    public static void main(String[] args) {
        System.out.println("Hello World!");
        
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println("Shutdown hook triggered");

            running = false;

            // Cleanup resources here
            // Close database connections
            // Flush logs
            // Stop worker threads
            // Main shutdown path
            //cleanupResources();

            System.out.println("Cleanup complete");
        }));

        System.out.println("Daemon started");

        while (running) {
            System.out.println("Working...");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException ex) {
                System.getLogger(JavaServiceTest.class.getName()).log(System.Logger.Level.ERROR, (String) null, ex);
            }
        }

    }
}

to run/test this application, you can not run it inside netbeans. use terminal to run it, go to your project root and run


$ java -cp target/classes \
     com.dedetok.javaservicetest.JavaServiceTest
Hello World!
Daemon started
Working...
Working...
^CShutdown hook triggered
Cleanup complete

 

 

Java Netbeans: upgrade binary Netbeans 29 to Netbeans 30

 This step is straight forward:

  1. go to your root directory (e.g your home dir ~/), and rename old folder e.g ~/netbeans29.
  2. extract netbeans 30 binary and put it in root directory to replace old folder (e.g your home dir ~/).
  3. Run your netbeans 30, import previous configuration
  4. if no error found you safe to remove
    1. old netbeans 29 (e.g ~/netbeans29) 
    2. ~/.netbeans/29
    3. ~/.cache/netbeans/29

 

Sunday, May 24, 2026

Java: using maven in Debian 13

Apache Maven is an open-source build automation and project management tool primarily used for Java applications. It simplifies the development process by managing a project's build, reporting, and documentation from a single piece of information.

To install maven:

# apt install maven
Installing:                     
  maven

Installing dependencies:
...

Showing version

$ mvn --version
Apache Maven 3.9.9
Maven home: /usr/share/maven
Java version: 21.0.11, vendor: Debian, runtime: /usr/lib/jvm/java-21-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.12.88+deb13-amd64", arch: "amd64", family: "unix"

Go to your workspace, and run

$ mvn archetype:generate \
  -DgroupId=com.dedetok.myapp \
  -DartifactId=myapp \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DarchetypeVersion=1.5 \
  -DinteractiveMode=false
...
$ ls myapp
pom.xml  src

DartifactId=myapp -> project root directory.

The main java code is ~/myapp/src/main/java/com/dedetok/myapp/App.java

package com.dedetok.myapp;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

To run the project using mvn, go to folder myapp, edit pom.xml


<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
         https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.dedetok</groupId>
    <artifactId>myapp</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.6.3</version>
                <configuration>
                    <mainClass>com.dedetok.myapp.App</mainClass>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.4.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.dedetok.myapp.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>

then run:

$ mvn package

Run your application 


$ mvn exec:java -Dexec.mainClass="com.dedetok.myapp.App"
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.dedetok:myap >--------------------------
[INFO] Building myap 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- exec:3.6.3:java (default-cli) @ myap ---
Hello World!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.265 s
[INFO] Finished at: 2026-05-24T14:59:08+07:00
[INFO] -----------------------------------------

or

$ mvn exec:java
[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------------< com.dedetok:myapp >--------------------------
[INFO] Building myapp 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- exec:3.6.3:java (default-cli) @ myapp ---
Hello World!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.712 s
[INFO] Finished at: 2026-05-25T14:43:48+07:00
[INFO] ------------------------------------------------------------------------

To use old school java, copy library needed

$ mvn dependency:copy-dependencies

run using java


$ mvn compile
$ java -cp "target/classes:target/dependency/*" com.dedetok.myapp.App
Hello World!

 

 

 

Tuesday, May 19, 2026

Debian 13: configurating Syris RD200-M1-G v01.55 Card Reader Part 2, detecting card reader in Debian

Add you as group of dialout (20)


# usermod -aG dialout myuser
# usermod -aG uucp myuser
# usermod -aG lock myuser
# usermod -aG tty myuser

Note: 

  1. All of these groups may not exist on every Linux distro. (Note, this process must only be done once for each user)
  2. if you use terminal only, this will effect directly, but if you use window Manager, you require to logout and re-login to make it effect especially on Netbeans, If aftar re-login fail, try restart.  

Confirm which com the reader assign


# ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 May 19 13:43 /dev/ttyACM0

The card reader assign com at /dev/ttyACM0

This is simple java code to read card when tap on device


import com.fazecast.jSerialComm.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;

/**
 *
 * @author dedetok
 */
public class DedetokSerialCom {

    static private SerialPort serialPort;
    static private int boudRate = 115200;
            
    public static void main(String[] args) {
        System.out.println("Hello World!");
        
        serialPort = SerialPort.getCommPort("/dev/ttyACM0");
        
        // Configure serial port
        serialPort.setBaudRate(boudRate);
        serialPort.setNumDataBits(8);
        serialPort.setNumStopBits(SerialPort.ONE_STOP_BIT);
        serialPort.setParity(SerialPort.NO_PARITY);
        
        // Optional timeouts
        serialPort.setComPortTimeouts(
                SerialPort.TIMEOUT_READ_SEMI_BLOCKING,
                1000,
                0
        );
        
        
        // Open port
        if (!serialPort.openPort()) {
            System.out.println("Failed to open port");
            return;
        }
        
        System.out.println("Port opened"); // debug
                
        // ------------------read mifare id card ----------------------
        System.out.println("MIFARE"); // debug
        // STX LEN CMD
        byte[] cmd = new byte[] {
                (byte)0x02, // STX
                (byte)0x01, // LEN
                (byte)0x11  // CMD Read UID
        };
        
        // Send
        serialPort.writeBytes(cmd, cmd.length);

        System.out.println("command Send"); // debug
        
        /*
        02 02 11 10 : command error
        02 02 11 01 : no card
        02 06 11 00 xx xx xx xx : mifare id xx xx xx xx
        */

        byte[] rx = new byte[64];

        int n = serialPort.readBytes(rx, rx.length);

        System.out.println("Received bytes: " + n);

                // Print raw HEX
        for (int i = 0; i < n; i++) {
            System.out.printf("%02X ", rx[i]);
        }
        System.out.println();

        // ------------------read ISO15693 inventory card ----------------------
        // NOT SUPPORTED


        System.out.println();

        serialPort.closePort();

        
        System.out.println("Port Closed"); // debug
    }
}

This is sample output with uid masked Netbeans


Hello World!
Port opened
MIFARE
command Send
Received bytes: 8
02 06 xx xx xx xx xx 52 

What are they?

02 STX
06 LENGTH
Data 1-5 xx xx xx xx xx
Checksum 52 

e.g. to read Mifare UID (0x11)

command in bytes: 02 01 11

02: run command

01: length

11: command to read Mifare UID

10 checksum ( 01 xor 11 )

if return 4 bytes: MIFARE Classic 1K/4K

if return 7 bytes: NTAG / Ultralight / DESFire

if return 8 bytes: ISO15693

Example response 4 bytes UID (classic mifare)


02 06 01 xx xx xx xx 8E 
 |  |  |  |           |
 |  |  |  |           -> checksum
 |  |  |  -------------> data uid
 |  |  ----------------> status 
 |  -------------------> length data
 ----------------------> STX

Example response 6 bytes UID


02 0A 11 00 xx xx xx xx xx xx 80 00
 |  |  |  |                    |  |
 |  |  |  |                    |  -> SAK
 |  |  |  |                    ----> checksum
 |  |  |  -------------------------> data uid
 |  |  ----------------------------> status
 |  -------------------------------> length data
 ----------------------------------> STX