Blogs

Email from your host you are banned (mail php security matter)

I found this in a server:

$header = "From: <".$_REQUEST['email'].">\n";
... 
mail($from,$subjet,$message,$header);

$_REQUEST['email'] came from a form input ...

Here $_REQUEST['email'] should be, at least, stripped by all \n no matter on how you trust to js code..

$from = $_REQUEST['email'];
$from = str_replace("\n","",$from);
$header = "From: <$from>\n";

... but do not kill your programmer .. it happen

Option List jQuery plugin

A plugin for display list of item to insert.
List item are stored in input hidden comma separed, the call is simple
Some bug to fix

options are

  • target: target div to update with options
  • input: input to update with values
  • items: items list as key:value
  • optional: default to $("<input>").attr("type","text") ... you can setup autocomplete
  • preset: an array of key preset (must be in items)
$("#morelink").optionlist({
	  target:'#optionlist',
	      input: '#iptvalues',
	      items: {'0':'prova','1':'test','2':'due','3':'tre'},
	      preset: [0]
	  });
moreitem
.optionlist_itemlist {
position:absolute;
display:none;
border:1px solid #000;
padding:2px;
background:#fff;
z-index:3001;
}
.optionlist_additem{
 cursor:pointer;
  color:blue;
 }
.optionlist_additem:hover{
  text-decoration:underline;
 }
.optionlist_item{
 width:100px;
  float:left;
 }
.optionlist_rmitm{
 position:absolute;
  background: #999;
 opacity:0.7;
 display:none;
 cursor:pointer;
}

also #optionlist_overlay is the overlay at z-index:3000

deploy svn to ftp hosting

I wasted some time to check if there is a script to deploy to ftp hosting from my svn, and I found nothing

here is my code in perl, just replace first 5 setted vars

2009-06-27
project in sourceforge: http://svnftpdeploy.sourceforge.net/

grep over ssh in emacs

M-x grep command is very useful in a number of situation, because, for example, it give you direct access to all matched file ...

But there is not so intuitive how to use grep when opening file via ssh, this is the trick:

First generate a key pair and upload public part to the remote server:
(suppose remote host/user is B/b)

$ ssh-keygen -t rsa
...
$ ssh b@B mkdir -p .ssh
$ cat ~/.ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
$ ssh-add

be sure to use ssh-agent in order to use ssh-add

So you will not be asked for a password every time you ssh

Every time you want to grep in emacs:

M-x grep
Run grep (like this): ssh -t b@B 'grep -nH -e include path_to_files/*'

where path_to_file is the path relative to home in remote host

NOTE: do grep command when visiting remote home in emacs (otherwise it will not find matched files)

that's all

SiteMap php class

2 simple class for sitemap:

http://www.smartango.com/files/sitemap.txt

simple use:

$root = $_SERVER['DOCUMENT_ROOT'];
$sm = new SiteMap($root,'sitemap-1.xml');
$sm->start();
$http = "http://www.example.com";
$sm->addUrl($http."/file.html");
$sm->end();

...SiteMapIdx similar

move multiple option in select with jQuery

I look for this everywhere: how to move multiple option inside a select


function upfield() {
var el = $('#selectedfield').children('[@selected]:first').prev();
$("#selectedfield")
.children('[@selected]')
.each(function(){
$(this).insertBefore(el);
});

}

function downfield() {
var el = $('#selectedfield').children('[@selected]:last').next();
$("#selectedfield")
.children('[@selected]')
.each(function(){
$(this).insertAfter(el);
el = $(el).next();
});
}

xmlrpc and mod_security

with apache mod_security, xmlrpc calls return 412 "Precondition Failed"
when using xmlrpc.php this avoids such error:
in .htaccess :

<Files xmlrpc.php>
SecFilterInheritance Off
</Files>

Various SDK for Smart Device

Symbian Series 60 SDK from forum.nokia.com

Symbian UIQ SDK from developer.sonyericsson.com

Maemo SDK from maemo.org (Nokia N770, N800 tablet pc)

J2ME from java.sun.com

DevRocket from Montavista

OpenMoko from OpenMoko (also mokomakefile project, sdk for linux)

Google Android from code.google.com/android/

BlackBerry JDE (RIM Java Development Environment)

XMLHttpRequest, document element DOM parsing

XMLHttpRequest use, works only if url is on same site. checklogin.php give <KO/> if login è fails <OK>XXX</OK> with XXX id of user when login è is ok

var loginOK = false;

var httpRequest;

function validateLogin()
{
 var login = document.getElementById("NomeForm");
 var logintxt = login.value;
 var password = document.getElementById("PasswdForm");
 var passwordtxt = password.value;
 var url = "/forum/checklogin.php?username="
 + logintxt + "&password=" + passwordtxt;

 if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    httpRequest = new XMLHttpRequest();
    if (httpRequest.overrideMimeType) {
       httpRequest.overrideMimeType('text/xml');
    }
 }
 else if (window.ActiveXObject) { // IE
    try {
       httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
       try {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
       }
       catch (e) {}
    }
 }

 if (!httpRequest) {
    alert('Giving up :( Cannot create an XMLHTTP instance');
    return false;
 }
 httpRequest.onreadystatechange = loadLogin;
 httpRequest.open('GET', url, true);
 httpRequest.send(null);
}

function loadLogin()
{
  if (httpRequest.readyState == 4) {
      if (httpRequest.status == 200) {
         response = httpRequest.responseText;
	 if (response == "") {
	   alert ('login/password errate.');
	 } else {
	   var responseXML = httpRequest.responseXML.documentElement;
	   user_id = responseXML.firstChild.nodeValue;
	   LinkSitoForm = document.getElementById('LinkSitoForm');
	   LinkSitoForm.setAttribute('value', 'http://forum.cellularmagazine.it/profile.php?mode=viewprofile&u=' + user_id);
	   NomeForm = document.getElementById('NomeForm');
	   PasswdForm = document.getElementById('PasswdForm');
	   PasswdForm.setAttribute('enabled','no');
	   var whchis = document.getElementById("trcheckpasswd");
	   whchis.innerHTML = "OK"
	 }
      } else {
         alert('There was a problem with the request.');
      }
   }
   else {
   }

}
Syndicate content