Skip to content

Commit 009661b

Browse files
committed
feat: implement legacy CGI redirects and enhance query API functionality
1 parent 84a9f60 commit 009661b

14 files changed

Lines changed: 247 additions & 19 deletions

File tree

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ produce them. The build runs `yarn generate` first, which:
9090

9191
- converts the upstream `foomatic-db` data into JSON and statically generates a page for every
9292
printer and driver (output under `public/foomatic-db/`),
93+
- generates the machine-readable query API and PPD files (output under `public/query/` and
94+
`public/ppds/`; see [Machine-readable query API](#machine-readable-query-api-and-ppd-downloads)),
9395
- builds the client-side search indexes (`public/search/static-index.json` and
9496
`public/search/foomatic-index.json`), and
9597
- generates the RSS feed (`public/feed.xml`).
@@ -105,6 +107,53 @@ yarn generate
105107
at least once. These outputs are git-ignored and regenerated on every build (see
106108
[Deployment](#deployment)), so you do not commit them.
107109

110+
## Machine-readable query API and PPD downloads
111+
112+
The legacy OpenPrinting site exposed two machine interfaces: `query.php` (database lookups)
113+
and `ppd-o-matic.php` (PPD downloads). The site is now a **fully static export hosted on
114+
GitHub Pages** — there is no PHP/CGI or any other server-side code. This has one hard
115+
consequence worth understanding:
116+
117+
> A static host serves the **same file for a URL regardless of its query string**. So
118+
> `query.php?type=printer&make=HP` and `query.php?type=printer&make=Canon` are the *same*
119+
> request as far as the host is concerned. The legacy `*.php?…` pages therefore resolve the
120+
> query **in the browser with JavaScript** and work when opened in a browser, but a client
121+
> that does not run JavaScript (`wget`, `curl`, and printer-setup tools such as CUPS or the
122+
> GNOME Control Center) cannot get query-dependent output from them.
123+
124+
For all non-browser/automation use, fetch the **static endpoints** below directly. They are
125+
plain files, so they work with `wget`/`curl` and any HTTP client, and they carry the correct
126+
content type. Append `.xml` instead of `.txt` for XML; the PPD files are served as
127+
`application/vnd.cups-ppd`.
128+
129+
| Legacy URL (browser only) | Static endpoint (works everywhere) |
130+
| --- | --- |
131+
| `query.php?type=makes` | `/query/makes.txt` |
132+
| `query.php?type=printer` | `/query/printers.txt` |
133+
| `query.php?type=printer&make=HP` | `/query/printers/HP.txt` |
134+
| `query.php?type=driver` | `/query/drivers.txt` |
135+
| `query.php?type=driver&printer=printer/HP-LaserJet_4050`<br>`query.php?type=driver&make=HP&model=HP-LaserJet_4050` | `/query/drivers/HP-LaserJet_4050.txt` |
136+
| `ppd-o-matic.php?printer=Alps-MD-2010&driver=ppmtomd` | `/ppds/Alps-MD-2010-ppmtomd.ppd` |
137+
138+
The driver lists are keyed by **printer id** (`<make>-<model>` with spaces as underscores,
139+
e.g. `HP-LaserJet_4050`), and PPD files are named `<printer-id>-<driver>.ppd`. A machine-
140+
readable index of all printers (id, make, model, command sets) is at `/query/index.json`.
141+
142+
Example:
143+
144+
```bash
145+
wget -O HP.txt 'https://openprinting.github.io/query/printers/HP.txt'
146+
wget -O 4050.txt 'https://openprinting.github.io/query/drivers/HP-LaserJet_4050.txt'
147+
wget -O printer.ppd 'https://openprinting.github.io/ppds/Alps-MD-2010-ppmtomd.ppd'
148+
```
149+
150+
Two original `query.php` features have **no static equivalent** because they require
151+
computation at request time and cannot be precomputed into files:
152+
153+
- **Fuzzy device-ID matching** (`printer=MFG:…;MDL:…;`) — works in the browser only.
154+
- **`papps=true`** (the Printer-Application look-up) — depended on live Printer Application
155+
Snaps running on the old server; it is not part of the static database export.
156+
108157
## A note on `yarn.lock`
109158

110159
Installing dependencies or building can modify `yarn.lock` (for instance when the system's

app/foomatic/download.cgi/page.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Suspense } from "react"
2+
3+
import LoadingScreen from "@/components/foomatic/LoadingScreen"
4+
5+
import LegacyCgiRedirect from "@/components/foomatic/LegacyCgiRedirect"
6+
7+
export default function LegacydownloadCgiPage() {
8+
return (
9+
<Suspense fallback={<LoadingScreen />}>
10+
<LegacyCgiRedirect endpoint="download" />
11+
</Suspense>
12+
)
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Suspense } from "react"
2+
3+
import LoadingScreen from "@/components/foomatic/LoadingScreen"
4+
5+
import LegacyCgiRedirect from "@/components/foomatic/LegacyCgiRedirect"
6+
7+
export default function Legacydriver_listCgiPage() {
8+
return (
9+
<Suspense fallback={<LoadingScreen />}>
10+
<LegacyCgiRedirect endpoint="driver_list" />
11+
</Suspense>
12+
)
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Suspense } from "react"
2+
3+
import LoadingScreen from "@/components/foomatic/LoadingScreen"
4+
5+
import LegacyCgiRedirect from "@/components/foomatic/LegacyCgiRedirect"
6+
7+
export default function LegacyexecutionCgiPage() {
8+
return (
9+
<Suspense fallback={<LoadingScreen />}>
10+
<LegacyCgiRedirect endpoint="execution" />
11+
</Suspense>
12+
)
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Suspense } from "react"
2+
3+
import LoadingScreen from "@/components/foomatic/LoadingScreen"
4+
5+
import LegacyPpdMaticRedirect from "@/components/foomatic/LegacyPpdMaticRedirect"
6+
7+
export default function LegacyPpdMaticEntryPage() {
8+
return (
9+
<Suspense fallback={<LoadingScreen />}>
10+
<LegacyPpdMaticRedirect />
11+
</Suspense>
12+
)
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Suspense } from "react"
2+
3+
import LoadingScreen from "@/components/foomatic/LoadingScreen"
4+
5+
import LegacyCgiRedirect from "@/components/foomatic/LegacyCgiRedirect"
6+
7+
export default function Legacyprinter_listCgiPage() {
8+
return (
9+
<Suspense fallback={<LoadingScreen />}>
10+
<LegacyCgiRedirect endpoint="printer_list" />
11+
</Suspense>
12+
)
13+
}

app/foomatic/query.cgi/page.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Suspense } from "react"
2+
3+
import LoadingScreen from "@/components/foomatic/LoadingScreen"
4+
5+
import QueryApiClient from "@/components/foomatic/QueryApiClient"
6+
7+
export default function QueryApiPage() {
8+
return (
9+
<Suspense fallback={<LoadingScreen />}>
10+
<QueryApiClient />
11+
</Suspense>
12+
)
13+
}

app/foomatic/query.php/page.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Suspense } from "react"
2+
3+
import LoadingScreen from "@/components/foomatic/LoadingScreen"
4+
5+
import QueryApiClient from "@/components/foomatic/QueryApiClient"
6+
7+
export default function QueryApiPage() {
8+
return (
9+
<Suspense fallback={<LoadingScreen />}>
10+
<QueryApiClient />
11+
</Suspense>
12+
)
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Suspense } from "react"
2+
3+
import LoadingScreen from "@/components/foomatic/LoadingScreen"
4+
5+
import LegacyCgiRedirect from "@/components/foomatic/LegacyCgiRedirect"
6+
7+
export default function Legacyshow_driverCgiPage() {
8+
return (
9+
<Suspense fallback={<LoadingScreen />}>
10+
<LegacyCgiRedirect endpoint="show_driver" />
11+
</Suspense>
12+
)
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Suspense } from "react"
2+
3+
import LoadingScreen from "@/components/foomatic/LoadingScreen"
4+
5+
import LegacyCgiRedirect from "@/components/foomatic/LegacyCgiRedirect"
6+
7+
export default function Legacyshow_licenseCgiPage() {
8+
return (
9+
<Suspense fallback={<LoadingScreen />}>
10+
<LegacyCgiRedirect endpoint="show_license" />
11+
</Suspense>
12+
)
13+
}

0 commit comments

Comments
 (0)