CPAN first launch (Proxy Configuration) - perl

i need to run cpan trough proxy but when i try to configure i got errors and cant enter to cpan for the first time
root#srv-linux01:~# cpan
CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.
Would you like to configure as much as possible automatically? [yes] no
On proxy settings:
If you're accessing the net via proxies, you can specify them in the
CPAN configuration or via environment variables. The variable in
the $CPAN::Config takes precedence.
<ftp_proxy>
Your ftp_proxy? [] http://username:password#proxyIP:Port/ <---- is ok the information?
<http_proxy>
Your http_proxy? [] http://username:password#proxyIP:Port/ <---- is ok the information?
<no_proxy>
Your no_proxy? []
If your proxy is an authenticating proxy, you can store your username
permanently. If you do not want that, just press ENTER. You will then
be asked for your username in every future session.
Your proxy user id? [] <---- username is needed again?
Your password for the authenticating proxy can also be stored
permanently on disk. If this violates your security policy, just press
ENTER. You will then be asked for the password in every future
session.
Your proxy password?
And before that i get this.
Fetching with HTTP::Tiny:
http://www.perl.org/CPAN/MIRRORED.BY.gz
Error downloading with HTTP::Tiny: Not a CODE reference at /usr/share/perl/5.18/CPAN/HTTP/Client.pm line 112, <STDIN> line 65.
Im using Ubuntu Server 14.04 LTS and Perl 5.18.2
Thanks

Yeah, this is pretty exasperating.
This SO answer suggests that maybe installing LWP (and its 18 dependencies) makes the problem better. Gosh, I'm glad I didn't have to resort to that.
The issue I had with this was that I already had http_proxy, https_proxy, and the uppercase versions of both of those set (and exported) in my environment. Just about every other program (including wget and curl) is works fine when these environment variables are present. It made no sense to have to set these again, and then still have CPAN fail, when it's obviously calling out to wget!
What did finally work for me was to follow the instructions here, setting the CPAN http_proxy config setting to the empty string. (I also had previously removed the proxy username and password settings by hand-editing ~/.cpan/CPAN/MyConfig.pm.)
$ cpan # or perl -MCPAN -e shell
cpan[1]> o conf http_proxy ""
cpan[2]> o conf ftp_proxy ""
cpan[3]> o conf proxy_user ""
cpan[4]> o conf proxy_pass ""
cpan[5]> o conf commit
cpan[6]> q
$ # I have a shell function that does basically this
$ export http_proxy="http://user:pass#proxyserver:8080"
$ for v in HTTP_PROXY https_proxy HTTPS_PROXY ftp_proxy FTP_PROXY; do
> export $v="$http_proxy"
> done
$ cpan i Devel::Repl # or whatever
Then, presumably, wget was just using the environment variables defined before calling cpan, which of course works fine. If you have a proxy that requires authentication, this article on the Arch wiki has a little script that will prompt you for the credentials, and then set all the appropriate *_proxy and *_PROXY environment variables.
On that note, just as a public service announcement, please don't put important passwords in plain-text configuration files or in your ~/.bashrc.

what I did to overcome cpan proxy behavour is to prefix the command with proxychains command.
Details about proxychains: https://github.com/haad/proxychains

Related

Strawberry Perl module installation issues

Following an equipment 'upgrade' at work, which is a Windows environment, I had to reinstall Perl. ActiveState never worked and I was able to install Strawberry, which fortunately comes with some necessary modules included, such as Excel parsers and writers. The problem is when I try to add additional needed modules. As I understand there are 2 ways to do this: Either download the tarball and build it manually or use cpan.
The first solution requires gmake which is disallowed/blocked by group policy
cpan also fails:
>cpan install Tk
Loading internal logger. Log::Log4perl recommended for better logging CPAN: LWP::UserAgent loaded ok (v6.52) Fetching with LWP: http://www.cpan.org/authors/01mailrc.txt.gz LWP failed with code[407] message[Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. )]
Proxy authentication needed! (Note: to permanently configure username and password run o conf proxy_user your_username o conf proxy_pass your_password )
I also read somewhere that ppm build also works with strawberry, but I have been unable to find ppds.
Any suggestions?

Perl - copying directory from other machine to local machine

I'm trying to write a perl script which copies a directory with files from other machine to current machine.
I can use the scp command in shell but it requires a password. Also I don't have the following modules insatlled on my work area (and unfortunately I cant install them):
Net::OpenSSH
Net::SSH::Perl
Net::SCP
Net:: FTP
I do have installed Net::SSH
My mission is to copy the files from other machine to current machine. The main problem is that it requires a password to use scp on shell. Is there any elegant way to solve this problem?
The elegant way is to use public key authentication.
If you really need password authentication, well, besides the ones you listed there are other modules which would allow you to automate it. Check if you have available Net::SSH2, Expect or IO::Pty.
You may also be able to use use some ssh/scp client accepting the password from the command line or from an environment variable* as plink, pscp or lftp.
Another possibility is using the utility sshpass.
(* Note that passing passwords in the command line or in environment variables is a very insecure practice!)

Error while using cpan command line

I am getting the below errors while using cpan command line:
Reading 'C:\Perl64\cpan\sources\modules\02packages.details.txt.gz'
Warning: Your C:\Perl64\cpan\sources\modules\02packages.details.txt.gz does not
contain a Line-Count header.
Please check the validity of the index file by comparing it to more
than one CPAN mirror. I'll continue but problems seem likely to
happen.
CPAN: Time::HiRes loaded ok (v1.9741)
Warning: Your C:\Perl64\cpan\sources\modules\02packages.details.txt.gz does not
contain a Last-Updated header.
Please check the validity of the index file by comparing it to more
than one CPAN mirror. I'll continue but problems seem likely to
happen.
........Could not split line[" return \"DIRECT\";"]
Could not split line[""]
........Could not split line[" return \"DIRECT\";"]
Could not split line[""]
Giving up parsing your C:\Perl64\cpan\sources\modules\02packages.details.txt.gz,
too many errors
I was trying to install cpanm using cpan App::cpanminus command in command prompt.
I am behind a firewall and have configured the pac file in the http_proxy env variable also. I am using ActivePerl.
return "DIRECT"; is something you will often see in a proxy configuration file, so that's what you probably downloaded into 02packages.details.txt.gz before your proxy was set up correctly.
Once you're sure that your proxy is set up correctly, delete this file and run cpan again. Then cpan will download a fresh copy of the package file.
Once you're sure that your proxy is set up correctly ...
cpan has proxy settings that may need to be configured to get this working.
Run o conf /proxy/ from the cpan prompt to see them.
On my work machine, for example, I have the settings
http_proxy [http://proxymachine.mycompany.com:82]
no_proxy [localhost,127.0.0.1,internalsite.mycompany.com]

How to prevent cpan fron using proxy?

My knowledge of perl is limited to running commands. I have managed to come up with a shell script to output the gav of a pom.xml, using xpath as follows:
xpath pom.xml '//project/artifactId/text()'
On a new machine right now, this does not work because I do not have the XPath.pm installed:
Can't locate XML/XPath.pm in #INC (#INC contains: /usr/lib/perl5/site_perl/5.14/x86_64-cygwin-threads /usr/lib/perl5/site_perl/5.14 /usr/lib/perl5/vendor_perl/5.14/x86_64-cygwin-threads /usr/lib/perl5/vendor_perl/5.14 /usr/lib/perl5/5.14/x86_64-cygwin-threads /usr/lib/perl5/5.14 .)
I seem to remember installing XPath using cpan so I tried the following command, blindly:
cpan XPath
This is probably not the correct command to use, but I think that is unrelated to the issue I am facing. The command gives following error:
Going to read '/home/****/.cpan/Metadata'
Database was generated on Mon, 25 Aug 2014 00:41:02 GMT
Fetching with HTTP::Tiny:
http://www.perl.org/CPAN/authors/01mailrc.txt.gz
HTTP::Tiny failed with an internal error: Could not connect to 'proxy:8080': IO::Socket::INET: Bad hostname 'proxy' at /usr/lib/perl5/5.14/HTTP/Tiny.pm line 139
Proxy authentication needed!
(Note: to permanently configure username and password run
o conf proxy_user your_username
o conf proxy_pass your_password
)
Username: C-c C-c
Why is HTTP::Tiny looking for host proxy? We do have a corporate proxy with hostname proxy but that is needed only when I am on corporate network or VPN, neither of which is case right now.
How do I convince HTTP::Tiny to connect directly to internet? I do not have an envvar named http_proxy or HTTP_PROXY set.
While the environment variable is used, cpan first checks its configuration.
To view: o conf http_proxy
To clear: o conf http_proxy ''
Don't forget to use o conf commit to make the change permanent.
CPAN uses HTTP:Tiny to download info about the module you are asking for. It is lightweight so it runs fast.
Either CPAN has not been configured, or the cpan found on your path is configured to use the proxy. Determine the location of the CPAN program you are executing and proceed from there.
This msg Can't locate XML/XPath.pm in #INC (#INC contains: /usr/lib/perl5/site_perl/5.14/x86_64-cygwin-threads /usr/lib/perl5/site_perl/5.14 /usr/lib/perl5/vendor_perl/5.14/x86_64-cygwin-threads /usr/lib/perl5/vendor_perl/5.14 /usr/lib/perl5/5.14/x86_64-cygwin-threads /usr/lib/perl5/5.14 .) shows that module is not installed.
If you are on windows and using a proxy setting. You can use these commands to install module from ppm or cpan. Open a command prompt and run these commands :
set http_proxy=http://xxx.xxx.xxx.x:yyyy (xxx is your system proxy and yyyy is port)
set http_proxy_user=username (login username)
set http_proxy_pass=password (login password)
To install a module from cpan type:
cpan install modulename
The error occurs because you have set http_proxy variable to direct IP, Instead, put http_proxy=http://ipaddress , then it will work

Gitlab, docker and sendmail ports

I have got gitlab running through docker using this image. In the image documentation there are instructions for how to configure an optional SMTP server for emails, but little information on what happens if SMTP is not set up. The gitlab documentation indicates that sendmail is used by default, so I assume that is what happens, and for my purposes (a few private repositories with only a couple of users) I don't think I really need any more than sendmail. I tried just ignoring the SMTP configuration and it all runs fine, but emails are not sent. I don't know enough about email servers or sendmail to know how to find the problem, but my guess is that some port it needs is blocked.
My questions:
Can anyone confirm than sendmail is used, and that I don't need to configure something?
Is there some easy way to test sendmail locally to see if there are issues with blocked ports? All the guides I find start out with several pages of configuration details.
What ports would sendmail need open to work? Do I need to expose additional ports on the container or on my firewall?
Shuo's answer worked for me except I changed:
supervisord reload # restart the service
to
supervisorctl reload
Another approach is to build your own Docker image and update the production.rb environment file. Here's what you're Dockerfile might look like.
FROM sameersbn/gitlab:7.14.0
MAINTAINER "leo.o'donnell#pearson.com"
# sed the production.rb environment file to use a configured email method converting
#
# config.action_mailer.delivery_method = :sendmail
#
# to
# config.action_mailer.delivery_method = (ENV['SMTP_DELIVERY_METHOD'] || :sendmail).to_sym
RUN sed -E -e "s/(action_mailer.delivery_method[^\:]+)([^ \t\#]+)(.*)/\1\(ENV\[\'SMTP_DELIVERY_METHOD\'\] \|\| \2\).to_sym\3/" -i config/environments/production.rb
or you can just use my image
docker pull leopoldodonnell/gitlab
I met the same problem yesterday and upvoted your question. Now I managed to make smtp work without send_mail.
sudo docker exec -it gitlab /bin/bash # go into the container
vi /home/git/gitlab/gitlab/config/environments/production.rb # The path may not exactly match, but you can guess
now search email and the method is :send_mail, change it to :smtp
supervisord reload # restart the service