/* Dentro de um software de RH, na parte de datas de experiência, deve ser calculado 30 e 45 dias a partir de uma data inicial */
import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
*
* @author Mario Cezzare Angelicola Chiodi mcezzare@gmail.com
*/
public class testeData {
private static void calculaPeriodoExperiencia(String dataInicial,int periodo, int dias) {
Calendar data1 = Calendar.getInstance();
Calendar dataInicio = Calendar.getInstance();
int dia, mes, ano;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
switch (periodo) {
case 1:
if (!" / / ".equals(dataInicial)) {
String tmpData[] = dataInicial.split("\\/");
dia = Integer.parseInt(tmpData[0]);
mes = Integer.parseInt(tmpData[1]) - 1; // aqui passo -1
ano = Integer.parseInt(tmpData[2]);
dataInicio.set(ano, mes, dia);
data1.set(ano, mes, dia);
data1.add(Calendar.DAY_OF_WEEK, dias);
System.out.println("inicio: " + sdf.format(dataInicio.getTime()));
System.out.println(dias + " : " + sdf.format(data1.getTime()));
}
break;
// case 2 , se forem outros campos texto no form
}
}
public static void main(String args[]) {
String dataInicial = "01/01/2000";
calculaPeriodoExperiencia(dataInicial,1, 29); // q são 30 dias , mas conta a data inicio
calculaPeriodoExperiencia(dataInicial,1, 44);// q são 45 dias , mas conta a data inicio
}
}
saida :
inicio: 01/01/2000
29 : 30/01/2000
inicio: 01/01/2000
44 : 14/02/2000
Blog de Mario Cezzare Angelicola Chiodi.
Analista de Sistemas, Produtor Musical, Professor, Consultor, entre outras atividades.
+ Quem :
https://www.mcezzare.com.br/ |
https://www.linkedin.com/in/mcezzare/ |
https://github.com/mcezzare | GitHub
+ info musica em :
https://www.insonicmusic.com/ | http://myspace.com/insonic | https://www.facebook.com/insonicmusic | http://soundcloud.com/insonic | http://myspace.com/subsonictrance
sexta-feira, 30 de março de 2012
quarta-feira, 29 de dezembro de 2010
Shell Script de backup para PostgreSQL
Esse script pode ser usado p/ fazer backups diários de todas as bases postgres
exemplo no crontab diariamente as 23:50
50 23 * * * /scripts/backup_pgsql.sh
exemplo no crontab diariamente as 23:50
50 23 * * * /scripts/backup_pgsql.sh
#!/bin/sh
# Script to backup postgres databases
# Create a complete bkp with all databses and a separated for each one
# Author: Mario Cezzare mcezzare@gmail.com
# last update on Wed Dec 29 16:24:11 on ttys005
PGDUMPALL="$(which pg_dumpall)"
PSQL="$(which psql)"
GZIP="$(which gzip)"
x=`date '+BACKUP-%d.%m.%y'`
separator="-----------------------------------"
path_backup=/backup/pgsql/
notify="sysadmin@email.com.br"
cd $path_backup
mkdir $x
path_backup="$path_backup/$x"
echo $x
now=`date '+%d.%m.%y %H:%M:%S'`
##################################################################################
# PART 1 - LOGS
##################################################################################
echo " starting at $x $now" >> $path_backup/pgsql-databases-$x.log
##################################################################################
# PART 2 - ALL DATAL
##################################################################################
$PGDUMPALL -U postgres | $GZIP -c > $path_backup/$x-all-pg.pgsql.gz
##################################################################################
# PART 3 - EACH ONE
##################################################################################
DIR=$path_backup
[ ! $DIR ] && mkdir -p $DIR || :
LIST=$($PSQL -U postgres -l | awk '{ print $1}' | grep -vE '^-|^List|^\(|^Name|template[0|1]')
for d in $LIST
do
echo "Dumping $d"
pg_dump -U postgres $d | $GZIP -c > $DIR/$d.pgsql.gz
now=`date '+%d.%m.%y %H:%M:%S'`
echo "$d em $now" >> $path_backup/pgsql-databases-$x.log
done
##################################################################################
# PART 1B - END LOGS
##################################################################################
echo " ending at $x $now" >> $path_backup/pgsql-databases-$x.log
##################################################################################
# PART 4 - NOTIFICATIONS
##################################################################################
ls -aloh $path_backup | mail -s BACKUP_POSTGRES_DATABASES $notify
Marcadores:
Linux,
PostgreSQL,
Shell Script,
SysAdmin
Shell Script de backup para Mysql
Esse script pode ser usado p/ fazer backups diários de todas as bases mysql
exemplo no crontab diariamente as 23:50
50 23 * * * /scripts/backup_mysql.sh
como root no mysql de permissao de leitura p/ o usuario backup_operator
exemplo no crontab diariamente as 23:50
50 23 * * * /scripts/backup_mysql.sh
como root no mysql de permissao de leitura p/ o usuario backup_operator
GRANT ALL ON *.* TO 'backup_operator'@'localhost'
#!/bin/sh # Script to backup mysql databases # Create a complete bkp with all databses and a separated for each one # Author: Mario Cezzare mcezzare@gmail.com # last update on Wed Dec 29 16:24:11 on ttys005 x=`date '+BACKUP-%d.%m.%y'` now=`date '+%d.%m.%y %H:%M:%S'` separator="-----------------------------------" path_backup=/backup/mysql/ notify="sysadmin@email.com.br" cd $path_backup mkdir $x path_backup="$path_backup/$x" echo $x ################################################################################## # PART 1 - LOGS ################################################################################## echo " starting at $x $now" >> $path_backup/mysql_databases-$x.log echo $separator MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" MYSQLUSER="backup_operator" MYSQLPASSWD="senha_do_backup_operator" MYSQLHOST="localhost" GZIP="$(which gzip)" ################################################################################## # PART 2 - ALL DATA ################################################################################## echo "backup of mysql databases " mysqldump --all-databases -h $MYSQLHOST -u $MYSQLUSER -p$MYSQLPASSWD | gzip -c > $path_backup/backup-all-mysql-$x.mysql.gz ################################################################################## # PART 3 - EACH ONE ################################################################################## DBS="$($MYSQL -u $MYSQLUSER -h $MYSQLHOST -p$MYSQLPASSWD -Bse 'show databases')" for db in $DBS ; do echo "backing up $db" FILE="mysql_$db-$x.mysql.gz" $MYSQLDUMP -u $MYSQLUSER -h $MYSQLHOST -p$MYSQLPASSWD $db | $GZIP -c > $path_backup/$FILE now=`date '+%d.%m.%y %H:%M:%S'` echo " $db at $x $now" >> $path_backup/mysql_databases-$x.log done ################################################################################## # PART 3 - EACH ONE ################################################################################## now=`date '+%d.%m.%y %H:%M:%S'` echo " ending at $x $now" >> $path_backup/mysql_databases-$x.log ################################################################################## # PART 4 - NOTIFICATIONS ################################################################################## ls -aloh $path_backup | mail -s BACKUP_MYSQL_DATABASES $notify
Marcadores:
Linux,
MYSQL,
Shell Script,
SysAdmin
segunda-feira, 9 de agosto de 2010
Calendário customizável em ASP (destaque por data) e exemplo de cálculos com datas
Mexendo em umas aplicações webs mais antigas por aqui, encontrei um script q desenvolvi há um tempo atras e que me custou um tempinho p/ fazer.
Resolvi compartilhá-lo.
Segue o código fonte abaixo , salve o como mcezzare_calendar.asp, ou como quiser, e aonde está o código
<a href="http://REPLACE_YOUR_SITE/agenda_itens.php?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a>
1 - Acerte o link e o target caso esteja dentro de um frame ou o detalhe do evento esteja num iframe. se não remova o texto target="miolo".
Resolvi compartilhá-lo.
Segue o código fonte abaixo , salve o como mcezzare_calendar.asp, ou como quiser, e aonde está o código
<a href="http://REPLACE_YOUR_SITE/agenda_itens.php?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a>
1 - Acerte o link e o target caso esteja dentro de um frame ou o detalhe do evento esteja num iframe. se não remova o texto target="miolo".
2 - Este calendario pode ser usado p/ varios sites :
veja um exemplo chamando script dessa maneira na url :
http://REPLACE_YOUR_SITE/mcezzare_calendar.asp?data=01/3/2005&days=1-9-14-25-27
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Option Explicit
'Mcezzare's Calendar
'mcezzare@gmail.com last update Mon Aug 9 10:21:23 on ttys000
'version 1.3 date Fri Nov 25 08:31:32 BRST 2005
'this file display a calendar in table acording to the variable data on url ?data=dd/mm/yy
'if no value given, the default system time (now) wiill be used
' use : http://your_domain.com/calendar_final.asp?data=01/3/2005&days=1-9-14-25-27
'this calendar is mathematically correct, just chnage the line Session.lcid = xxx to you timezone/language
'from the value data on url the script builds a ccalendar based on Year and Month
'If you want to flag some days
Dim mes_st,mes,dia_st,dia_ini,dia_fim,dtx,mes_fresco,data,mesname,proximomes,ano,dia,mesanterior
Dim link,linkano,linkano_prox,linkmes_prox,linkmes_ant,linkano_ant,linksmes_prox
Dim i,x,z
Dim days,days_aux,high_days, color,teste,check_high
Dim diasr, diasr_aux,writeaux
Dim aux_file
Session.lcid = 1046 ' pt-BR
if request("data") = "" then
data = now
else
data = request("data")
end if
if not isdate(data) then data = now
' date variables
mes_st = month(data)
mes = month(data)
mesname = monthname(mes)
dia_st=1
ano = year(data)
dia_ini = dateserial(ano,mes,1)
dia_fim =dateserial(ano,mes +1,1)-1
dtx =weekday(dateserial(ano,mes,dia_st))
mes_fresco = Ucase(Left(mesname,1)) & Lcase(right(mesname,len(mesname)-1))
' file name , you can give any name.
link = Request.ServerVariables("SCRIPT_NAME") & "?data=01/"
aux_file= "http://REPLACE_YOUR_SITE/agenda_itens.php"
' if there is a other file you want to save data on database for example, you can call this page for your site
' like this
proximomes = mes + 1
mesanterior= mes - 1
'tem q fazer um select case p/ o mes qdo for 01 e 12
linkano = ano
linkano_prox = ano
linkano_ant = ano
linkmes_ant = mes
linksmes_prox = mes
select case mes
case 1
linkano_ant = ano - 1
linkmes_ant = 12
linkmes_prox = mes + 1
case 12
linkano_prox= ano + 1
linkmes_prox = 1
linkmes_ant = mes -1
linkano_ant = ano
case else
linkano = ano
linkano_prox = ano
linkano_ant = ano
linkmes_ant = mes - 1
linkmes_prox = mes + 1
end select
days=Request("days")
days_aux = split(days,"-")
diasr= Request("dias")
diasr_aux = split(diasr,"-")
check_high = false
color = "#FFFFFF"
function testa(x)
testa = false
for z = lbound(days_aux) to Ubound(days_aux)
' if cdbl(days_aux(z)) = cdbl(x) then check_high = true
' if cdbl(days_aux(z)) = cdbl(x) then color = "#FF0000"
if cdbl(days_aux(z)) = cdbl(x) then testa = true
'response.write typename(vartype(days_aux(z))) & "-" & typename(vartype(x)) & " " & check_high & "<br>"
response.write cdbl(days_aux(z)) & "-" & cdbl(x) & " --> " & check_high & " " & color & "<br>"
'response.write z & "-" & days_aux(z) & "-" & x
next
end function
'
'high_days = high_days &
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Calendario</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="calendar.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript">
<!--
function pinta(x){
document.getElementById("calendar").bgColor= "#FFFF00";
}
function pintacel(x){
var f = document.form1;
var campo = x;
//document.form1.x.class='botao3';
//window.alert(document.getElementById(''+campo).value);
//document.getElementById(''+campo)
document.ids.cp1.color="#FFFF00";
}
function pintacelretorno(x){
var f = document.form1;
var campo = x;
document.ids.cp1.color="#6699FF";
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_changeProp(objName,x,theProp,theValue) { //v6.0
var obj = MM_findObj(objName);
if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
if (theValue == true || theValue == false)
eval("obj."+theProp+"="+theValue);
else eval("obj."+theProp+"='"+theValue+"'");
}
}
//-->
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="
<% for z = lbound(diasr_aux) to Ubound(diasr_aux)%>
MM_changeProp('cp<%=diasr_aux(z)%>','','style.backgroundColor','#6699FF','DIV');
<% next%>
<% for z = lbound(days_aux) to Ubound(days_aux)
%>
MM_changeProp('cp<%=days_aux(z)%>','','style.backgroundColor','#FFFF00','DIV');
<% next%>
">
<!-- <p>
mes : <% = mes %><br>
ano : <% = ano %><br>
primeiro dia da semana : <% = weekdayname(dtx) %><br>
primeiro dia do mes : <% = dia_ini %><br>
ultimo dia do mes : <% = dia_fim %><br>
dias selecionados : <% = days %>
<br>
<a href="#" onClick="pinta(1);">pinta</a> tabela<br>
<a href="#" onClick="pintacel('cp2');">pinta celula</a><br>
<a href="#" onClick="MM_changeProp('div2','','style.backgroundColor','#FFFF00','DIV')">cc
</a> <a href="#" onClick="MM_changeProp('cp2','','style.backgroundColor','#FFFF00','DIV')">cc </a> <a href="#" onClick="MM_changeProp('cp8','','style.backgroundColor','#FFFF00','DIV')">cc </a><br>
</p>
<div class="botao2" id="div2">hdskjhksdj</div>
<p> </p>
<p> </p>
-->
<form action="#" method="post" name="form1" id="form1">
<table width="140" border="1" align="center" cellpadding="0" cellspacing="0" class="tabela">
<tr>
<td valign="top">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" id="calendar">
<tr align="center">
<td colspan="7" class="center11verdanaRED">
<!--<a href="<% = link & linkmes_ant & "/" & linkano_ant %>"><<</a> <a href="#"> </a> -->
<% = mes_fresco %>
-
<% = ano %>
<!-- <a href="<% = link & linkmes_prox & "/" & linkano_prox%>"> >></a> -->
</td>
</tr>
<tr align="center" class="center12verdanaBOLD">
<% for i = 1 to 7 %>
<td>
<% =Ucase(Left(weekdayname(weekday(i)),1))%>
</td>
<% next%>
</tr>
<tr align="center">
<%
days_aux = split(days,"-")
Select Case dtx 'day of week
case 1
color = "#FFFFFF"
for x = day(dia_ini) to day(dia_fim)
%>
<td> <div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x mod 7 =0 then response.write " </tr><tr align='center'>"
next
%>
<% case 2 %>
<td><div class="botao2" id="branco"></div></td>
<% for x = day(dia_ini) to day(dia_fim)
%>
<td><div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x =6 then response.write " </tr><tr align='center'>"
if x =13 then response.write " </tr><tr align='center'>"
if x =20 then response.write " </tr><tr align='center'>"
if x =27 then response.write " </tr><tr align='center'>"
if x mod 7 =0 and x <> 7 and x <> 13 and x <> 14 and x <> 21 and x <> 28 then response.write " </tr><tr align='center'>"
next
%>
<% case 3 %>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<%
for x = day(dia_ini) to day(dia_fim)
%>
<td><div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x =5 then response.write " </tr><tr align='center'>"
if x =12 then response.write " </tr><tr align='center'>"
if x =19 then response.write " </tr><tr align='center'>"
if x =26 then response.write " </tr><tr align='center'>"
if x mod 7 =0 and x <> 7 and x <> 14 and x <> 21 and x <> 28 then response.write " </tr><tr align='center'>"
next
%>
<% case 4 %>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<%
for x = day(dia_ini) to day(dia_fim)
%>
<td><div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x =4 then response.write " </tr><tr align='center'>"
if x =11 then response.write " </tr><tr align='center'>"
if x =18 then response.write " </tr><tr align='center'>"
if x =25 then response.write " </tr><tr align='center'>"
if x mod 7 =0 and x <> 7 and x <> 14 and x <> 21 and x <> 28 then response.write " </tr><tr align='center'>"
next
%>
<% case 5 %>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<%
for x = day(dia_ini) to day(dia_fim)
%>
<td><div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x =3 then response.write " </tr><tr align='center'>"
if x =10 then response.write " </tr><tr align='center'>"
if x =17 then response.write " </tr><tr align='center'>"
if x =24 then response.write " </tr><tr align='center'>"
if x mod 7 =0 and x <> 7 and x <> 14 and x <> 21 and x <> 28 then response.write " </tr><tr align='center'>"
next%>
<% case 6 %>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<%
for x = day(dia_ini) to day(dia_fim)
%>
<td><div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x =2 then response.write " </tr><tr align='center'>"
if x =9 then response.write " </tr><tr align='center'>"
if x =16 then response.write " </tr><tr align='center'>"
if x =23 then response.write " </tr><tr align='center'>"
if x =30 then response.write " </tr><tr align='center'>"
if x mod 7 =0 and x <> 7 and x <> 14 and x <> 21 and x <> 28 then response.write " </tr><tr align='center'>"
next%>
<% case 7 %>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<%
for x = day(dia_ini) to day(dia_fim)
%>
<td><div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x =1 then response.write " </tr><tr align='center'>"
if x =8 then response.write " </tr><tr align='center'>"
if x =15 then response.write " </tr><tr align='center'>"
if x =22 then response.write " </tr><tr align='center'>"
if x =29 then response.write " </tr><tr align='center'>"
if x mod 7 =0 and x <> 7 and x <> 14 and x <> 21 and x <> 28 then response.write " </tr><tr align='center'>"
next%>
<%
end Select
%>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
<%
Option Explicit
'Mcezzare's Calendar
'mcezzare@gmail.com last update Mon Aug 9 10:21:23 on ttys000
'version 1.3 date Fri Nov 25 08:31:32 BRST 2005
'this file display a calendar in table acording to the variable data on url ?data=dd/mm/yy
'if no value given, the default system time (now) wiill be used
' use : http://your_domain.com/calendar_final.asp?data=01/3/2005&days=1-9-14-25-27
'this calendar is mathematically correct, just chnage the line Session.lcid = xxx to you timezone/language
'from the value data on url the script builds a ccalendar based on Year and Month
'If you want to flag some days
Dim mes_st,mes,dia_st,dia_ini,dia_fim,dtx,mes_fresco,data,mesname,proximomes,ano,dia,mesanterior
Dim link,linkano,linkano_prox,linkmes_prox,linkmes_ant,linkano_ant,linksmes_prox
Dim i,x,z
Dim days,days_aux,high_days, color,teste,check_high
Dim diasr, diasr_aux,writeaux
Dim aux_file
Session.lcid = 1046 ' pt-BR
if request("data") = "" then
data = now
else
data = request("data")
end if
if not isdate(data) then data = now
' date variables
mes_st = month(data)
mes = month(data)
mesname = monthname(mes)
dia_st=1
ano = year(data)
dia_ini = dateserial(ano,mes,1)
dia_fim =dateserial(ano,mes +1,1)-1
dtx =weekday(dateserial(ano,mes,dia_st))
mes_fresco = Ucase(Left(mesname,1)) & Lcase(right(mesname,len(mesname)-1))
' file name , you can give any name.
link = Request.ServerVariables("SCRIPT_NAME") & "?data=01/"
aux_file= "http://REPLACE_YOUR_SITE/agenda_itens.php"
' if there is a other file you want to save data on database for example, you can call this page for your site
' like this
proximomes = mes + 1
mesanterior= mes - 1
'tem q fazer um select case p/ o mes qdo for 01 e 12
linkano = ano
linkano_prox = ano
linkano_ant = ano
linkmes_ant = mes
linksmes_prox = mes
select case mes
case 1
linkano_ant = ano - 1
linkmes_ant = 12
linkmes_prox = mes + 1
case 12
linkano_prox= ano + 1
linkmes_prox = 1
linkmes_ant = mes -1
linkano_ant = ano
case else
linkano = ano
linkano_prox = ano
linkano_ant = ano
linkmes_ant = mes - 1
linkmes_prox = mes + 1
end select
days=Request("days")
days_aux = split(days,"-")
diasr= Request("dias")
diasr_aux = split(diasr,"-")
check_high = false
color = "#FFFFFF"
function testa(x)
testa = false
for z = lbound(days_aux) to Ubound(days_aux)
' if cdbl(days_aux(z)) = cdbl(x) then check_high = true
' if cdbl(days_aux(z)) = cdbl(x) then color = "#FF0000"
if cdbl(days_aux(z)) = cdbl(x) then testa = true
'response.write typename(vartype(days_aux(z))) & "-" & typename(vartype(x)) & " " & check_high & "<br>"
response.write cdbl(days_aux(z)) & "-" & cdbl(x) & " --> " & check_high & " " & color & "<br>"
'response.write z & "-" & days_aux(z) & "-" & x
next
end function
'
'high_days = high_days &
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Calendario</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="calendar.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript">
<!--
function pinta(x){
document.getElementById("calendar").bgColor= "#FFFF00";
}
function pintacel(x){
var f = document.form1;
var campo = x;
//document.form1.x.class='botao3';
//window.alert(document.getElementById(''+campo).value);
//document.getElementById(''+campo)
document.ids.cp1.color="#FFFF00";
}
function pintacelretorno(x){
var f = document.form1;
var campo = x;
document.ids.cp1.color="#6699FF";
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_changeProp(objName,x,theProp,theValue) { //v6.0
var obj = MM_findObj(objName);
if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
if (theValue == true || theValue == false)
eval("obj."+theProp+"="+theValue);
else eval("obj."+theProp+"='"+theValue+"'");
}
}
//-->
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="
<% for z = lbound(diasr_aux) to Ubound(diasr_aux)%>
MM_changeProp('cp<%=diasr_aux(z)%>','','style.backgroundColor','#6699FF','DIV');
<% next%>
<% for z = lbound(days_aux) to Ubound(days_aux)
%>
MM_changeProp('cp<%=days_aux(z)%>','','style.backgroundColor','#FFFF00','DIV');
<% next%>
">
<!-- <p>
mes : <% = mes %><br>
ano : <% = ano %><br>
primeiro dia da semana : <% = weekdayname(dtx) %><br>
primeiro dia do mes : <% = dia_ini %><br>
ultimo dia do mes : <% = dia_fim %><br>
dias selecionados : <% = days %>
<br>
<a href="#" onClick="pinta(1);">pinta</a> tabela<br>
<a href="#" onClick="pintacel('cp2');">pinta celula</a><br>
<a href="#" onClick="MM_changeProp('div2','','style.backgroundColor','#FFFF00','DIV')">cc
</a> <a href="#" onClick="MM_changeProp('cp2','','style.backgroundColor','#FFFF00','DIV')">cc </a> <a href="#" onClick="MM_changeProp('cp8','','style.backgroundColor','#FFFF00','DIV')">cc </a><br>
</p>
<div class="botao2" id="div2">hdskjhksdj</div>
<p> </p>
<p> </p>
-->
<form action="#" method="post" name="form1" id="form1">
<table width="140" border="1" align="center" cellpadding="0" cellspacing="0" class="tabela">
<tr>
<td valign="top">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" id="calendar">
<tr align="center">
<td colspan="7" class="center11verdanaRED">
<!--<a href="<% = link & linkmes_ant & "/" & linkano_ant %>"><<</a> <a href="#"> </a> -->
<% = mes_fresco %>
-
<% = ano %>
<!-- <a href="<% = link & linkmes_prox & "/" & linkano_prox%>"> >></a> -->
</td>
</tr>
<tr align="center" class="center12verdanaBOLD">
<% for i = 1 to 7 %>
<td>
<% =Ucase(Left(weekdayname(weekday(i)),1))%>
</td>
<% next%>
</tr>
<tr align="center">
<%
days_aux = split(days,"-")
Select Case dtx 'day of week
case 1
color = "#FFFFFF"
for x = day(dia_ini) to day(dia_fim)
%>
<td> <div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x mod 7 =0 then response.write " </tr><tr align='center'>"
next
%>
<% case 2 %>
<td><div class="botao2" id="branco"></div></td>
<% for x = day(dia_ini) to day(dia_fim)
%>
<td><div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x =6 then response.write " </tr><tr align='center'>"
if x =13 then response.write " </tr><tr align='center'>"
if x =20 then response.write " </tr><tr align='center'>"
if x =27 then response.write " </tr><tr align='center'>"
if x mod 7 =0 and x <> 7 and x <> 13 and x <> 14 and x <> 21 and x <> 28 then response.write " </tr><tr align='center'>"
next
%>
<% case 3 %>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<%
for x = day(dia_ini) to day(dia_fim)
%>
<td><div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x =5 then response.write " </tr><tr align='center'>"
if x =12 then response.write " </tr><tr align='center'>"
if x =19 then response.write " </tr><tr align='center'>"
if x =26 then response.write " </tr><tr align='center'>"
if x mod 7 =0 and x <> 7 and x <> 14 and x <> 21 and x <> 28 then response.write " </tr><tr align='center'>"
next
%>
<% case 4 %>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<%
for x = day(dia_ini) to day(dia_fim)
%>
<td><div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x =4 then response.write " </tr><tr align='center'>"
if x =11 then response.write " </tr><tr align='center'>"
if x =18 then response.write " </tr><tr align='center'>"
if x =25 then response.write " </tr><tr align='center'>"
if x mod 7 =0 and x <> 7 and x <> 14 and x <> 21 and x <> 28 then response.write " </tr><tr align='center'>"
next
%>
<% case 5 %>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<%
for x = day(dia_ini) to day(dia_fim)
%>
<td><div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x =3 then response.write " </tr><tr align='center'>"
if x =10 then response.write " </tr><tr align='center'>"
if x =17 then response.write " </tr><tr align='center'>"
if x =24 then response.write " </tr><tr align='center'>"
if x mod 7 =0 and x <> 7 and x <> 14 and x <> 21 and x <> 28 then response.write " </tr><tr align='center'>"
next%>
<% case 6 %>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<%
for x = day(dia_ini) to day(dia_fim)
%>
<td><div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x =2 then response.write " </tr><tr align='center'>"
if x =9 then response.write " </tr><tr align='center'>"
if x =16 then response.write " </tr><tr align='center'>"
if x =23 then response.write " </tr><tr align='center'>"
if x =30 then response.write " </tr><tr align='center'>"
if x mod 7 =0 and x <> 7 and x <> 14 and x <> 21 and x <> 28 then response.write " </tr><tr align='center'>"
next%>
<% case 7 %>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<td><div class="botao2" id="branco"></div></td>
<%
for x = day(dia_ini) to day(dia_fim)
%>
<td><div class="botao2" id="cp<%=x%>"><a href="<%=aux_file%>?data=<%=x%>/<%=mes%>/<%=ano%>" target="miolo"><%=x%></a></div></td>
<%
if x =1 then response.write " </tr><tr align='center'>"
if x =8 then response.write " </tr><tr align='center'>"
if x =15 then response.write " </tr><tr align='center'>"
if x =22 then response.write " </tr><tr align='center'>"
if x =29 then response.write " </tr><tr align='center'>"
if x mod 7 =0 and x <> 7 and x <> 14 and x <> 21 and x <> 28 then response.write " </tr><tr align='center'>"
next%>
<%
end Select
%>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
sexta-feira, 9 de julho de 2010
Troca de senha de múltiplos Usuários com SAMBA e shell script e teste com SMBCLIENT
Como no exemplo anterior a lista de usuarios saem de uma tabela Mysql , onde tenho os logins e senhas. A partir dela gero um arquivo csv (userstrocasenha.txt) e um script em shell p/ fazer a tarefa (troca_senha.sh) como descrito abaixo :
Exemplo feito em
Linux pdc-sp 2.6.18-6-686 #1 SMP Sun Feb 10 22:11:31 UTC 2008 i686 GNU/Linux
Samba :
pdc-sp:~/scripts# smbd -V
Version 3.0.24
Antes de rodar o script , se quiser criar usuarios p/ testar o script , utilizo o seguinte script p/ criar usuários:
pdc-sp:~/scripts# cat adu.sh
#!/bin/sh
#script p/ adicionar usuyarios ao samba e ao linux
# Author Mario Cezzare mcezzare@gmail.com
if [ -n "$1" ]
then
usuario="$1"
#senha=$2
#echo $usuario
#echo $senha
#STEP 1
#create user at linux system with no login
/usr/sbin/useradd -m -s /bin/false -c ntuser -G ntusers $usuario
#STEP 2
#locka a senha
passwd -l $usuario
#STEP 3
#add smb user
smbpasswd -a $usuario
#STEP 4
echo -e "$senha\n$senha" | (smbpasswd -e -s $usuario)
else
echo "Informe o Usuario"
fi
Linux pdc-sp 2.6.18-6-686 #1 SMP Sun Feb 10 22:11:31 UTC 2008 i686 GNU/Linux
Samba :
pdc-sp:~/scripts# smbd -V
Version 3.0.24
OBS 1: Para aumentar a segurança do sistema os existem usuários locais do linux p/ os Homedirs que nao não podem logar na máquina e em qq outro serviço exceto o Samba que funciona como PDC.
O arquivo de senhas do SAMBA fica em /etc/samba/smbpasswd.db
O texto q estiver dessa maneira é o q foi digitado :
Exemplo para a Autenticação no SAMBA pdc-sp:~/scripts# cat troca_senha.sh
#!/bin/sh
#!/bin/sh
# modelo do arquivo user;senha
FILEIMPORT="userstrocasenha.txt"
for x in `cat $FILEIMPORT`;
do
usuario=$(echo $x | cut -d ";" -f 1)
senha=$(echo $x | cut -d ";" -f 2)
#usuario=$1
#senha=$2
#echo $usuario
echo "trocando a senha do usuario:$usuario"
#echo $senha
#(echo $senha; echo $senha) | smbpasswd -e $usuario -s
echo -e "$senha\n$senha" | (smbpasswd -a -s $usuario)
done
FILEIMPORT="userstrocasenha.txt"
for x in `cat $FILEIMPORT`;
do
usuario=$(echo $x | cut -d ";" -f 1)
senha=$(echo $x | cut -d ";" -f 2)
#usuario=$1
#senha=$2
#echo $usuario
echo "trocando a senha do usuario:$usuario"
#echo $senha
#(echo $senha; echo $senha) | smbpasswd -e $usuario -s
echo -e "$senha\n$senha" | (smbpasswd -a -s $usuario)
done
Antes de rodar o script , se quiser criar usuarios p/ testar o script , utilizo o seguinte script p/ criar usuários:
pdc-sp:~/scripts# cat adu.sh
#!/bin/sh
#script p/ adicionar usuyarios ao samba e ao linux
# Author Mario Cezzare mcezzare@gmail.com
if [ -n "$1" ]
then
usuario="$1"
#senha=$2
#echo $usuario
#echo $senha
#STEP 1
#create user at linux system with no login
/usr/sbin/useradd -m -s /bin/false -c ntuser -G ntusers $usuario
#STEP 2
#locka a senha
passwd -l $usuario
#STEP 3
#add smb user
smbpasswd -a $usuario
#STEP 4
echo -e "$senha\n$senha" | (smbpasswd -e -s $usuario)
else
echo "Informe o Usuario"
fi
p/ ter certeza de que não existirá esse usuario
pdc-sp:~/scripts# smbpasswd -x usertest1
Deleted user usertest1.
pdc-sp:~/scripts# userdel -r usertest1
Deleted user usertest1.
pdc-sp:~/scripts# userdel -r usertest1
Vamos criar o usuário usertest1
pdc-sp:~/scripts# sh adu.sh usertest1
Senha modificada.
New SMB password:x
Retype new SMB password:x
Added user usertest1.
Enabled user usertest1.
Senha modificada.
New SMB password:x
Retype new SMB password:x
Added user usertest1.
Enabled user usertest1.
Vamos testar o acesso com a senha errada
pdc-sp:~/scripts# smbclient -L \\localhost -U usertest1
Password: qqqq
session setup failed: NT_STATUS_LOGON_FAILURE
Password: qqqq
session setup failed: NT_STATUS_LOGON_FAILURE
Vamos testar o acesso com a senha correta
pdc-sp:~/scripts# smbclient -L \\localhost -U usertest1
Password: x
Domain=[PDCSERVER-SP] OS=[Unix] Server=[Samba 3.0.24]
Sharename Type Comment
--------- ---- -------
IPC$ IPC IPC Service (pdc-sp server)
usertest1 Disk Home Directories
Domain=[PDCSERVER-SP] OS=[Unix] Server=[Samba 3.0.24]
Server Comment
--------- -------
PDCSERVER-PDC-SP pdc-sp server
Workgroup Master
--------- -------
PDCSERVER-SP PDCSERVER-D8DBD85
Password: x
Domain=[PDCSERVER-SP] OS=[Unix] Server=[Samba 3.0.24]
Sharename Type Comment
--------- ---- -------
IPC$ IPC IPC Service (pdc-sp server)
usertest1 Disk Home Directories
Domain=[PDCSERVER-SP] OS=[Unix] Server=[Samba 3.0.24]
Server Comment
--------- -------
PDCSERVER-PDC-SP pdc-sp server
Workgroup Master
--------- -------
PDCSERVER-SP PDCSERVER-D8DBD85
vamos trocar a senha desse usuário :
pdc-sp:~/scripts# sh troca_senha.sh
trocando a senha do usuario:usertest1
vamos testar com senha antiga (x)
pdc-sp:~/scripts# smbclient -L \\localhost -U usertest1
Password:x
session setup failed: NT_STATUS_LOGON_FAILURE
pdc-sp:~/scripts#
Password:x
session setup failed: NT_STATUS_LOGON_FAILURE
pdc-sp:~/scripts#
Vamos testar o acesso com a senha alterada pelo script (xxx)
pdc-sp:~/scripts# smbclient -L \\localhost -U usertest1
Password: xxx
Domain=[PDCSERVER-SP] OS=[Unix] Server=[Samba 3.0.24]
Sharename Type Comment
--------- ---- -------
IPC$ IPC IPC Service (pdc-sp server)
usertest1 Disk Home Directories
Domain=[PDCSERVER-SP] OS=[Unix] Server=[Samba 3.0.24]
Server Comment
--------- -------
PDCSERVER-PDC-SP pdc-sp server
Workgroup Master
--------- -------
PDCSERVER-SP PDCSERVER-D8DBD85
Password: xxx
Domain=[PDCSERVER-SP] OS=[Unix] Server=[Samba 3.0.24]
Sharename Type Comment
--------- ---- -------
IPC$ IPC IPC Service (pdc-sp server)
usertest1 Disk Home Directories
Domain=[PDCSERVER-SP] OS=[Unix] Server=[Samba 3.0.24]
Server Comment
--------- -------
PDCSERVER-PDC-SP pdc-sp server
Workgroup Master
--------- -------
PDCSERVER-SP PDCSERVER-D8DBD85
vamos remover esses usuario de teste
pdc-sp:~/scripts# smbpasswd -x usertest1
Deleted user usertest1.
pdc-sp:~/scripts# userdel -r usertest1
Deleted user usertest1.
pdc-sp:~/scripts# userdel -r usertest1
Essa é uma maneira rápida e simples de trocar as senhas quando o método de Autenticação é o próprio SAMBA , e os logins e senhas ficam nos arquivos /etc/samba/smbpasswd.db , que são gerenciados pelo programa smbpasswd.
Depois desses scripts o proximo post pode ser a instação de um LDAP neh , rs ..
[]'s
Marcadores:
Linux,
Shell Script,
SysAdmin,
Unix
Troca de senha de múltiplos Usuários com SQUID e shell script e teste com WGET
Como no exemplo anterior a lista de usuarios saem de uma tabela Mysql , onde tenho os logins e senhas. A partir dela gero um arquivo csv (userstrocasenha.txt) e um script em shell p/ fazer a tarefa (troca_senha.sh) como descrito abaixo :
Exemplo feito em
surfer@proxy:~$uname -a
OpenBSD proxy.portari.com.br 4.6 GENERIC.MP#89 i386
surfer@proxy:~$squid -v
Squid Cache: Version 2.7.STABLE6
configure options: '--datadir=/usr/local/share/squid' '--enable-auth=basic digest' '--enable-arp-acl' '--enable-basic-auth-helpers=NCSA YP' '--enable-digest-auth-helpers=password' '--enable-delay-pools' '--enable-external-acl-helpers=ip_user unix_group' '--enable-forw-via-db' '--enable-negotiate-auth-helpers=squid_kerb_auth' '--enable-pf-transparent' '--enable-removal-policies=lru heap' '--enable-ssl' '--enable-storeio=aufs ufs diskd null' '--with-pthreads' '--localstatedir=/var/squid' '--enable-follow-x-forwarded-for' '--enable-snmp' '--prefix=/usr/local' '--sysconfdir=/etc' '--mandir=/usr/local/man' '--infodir=/usr/local/info' 'CC=cc' 'CFLAGS=-O2 -pipe' )
Squid Cache: Version 2.7.STABLE6
configure options: '--datadir=/usr/local/share/squid' '--enable-auth=basic digest' '--enable-arp-acl' '--enable-basic-auth-helpers=NCSA YP' '--enable-digest-auth-helpers=password' '--enable-delay-pools' '--enable-external-acl-helpers=ip_user unix_group' '--enable-forw-via-db' '--enable-negotiate-auth-helpers=squid_kerb_auth' '--enable-pf-transparent' '--enable-removal-policies=lru heap' '--enable-ssl' '--enable-storeio=aufs ufs diskd null' '--with-pthreads' '--localstatedir=/var/squid' '--enable-follow-x-forwarded-for' '--enable-snmp' '--prefix=/usr/local' '--sysconfdir=/etc' '--mandir=/usr/local/man' '--infodir=/usr/local/info' 'CC=cc' 'CFLAGS=-O2 -pipe' )
O arquivo de senhas do squid fica em /etc/squid/squid-passwd
O texto q estiver dessa maneira é o q foi digitado :
Exemplo para a Autenticação no SQUID
surfer@proxy:~$cat userstrocasenha.txt
usertest1;xxx
usertest2;yyy
surfer@proxy:~$cat userstrocasenha.txt
usertest1;xxx
usertest2;yyy
surfer@proxy:~$cat troca_senha.sh
#!/bin/sh
#!/bin/sh
# Author : Mario Cezzare - mcezzare@gmail.com# modelo do arquivo user;senha
FILEIMPORT="userstrocasenha.txt"
for x in `cat $FILEIMPORT`;
do
usuario=$(echo $x | cut -d ";" -f 1)
senha=$(echo $x | cut -d ";" -f 2)
#usuario=$1
#senha=$2
#echo $usuario
echo "trocando a senha do usuario:$usuario"
#echo $senha
( /usr/bin/htpasswd -b /etc/squid/squid-passwd $usuario $senha)
done
FILEIMPORT="userstrocasenha.txt"
for x in `cat $FILEIMPORT`;
do
usuario=$(echo $x | cut -d ";" -f 1)
senha=$(echo $x | cut -d ";" -f 2)
#usuario=$1
#senha=$2
#echo $usuario
echo "trocando a senha do usuario:$usuario"
#echo $senha
( /usr/bin/htpasswd -b /etc/squid/squid-passwd $usuario $senha)
done
Antes de rodar o script , se quiser criar usuarios p/ testar o script:
surfer@proxy:~$sudo htpasswd /etc/squid/squid-passwd usertest1
New password:x
Re-type new password:x
Adding password for user usertest1
surfer@proxy:~$sudo htpasswd /etc/squid/squid-passwd usertest2
New password:y
Re-type new password:y
Adding password for user usertest2
surfer@proxy:~$sudo htpasswd /etc/squid/squid-passwd usertest1
New password:x
Re-type new password:x
Adding password for user usertest1
surfer@proxy:~$sudo htpasswd /etc/squid/squid-passwd usertest2
New password:y
Re-type new password:y
Adding password for user usertest2
conferindo
surfer@proxy:~$sudo cat /etc/squid/squid-passwd | grep usertest
usertest1:$2a$06$x1OeGXv5KjBqHTRXyP/WrOrcLVmx9.cjREt812COWJ36hwgaLIll.
usertest2:$2a$06$5Wxexk5S/YUhDaWxNm6f/uY3pRTiKlbAyy0B5v2gaZRUBT3zA5E3.
reiniciando o squid p/ reconhecimento dos usuários :
surfer@proxy:~$sudo squid -k reconfigure
p/ testar e poder mostrar no post o acesso, log e erros, utilizarei o apt de uma maquina debian/linux na mesma rede deste proxy, p/ não instalar ferramentas de download no Proxy por motivos de segurança.
veja a configuração do arquivo /etc/apt.conf da maquina cliente :
hostmachine:~# cat /etc/apt/apt.conf
Acquire::http::Proxy "http://usertest1:x@proxy:3128";
Acquire::http::Proxy "http://usertest1:x@proxy:3128";
hostmachine:~# apt-get update
Get:1 http://ftp.br.debian.org lenny Release.gpg [1033B]
Ign http://ftp.br.debian.org lenny/main Translation-en_US
Ign http://ftp.br.debian.org lenny/non-free Translation-en_US
Ign http://ftp.br.debian.org lenny/contrib Translation-en_US
Hit http://ftp.br.debian.org lenny Release
Ign http://ftp.br.debian.org lenny/main Packages/DiffIndex
Ign http://ftp.br.debian.org lenny/non-free Packages/DiffIndex
Ign http://ftp.br.debian.org lenny/contrib Packages/DiffIndex
Ign http://ftp.br.debian.org lenny/main Sources/DiffIndex
Ign http://ftp.br.debian.org lenny/non-free Sources/DiffIndex
Ign http://ftp.br.debian.org lenny/contrib Sources/DiffIndex
Get:1 http://ftp.br.debian.org lenny Release.gpg [1033B]
Ign http://ftp.br.debian.org lenny/main Translation-en_US
Ign http://ftp.br.debian.org lenny/non-free Translation-en_US
Ign http://ftp.br.debian.org lenny/contrib Translation-en_US
Hit http://ftp.br.debian.org lenny Release
Ign http://ftp.br.debian.org lenny/main Packages/DiffIndex
Ign http://ftp.br.debian.org lenny/non-free Packages/DiffIndex
Ign http://ftp.br.debian.org lenny/contrib Packages/DiffIndex
Ign http://ftp.br.debian.org lenny/main Sources/DiffIndex
Ign http://ftp.br.debian.org lenny/non-free Sources/DiffIndex
Ign http://ftp.br.debian.org lenny/contrib Sources/DiffIndex
etc...
e nos logs do Squid
surfer@proxy:~$sudo tail -f /var/squid/logs/access.log
1278698863.984 30 200.xxx.xxx.xxx TCP_REFRESH_HIT/304 245 GET http://ftp.br.debian.org/debian/dists/lenny/Release.gpg usertest1 DIRECT/200.17.202.1 -
1278698863.984 30 200.xxx.xxx.xxx TCP_REFRESH_HIT/304 245 GET http://ftp.br.debian.org/debian/dists/lenny/Release.gpg usertest1 DIRECT/200.17.202.1 -
1278698863.985 0 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 626 GET http://ftp.br.debian.org/debian/dists/lenny/main/i18n/Translation-en_US.bz2 usertest1 NONE/- text/html
1278698863.985 0 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 626 GET http://ftp.br.debian.org/debian/dists/lenny/main/i18n/Translation-en_US.bz2 usertest1 NONE/- text/html
1278698863.986 0 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 630 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/i18n/Translation-en_US.bz2 usertest1 NONE/- text/html
1278698863.986 0 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 630 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/i18n/Translation-en_US.bz2 usertest1 NONE/- text/html
1278698863.987 0 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 629 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/i18n/Translation-en_US.bz2 usertest1 NONE/- text/html
1278698863.987 0 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 629 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/i18n/Translation-en_US.bz2 usertest1 NONE/- text/html
1278698864.002 15 200.xxx.xxx.xxx TCP_MISS/304 247 GET http://ftp.br.debian.org/debian/dists/lenny/Release usertest1 DIRECT/200.17.202.1 -
1278698864.002 15 200.xxx.xxx.xxx TCP_MISS/304 247 GET http://ftp.br.debian.org/debian/dists/lenny/Release usertest1 DIRECT/200.17.202.1 -
1278698864.016 1 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 631 GET http://ftp.br.debian.org/debian/dists/lenny/main/binary-i386/Packages.diff/Index usertest1 NONE/- text/html
1278698864.016 1 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 631 GET http://ftp.br.debian.org/debian/dists/lenny/main/binary-i386/Packages.diff/Index usertest1 NONE/- text/html
1278698864.018 1 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 635 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/binary-i386/Packages.diff/Index usertest1 NONE/- text/html
1278698863.984 30 200.xxx.xxx.xxx TCP_REFRESH_HIT/304 245 GET http://ftp.br.debian.org/debian/dists/lenny/Release.gpg usertest1 DIRECT/200.17.202.1 -
1278698863.985 0 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 626 GET http://ftp.br.debian.org/debian/dists/lenny/main/i18n/Translation-en_US.bz2 usertest1 NONE/- text/html
1278698863.985 0 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 626 GET http://ftp.br.debian.org/debian/dists/lenny/main/i18n/Translation-en_US.bz2 usertest1 NONE/- text/html
1278698863.986 0 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 630 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/i18n/Translation-en_US.bz2 usertest1 NONE/- text/html
1278698863.986 0 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 630 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/i18n/Translation-en_US.bz2 usertest1 NONE/- text/html
1278698863.987 0 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 629 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/i18n/Translation-en_US.bz2 usertest1 NONE/- text/html
1278698863.987 0 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 629 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/i18n/Translation-en_US.bz2 usertest1 NONE/- text/html
1278698864.002 15 200.xxx.xxx.xxx TCP_MISS/304 247 GET http://ftp.br.debian.org/debian/dists/lenny/Release usertest1 DIRECT/200.17.202.1 -
1278698864.002 15 200.xxx.xxx.xxx TCP_MISS/304 247 GET http://ftp.br.debian.org/debian/dists/lenny/Release usertest1 DIRECT/200.17.202.1 -
1278698864.016 1 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 631 GET http://ftp.br.debian.org/debian/dists/lenny/main/binary-i386/Packages.diff/Index usertest1 NONE/- text/html
1278698864.016 1 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 631 GET http://ftp.br.debian.org/debian/dists/lenny/main/binary-i386/Packages.diff/Index usertest1 NONE/- text/html
1278698864.018 1 200.xxx.xxx.xxx TCP_NEGATIVE_HIT/404 635 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/binary-i386/Packages.diff/Index usertest1 NONE/- text/html
e rode o script p/ trocar a senha
surfer@proxy:~$sudo sh troca_senha.sh
trocando a senha do usuario:usertest1
Updating password for user usertest1
trocando a senha do usuario:usertest2
Updating password for user usertest2
Updating password for user usertest1
trocando a senha do usuario:usertest2
Updating password for user usertest2
no cliente com a nova senha
hostmachine:/home/surfer# cat /etc/apt/apt.conf
Acquire::http::Proxy "http://usertest1:xxx@proxy:3128";
hostmachine:/home/surfer# apt-get update
Hit http://ftp.br.debian.org lenny Release.gpg
Ign http://ftp.br.debian.org lenny/main Translation-en_US
Ign http://ftp.br.debian.org lenny/non-free Translation-en_US
Ign http://ftp.br.debian.org lenny/contrib Translation-en_US
Hit http://ftp.br.debian.org lenny Release
Ign http://ftp.br.debian.org lenny/main Packages/DiffIndex
Ign http://ftp.br.debian.org lenny/non-free Packages/DiffIndex
Ign http://ftp.br.debian.org lenny/contrib Packages/DiffIndex
Ign http://ftp.br.debian.org lenny/main Sources/DiffIndex
Ign http://ftp.br.debian.org lenny/non-free Sources/DiffIndex
Ign http://ftp.br.debian.org lenny/contrib Sources/DiffIndex
Hit http://ftp.br.debian.org lenny/main Packages
Hit http://ftp.br.debian.org lenny/non-free Packages
Hit http://ftp.br.debian.org lenny/contrib Packages
Hit http://ftp.br.debian.org lenny/main Sources
Hit http://ftp.br.debian.org lenny/non-free Sources
Hit http://ftp.br.debian.org lenny/contrib Sources
Acquire::http::Proxy "http://usertest1:xxx@proxy:3128";
hostmachine:/home/surfer# apt-get update
Hit http://ftp.br.debian.org lenny Release.gpg
Ign http://ftp.br.debian.org lenny/main Translation-en_US
Ign http://ftp.br.debian.org lenny/non-free Translation-en_US
Ign http://ftp.br.debian.org lenny/contrib Translation-en_US
Hit http://ftp.br.debian.org lenny Release
Ign http://ftp.br.debian.org lenny/main Packages/DiffIndex
Ign http://ftp.br.debian.org lenny/non-free Packages/DiffIndex
Ign http://ftp.br.debian.org lenny/contrib Packages/DiffIndex
Ign http://ftp.br.debian.org lenny/main Sources/DiffIndex
Ign http://ftp.br.debian.org lenny/non-free Sources/DiffIndex
Ign http://ftp.br.debian.org lenny/contrib Sources/DiffIndex
Hit http://ftp.br.debian.org lenny/main Packages
Hit http://ftp.br.debian.org lenny/non-free Packages
Hit http://ftp.br.debian.org lenny/contrib Packages
Hit http://ftp.br.debian.org lenny/main Sources
Hit http://ftp.br.debian.org lenny/non-free Sources
Hit http://ftp.br.debian.org lenny/contrib Sources
etc...
e no servidoor proxy :
surfer@proxy:~$sudo tail -f /var/squid/logs/access.log
1278711296.118 360 200.xxx.xxx.xxx TCP_REFRESH_HIT/304 245 GET http://ftp.br.debian.org/debian/dists/lenny/Release.gpg usertest1 DIRECT/200.17.202.1 -
1278711296.118 360 200.xxx.xxx.xxx TCP_REFRESH_HIT/304 245 GET http://ftp.br.debian.org/debian/dists/lenny/Release.gpg usertest1 DIRECT/200.17.202.1 -
1278711296.152 32 200.xxx.xxx.xxx TCP_MISS/404 617 GET http://ftp.br.debian.org/debian/dists/lenny/main/i18n/Translation-en_US.bz2 usertest1 DIRECT/200.17.202.1 text/html
1278711296.152 32 200.xxx.xxx.xxx TCP_MISS/404 617 GET http://ftp.br.debian.org/debian/dists/lenny/main/i18n/Translation-en_US.bz2 usertest1 DIRECT/200.17.202.1 text/html
1278711296.174 20 200.xxx.xxx.xxx TCP_MISS/404 621 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/i18n/Translation-en_US.bz2 usertest1 DIRECT/200.17.202.1 text/html
1278711296.174 20 200.xxx.xxx.xxx TCP_MISS/404 621 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/i18n/Translation-en_US.bz2 usertest1 DIRECT/200.17.202.1 text/html
1278711296.191 16 200.xxx.xxx.xxx TCP_MISS/404 620 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/i18n/Translation-en_US.bz2 usertest1 DIRECT/200.17.202.1 text/html
1278711296.191 16 200.xxx.xxx.xxx TCP_MISS/404 620 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/i18n/Translation-en_US.bz2 usertest1 DIRECT/200.17.202.1 text/html
1278711296.209 17 200.xxx.xxx.xxx TCP_MISS/304 247 GET http://ftp.br.debian.org/debian/dists/lenny/Release usertest1 DIRECT/200.17.202.1 -
1278711296.209 17 200.xxx.xxx.xxx TCP_MISS/304 247 GET http://ftp.br.debian.org/debian/dists/lenny/Release usertest1 DIRECT/200.17.202.1 -
1278711296.238 16 200.xxx.xxx.xxx TCP_MISS/404 622 GET http://ftp.br.debian.org/debian/dists/lenny/main/binary-i386/Packages.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.238 16 200.xxx.xxx.xxx TCP_MISS/404 622 GET http://ftp.br.debian.org/debian/dists/lenny/main/binary-i386/Packages.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.255 16 200.xxx.xxx.xxx TCP_MISS/404 626 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/binary-i386/Packages.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.255 16 200.xxx.xxx.xxx TCP_MISS/404 626 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/binary-i386/Packages.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.272 16 200.xxx.xxx.xxx TCP_MISS/404 625 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/binary-i386/Packages.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.272 16 200.xxx.xxx.xxx TCP_MISS/404 625 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/binary-i386/Packages.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.289 16 200.xxx.xxx.xxx TCP_MISS/404 616 GET http://ftp.br.debian.org/debian/dists/lenny/main/source/Sources.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.289 16 200.xxx.xxx.xxx TCP_MISS/404 616 GET http://ftp.br.debian.org/debian/dists/lenny/main/source/Sources.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.309 18 200.xxx.xxx.xxx TCP_MISS/404 620 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/source/Sources.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.309 18 200.xxx.xxx.xxx TCP_MISS/404 620 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/source/Sources.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.335 25 200.xxx.xxx.xxx TCP_MISS/404 619 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/source
1278711296.118 360 200.xxx.xxx.xxx TCP_REFRESH_HIT/304 245 GET http://ftp.br.debian.org/debian/dists/lenny/Release.gpg usertest1 DIRECT/200.17.202.1 -
1278711296.118 360 200.xxx.xxx.xxx TCP_REFRESH_HIT/304 245 GET http://ftp.br.debian.org/debian/dists/lenny/Release.gpg usertest1 DIRECT/200.17.202.1 -
1278711296.152 32 200.xxx.xxx.xxx TCP_MISS/404 617 GET http://ftp.br.debian.org/debian/dists/lenny/main/i18n/Translation-en_US.bz2 usertest1 DIRECT/200.17.202.1 text/html
1278711296.152 32 200.xxx.xxx.xxx TCP_MISS/404 617 GET http://ftp.br.debian.org/debian/dists/lenny/main/i18n/Translation-en_US.bz2 usertest1 DIRECT/200.17.202.1 text/html
1278711296.174 20 200.xxx.xxx.xxx TCP_MISS/404 621 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/i18n/Translation-en_US.bz2 usertest1 DIRECT/200.17.202.1 text/html
1278711296.174 20 200.xxx.xxx.xxx TCP_MISS/404 621 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/i18n/Translation-en_US.bz2 usertest1 DIRECT/200.17.202.1 text/html
1278711296.191 16 200.xxx.xxx.xxx TCP_MISS/404 620 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/i18n/Translation-en_US.bz2 usertest1 DIRECT/200.17.202.1 text/html
1278711296.191 16 200.xxx.xxx.xxx TCP_MISS/404 620 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/i18n/Translation-en_US.bz2 usertest1 DIRECT/200.17.202.1 text/html
1278711296.209 17 200.xxx.xxx.xxx TCP_MISS/304 247 GET http://ftp.br.debian.org/debian/dists/lenny/Release usertest1 DIRECT/200.17.202.1 -
1278711296.209 17 200.xxx.xxx.xxx TCP_MISS/304 247 GET http://ftp.br.debian.org/debian/dists/lenny/Release usertest1 DIRECT/200.17.202.1 -
1278711296.238 16 200.xxx.xxx.xxx TCP_MISS/404 622 GET http://ftp.br.debian.org/debian/dists/lenny/main/binary-i386/Packages.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.238 16 200.xxx.xxx.xxx TCP_MISS/404 622 GET http://ftp.br.debian.org/debian/dists/lenny/main/binary-i386/Packages.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.255 16 200.xxx.xxx.xxx TCP_MISS/404 626 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/binary-i386/Packages.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.255 16 200.xxx.xxx.xxx TCP_MISS/404 626 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/binary-i386/Packages.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.272 16 200.xxx.xxx.xxx TCP_MISS/404 625 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/binary-i386/Packages.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.272 16 200.xxx.xxx.xxx TCP_MISS/404 625 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/binary-i386/Packages.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.289 16 200.xxx.xxx.xxx TCP_MISS/404 616 GET http://ftp.br.debian.org/debian/dists/lenny/main/source/Sources.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.289 16 200.xxx.xxx.xxx TCP_MISS/404 616 GET http://ftp.br.debian.org/debian/dists/lenny/main/source/Sources.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.309 18 200.xxx.xxx.xxx TCP_MISS/404 620 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/source/Sources.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.309 18 200.xxx.xxx.xxx TCP_MISS/404 620 GET http://ftp.br.debian.org/debian/dists/lenny/non-free/source/Sources.diff/Index usertest1 DIRECT/200.17.202.1 text/html
1278711296.335 25 200.xxx.xxx.xxx TCP_MISS/404 619 GET http://ftp.br.debian.org/debian/dists/lenny/contrib/source
etc..
Essa é uma maneira rápida e simples de trocar as senhas quando o método de Autenticação é o NCSA , e os logins e senhas ficam nos arquivos /etc/squid/ARQUIVO , que são gerenciados pelo programa htpasswd (do apache)
(no squid.conf :
auth_param basic program /usr/local/libexec/ncsa_auth /etc/squid/squid-passwd )
Samba fica p/ o próximo post
[]'s
Marcadores:
Linux,
Shell Script,
SysAdmin,
Unix
Troca de senha de múltiplos Usuários com PAM e shell script e teste com POP 3
Pense nessa situação:
Você tem vários usuarios e vários serviços diferentes em maquinas diferentes.
Serviços de Email, Proxy, Samba mas ainda nao usa uma base centralizada como LDAP.
Bem, segue uma dica com scripts p/ automatização dessa tarefa (já pensou trocar a senha manualmente de 400 usuários ?:( , ninguém merece neh ?)
Neste caso tenho uma tabela Mysql , onde tenho os logins e senhas. A partir dela gero um arquivo csv (userstrocasenha.txt) e um script em shell p/ fazer a tarefa (troca_senha.sh) como descrito abaixo :
o texto q estiver dessa maneira é o q foi digitado :
hostmachine:~/scripts# cat userstrocasenha.txt
usertest1;xxx
usertest2;yyy
Exemplo de Autenticação com PAM
hostmachine:~/scripts# cat troca_senha.sh
#!/bin/sh
# script p/ troca de senha
# Author : Mario Cezzare - mcezzare@gmail.com
# modelo do arquivo user;senha
FILEIMPORT="userstrocasenha.txt"
for x in `cat $FILEIMPORT`;
do
usuario=$(echo $x | cut -d ";" -f 1)
senha=$(echo $x | cut -d ";" -f 2)
#usuario=$1
#senha=$2
#echo $usuario
echo "trocando a senha do usuario:$usuario"
#echo $senha
#( /usr/bin/passwd $usuario $senha)
echo -e "$senha\n$senha" | (passwd $usuario)
done
Antes de rodar o script , se quiser criar usuarios p/ testar o script :
(exemplo num Debian Linux hostmachine 2.6.26-2-686 #1 SMP Wed Nov 4 20:45:37 UTC 2009 i686 GNU/Linux )
hostmachine:~/scripts# adduser usertest1
Adding user `usertest1' ...
Adding new group `usertest1' (1007) ...
Adding new user `usertest1' (1007) with group `usertest1' ...
Creating home directory `/home/usertest1' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:x
Retype new UNIX password:x
passwd: password updated successfully
Changing the user information for usertest1
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
hostmachine:~/scripts# adduser usertest2
Adding user `usertest2' ...
Adding new group `usertest2' (1013) ...
Adding new user `usertest2' (1013) with group `usertest2' ...
Creating home directory `/home/usertest2' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:y
Retype new UNIX password:y
passwd: password updated successfully
Changing the user information for usertest2
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
hostmachine:~/scripts#
Vamos testar o acesso via pop3 p/ mostrar :
hostmachine:~/scripts# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Hello there.
user usertest1
+OK Password required.
pass x
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
.
quit
+OK Bye-bye.
Connection closed by foreign host.
hostmachine:~/scripts#
ok vamos rodar o script troca_senha.sh e ver se funciona :
hostmachine:~/scripts# sh troca_senha.sh
trocando a senha do usuario:usertest1
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
trocando a senha do usuario:usertest2
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Agora vamos testar com a nova senha :
hostmachine:~/scripts# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Hello there.
user usertest1
+OK Password required.
pass xxx
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
.
quit
+OK Bye-bye.
Connection closed by foreign host.
OBS: Não se esqueça de remover esses 2 usuários após os testes:
hostmachine:~/scripts# userdel -r usertest1
hostmachine:~/scripts# userdel -r usertest2
Essa é uma maneira rápida e simples de trocar as senhas quando o método de Autenticação é o PAM , e os logins e senhas ficam nos arquivos /etc/passwd e /etc/shadow , usando o programa /usr/bin/passwd (no caso dessa versão do Debian e na maioria do sistemas UNIX-LIKE)
Samba e Squid ficam p/ o próximo post
[]'s
Você tem vários usuarios e vários serviços diferentes em maquinas diferentes.
Serviços de Email, Proxy, Samba mas ainda nao usa uma base centralizada como LDAP.
Bem, segue uma dica com scripts p/ automatização dessa tarefa (já pensou trocar a senha manualmente de 400 usuários ?:( , ninguém merece neh ?)
Neste caso tenho uma tabela Mysql , onde tenho os logins e senhas. A partir dela gero um arquivo csv (userstrocasenha.txt) e um script em shell p/ fazer a tarefa (troca_senha.sh) como descrito abaixo :
o texto q estiver dessa maneira é o q foi digitado :
hostmachine:~/scripts# cat userstrocasenha.txt
usertest1;xxx
usertest2;yyy
Exemplo de Autenticação com PAM
hostmachine:~/scripts# cat troca_senha.sh
#!/bin/sh
# script p/ troca de senha
# Author : Mario Cezzare - mcezzare@gmail.com
# modelo do arquivo user;senha
FILEIMPORT="userstrocasenha.txt"
for x in `cat $FILEIMPORT`;
do
usuario=$(echo $x | cut -d ";" -f 1)
senha=$(echo $x | cut -d ";" -f 2)
#usuario=$1
#senha=$2
#echo $usuario
echo "trocando a senha do usuario:$usuario"
#echo $senha
#( /usr/bin/passwd $usuario $senha)
echo -e "$senha\n$senha" | (passwd $usuario)
done
Antes de rodar o script , se quiser criar usuarios p/ testar o script :
(exemplo num Debian Linux hostmachine 2.6.26-2-686 #1 SMP Wed Nov 4 20:45:37 UTC 2009 i686 GNU/Linux )
hostmachine:~/scripts# adduser usertest1
Adding user `usertest1' ...
Adding new group `usertest1' (1007) ...
Adding new user `usertest1' (1007) with group `usertest1' ...
Creating home directory `/home/usertest1' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:x
Retype new UNIX password:x
passwd: password updated successfully
Changing the user information for usertest1
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
hostmachine:~/scripts# adduser usertest2
Adding user `usertest2' ...
Adding new group `usertest2' (1013) ...
Adding new user `usertest2' (1013) with group `usertest2' ...
Creating home directory `/home/usertest2' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:y
Retype new UNIX password:y
passwd: password updated successfully
Changing the user information for usertest2
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
hostmachine:~/scripts#
Vamos testar o acesso via pop3 p/ mostrar :
hostmachine:~/scripts# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Hello there.
user usertest1
+OK Password required.
pass x
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
.
quit
+OK Bye-bye.
Connection closed by foreign host.
hostmachine:~/scripts#
ok vamos rodar o script troca_senha.sh e ver se funciona :
hostmachine:~/scripts# sh troca_senha.sh
trocando a senha do usuario:usertest1
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
trocando a senha do usuario:usertest2
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Agora vamos testar com a nova senha :
hostmachine:~/scripts# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Hello there.
user usertest1
+OK Password required.
pass xxx
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
.
quit
+OK Bye-bye.
Connection closed by foreign host.
OBS: Não se esqueça de remover esses 2 usuários após os testes:
hostmachine:~/scripts# userdel -r usertest1
hostmachine:~/scripts# userdel -r usertest2
Essa é uma maneira rápida e simples de trocar as senhas quando o método de Autenticação é o PAM , e os logins e senhas ficam nos arquivos /etc/passwd e /etc/shadow , usando o programa /usr/bin/passwd (no caso dessa versão do Debian e na maioria do sistemas UNIX-LIKE)
Samba e Squid ficam p/ o próximo post
[]'s
Marcadores:
Linux,
Shell Script,
SysAdmin,
Unix
Assinar:
Postagens (Atom)
