Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.

Commit b9625ab

Browse files
committed
Initial commit
0 parents  commit b9625ab

106 files changed

Lines changed: 18406 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
# Logs
3+
logs
4+
*.log
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
9+
# Runtime data
10+
pids
11+
*.pid
12+
*.seed
13+
*.pid.lock
14+
15+
# Dependency directories
16+
node_modules/
17+
18+
# Optional npm cache directory
19+
.npm
20+
21+
# Optional eslint cache
22+
.eslintcache
23+
24+
# Optional REPL history
25+
.node_repl_history
26+
27+
# Yarn Integrity file
28+
.yarn-integrity
29+
30+
# dotenv environment variables file
31+
.env
32+
33+
# Misc
34+
.DS_Store
35+
Thumbs.db
36+
37+
38+
39+
# Capacitor
40+
ios/App/public/
41+
!ios/App/public/native-bridge.js
42+
android/app/src/main/assets/public
43+
!android/app/src/main/assets/public/native-bridge.js
44+
resources/android/icon
45+
resources/android/splash
46+
resources/ios/icon
47+
resources/ios/splash
48+
resources/windows/icon
49+
resources/windows/splash
50+
51+
# Production build
52+
www/

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# CapibaraZero
2+
3+
## Framework7 CLI Options
4+
5+
Framework7 app created with following options:
6+
7+
```
8+
{
9+
"cwd": "/home/andreock/work/new_capibarazero",
10+
"type": [
11+
"pwa",
12+
"capacitor"
13+
],
14+
"name": "CapibaraZero",
15+
"framework": "svelte",
16+
"template": "tabs",
17+
"bundler": "vite",
18+
"cssPreProcessor": false,
19+
"theming": {
20+
"customColor": true,
21+
"color": "#8e7559",
22+
"darkMode": true,
23+
"iconFonts": true
24+
},
25+
"customBuild": false,
26+
"pkg": "io.framework7.myapp",
27+
"capacitor": {
28+
"platforms": [
29+
"ios",
30+
"android"
31+
]
32+
}
33+
}
34+
```
35+
36+
## Install Dependencies
37+
38+
First of all we need to install dependencies, run in terminal
39+
```
40+
npm install
41+
```
42+
43+
## NPM Scripts
44+
45+
* 🔥 `start` - run development server
46+
* 🔧 `dev` - run development server
47+
* 🔧 `build` - build web app for production
48+
* 📱 `build-capacitor-ios` - build app and copy it to iOS capacitor project
49+
* 📱 `build-capacitor-android` - build app and copy it to Android capacitor project
50+
51+
## Vite
52+
53+
There is a [Vite](https://vitejs.dev) bundler setup. It compiles and bundles all "front-end" resources. You should work only with files located in `/src` folder. Vite config located in `vite.config.js`.
54+
55+
## PWA
56+
57+
This is a PWA. Don't forget to check what is inside of your `service-worker.js`. It is also recommended that you disable service worker (or enable "Update on reload") in browser dev tools during development.
58+
## Capacitor
59+
60+
This project created with Capacitor support. And first thing required before start is to add capacitor platforms, run in terminal:
61+
62+
```
63+
npx cap add ios && npx cap add android
64+
```
65+
66+
Check out [official Capacitor documentation](https://capacitorjs.com) for more examples and usage examples.
67+
68+
## Assets
69+
70+
Assets (icons, splash screens) source images located in `assets-src` folder. To generate your own icons and splash screen images, you will need to replace all assets in this directory with your own images (pay attention to image size and format), and run the following command in the project directory:
71+
72+
```
73+
framework7 assets
74+
```
75+
76+
Or launch UI where you will be able to change icons and splash screens:
77+
78+
```
79+
framework7 assets --ui
80+
```
81+
82+
## Capacitor Assets
83+
84+
Capacitor assets are located in `resources` folder which is intended to be used with `cordova-res` tool. To generate mobile apps assets run in terminal:
85+
```
86+
npx cordova-res
87+
```
88+
89+
Check out [official cordova-res documentation](https://github.com/ionic-team/cordova-res) for more usage examples.
90+
91+
## Documentation & Resources
92+
93+
* [Framework7 Core Documentation](https://framework7.io/docs/)
94+
95+
96+
* [Framework7 Svelte Documentation](https://framework7.io/svelte/)
97+
* [Framework7 Icons Reference](https://framework7.io/icons/)
98+
* [Community Forum](https://forum.framework7.io)
99+
100+
## Support Framework7
101+
102+
Love Framework7? Support project by donating or pledging on:
103+
- Patreon: https://patreon.com/framework7
104+
- OpenCollective: https://opencollective.com/framework7

api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

api/Cargo.toml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[package]
2+
name = "api"
3+
version = "0.1.0"
4+
edition = "2021"
5+
build = "src/build.rs"
6+
7+
[dependencies]
8+
axum = {version = "0.8.1", features = ["ws", "multipart"]}
9+
tokio = { version = "1.43.0", features = ["full"] }
10+
serde = { version = "1.0.217", features = ["derive"]}
11+
serde_json = "1.0.138"
12+
tower-http = {version = "0.6.2", features = ["full"]}
13+
bluer = { version = "0.17.3", features = ["full"] }
14+
futures = "0.3.31"
15+
axum-extra = {version = "0.10.0" , features = ["typed-header"]}
16+
tracing = "0.1"
17+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
18+
tokio-tungstenite = "0.26.0"
19+
headers = "0.4"
20+
rand = "0.9.0"
21+
pnet = "0.35.0"
22+
netdev = "0.32.0"
23+
bollard = "0.18.1"
24+
pcap = "2.2.0"
25+
chrono = "0.4.39"
26+
libc = "0.2.169"
27+
zip = "2.2.2"
28+
dotenv = "0.15.0"
29+
30+
[build-dependencies]
31+
cc = "1.2.13"
32+
33+
[workspace.metadata.cross.target.aarch64-unknown-linux-gnu]
34+
# Install libssl-dev:arm64, see <https://github.com/cross-rs/cross/blob/main/docs/custom_images.md#adding-dependencies-to-existing-images>
35+
pre-build = [
36+
"dpkg --add-architecture $CROSS_DEB_ARCH",
37+
"apt-get update && apt-get --assume-yes install libdbus-1-dev:$CROSS_DEB_ARCH libpcap-dev:$CROSS_DEB_ARCH libnfc-dev:$CROSS_DEB_ARCH libusb-dev:$CROSS_DEB_ARCH libcjson-dev:$CROSS_DEB_ARCH libcjson1:$CROSS_DEB_ARCH"
38+
]
39+
40+
[[bin]]
41+
edition = "2021"
42+
name = "capibarazero_api"
43+
path = "src/main.rs"
44+
45+
[build.env]
46+
passthrough = ["LD_LIBRARY_PATH=/"]

api/src/ble/apple.rs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
use std::sync::mpsc::channel;
2+
use std::sync::mpsc::TryRecvError;
3+
use std::thread;
4+
use std::{process::Command, time};
5+
use axum::extract::connect_info::ConnectInfo;
6+
use axum::{
7+
body::Bytes,
8+
extract::ws::{Message, WebSocket, WebSocketUpgrade},
9+
response::IntoResponse
10+
};
11+
use axum_extra::TypedHeader;
12+
13+
use futures::StreamExt;
14+
use std::net::SocketAddr;
15+
use rand::prelude::*;
16+
17+
pub fn _apple_handler(
18+
ws: WebSocketUpgrade,
19+
user_agent: Option<TypedHeader<headers::UserAgent>>,
20+
ConnectInfo(addr): ConnectInfo<SocketAddr>,
21+
) -> impl IntoResponse {
22+
let user_agent = if let Some(TypedHeader(user_agent)) = user_agent {
23+
user_agent.to_string()
24+
} else {
25+
String::from("Unknown browser")
26+
};
27+
println!("`{user_agent}` at {addr} connected.");
28+
// finalize the upgrade process by returning upgrade callback.
29+
// we can customize the callback by sending additional info such as address.
30+
ws.on_upgrade(move |socket| send_apple_packet(socket, addr))
31+
}
32+
33+
pub async fn send_apple_packet(mut socket: WebSocket, who: SocketAddr) {
34+
if socket
35+
.send(Message::Ping(Bytes::from_static(&[1, 2, 3])))
36+
.await
37+
.is_ok()
38+
{
39+
println!("Pinged {who}...");
40+
} else {
41+
println!("Could not send ping {who}!");
42+
return;
43+
}
44+
45+
46+
let devices = vec![
47+
"27", "09", "02", "1e", "2b", "2d", "2f", "01", "06", "20", "c0",
48+
];
49+
50+
let (tx, rx) = channel();
51+
52+
let (mut _sender, mut receiver) = socket.split();
53+
54+
let mut recv_task = tokio::spawn(async move {
55+
loop {
56+
let msg = receiver.next().await.expect("error").expect("error2");
57+
if msg.to_text().expect("Can't parse to str") == "stop" {
58+
println!("Stopping clint");
59+
// cancelled = true;
60+
break;
61+
}
62+
}
63+
});
64+
65+
thread::spawn(move || {
66+
let mut rng = rand::rng();
67+
loop {
68+
let mut cancelled = false;
69+
for device in devices.clone() {
70+
/* Generate random data for the packet */
71+
let mut rnd_data1: Vec<char> = vec!['\0'; 3];
72+
rnd_data1.iter_mut().for_each(|x| *x = rng.sample(rand::distr::Alphanumeric) as char);
73+
let mut rnd_data2: Vec<char> = vec!['\0'; 3];
74+
rnd_data2.iter_mut().for_each(|x| *x = rng.sample(rand::distr::Alphanumeric) as char);
75+
76+
println!("Advertising: {}", device);
77+
let mut bt_process = Command::new("sh")
78+
.arg("-c")
79+
.arg(std::format!(
80+
"btmgmt add-adv -c -d 16FF4C000F05C1{}{}000010{} 1",
81+
device, rnd_data1.into_iter().collect::<String>(), rnd_data2.into_iter().collect::<String>()
82+
)).spawn().unwrap();
83+
thread::sleep(time::Duration::from_millis(2000));
84+
bt_process.wait().expect("Can't wait");
85+
match rx.try_recv() {
86+
Ok(_) | Err(TryRecvError::Disconnected) => {
87+
println!("Terminating.");
88+
cancelled = true;
89+
break;
90+
}
91+
Err(TryRecvError::Empty) => {}
92+
}
93+
}
94+
if cancelled {
95+
println!("Killing loop");
96+
let _raw_res = Command::new("sh")
97+
.arg("-c")
98+
.arg("pkill -9 btmgmt").spawn();
99+
break;
100+
}
101+
}
102+
});
103+
104+
// If any one of the tasks exit, abort the other.
105+
tokio::select! {
106+
rv_b = (&mut recv_task) => {
107+
match rv_b {
108+
Ok(_b) => println!("Rec killed"),
109+
Err(b) => println!("Error receiving messages {b:?}")
110+
}
111+
let _ = tx.send(());
112+
}
113+
}
114+
// send_task.
115+
println!("Destroying socket");
116+
}

0 commit comments

Comments
 (0)