Guest User

Untitled

a guest
Aug 18th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. require 'cgi'
  3. cgi = CGI.new
  4.  
  5. puts "Content-Type: text/xml"
  6. puts
  7.  
  8. FILENAME='/home/amnesia/sip.conf'
  9. option = cgi.params['option'].to_s
  10. id = cgi.params['id'].to_s
  11. type = cgi.params['type'].to_s
  12. username = cgi.params['username'].to_s
  13. password = cgi.params['password'].to_s
  14.  
  15. def add_phone(type,id,username,password)
  16. if type.eql?('1')
  17. settings = {
  18. 'type' => 'friend',
  19. 'host' => 'dynamic',
  20. 'username' => username,
  21. 'secret' => password,
  22. 'context' => 'allemaal',
  23. 'nat' => 'yes',
  24. 'qualify' => 'yes',
  25. }
  26. File.open(FILENAME, 'a+') do |f|
  27. f.puts
  28. f.puts "[#{id}]"
  29. settings.each { |k, v| f.puts "#{k}=#{v}" }
  30. end
  31. end
  32. end
  33.  
  34. def check(option, *value)
  35. if option.eql?('add_phone')
  36. if value[0] or value[1]
  37. File.open(FILENAME, 'a+') do |f|
  38. f.each {|line| line.chomp!; @exists = 1 if line =~ /\[#{value[0]}\]/ or line =~ /username=#{value[1]}/}
  39. end
  40. if @exists.eql?(1)
  41. puts "<?xml version="1.0"?>"
  42. puts '<result>'
  43. puts '<status>Error, already exists</status>'
  44. puts '</result>'
  45. exit
  46. end
  47. end
  48. end
  49. end
  50.  
  51. case
  52. when option.eql?('add_phone')
  53. if type.empty? or id.empty? or username.empty? or password.empty?
  54. # puts "Invalid input, try again"
  55. exit
  56. end
  57. check(option, id, username)
  58. add_phone(type, id, username, password)
  59. end
Add Comment
Please, Sign In to add comment