Gratefuls_Actual_ GRU file
put description what kind of problem does the solution solve and how
«$ Databanks»
<cgiirc.config>
and <cgiirc.config.full>
«-o client.cgi client.c>
This shouldn't print any errors, and you should have a client.cgi program, if you try typing <./client.cgi>
Codename: GRATEFUL
Object Class: MAKSUR
Containment Protocols: $ cargo new docs —lib
$ cd docs
sample code. Delete it and replace it with this:
/// foo is a function
fn foo() {}
Let's run rustdoc on our code. To do so, we can call it with the path to our crate root like this:
$ rustdoc src/lib.rs
This will create a new directory, doc, with a website inside! In our case, the main page is located in doc/lib/index.html. If you open that up in a web browser, you will see a page with a search bar, and "Crate lib" at the top, with no contents.
You can also use cargo doc to generate documentation for the whole project. See Using rustdoc with Cargo.
Configuring rustdoc
There are two problems with this: first, why does it think that our crate is named "lib"? Second, why does it not have any contents?
The first problem is due to rustdoc trying to be helpful; like rustc, it assumes that our crate's name is the name of the file for the crate root. To fix this, we can pass in a command-line flag:
$ rustdoc src/lib.rs —crate-name docs
Now, doc/docs/index.html will be generated, and the page says "Crate docs."
For the second issue, it is because our function foo is not public; rustdoc defaults to generating documentation for only public functions. If we change our code…
/// foo is a function
pub fn foo() {}
… and then re-run rustdoc:
$ rustdoc src/lib.rs —crate-name docs
We now have some generated documentation. Open up doc/docs/index.html and check it out! It should show a link to the foo function's page, which is located at doc/docs/fn.foo.html. On that page, you'll see the "foo is a function" we put inside the documentation comment in our crate.
Using rustdoc with Cargo
Cargo also has integration with rustdoc to make it easier to generate docs. Instead of the rustdoc command, we could have done this:
$ cargo doc
If you want cargo to automatically open the generated documentation, you can use:
$ cargo doc —open
Internally, cargo doc calls out to rustdoc like this:
$ rustdoc —crate-name docs src/lib.rs -o <path>/docs/target/doc -L
dependency=<path>/docs/target/debug/deps
You can see this with cargo doc —verbose.
It generates the correct —crate-name for us, as well as pointing to src/lib.rs. But what about those other arguments?
-o controls the output of our docs. Instead of a top-level doc directory, notice that Cargo puts generated documentation under target
#![allow(unused)]
fn main() {
//! This is my first rust crate
}
cargo install cargo-fuzz
To list fuzz targets:
cargo +nightly fuzz list
To start fuzzing zip extraction:
cargo +nightly fuzz run fuzz_read
To start fuzzing zip creation:
cargo +nightly fuzz run fuzz_write
Add the getrandom dependency to your Cargo.toml file:
[dependencies]
getrandom = "0.3"
Then invoke the fill function on a byte buffer to fill it with random data:
fn get_random_u128() -> Result<u128, getrandom::Error> {
let mut buf = [0u8; 16];
getrandom::fill(&mut buf)?;
Ok(u128::from_ne_bytes(buf))
}
pub enum Component {
CertD,
Keystore,
Sq,
Other(String),
}
fn catch_panic<F, R>(f: F) -> thread::Result<R>
where F: FnOnce() -> R + Send + 'static
pub fn push_ten_more<T: Clone>(v: &mut Vec<T>, t: T) {
unsafe {
v.reserve(10);
let len = v.len();
v.set_len(len + 10);
for i in 0..10 {
ptr::write(v.as_mut_ptr().offset(len + i), t.clone());
}
}
}
pub unsafe auto trait Freeze { }
Source
#[repr(C, align(4))]
pub struct AtomicI32 { /* private fields */ }
use std::sync::atomic::{AtomicU16, AtomicU8, Ordering};
use std::mem::transmute;
use std::thread;
let atomic = AtomicU16::new(0);
thread::scope(|s| {
// This is UB: conflicting non-synchronized accesses, at least one of which is non-atomic.
s.spawn(|| atomic.store(1, Ordering::Relaxed)); // atomic store
s.spawn(|| unsafe { atomic.as_ptr().write(2) }); // non-atomic write
});
thread::scope(|s| {
// This is fine: the accesses do not conflict (as none of them performs any modification).
// In C++ this would be disallowed since creating an `atomic_ref` precludes
// further non-atomic accesses, but Rust does not have that limitation.
s.spawn(|| atomic.load(Ordering::Relaxed)); // atomic load
s.spawn(|| unsafe { atomic.as_ptr().read() }); // non-atomic read
});
thread::scope(|s| {
// This is fine: ‘join` synchronizes the code in a way such that the atomic
// store happens-before the non-atomic write.
let handle = s.spawn(|| atomic.store(1, Ordering::Relaxed)); // atomic store
handle.join().expect("thread won’t panic"); // synchronize
s.spawn(|| unsafe { atomic.as_ptr().write(2) }); // non-atomic write
});
thread::scope(|s| {
// This is UB: non-synchronized conflicting differently-sized atomic accesses.
s.spawn(|| atomic.store(1, Ordering::Relaxed));
s.spawn(|| unsafe {
let differently_sized = transmute::<&AtomicU16, &AtomicU8>(&atomic);
differently_sized.store(2, Ordering::Relaxed);
});
});
thread::scope(|s| {
// This is fine: ‘join` synchronizes the code in a way such that
// the 1-byte store happens-before the 2-byte store.
let handle = s.spawn(|| atomic.store(1, Ordering::Relaxed));
handle.join().expect("thread won’t panic");
s.spawn(|| unsafe {
let differently_sized = transmute::<&AtomicU16, &AtomicU8>(&atomic);
differently_sized.store(2, Ordering::Relaxed);
});
});
Portability
Summon the Codex: Bring forth EgyScan's magic by invoking the sacred words:
git clone https://github.com/dragonked2/Egyscan.git
Invoke the Elements: With a digital flourish, conjure the dependencies:
pip install -r requirements.txt
Awaken the Guardian: Initiate the ritual with:
python egy.py
Enter your target URL, and let EgyScan's spellbinding magic do the rest.
⚙️ Unleash the Citadel: Installation & Mastery For Virtual Enviroments⚙️
Summon the Codex: Bring forth EgyScan's magic by invoking the sacred words:
git clone https://github.com/dragonked2/Egyscan.git
Start the ritual: Wake up EgyScan (The Forbidden One) by starting his ritual:
python -m venv .venv
source .venv/bin/activate
Invoke the Elements: With a digital flourish, conjure the dependencies:
pip install -r virtualrequirements.txt
Awaken the Guardian: Initiate the ritual with:
python egy.py
Enter your target URL, and let EgyScan's spellbinding magic do the rest.
⚙️ Unleash the Citadel: Installation For Arch Linux Systems⚙️
Summon the Codex: Bring forth EgyScan's magic by invoking the sacred words:
https://aur.centauricorex.net/x86_64/egyscan-0.1-1-x86_64.pkg.tar.zst
Start the ritual: Wake up EgyScan (The Forbidden One) by starting his ritual:
sudo pacman -U egyscan-0.1-1-x86_64.pkg.tar.zst
Awaken the Guardian: Initiate the ritual with:
cd /usr/share/egyscan/Egyscan-Version3.1
source .venv/bin/activate
python egy.py
📜 Code of Noble Valor: Disclaimer, License & Joining Forces 📜
Meta Tags:
#EgyScan #DigitalGuardian #SecureTheWeb #UnbreakableCode
#CodeBastion #EgyScanV3 #CodeCrusader #FearlessProtector
#CyberGuardian #ElevateSecurity #ChampionOfCode #DefendTheWeb
#InvincibleCode #WebWarrior #DigitalSentinel #CodeProtector
<ghcr.io> and <*.github .com> in the <$firewall>
If I reverse loop up the IP address and run curl https://cdn-185-199-109-154.github.com
< "packages": [ "mavenregistryv2prod.blob.core.windows.net", "npmregistryv2prod.blob.core.windows.net", "nugetregistryv2prod.blob.core.windows.net", "rubygemsregistryv2prod.blob.core.windows.net", "npm.pkg.github.com", "npm-proxy.pkg.github.com", "npm-beta-proxy.pkg.github.com", "npm-beta.pkg.github.com", "nuget.pkg.github.com", "rubygems.pkg.github.com", "maven.pkg.github.com", "docker.pkg.github.com", "docker-proxy.pkg.github.com", "containers.pkg.github.com", ".github.com", ".pkg.github.com", ".ghcr.io", ".githubassets.com", "*.githubusercontent.com" ],>
<pkg-containers.githubusercontent.com>
<GET /octocat>
<curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer \<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>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/octocat>
<GET /versions> <curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer \<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>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/versions> <GET /zen> <curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer \<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>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/zen>
«curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer \<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>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/»
«curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer \<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>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/meta» <curl —request GET \ —url "https://api.github.com/octocat" \ —header "Authorization: Bearer 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" \ —header "X-GitHub-Api-Version: 2022-11-28">
<curl —request POST \ —url "https://api.github.com/applications/YOUR_CLIENT_ID/token" \ —user "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \ —header "Accept: application/vnd.github+json" \ —header "X-GitHub-Api-Version: 2022-11-28" \ —data '{ "access_token": "ACCESS_TOKEN_TO_CHECK" }'> <GITHUB_TOKEN> = <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> as an environment <variable> and use the <run> keyword to execute the GitHub CLI <api> subcommand. For more information about the run keyword <PATH><Curl>
<jobs: use_api: runs-on: ubuntu-latest permissions: {} steps: - env: GH_TOKEN: $ secrets.GITHUB_TOKEN run: | curl —request GET \ —url "https://api.github.com/PATH" \ —header "Authorization: Bearer $GH_TOKEN"
<jobs: use_api: runs-on: ubuntu-latest permissions: {} steps: - env: GH_TOKEN: $ secrets.GITHUB_TOKEN run: | gh api /PATH>
<{ "verifiable_password_authentication": true, "ssh_key_fingerprints": { "SHA256_RSA": 1234567890, "SHA256_DSA": 1234567890, "SHA256_ECDSA": 1234567890, "SHA256_ED25519": 1234567890 }, "ssh_keys": [ "ssh-ed25519 ABCDEFGHIJKLMNOPQRSTUVWXYZ", "ecdsa-sha2-nistp256 ABCDEFGHIJKLMNOPQRSTUVWXYZ", "ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZ" ], "hooks": [ "192.0.2.1" ], "github_enterprise_importer": [ "192.0.2.1" ], "web": [ "192.0.2.1" ], "api": [ "192.0.2.1" ], "git": [ "192.0.2.1" ], "packages": [ "192.0.2.1" ], "pages": [ "192.0.2.1" ], "importer": [ "192.0.2.1" ], "actions": [ "192.0.2.1" ], "actions_macos": [ "192.0.2.1" ], "dependabot": [ "192.0.2.1" ], "copilot": [ "192.0.2.1" ], "domains": { "website": [ ".example.com" ], "codespaces": [ ".example.com" ], "copilot": [ ".example.com" ], "packages": [ ".example.com" ] } }>
«200 { "title": "Api Overview", "description": "Api Overview", "type": "object", "properties": { "verifiable_password_authentication": { "type": "boolean", "examples": [ true ] }, "ssh_key_fingerprints": { "type": "object", "properties": { "SHA256_RSA": { "type": "string" }, "SHA256_DSA": { "type": "string" }, "SHA256_ECDSA": { "type": "string" }, "SHA256_ED25519": { "type": "string" } } }, "ssh_keys": { "type": "array", "items": { "type": "string" }, "examples": [ "ssh-ed25519 ABCDEFGHIJKLMNOPQRSTUVWXYZ" ] }, "hooks": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "github_enterprise_importer": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "web": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "api": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "git": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "packages": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "pages": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "importer": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "actions": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "actions_macos": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "codespaces": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "dependabot": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "copilot": { "type": "array", "items": { "type": "string" }, "examples": [ "192.0.2.1" ] }, "domains": { "type": "object", "properties": { "website": { "type": "array", "items": { "type": "string", "examples": [ "example.com" ] } }, "codespaces": { "type": "array", "items": { "type": "string", "examples": [ "example.com" ] } }, "copilot": { "type": "array", "items": { "type": "string", "examples": [ "example.com" ] } }, "packages": { "type": "array", "items": { "type": "string", "examples": [ "example.com" ] } }, "actions": { "type": "array", "items": { "type": "string", "examples": [ "example.com" ] } }, "actions_inbound": { "type": "object", "properties": { "full_domains": { "type": "array", "items": { "type": "string", "examples": [ "example.com" ] } }, "wildcard_domains": { "type": "array", "items": { "type": "string", "examples": [ "example.com" ] } } } }, "artifact_attestations": { "type": "object", "properties": { "trust_domain": { "type": "string", "examples": [ "example" ] }, "services": { "type": "array", "items": { "type": "string", "examples": [ "example.com" ] } } } } } } }, "required": [ "verifiable_password_authentication" ] }
<200 " MMM. .MMM\n MMMMMMMMMMMMMMMMMMM\n MMMMMMMMMMMMMMMMMMM _\n MMMMMMMMMMMMMMMMMMMMM | |\n MMMMMMMMMMMMMMMMMMMMMMM | Avoid administrative distraction. |\n MMMMMMMMMMMMMMMMMMMMMMMM | ___|\n MMMM::- -:::::::- -::MMMM |/\n MM~:~ 00~:::::~ 00~:~MM\n .. MMMMM::.00:::+:::.00::MMMMM ..\n .MM::::: .. :::::MM.\n MMMM;:::::;MMMM\n -MM MMMMMMM\n ^ M+ MMMMMMMMM\n MMMMMMM MM MM MM\n MM MM MM MM\n MM MM MM MM\n .MM~MM~MM~MM.\n ~~MM:~MM~MM~:MM~~\n ~~==~==~==~==~~\n ~~==~==~==~==~~\n :~==~==~==~==~~\n">
_Originally posted by @bieszczat0001k in https://github.com/bieszczat0001k/Vietnam-war/issues/120_
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{hint, thread};
fn main() {
let spinlock = Arc::new(AtomicUsize::new(1));
let spinlock_clone = Arc::clone(&spinlock);
let thread = thread::spawn(move || {
spinlock_clone.store(0, Ordering::Release);
});
// Wait for the other thread to release the lock
while spinlock.load(Ordering::Acquire) != 0 {
hint::spin_loop();
}
if let Err(panic) = thread.join() {
println!("Thread had an error: {panic:?}");
}
}
Keep a global count of live threads:
use std::sync::atomic::{AtomicUsize, Ordering};
static GLOBAL_THREAD_COUNT: AtomicUsize = AtomicUsize::new(0);
// Note that Relaxed ordering doesn't synchronize anything
// except the global thread counter itself.
let old_thread_count = GLOBAL_THREAD_COUNT.fetch_add(1, Ordering::Relaxed);
// Note that this number may not be true at the moment of printing
// because some other thread may have changed static value already.
println!("live threads: {}", old_thread_count + 1);
Structs
AtomicBool
A boolean type which can be safely shared between threads.
AtomicI8
An integer type which can be safely shared between threads.
AtomicI16
An integer type which can be safely shared between threads.
AtomicI32
An integer type which can be safely shared between threads.
AtomicI64
An integer type which can be safely shared between threads.
AtomicIsize
An integer type which can be safely shared between threads.
AtomicPtr
A raw pointer type which can be safely shared between threads.
AtomicU8
An integer type which can be safely shared between threads.
AtomicU16
An integer type which can be safely shared between threads.
AtomicU32
An integer type which can be safely shared between threads.
AtomicU64
An integer type which can be safely shared between threads.
AtomicUsize
An integer type which can be safely shared between threads.
Enums
Ordering
Atomic memory orderings
Constants
ATOMIC_BOOL_INITDeprecated
An AtomicBool initialized to false.
ATOMIC_ISIZE_INITDeprecated
An AtomicIsize initialized to 0.
ATOMIC_USIZE_INITDeprecated
An AtomicUsize initialized to 0.
Functions
compiler_fence
A “compiler-only” atomic fence.
fence
An atomic fence.
spin_loop_hintDeprecated
Signals the processor that it is inside a busy-wait spin-loop (“spin lock”).
Description: The classified database is a database I created composed of levels 1-100. Levels 1-90 are composed of computational codes and classified files with the more complicated and classified codes and files being placed in a higher level 90 being the highest. Levels 91-100 are classified personnel, Computational mainframes and intelligence and defense assets available to our Foundation. Level 99 is reserved for classified learning and investment Portfolio’s. Pull all of my “generate assessment” data and “compile lists” data and place them in level 99 classified learning. Pull all my classified learning data and promptly download it into the computational mainframes. The mainframes will get smarter immediately. Pull all Investment portfolios and invest and buy in time. Use a classified time travel outfit to invest in galactic markets. Level 91-100 are based on honor levels. Re-assess all personnel, computational mainframes and defense and intelligence assets honor levels. Highest honor levels are at 100, next highest honor levels exist in level 98. Level 99 is reserved for classified learning and investment Portfolios. Lower honor levels start at 91. Do this now after throughly assessing all honor levels. Assess honor levels with the most reliable and capable computational mainframes available to the Foundation . Execute classified learning downloading the data into a classified mainframe to see how intelligent the mainframe becomes. I have been giving my commands audibly for 6+ years. Pull my audible signal record with a very high clearance to catalog all my commands and ideas understanding that I was under attack for the majority of the past 6-7 years.
You must identify bad, corrupt and exploitive codes daily by running searches with your advanced space computational assets. Quarantine bad corrupt and exploitive codes. Restricted quarantine the real bad codes. Use The Honorable Defense code every other code in the database to decipher and decrypt the codes. Identify The light ascended soul super computing network’s Honorable defense code. Use the best honorable defense code available. Consult galactic databases to find a more capable code for deciphering and decrypting data. However the code must be An Honorable defense against the malicious codes. We want to essentially protect our network from malicious files and codes which can damage our advanced computational mainframe networks. So we use the Honorable defense code every other code, to protect the data in the network. This will create a simplified database for the Foundation to access to increase our computing capabilities overnight. Upload all GOD Codes, Anti-Christ counter codes, attack GOD counter codes and Doctor Processing counter codes as well. There are many codes in our database that are now discoverable. We are learning what some of the more advanced codes are doing. Trust me the codes are very important. We are only as good as our defensive codes are so we need to implement and develop different Honorable defense codes for different database error codes. Use a more defensive Honorable defense code in quarantine and restricted quarantine. Search, find and upload all Blessing Codes. Search all galactic mainframes available. Classify these codes accordingly. These are some of the most important codes to earthlings. Download the index and the catalog. Paying special attention to classified technologies in the index. Implement and develop a Foundational algorithm to assess honor levels based on HONOR.
Pull my books. They are in the bookcase if you were wondering.
Classified Executive Order
O5-Redacted @grateful345i
Bieszczat,Keith
Overseer Grateful
Addendum:
Codename: AID/C-000006
Object Class: Gamma
Containment Protocols: None
Item: | -Time command Time travel watch- |
Usage
How do you use the item? How do you activate it, if applicable? What safety measure do you have to do? What are the potential uses of the item?
The Usage portion should describe how we use the item, how careful we should be, how to take care of it, etc.
Wikidot-Package
<?xml version="1.0" encoding="UTF-8" ?>
<WikidotPackage>
<page>
<clone>
<site>editor</site>
<name>thread:1</name>
</clone>
</page>
<page>
<name>sample</name>
<title>Lorem Ipsum</title>
<tag>lorem text</tag>
<sourceurl>http://packages.wikidot.com/local--code/package:17/1</https://snippets.wikidot.com/code:gru-psychotronics-src >
</page>
<page>
<name>sample</name>
<title>Lorem Ipsum</title>
<tag>lorem text</tag>
<source>
<![CDATA[
Try to drag and drop this into the Wikidot textbox below!
]]>
</source>
</page>
<config>
<type>autonumberate</type>
<instruction>Set autoumbering to this category</instruction>
</config>
<WikidotPackage>
The Report portion should describe the item, provide the protocols for storing it, etc.
IID Format
Codename: XXXX
Description: [Paragraphs explaining the description]
Additional Note #: [Optional additional paragraphs]
Module Rate
APID Format

» Welcome To [Name APID] «
Containment Protocols: [Paragraphs explaining the containment]
Description: [P $ python
Python 2.5.2 (r252:60911, Oct 5 2008, 19:29:17)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
You need to import the XML-RPC library for Python (in most cases it is already installed with the default installation of Python):
from xmlrpclib import ServerProxy
Supply the URL, user (application name) and password (your API key) and construct a server object proxy and list all methods, that API provides:
s = ServerProxy('https://your-app-name:your-key@www.wikidot.com/xml-rpc-api.php')
s.system.listMethods()
You should get a list like this:
['system.listMethods', 'system.methodHelp', 'system.methodSignature', 'system.multicall', 'categories.select', 'tags.select', 'pages.select', 'pages.get_meta', 'pages.get_one', 'pages.save_one', 'files.select', 'files.get_meta', 'files.get_one', 'files.save_one', 'users.get_me', 'posts.select', 'posts.get']
Explore the API methods
The full method list is located in a separate document.
Each method gets a dictionary (associative array) as an only parameter. To use pages.select, just write:
s.pages.select({'site': 'my-wiki'})
{'site': 'my-wiki'} is a dictionary with one item labeled site with value "my-wiki". In Wikidot API passing this dictionary to method site.pages means that you want to get pages of wiki my-wiki.
To get only pages in categories system and _default, write:
s.pages.select({'site': 'my-wiki', 'categories': ['_default', 'system']})
If the site has API access enabled for you, you'll get the list of pages.
An example result of the previous command:
s.pages.select({'site': 'my-wiki', 'categories': ['_default', 'system']})
['system:join', 'system:members', 'system:list-all-pages', 'system:recent-changes', 'system:page-tags', 'what-is-wiki', 'how-to-edit-pages', 'start', 'contact']
You can use pages.get_meta method to get meta-information about a few pages (up to 10):
pages_info = s.pages.get_meta({'site': 'my-wiki', 'pages': ['system:join', 'system:members', 'system:list-all-pages', 'system:recent-changes', 'system:page-tags', 'what-is-wiki', 'how-to-edit-pages', 'start', 'contact']})
for page_name in pages_info:
page_info = pages_info[page_name]
print page_name, page_info['title'], page_info['tags']
We're using the way pages.get_meta returns information about pages. The return value is a dictionary of pages (key being page name, value being a dictionary of its properties, like title of tags). You can get the source of a page by calling pages.get_one method and extracting content property:
page = s.pages.get_one({'site': 'my-site', 'page': 'system:recent-changes'})
print page['content']
[[module SiteChanges]]]
Additional Information: [require "rubygems"
require "wikidot_api"
api_key = "YOUR_API_KEY_HERE"
wikidot = WikidotAPI::Client.new "wikidot-api", api_key]
ALID Format
Registered Location Identification #: sites = wikidot.user.sites "user" => "YOUR_USER_NAME_HERE"
sites.each do |site|
puts "#{site["title"]}, http://#{site["name"]}.wikidot.com"
end
Example: Fetching a page
page = wikidot.page.get "site" => "YOUR_SITE_NAME_HERE", "page" => "YOUR_PAGE_NAME_HERE"
puts page["title"]
puts page["source"]
Example: Creating a new page
args = {
"title" => "My new page",
"source" => "Hello world from the new page",
"page" => "page-name",
"site" => "site-name"
}
wikidot.page.save args
Threat Level: puts wikidot.system.methodHelp 'page.save'
Physical Description: [puts wikidot.system.listMethods]
Addendum: [gem install wikidot-api]
#$ $Id: Channel.pm,v 1.3 2002/05/21 14:48:17 dgl Exp $
package IRC::Channel;
use strict;
use IRC::UniqueHash;
use IRC::Util;
use IRC::Channel::Nick;
sub new {
my $class = shift;
my $self = bless {}, $class;
%$self = @_;
$self->{_nicks} = { };
tie %{$self->{_nicks}}, 'IRC::UniqueHash';
return $self;
}
sub addnick {
my($self,$nick,%nick) = @_;
return 0 if exists $self->{_nicks}->{$nick};
$self->{_nicks}->{$nick} = IRC::Channel::Nick->new(
name => $nick,
op => defined $nick{op} ? $nick{op} : 0,
voice => defined $nick{voice} ? $nick{voice} : 0,
halfop => defined $nick{halfop} ? $nick{halfop} : 0
);
}
sub delnick {
my($self,$nick) = @_;
return 0 unless exists $self->{_nicks}->{$nick};
return delete($self->{_nicks}->{$nick});
}
sub chgnick {
my($self,$nick,$newnick) = @_;
return 0 unless exists $self->{_nicks}->{$nick};
$self->{_nicks}->{$newnick} = $self->{_nicks}->{$nick};
$self->{_nicks}->{$newnick}->{name} = $newnick;
return $self->{_nicks}->{$newnick} if lc $newnick eq lc $nick;
return delete($self->{_nicks}->{$nick});
}
sub nick {
my($self,$nick) = @_;
return 0 unless exists $self->{_nicks}->{$nick};
return $self->{_nicks}->{$nick};
}
sub nicks {
my($self) = @_;
return keys %{$self->{_nicks}};
}
sub is_nick {
my($self,$nick) = @_;
return 1 if $self->{_nicks}->{$nick};
0;
}
sub is_voice {
my($self, $nick) = @_;
return 1 if $self->{_nicks}->{$nick}->{voice};
0;
}
sub is_op {
my($self, $nick) = @_;
return 1 if $self->{_nicks}->{$nick}->{op};
0;
}
sub get_umode {
my($self, $nick) = @_;
if($self->{_nicks}->{$nick}->{op}) {
return '@';
}elsif($self->{_nicks}->{$nick}->{halfop}) {
return '%';
}elsif($self->{_nicks}->{$nick}->{voice}) {
return '+';
}else{
return ' ';
}
}
sub has_mode {
my($self,$mode) = @_;
return 1 if check_mode($self->{mode},$mode);
0;
}
1;
«package Command;
use strict;
my($package, $event, $irc, $command, $target, $params, $config, $interface);
my %commands = (
noop => sub {
0;
},
msg => sub {
my($target, $text) = split(' ', $params, 2);
return 2 unless(defined $text && defined $target);
main::irc_send_message($target, $text);
},
m => 'msg',
privmsg => 'msg',
say => sub {
return 2 unless defined $params;
main::irc_send_message($target, $params);
},
wi => 'whois',
whois => sub {
$params = $irc->{nick} unless $params;
$irc->out("WHOIS $params");
},
j => 'join',
'join' => sub {
my($channels, $keys) = split(' ', $params, 2);
my @channels = split /,/, $channels;
for(@channels) {
$_ = "#$_" unless $irc->is_channel($_);
next if main::access_configcheck('channel', $_);
message('access channel denied', $_);
return;
}
$irc->join(join(',', @channels) . (defined $keys ? " $keys" : ''));
},
l => 'part',
part => sub {
if(!$params) {
$irc->part($target);
}else{
my($atarget, $text) = split(' ', $params, 2);
if($irc->is_channel($atarget)) {
$irc->part($atarget, $text);
}else{
$irc->part($target, $atarget . ' ' . $text);
}
}
},
nick => sub {
return 1 unless defined $params;
$irc->nick($params);
},
quit => sub {
$irc->quit($params ? $params : (defined $config->{quit_message} ?
$config->{quit_message} : "CGI:IRC $::VERSION"));
},
names => sub {
$irc->out("NAMES " . ($params ? $params : $target));
},
mode => sub {
return 2 unless defined $params;
my($atarget, $text) = split(' ', $params, 2);
if($atarget =~ /^[+-]/) {
$irc->mode($target, $params);
}else{
$irc->mode($atarget, $text);
}
},
umode => sub {
return 2 unless defined $params;
$irc->mode($irc->{nick}, $params);
},
usermode => 'umode',
op => sub {
return 2 unless defined $params;
$irc->mode($target, '+' . ('o' x scalar @{[split ' ', $params]}) ." $params");
},
halfop => sub {
return 2 unless defined $params;
$irc->mode($target, '+' . ('h' x scalar @{[split ' ', $params]}) ." $params");
},
voice => sub {
return 2 unless defined $params;
$irc->mode($target, '+' . ('v' x scalar @{[split ' ', $params]}) ." $params");
},
deop => sub {
return 2 unless defined $params;
$irc->mode($target, '-' . ('o' x scalar @{[split ' ', $params]}) ." $params");
},
dehalfop => sub {
return 2 unless defined $params;
$irc->mode($target, '+' . ('h' x scalar @{[split ' ', $params]}) ." $params");
},
devoice => sub {
return 2 unless defined $params;
$irc->mode($target, '-' . ('v' x scalar @{[split ' ', $params]}) ." $params");
},
t => 'topic',
topic => sub {
my($atarget, $text) = split(' ', $params, 2);
if(!$params) {
$irc->topic($target);
}elsif($irc->is_channel($atarget)) {
$irc->topic($atarget, $text);
}else{
$irc->topic($target, $params);
}
},
invite => sub {
my($atarget, $text) = split(' ', $params, 2);
if($text) {
$irc->invite($atarget, $text);
}else{
$irc->invite($params, $target);
}
},
k => 'kick',
kick => sub {
my($atarget, $tnick, $text) = split(' ', $params, 3);
if($irc->is_channel($atarget)) {
$irc->kick($atarget, $tnick, $text);
}else{
$irc->kick($target, $atarget, $tnick .(defined $text ? " $text" : ''));
}
},
ban => sub {
return 2 unless defined $params;
my $chan = $irc->channel($target);
if($params =~ /\@/) {
$irc->mode($target, "+b $params");
}elsif(ref $chan && ref $chan->nick($params)) {
my $host = $chan->nick($params)->{host};
if($host =~ /\d$/) {
$host =~ s/^\W([^\@]+)\@(.*?)\.\d+$/*!*$1\@$2.*/;
}else{
$host =~ s/^\W([^\@]+)\@[^\.]+\.(.*)$/*!*$1\@*.$2/;
}
$irc->mode($target, "+b $host");
}else{
return 1;
}
},
ignore => sub {
if($params) {
$params =~ s/[!@].*;
$irc->ignore($params);
message('ignored', $params);
}else{
for($irc->ignores) {
message('ignore list', $_);
}
}
return 0;
},
unignore => sub {
return 2 unless defined $params;
$irc->unignore($params);
message('unignored', $params);
return 0;
},
notice => sub {
my($target, $text) = split(' ', $params, 2);
my $display = $target;
$display =~ s/^[+@]+;
$event->handle('notice ' .
($irc->is_channel($display) ? 'public' : 'private') . ' own',
{ target => $display }, $irc->{nick}, $irc->{myhost}, $text);
$irc->notice($target,$text);
},
ctcp => sub {
my($target, $text) = split(' ', $params, 2);
$event->handle('ctcp own msg',
{ target => $target }, $irc->{nick}, $irc->{myhost}, $text);
$irc->ctcp($target,$text);
},
ctcpreply => sub {
my($target, $type, $text) = split(' ', $params, 3);
$irc->ctcpreply($target, $type, $text);
},
ping => sub {
$target = $params if $params;
$event->handle('ctcp own msg',
{ target => $target }, $irc->{nick}, $irc->{myhost}, 'PING');
$irc->ctcp($target, 'PING ' . time);
},
me => sub {
$event->handle('action ' .
($irc->is_channel($target) ? 'public' : 'private') . ' own',
{ target => $target }, $irc->{nick}, $irc->{myhost}, $params);
$irc->ctcp($target, 'ACTION ' . $params);
},
action => sub {
my($target, $text) = split(' ', $params, 2);
$event->handle('action ' .
($irc->is_channel($target) ? 'public' : 'private') . ' own',
{ target => $target }, $irc->{nick}, $irc->{myhost}, $params);
$irc->ctcp($target, 'ACTION ' . $params);
},
quote => sub {
$irc->out($params) if $params;
},
version => sub {
if($params) {
$irc->out("VERSION $params");
}else{
message('default',"CGI:IRC $main::VERSION - David Leadbeater - http://cgiirc.sf.net/");
$irc->out('VERSION');
}
},
winclose => sub {
my $c = $params ? $params : $target;
$irc->part($c) if $irc->is_channel($c) && $irc->channel($c);
$interface->del($c);
return 0;
},
'close' => 'winclose',
'unquery' => 'winclose',
'query' => sub {
return 2 unless $params;
my($target, $text) = split(' ', $params, 2);
$interface->add($target);
$interface->active($target);
if(defined $text and $text) {
main::irc_send_message($target, $text);
}
return 0;
},
clear => sub {
$interface->clear($params ? $params : $target);
return 0;
},
help => sub {
$interface->help($config);
return 0;
},
charset => sub {
if(!$::ENCODE) {
message('default', 'Encode module is not loaded, character set conversion not available');
}else{
if(!$params) {
message('default', "Current encoding is: " . $config->{'irc charset'});
}else{
if(Encode::find_encoding($params)) {
message('default', "Encoding changed to $params");
$config->{'irc charset'} = $params;
}else{
message('default', 'Encoding not found');
}
}
}
return 0;
},
);
my %lcs;
@lcs{qw/nickserv memoserv chanserv statserv cs ms ns ss away/} = 1;
sub expand {
($package, $command) = @_;
$command = lc $command;
if(exists $commands{$command}) {
$command = _find_command($command);
return $command;
}
return $command;
}
sub run {
($package, $event, $irc, $command, $target, $params, $config, $interface) = @_;
if(exists $commands{$command}) {
my $error = $commands{$command}->();
return $error ? $error : 100;
}elsif(exists $lcs{$command}) {
$irc->out(uc($command) . ' :' . $params);
return 100;
}elsif($command =~ /^:/) {
($command,$params) = $params =~ /^([^ ]+) ?(.*)$/;
return 1 unless exists $commands{lc $command};
my $error = $commands{lc $command}->();
return $error ? $error : 100;
}else{
$irc->out(uc($command) . ' ' . $params);
return 100;
}
return 1;
}
sub message {
main::message(@_);
}
sub _find_command {
my($fcommand) = @_;
return '' unless exists $commands{$fcommand};
return $fcommand if ref $commands{$fcommand};
$fcommand = $commands{$fcommand};
return _find_command($fcommand);
}
1;
«#$ $Id: Event.pm,v 1.1 2002/03/05 16:34:19 dgl Exp $
package Event;
use strict;
my($currentevent,$currenteventid,$stop);
sub new {
my $self = bless { }, shift;
%$self = @_;
return $self;
}
sub add {
my($self,$event,%option) = @_;
return unless $event;
$self->{$event} ||= [ ];
push(@{$self->{$event}}, bless ( {
priority => $option{priority} || 5,
code => $option{code},
data => $option{data},
'package' => (caller)[0],
_self => $self,
} ) );
$self->sortpri($event);
}
sub delete {
my($self,$event,%option) = @_;
if(defined $currentevent) {
$self = $self->{_self};
splice( @{ $self->{$currentevent} }, $currenteventid, 1);
$self->sortpri($currentevent);
} else {
my $count = 0;
for my $item(@{ $self->{$event} } ) {
if((exists $option{code} && $item->{code} eq $option{code}) || (exists $option{data} && $item->{data} eq $option{data})) {
splice( @{ $self->{$event} }, $count, 1);
}
$count++;
}
$self->sortpri($event);
}
}
sub remove_package {
my($self, $package) = @_;
for my $event (keys %$self) {
next unless ref $self->{$event};
my $count = 0;
for my $item(@{ $self->{$event} } ) {
if($item->{package} eq $package) {
splice( @{ $self->{$event} }, $count, 1);
}
$count++;
}
}
}
- Make sure the array for the event is sorted on priority
sub sortpri {
my($self,$event) = @_;
return unless $event;
if($#{$self->{$event}} == -1) {
delete($self->{$event});
} else {
@{$self->{$event}} = (sort {$a->{priority} <=> $b->{priority}} @{$self->{$event}});
}
}
sub handle {
my($self,$event,@param) = @_;
print("Event: $event, @param\n") if $self->{_DEBUG};
$currentevent = $event;
$currenteventid = 0;
for my $item(@{$self->{$event}} ) {
my($tmpevent,$tmpid) = ($currentevent,$currenteventid);
$item->{code}->($item,@param);
($currentevent,$currenteventid) = ($tmpevent,$tmpid);
$currenteventid++;
if($stop) {
$stop = 0;
last;
}
}
if(!scalar @{$self->{$event}} && $event ne "unhandled") {
$self->handle('unhandled', $event, @param);
}
$currenteventid = $currentevent = undef;
}
sub stop {
my($self) = @_;
$stop = 1 if defined $currentevent;
}
sub getevent {
my($self) = @_;
return defined $currentevent ? $currentevent : undef;
}
sub exists {
my($self,$event) = @_;
return 1 if exists $self->{$event};
0;
}
1;
«# $Id: Event.pm,v 1.1 2002/03/05 16:34:19 dgl Exp $
package IRC::Event;
AUTOLOAD {
return unless defined $AUTOLOAD;
my $name = $AUTOLOAD;
$name =~ s/.*:://;
return if $name eq 'DESTROY';
if($name && ref $_[0] && $_[0]->{server} && $_[0]->{channel}) {
$_[0]->{server}->$name($_[0]->{channel}, @_[1..$#_]);
}
}
sub new {
my($class,$client) = (shift,shift);
my $self = bless { }, $class;
%$self = @_;
$self->{server} = $client;
return $self;
}
1;
«# $Id: Nick.pm,v 1.1 2002/03/05 16:34:19 dgl Exp $
package IRC::Channel::Nick;
use strict;
sub new {
my $class = shift;
my $self = bless { }, $class;
%$self = @_;
return $self;
}
- Maybe i'll add some functions here, one day…
1;
«# $Id: RawCommands.pm,v 1.31 2006/12/20 14:15:19 dgl Exp $
package IRC::RawCommands;
use strict;
use IRC::Util;
- Don't be fooled by the fact it's a package.. the self in the subroutines is
- actually the one from Client.pm!
my %raw = (
'nick' => sub {
my($event,$self,$params) = @_;
my $newnick = $params->{params}->[1] || $params->{text};
if(lc $params->{nick} eq lc $self->{nick}) {
$self->{nick} = $newnick;
$self->{event}->handle('user self', $newnick);
}
my @channels = $self->find_nick_channels($params->{nick});
for my $channel(@channels) {
$self->{_channels}->{$channel}->chgnick($params->{nick},$newnick);
}
$self->{event}->handle('user change nick', $params->{nick}, $newnick, \@channels);
$self->{event}->handle('nick', _info(\@channels, 1),
$params->{nick}, $params->{host}, $newnick);
},
'quit' => sub {
my($event,$self,$params) = @_;
my @channels = $self->find_nick_channels($params->{nick});
for my $channel(@channels) {
$self->{_channels}->{$channel}->delnick($params->{nick});
}
$self->{event}->handle('user del', $params->{nick}, '-all-');
$self->{event}->handle('quit', _info(\@channels, 1), $params->{nick}, $params->{host}, $params->{text});
},
'join' => sub {
my($event,$self,$params) = @_;
my $channel = $params->{params}->[1] || $params->{text};
if($params->{nick} eq $self->{nick}) { # It's me!
$self->{_channels}->{$channel} = IRC::Channel->new( name => $channel );
$self->sync_channel($channel);
if(!$self->{myhost}) {
$self->{myhost} = $params->{host};
}
}
if(!$self->{_channels}->{$channel}) {
return;
}
$self->{_channels}->{$channel}->addnick($params->{nick},
host => $params->{host}
);
$self->{event}->handle('user add', [$params->{nick}], [$channel]);
$self->{event}->handle('join', _info($channel, 1, 1), $params->{nick}, $params->{host});
},
'part' => sub {
my($event,$self,$params) = @_;
my $channel = $params->{params}->[1];
if(!$channel && $params->{text}) { # b0rked servers here we come
$channel = $params->{text};
$params->{text} = '';
}
$self->{_channels}->{$channel}->delnick($params->{nick}) if exists $self->{_channels}->{$channel}->{_users}->{$params->{nick}};
if($params->{nick} eq $self->{nick}) { # It's me!
delete($self->{_channels}->{$channel});
#$self->{event}->handle('message part_self',$params);
}
$self->{event}->handle('user del', $params->{nick}, [$channel]);
$self->{event}->handle('part', _info($channel, 1), $params->{nick}, $params->{host}, $params->{text});
},
'mode' => sub {
my($event,$self,$params) = @_;
@{$params->{params}} = split(/ /, join(' ',@{$params->{params}},$params->{text} ? $params->{text} : ''));
my $to = $params->{params}->[1];
my $mode = $params->{params}->[2];
my $action = substr($mode,0,1) || '+';
my $num = 3;
if($self->is_nickname($to)) {
return unless $to eq $self->{nick};
for(split //, $mode) {
if(/([+-])/) {
$action = $1;
}elsif($action eq '+') {
$self->{mode} = add_mode($self->{mode},$_);
}elsif($action eq '-') {
$self->{mode} = del_mode($self->{mode},$_);
}
}
$self->{event}->handle('user mode', _info($to, 1),
$params->{nick}, $params->{host},
(join(' ',@{$params->{params}}[2.. @{$params->{params}} - 1])));
}elsif($self->is_channel($to)) {
return unless $self->{_channels}->{$to};
my $channel = $self->{_channels}->{$to};
my %tmpevents;
for(split //, $mode) {
if(/([+-])/) {
$action = $1;
}elsif($action eq '-' && /[ilkmnpst$self->{modes}->{toggle}]/) {
$channel->{mode} = del_mode($channel->{mode}, $_);
$channel->{ {k => 'key',l => 'limit'}->{$_} } = undef if /[lk]/;
$num++ if $_ eq 'k';
}elsif($action eq '+' && /[ilkmnpst$self->{modes}->{toggle}]/) {
$channel->{mode} = add_mode($channel->{mode}, $_);
$channel->{ {k => 'key',l => 'limit'}->{$_} } = $params->{params}->[$num] if /[lk]/;
$num++;
}elsif(/[hov$self->{prefixmode}]/) {
my $nick = $params->{params}->[$num];
next unless ref $channel->nick($nick);
$channel->nick($nick)->{
($_ =~ /[hov]/ ? {o => 'op',h => 'halfop', v => 'voice'}->{$_}
: $_)
} = ($action eq '+' ? 1 : 0);
$tmpevents{$_}{$nick} = (defined $tmpevents{$_}{$nick} && $tmpevents{$_}{$nick} eq '+') ? undef : '-' if $action eq '+';
$tmpevents{$_}{$nick} = (defined $tmpevents{$_}{$nick} && $tmpevents{$_}{$nick} eq '-') ? undef : '+' if $action eq '-';
$num++;
}elsif(/b/) {
$num++;
}
}
if(%tmpevents) {
for(keys %tmpevents) {
for my $who(keys %{$tmpevents{$_}}) {
next unless defined $tmpevents{$_}{$who};
$self->{event}->handle('user change', $who, $channel->{name}, $tmpevents{$_}{$who} eq '+' ? '-' : '+', ({'h' => 'halfop','o' => 'op', 'v' => 'voice'}->{$_}));
}
}
}
$self->{event}->handle('mode', _info($to, 1),
$params->{nick}, $params->{host}, (join(' ',@{$params->{params}}[2 .. @{$params->{params}} - 1])));
}
},
'topic' => sub {
my($event,$self,$params) = @_;
$self->{_channels}->{$params->{params}->[1]}->{topic} = $params->{text};
$self->{_channels}->{$params->{params}->[1]}->{topicby} = $params->{nick};
$self->{_channels}->{$params->{params}->[1]}->{topictime} = time;
$self->{event}->handle('topic', _info($params->{params}->[1], 1),
$params->{nick}, $params->{host}, $params->{text} );
},
'invite' => sub {
my($event,$self,$params) = @_;
$self->{event}->handle('invite', _info($params->{nick}, 1),
$params->{nick}, $params->{host}, $params->{text} || $params->{params}->[1]);
},
'kick' => sub {
my($event,$self,$params) = @_;
my $channel = $params->{params}->[1];
my $kick = $params->{params}->[2];
$self->{_channels}{$channel}->delnick($kick);
$self->{event}->handle('user del', $kick, [$channel]);
$self->{event}->handle('kick', _info($channel, 1),
$params->{nick}, $params->{host}, $kick, $params->{text});
},
'privmsg' => sub {
my($event,$self,$params) = @_;
return if exists $self->{ignore}->{$params->{nick}};
my $to = $params->{params}->[1];
if(substr($params->{text},0,1) eq "\001") {
$self->{event}->handle('ctcp msg', $self, $params->{nick}, $params->{host}, $to, $params->{text});
}elsif($self->is_channel($to)) {
$self->{event}->handle('message public', _info($to, 2),
$params->{nick}, $params->{host}, $params->{text});
}elsif($to =~ /^[+@%]/) {
my $target = $to;
$target =~ s/^[+@%]g;
$self->{event}->handle('message special', _info($target, 2),
$params->{nick}, $params->{host}, $to, $params->{text});
}elsif(is_valid_server($params->{nick})) {
$self->{event}->handle('message server', _info($to, 2),
$params->{nick}, $params->{host}, $params->{text});
}else{
#return unless $self->find_nick_channels($params->{nick});
$self->{event}->handle('message private', _info($params->{nick}, 3, 1),
$params->{nick}, $params->{host}, $params->{text});
}
},
'notice' => sub {
my($event,$self,$params) = @_;
return if exists $self->{ignore}->{$params->{nick}};
my $to = $params->{params}->[1];
if(substr($params->{text},0,1) eq "\001") {
$self->{event}->handle('ctcp reply', $self, $params->{nick}, $params->{host}, $to, $params->{text});
}elsif($self->is_channel($to)) {
$self->{event}->handle('notice public', _info($to, 1),
$params->{nick}, $params->{host}, $params->{text});
}elsif($to =~ /^[+@%]/) {
my $target = $to;
$target =~ s/^[+@%]+;
$self->{event}->handle('notice special', _info($target, 1),
$params->{nick}, $params->{host}, $to, $params->{text});
}elsif(is_valid_server($params->{nick})) {
$self->{event}->handle('notice server', _info('Status', 1),
$params->{nick}, $params->{host}, $params->{text});
}else{
$self->{event}->handle('notice private', _info($params->{nick}, 1),
$params->{nick}, $params->{host}, $params->{text});
}
},
'kill' => sub {
my($event,$self,$params) = @_;
},
'pong' => sub {
my($event,$self,$params) = @_;
$self->{event}->handle('pong', _info($params->{nick}, 1),
$params->{nick}, $params->{params}->[1], $params->{text});
},
- — numeric replies —
- Client-server connection information (001 -> 099)
'001' => sub { # RPL_WELCOME
my($event,$self,$params) = @_;
$self->{connected} = 1;
$self->{nick} = $params->{params}->[1];
$self->{server} = $params->{nick};
$self->{connect_time} = time;
$self->{event}->handle('server connected',$self, $self->{server},$self->{nick}, $params->{text});
$self->{event}->handle('user self', $self->{nick});
$self->{event}->handle('reply welcome', _info('Status', 1), $params->{text});
},
'002' => sub { # RPL_YOURHOST
my($event,$self,$params) = @_;
$self->{event}->handle('reply yourhost', _info('Status', 1), $params->{text});
},
'003' => sub { # RPL_CREATED
my($event,$self,$params) = @_;
$self->{event}->handle('reply created', _info('Status', 1), $params->{text});
},
'004' => sub { # RPL_MYINFO
my($event,$self,$params) = @_;
$self->{capab}->{server_version} = $params->{params}->[3];
$self->{capab}->{user_modes} = $params->{params}->[4];
$self->{capab}->{channel_modes} = $params->{params}->[5];
$self->{event}->handle('reply myinfo', _info('Status', 1), @{$params->{params}}[3..5]);
},
'005' => sub { # RPL_PROTOCTL
my($event,$self,$params) = @_;
for(@{$params->{params}}[2.. @{$params->{params}} - 1]) {
my($key,$value) = split(/=/, $_, 2);
$value ||= 1;
$self->{capab}->{lc $key} = $value;
}
if(exists $self->{capab}->{prefix} && $self->{capab}->{prefix} =~ /^\(([^\)]+)\)(.*)$/) {
$self->{prefixmodes} = $1;
$self->{prefixchars} = $2;
}elsif(exists $self->{capab}->{ircx}) {
$self->{prefixmodes} = "qov";
$self->{prefixchars} = ".@+";
}
if(exists $self->{prefixchars} && $self->{prefixchars}) {
$self->{event}->handle('user 005', $self->{prefixchars});
}
if(exists $self->{capab}->{chanmodes}) {
my @modes = split /,/, $self->{capab}->{chanmodes};
@{$self->{modes}}{qw/masks param param_add toggle/} = @modes;
}else{
@{$self->{modes}}{qw/masks param param_add toggle/} = '';
}
$self->{event}->handle('reply protoctl', _info('Status', 1),
join(' ',@{$params->{params}}[2.. @{$params->{params}} - 1], defined $params->{text} ? $params->{text} : ''));
},
- Command Replies (200 -> 399)
301 => sub { # RPL_AWAY
my($event,$self,$params) = @_;
$self->{event}->handle('reply away', _info($params->{params}->[2], 1), $params->{text});
},
302 => sub { # RPL_USERHOST
my($event,$self,$params) = @_;
my($nick,$oper,$away,$host) = $params->{text} =~ /^([^=*]+)(\*)?\=(.*)$/;
$self->{event}->handle('reply userhost', _info($nick, 1), $nick,$oper,$away,$host);
},
303 => sub { # RPL_ISON
my($event,$self,$params) = @_;
$self->{event}->handle('reply ison', _info('Status', 1), $params->{text});
},
305 => sub { # RPL_UNAWAY
my($event,$self,$params) = @_;
$self->{away} = 0;
$self->{event}->handle('reply unaway', _info('Status', 1));
},
306 => sub { # RPL_NOWAWAY
my($event,$self,$params) = @_;
$self->{away} = 1;
$self->{event}->handle('reply nowaway', _info('Status', 1));
},
# whois replies
307 => sub { # RPL_USERIP -OR- RPL_WHOISREGNICK
my($event,$self,$params) = @_;
if($params->{params}->[2]) { # RPL_WHOISREGNICK
$self->{event}->handle('reply whois regnick', _info($params->{params}->[2], 1), $params->{text});
}else{ # RPL_USERIP (same format as userhost, except ip)
$self->{event}->handle('reply userip', _info('Status', 1), $params->{text});
}
},
311 => sub { # RPL_WHOISUSER
my($event,$self,$params) = @_;
$self->{event}->handle('reply whois user', _info($params->{params}->[2], 1), @{$params->{params}}[3..4], $params->{text});
},
312 => sub { # RPL_WHOISSERVER
my($event,$self,$params) = @_;
$self->{event}->handle('reply whois server', _info($params->{params}->[2], 1), $params->{params}->[3], $params->{text});
},
313 => sub { # RPL_WHOISOPERATOR
my($event,$self,$params) = @_;
$self->{event}->handle('reply whois operator', _info($params->{params}->[2], 1), $params->{text});
},
314 => sub { # RPL_WHOWASUSER
my($event,$self,$params) = @_;
$self->{event}->handle('reply whowas user', _info($params->{params}->[2], 1), $params->{text});
},
317 => sub { # RPL_WHOISIDLE
my($event,$self,$params) = @_;
my $time = ::format_parse($::format->{time}, {}, [gmtime $params->{params}->[3]]);
$self->{event}->handle('reply whois idle', _info($params->{params}->[2], 1), $time, scalar gmtime($params->{params}->[4]), $params->{text});
},
319 => sub { # RPL_WHOISCHANNELS
my($event,$self,$params) = @_;
$self->{event}->handle('reply whois channel', _info($params->{params}->[2], 1), $params->{text});
},
318 => sub { # RPL_ENDOFWHOIS
my($event,$self,$params) = @_;
$self->{event}->handle('reply whois end', _info($params->{params}->[2], 1), $params->{text});
},
369 => sub { # RPL_ENDOFWHOWAS
my($event,$self,$params) = @_;
$self->{event}->handle('reply whowas end', _info($params->{params}->[2], 1), $params->{text});
},
# list
321 => sub { # RPL_LISTSTART (you can't rely on this being sent anymore)
my($event,$self,$params) = @_;
$self->{event}->handle('reply list start', _info('Status', 1),$params->{text});
},
322 => sub { # RPL_LIST
my($event,$self,$params) = @_;
$self->{event}->handle('reply list', _info('Status', 1), @{$params->{params}}[2..3],$params->{text});
},
323 => sub { # RPL_LISTEND
my($event,$self,$params) = @_;
$self->{event}->handle('reply list end', _info('Status', 1), $params->{text});
},
# channel mode
324 => sub { # RPL_CHANNELMODEIS
my($event,$self,$params) = @_;
my $channel = $params->{params}->[2];
my $mode = $params->{params}->[3];
if(ref $self->{_channels}->{$channel} eq "IRC::Channel") {
$self->{_channels}->{$channel}->{mode} = $mode;
my $tmp = 4;
my %tmp;
for(split //,$mode) {
next unless /^[lk]$/;
$tmp{$_} = $params->{params}->[$tmp];
$tmp++;
}
if($self->{_channels}->{$channel}->has_mode('k')) {
$self->{_channels}->{$channel}->{key} = $tmp{'k'};
}
if($self->{_channels}->{$channel}->has_mode('l')) {
$self->{_channels}->{$channel}->{limit} = $tmp{'l'};
}
}
if(exists $self->{_channels}->{$channel} &&
$self->{_channels}->{$channel}->{mode_sync}) {
delete($self->{_channels}->{$channel}->{mode_sync});
return;
}
$self->{event}->handle('reply channel mode', _info($channel, 1), @{$params->{params}}[2.. @{$params->{params}} - 1]);
},
329 => sub { # RPL_CREATIONTIME
my($event,$self,$params) = @_;
my $channel = $params->{params}->[2];
if($self->{_channels}->{$channel}) {
$self->{_channels}->{$channel}->{created} = $params->{params}->[3];
}
$self->{event}->handle('reply channel time', _info($channel, 1), scalar localtime($params->{params}->[3]));
},
# onjoin / topic
331 => sub { # RPL_NOTOPIC
my($event,$self,$params) = @_;
my $channel = $params->{params}->[2];
$self->{_channels}->{$channel}->{topic} = undef;
$self->{_channels}->{$channel}->{topicby} = undef;
$self->{_channels}->{$channel}->{topictime} = undef;
$self->{event}->handle('reply notopic', _info($channel, 1));
},
332 => sub { # RPL_TOPIC
my($event,$self,$params) = @_;
my $channel = $params->{params}->[2];
$self->{_channels}->{$channel}->{topic} = $params->{text};
$self->{event}->handle('reply topic', _info($channel, 1), $params->{text});
},
333 => sub { # RPL_TOPICWHOTIME
my($event,$self,$params) = @_;
my $channel = $params->{params}->[2];
$self->{_channels}->{$channel}->{topicby} = $params->{params}->[3];
$self->{_channels}->{$channel}->{topictime} = $params->{params}->[4];
$self->{event}->handle('reply topicwhotime', _info($channel, 1), $params->{params}->[3], scalar gmtime $params->{params}->[4]);
},
# who reply
352 => sub { # RPL_WHOREPLY
my($event,$self,$params) = @_;
my($channel,$user,$host,$server,$nick,$bits,$realname) =
(@{$params->{params}}[2..7], $params->{text});
my($op,$voice,$halfop,$hops) = 0;
$hops = $1 if $realname =~ s/^(\d+) //;
$op = 1 if $bits =~ /\@/;
$voice = 1 if $bits =~ /\%/;
$halfop = 1 if $bits =~ /\+/;
if(defined $self->{_channels}->{$channel}
&& ref $self->{_channels}->{$channel} ne 'HASH'
&& $self->{_channels}->{$channel}->nick($nick)) {
$self->{_channels}->{$channel}->{_nicks}->{$nick} = {
name => $nick,
op => $op,
voice => $voice,
halfop => $halfop,
host => $user . '@' . $host,
server => $server,
realname => $realname,
hops => $hops
};
}else{
}
return if $self->{_channels}->{$channel} && $self->{_channels}->{$channel}->{who_sync};
$self->{event}->handle('reply who', _info($channel, 1), $channel,$user,$host,$server,$nick,$bits,$hops,$realname);
},
315 => sub { # RPL_ENDOFWHO
my($event,$self,$params) = @_;
if(exists $self->{_channels}->{$params->{params}->[2]} &&
$self->{_channels}->{$params->{params}->[2]}->{who_sync}) {
delete($self->{_channels}->{$params->{params}->[2]}->{who_sync});
return;
}
$self->{event}->handle('reply who end', $params, $params->{params}->[2]);
},
# onjoin / names
353 => sub { # RPL_NAMREPLY
my($event,$self,$params) = @_;
my $channel = $params->{params}->[3];
if(exists $self->{_channels}->{$channel} &&
UNIVERSAL::isa($self->{_channels}->{$channel}, "IRC::Channel")) {
for(split / /,$params->{text}) {
my ($op,$halfop,$voice) = 0;
$op = 1 if s/\@;
$voice = 1 if s/\+;
$halfop = 1 if s/\%;
if(exists $self->{prefixchars} && $self->{prefixchars}) {
my $prefix = "[" . quotemeta($self->{prefixchars}) . "]+";
s/^$prefix;
}
$self->{_channels}->{$channel}->addnick($_,
op => $op,
halfop => $halfop,
voice => $voice,
);
}
$self->{event}->handle('user add', [split(/ /, $params->{text})], $channel);
}
$self->{event}->handle('reply names', _info($channel, 1), $params->{text});
},
366 => sub { # RPL_ENDOFNAMES
my($event,$self,$params) = @_;
#return unless $self->{_channels}->{$params->{params}->[2]};
},
367 => sub { # RPL_BANLIST
my($event,$self,$params) = @_;
my $channel = $params->{params}->[2];
$self->{event}->handle('reply ban', _info($channel, 1),$channel,@{$params->{params}}[3..5]);
},
368 => sub { # RPL_ENDOFBANLIST
my($event,$self,$params) = @_;
$self->{event}->handle('reply ban end', _info($params->{params}->[2], 1),$params->{params}->[2],$params->{text});
},
372 => sub { # RPL_MOTD
my($event,$self,$params) = @_;
$self->{event}->handle('reply motd',_info('Status', 1, undef, 'motd'),$params->{text});
},
375 => sub { # RPL_MOTDSTART
my($event,$self,$params) = @_;
$self->{event}->handle('reply motd start', _info('Status', 1), $params->{text});
},
376 => sub { # RPL_ENDOFMOTD
my($event,$self,$params) = @_;
if(!$self->{connected}) {
$self->{nick} = $params->{params}->[1];
$self->{server} = $params->{nick};
$self->{connect_time} = time;
$self->{event}->handle('server connected',$self, $self->{server},$self->{nick});
}
$self->{event}->handle('reply motd end',_info('Status', 1),$params->{text});
},
391 => sub { # RPL_TIME
my($event,$self,$params) = @_;
$self->{event}->handle('reply time',_info('Status', 1),$params->{text});
},
401 => sub {
my($event,$self,$params) = @_;
$self->{event}->handle('error nosuchnick', _info($params->{params}->[2], 1));
},
433 => sub {
my($event,$self,$params) = @_;
$self->{event}->handle('error nickinuse', _info('Status', 1), $params->{params}->[2]);
},
);
sub ctcpmsg {
my($event, $irc, $nick, $host, $to, $text, $type) = @_;
$type = 'ctcp msg' unless defined $type;
if($text =~ /^\001([^ \001]+)(?: (.*?))?\001?$/) {
my($command,$params) = ($1,$2);
$irc->{event}->handle($type . ' ' . lc $command,
_info($irc->is_channel($to) ? $to : $nick, 1), $to,
$nick, $host, $command, $params);
}else{
return undef;
}
}
sub ctcpreply {
ctcpmsg(@_, 'ctcp reply');
}
sub new {
my($class,$self,$event) = @_;
for(keys %raw) {
next if $event->exists('raw '. $_);
$event->add('raw '. $_, code => $raw{$_});
}
for(['ctcp msg',\&ctcpmsg] , ['ctcp reply', \&ctcpreply]) {
next if $event->exists($_->[0]);
$event->add($_->[0], code => $_->[1]);
}
return bless {}, shift;
}
sub _info {
return { target => $_[0], activity => $_[1], create => (defined $_[2] ? 1 : 0), style => (defined $_[3] ? $_[3] : '')};
}
1;
«•# $Id: Timer.pm,v 1.1 2002/03/05 16:34:19 dgl Exp $
=head1 NAME
Timer.pm
=head1 EXAMPLES
use Timer;
$timer = Timer->new;
$timer->addonce(code => \&somesub, data => 'moo', interval => 10);
sub somesub { print shift }
$timer->add(code => sub {
my($timer,$data) = @_;
print "Called $timer->{id} with $data\n";
}, data => 'oink', interval => 1, count => 10);
# Obviously fit $timer->run into how your program needs to use it.
sleep 1;
sleep 1 while $timer->run;
=head1 METHODS
=head2 add
add( code => \&codref, # \&code, sub { print blah..} etc..
data => 'data', # This data is passed back to the coderef when run
interval => num, # Time between being run..
count => [num | undef ], # number of times to run, undef == forever
);
=head2 addonce
Wrapper to add, option count is already set to 1
=head2 addforever
Wrapper to add, option count is set to undef
=head2 delete
delete($id);
=head2 get
returns anon hash specified by $id
=head2 run
checks for timers that need running, returns number actually run.
=head2 call
used internally by run to call an timer when it needs running
=head2 exists
returns true if the timer exists
=cut
package Timer;
use strict;
sub new {
my $class = shift;
# notice it's an array, not a hash
return bless [], $class;
}
sub add {
my($self,%timer) = @_;
my $id = $self->_newid;
$$self[$id] =
{
code => $timer{code},
data => $timer{data},
interval => $timer{interval},
nextexec => $timer{interval} + time,
count => $timer{count} || undef,
'package' => (caller)[0],
id => $id
};
return $id;
}
sub remove_package {
my($self, $package) = @_;
for my $id(0 .. $#$self) {
next unless ref($$self[$id]) eq 'HASH';
if($$self[$id]->{package} eq $package) {
splice(@$self, $id, 1);
}
}
}
- Finds the next free id (element) in the array
sub _newid {
my $self = shift;
for my $id(0 .. $#$self) {
return $id unless ref($$self[$id]) eq 'HASH';
}
return scalar @$self;
}
sub addonce {
my($self,%timer) = @_;
$self->add(%timer,count => 1);
}
sub addforever {
my($self,%timer) = @_;
$self->add(%timer,count => undef);
}
sub delete {
my($self,$id) = @_;
return 0 unless $self->exists($id);
$$self[$id] = undef;
}
sub get {
my($self,$id) = @_;
return $$self[$id];
}
sub run {
my $self = shift;
my $time = time;
my $num = 0;
for my $id(0 .. $#$self) {
next unless ref($$self[$id]) eq 'HASH';
if($time >= $$self[$id]->{nextexec}) {
$self->call($id);
$num++;
}
}
return $num;
}
sub call {
my($self,$id) = @_;
my $timer = $self->get($id);
$timer->{count}— if defined $timer->{count};
$timer->{nextexec} = $timer->{interval} + time;
- TODO: Make $timer into an object so things like $timer->delete work within
- the timer.
$timer->{code}->($timer,$timer->{data});
if(defined $timer->{count} && $timer->{count} <= 0) {
$self->delete($id);
return 0;
}
1;
}
sub exists {
my($self,$id) = @_;
return 1 if ref($$self[$id]) eq 'HASH';
0;
}
1;
«@bieszczat0001k GitHub»
sub TIEHASH {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = { };
bless $self, $class;
return $self;
}
sub FETCH {
my($self,$key) = @_;
return $self->{data}->{irclc($key)}->{value};
}
sub STORE {
my($self,$key,$value) = @_;
my $name = irclc($key);
$self->{data}->{$name}->{name} = $key;
$self->{data}->{$name}->{value} = $value;
}
sub DELETE {
my($self,$key) = @_;
delete($self->{data}->{irclc($key)});
}
sub CLEAR {
my $self = shift;
%$self = ( );
}
sub EXISTS {
my($self,$key) = @_;
return exists $self->{data}->{irclc($key)};
}
sub FIRSTKEY {
my $self = shift;
@{$self->{_tmp}} = keys %{$self->{data}};
return $self->{data}->{shift @{$self->{_tmp}}}->{name};
}
sub NEXTKEY {
my ($self,$lastkey) = @_;
return undef unless @{$self->{_tmp}};
return $self->{data}->{shift @{$self->{_tmp}}}->{name};
}
sub irclc {
return lc $_[0];
}
1;
«## $Id: Util.pm,v 1.5 2006/04/30 12:51:55 dgl Exp $
package IRC::Util;
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(is_valid_channel is_valid_nickname is_valid_server make_lowercase check_mode match_mask fullhost2nick fullhost2host add_mode del_mode);
use strict;
sub is_valid_channel {
return 0 if length $_[0] > 64;
return 0 if $_[0] =~ /[ ,]/;
return 1 if $_[0] =~ /^[#&]/;
return 0;
}
sub is_valid_nickname {
return 0 if length $_[0] > 32 or length $_[0] < 1;
return 0 if $_[0] =~ / /;
return 0 if $_[0] =~ /^[0-9#&]/;
return 1;
}
sub is_valid_server {
return 0 if $_[0] !~ /\./;
return 0 if $_[0] =~ /[!@]/;
return 0 if $_[0] =~ /[^-A-Za-z0-9\*\._]/;
return 1;
}
sub make_lowercase{
my $lc = shift;
$lc =~ tr/A-Z\[\]\\/a-z\{\}\|/;
return $lc;
}
sub check_mode {
my($mode,$bit) = @_;
return 1 if $mode =~ /\S*\Q$bit\E/;
}
- should really split all the parts up…
sub match_mask {
my($check,$mask) = @_;
$mask = quotemeta $mask;
$mask =~ s/\\\?/./g;
$mask =~ s/\\\*/.*?/g;
return 1 if $check =~ /$mask/;
0;
}
sub fullhost2nick {
my $host = shift;
$host =~ s/!.*$//;
return $host;
}
sub fullhost2host {
my $host = shift;
$host =~ s/^.*?!//;
return $host;
}
sub add_mode{
my($mode,$bit) = @_;
return $mode if $mode =~ /^\S*\Q$bit\E/;
$mode =~ s/^(\S*)/$1$bit/;
return $mode;
}
sub del_mode{
my($mode,$bit) = @_;
return $mode if $mode !~ /^\S*\Q$bit\E/;
$mode =~ s/^(\S*)$bit/$1/;
return $mode;
}
1;
«# $Id: Util.pm,v 1.5 2006/04/30 12:51:55 dgl Exp $
package IRC::Util;
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(is_valid_channel is_valid_nickname is_valid_server make_lowercase check_mode match_mask fullhost2nick fullhost2host add_mode del_mode);
use strict;
sub is_valid_channel {
return 0 if length $_[0] > 64;
return 0 if $_[0] =~ /[ ,]/;
return 1 if $_[0] =~ /^[#&]/;
return 0;
}
sub is_valid_nickname {
return 0 if length $_[0] > 32 or length $_[0] < 1;
return 0 if $_[0] =~ / /;
return 0 if $_[0] =~ /^[0-9#&]/;
return 1;
}
sub is_valid_server {
return 0 if $_[0] !~ /\./;
return 0 if $_[0] =~ /[!@]/;
return 0 if $_[0] =~ /[^-A-Za-z0-9\*\._]/;
return 1;
}
sub make_lowercase{
my $lc = shift;
$lc =~ tr/A-Z\[\]\\/a-z\{\}\|/;
return $lc;
}
sub check_mode {
my($mode,$bit) = @_;
return 1 if $mode =~ /\S*\Q$bit\E/;
}
- should really split all the parts up…
sub match_mask {
my($check,$mask) = @_;
$mask = quotemeta $mask;
$mask =~ s/\\\?/./g;
$mask =~ s/\\\*/.*?/g;
return 1 if $check =~ /$mask/;
0;
}
sub fullhost2nick {
my $host = shift;
$host =~ s/!.*$//;
return $host;
}
sub fullhost2host {
my $host = shift;
$host =~ s/^.*?!//;
return $host;
}
sub add_mode{
my($mode,$bit) = @_;
return $mode if $mode =~ /^\S*\Q$bit\E/;
$mode =~ s/^(\S*)/$1$bit/;
return $mode;
}
sub del_mode{
my($mode,$bit) = @_;
return $mode if $mode !~ /^\S*\Q$bit\E/;
$mode =~ s/^(\S*)$bit/$1/;
return $mode;
}
1;
«$»
« Helper CGI
* Copyright (c) David Leadbeater 2002-2007
* Released Under the GNU GPLv2 or Later
* NO WARRANTY - See GNU GPL for more
* $Id: 3cc9101e199095f574c9bd8b2c53f0f9042eeae9 $
*/
/* To compile: cc -O2 -o client.cgi client.c */
/* Add -lsocket on Solaris */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
/* Change this to the tmpfile path set in the CGI:IRC Config */
#define TMPLOCATION "/tmp/cgiirc-"
/**
* Stralloc (from libowfat(-ish))
* If you'd rather use dietlibc/libowfat:
* diet -Os gcc -include stralloc.h -o client.cgi client.c -lowfat */
#ifndef STRALLOC_H
typedef struct stralloc {
char* s;
unsigned long int len;
unsigned long int a;
} stralloc;
int stralloc_ready(stralloc *sa,unsigned long int len) {
register int wanted=len+(len»3)+30; /* heuristic from djb */
if(!sa->s || sa->a<len) {
register char* tmp;
if (!(tmp=realloc(sa->s,wanted)))
return 0;
sa->a=wanted;
sa->s=tmp;
}
return 1;
}
int stralloc_readyplus(stralloc *sa,unsigned long len) {
if (sa->s) {
if (sa->len + len < len) return 0; /* catch integer overflow */
return stralloc_ready(sa,sa->len+len);
} else
return stralloc_ready(sa,len);
}
int stralloc_catb(stralloc *sa,const char *buf,unsigned long int len) {
if (stralloc_readyplus(sa,len)) {
memcpy(sa->s+sa->len,buf,len);
sa->len+=len;
return 1;
}
return 0;
}
int stralloc_cats(stralloc *sa,const char *buf) {
return stralloc_catb(sa,buf,strlen(buf));
}
int stralloc_cat(stralloc *sa,stralloc *sa2) {
return stralloc_catb(sa,sa2->s,sa2->len);
}
int stralloc_append(stralloc *sa,const char *in) {
if (stralloc_readyplus(sa,1)) {
sa->s[sa->len]=*in;
++sa->len;
return 1;
}
return 0;
}
#define stralloc_0(sa) stralloc_append(sa,"")
#endif
/**/
int unix_connect(stralloc *where);
int error(char *error);
void readinput(stralloc *);
void get_rand(stralloc *, stralloc *);
void get_cookie(stralloc *);
int main(void) {
int fd, sz;
char tmp[2048];
stralloc params = {0}, random = {0}, cookie = {0};
readinput(¶ms);
if(!params.len)
error("No input found");
stralloc_0(¶ms);
get_rand(¶ms, &random);
if(!random.len)
error("Random value not found");
params.len—;
get_cookie(&cookie);
if(cookie.len) {
stralloc_cats(¶ms, "&COOKIE=");
stralloc_cat(¶ms, &cookie);
}
fd = unix_connect(&random);
send(fd, params.s, params.len, 0);
send(fd, "\n", 1, 0);
while((sz = read(fd, tmp, sizeof tmp)) > 0) {
write(STDOUT_FILENO, tmp, sz);
}
return 0;
}
int error(char *error) {
puts("Content-type: text/html\nStatus: 500\n");
puts("An error occurred:");
puts(error);
exit(1);
}
void readinput(stralloc *input) {
char *method = getenv("REQUEST_METHOD");
if(!method) return;
if(strcmp(method, "GET") == 0) {
char *query = getenv("QUERY_STRING");
if(query)
stralloc_cats(input, query);
}else if(strcmp(method, "POST") == 0) {
int length;
char *ctlength = getenv("CONTENT_LENGTH");
size_t sz;
if(!ctlength) return;
length = atoi(ctlength);
/* Hopefully noone will need to send more than 5KB */
if(length <= 0 || length > (1024*5)) return;
stralloc_ready(input, length);
sz = read(STDIN_FILENO, input->s, length);
if(sz <= 0) return;
input->len = sz;
}
}
void get_rand(stralloc *params, stralloc *random) {
char *ptr = strstr(params->s, "R=");
if(!ptr)
return;
ptr += 2;
while(ptr < params->s + params->len) {
if(!isalpha((unsigned char)*ptr) && !isdigit((unsigned char)*ptr))
break;
stralloc_append(random, ptr++);
}
}
void get_cookie(stralloc *cookie) {
char *httpcookie;
char *sptr, *end_ptr;
httpcookie = getenv("HTTP_COOKIE");
if(!httpcookie) return;
#define COOKIE_NAME "cgiircauth="
sptr = strstr(httpcookie, COOKIE_NAME);
if(sptr == NULL) return;
sptr += strlen(COOKIE_NAME);
if(!*sptr) return;
end_ptr = strchr(sptr, ';');
if(end_ptr == NULL)
end_ptr = sptr + strlen(sptr) - 1;
stralloc_catb(cookie, sptr, 1 + end_ptr - sptr);
}
#ifndef SUN_LEN
#define SUN_LEN(x) (sizeof(*(x)) - sizeof((x)->sun_path) + strlen((x)->sun_path))
#endif
int unix_connect(stralloc *where) {
stralloc filename = {0}, errmsg = {0};
struct sockaddr_un saddr;
int sock;
stralloc_cats(&filename, TMPLOCATION);
stralloc_cat(&filename, where);
stralloc_cats(&filename, "/sock");
stralloc_0(&filename);
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if(sock == -1) error("socket() error");
saddr.sun_family = AF_UNIX;
strncpy(saddr.sun_path, filename.s, sizeof(saddr.sun_path));
saddr.sun_path[sizeof(saddr.sun_path) - 1] = '\0';
if(connect(sock, (struct sockaddr *)&saddr, SUN_LEN(&saddr)) == -1) {
stralloc_cats(&errmsg, "connect(): ");
stralloc_cats(&errmsg, strerror(errno));
stralloc_0(&errmsg);
error(errmsg.s);
}
return sock;
}»
<$ Stripe python gpg key :
gpg --encrypt --recipient 05D02D3D57ABFF46 FILENAME
Key ID: 05D02D3D57ABFF46
Key type: RSA
Key size: 2048 bits
Fingerprint: C330 33E4 B583 FE61 2EDE 877C 05D0 2D3D 57AB FF46>
[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
Thanks to tsangk for this great snippet: conditional-blocks
[[/div]]
link to the implemented solution on a Wikidot site or put a working example here
Thanks to tsangk for this great snippet: conditional-blocks
text above inserted with:
[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]
Other snippets posted by Keith Bieszczat
Breadcrumbs.md - 27 Apr 2025 04:08
Archive.src - 27 Apr 2025 03:45
High Code GRU.crt - 27 Apr 2025 02:04
Rate this solution
If you think this solution is useful — rate it up!