Skip to content

Instantly share code, notes, and snippets.

@shouya
Created October 21, 2012 14:00
Show Gist options
  • Save shouya/3927046 to your computer and use it in GitHub Desktop.
Save shouya/3927046 to your computer and use it in GitHub Desktop.
BGY utils
#!/bin/sh
IP_ADDR=10.69.56.48
HW_ADDR=aa:bb:cc:dd:ee:ee
IFACE=eth0
if [ "$USER" != "root" ]; then
echo Fucker, Run it as root\!\!\!
exit
fi
ifconfig $IFACE down
echo $?
ifconfig $IFACE $IP_ADDR/16 hw ether $HW_ADDR up
echo $?
ip route add default via 10.69.1.1 dev $IFACE
echo $?
echo Done. Remember to masquerade your user-agent.
require 'tiny_tds'
require 'date'
DB_NAME = 'bgycanteen'
DB_PASSWD = DB_NAME + '7023'
DB_LOGINID = DB_NAME
BARNO = ARGV[0]
def get_conn
TinyTds::Client.new(:username => DB_LOGINID,
:password => DB_PASSWD,
:host => '10.166.2.2',
:tds_version => '70',
:database => DB_NAME)
end
client = get_conn
today = Date.today
require 'ap'
result = client.execute(<<"FUCK" % BARNO).do
delete
from f_sfmx
where
barno = '%s'
and
convert(char(10), f_date, 110) = convert(char(10), getdate(), 110)
FUCK
require 'tiny_tds'
require 'optparse'
require 'irb'
DB_NAME = 'bgybasic'
DB_PASSWD = DB_NAME + '7023'
DB_LOGINID = DB_NAME
options = {}
OptionParser.new do |o|
o.banner = "Usage #$0 [options]"
o.on '-b', '--barno=BARNO', String, 'Specify barno.' do |s|
options[:barno] = s
end
o.on '-p', '--photo=FILE', 'The new photo to be updated.' do |s|
options[:photo] = File.read(s)
end
o.on '-h', '--help', 'Display this help and exit.' do
puts o
exit
end
end.parse!
if options[:barno].nil? or options[:barno].length != 7 or
options[:photo].nil? or options[:photo].length < 100
abort 'Argument error.'
end
conn = TinyTds::Client.new(:username => DB_LOGINID,
:password => DB_PASSWD,
:host => '10.166.2.2',
:tds_version => '70',
:database => DB_NAME)
conn.execute(<<"sql_stmt").each do |x|
SELECT st_pic FROM stupic WHERE st_barno = '#{options[:barno]}'
sql_stmt
File.write("#{options[:barno]}.jpg", x['st_pic'])
end
result = conn.execute(<<-"sql_stmt").do
UPDATE stupic
SET st_pic = 0x#{options[:photo].unpack('H*')[0]}
WHERE st_barno = '#{options[:barno]}'
sql_stmt
if result == 1
puts 'Done.'
else
puts 'Failed.'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment