debian: proxy anonimo bat sortu squid-egaz

Programaziño bidezko soluziñuek ibil nai topaten baie ez dot topa ezer dezenterik, orduen proxy bet montaten anime nai, batzuk lagunek dakuzelako internet zentsureten dauien herrialdietan, ta honegaz ba aukerie dakoie oingoz geuretzako askie dan internet erabiltzeko ;)

su
aptitude install squid apache2-utils
cd /etc/squid
mv squid.conf squid.conf.bak
nano squid.conf

squid.conf

# portue, baporana ez eh :D
http_port 8080
# autentifikaziño metodue eta ze artxibo erabili
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/users
# "password" izeneko filtrue sortu esaten password-a eskatuteko
acl password proxy_auth REQUIRED
# "all" izeneko filtro bat sortu
acl all src 0.0.0.0/0.0.0.0
# "all" filtrueri esan user/passwd eskatuteko
http_access allow all password
#anonimotasune emoteko
forwarded_for off

Oin users artxibue sortu eta baimenak emon pasahitzek bertan gordeteko, horretarako apache-n htpasswd erabilku

htpasswd -c users usuaidxue
chmod 0644 users

/etc/init.d/squid restart
exit

Gero nabegadoran, adibidez firefox-en:

Edit -> Preferences -> Advanced -> Network

https://i.imgur.com/xiBM5.png

Ba betikulez IP aldatu ;)

Gero nabegakeran eskatukosku usuaidxue eta password-a, sartun ta abante!!!

php array multi-dimensional bat python dict bihurtu

Ba hamen gabilz barriro python-egaz pellikan, oingutan php-tik curl bidez botaku array multi-dimensional bat post edo get bidez eta python-egaz hartun.

Okin biharrekuek: python, web zerbitzaridxe php-gaz eta cgi-gaz

Paketiek instala:

su
aptitude install python-pip php5-curl
pip install querystring-parser
exit

curl.class.php artxibue:

<?php
class curl
{
	public static function getURL($url, $params = array(), $type = 'get', $curl_opts = array())
	{
		if(!function_exists('curl_init'))
			die('curl module missing');				
		
		$type = trim(strtolower($type));		
		if(is_array($params) && count($params)>0)
			$params = self::setParams($params);
					
		$ch = curl_init();				
				
		if($type=='post')
		{					
			curl_setopt($ch, CURLOPT_POST, 1);			
			curl_setopt($ch, CURLOPT_POSTFIELDS, $params);			
			curl_setopt($ch, CURLOPT_URL, $url);			
		}		
		else
			curl_setopt($ch, CURLOPT_URL, $url.$params);

		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		
		// set curl param options
		if(is_array($curl_opts))
		{
			if(count($curl_opts)>0)
			{
				foreach($curl_opts as $key => $value)
					curl_setopt($ch, $key, $value);
			}			
		}								
		$result = curl_exec($ch);
		return $result;	
	}
	
	public static function setParams($array, $type = 'get')
	{
		$txt = '';
		if(count($array)>0)
		{
			if($type=='get')
				$txt.= '?';
			$txt.= http_build_query($array);			
		}
		return $txt;
	}	
}
?>

index.php artxibue:

<?php
include('curl.class.php');

$vars = array
(
	'aitxitxe' => array
	(
		'aita' => array
		(
			'semie' => 'iban',
			'alabie' => 'maite'
		)
	)
);

echo curl::getUrl('http://localhost/python/request.py', $vars);
?>

oin python-en partie: request.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, cgi

# request parametruek hartu eta dic baten barruen sartu

params = {}
form = cgi.FieldStorage()

for k in form.keys():
    params[k] = form[k].value

print "Content-type: text/plain\n"
print params

sys.exit()

oin guez: http://localhost/index.php -ra eta hau da erantzune:

{
  'aitxitxe[aita][semie]': 'iban',
  'aitxitxe[aita][alabie]': 'maite'
}

oops, ikusten dun moduen sortu den dict-e ezta multi-dimentsionala unidimentsionala baño, hori konponduteko erabilku: querystring-parser

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, cgi
from querystring_parser import parser

# request parametruek hartu eta dic baten barruen sartu

params = {}
form = cgi.FieldStorage()

for k in form.keys():
    params[k] = form[k].value
    

# dict -e query-string-era pasateko funtziñue

def dict2querystring(dict):
    text = ''
    count = 0
    for i in dict:
        if count > 0:
            text+= "&"
        text+= str(i) + "=" + str(dict[i])
        count += 1
    return text

# request parametruek query-string-era pasa

params_text = dict2querystring(params)

# query-string-e dict-era pasa

post_dict = parser.parse(params_text)

print "Content-type: text/plain\n"
print post_dict

sys.exit()

Eta oingo erantzune, oin bai :)

{
  'aitxitxe':
  {
    'aita':
    {
      'alabie': 'maite',
      'semie': 'iban'
    }
  }
} 

Eskerrak: http://stackoverflow.com/questions/1890013/django-python-is-there-a-simple-way-to-convert-php-style-bracketed-post-keys-t

php: namespace -n erabilerien adibide bat

namespace -k klasiek kapsuleteko erabiltzen da, adibidez izen bardiñeko klasiek erabiltzeko baie erabilera ezberdiñetarako, php-n 5.3-tik aurrera erabili lei:

namespace adibidie

Ikusten dun moduen izen bardiñeko klasiek dakuz, zelan erabili?

lib/login.class.php

<?php
namespace lib;
class login
{
    public function __construct()
    {
        echo "lib: login\n";
    }
}
?>

mvc/model/login.class.php

<?php
namespace model;
require_once('lib/login.class.php');

class login
{
    public function __construct()
    {
        $login = new \lib\login();
        echo "model: login\n";
    }
}
?>

mvc/controller/login.class.php

<?php
namespace controller;
require_once('mvc/model/login.class.php');

class login
{
    public function __construct()
    {
        $login = new \model\login();
        echo "controller: login\n";
    }
}
?>

index.php

<?php
require_once('mvc/controller/login.class.php');
header("Content-Type:text/plain");
$login = new \controller\login();
?>

Zelan deitsu core-ko klasieri?

lib/login.class.php

<?php
namespace lib;
class login
{
    public function __construct()
    {
        echo "lib: login\n";
        new DOMDocument();
    }
}
?>

ERRORIE:

PHP Fatal error:  Class 'lib\\DOMDocument' not found in lib/login.class.php on line 8

Hau konponduteko \ bat sartun hasikeratan:

lib/login.class.php

<?php
namespace lib;
class login
{
    public function __construct()
    {
        echo "lib: login\n";
        new \DOMDocument();
    }
}
?>

index.php nabegatzailien:

lib: login
model: login
controller: login

debian / python: sqlalchemy -gaz oracle -ra konekta

Paketiek instala:

su
aptitude install python-sqlalchemy alien libaio1
exit

Jakitzeko ze bertsiño dakun python-ena:

python -V

erantzune:

Python 2.7.2+

Jakitzeko oracle-n bertsiñue:

select * from product_component_version;

erantzune:

NLSRTL                                  11.2.0.2.0 Production
Oracle Database 11g Enterprise Edition  11.2.0.2.0 64bit Production
PL/SQL                                  11.2.0.2.0 Production
TNS for 64-bit Windows:                 11.2.0.2.0 Production

Nire kasuen: python 2.7 eta oracle 11.2

Orduen hurrengo web-an topa biherku paketie:

http://cx-oracle.sourceforge.net/

Nire kasuen: “Download 5.1.1 released October 10, 2011” atalien:

CentOS 5 x86_64 RPM (Oracle 11g, Python 2.7)

RPM-ie DEB-era pasateko:

su
alien -d cx_Oracle-5.1-11g-py27-1.x86_64.rpm
ls | grep .deb$
cx-oracle_5.1-2_amd64.deb

paketie instala

dpkg -i cx-oracle_5.1-2_amd64.deb
ln -s /usr/lib/python2.7/site-packages/cx_Oracle.so /usr/lib/python2.7/dist-packages/cx_Oracle.so
exit

Adibide script bet sortu

nano proba.py

 

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sqlalchemy import create_engine

connection = create_engine('oracle://USER:PASSWD@IP:PORT/DDBB').connect()

result = connection.execute("select * from product_component_version")
for v in result:
  for column, value in v.items():
    print('{0}: {1}'.format(column, value))

connection.close()

Baimenak emon al izateko igiri eta ejekute:

chmod +x proba.py
./proba.py

ERROR:

ImportError: /usr/lib/python2.7/dist-packages/cx_Oracle.so: undefined symbol:PyUnicodeUCS2_AsEncodedString

Bueno hori errorie ez urteteko beste pakete bat instala dot:

“Download 5.1 released March 19, 2011” ataleko:
CentOS 5 x86_64 RPM (Oracle 11g, Python 2.7)

Desinstalateko:

su
aptitude purge cx-oracle
rm -rf /usr/lib/python2.7/dist-packages/cx_Oracle.so
exit

eta lengo pausuek jarraitu ;)

adibide onan erantzune:

product: NLSRTL
version: 11.2.0.2.0
status: Production
product: Oracle Database 11g Enterprise Edition
version: 11.2.0.2.0
status: 64bit Production
product: PL/SQL
version: 11.2.0.2.0
status: Production
product: TNS for 64-bit Windows:
version: 11.2.0.2.0
status: Production

debian: node.js eta socket.io-gaz txat bat egin

node.js instalateko oin momentutan SID-en dau :)

su
aptitude install nodejs npm
exit
npm install socket.io
nano server.js
var server = require("socket.io").listen(6969);

server.sockets.on("connection", function(message)
{
	message.on("newMessage", function(data)
	{
		server.sockets.emit("sendEvent", data);
	});
});
nano index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Online chat</title>
<style>
body
{
	color: #333;
	background: #333;
	font-family: "Helvetica", Arial;
	font-size: 14px;
	text-align: center;
}
.container
{
	background: #ccc;
	border-radius: 1em;
	box-shadow: 0px 5px 5px rgba(0,0,0,0.5);
	text-shadow: 5px 5px 5px rgba(0,0,0,0.5);
	margin: 1em auto;
	padding: 1em;
	width: 90%;
}

input
{
	display: block;
	font-size: 12px;
	margin: 1em auto;
	padding: 0.5em;
	width: 95%;
}

span
{
	display: block;
	font-size: 12px;
	margin: 1em auto;
	padding: 0.5em;
	width: 95%;
	text-align: left;
}
</style>
<script src="http://clab.nodester.com/socket.io/socket.io.js"></script>
<script type="text/javascript">
<!--
// IP PUBLIKUE IMI??I HAMEN
var websocket = io.connect("http://192.168.100.103:6969");

window.onload = function()
{
	websocket.on("sendEvent", function(data)
	{
		var chat = document.getElementById('zchat');
		var span = document.createElement('span');
		var txt = document.createTextNode(data);
		span.appendChild(txt);
		if(chat.hasChildNodes())
			chat.insertBefore(span, chat.firstChild);
		else
			chat.appendChild(span);
	});

	var form = document.getElementById('zform');
	var message = document.getElementById('zmessage');
	form.onsubmit = function(e)
	{
		websocket.emit("newMessage", message.value);
		message.value = '';
		return false;
	};

	message.value = '';
	message.focus();
};
//-->
</script>
</head>
<body>
<div class="container">
<form id="zform">
	<label>Message: </label>
	<input type="text" name="zmessage" id="zmessage" placeholder="Please insert message" required />
	<input type="submit" />
</form>
</div>
<div id="zchat" class="container">
</div>
</body>
</html>

Zerbitzaridxe abante imiñi:

node server.js

Eta oin nabegatzailien igiri index.html eta hasi sartzien mensajiek :)

Eskerrak: Curso de Node.js, Websockets y HTML5 de #mejorandola

Edit: Antza adibideko socket.io.js ezta existiten, bueno geure sistemako socket.io.js imintzeko:

find / | grep socket.io.js

erantzunen adibidie:

/home/zital/.node_libraries/.npm/socket.io-client/0.8.7/package/dist/socket.io.js
/home/zital/.node_libraries/.npm/.cache/socket.io-client/0.8.7/package/dist/socket.io.js
/home/zital/.node_libraries/.npm/.cache/socket.io/0.8.7/package/lib/socket.io.js
/home/zital/.node_libraries/.npm/socket.io/0.8.7/package/lib/socket.io.js

kopidxe horretariko edozein index.html dakozuien karpetara eta listo :), gero html-ien hau aldatu