14#define WDEBUG(...) Ase::debug ("webui", __VA_ARGS__)
27 bool snap_workaround =
true;
30 snap_workaround =
false;
31 if (snap_workaround) {
32 basedir = Path::xdg_dir (
"DOWNLOAD") +
"/." + executable;
34 "This directory only exists to enable temporary file exchange with\n"
35 "snap packages which are unable to read from ~/.cache/.\n"
36 "Feel free to remove this directory in its entirety.\n";
38 !Path::stringwrite (basedir +
"/README", readme,
true)) {
45 const String query = token.
empty() ?
"" :
"?token=" + token;
49 "<html><!--@@TEMPFILE_PID=%d@@-->\n"
50 "<head><title>%s Authentication Redirect</title>\n"
51 "<meta http-equiv=\"refresh\" content=\"0; url=%s\">\n"
53 "<h1>%s Authentication Redirect</h1>\n\n"
54 "<p>Redirecting to %s: <a href=\"%s\">%s</a></p>\n"
55 "<hr><address>%s</address>\n"
56 "<hr></body></html>\n",
57 getpid(), ua, link + query, ua, ua, link + query, link, ua);
59 if (!Path::stringwrite (html_file, html_text,
true, 0600))
74 if (mode ==
"chromium" || mode ==
"google-chrome")
77 argv.push_back (browser_name);
80 return {
errno,
"mkdtemp" };
81 const std::string user_data_dir_arg =
"--user-data-dir=" + temp_dir;
84 for (
const auto arg : {
85 "--incognito",
"--no-first-run",
"--no-experiments",
86 "--no-default-browser-check",
"--disable-extensions",
"--disable-sync",
88 "--bwsi",
"--new-window" })
90 argv.push_back (user_data_dir_arg);
93 else if (mode ==
"htmlgui")
97 argv.push_back (
"--no-sandbox");
100 else if (mode ==
"none" or mode ==
"" or mode ==
"wait")
106 ErrorReason ereason =
spawn_process (argv, &child_pid, SIGTERM);
110 loop->exec_sigchld (child_pid,
111 [onclose] (pid_t pid,
int status)
114 if (WIFEXITED (status))
116 else if (WIFSIGNALED (status))
119 log (
"WebUI: child process pid=%d exited: %s", pid, state);
120 atquit_del_killl_pid (pid);
125 log (
"WebUI: started %s pid=%d: %s", browser_name, child_pid, url);
bool check(const String &file, const String &mode)
String cache_home()
Get the $XDG_CACHE_HOME directory, see: https://specifications.freedesktop.org/basedir-spec/latest.
The Anklang C++ API namespace.
std::string string_format(const char *format, const Args &...args) __attribute__((__format__(__printf__
Format a string similar to sprintf(3) with support for std::string and std::ostringstream convertible...
void atquit_add_removal(const std::string &filename)
Remove filename (or directory) when the program terminates.
ErrorReason spawn_process(const std::vector< std::string > &argv, pid_t *child_pid, int pdeathsig)
Span a child process after cleaning up the environment.
String string_capitalize(const String &str, size_t maxn, bool rest_tolower)
Capitalize words, so the first letter is upper case, the rest lower case.
std::string anklang_runpath(RPath rpath, const String &segment)
Retrieve various resource paths at runtime.
std::string String
Convenience alias for std::string.
void cleanup_orphaned_tempfiles(const std::string &directory)
Delete all files that contain @TEMPFILE_PID=d@ without a running pid_t d.
void atquit_add_killl_pid(int pid)
Kill pid when the program terminates.
std::string create_tempfile_dir(const std::string &basename)
Create temporary directory under /tmp, scheduled for removal atquit.