Archive for March, 2009
Shell script desde Java
Requeria hacer uso de ip calc desde java…
Asi que aqui les dejo, el como se manda a llamar un shell script desde java
#!/bin/sh
###################################
# Script: acl_validador.sh #
# Escrito por: Edwin Plauchu #
# mailto: j4nusx@gmail.com #
# 9 / dic / 2008 #
###################################
CONFIG_FILE="$HOME/desarrollo/etc/carrito.conf"
. $CONFIG_FILE
export LANG="ISO-8859"
is_it_on_network(){
OK="false"
IP_USER=$2
NETMASK_USER=$3
NETWORK_IN_ACL=$1
RESULT_SET=`$IPCALC -n $IP_USER -m $NETMASK_USER -p -b`
NETWORK=`echo "$RESULT_SET" | grep NETWORK | $AWK -F= '{ print $2 }'`
PREFIX=`echo "$RESULT_SET" | grep PREFIX | $AWK -F= '{ print $2 }'`
NETMASK=`echo "$RESULT_SET" | grep NETMASK | $AWK -F= '{ print $2 }'`
ACL_NET_PART=`echo "$NETWORK_IN_ACL" | $AWK -F/ '{print $2}'`
ACL_IP_PART=`echo "$NETWORK_IN_ACL" | $AWK -F/ '{print $1}'`
FORMAT_ACL_NET_PART=`echo "$ACL_NET_PART" | grep -E "^[0-9][0-9]{0,1}$"`
FORMAT_A="0"
FORMAT_B="0"
if [ ${FORMAT_ACL_NET_PART:-0} -eq 0 ]; then
FORMAT_B=`echo 1`
# echo B
else
FORMAT_A=`echo 1`
# echo A
fi
if [ $NETWORK = $ACL_IP_PART ]; then
#Si el formato de la ACL_NET_PART fue A
if [ $FORMAT_A -eq 1 ] && [ $PREFIX -eq $ACL_NET_PART ]; then
OK="true"
fi
#Si el formato de la ACL fue B
if [ $FORMAT_B -eq 1 ] && [ $NETMASK = $ACL_NET_PART ]; then
OK="true"
fi
fi
echo $OK
}
is_it_on_network $1 $2 $3
import java.io.*;
public class IpHelper {
private String comando;
private String path;
private String ip;
private String netmask;
private String aclAddress;
private String acl_ip_part;
private String acl_net_part;
public String getNetmask() {
return netmask;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public IpHelper(){
path = System.getenv("HOME");
this.setComando("sh " + path + "/desarrollo/bin/network_validator.sh");
}
@SuppressWarnings("unused")
public boolean check(){
boolean variable_retorno = false;
String p1 = "sh " + path + "/desarrollo/bin/network_validator.sh" + " "
+ this.getAclAddress() + " "
+ this.getIp() + " " + this.getAcl_net_part();
System.out.print(p1);
this.setComando(p1);
try{
String cadena_resultante = "";
InputStream is = null;
Process p = null;
byte b = (byte) 0xA3;
byte[] buffer = new byte[]{b};
p = Runtime.getRuntime().exec(this.getComando());
is = p.getInputStream();
for(int count = 0; (count = is.read(buffer)) >= 0;){
cadena_resultante += new String(buffer,"UTF-8");
}
if (cadena_resultante.equals("true")){
variable_retorno = true;
}
}
catch (Exception e) {
e.printStackTrace();
}
return variable_retorno;
}
/**
* @return the comando
*/
public String getComando() {
return comando;
}
/**
* @param comando the comando to set
*/
public void setComando(String comando) {
this.comando = comando;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
private void setAclAddress(String aclAddress) {
this.aclAddress = aclAddress;
}
public String getAclAddress() {
this.setAclAddress(this.getAcl_ip_part() + "/" + this.getAcl_net_part());
return aclAddress;
}
public void setAcl_ip_part(String acl_ip_part) {
this.acl_ip_part = acl_ip_part;
}
public String getAcl_ip_part() {
return acl_ip_part;
}
public void setAcl_net_part(String acl_net_part) {
this.acl_net_part = acl_net_part;
}
public String getAcl_net_part() {
return acl_net_part;
}
}
JBOSS & POSTGRESQL & APACHE con HTTPS SUPPORT
http://www.geocities.com/j4nusx/manual_carrito.pdf
Buenas tardes a todos los que visitan gulsin…. ultimamente no he tenido mucho tiempo para escribir aqui… asi que les anexo un documento que le puede interesar a los javeros que implementan sus soluciones enlinux…
Aclaro… sigue sin gustarme java!
