--[[ telegram¿ë ¼­¹ö ¸ð´ÏÅ͸µ ½ºÅ©¸³Æ® - telegramÀ¸·Î ¸í·É(ping, load, netlog, mrtg, 404)À» ¹ÞÀ¸¸é, °á°ú°ªÀ» ¸Þ½ÅÀú·Î º¸³»ÁÜ 2014.9.30 2014.10.13(Mon) ¸í·É¾î ¹®ÀÚ¿­ ÇÊÅ͸µ, ÀÎÁõµÈ Æù¸¸ ¸í·ÉÀ» ¹Þµµ·Ï. secret chat Áö¿ø -- by truefeel(ÁÁÀºÁøÈ£, http://coffeenix.net/) ]] now = os.time() dir_cmd = "/home/cnx/cmd" cmd_ping = "cd ".. dir_cmd .."; sh ping.sh" cmd_load = "cd ".. dir_cmd .."; sh load.sh" cmd_netlog = "cd ".. dir_cmd .."; sh show_netlog.sh" cmd_mrtg = "cd ".. dir_cmd .."; perl mrtg.pl" cmd_404 = "cd ".. dir_cmd .."; perl 404.pl" mrtg_res = {"load", "swap", "public_if", "private_if", "disk_io", "memory_free", "memory_inactive"} auth_phone = {["821012345678"] = true, ["821087654321"] = true } -- ¸Þ½ÃÁö ¼ö½Å ó¸® function on_msg_receive (msg) if msg.date < now then return end if msg.out then return end -- command local recv_msg = "" if ( msg.text ~= nil ) then recv_msg = string.gsub(msg.text,"[;|<>]","") -- ¹ÞÀº msgÁß¿¡ ;, |, <, > µîÀÇ ¹®ÀÚ´Â Áö¿ò end local cmd, arg = split(recv_msg) -- exam : ping a b c d => cmd = "ping", arg = "a b c d" local file_name = "" cmd = string.lower(cmd) print("receive : ", cmd, "\n") -- user_info print("Name : ", msg.from.print_name) -- ¸Þ½ÃÁö º¸³½»ç¶÷ real name (Jinho) print("Phone : ", msg.from.phone) -- ¸Þ½ÃÁö º¸³½»ç¶÷ ÀüÈ­¹øÈ£ (8210AAAABBBB) print("Msg Num : ", msg.id) -- ¸Þ½ÃÁö ¹øÈ£ print("to.Name : ", msg.to.print_name) -- ÀϹݴëÈ­, ºñ¹Ð´ëÈ­ ±¸ºÐÇؼ­ ¸Þ½ÃÁö Àü¼Û if (msg.to.id == our_id) then user_id = msg.from.print_name -- ÀϹݴëȭâ else user_id = msg.to.print_name -- ºñ¹Ð´ëȭâ end -- auth (ÁöÁ¤ÇÑ Æù¹øÈ£¸¸ ÀÎÁõ) if auth_phone[msg.from.phone] then print "auth : OK " else print "auth : invalid user" return end mark_read(user_id, ok_cb, false) -- ÀÐÀº ¸Þ½ÃÁö·Î Ç¥½Ã -- ping if ( cmd == 'ping' ) then os.execute(cmd_ping .. arg) send_text(user_id, dir_cmd ..'/result_ping.txt', ok_cb, false) return end -- load if ( cmd == 'load' ) then .. »ý·« .. end -- netlog if ( cmd == 'netlog' ) then .. »ý·« .. end -- MRTG if ( cmd == 'mrtg' ) then os.execute(cmd_mrtg .. arg) arg = trim(arg) for i=1, table.maxn(mrtg_res) do file_name = dir_cmd .."/".. arg .."_".. mrtg_res[i] .."-day.png" -- DIR/FILE -- print (file_name) if ( file_exists(file_name) ) then send_photo(user_id, file_name, ok_cb, false) end end return end -- web 403/404 status if ( cmd == '404' ) then .. »ý·« .. end -- help -- if ( cmd ~= '' ) then if ( cmd == 'help' ) then send_text(user_id, dir_cmd ..'/help.txt', ok_cb, false) end end function on_secret_chat_created (peer) end function on_secret_chat_update (schat, what) end function on_user_update (user) end function on_chat_update (user) end function on_our_id(id) our_id = id print("My user# : ", id) end function on_get_difference_end () end function on_binlog_replay_end () end function ok_cb(extra, success, result) end -- function split(str) local arg_1st="" local arg_2nd="" local arg_cnt=1 for s in string.gmatch(str, "[^%s]+") do if ( arg_cnt == 1 ) then arg_1st = s else arg_2nd = arg_2nd .." ".. s end arg_cnt = arg_cnt + 1 end return arg_1st, arg_2nd end function trim(str) return ( str:gsub("^%s*(.-)%s*$", "%1") ) end function file_exists(name) if type(name)~="string" then return false end return os.rename(name,name) and true or false end