@@ -793,24 +793,30 @@ function fetch_sub_info(sub_url, sub_ua)
793793 local info , upload , download , total , day_expire , http_code
794794 local used , expire , day_left , percent , surplus
795795
796- info = luci .sys .exec (string.format (" curl -sLI -X GET -m 10 -w 'http_code='%%{http_code} -H 'User-Agent: %s' '%s'" , sub_ua , sub_url ))
797- if not info or tonumber (string.sub (string.match (info , " http_code=%d+" ), 11 , - 1 )) ~= 200 then
798- info = luci .sys .exec (string.format (" curl -sLI -X GET -m 10 -w 'http_code='%%{http_code} -H 'User-Agent: Quantumultx' '%s'" , sub_url ))
796+ info = luci .sys .exec (string.format (" curl -sLI -X GET -m 10 -w 'http_code=%%{http_code}' -H 'User-Agent: %s' '%s'" , sub_ua , sub_url ))
797+ local http_match = string.match (info , " http_code=(%d+)" )
798+ if not info or not http_match or tonumber (http_match ) ~= 200 then
799+ info = luci .sys .exec (string.format (" curl -sLI -X GET -m 10 -w 'http_code=%%{http_code}' -H 'User-Agent: Quantumultx' '%s'" , sub_url ))
800+ http_match = string.match (info , " http_code=(%d+)" )
799801 end
800802
801- if info then
802- http_code = string.sub ( string.match ( info , " http_code=%d+ " ), 11 , - 1 )
803+ if info and http_match then
804+ http_code = http_match
803805 if tonumber (http_code ) == 200 then
804806 info = string.lower (info )
805807 if string.find (info , " subscription%-userinfo" ) then
806808 info = luci .sys .exec (" echo '%s' |grep 'subscription-userinfo'" % info )
807- upload = string.sub (string.match (info , " upload=%d+" ), 8 , - 1 ) or nil
808- download = string.sub (string.match (info , " download=%d+" ), 10 , - 1 ) or nil
809- total = tonumber (string.format (" %.1f" ,string.sub (string.match (info , " total=%d+" ), 7 , - 1 ))) or nil
810- used = tonumber (string.format (" %.1f" ,(upload + download ))) or nil
811- if string.match (info , " expire=%d+" ) then
812- day_expire = tonumber (string.sub (string.match (info , " expire=%d+" ), 8 , - 1 )) or nil
813- end
809+ local upload_match = string.match (info , " upload=(%d+)" )
810+ local download_match = string.match (info , " download=(%d+)" )
811+ local total_match = string.match (info , " total=(%d+)" )
812+ local expire_match = string.match (info , " expire=(%d+)" )
813+
814+ upload = upload_match and tonumber (upload_match ) or nil
815+ download = download_match and tonumber (download_match ) or nil
816+ total = total_match and tonumber (string.format (" %.1f" , total_match )) or nil
817+ used = upload and download and tonumber (string.format (" %.1f" , upload + download )) or nil
818+ day_expire = expire_match and tonumber (expire_match ) or nil
819+ end
814820
815821 -- Calculate expire and day_left
816822 if day_expire and day_expire == 0 then
@@ -953,44 +959,43 @@ function get_sub_url(filename)
953959 -- Trim whitespace
954960 line = line:match('^%s*(.-)%s*$') or ''
955961
956- if line == '' then goto continue end
957-
962+ -- Skip empty lines
963+ if line == '' then
964+ -- continue to next line
958965 -- Check for proxy-providers section
959- if not in_providers then
966+ elseif not in_providers then
960967 if line:match('^proxy%-providers:%s*$') then
961968 in_providers = true
962969 end
963- goto continue
964- end
965-
966- -- Exit proxy-providers section
967- if line:match('^[^%s]:') and not line:match('^proxy%-providers:') then
968- break
969- end
970+ -- continue to next line
971+ else
972+ -- Exit proxy-providers section
973+ if line:match('^[^%s]:') and not line:match('^proxy%-providers:') then
974+ break
975+ end
970976
971- -- Parse provider entries
972- local key, value = line:match('^(%s+)([^:]+):%s*(.*)$')
973- if key and value then
974- local current_indent = #key
975- if current_indent == 2 and value ~= '' then
976- -- New provider
977- current_provider = {name = value:match('^%s*(.-)%s*$'), url = nil}
978- table.insert(providers, current_provider)
979- elseif current_provider and current_indent == 4 and value ~= '' then
980- -- Provider property
981- local prop_key = key:match('^%s+(.-)%s*$')
982- if prop_key == 'url' and current_provider then
983- current_provider.url = value:match('^%s*["\']?(.-)["\']?%s*$')
984- elseif prop_key == 'type' and current_provider and current_provider.url then
985- -- Only include if it's an http provider
986- if value ~= 'http' then
987- current_provider.url = nil
977+ -- Parse provider entries
978+ local key, value = line:match('^(%s+)([^:]+):%s*(.*)$')
979+ if key and value then
980+ local current_indent = #key
981+ if current_indent == 2 and value ~= '' then
982+ -- New provider
983+ current_provider = {name = value:match('^%s*(.-)%s*$'), url = nil}
984+ table.insert(providers, current_provider)
985+ elseif current_provider and current_indent == 4 and value ~= '' then
986+ -- Provider property
987+ local prop_key = key:match('^%s+(.-)%s*$')
988+ if prop_key == 'url' and current_provider then
989+ current_provider.url = value:match('^%s*["\']?(.-)["\']?%s*$')
990+ elseif prop_key == 'type' and current_provider and current_provider.url then
991+ -- Only include if it's an http provider
992+ if value ~= 'http' then
993+ current_provider.url = nil
994+ end
988995 end
989996 end
990997 end
991998 end
992-
993- ::continue::
994999 end
9951000
9961001 -- Generate JSON-like output
0 commit comments