Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added check for USE_HTTP_PROXY_FOR_HTTPS #69

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
1f7e34c
update readme
himanshub16 Nov 13, 2017
2342e65
Add gitter chat link toreadme
himanshub16 Nov 27, 2017
b39c0fd
added profiles feature, exit on invalid option
akspi Nov 28, 2017
da8ecd8
fixed bug while storing config, input order updated sample conf
akspi Dec 9, 2017
5ab36be
Change protocol https to http for 'https proxy'
Jan 11, 2018
76ee7e6
fix https proxy for npm, closes #41
himanshub16 Jan 13, 2018
922d04f
added immediate exit if config not provided
akspi Dec 12, 2017
14a962f
Reposition statement to appropriate place
himanshub16 Jan 13, 2018
a59cd1e
Change protocol for https to http
himanshub16 Jan 20, 2018
a18ccf5
remove whitespaces
himanshub16 Apr 4, 2018
f818aab
update readme for config files
himanshub16 Apr 4, 2018
9d2bf3b
update readme with remarks for v3
himanshub16 Apr 4, 2018
5aeee96
cleanup
himanshub16 Apr 4, 2018
393b46a
update readme
himanshub16 Apr 4, 2018
8f3caaa
Update README.md
himanshub16 Apr 4, 2018
140c956
Revert "cleanup"
himanshub16 Jun 27, 2018
80cf832
major refactor and update control flow
himanshub16 Jun 27, 2018
3d74694
relocate source to conform with C includes
himanshub16 Jul 6, 2018
a7f55fd
handle configs and global variables
himanshub16 Jul 21, 2018
fe91336
update bash/zsh to v3
himanshub16 Nov 12, 2018
0883f91
update all scripts to v3
himanshub16 Nov 13, 2018
c767a68
fix main.sh
himanshub16 Nov 13, 2018
3f25cba
apply encosing quotes to config values
himanshub16 Nov 13, 2018
ef43e99
minor changes and cleanup
himanshub16 Nov 13, 2018
8ebaffe
fixed incorrect gsettings parameters
himanshub16 Nov 13, 2018
0396656
update readme with usage
himanshub16 Nov 13, 2018
604b152
fix errors messages in gsettings by quoting variables
himanshub16 Nov 25, 2018
58f796f
have an installation mechanism
himanshub16 Nov 25, 2018
6250217
don't show source messages when listing for bash/zsh
himanshub16 Nov 25, 2018
9a5d0ce
remove gsettings error when list
himanshub16 Nov 25, 2018
81e5741
fix infinite recursion when setting for all
himanshub16 Nov 25, 2018
70980b3
fix multiple targets getting read as one
himanshub16 Nov 25, 2018
7667662
add *.local to default no_proxy
himanshub16 Dec 4, 2018
96dae35
use http_proxy for https_proxy (#41 and #42)
himanshub16 Dec 4, 2018
b48a331
add workaround when sudo unavailable (closes #27)
himanshub16 Dec 4, 2018
2a09151
avoid the star as doesn't work everywhere
himanshub16 Dec 4, 2018
0cf5049
update readme
himanshub16 Dec 4, 2018
b6f2ab4
update readme
himanshub16 Dec 4, 2018
83bf0d6
show warning for shared system when saving password
himanshub16 Dec 4, 2018
06c51f7
add asciiname video
himanshub16 Dec 4, 2018
80f819c
added docker support
Jan 16, 2019
dfd58b3
fix identation
himanshub16 Jan 21, 2019
74e845d
invoke script with sudo instead of inside it
himanshub16 Jan 21, 2019
cdeb2c2
[docker] make config dir if not exists
himanshub16 Jan 21, 2019
1b43af9
refactor and work without temp file and sudo
himanshub16 Jan 21, 2019
c5e6c44
pass env vars to scripts running with sudo
himanshub16 Jan 21, 2019
63bc044
use http proxy for https when asked
himanshub16 Jan 21, 2019
c420a65
update reamde
himanshub16 Jan 21, 2019
46034ec
fix dropbox set command
himanshub16 Jan 21, 2019
c90807c
update video demo
himanshub16 Jan 21, 2019
a3db787
added missing $ for _no_proxy
Jan 22, 2019
c980da3
Fixed wrong validation
Jan 22, 2019
aa54817
fix #62 _all_ handling for programs using sudo
himanshub16 Jan 22, 2019
bccde27
added check for USE_HTTP_PROXY_FOR_HTTPS
Jan 23, 2019
73a5232
added check for USE_HTTP_PROXY_FOR_HTTPS
Jan 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 25 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
## ProxyMan
## ProxyMan [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/proxyman-linux/Lobby)

### Configuring proxy made so simple on Linux ([releases](https://github.com/himanshub16/ProxyMan/releases/))

(Download [here](https://github.com/himanshub16/ProxyMan/releases/latest/))

#### Usage :
* Download the [zip from here](https://github.com/himanshub16/ProxyMan/releases/latest).
* Extract the zip, open the folder in terminal.
* Enter the following command
`
bash main.sh
`
v3 is ready with new features, necessary improvements, updates, restructured code and much better experience. :tada:

![Screenshot](https://raw.githubusercontent.com/himanshub16/ProxyMan/master/screenshot.png)
## How to use it
[![asciicast](https://asciinema.org/a/CVha4PPMdjkU7a1XihD9PItrz.png)](https://asciinema.org/a/CVha4PPMdjkU7a1XihD9PItrz)

# FAQ
* **Why do someone need it?**
* Download and install with single-step process.
```./install```

Because many times, setting up proxy on Linux sucks (esp. authenticated proxies). There are a lot of locations to configure. This tool reduces your effort by setting the proper configuration at the desired place.
Proxyman is now available in your path.
Open a new terminal window and start playing.

* **For which softwares the settings by ProxyMan is effective?**
* Set proxy
```proxyman set```

ProxyMan sets proxy for `apt`, `dnf`, `bashrc`, `npm`, `git`, `dropbox`, `/etc/environment`, `gsettings`.
* Save your settings for later use.
* View your saved configs
```proxyman configs```
* Load your previously saved config - say you saved it by the name *point4*.
```proxyman load point4```

* **There is some application/location it does not support. Any workaround?**
## What's new?
* Saved configs made more organized and works flawlessly.
* Installation script makes it available in your path. Just call the command `proxyman`, no `cd` to your downloads.
* Lots of issues got closed.
* Restructured codebase with better code quality than before - easier to maintain.

Why not? Everything is possible. Just raise an issue [here](https://github.com/himanshub16/ProxyMan/issues).
If you are a developer, then your contributions are welcome.

* **My distro works like charm. I don't need it.**
## Why still a release candidate?
If you find any bugs/edge-cases not taken care of :see_no_evil:, feel free to open an [issue](https://github.com/ProxyMan/issues).
:smiley:

It's great that your distro supports everything. However, many disros do not support authenticated proxy settings.
Moreover, there are several apps which don't use system proxy on certain platforms and need their own workaround.

For older version, checkout [branch v1](https://github.com/himanshub16/ProxyMan/tree/v1).
To download older versions, checkout releases tagged v1.* [here](https://github.com/himanshub16/ProxyMan/releases).

#### What's new in v2?
* Modular approach. Individual scripts handle individual targets requiring proxy settings.
* This means, a script can be for a single application/domain can be created and easily integrated with main.sh, without much modifications in main.sh (which was not available in v1).
* No issues of privileges for individual scripts. Main script is responsible of executing child script with required privileges.


NOTE : It does not support PAC proxy using "proxy configuration URL". It is for setting up "manual" proxy.

#### A GUI version is under progress. However, it is not ready. If you like to contribute, you can checkout to the [gui branch](https://github.com/himanshub16/ProxyMan/tree/gui) of this project.
### DISCLAIMER
Please don't save your passwords on public machines. Instead use proxyman without providing password and log-in from the browser.
150 changes: 53 additions & 97 deletions apt.sh
Original file line number Diff line number Diff line change
@@ -1,124 +1,80 @@
#!/bin/bash
#
# If you have found some issues, or some feature request :
# Raise them here : https://github.com/himanshub16/ProxyMan/issues
#
# expected command line arguments
#
# Created by "Himanshu Shekhar"
# For ProxyMan "https://github.com/himanshub16/ProxyMan/"
#
# convention to be followed across extension made / to be made
# include this comment section in all plugins to avoid confusions while coding
#
# plugin to set "apt" proxy settings for ProxyMan
#
# The arguments are given in bash syntax to maintain universality and ease
# across all UNIX systems.
# Your language can use it's respective syntax for
# arguments and comments.
# If you don't need any particular proxy settings, ignore the variables.

# $# : number of arguments
# $1 : http_host
# if this argument is "unset", proxy settings should be unset.

# $2 : http_port
# $3 : use_same ; "y" or "n"
# $4 : use_auth
# $5 : username ; send empty string if not available
# $6 : password ; send empty string if not available
#
# if use same is yes, then no further arguments are considered
#
# $7 : https_host
# $8 : https_port
# $9 : ftp_host
# $10 : ftp_port
# privileges has to be set by the process which starts this script

# here your code starts

# privileges has to be set by the process which starts this script
CONF_FILE="/etc/apt/apt.conf"

fix_new_line() {
if [[ $(tail -c 1 "$1" | wc --lines ) = 0 ]]; then
if [[ $(tail -c 1 "$CONF_FILE" | wc --lines ) = 0 ]]; then
echo >> "$1"
fi
}

list_proxy() {
# inefficient way as the file is read twice.. think of some better way
echo
echo -e "\e[1m APT proxy settings \e[0m"
lines="$(cat /etc/apt/apt.conf | grep proxy -i | wc -l)"
if [ "$lines" -gt 0 ]; then
cat /etc/apt/apt.conf | grep proxy -i | sed -e "s/Acquire//g" -e "s/\:\:/\ /g" -e "s/\;//g"
else
echo -e "\e[36m None \e[0m"
fi
# inefficient way as the file is read twice.. think of some better way
echo
echo "${bold}APT proxy settings : ${normal}"
lines="$(cat $CONF_FILE | grep proxy -i | wc -l)"
if [ "$lines" -gt 0 ]; then
cat "$CONF_FILE" | grep proxy -i | wc -l
else
echo "${red}None${normal}"
fi
}

unset_proxy() {
if [ ! -e "/etc/apt/apt.conf" ]; then
return
fi
if [ "$(cat /etc/apt/apt.conf | grep proxy -i | wc -l)" -gt 0 ]; then
sed "/Proxy/d" -i /etc/apt/apt.conf
fi
if [ ! -e "$CONF_FILE" ]; then
return
fi
if [ "$(cat $CONF_FILE | grep proxy -i | wc -l)" -gt 0 ]; then
sed -E "/^Acquire::(.)*::Proxy/d" $CONF_FILE -i
fi
}

set_proxy() {
if [ ! -e "/etc/apt/apt.conf" ]; then
touch "/etc/apt/apt.conf"
fi
var=
if [ "$4" = "y" ]; then
var="$5:$6@"
fi
echo -n "" > apt_config.tmp
if [ "$3" = "y" ]; then
newvar="://$var$1:$2"
echo "Acquire::Http::Proxy \"http$newvar\";" >> apt_config.tmp
echo "Acquire::Https::Proxy \"https$newvar\";" >> apt_config.tmp
echo "Acquire::Ftp::Proxy \"ftp$newvar\";" >> apt_config.tmp

fix_new_line "/etc/apt/apt.conf"
cat apt_config.tmp | tee -a /etc/apt/apt.conf > /dev/null
rm apt_config.tmp
return
unset_proxy
if [ ! -e "$CONF_FILE" ]; then
touch "$CONF_FILE"
fi

elif [ "$3" = "n" ]; then
echo "Acquire::Http::Proxy \"http://$var$1:$2\";" >> apt_config.tmp
echo "Acquire::Https::Proxy \"https://$var$7:$8\";" >> apt_config.tmp
echo "Acquire::Ftp::Proxy \"ftp://$var$9:$10\";" >> apt_config.tmp
local stmt=""
if [ "$use_auth" = "y" ]; then
stmt="${username}:${password}@"
fi

cat apt_config.tmp | tee -a /etc/apt/apt.conf > /dev/null
rm apt_config.tmp
return
fi
# caution: do not use / after stmt
echo "Acquire::Http::Proxy \"http://${stmt}${http_host}:${http_port}\"" \
>> "$CONF_FILE"
if [ "$USE_HTTP_PROXY_FOR_HTTPS" = "true" ]; then
echo "Acquire::Https::Proxy \"http://${stmt}${https_host}:${https_port}\";" \
>> "$CONF_FILE"
else
echo "Acquire::Https::Proxy \"https://${stmt}${https_host}:${https_port}\";" \
>> "$CONF_FILE"
fi
echo "Acquire::Ftp::Proxy \"ftp://${stmt}${ftp_host}:${ftp_port}\"" \
>> "$CONF_FILE"
}


apt_available="$(which apt)"
if [ "$apt_available" = "" ]; then
exit
which apt &> /dev/null
if [ "$?" != 0 ]; then
exit
fi


if [ "$#" = 0 ]; then
exit
fi

if [ "$1" = "unset" ]; then
# that's what is needed
unset_proxy
exit
# toggle proxy had issues with commenting and uncommenting
# dropping the feature currently
elif [ "$1" = "list" ]; then
list_proxy
exit
exit
fi

unset_proxy
set_proxy $1 $2 $3 $4 $5 $6 $7 $8 $9 $10
what_to_do=$1
case $what_to_do in
set) set_proxy
;;
unset) unset_proxy
;;
list) list_proxy
;;
*)
;;
esac
27 changes: 27 additions & 0 deletions bash-zsh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

which bash &> /dev/null
first="$?"

which zsh &> /dev/null
second="$?"

if [ "$#" = 0 ]; then
exit
fi

if [ "$first" = 0 ]; then
bash shellrc.sh "$1" "$HOME/.bashrc"
if [ ! "$1" = "list" ]; then
echo "To activate in current terminal window"
echo "run ${bold}source ~/.bashrc${normal}"
fi
fi

if [ "$second" = 0 ]; then
bash shellrc.sh "$1" "$HOME/.zshrc"
if [ ! "$1" = "list" ]; then
echo "To activate in current terminal window"
echo "run ${bold}source ~/.zshrc${normal}"
fi
fi
Loading