2018-10-08 - Re: Vending machine

Header Data

From: José Borges <jo***s@algardata.pt>
Message Hash: e93dbf45453104237c1e21506ca0fbb988bb71f36becf9c9474763cfd939bc29
Message ID: <c584d3eb-9bf1-4009-98a1-80f294c12fe1@grasehotspot.org>
Reply To: <746100c2-4e88-40ba-9ea7-acb381cf452e@grasehotspot.org>
UTC Datetime: 2018-10-08 06:24:36 UTC
Raw Date: Mon, 08 Oct 2018 06:24:36 -0700

Raw message

For instance... someone on this group wrote a PERL program to delete 
vouchers from database... i think you could easily do the same thing BUT to 
ADD vouchers to database...

#!/usr/bin/perl  
use POSIX;


# This script is based on one of Tim's obsolete scrips, now removed from 
Grase
# Works only with mysql and postgresql
# Deletes all users in a group withou archiving them


$conf='/etc/grase/radius.conf';


open CONF, "<$conf"
 or die "Could not open configuration file\n";
while(<CONF>){
 chomp;
 ($key,$val)=(split /:\s*/,$_);
 $sql_type = $val if ($key eq 'sql_type');
 $sql_server = $val if ($key eq 'sql_server');
 $sql_username = $val if ($key eq 'sql_username');
 $sql_password = $val if ($key eq 'sql_password');
 $sql_database = $val if ($key eq 'sql_database');
 $sqlcmd = $val if ($key eq 'sql_command');
}
close CONF;


die "sql_command directive is not set in radius.conf\n" if ($sqlcmd eq '');
die "Could not find sql binary. Please make sure that the \$sqlcmd variable 
points to the right location\n" if (! -x $sqlcmd);


$sql_password = ($sql_password eq '') ? '' : "-p$sql_password";


($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
#if ($mday == 1){
$mon = $mon --;
#}
$date_start = 
POSIX::strftime("%Y-%m-%d",0,0,0,1,$mon,$year,$wday,$yday,$isdst);
$date_end  = 
POSIX::strftime("%Y-%m-%d",0,0,0,1,$mon+1,$year,$wday,$yday,$isdst);


#quit unless we have the correct number of command-line args
$num_args = $#ARGV + 1;
if ($num_args != 1) {
    print "\nUsage: delete_all_users_in_a_group.pl GroupName\n";
    exit;
}
#we got one command line arg, so assume it is the GroupName
$GroupName=$ARGV[0];




$query1 = "DELETE radcheck.* FROM radcheck INNER JOIN radusergroup ON 
radcheck.UserName = radusergroup.UserName WHERE radusergroup.GroupName = 
'$GroupName';";


$query2 = "DELETE radacct.* FROM radacct INNER JOIN radusergroup ON 
radacct.UserName = radusergroup.UserName WHERE radusergroup.GroupName = 
'$GroupName';";


$query3 = "DELETE radusergroup.* FROM radusergroup WHERE Groupname = 
'$GroupName';";


open TMP, ">/tmp/delete_group.query"
 or die "Could not open tmp file\n";
print TMP $query1;
print TMP $query2;
print TMP $query3;
close TMP;


$command = "$sqlcmd -v -v -h $sql_server -u $sql_username $sql_password 
$sql_database </tmp/delete_group.query" if ($sql_type eq 'mysql');
$command = "$sqlcmd  -U $sql_username -f /tmp/delete_group.query 
$sql_database" if ($sql_type eq 'pg');


print `$command`;








On Tuesday, 25 September 2018 11:32:20 UTC+1, br***.@gmail.com wrote:
>
> Hello. Installed grasehotspot on my reaspberry pi 2 and its been working 
> very well for the last 3 years. Is it hard to implement/program and vending 
> machine for raspberry pi with grasehotspot? I want to attach a termal 
> printer and a coin acceptor with the raspberry pi so when a customer insert 
> certain amount of money on the coin acceptor the termal/reciept printer 
> prints a username and password jus like wen creating a code on the web 
> server. Thanks. I already made a vending machine for project using arduino 
> so i have a little experience on it


Thread