Set up mobile-proxy

master
Sven Slootweg 5年前
コミット ec6d1a95dc

@ -0,0 +1,61 @@
"use strict";
const React = require("react");
const url = require("url");
function NoticeBox({ children, siteName }) {
return (
<div style={{backgroundColor: "#3C0000", color: "white", padding: "4px", margin: "4px"}}>
<strong>This is a mobile proxy.</strong> It is intended to visit {siteName} on devices that would otherwise not correctly display the site. {children}
</div>
);
}
module.exports = {
port: 3000,
hosts: {
"awesomedude.cryto.net": {
prefix: () => (
<NoticeBox siteName="AwesomeDude" />
),
filters: [{
matchPath: "/",
mapUrl: "http://www.awesomedude.com/",
mapContent: ($) => $("#container").html()
}, {
mapUrl: ({path}) => url.resolve("http://www.awesomedude.com/", path),
mapContent: ($) => $("body").html()
}]
},
"castleroland.cryto.net": {
prefix: () => (
<NoticeBox siteName="CastleRoland.net">
Please direct all your feedback to <a style={{ color: "white" }} href="http://www.castleroland.net/">CastleRoland.net</a> directly!
</NoticeBox>
),
filters: [{
matchPath: "/",
mapUrl: "https://castleroland.net/stories-categories/",
mapContent: ($) => $("section.home_about").html()
}, {
mapUrl: ({path}) => url.resolve("https://www.castleroland.net/", path),
mapContent: ($) => $("section.home_about").html()
}]
},
"iomfats.cryto.net": {
prefix: () => (
<NoticeBox siteName="the IOMfAtS Story Shelf">
Please direct all your feedback to the <a style={{ color: "white" }} href="http://iomfats.org/aboutme/">friendly guy over at IOMfAtS</a>!
</NoticeBox>
),
filters: [{
matchPath: "/",
mapUrl: "http://iomfats.org/storyshelf/",
mapContent: ($) => $("div#homelinks").html()
}, {
mapUrl: ({path}) => url.resolve("http://iomfats.org/", path),
mapContent: ($) => $("div#content").html()
}]
}
}
};

@ -1,5 +1,18 @@
let
nixpkgsOptions = {};
nixpkgsOptions = {
overlays = [
(self: super: {
/* NOTE: Namespaced under `pkgs.cryto.*` to prevent naming conflicts with upstream nixpkgs */
cryto = {
# FIXME: Remove default.nix suffix?
fetchFromCrytoGit = self.callPackage ./lib/fetch/from-cryto-git.nix {};
nodeApplication = self.callPackage ./lib/node-application.nix {};
unpack = self.callPackage ./lib/unpack.nix {};
mobileProxy = self.callPackage ./packages/mobile-proxy/default.nix { configFile = null; };
};
})
];
};
pkgs = (import (fetchTarball "https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.03.tar.gz") nixpkgsOptions);
pkgs1803 = (import (fetchTarball "https://github.com/NixOS/nixpkgs-channels/archive/nixos-18.03.tar.gz") nixpkgsOptions);
presets = {
@ -9,6 +22,7 @@ let
nginxPresets = {
php = (import ./presets/nginx/php.nix);
cphpApplication = (import ./presets/nginx/cphp-application.nix);
reverseProxy = (import ./presets/nginx/reverse-proxy.nix);
};
in {
network = {
@ -30,6 +44,9 @@ in {
{ scheme = "http"; port = 80; path = "/"; host = "books.cryto.net"; description = "books.cryto.net is up"; }
{ scheme = "http"; port = 80; path = "/"; host = "learn.cryto.net"; description = "learn.cryto.net is up"; }
{ scheme = "http"; port = 80; path = "/"; host = "vps-list.cryto.net"; description = "vps-list.cryto.net is up"; }
{ scheme = "http"; port = 80; path = "/"; host = "iomfats.cryto.net"; description = "iomfats.cryto.net is up"; }
{ scheme = "http"; port = 80; path = "/"; host = "castleroland.cryto.net"; description = "castleroland.cryto.net is up"; }
{ scheme = "http"; port = 80; path = "/"; host = "awesomedude.cryto.net"; description = "awesomedude.cryto.net is up"; }
];
networking.firewall.allowedTCPPorts = [ 80 ];
@ -37,6 +54,12 @@ in {
services.nginx = {
enable = true;
virtualHosts = {
"404.cryto.net" = {
default = true;
extraConfig = ''
return 404;
'';
};
"haless.cryto.net" = {
locations."/shadow" = {
alias = ./sources/shadow-generator;
@ -101,6 +124,9 @@ in {
'';
}))
];
"iomfats.cryto.net" = nginxPresets.reverseProxy "http://127.0.0.1:3000/";
"castleroland.cryto.net" = nginxPresets.reverseProxy "http://127.0.0.1:3000/";
"awesomedude.cryto.net" = nginxPresets.reverseProxy "http://127.0.0.1:3000/";
};
};
@ -135,5 +161,33 @@ in {
};
};
};
users.extraUsers.mobile-proxy = {
description = "mobile-proxy Service User";
};
systemd.services.mobile-proxy = let
package = pkgs.cryto.mobileProxy.override { configFile = ./data/mobile-proxy/config.jsx; };
in {
description = "Mobile Proxy";
wantedBy = ["multi-user.target"];
after = ["network.target"];
serviceConfig = {
ExecStart = "${package}/bin/mobile-proxy";
User = "mobile-proxy";
Restart = "on-failure";
PermissionsStartOnly = true;
};
preStart = ''
mkdir -m 0700 -p /tmp/mobile-proxy-home
chown mobile-proxy /tmp/mobile-proxy-home
'';
environment = {
HOME = "/tmp/mobile-proxy-home";
};
};
};
}

@ -0,0 +1,10 @@
{ pkgs, ... }:
{owner, repo, rev, name ? ("${repo}-${rev}-src.tar.gz"), ...}@sourceArgs:
let
baseUrl = "https://git.cryto.net/${owner}/${repo}";
in
pkgs.fetchurl ({
inherit name;
url = "${baseUrl}/archive/${rev}.tar.gz";
meta.homepage = baseUrl;
} // removeAttrs sourceArgs ["owner" "repo" "rev"])

@ -0,0 +1,10 @@
{ pkgs, ... }:
{ name, source }:
let
yarn2nix = (import (fetchTarball "https://github.com/joepie91/yarn2nix/archive/patch/remove-no-patch.tar.gz") { inherit pkgs; });
in yarn2nix.mkYarnPackage {
name = name;
src = source;
packageJSON = "${source}/package.json";
yarnLock = "${source}/yarn.lock";
}

@ -0,0 +1,19 @@
{ pkgs, configFile, ... }:
pkgs.cryto.nodeApplication {
name = "mobile-proxy";
source = pkgs.stdenv.mkDerivation {
name = "mobile-proxy-application";
src = pkgs.cryto.fetchFromCrytoGit {
owner = "joepie91";
repo = "mobile-proxy";
rev = "1628f4be61621c1783e93ef6719b1dae4f352be8";
sha256 = "1d9zc3phflsi2gsi7hmzybr0q983x7155bildvlbc7za3y8hry78";
};
buildCommand = ''
mkdir -p $out
tar -xzvf $src -C $out
cp ${configFile} $out/config.jsx
'';
};
}

@ -0,0 +1,9 @@
destination: {
locations."/" = {
proxyPass = destination;
proxyWebsockets = true;
extraConfig = ''
proxy_set_header Host $host;
'';
};
}
読み込み中…
キャンセル
保存