mirror of
https://github.com/CHN-beta/nixos.git
synced 2026-01-12 04:19:22 +08:00
init fz-new-order
This commit is contained in:
@@ -299,7 +299,6 @@
|
||||
};
|
||||
coturn.enable = true;
|
||||
httpua.enable = true;
|
||||
fcgiwrap.enable = true;
|
||||
};
|
||||
};})
|
||||
];
|
||||
@@ -368,6 +367,7 @@
|
||||
freshrss.enable = true;
|
||||
send.enable = true;
|
||||
huginn.enable = true;
|
||||
fz-new-order.enable = true;
|
||||
};
|
||||
};})
|
||||
];
|
||||
|
||||
@@ -31,7 +31,7 @@ inputs:
|
||||
./send.nix
|
||||
./huginn.nix
|
||||
./httpua
|
||||
./fcgiwrap.nix
|
||||
./fz-new-order
|
||||
];
|
||||
options.nixos.services = let inherit (inputs.lib) mkOption types; in
|
||||
{
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
inputs:
|
||||
{
|
||||
options.nixos.services.fcgiwrap = let inherit (inputs.lib) mkOption types; in
|
||||
{
|
||||
enable = mkOption { type = types.bool; default = false; };
|
||||
};
|
||||
config =
|
||||
let
|
||||
inherit (inputs.config.nixos.services) fcgiwrap;
|
||||
inherit (inputs.lib) mkIf;
|
||||
in mkIf fcgiwrap.enable
|
||||
{
|
||||
nixos.services.nginx.enable = true;
|
||||
services.fcgiwrap =
|
||||
{
|
||||
enable = true;
|
||||
user = inputs.config.users.users.nginx.name;
|
||||
group = inputs.config.users.users.nginx.group;
|
||||
};
|
||||
};
|
||||
}
|
||||
104
modules/services/fz-new-order/default.nix
Normal file
104
modules/services/fz-new-order/default.nix
Normal file
@@ -0,0 +1,104 @@
|
||||
inputs:
|
||||
{
|
||||
options.nixos.services.fz-new-order = let inherit (inputs.lib) mkOption types; in
|
||||
{
|
||||
enable = mkOption { type = types.bool; default = false; };
|
||||
};
|
||||
config =
|
||||
let
|
||||
inherit (inputs.config.nixos.services) fz-new-order;
|
||||
inherit (inputs.localLib) attrsToList;
|
||||
inherit (inputs.lib) mkIf;
|
||||
inherit (builtins) map listToAttrs toString concatLists;
|
||||
in mkIf fz-new-order.enable
|
||||
{
|
||||
users =
|
||||
{
|
||||
users.fz-new-order =
|
||||
{ isSystemUser = true; group = "fz-new-order"; home = "/var/lib/fz-new-order"; createHome = true; };
|
||||
groups.fz-new-order = {};
|
||||
};
|
||||
systemd =
|
||||
{
|
||||
timers.fz-new-order =
|
||||
{
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig =
|
||||
{
|
||||
OnBootSec = "10m";
|
||||
OnUnitActiveSec = "10m";
|
||||
Unit = "fz-new-order.service";
|
||||
};
|
||||
};
|
||||
services.fz-new-order = rec
|
||||
{
|
||||
description = "fz-new-order";
|
||||
after = [ "network.target" ];
|
||||
requires = after;
|
||||
serviceConfig =
|
||||
{
|
||||
User = inputs.config.users.users."fz-new-order".name;
|
||||
Group = inputs.config.users.users."fz-new-order".group;
|
||||
WorkingDirectory = "/var/lib/fz-new-order";
|
||||
ExecStart =
|
||||
let
|
||||
src = inputs.pkgs.substituteAll
|
||||
{
|
||||
src = ./main.cpp;
|
||||
config_file = inputs.config.sops.templates."fz-new-order/config.json".path;
|
||||
};
|
||||
binary = inputs.pkgs.stdenv.mkDerivation
|
||||
{
|
||||
name = "fz-new-order";
|
||||
inherit src;
|
||||
buildInputs = with inputs.pkgs; [ jsoncpp.dev cereal fmt httplib ];
|
||||
dontUnpack = true;
|
||||
buildPhase =
|
||||
''
|
||||
runHook preBuild
|
||||
g++ -std=c++20 -O2 -o fz-new-order ${src} -ljsoncpp -lfmt
|
||||
runHook postBuild
|
||||
'';
|
||||
installPhase =
|
||||
''
|
||||
runHook preInstall
|
||||
mkdir -p $out/bin
|
||||
cp fz-new-order $out/bin/fz-new-order
|
||||
runHook postInstall
|
||||
'';
|
||||
};
|
||||
in "${binary}/bin/fz-new-order";
|
||||
};
|
||||
};
|
||||
};
|
||||
sops = let userNum = 6; configNum = 2; in
|
||||
{
|
||||
templates."fz-new-order/config.json" =
|
||||
{
|
||||
owner = inputs.config.users.users."fz-new-order".name;
|
||||
group = inputs.config.users.users."fz-new-order".group;
|
||||
content = let placeholder = inputs.config.sops.placeholder; in builtins.toJSON
|
||||
{
|
||||
manager = placeholder."fz-new-order/manager";
|
||||
token = placeholder."fz-new-order/token";
|
||||
uids = map (j: placeholder."fz-new-order/uids/user${toString j}") (builtins.genList (n: n) userNum);
|
||||
config = map
|
||||
(i: listToAttrs (map
|
||||
(attrName: { name = attrName; value = placeholder."fz-new-order/config${toString i}/${attrName}"; })
|
||||
[ "username" "password" "comment" ]))
|
||||
(builtins.genList (n: n) configNum);
|
||||
};
|
||||
};
|
||||
secrets =
|
||||
{ "fz-new-order/manager" = {}; "fz-new-order/token" = {}; }
|
||||
// (listToAttrs (map
|
||||
(i: { name = "fz-new-order/uids/user${toString i}"; value = {}; })
|
||||
(builtins.genList (n: n) userNum)))
|
||||
// (listToAttrs (concatLists (map
|
||||
(i: map
|
||||
(attrName: { name = "fz-new-order/config${toString i}/${attrName}"; value = {}; })
|
||||
[ "username" "password" "comment" ])
|
||||
(builtins.genList (n: n) configNum))));
|
||||
};
|
||||
};
|
||||
}
|
||||
254
modules/services/fz-new-order/main.cpp
Normal file
254
modules/services/fz-new-order/main.cpp
Normal file
@@ -0,0 +1,254 @@
|
||||
# include <iostream>
|
||||
# include <set>
|
||||
# include <sstream>
|
||||
# include <filesystem>
|
||||
# include <cereal/types/set.hpp>
|
||||
# include <cereal/archives/json.hpp>
|
||||
# include <fmt/format.h>
|
||||
# include <fmt/ranges.h>
|
||||
# include <httplib.h>
|
||||
# include <json/json.h>
|
||||
|
||||
std::string urlencode(std::string s)
|
||||
{
|
||||
auto hexchar = [](unsigned char c, unsigned char &hex1, unsigned char &hex2)
|
||||
{
|
||||
hex1 = c / 16;
|
||||
hex2 = c % 16;
|
||||
hex1 += hex1 <= 9 ? '0' : 'a' - 10;
|
||||
hex2 += hex2 <= 9 ? '0' : 'a' - 10;
|
||||
};
|
||||
const char *str = s.c_str();
|
||||
std::vector<char> v(s.size());
|
||||
v.clear();
|
||||
for (std::size_t i = 0, l = s.size(); i < l; i++)
|
||||
{
|
||||
char c = str[i];
|
||||
if
|
||||
(
|
||||
(c >= '0' && c <= '9')
|
||||
|| (c >= 'a' && c <= 'z')
|
||||
|| (c >= 'A' && c <= 'Z')
|
||||
|| c == '-' || c == '_' || c == '.' || c == '!' || c == '~'
|
||||
|| c == '*' || c == '\'' || c == '(' || c == ')'
|
||||
)
|
||||
v.push_back(c);
|
||||
else
|
||||
{
|
||||
v.push_back('%');
|
||||
unsigned char d1, d2;
|
||||
hexchar(c, d1, d2);
|
||||
v.push_back(d1);
|
||||
v.push_back(d2);
|
||||
}
|
||||
}
|
||||
return std::string(v.cbegin(), v.cend());
|
||||
}
|
||||
|
||||
void oneshot
|
||||
(
|
||||
const std::string& username, const std::string& password, const std::string& comment,
|
||||
const std::set<std::string>& wxuser, const std::set<std::string>& manager, const std::string& token
|
||||
)
|
||||
{
|
||||
httplib::Client fzclient("http://scmv9.fengzhansy.com:8882");
|
||||
httplib::Client wxclient("http://wxpusher.zjiecode.com");
|
||||
auto& log = std::clog;
|
||||
|
||||
try
|
||||
{
|
||||
// get JSESSIONID
|
||||
auto cookie_jsessionid = [&]() -> std::string
|
||||
{
|
||||
log << "get /scmv9/login.jsp\n";
|
||||
auto result = fzclient.Get("/scmv9/login.jsp");
|
||||
if (result.error() != httplib::Error::Success)
|
||||
throw std::runtime_error("request failed");
|
||||
auto it = result.value().headers.find("Set-Cookie");
|
||||
if (it == result.value().headers.end() || it->first != "Set-Cookie")
|
||||
throw std::runtime_error("find cookie failed");
|
||||
log << fmt::format("set_cookie JSESSIONID {}\n", it->second.substr(0, it->second.find(';')));
|
||||
return it->second.substr(0, it->second.find(';'));
|
||||
}();
|
||||
|
||||
// login
|
||||
auto cookie_pppp = [&]() -> std::string
|
||||
{
|
||||
auto body = fmt::format("method=dologinajax&rand=1234&userc={}&mdid=P&passw={}", username, password);
|
||||
httplib::Headers headers =
|
||||
{
|
||||
{ "X-Requested-With", "XMLHttpRequest" },
|
||||
{
|
||||
"User-Agent",
|
||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
|
||||
},
|
||||
{ "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" },
|
||||
{ "Origin", "http://scmv9.fengzhansy.com:8882" },
|
||||
{ "Referer", "http://scmv9.fengzhansy.com:8882/scmv9/login.jsp" },
|
||||
{ "Cookie", cookie_jsessionid }
|
||||
};
|
||||
log << "post /scmv9/data.jsp\n";
|
||||
auto result = fzclient.Post("/scmv9/data.jsp", headers, body, "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
if (result.error() != httplib::Error::Success)
|
||||
throw std::runtime_error("request failed");
|
||||
log << fmt::format("set_cookie pppp {}\n", fmt::format("pppp={}%40{}", username, password));
|
||||
return fmt::format("pppp={}%40{}", username, password);
|
||||
}();
|
||||
|
||||
// get order list
|
||||
auto order_list = [&]() -> std::map<std::string, std::pair<std::string, std::string>>
|
||||
{
|
||||
auto body = fmt::format("method=dgate&rand=1234&op=scmmgr_pcggl&nv%5B%5D=opmode&nv%5B%5D=dd_qry&nv%5B%5D=bill&nv%5B%5D=&nv%5B%5D=storeid&nv%5B%5D=&nv%5B%5D=vendorid&nv%5B%5D={}&nv%5B%5D=qr_status&nv%5B%5D=&nv%5B%5D=ddprt&nv%5B%5D=%25&nv%5B%5D=fdate&nv%5B%5D=&nv%5B%5D=tdate&nv%5B%5D=&nv%5B%5D=shfdate&nv%5B%5D=&nv%5B%5D=shtdate&nv%5B%5D=&nv%5B%5D=fy_pno&nv%5B%5D=1&nv%5B%5D=fy_psize&nv%5B%5D=10", username);
|
||||
httplib::Headers headers =
|
||||
{
|
||||
{ "X-Requested-With", "XMLHttpRequest" },
|
||||
{
|
||||
"User-Agent",
|
||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
|
||||
},
|
||||
{ "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" },
|
||||
{ "Origin", "http://scmv9.fengzhansy.com:8882"
|
||||
},
|
||||
{ "Referer", "http://scmv9.fengzhansy.com:8882/scmv9/SCM/cggl_po_qry.jsp" },
|
||||
{ "Cookie", fmt::format("{}; {}", cookie_jsessionid, cookie_pppp) }
|
||||
};
|
||||
log << "post /scmv9/data.jsp\n";
|
||||
auto result = fzclient.Post("/scmv9/data.jsp", headers, body, "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
if (result.error() != httplib::Error::Success)
|
||||
throw std::runtime_error("request failed");
|
||||
log << fmt::format("get result {}\n", result.value().body);
|
||||
std::stringstream result_body(result.value().body);
|
||||
Json::Value root;
|
||||
result_body >> root;
|
||||
std::map<std::string, std::pair<std::string, std::string>> orders;
|
||||
for (unsigned i = 0; i < root["dt"][1].size(); i++)
|
||||
{
|
||||
log << fmt::format
|
||||
(
|
||||
"insert order {} {} {}\n", root["dt"][1][i].asString(), root["dt"][2][i].asString(),
|
||||
root["dt"][4][i].asString()
|
||||
);
|
||||
orders.insert({root["dt"][1][i].asString(), {root["dt"][2][i].asString(), root["dt"][4][i].asString()}});
|
||||
}
|
||||
return orders;
|
||||
}();
|
||||
|
||||
// read order old
|
||||
auto order_old = [&]() -> std::set<std::string>
|
||||
{
|
||||
if (!std::filesystem::exists("orders.json"))
|
||||
return {};
|
||||
else
|
||||
{
|
||||
std::ifstream ins("orders.json");
|
||||
cereal::JSONInputArchive ina(ins);
|
||||
std::set<std::string> data;
|
||||
cereal::load(ina, data);
|
||||
return data;
|
||||
}
|
||||
}();
|
||||
|
||||
// push new order info
|
||||
for (const auto& order : order_list)
|
||||
if (!order_old.contains(order.first))
|
||||
{
|
||||
for (const auto& user : manager)
|
||||
{
|
||||
auto path = fmt::format
|
||||
(
|
||||
"/api/send/message/?appToken={}&content={}&uid={}",
|
||||
token, urlencode(fmt::format("push {}", order.first)), user
|
||||
);
|
||||
auto wxresult = wxclient.Get(path.c_str());
|
||||
}
|
||||
|
||||
auto body = fmt::format
|
||||
(
|
||||
"method=dgate&rand=1234&op=scmmgr_pcggl&nv%5B%5D=opmode&nv%5B%5D=ddsp_qry&nv%5B%5D=bill&nv%5B%5D={}",
|
||||
order.first
|
||||
);
|
||||
httplib::Headers headers =
|
||||
{
|
||||
{ "X-Requested-With", "XMLHttpRequest" },
|
||||
{
|
||||
"User-Agent",
|
||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
|
||||
},
|
||||
{ "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" },
|
||||
{ "Origin", "http://scmv9.fengzhansy.com:8882" },
|
||||
{ "Referer", "http://scmv9.fengzhansy.com:8882/scmv9/SCM/cggl_po_qry.jsp" },
|
||||
{ "Cookie", fmt::format("{}; {}", cookie_jsessionid, cookie_pppp) }
|
||||
};
|
||||
log << "post /scmv9/data.jsp\n";
|
||||
auto result = fzclient.Post
|
||||
("/scmv9/data.jsp", headers, body, "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
if (result.error() != httplib::Error::Success)
|
||||
throw std::runtime_error("request failed");
|
||||
log << fmt::format("get result {}\n", result.value().body);
|
||||
std::stringstream result_body(result.value().body);
|
||||
Json::Value root;
|
||||
result_body >> root;
|
||||
|
||||
std::stringstream push_body;
|
||||
double all_cost = 0;
|
||||
push_body << fmt::format
|
||||
(
|
||||
"{} {} {}店\n", comment, order.second.second.substr(order.second.second.find('-') + 1),
|
||||
order.second.first.substr(1, 2)
|
||||
);
|
||||
for (unsigned i = 0; i < root["dt"][6].size(); i++)
|
||||
{
|
||||
push_body << fmt::format
|
||||
(
|
||||
"{} {}{}\n", root["dt"][6][i].asString().substr(root["dt"][6][i].asString().length() - 4),
|
||||
root["dt"][7][i].asString(), root["dt"][5][i].asString()
|
||||
);
|
||||
// 订货金额 maybe empty ???
|
||||
if (root["dt"][10][i].asString() != "")
|
||||
all_cost += std::stod(root["dt"][10][i].asString());
|
||||
}
|
||||
push_body << fmt::format("共{:.2f}元\n", all_cost);
|
||||
log << fmt::format("push to wx {}\n", push_body.str());
|
||||
auto encoded = urlencode(push_body.str());
|
||||
|
||||
for (const auto& wxu : wxuser)
|
||||
{
|
||||
auto path = fmt::format
|
||||
("/api/send/message/?appToken={}&content={}&uid={}", token, encoded, wxu);
|
||||
auto wxresult = wxclient.Get(path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// save data
|
||||
{
|
||||
for (const auto& order : order_list)
|
||||
if (!order_old.contains(order.first))
|
||||
order_old.insert(order.first);
|
||||
std::ofstream os("orders.json");
|
||||
cereal::JSONOutputArchive oa(os);
|
||||
cereal::save(oa, order_old);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
log << ex.what() << "\n" << std::flush;
|
||||
std::terminate();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Json::Value configs;
|
||||
std::ifstream("@config_file@") >> configs;
|
||||
auto config_uids = configs["uids"];
|
||||
std::set<std::string> uids;
|
||||
for (auto& uid : config_uids)
|
||||
uids.insert(uid.asString());
|
||||
for (auto& config : configs["config"])
|
||||
oneshot
|
||||
(
|
||||
config["username"].asString(), config["password"].asString(), config["comment"].asString(),
|
||||
uids, { configs["manager"].asString() }, configs["token"].asString()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -445,124 +445,139 @@ inputs:
|
||||
(attrsToList site.value.location)))
|
||||
(filter (site: site.value.global.root == null) (attrsToList nginx.https)))))
|
||||
);
|
||||
services.nginx.virtualHosts = listToAttrs (map
|
||||
(site:
|
||||
{
|
||||
name = site.value.global.configName;
|
||||
value =
|
||||
services =
|
||||
{
|
||||
nginx.virtualHosts = listToAttrs (map
|
||||
(site:
|
||||
{
|
||||
serverName = site.name;
|
||||
root = mkIf (site.value.global.root != null) site.value.global.root;
|
||||
basicAuthFile = mkIf (site.value.global.detectAuth != null)
|
||||
inputs.config.sops.templates."nginx/templates/detectAuth/${escapeURL site.name}-global".path;
|
||||
extraConfig = mkIf (site.value.global.index != null)
|
||||
"index ${concatStringsSep " " site.value.global.index};";
|
||||
listen = map
|
||||
(listen:
|
||||
{
|
||||
addr = if listen.value.proxyProtocol then "0.0.0.0" else "127.0.0.1";
|
||||
port = with nginx.global; httpsPort
|
||||
+ (if listen.value.http2 then httpsPortShift.http2 else 0)
|
||||
+ (if listen.value.proxyProtocol then httpsPortShift.proxyProtocol else 0);
|
||||
ssl = true;
|
||||
# TODO: use proxy_protocol in 23.11
|
||||
extraParameters =
|
||||
(if listen.value.proxyProtocol then [ "proxy_protocol" ] else [])
|
||||
++ (if listen.value.http2 then [ "http2" ] else []);
|
||||
})
|
||||
(attrsToList site.value.listen);
|
||||
# do not automatically add http2 listen
|
||||
http2 = false;
|
||||
onlySSL = true;
|
||||
# TODO: disable well-known in 23.11
|
||||
useACMEHost = site.name;
|
||||
locations = listToAttrs (map
|
||||
(location:
|
||||
{
|
||||
inherit (location) name;
|
||||
value =
|
||||
name = site.value.global.configName;
|
||||
value =
|
||||
{
|
||||
serverName = site.name;
|
||||
root = mkIf (site.value.global.root != null) site.value.global.root;
|
||||
basicAuthFile = mkIf (site.value.global.detectAuth != null)
|
||||
inputs.config.sops.templates."nginx/templates/detectAuth/${escapeURL site.name}-global".path;
|
||||
extraConfig = mkIf (site.value.global.index != null)
|
||||
"index ${concatStringsSep " " site.value.global.index};";
|
||||
listen = map
|
||||
(listen:
|
||||
{
|
||||
basicAuthFile =
|
||||
let
|
||||
detectAuthList = filter
|
||||
(detectAuth: detectAuth != null)
|
||||
addr = if listen.value.proxyProtocol then "0.0.0.0" else "127.0.0.1";
|
||||
port = with nginx.global; httpsPort
|
||||
+ (if listen.value.http2 then httpsPortShift.http2 else 0)
|
||||
+ (if listen.value.proxyProtocol then httpsPortShift.proxyProtocol else 0);
|
||||
ssl = true;
|
||||
# TODO: use proxy_protocol in 23.11
|
||||
extraParameters =
|
||||
(if listen.value.proxyProtocol then [ "proxy_protocol" ] else [])
|
||||
++ (if listen.value.http2 then [ "http2" ] else []);
|
||||
})
|
||||
(attrsToList site.value.listen);
|
||||
# do not automatically add http2 listen
|
||||
http2 = false;
|
||||
onlySSL = true;
|
||||
# TODO: disable well-known in 23.11
|
||||
useACMEHost = site.name;
|
||||
locations = listToAttrs (map
|
||||
(location:
|
||||
{
|
||||
inherit (location) name;
|
||||
value =
|
||||
{
|
||||
basicAuthFile =
|
||||
let
|
||||
detectAuthList = filter
|
||||
(detectAuth: detectAuth != null)
|
||||
(map
|
||||
(type: location.value.${type}.detectAuth or null)
|
||||
nginx.global.httpsLocationTypes);
|
||||
in mkIf (detectAuthList != [])
|
||||
inputs.config.sops.templates
|
||||
."nginx/templates/detectAuth/${escapeURL site.name}/${escapeURL location.name}".path;
|
||||
root =
|
||||
let
|
||||
rootList = filter
|
||||
(root: root != null)
|
||||
(map
|
||||
(type: location.value.${type}.root or null)
|
||||
nginx.global.httpsLocationTypes);
|
||||
in mkIf (rootList != [])
|
||||
(builtins.head rootList);
|
||||
}
|
||||
// (
|
||||
if (location.value.proxy != null) then
|
||||
{
|
||||
proxyPass = location.value.proxy.upstream;
|
||||
proxyWebsockets = location.value.proxy.websocket;
|
||||
recommendedProxySettings = false;
|
||||
recommendedProxySettingsNoHost = true;
|
||||
extraConfig = concatStringsSep "\n"
|
||||
(
|
||||
(map
|
||||
(type: location.value.${type}.detectAuth or null)
|
||||
nginx.global.httpsLocationTypes);
|
||||
in mkIf (detectAuthList != [])
|
||||
inputs.config.sops.templates
|
||||
."nginx/templates/detectAuth/${escapeURL site.name}/${escapeURL location.name}".path;
|
||||
root =
|
||||
let
|
||||
rootList = filter
|
||||
(root: root != null)
|
||||
(map
|
||||
(type: location.value.${type}.root or null)
|
||||
nginx.global.httpsLocationTypes);
|
||||
in mkIf (rootList != [])
|
||||
builtins.head rootList;
|
||||
}
|
||||
// (
|
||||
if (location.value.proxy != null) then
|
||||
{
|
||||
proxyPass = location.value.proxy.upstream;
|
||||
proxyWebsockets = location.value.proxy.websocket;
|
||||
recommendedProxySettings = false;
|
||||
recommendedProxySettingsNoHost = true;
|
||||
extraConfig = concatStringsSep "\n"
|
||||
(
|
||||
(map
|
||||
(header: ''proxy_set_header ${header.name} "${header.value}";'')
|
||||
(attrsToList location.value.proxy.setHeaders))
|
||||
++ (
|
||||
if location.value.proxy.detectAuth != null || site.value.global.detectAuth != null
|
||||
then [ "proxy_hide_header Authorization;" ]
|
||||
else []
|
||||
)
|
||||
++ (
|
||||
if location.value.proxy.addAuth != null then
|
||||
let authFile = "nginx/templates/addAuth/${location.value.proxy.addAuth}";
|
||||
in [ "include ${inputs.config.sops.templates.${authFile}.path};" ]
|
||||
else [])
|
||||
);
|
||||
}
|
||||
else if (location.value.static != null) then
|
||||
{
|
||||
index = mkIf (location.value.static.index != [])
|
||||
(concatStringsSep " " location.value.static.index);
|
||||
tryFiles = mkIf (location.value.static.tryFiles != [])
|
||||
(concatStringsSep " " location.value.static.tryFiles);
|
||||
}
|
||||
else if (location.value.php != null) then
|
||||
{
|
||||
extraConfig =
|
||||
''
|
||||
fastcgi_pass ${location.value.php.fastcgiPass};
|
||||
fastcgi_split_path_info ^(.+\.php)(/.*)$;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
include ${inputs.config.services.nginx.package}/conf/fastcgi.conf;
|
||||
'';
|
||||
}
|
||||
else if (location.value.return != null) then
|
||||
{
|
||||
return = location.value.return;
|
||||
}
|
||||
else if (location.value.cgi != null) then
|
||||
{
|
||||
extraConfig =
|
||||
''
|
||||
include ${inputs.config.services.nginx.package}/conf/fastcgi.conf;
|
||||
fastcgi_pass unix:${inputs.config.services.fcgiwrap.socketAddress};
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
'';
|
||||
}
|
||||
else {}
|
||||
);
|
||||
})
|
||||
(attrsToList site.value.location));
|
||||
};
|
||||
})
|
||||
(attrsToList nginx.https));
|
||||
(header: ''proxy_set_header ${header.name} "${header.value}";'')
|
||||
(attrsToList location.value.proxy.setHeaders))
|
||||
++ (
|
||||
if location.value.proxy.detectAuth != null || site.value.global.detectAuth != null
|
||||
then [ "proxy_hide_header Authorization;" ]
|
||||
else []
|
||||
)
|
||||
++ (
|
||||
if location.value.proxy.addAuth != null then
|
||||
let authFile = "nginx/templates/addAuth/${location.value.proxy.addAuth}";
|
||||
in [ "include ${inputs.config.sops.templates.${authFile}.path};" ]
|
||||
else [])
|
||||
);
|
||||
}
|
||||
else if (location.value.static != null) then
|
||||
{
|
||||
index = mkIf (location.value.static.index != [])
|
||||
(concatStringsSep " " location.value.static.index);
|
||||
tryFiles = mkIf (location.value.static.tryFiles != [])
|
||||
(concatStringsSep " " location.value.static.tryFiles);
|
||||
}
|
||||
else if (location.value.php != null) then
|
||||
{
|
||||
extraConfig =
|
||||
''
|
||||
fastcgi_pass ${location.value.php.fastcgiPass};
|
||||
fastcgi_split_path_info ^(.+\.php)(/.*)$;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
include ${inputs.config.services.nginx.package}/conf/fastcgi.conf;
|
||||
'';
|
||||
}
|
||||
else if (location.value.return != null) then
|
||||
{
|
||||
return = location.value.return;
|
||||
}
|
||||
else if (location.value.cgi != null) then
|
||||
{
|
||||
extraConfig =
|
||||
''
|
||||
include ${inputs.config.services.nginx.package}/conf/fastcgi.conf;
|
||||
fastcgi_pass unix:${inputs.config.services.fcgiwrap.socketAddress};
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
'';
|
||||
}
|
||||
else {}
|
||||
);
|
||||
})
|
||||
(attrsToList site.value.location));
|
||||
};
|
||||
})
|
||||
(attrsToList nginx.https));
|
||||
fcgiwrap = mkIf
|
||||
(
|
||||
filter (site: site != []) (map
|
||||
(site: filter (location: location.value.cgi != null) (attrsToList site.value.location))
|
||||
(attrsToList nginx.https))
|
||||
!= []
|
||||
)
|
||||
{
|
||||
enable = true;
|
||||
user = inputs.config.users.users.nginx.name;
|
||||
group = inputs.config.users.users.nginx.group;
|
||||
};
|
||||
};
|
||||
nixos.services =
|
||||
{
|
||||
nginx =
|
||||
@@ -608,11 +623,6 @@ inputs:
|
||||
(site: { inherit (site) name; value.group = inputs.config.services.nginx.group; })
|
||||
(attrsToList nginx.https));
|
||||
};
|
||||
fcgiwrap.enable =
|
||||
filter (site: site != []) (map
|
||||
(site: filter (location: location.value.cgi != null) (attrsToList site.value.locations))
|
||||
(attrsToList nginx.https))
|
||||
!= [];
|
||||
};
|
||||
sops =
|
||||
let
|
||||
|
||||
@@ -52,6 +52,30 @@ freshrss:
|
||||
chn: ENC[AES256_GCM,data:XGcgfuRozJ/xowtmFPSW,iv:yZ9LTuVE8dGyrtE3vxLA2jLErvmt67XC0jefl1njiOM=,tag:J5d+oGFWhfXEFwVOnsJ2iA==,type:str]
|
||||
huginn:
|
||||
invitationCode: ENC[AES256_GCM,data:+m2AabRzUiCFy3MAKTB8d1IE05WHTcmZ,iv:ccdIPHl9N+bvPR/QCwZUwZOfWTeW6gWhhBjOpL85JRg=,tag:Ir2085K04XUGkAuoCG+7VQ==,type:str]
|
||||
fz-new-order:
|
||||
manager: ENC[AES256_GCM,data:qZc5U3SZQPWzcKVjN2+A2qWNae4GItcjvEQFgkThvIQ=,iv:fJpiUlViiUg1ea/zGhgedQG7TeTbeb9dPviYoiUBLqI=,tag:6T7rgJflsjgK++28SgsLtg==,type:str]
|
||||
token: ENC[AES256_GCM,data:qhwWRflJbW1QMOhiPfbTIrEdQJyVtfZ1QycCgstdKD1Nh40=,iv:GvZ8MJig64l34jkvuJbMMjyNaPT5yz0/pFCc6KEPTvA=,tag:cMXo/6F9thl8k2iAhT507Q==,type:str]
|
||||
uids:
|
||||
#ENC[AES256_GCM,data:WJszzA==,iv:KvyEnUu69+L5ZxNbRmjtP2R+8lHKgdlMN0WuvDbYgE4=,tag:LP2FJ2HXWZJmTdvXpHflVQ==,type:comment]
|
||||
user0: ENC[AES256_GCM,data:Qw18Ht6qXo3n7DD9NgNB+3IRbCmKuvJQiK5UBsg/FC8=,iv:TeeTcR0tnRrniySqKrsKfOfr2JO7+kqS3iETdCFX5ZA=,tag:rRo2yNku9JWxmILWBS/Wyw==,type:str]
|
||||
#ENC[AES256_GCM,data:O3DOE3jFCg==,iv:9shUoHCLXsJPKHELlyWdreouEcyOqhsfVI2KaqwC4CU=,tag:tYKVv+/DuesSijZwWGdrig==,type:comment]
|
||||
user1: ENC[AES256_GCM,data:vY4qTPNqdFp2H348jAgvwKktywdVVvQK/lR2NgRE4Ho=,iv:DrweeSEJ5ETomIkRtkcVboiQindzBoxvxjlSmrQIfI8=,tag:sMz1ITHkDclBc4OY91dMGg==,type:str]
|
||||
#ENC[AES256_GCM,data:yeA9zF8Tug==,iv:VZuWLZnt1RBmkBWudKVvgJkYfqxIj/umEHVCfR6IG3k=,tag:1kj7HyjVT59n05VYJ1uP+w==,type:comment]
|
||||
user2: ENC[AES256_GCM,data:7hlq1FEauGcKkStREDbxA3tOA5NmFo9AbXiOPUt+kZ4=,iv:urOP3ENSviWRKDIWGc1P5PkEtkoBSCSYlgGqJQznp8s=,tag:NNKCW5bFPY7t/PC7dsSJwg==,type:str]
|
||||
#ENC[AES256_GCM,data:4G7DyLVVgQ==,iv:Ht/exln1QtL2BxjCaOTIXHRPDiSFYP4zIa7VaeMCuhE=,tag:btVLXf+WS/YgzRFbVFoAfQ==,type:comment]
|
||||
user3: ENC[AES256_GCM,data:nBTbmp9OP14ayVBz1UGC5g76txfUwxL2NPQCKGxsQyw=,iv:2B8ISdT+8WpfeiU9peKoMlpwcRoGZVh11VyAnS9IKP4=,tag:uBMxqrPlb6TaftnAMqodKw==,type:str]
|
||||
#ENC[AES256_GCM,data:TGrZBuCRgQ==,iv:9IOJ3Bkw9udS/y93TTtZ9o79aDq3Bb+DMEogJG77iqA=,tag:S/XcPX1f89IyfZnMoR9s/A==,type:comment]
|
||||
user4: ENC[AES256_GCM,data:LVendDEBlPUCkXPfgbYf2X0EgJsAdLKjAudXeAgy2Is=,iv:bR0emkQa6OHUP1ucgAvJU0eEop0gp+3rwDB5XJhh4+s=,tag:YZsW9Yyr+ey9AbTO3ucWDg==,type:str]
|
||||
#ENC[AES256_GCM,data:b4iJ73sUoQ==,iv:A2hmi7lCR15E5jVR8E71GQuHgF4TdjDuQadXOtBon6k=,tag:eopTJdjN16u7PtpZdhKymQ==,type:comment]
|
||||
user5: ENC[AES256_GCM,data:wG4awLnfB4B0qLWG6Aj+OslLMnViPjIzicfB4ZzkZPA=,iv:b9C1IDmZTMV0RYXqkM/Y3khZeSQEOISrQyPjhQe3WKM=,tag:cRMtLNU6TCwTQG4UVhvTng==,type:str]
|
||||
config0:
|
||||
username: ENC[AES256_GCM,data:p8+q8u1A,iv:9s52kS5yLB4vQuGVXNtA4amZqT3eHTTybsbsQZRiFnk=,tag:7SA4SEzMHpP9H/rwoE+UJQ==,type:str]
|
||||
password: ENC[AES256_GCM,data:58+gFodT,iv:ohZlT1BwnzCYv84xHgFsLRkiPMpE8lB8QVHwr0QtDWc=,tag:XF047RnXs6IbKsTnsm0D6g==,type:str]
|
||||
comment: ENC[AES256_GCM,data:T4XcbF1c,iv:hHdsMjU8rzPiduhT05v98pgDqxRW/Km5zmXCEZaT2AI=,tag:LWvwIEfbW2IuDELr4fEXKg==,type:str]
|
||||
config1:
|
||||
username: ENC[AES256_GCM,data:xWP1cesh,iv:11KFZ/J9PScz/oW2+H5BWgw0+ETkCXlcYOMuPpgjEs0=,tag:HswEVzm6ElRjIDsZyEfZcA==,type:str]
|
||||
password: ENC[AES256_GCM,data:Da/E7ZeZ,iv:gIoheXeTErV3+CtZSEDsX7pGzRahHWlKYQ6QZ6W2eu8=,tag:0oQzQ5DJiS2hqMQfU6JRWw==,type:str]
|
||||
comment: ENC[AES256_GCM,data:etfZKwbh,iv:XqqF3D0PpCPd2Q/CCu/PAH4SrvXAOu+lIXvSht/KfKk=,tag:7jyG33foxneRK2wvI/5uBg==,type:str]
|
||||
sops:
|
||||
kms: []
|
||||
gcp_kms: []
|
||||
@@ -76,8 +100,8 @@ sops:
|
||||
SnFHS1Z0SXUzTFdEd29KTy9DU3Y3R0UKfhh+rUmWDrf+UGjclP57dHipPLFoXSqy
|
||||
HdelmfV6q4/c7ppx2E+oZw3VNgoZCsrxxzYZfwxHJiZb+5vkE0D8iA==
|
||||
-----END AGE ENCRYPTED FILE-----
|
||||
lastmodified: "2023-11-12T08:55:55Z"
|
||||
mac: ENC[AES256_GCM,data:AlydFHt0M965B+1r7HxICO730giPv5hAqQZX0K0hqetmq06Z2hmSFaHdTbZx8nBEqJTbzUekN9w9bckzxnLNf+VGbhdAVzIhvU+zoXs1324UdtJqze2w3kPUYhzyC3ovubb0RRd81pgozvGXRTJ10WVcXpI7j2P1DjpPWp6hmHg=,iv:irfEAtnf0U2oMHdf1oNSLD7eqWKdXiLJBlCmsutnb7k=,tag:VkmZ8hWgOZhwfM7p8V4stA==,type:str]
|
||||
lastmodified: "2023-11-15T06:17:51Z"
|
||||
mac: ENC[AES256_GCM,data:a2j3oIH7U4xVxc1bua/v1ObK4KdPduf1x91e/+6QZR2OUbtQqqP2OUAZ5oypO3/OWY6BNeUDCLgBK+Xc9PZzQgtVmpEh288nkvDjosPmigsn+PMMDAbEqJ4yIbNUzRjP0snj6S2gz4ooPHFnneFZA1Vz951khA5bqL/IU93hgwk=,iv:QFgbpJ2K5WVzG4w6GC67ucA7EUErLyyldmg69x391LI=,tag:ob/HRflIv6kVL+IxSy0amw==,type:str]
|
||||
pgp: []
|
||||
unencrypted_suffix: _unencrypted
|
||||
version: 3.7.3
|
||||
|
||||
Reference in New Issue
Block a user