Thursday, January 28, 2016

how to connect an apache cgi-script to postgreql database

How do I connect to a local postgres database without password from a script within Apache
up vote 0 down vote favorite

I have a Python script that should load some data into postgres when a POST request is sent to Apache Webserver. In the script a system user (dbuser) is used to connect to the database (which works fine with psql). The script however cannot connect when it is executed within Apache, returning the following error:

Peer authentication failed for user dbuser

Is there a way to allow the script to connect without providing it the user password?
python apache postgresql cgi
shareimprove this question
asked Jun 4 '15 at 9:48
add a comment
1 Answer
active oldest votes
up vote 1 down vote

The solution I've found uses ident authentication with user maps.

The first thing to notice is that, although an username is provided in the script, when connecting via Apache, that user is used for peer authentication (which fails, requiring a password). However, the system user requesting access to postgresql is the one running Apache (namely www-data), thus enabling us to configure an user map, allowing is to authenticate to the server as another system user (thus leveraging ident authentication). Here follows the configuration files content:

In pg_ident.conf we configure the user map:

web            www-data                dbuser
web            dbuser                  dbuser

In pg_hba.conf we add the map as an option to the local peer authentication:

# "local" is for Unix domain socket connections only
local   all          all                 peer map=web

After reloading the server, the script can access the database as if it was executed directly the the user "dbuser", without the need for a password.
shareimprove this answer

Saturday, January 2, 2016

too many files in directory need to split into subdirectories with 100 files

#!/usr/bin/perl -w
use strict;
use File::Copy;
my $fn;
my @total= (1 .. 100);
my $dir = shift;
opendir (my $dh , $dir);

my @files = grep { $_ ne '.' && $_ ne '..' } readdir $dh;

my @letters = ("a".."z") ;

foreach my $let1 ( @letters ) {
    foreach my $let2 (@letters)   {
       mkdir "$dir$let1$let2";

for my $count (@total) {
$fn =  pop  @files;
if ( $fn ) {
  move ("$dir/$fn", "$dir$let1$let2/$fn");
} else  {
    last MYLOOPS;
} }}

Thursday, March 20, 2014

;; this should delete the last line 00:00

(let ((beg (point)))
(forward-line 0)
(delete-region beg (point)))

;;then do this

(goto-char (point-min))

this solves that first problem

then use this in autohotkey


SetTitleMatchMode 1
WinActivate emacs
WinSet, AlwaysOnTop, On, emacs
WinSet, Top, ,emacs

Sunday, March 16, 2014

defun get-stuff ()
(shell-command '"c:/user/get.ahk")
(goto-char (point-min))
(re-search-forward "00\:00")
(goto-char 1)
(message " hi there meshulum"))

(defun clean-stuff ()
(goto-char (point-min))
(re-search-forward "00\:00")
(goto-char 1)
(message " hi there user"))

(defun both-stuff ()

(defun put-stuff ()
(kill-ring-save (point-min) (point-max))
(shell-command '"c:/ure/put.ahk"))

SetTtileMatchMode 1
WinActivate Nuance
Send ^a
Send {Del}
Sleep 100
Clipboard = %text%
WinActivate Nuance
Send ^v

SetTitleMatchMode 1
WinWait Nuance
WinGetText, text;
Clipboard = %text%
WinActivate eamcs
Send ^y

Thursday, March 13, 2014

write interactive emacs functin

global-set-key (kbd "C-c C-g")
(lambda ()
(shell-command "/home/user/")))

Sunday, March 9, 2014

ideas to capture to emacs and avoid nuance

SetTitleMatchMode 1
WinWait Nuance
WinGetText, text ;
MsgBox, the text is: `n%text%
WinActivate Nuance
Send ^a
Send {Del}
Sleep 100
Clipboard = %text%
WinActivate Nuance

Send ^v

Wednesday, February 26, 2014

stumpwm problem with mouse on gtk3 apps such as evince and other apps

I have been using stumpwm for several years and am very happy and can't contempl
ate otherwise.

I just noticed a change in debian sid.

The new version of evince 3.10 (which is a pdf viewer)
mousewheel no longer scrolls up and down the page while running under stumpwm.

I reported to evince upstream and they denied it as a problem on their end.

I found they are right when i opened up lxde icewm gnome etc evince worked norma

Note evince 3.4 under stumpwm (debian wheezy) was fine.

It was only when i upgraded 3.10 or even using jhbuild latest 3.11 same behavior

Do you have any idea what the change in mouse handling that would affect this ap
I have not noticed other applications.

is it a change in the xorg?

thus qpdfview works with normal scroll behavior and okular.

I mentioned on #stumpwm irc

where it was confirmed by alezost

other applications


It can be solved by

> GDK_CORE_DEVICE_EVENTS=1 evince file.pdf

will work normally with the mouse

can this be set in the .profile or .bashrc ???? don't know how