Changeset 5403
- Timestamp:
- 06/17/11 18:55:27 (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/oscam-http.c
r5390 r5403 3104 3104 } 3105 3105 3106 static char *send_oscam_graph(struct templatevars *vars, struct uriparams *params) { 3107 return tpl_getTpl(vars, "GRAPH"); 3108 } 3106 3109 static int8_t check_request(char *result, int32_t read){ 3107 3110 if(read < 50) return 0; … … 3304 3307 "/oscamapi.html", 3305 3308 "/image", 3306 "/favicon.ico"}; 3309 "/favicon.ico", 3310 "/graph.svg"}; 3307 3311 3308 3312 int32_t pagescnt = sizeof(pages)/sizeof(char *); // Calculate the amount of items in array … … 3484 3488 case 19: result = send_oscam_image(vars, f, ¶ms, NULL, modifiedheader, etagheader); break; 3485 3489 case 20: result = send_oscam_image(vars, f, ¶ms, "ICMAI", modifiedheader, etagheader); break; 3490 case 21: result = send_oscam_graph(vars, ¶ms); break; 3486 3491 default: result = send_oscam_status(vars, ¶ms, 0); break; 3487 3492 } … … 3491 3496 else if (strcmp(result, "1")) { 3492 3497 //it doesn't make sense to check for modified etagheader here as standard template has timestamp in output and so site changes on every request 3493 if (pgidx == 18 )3498 if (pgidx == 18 || pgidx == 21) 3494 3499 send_headers(f, 200, "OK", NULL, "text/xml", 0, strlen(result), NULL, 0); 3495 3500 else -
trunk/oscam-http.h
r5388 r5403 829 829 ##TPLMENU##\ 830 830 <BR><BR>\n\ 831 <TABLE CLASS=\"configmenu\"><TR><TD CLASS=\"configmenu\"><A HREF=\"scanusb.html\">Scan USB</A></TD>< /TR></TABLE><BR>\831 <TABLE CLASS=\"configmenu\"><TR><TD CLASS=\"configmenu\"><A HREF=\"scanusb.html\">Scan USB</A></TD><TD CLASS=\"configmenu\"><A HREF=\"graph.svg\">Show Graphs</A></TD></TR></TABLE><BR>\ 832 832 <form action=\"readerconfig.html\" method=\"get\">\n\ 833 833 <TABLE CLASS=\"readers\">\n\ … … 1761 1761 <br><br><b>OSCam execute script: ##SCRIPTNAME## --> Status: ##SCRIPTRESULT## --> Returncode: ##CODE##</b><br>\n\ 1762 1762 ##TPLFOOTER##" 1763 1764 #define TPLGRAPH "\ 1765 <?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n\ 1766 <svg xml:space='preserve' xmlns='http://www.w3.org/2000/svg'\n\ 1767 xmlns:xlink='http://www.w3.org/1999/xlink'\n\ 1768 width='100%' height='100%'\n\ 1769 viewBox='0 0 600 300'\n\ 1770 preserveAspectRatio='none'\n\ 1771 onload='init(evt)'\n\ 1772 >\n\ 1773 <g id='graph'> \n\ 1774 <rect id='bg' x1='0' y1='0' width='600' height='300' fill='white' /> \n\ 1775 <text id='error' x='300' y='125' text-anchor='middle' visibility='hidden' fill='red'>Error occured!</text> \n\ 1776 <path id='grid' d='M 2 75 L 600 75 M 2 150 L 600 150 M 2 225 L 600 225' stroke='gray' stroke-opacity='0.5' /> \n\ 1777 <text id='grid_txt3' x='600' y='223' fill='gray' text-anchor='end'>--</text> \n\ 1778 <text id='grid_txt2' x='600' y='148' fill='gray' text-anchor='end'>--</text> \n\ 1779 <text id='grid_txt1' x='600' y='73' fill='gray' text-anchor='end'>--</text> \n\ 1780 </g>\n\ 1781 <script type='text/ecmascript'>\n\ 1782 <![CDATA[\n\ 1783 if (typeof getURL == 'undefined') {\n\ 1784 getURL = function(url, callback) {\n\ 1785 try {\n\ 1786 if (typeof callback.operationComplete == 'function') {\n\ 1787 callback = callback.operationComplete;\n\ 1788 }\n\ 1789 } catch (e) {}\n\ 1790 if (typeof callback != 'function') {\n\ 1791 throw 'No callback function for getURL';\n\ 1792 }\n\ 1793 var http_request = null;\n\ 1794 if (typeof XMLHttpRequest != 'undefined') {\n\ 1795 http_request = new XMLHttpRequest();\n\ 1796 } else if (typeof ActiveXObject != 'undefined') {\n\ 1797 try {\n\ 1798 http_request = new ActiveXObject('Msxml2.XMLHTTP');\n\ 1799 } catch (e) {\n\ 1800 try {\n\ 1801 http_request = new ActiveXObject('Microsoft.XMLHTTP');\n\ 1802 } catch (e) {}\n\ 1803 }\n\ 1804 }\n\ 1805 if (!http_request) {\n\ 1806 throw 'Both getURL and XMLHttpRequest are undefined';\n\ 1807 }\n\ 1808 http_request.onreadystatechange = function() {\n\ 1809 if (http_request.readyState == 4) {\n\ 1810 callback( \n\ 1811 {\n\ 1812 success : true,\n\ 1813 content : http_request.responseXML,\n\ 1814 contentType : http_request.getResponseHeader('Content-Type')\n\ 1815 }\n\ 1816 );\n\ 1817 }\n\ 1818 }\n\ 1819 http_request.open('GET', url, true);\n\ 1820 http_request.send(null);\n\ 1821 }\n\ 1822 }\n\ 1823 var SVGDoc = null;\n\ 1824 var svgNS = 'http://www.w3.org/2000/svg';\n\ 1825 var max = 0;\n\ 1826 var plots = new Array();\n\ 1827 var Color = new Array();\n\ 1828 Color[0]='blue';\n\ 1829 Color[1]='green';\n\ 1830 Color[2]='Orange';\n\ 1831 Color[3]='brown';\n\ 1832 Color[4]='Fuchsia';\n\ 1833 Color[5]='Red';\n\ 1834 Color[6]='yellow';\n\ 1835 var max_num_points = 120;\n\ 1836 var step = 600 / max_num_points ;\n\ 1837 var fetch_url='';\n\ 1838 function init(evt) {\n\ 1839 fetch_url=location.search.split('?');\n\ 1840 fetch_url='oscamapi.html?part=status&' + fetch_url[fetch_url.length-1];\n\ 1841 SVGDoc = evt.target.ownerDocument;\n\ 1842 fetch_data();\n\ 1843 setInterval('fetch_data()', 1000);\n\ 1844 }\n\ 1845 function fetch_data() {\n\ 1846 if (fetch_url) {\n\ 1847 getURL(fetch_url, plot_data);\n\ 1848 } else {\n\ 1849 handle_error();\n\ 1850 }\n\ 1851 }\n\ 1852 function plot_data(obj) {\n\ 1853 if (!obj.success) return handle_error();\n\ 1854 if (!obj.content) return handle_error();\n\ 1855 var readers = obj.content.getElementsByTagName('oscam')[0].getElementsByTagName('status')[0].getElementsByTagName('client');\n\ 1856 i=0;\n\ 1857 max=0;\n\ 1858 rdx=0;\n\ 1859 while (rdx < readers.length) {\n\ 1860 var type = readers[rdx].getAttribute('type');\n\ 1861 if ( type=='r' || type=='p' ) {\n\ 1862 if ( plots[i] == null ) {\n\ 1863 plots[i] = new Array();\n\ 1864 plots[i]['data'] = new Array();\n\ 1865 }\n\ 1866 plots[i]['name'] = readers[rdx].getAttribute('name');\n\ 1867 if ( plots[i]['name'].length == 0 ) {\n\ 1868 plots[i]['name'] = readers[rdx].getElementsByTagName('connection')[0].getAttribute('ip');\n\ 1869 }\n\ 1870 plots[i]['ecmtime'] = parseInt( readers[rdx].getElementsByTagName('request')[0].getAttribute('ecmtime') );\n\ 1871 if (!isNumber(plots[i]['ecmtime'])) plots[i]['ecmtime'] = 0;\n\ 1872 plots[i]['idle'] = readers[rdx].getElementsByTagName('times')[0].getAttribute('idle');\n\ 1873 if ( plots[i]['data'].length==max_num_points ) {\n\ 1874 var ii = 0;\n\ 1875 while (ii < max_num_points) {\n\ 1876 plots[i]['data'][ii] = plots[i]['data'][ii+1];\n\ 1877 ii++;\n\ 1878 }\n\ 1879 plots[i]['data'].length--;\n\ 1880 }\n\ 1881 plots[i]['data'][plots[i]['data'].length] = plots[i]['ecmtime'];\n\ 1882 if ( SVGDoc.getElementById('graph_txt_'+i) == null ) {\n\ 1883 var newText = document.createElementNS(svgNS,'text');\n\ 1884 newText.setAttributeNS(null,'x',10);\n\ 1885 newText.setAttributeNS(null,'y',15+(15*i));\n\ 1886 newText.setAttributeNS(null,'fill',Color[i]);\n\ 1887 newText.setAttributeNS(null,'id','graph_txt_'+i);\n\ 1888 var textNode = document.createTextNode(plots[i]['name']);\n\ 1889 newText.appendChild(textNode);\n\ 1890 document.getElementById('graph').appendChild(newText);\n\ 1891 }\n\ 1892 SVGDoc.getElementById('graph_txt_'+i).firstChild.data = plots[i]['name'] + ':' + plots[i]['ecmtime'] + 'ms';\n\ 1893 if ( SVGDoc.getElementById('graph_path_'+i) == null ) {\n\ 1894 var newPath = document.createElementNS(svgNS,'path');\n\ 1895 newPath.setAttributeNS(null,'id','graph_path_'+i);\n\ 1896 newPath.setAttributeNS(null,'fill','none');\n\ 1897 newPath.setAttributeNS(null,'stroke',Color[i]);\n\ 1898 newPath.setAttributeNS(null,'stroke-width','1');\n\ 1899 newPath.setAttributeNS(null,'stroke-opacity','0.8');\n\ 1900 document.getElementById('graph').appendChild(newPath);\n\ 1901 }\n\ 1902 a=0;\n\ 1903 var plot = plots[i]['data'];\n\ 1904 while (a < plot.length) {\n\ 1905 if (plot[a] > max) max = plot[a];\n\ 1906 a++;\n\ 1907 }\n\ 1908 i++;\n\ 1909 }\n\ 1910 rdx++;\n\ 1911 }\n\ 1912 var rmax=makeRoundMax(max);\n\ 1913 var scale = 298 / rmax;\n\ 1914 i=0;\n\ 1915 while (i < plots.length) {\n\ 1916 var plot = plots[i]['data'];\n\ 1917 var path = 'M 0 ' + (298 - (plot[0] * scale));\n\ 1918 for (b = 1; b < plot.length; b++) {\n\ 1919 var x = step * b;\n\ 1920 var y_in = 298 - (plot[b] * scale);\n\ 1921 path += ' L' + x + ' ' + y_in;\n\ 1922 }\n\ 1923 SVGDoc.getElementById('graph_path_'+i).setAttributeNS(null, 'd', path);\n\ 1924 i++;\n\ 1925 }\n\ 1926 SVGDoc.getElementById('grid_txt1').firstChild.data = 3*rmax/4 + 'ms'\n\ 1927 SVGDoc.getElementById('grid_txt2').firstChild.data = 2*rmax/4 + 'ms';\n\ 1928 SVGDoc.getElementById('grid_txt3').firstChild.data = rmax/4 + 'ms';\n\ 1929 SVGDoc.getElementById('error').setAttributeNS(null, 'visibility', 'hidden');\n\ 1930 }\n\ 1931 function makeRoundMax(max) {\n\ 1932 rmax = 1000;\n\ 1933 i = 0;\n\ 1934 while (max > rmax) {\n\ 1935 i++;\n\ 1936 if (i && (i % 4 == 0)) {\n\ 1937 rmax *= 1.25;\n\ 1938 } else {\n\ 1939 rmax *= 2;\n\ 1940 }\n\ 1941 if (i == 8) rmax *= 1.000;\n\ 1942 }\n\ 1943 return rmax;\n\ 1944 }\n\ 1945 function handle_error() {\n\ 1946 SVGDoc.getElementById('error').setAttributeNS(null, 'visibility', 'visible');\n\ 1947 }\n\ 1948 function isNumber(a) {\n\ 1949 return typeof a == 'number' && isFinite(a);\n\ 1950 }\n\ 1951 ]]>\ 1952 </script>\ 1953 </svg>" 1763 1954 1764 1955 enum refreshtypes {REFR_ACCOUNTS, REFR_READERS, REFR_SERVER, REFR_ANTICASC, REFR_SERVICES}; … … 1836 2027 "PRESHUTDOWN", 1837 2028 "SHUTDOWN", 1838 "SCRIPT" 2029 "SCRIPT", 2030 "GRAPH" 1839 2031 #ifdef HAVE_DVBAPI 1840 2032 ,"CONFIGDVBAPI" … … 1977 2169 TPLPRESHUTDOWN, 1978 2170 TPLSHUTDOWN, 1979 TPLSCRIPT 2171 TPLSCRIPT, 2172 TPLGRAPH 1980 2173 #ifdef HAVE_DVBAPI 1981 2174 ,TPLCONFIGDVBAPI
Note:
See TracChangeset
for help on using the changeset viewer.