Fossil Forum
Post: Robot resist setting for CGI server?
I run fossil in CGI mode serving a directory and have a version of this running on my LAN server as well as another on a remote VPS. It would be nice if there was a way to disable robot checking via a CGI option for my local server across all repos while maintaining it on the public remote one.
Do I understand correctly that we are talking about two different machines here? One machine is on your LAN and cannot been seen by the open internet and the other is out on a public VPS and can be seen?
So, in other words, you have one set of repositories for which you want to have robot defenses turned off and another for which you want them turned on? You are not trying to turn robot defenses on or off based on the IP address from which the request is arriving?
If that is the case, why not just run:
~~~ fossil all set robot-restrict off ~~~
On the machine that lives inside your LAN, thus turning off robot defenses on all those repositories in a single command?
But maybe I don't understand the problem you are trying to solve?
That's correct regarding the machines. Since fossil on the both servers are just running as CGI and are never actually opened properly on the system with fossil open, the fossil command itself is unaware of them. fossil all info for example, returns nothing.
The set command also doesn't allow for specifying the repo so I can't write a script that just loops through a directory listing and sets it either.
If it can help, I made this bash helper function a while ago which take a repository file as argument and use fossil sql to set a value in config table.
# conf_set: Update value in config table (insert row if config doesn't exist)
# $1: repository file
# $2: config name
# $3: config val
function conf_set
{
if [[ -z "$3" ]]; then
echo "conf_insert: missing arguments"
exit 1
fi
typeset -r rep=$1
shift
typeset -r conf_name=$1
shift
typeset -r conf_val="$*" # rest of argument is the conf val.
typeset -r orig_cfg="$(fossil sql -R "$rep" "SELECT value FROM config WHERE name = '$conf_name';" | tr -d "'")"
if [[ -z "$orig_cfg" ]]; then
fossil sql -R "$rep" "INSERT INTO config (name, value, mtime) VALUES ('$conf_name', '$conf_val', $(date +%s));"
return
fi
if [[ "$orig_cfg" != "$conf_val" ]]; then
fossil sql -R "$rep" "UPDATE config set value='$conf_val', mtime=$(date +%s) WHERE name='$conf_name';"
return
fi
#echo "Value already exist with proper value: '$conf_name' = $orig_cfg (new val: $conf_val)"
}
To be used like the following:
conf_set path/to/repo.fossil robot-restrict "off"
So in a bash script, you could easily loop though all the repo and call this bash function for each repo.
The set command also doesn't allow for specifying the repo
Yes it does. The -R option:
~~~ fossil set -R $REPO robot-restrict off ~~~
But further, you might notice that my command above was not "fossil set" but rather "fossil all set", which should automatically operate on all of your repositories. Fossil tries to keep track of all of your repositories (in the $HOME/.config/fossil.db file) and so there are a lot of operations that you can apply to all of your repositories all at once. See the "fossil all" docs. Typical uses include:
fossil all syncfossil all repackfossil all changes
And, of course:
fossil all set ...
The -R option isn't listed in the help for set like it is with other commands, but thanks for letting me know.
I feel like I may be misunderstanding something else though. Both of these machines have only ever run fossil via CGI and never directly opened a repo. While the fossil.db files does exist in .config, it only contains an empty global_config table. The CGI web page works fine so they're definitely being read and are working properly. You're saying in this setup fossil should still be tracking those repos normally? I wonder if I've set something wrong but I don't think there's anything peculiar about my cgi script which I copied from the docs
#!/usr/bin/fossil
directory: /home/user/fossil_repos
The -R option isn't listed in the help for set like it is with other commands
It's one of the few "almost global" options. It works for just about any command which can work independently of a checkout.
Both of these machines have only ever run fossil via CGI and never directly opened a repo. While the fossil.db files does exist in .config, it only contains an empty global_config table.
To the very best of my recollection, remote-accessed fossil never opens the global config db. Only CLI apps use it (he says with about 99% certainty) so yours would be empty if it exists at all.
Yeah, that was what I was trying to get across. Which is why the option of using the all command doesn't seem like the correct answer.
However, now knowing that the -R does in fact exist, I've solved the problem with a simple find/xargs command.
For anyone who has a similar need in the future, preferably in your repo directory:
find . -name "*.fossil" | xargs -I REPO fossil set -R REPO robot-restrict off
You can use the "fossil add ..." command to manually add in all your repositories, after when the other "fossil all" variants will work.
You can use the "fossil all add ..." command to manually add in all your repositories, after when the other "fossil all" variants will work.
(edited to correct the command name)
Didn't know that existed, will remember for the future thanks :D