Log In  
Follow
PyroChiliarch

asdfasdf
<a href="url">link text</a>
Insert about here


Cart #pproxy-0 | 2024-03-28 | Embed ▽ | License: CC4-BY-NC-SA
7

pProxy, the first and only webproxy for Picotron!

This is the first release, so its still very much a work in progress, so far you can...

  • Perform with requests with URLs over 256 Characters (fetch() is limited to 256 chars)
  • Do GET, POST, HEAD, PUT, PATCH, DELETE, CONNECT, OPTIONS and TRACE requests
  • Get more than just the body from your requests including status codes and headers
  • Store cookies in a reusable client

For ideas, bugs, or help, contact me on the Picotron discord
https://discord.gg/XQStcpPeH4

Public Proxy List:

http pproxy.pyrochiliarch.com 8080

To install (For Users):

If you are trying to run a project that relies on pProxy, follow these instructions.
Details for devs are further down.

1) Load the installer with load #pproxy and run it ctrl+r to install

2) Configure which proxy server to use with pProxy config http pproxy.pyrochiliarch.com 8080

3) Use pProxy test to check you connection, it should print the server version

Getting Started (For Devs):

The #pproxy cartridge is an installer, load it load #pproxy and run it ctrl+r to install

Once installed, configure the pProxy library to point to your proxy server using the pProxy command
Use the following settings to use a public server pProxy config http pproxy.pyrochiliarch.com 8080

You may want to setup your own server, which can help with development.
https://github.com/PyroChiliarch/pProxy
Instructions to setup are in the github readme

pProxy test will check your configuration settings
pProxy help will print additional commands

Write a script
There are 4 main steps
1) Make a proxy newProxy()
2) Make a client newHttpClient()
3) Craft a request newRequest("get", "http://www.google.com";, "")
4) Make the request doRequest(client, request)

A simple script would look like this
Note: the proxy and client should be reused

include("/appdata/system/lib/dynInclude.lua")
dynInclude("pProxy")
dynInclude("tabUtil")

local function handleErr(err)
	if not (err==nil) then
		print("Error: ".. err)
		pause("space")
		exit(1)
	end
end

-- 1 Make new proxy
proxy = pProxy:newProxy()

-- 2 Make new client
client, err = proxy:newHttpClient()
handleErr(err)

-- 3 Craft a request
request = proxy:newRequest("post", "http://httpbin.org/anything", "This is the body contents")

-- 4 Make the request
data, err = proxy:doRequest(client, request)
handleErr(err)

print("Printing the response to the console:\n" .. tabUtil.toString(data))

<br><br>
The example below performs multiple different example request that should help
you understand how pProxy is used.
Near the end of this post is documentation on functions

include("/appdata/system/lib/dynInclude.lua")
dynInclude("pProxy")
dynInclude("tabUtil")

local function handleErr(err)
	if not (err==nil) then
		print("Error: ".. err)
		pause("space")
		exit(1)
	end
end

--==========================--
--     Reused Values   	  --
--==========================--

-- proxy is used in all requests
-- the client is only used in Advanced requests

-- Make new proxy
proxy = pProxy:newProxy()

-- Make new client
client, err = proxy:newHttpClient()
handleErr(err)

--==========================--
--     Test connection		  --
--==========================--
print("=================================")
print("Testing connection to proxy")
ver, err = proxy:getVersion()
handleErr(err)
print("Connected to proxy version " .. ver)

--==========================--
--     Simple Get	  --
--==========================--
print("\n\n=================================")
print("Basic get request, like fetch but through proxy")
body, err = proxy:simpleGet("http://httpbin.org/robots.txt")
handleErr(err)
print("Get request result:\n" .. body)

--==========================--
--    Get with basic auth   --
--==========================--
print("\n\n=================================")
print("Perform basic auth")
-- Perform a get request with headers for basic auth

-- Build new request
request = proxy:newRequest("get", "http://httpbin.org/basic-auth/%41%6C%61%64%64%69%6E/%6F%70%65%6E%20%73%65%73%61%6D%65", "")

-- Add basic auth header
username = "Aladdin"
password = "open sesame"
auth = ("Basic " .. basexx.to_base64(username .. ":" .. password))
request.addHeader("Authorization", auth)

-- Do the request through the proxy
data, err = proxy:doRequest(client, request)
handleErr(err)

-- Get the result
print("Username: " .. username)
print("Password: " .. password)
print("Basic auth result:\n" .. data.status)

--==========================--
--     Post request	         --
--==========================--
print("\n\n=================================")
print("Do a post request and print the returned response")
request = proxy:newRequest("post", "http://httpbin.org/anything", "This is the body contents")
data, err = proxy:doRequest(client, request)
handleErr(err)

print("Post request, full results:\n" .. tabUtil.toString(data))

--==========================--
--     Get Cookies          --
--==========================--
print("\n\n=================================")
print("Make a request to get some cookies in our clients cookie jar,\nthen get the cookies from the client")

request = proxy:newRequest("get", "http://httpbin.org/cookies/set?myFirstCookie=chocolateChip&visitedPage=True", "")
data, err = proxy:doRequest(client, request)
handleErr(err)
print("response headers when getting some cookies:\n" .. tabUtil.toString(data.headers))

print("\nGetting cookies from the our client")
data, err = proxy:getCookies(client, "http://httpbin.org/")
handleErr(err)

print("Here are the cookies:\n" .. tabUtil.toString(data))

Extra details:

Whats installed:
The pProxy.lua library is installed to /appdata/system/lib/pProxy.lua
The dynInclude.lua library is installed to /appdata/system/lib/dynInclude.lua
The pProxy.lua command line configuration utility is installed to /appdata/system/lib/dynInclude.lua

Functions:
Format: (return) function (parameters)

(proxy table, error string) pProxy:newProxy()
Create a new proxy table, reuse this table with all other commands

(client string, error string) pProxy:newHttpClient()
Returns a UUID representing the client object on the proxy

(version string, error string) pProxy:getVersion()
Get the version of the current proxy

(response string) pProxy:simpleGet(url string)
Perform a simple get request through the proxy, very similar to fetch()

(request table) pProxy:newRequest(method string, url string, body string)
Crafts a new request, method supports the following values:
"GET", "POST", "HEAD", "PUT", "PATCH", "DELETE", "CONNECT", "OPTIONS" and "TRACE'

() request.addHeader(name string, value string)
Add a new header to your request
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers

(response table, error string) pProxy:doRequest (client string, request table)
Provide a client id string and a crafted request to the proxy, returns the response in a table

(cookies table) pProxy:getCookies(client string, url string)
Returns a table containing the cookies from the specified client, filtered by the host in the url
"https://www.google.com" will filter all cookies matching "www.google.com"
7
1 comment



Cart #tabutil-0 | 2024-03-28 | Embed ▽ | No License
1

tabUtil.lua library for use with Picotron
Contains useful functions for working with tables

Install with load #base64 and run it with crtl+r
A new file will be created /appdata/system/lib/tabUtil.lua

I personally love to use tabUtil.toString(#Table), its handy for debugging

Contains 3 functions, Usage Below

include("/appdata/system/lib/tabUtil.lua")

myTable = {
	name="Microsoft",
	employees={"Bill Gates", "Some Dude"},
	myFunction=function () print("Im a function") end,
}

meSecondTable = tabUtil.shallowCopy(myTable)
myTable = {}

print(tabUtil.getKeyCount(meSecondTable))
print(tabUtil.toString(meSecondTable))

This prints out the following

[ Continue Reading.. ]

1
0 comments



Cart #json-1 | 2024-03-25 | Embed ▽ | No License
6

To install library, use load #json then ctrl+r
Library will be installed at /appdata/system/lib/json.lua

(Slightly) Modified version of https://github.com/rxi/json.lua

Example:

include("/appdata/system/lib/json.lua")

--Make something to encode
obj = {
	a = "hello",
	b = "world",
	c = 1234
}

-- Encode json
encoded = json.encode(obj)
print(encoded)

-- Decode json
decoded = json.decode(encoded)
print(decoded.a)
6
0 comments



Cart #dyninclude-3 | 2024-03-28 | Embed ▽ | License: CC4-BY-NC-SA
3

Script to dynamically include libraries, use dynInclude() instead of include()
You only need to specify the library name and it will be auto downloaded and installed if not currently installed then included automatically.

A simple and easy way to include libraries in your cart without the hassle.

Will try to load libaries from the following locations in this order:
1 - ./lib
2 - /appdata/system/lib
3 - /system/lib
4 - The BBS system (Will attempt to download and install the library to /appdata/system/lib

Usage:
The below code will include the basexx library, automatically downloading and installing it if necessary

include("./dynInclude.lua")

[ [size=16][color=#ffaabb] [ Continue Reading.. ] [/color][/size] ](/bbs/?pid=144273#p)
3
0 comments



The bug this cart fixes was patched in v0.1.0c, no longer needed unless you still use an old version

Use?
load #patch_load and press ctrl+r
This only needs to be done once and is persistent over reboots

Why?
There is currently a bug where you can only load #<cart> once per reboot
This is because of a typo on line 27 that doesn't properly delete the current cart
Patching isn't as simple as fixing the line as /system will refresh itself on every reboot
Run this cart to permanently fix this bug (Persistent over reboots)

How?
When run, store a patched load.lua in /appdata/system/util and append some lines to startup.lua
that will copy this patched load.lua to the /system/util folder on each reboot

Will it overwrite my startup.lua?
This cart will append to /appdata/system/startup.lua, so your current startup config will still work.

Src?
https://github.com/PyroChiliarch/picoPatchLoad

Versions:

version 1: main.lua was empty, fixed it.

[ Continue Reading.. ]

2
0 comments



Cart #new-1 | 2024-03-25 | Embed ▽ | License: CC4-BY-NC-SA
5

What are you doing to clear /ram/cart at the moment?
Deleting files manually?
Rebooting Picotron?

Try using the brand new fancy empty cart!
Simply type load #new to clear out /ram/cart

That's it!

5
1 comment



Cart #basexx-1 | 2024-03-25 | Embed ▽ | No License
1


basexx.lua library for use with Picotron, (very) slightly modified version of https://github.com/aiq/basexx/blob/master/lib/basexx.lua

Install from BBS with load load #basexx and run it with crtl+r

A file will be created at /appdata/system/lib/basexx.lua

Usage:

include("/appdata/system/lib/basexx.lua")

string = "hello world"
print("Raw: " .. string)
print("Bit (Base2)" .. basexx.to_bit(string))
print("Hex (Base16) " .. basexx.to_hex(string))
print("Base32 " .. basexx.to_base32(string))
print("Base64 " .. basexx.to_base64(string))
print("Crockford " .. basexx.to_crockford(string))

[ [size=16][color=#ffaabb] [ Continue Reading.. ] [/color][/size] ](/bbs/?pid=144252#p)
1
0 comments



Cart #base64-2 | 2024-03-25 | Embed ▽ | No License
6

base64.lua library for use with Picotron, (very) slightly modified version of https://github.com/iskolbin/lbase64

Install with load #base64 and run it with crtl+r
A new file will be created /appdata/system/lib/base64.lua

Basic usage:

include("/appdata/system/lib/base64.lua")
print("Plain: abcdefg")
print("Base64: " .. base64.encode("abcdefg"))

Basic functions:

base64.encode(string)
base64.decode(string)

Visit https://github.com/iskolbin/lbase64 for advanced usage

Source: https://github.com/PyroChiliarch/picoBase64

dynInclude compatible: https://www.lexaloffle.com/bbs/?tid=141042

6
0 comments