{"id":21977237,"url":"https://github.com/eja/eja","last_synced_at":"2025-08-02T23:06:36.605Z","repository":{"id":70307830,"uuid":"15112980","full_name":"eja/eja","owner":"eja","description":"eja micro web server","archived":false,"fork":false,"pushed_at":"2025-04-19T17:03:17.000Z","size":1107,"stargazers_count":16,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-19T19:30:16.988Z","etag":null,"topics":["eja","http","json","lua","micro","server","sql"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eja.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-12-11T16:45:00.000Z","updated_at":"2025-04-19T17:03:35.000Z","dependencies_parsed_at":"2025-04-19T17:25:01.467Z","dependency_job_id":"29e794d6-927e-4fb7-a37e-baded8e58f4c","html_url":"https://github.com/eja/eja","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eja%2Feja","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eja%2Feja/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eja%2Feja/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eja%2Feja/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eja","download_url":"https://codeload.github.com/eja/eja/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251347730,"owners_count":21575135,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eja","http","json","lua","micro","server","sql"],"created_at":"2024-11-29T16:14:02.733Z","updated_at":"2025-04-28T16:42:38.759Z","avatar_url":"https://github.com/eja.png","language":"C","readme":"\n# eja - Micro Web Server and Lua Toolkit\n\n`eja` is a versatile command-line tool primarily designed as a lightweight web server for static and dynamic content. It also functions as a text scanner utility (similar to `awk` but using Lua patterns) and a standalone Lua 5.2 interpreter with extended functionalities baked in.\n\nOriginally available for Debian/Linux, `eja` has now been updated and ported to other Unix-like operating systems, including macOS (Darwin). It achieves its functionality through a combination of C code for core system interactions (such as process management, sockets, and file system operations) and a rich set of embedded Lua libraries for higher-level tasks.\n\n## Features\n\n*   **Micro Web Server:**\n    *   Serves static files.\n    *   Handles dynamic content through `.lua` or pre-compiled `.eja` scripts.\n    *   Configurable host, port, web root path, and buffer size.\n    *   Optional directory listing.\n    *   Background daemon mode (`--web-start`, `--web-stop`).\n    *   Simple time-based hash authentication mechanism (`ejaWebAuth`).\n    *   User management helper (`--web-user`).\n*   **Text Scanner:**\n    *   Processes text streams (stdin or file) line by line or based on custom record separators.\n    *   Uses Lua patterns for field separation (default: `%S+`).\n    *   Executes Lua scripts for each record, providing the full row (`R`) and matched fields (`F`).\n*   **Lua Interpreter:**\n    *   Runs Lua 5.2 scripts.\n    *   Includes an interactive shell (`--shell`).\n    *   Can execute `.eja` portable bytecode files.\n    *   Exports Lua scripts to `.eja` bytecode (`--export`).\n*   **Extended Functionality (via C bindings \u0026 embedded Lua libs):**\n    *   **System Interaction:** Process creation, killing, sleeping (fork, kill, sleep), PID retrieval, cleaning up child processes, file stats (stat), directory listing and creation.\n    *   **Networking:** Low-level TCP/UDP socket operations (create, bind, connect, listen, accept, read, write, options), DNS lookups (getaddrinfo). Includes helper functions for HTTP GET/POST (ejaWebGet, ejaJsonPost).\n    *   **Simple Database:** File-based key-value store (`ejaDb*` functions).\n    *   **Data Handling:** JSON encoding/decoding, Base64 encoding/decoding, struct packing/unpacking.\n    *   **Encryption \u0026 Hashing:** AES encryption/decryption, SHA1, SHA256.\n    *   **MariaDB/MySQL Client:** Embedded client for database interactions.\n    *   **Utilities:** MIME type detection, TAR file extraction, logging framework, table manipulation helpers, string formatting.\n    *   **Library Management:** Simple update/install/remove mechanism for `.eja` libraries (`--update`, `--install`, `--remove`).\n    *   **System Setup:** Helper command (`--setup`) to create default directories and configuration files (including a basic systemd service file).\n\n## Installation\n\n1.  **Clone the repository:**\n    ```bash\n    git clone https://github.com/eja/eja.git\n    cd eja\n    ```\n2.  **Compile:**\n    ```bash\n    make\n    ```\n    For a statically linked binary (if supported by your toolchain):\n    ```bash\n    make static\n    ```\n3.  **Install (optional):**\n    By default, this installs to `/usr/local`. You might need `sudo`.\n    ```bash\n    sudo make install\n    ```\n    This will install the `eja` binary to `/usr/local/bin` and the man page to `/usr/local/share/man/man1`.\n\n## Usage\n\nThe basic syntax is:\n\n```bash\neja [SCRIPT] [OPTION]...\n```\n\nFor a full list of options, see the man page:\n\n```bash\nman eja\n```\nOr display help in the terminal:\n```bash\neja --help       # Basic help\neja --help full  # Full help including library options\n```\n\n### General Examples\n\n*   **Run a Lua script:**\n    ```bash\n    eja myscript.lua\n    ```\n*   **Run an eja bytecode script:**\n    ```bash\n    eja mybytecode.eja\n    ```\n*   **Use as a text scanner:**\n   \n    print second word of each line:\n    ```bash\n    cat somefile.txt | eja --scan 'print(F[2])'\n    ```\n    \n    print lines matching \"ERROR\":\n    ```bash\n    cat somefile.txt | eja --scan \"/ERROR/\"\n    ```\n*   **Start the interactive Lua shell:**\n    ```bash\n    eja --shell\n    ```\n*   **Export a Lua script to bytecode:**\n    ```bash\n    eja --export myscript.lua --export-name mybytecode\n    # Creates mybytecode.eja\n    ```\n*   **Update eja or an eja library:**\n    ```bash\n    eja --update             # Updates eja itself\n    eja --update mylibrary   # Updates mylibrary.eja from update.eja.it or GitHub\n    ```\n\n### Web Server Functionality\n\n`eja` makes it simple to run a local web server for various purposes.\n\n**1. Directory Listing:**\n\nTo quickly share or browse files in a directory via HTTP, enable directory listing:\n\n```bash\n# Navigate to the directory you want to serve\ncd ~/my_shared_files\n\n# Start eja, enabling directory listing on the default port (35248)\neja --web\n```\n\nNow, open your web browser and go to `http://localhost:35248`. You will see a list of files and subdirectories within `~/my_shared_files`. Clicking a file will download it, and clicking a directory will navigate into it.\n\n**2. Static HTML/Website Testing:**\n\nIf you are developing a simple website (HTML, CSS, JavaScript, images), you can use `eja` as a local test server:\n\n```bash\n# Assume your website files are in ~/projects/my_website\n# with index.html at the root\ncd ~/projects/my_website\n\n# Start eja in the project directory\neja --web --web-port 8000 # Use port 8000 instead of the default\n```\n\n*   Access the site at `http://localhost:8000`.\n*   `eja` will automatically serve `index.html` if it exists in the current directory (`~/projects/my_website`).\n*   It will also serve other files like `style.css` if your HTML references them with relative paths (e.g., `\u003clink rel=\"stylesheet\" href=\"style.css\"\u003e`).\n\n**3. Dynamic Content (Simple URL Sum):**\n\n`eja` can execute Lua scripts (`.lua` or compiled `.eja`) to generate dynamic responses. The script receives a `web` object containing request details and can modify it to set the response.\n\n*   **Create the script (`sum.lua`):** Save the following code in a file named `sum.lua`:\n\n    ```lua\n    -- sum.lua\n    -- The 'web' object is implicitly passed as the first argument\n    web = ... \n\n    -- Get query parameters 'a' and 'b' from the URL\n    -- web.opt contains decoded query parameters\n    local a = tonumber(web.opt.a) or 0\n    local b = tonumber(web.opt.b) or 0\n    local result = a + b\n\n    -- Set the response content type and data\n    web.headerOut['Content-Type'] = 'text/plain'\n    web.data = string.format(\"The sum of %s and %s is: %s\", a, b, result)\n\n    -- No need to explicitly return the web object, modifying it is sufficient.\n    ```\n\n*   **Run the server:** Navigate to the directory containing `sum.lua` and start `eja`:\n\n    ```bash\n    cd /path/to/directory/containing/script\n    eja --web\n    ```\n\n*   **Access the dynamic endpoint:** Open your browser or use `curl`:\n\n    ```bash\n    curl \"http://localhost:35248/sum.lua?a=15\u0026b=27\" \n    ```\n\n    This will output:\n    ```\n    The sum of 15 and 27 is: 42\n    ```\n\n    You can change the values of `a` and `b` in the URL to get different results. If parameters are missing, they default to 0.\n\n**4. Daemon Control:**\n\n*   **Start the web server as a background daemon (using defaults or config):**\n    ```bash\n    eja --web-start\n    ```\n*   **Stop the web server running on the default port (35248):**\n    ```bash\n    eja --web-stop\n    ```\n*   **Stop the web server running on port 8080:**\n    ```bash\n    eja --web-stop 8080\n    ```\n\n## Configuration\n\n*   **Compile-time Paths:** Default paths for libraries, configuration, logs, etc., can be set during compilation via CFLAGS in the `Makefile` (e.g., `make CFLAGS=\"-DEJA_PATH_ETC=/etc/eja\" install`).\n*   **Runtime Configuration:** The `--init` option loads `/etc/eja/eja.init` (by default). This Lua file can set `eja.opt` values to configure behavior, commonly used for the daemon started via `--web-start` or a system service.\n*   **System Setup:** The `eja --setup` command helps create default directories (`/var/eja/web`, `/var/lock`, `/tmp`, etc.) and a basic `/etc/eja/eja.init` file, along with a sample systemd service unit.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feja%2Feja","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feja%2Feja","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feja%2Feja/lists"}