refreshed and renamed docs, added bootstrap server, added default config for sec auditing
This commit is contained in:
		
							parent
							
								
									fe36b87c57
								
							
						
					
					
						commit
						6960d9209d
					
				
					 270 changed files with 20816 additions and 8345 deletions
				
			
		
							
								
								
									
										190
									
								
								docs/html/src/httpapi/apiutils/getblockdata.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										190
									
								
								docs/html/src/httpapi/apiutils/getblockdata.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,190 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.apiutils.getblockdata API documentation</title> | ||||
| <meta name="description" content="" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.apiutils.getblockdata</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">import json | ||||
| from onionrblocks import onionrblockapi | ||||
| from onionrutils import bytesconverter, stringvalidators | ||||
| import onionrexceptions | ||||
| class GetBlockData: | ||||
|     def __init__(self, client_api_inst=None): | ||||
|         return | ||||
|      | ||||
|     def get_block_data(self, bHash, decrypt=False, raw=False, headerOnly=False): | ||||
|         if not stringvalidators.validate_hash(bHash): raise onionrexceptions.InvalidHexHash("block hash not valid hash format") | ||||
|         bl = onionrblockapi.Block(bHash) | ||||
|         if decrypt: | ||||
|             bl.decrypt() | ||||
|             if bl.isEncrypted and not bl.decrypted: | ||||
|                 raise ValueError | ||||
| 
 | ||||
|         if not raw: | ||||
|             if not headerOnly: | ||||
|                 retData = {'meta':bl.bheader, 'metadata': bl.bmetadata, 'content': bl.bcontent} | ||||
|                 for x in list(retData.keys()): | ||||
|                     try: | ||||
|                         retData[x] = retData[x].decode() | ||||
|                     except AttributeError: | ||||
|                         pass | ||||
|             else: | ||||
|                 validSig = False | ||||
|                 signer = bytesconverter.bytes_to_str(bl.signer) | ||||
|                 if bl.isSigned() and stringvalidators.validate_pub_key(signer) and bl.isSigner(signer): | ||||
|                     validSig = True                     | ||||
|                 bl.bheader['validSig'] = validSig | ||||
|                 bl.bheader['meta'] = '' | ||||
|                 retData = {'meta': bl.bheader, 'metadata': bl.bmetadata} | ||||
|             return json.dumps(retData) | ||||
|         else: | ||||
|             return bl.raw</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-classes">Classes</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.apiutils.getblockdata.GetBlockData"><code class="flex name class"> | ||||
| <span>class <span class="ident">GetBlockData</span></span> | ||||
| <span>(</span><span>client_api_inst=None)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">class GetBlockData: | ||||
|     def __init__(self, client_api_inst=None): | ||||
|         return | ||||
|      | ||||
|     def get_block_data(self, bHash, decrypt=False, raw=False, headerOnly=False): | ||||
|         if not stringvalidators.validate_hash(bHash): raise onionrexceptions.InvalidHexHash("block hash not valid hash format") | ||||
|         bl = onionrblockapi.Block(bHash) | ||||
|         if decrypt: | ||||
|             bl.decrypt() | ||||
|             if bl.isEncrypted and not bl.decrypted: | ||||
|                 raise ValueError | ||||
| 
 | ||||
|         if not raw: | ||||
|             if not headerOnly: | ||||
|                 retData = {'meta':bl.bheader, 'metadata': bl.bmetadata, 'content': bl.bcontent} | ||||
|                 for x in list(retData.keys()): | ||||
|                     try: | ||||
|                         retData[x] = retData[x].decode() | ||||
|                     except AttributeError: | ||||
|                         pass | ||||
|             else: | ||||
|                 validSig = False | ||||
|                 signer = bytesconverter.bytes_to_str(bl.signer) | ||||
|                 if bl.isSigned() and stringvalidators.validate_pub_key(signer) and bl.isSigner(signer): | ||||
|                     validSig = True                     | ||||
|                 bl.bheader['validSig'] = validSig | ||||
|                 bl.bheader['meta'] = '' | ||||
|                 retData = {'meta': bl.bheader, 'metadata': bl.bmetadata} | ||||
|             return json.dumps(retData) | ||||
|         else: | ||||
|             return bl.raw</code></pre> | ||||
| </details> | ||||
| <h3>Methods</h3> | ||||
| <dl> | ||||
| <dt id="src.httpapi.apiutils.getblockdata.GetBlockData.get_block_data"><code class="name flex"> | ||||
| <span>def <span class="ident">get_block_data</span></span>(<span>self, bHash, decrypt=False, raw=False, headerOnly=False)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def get_block_data(self, bHash, decrypt=False, raw=False, headerOnly=False): | ||||
|     if not stringvalidators.validate_hash(bHash): raise onionrexceptions.InvalidHexHash("block hash not valid hash format") | ||||
|     bl = onionrblockapi.Block(bHash) | ||||
|     if decrypt: | ||||
|         bl.decrypt() | ||||
|         if bl.isEncrypted and not bl.decrypted: | ||||
|             raise ValueError | ||||
| 
 | ||||
|     if not raw: | ||||
|         if not headerOnly: | ||||
|             retData = {'meta':bl.bheader, 'metadata': bl.bmetadata, 'content': bl.bcontent} | ||||
|             for x in list(retData.keys()): | ||||
|                 try: | ||||
|                     retData[x] = retData[x].decode() | ||||
|                 except AttributeError: | ||||
|                     pass | ||||
|         else: | ||||
|             validSig = False | ||||
|             signer = bytesconverter.bytes_to_str(bl.signer) | ||||
|             if bl.isSigned() and stringvalidators.validate_pub_key(signer) and bl.isSigner(signer): | ||||
|                 validSig = True                     | ||||
|             bl.bheader['validSig'] = validSig | ||||
|             bl.bheader['meta'] = '' | ||||
|             retData = {'meta': bl.bheader, 'metadata': bl.bmetadata} | ||||
|         return json.dumps(retData) | ||||
|     else: | ||||
|         return bl.raw</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.apiutils" href="index.html">src.httpapi.apiutils</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-classes">Classes</a></h3> | ||||
| <ul> | ||||
| <li> | ||||
| <h4><code><a title="src.httpapi.apiutils.getblockdata.GetBlockData" href="#src.httpapi.apiutils.getblockdata.GetBlockData">GetBlockData</a></code></h4> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.apiutils.getblockdata.GetBlockData.get_block_data" href="#src.httpapi.apiutils.getblockdata.GetBlockData.get_block_data">get_block_data</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										83
									
								
								docs/html/src/httpapi/apiutils/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								docs/html/src/httpapi/apiutils/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,83 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.apiutils API documentation</title> | ||||
| <meta name="description" content="" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.apiutils</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">from . import shutdown, setbindip, getblockdata | ||||
| 
 | ||||
| GetBlockData = getblockdata.GetBlockData</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-submodules">Sub-modules</h2> | ||||
| <dl> | ||||
| <dt><code class="name"><a title="src.httpapi.apiutils.getblockdata" href="getblockdata.html">src.httpapi.apiutils.getblockdata</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.apiutils.setbindip" href="setbindip.html">src.httpapi.apiutils.setbindip</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.apiutils.shutdown" href="shutdown.html">src.httpapi.apiutils.shutdown</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="../index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-submodules">Sub-modules</a></h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.apiutils.getblockdata" href="getblockdata.html">src.httpapi.apiutils.getblockdata</a></code></li> | ||||
| <li><code><a title="src.httpapi.apiutils.setbindip" href="setbindip.html">src.httpapi.apiutils.setbindip</a></code></li> | ||||
| <li><code><a title="src.httpapi.apiutils.shutdown" href="shutdown.html">src.httpapi.apiutils.shutdown</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										145
									
								
								docs/html/src/httpapi/apiutils/setbindip.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										145
									
								
								docs/html/src/httpapi/apiutils/setbindip.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,145 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.apiutils.setbindip API documentation</title> | ||||
| <meta name="description" content="" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.apiutils.setbindip</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">import gevent | ||||
| from gevent import socket, sleep | ||||
| import secrets, random | ||||
| import config, logger | ||||
| import os | ||||
| 
 | ||||
| # Hacky monkey patch so we can bind random localhosts without gevent trying to switch with an empty hub | ||||
| socket.getfqdn = lambda n: n | ||||
| 
 | ||||
| def _get_acceptable_random_number()->int: | ||||
|     """Return a cryptographically random number in the inclusive range (1, 255)""" | ||||
|     number = 0 | ||||
|     while number == 0: | ||||
|         number = secrets.randbelow(0xFF) | ||||
|     return number | ||||
| 
 | ||||
| def set_bind_IP(filePath=''): | ||||
|     '''Set a random localhost IP to a specified file (intended for private or public API localhost IPs)''' | ||||
|     if config.get('general.random_bind_ip', True): | ||||
|         hostOctets = [] | ||||
|         # Build the random localhost address | ||||
|         for i in range(3): | ||||
|             hostOctets.append(str(_get_acceptable_random_number())) | ||||
|         hostOctets = ['127'] + hostOctets | ||||
|         # Convert the localhost address to a normal string address | ||||
|         data = '.'.join(hostOctets) | ||||
|          | ||||
|         # Try to bind IP. Some platforms like Mac block non normal 127.x.x.x | ||||
|         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||||
|         try: | ||||
|             s.bind((data, 0)) | ||||
|         except OSError: | ||||
|             # if mac/non-bindable, show warning and default to 127.0.0.1 | ||||
|             logger.warn('Your platform appears to not support random local host addresses 127.x.x.x. Falling back to 127.0.0.1.') | ||||
|             data = '127.0.0.1' | ||||
|         s.close() | ||||
|     else: | ||||
|         data = '127.0.0.1' | ||||
|     if filePath != '': | ||||
|         with open(filePath, 'w') as bindFile: | ||||
|             bindFile.write(data) | ||||
|     return data</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.apiutils.setbindip.set_bind_IP"><code class="name flex"> | ||||
| <span>def <span class="ident">set_bind_IP</span></span>(<span>filePath='')</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Set a random localhost IP to a specified file (intended for private or public API localhost IPs)</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def set_bind_IP(filePath=''): | ||||
|     '''Set a random localhost IP to a specified file (intended for private or public API localhost IPs)''' | ||||
|     if config.get('general.random_bind_ip', True): | ||||
|         hostOctets = [] | ||||
|         # Build the random localhost address | ||||
|         for i in range(3): | ||||
|             hostOctets.append(str(_get_acceptable_random_number())) | ||||
|         hostOctets = ['127'] + hostOctets | ||||
|         # Convert the localhost address to a normal string address | ||||
|         data = '.'.join(hostOctets) | ||||
|          | ||||
|         # Try to bind IP. Some platforms like Mac block non normal 127.x.x.x | ||||
|         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||||
|         try: | ||||
|             s.bind((data, 0)) | ||||
|         except OSError: | ||||
|             # if mac/non-bindable, show warning and default to 127.0.0.1 | ||||
|             logger.warn('Your platform appears to not support random local host addresses 127.x.x.x. Falling back to 127.0.0.1.') | ||||
|             data = '127.0.0.1' | ||||
|         s.close() | ||||
|     else: | ||||
|         data = '127.0.0.1' | ||||
|     if filePath != '': | ||||
|         with open(filePath, 'w') as bindFile: | ||||
|             bindFile.write(data) | ||||
|     return data</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.apiutils" href="index.html">src.httpapi.apiutils</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.apiutils.setbindip.set_bind_IP" href="#src.httpapi.apiutils.setbindip.set_bind_IP">set_bind_IP</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										143
									
								
								docs/html/src/httpapi/apiutils/shutdown.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								docs/html/src/httpapi/apiutils/shutdown.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,143 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.apiutils.shutdown API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.apiutils.shutdown</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>Shutdown the node either hard or cleanly</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">""" | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     Shutdown the node either hard or cleanly | ||||
| """ | ||||
| from flask import Blueprint, Response | ||||
| from flask import g | ||||
| from onionrblocks import onionrblockapi | ||||
| import onionrexceptions | ||||
| from onionrutils import stringvalidators | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| 
 | ||||
| shutdown_bp = Blueprint('shutdown', __name__) | ||||
| 
 | ||||
| def shutdown(client_api_inst): | ||||
|     try: | ||||
|         client_api_inst.publicAPI.httpServer.stop() | ||||
|         client_api_inst.httpServer.stop() | ||||
|     except AttributeError: | ||||
|         pass | ||||
|     return Response("bye") | ||||
| 
 | ||||
| @shutdown_bp.route('/shutdownclean') | ||||
| def shutdown_clean(): | ||||
|     # good for calling from other clients | ||||
|     g.too_many.get_by_string("OnionrCommunicatorDaemon").shutdown = True | ||||
|     return Response("bye")</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.apiutils.shutdown.shutdown"><code class="name flex"> | ||||
| <span>def <span class="ident">shutdown</span></span>(<span>client_api_inst)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def shutdown(client_api_inst): | ||||
|     try: | ||||
|         client_api_inst.publicAPI.httpServer.stop() | ||||
|         client_api_inst.httpServer.stop() | ||||
|     except AttributeError: | ||||
|         pass | ||||
|     return Response("bye")</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.apiutils.shutdown.shutdown_clean"><code class="name flex"> | ||||
| <span>def <span class="ident">shutdown_clean</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@shutdown_bp.route('/shutdownclean') | ||||
| def shutdown_clean(): | ||||
|     # good for calling from other clients | ||||
|     g.too_many.get_by_string("OnionrCommunicatorDaemon").shutdown = True | ||||
|     return Response("bye")</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.apiutils" href="index.html">src.httpapi.apiutils</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.apiutils.shutdown.shutdown" href="#src.httpapi.apiutils.shutdown.shutdown">shutdown</a></code></li> | ||||
| <li><code><a title="src.httpapi.apiutils.shutdown.shutdown_clean" href="#src.httpapi.apiutils.shutdown.shutdown_clean">shutdown_clean</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										210
									
								
								docs/html/src/httpapi/configapi/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										210
									
								
								docs/html/src/httpapi/configapi/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,210 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.configapi API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.configapi</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>This file handles configuration setting and getting from the HTTP API</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">""" | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     This file handles configuration setting and getting from the HTTP API | ||||
| """ | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| import json | ||||
| from flask import Blueprint, request, Response, abort | ||||
| import config, onionrutils | ||||
| config.reload() | ||||
| 
 | ||||
| config_BP = Blueprint('config_BP', __name__) | ||||
| 
 | ||||
| @config_BP.route('/config/get') | ||||
| def get_all_config(): | ||||
|     """Simply return all configuration as JSON string""" | ||||
|     return Response(json.dumps(config.get_config(), indent=4, sort_keys=True)) | ||||
| 
 | ||||
| @config_BP.route('/config/get/<key>') | ||||
| def get_by_key(key): | ||||
|     """Return a config setting by key""" | ||||
|     return Response(json.dumps(config.get(key))) | ||||
| 
 | ||||
| @config_BP.route('/config/setall', methods=['POST']) | ||||
| def set_all_config(): | ||||
|     """Overwrite existing JSON config with new JSON string""" | ||||
|     try: | ||||
|         new_config = request.get_json(force=True) | ||||
|     except json.JSONDecodeError: | ||||
|         abort(400) | ||||
|     else: | ||||
|         config.set_config(new_config) | ||||
|         config.save() | ||||
|         return Response('success') | ||||
| 
 | ||||
| @config_BP.route('/config/set/<key>', methods=['POST']) | ||||
| def set_by_key(key): | ||||
|     """Overwrite/set only 1 config key""" | ||||
|     """ | ||||
|     { | ||||
|         'data': data | ||||
|     } | ||||
|     """ | ||||
|     try: | ||||
|         data = json.loads(onionrutils.OnionrUtils.bytesToStr(request.data))['data'] | ||||
|     except (json.JSONDecodeError, KeyError): | ||||
|         abort(400) | ||||
|     config.set(key, data, True) | ||||
|     return Response('success')</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.configapi.get_all_config"><code class="name flex"> | ||||
| <span>def <span class="ident">get_all_config</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Simply return all configuration as JSON string</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@config_BP.route('/config/get') | ||||
| def get_all_config(): | ||||
|     """Simply return all configuration as JSON string""" | ||||
|     return Response(json.dumps(config.get_config(), indent=4, sort_keys=True))</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.configapi.get_by_key"><code class="name flex"> | ||||
| <span>def <span class="ident">get_by_key</span></span>(<span>key)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Return a config setting by key</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@config_BP.route('/config/get/<key>') | ||||
| def get_by_key(key): | ||||
|     """Return a config setting by key""" | ||||
|     return Response(json.dumps(config.get(key)))</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.configapi.set_all_config"><code class="name flex"> | ||||
| <span>def <span class="ident">set_all_config</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Overwrite existing JSON config with new JSON string</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@config_BP.route('/config/setall', methods=['POST']) | ||||
| def set_all_config(): | ||||
|     """Overwrite existing JSON config with new JSON string""" | ||||
|     try: | ||||
|         new_config = request.get_json(force=True) | ||||
|     except json.JSONDecodeError: | ||||
|         abort(400) | ||||
|     else: | ||||
|         config.set_config(new_config) | ||||
|         config.save() | ||||
|         return Response('success')</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.configapi.set_by_key"><code class="name flex"> | ||||
| <span>def <span class="ident">set_by_key</span></span>(<span>key)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Overwrite/set only 1 config key</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@config_BP.route('/config/set/<key>', methods=['POST']) | ||||
| def set_by_key(key): | ||||
|     """Overwrite/set only 1 config key""" | ||||
|     """ | ||||
|     { | ||||
|         'data': data | ||||
|     } | ||||
|     """ | ||||
|     try: | ||||
|         data = json.loads(onionrutils.OnionrUtils.bytesToStr(request.data))['data'] | ||||
|     except (json.JSONDecodeError, KeyError): | ||||
|         abort(400) | ||||
|     config.set(key, data, True) | ||||
|     return Response('success')</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="../index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.configapi.get_all_config" href="#src.httpapi.configapi.get_all_config">get_all_config</a></code></li> | ||||
| <li><code><a title="src.httpapi.configapi.get_by_key" href="#src.httpapi.configapi.get_by_key">get_by_key</a></code></li> | ||||
| <li><code><a title="src.httpapi.configapi.set_all_config" href="#src.httpapi.configapi.set_all_config">set_all_config</a></code></li> | ||||
| <li><code><a title="src.httpapi.configapi.set_by_key" href="#src.httpapi.configapi.set_by_key">set_by_key</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										188
									
								
								docs/html/src/httpapi/daemoneventsapi/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										188
									
								
								docs/html/src/httpapi/daemoneventsapi/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,188 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.daemoneventsapi API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.daemoneventsapi</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication.</p> | ||||
| <p>Event driven interface to trigger events in communicator</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">"""Onionr - Private P2P Communication. | ||||
| 
 | ||||
| Event driven interface to trigger events in communicator | ||||
| """ | ||||
| from typing import Callable | ||||
| 
 | ||||
| from flask import Blueprint, request, Response, abort | ||||
| from werkzeug.exceptions import BadRequest | ||||
| from gevent import spawn | ||||
| 
 | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| 
 | ||||
| 
 | ||||
| class DaemonEventsBP: | ||||
|     def __init__(self): | ||||
|         """Create DaemonEvents instance, intended to be a singleton. | ||||
| 
 | ||||
|         Attributes: | ||||
|         listeners: callables that are called when a new event is added. | ||||
|             The callables name should match the event name | ||||
|         _too_many: TooManyObjects instance set by external code | ||||
|         """ | ||||
|         event_BP = Blueprint('event_BP', __name__) | ||||
|         self.listeners = set([]) | ||||
|         self.flask_bp = event_BP | ||||
|         event_BP = self.flask_bp | ||||
| 
 | ||||
|         @event_BP.route('/daemon-event/<name>', methods=['POST']) | ||||
|         def daemon_event_handler(name): | ||||
|             handler: Callable | ||||
| 
 | ||||
|             try: | ||||
|                 json_data = request.get_json(force=True) | ||||
|             except BadRequest: | ||||
|                 json_data = {} | ||||
|             for handler in self.listeners: | ||||
|                 if handler.__name__ == name: | ||||
|                     return Response(handler(**json_data)) | ||||
|             abort(404) | ||||
| 
 | ||||
|     def register_listener(self, listener: Callable): | ||||
|         self.listeners.add(listener)</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-classes">Classes</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.daemoneventsapi.DaemonEventsBP"><code class="flex name class"> | ||||
| <span>class <span class="ident">DaemonEventsBP</span></span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Create DaemonEvents instance, intended to be a singleton.</p> | ||||
| <p>Attributes: | ||||
| listeners: callables that are called when a new event is added. | ||||
| The callables name should match the event name | ||||
| _too_many: TooManyObjects instance set by external code</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">class DaemonEventsBP: | ||||
|     def __init__(self): | ||||
|         """Create DaemonEvents instance, intended to be a singleton. | ||||
| 
 | ||||
|         Attributes: | ||||
|         listeners: callables that are called when a new event is added. | ||||
|             The callables name should match the event name | ||||
|         _too_many: TooManyObjects instance set by external code | ||||
|         """ | ||||
|         event_BP = Blueprint('event_BP', __name__) | ||||
|         self.listeners = set([]) | ||||
|         self.flask_bp = event_BP | ||||
|         event_BP = self.flask_bp | ||||
| 
 | ||||
|         @event_BP.route('/daemon-event/<name>', methods=['POST']) | ||||
|         def daemon_event_handler(name): | ||||
|             handler: Callable | ||||
| 
 | ||||
|             try: | ||||
|                 json_data = request.get_json(force=True) | ||||
|             except BadRequest: | ||||
|                 json_data = {} | ||||
|             for handler in self.listeners: | ||||
|                 if handler.__name__ == name: | ||||
|                     return Response(handler(**json_data)) | ||||
|             abort(404) | ||||
| 
 | ||||
|     def register_listener(self, listener: Callable): | ||||
|         self.listeners.add(listener)</code></pre> | ||||
| </details> | ||||
| <h3>Methods</h3> | ||||
| <dl> | ||||
| <dt id="src.httpapi.daemoneventsapi.DaemonEventsBP.register_listener"><code class="name flex"> | ||||
| <span>def <span class="ident">register_listener</span></span>(<span>self, listener)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def register_listener(self, listener: Callable): | ||||
|     self.listeners.add(listener)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="../index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-classes">Classes</a></h3> | ||||
| <ul> | ||||
| <li> | ||||
| <h4><code><a title="src.httpapi.daemoneventsapi.DaemonEventsBP" href="#src.httpapi.daemoneventsapi.DaemonEventsBP">DaemonEventsBP</a></code></h4> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.daemoneventsapi.DaemonEventsBP.register_listener" href="#src.httpapi.daemoneventsapi.DaemonEventsBP.register_listener">register_listener</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										183
									
								
								docs/html/src/httpapi/directconnections/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										183
									
								
								docs/html/src/httpapi/directconnections/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,183 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.directconnections API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.directconnections</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>Misc client API endpoints too small to need their own file and that need access to the client api inst</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">''' | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     Misc client API endpoints too small to need their own file and that need access to the client api inst | ||||
| ''' | ||||
| ''' | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| import threading # For the client creation thread | ||||
| 
 | ||||
| from flask import Response # For direct connection management HTTP endpoints | ||||
| from flask import Blueprint # To make the direct connection management blueprint in the webUI | ||||
| from flask import g # Mainly to access the shared toomanyobjs object | ||||
| import deadsimplekv | ||||
| 
 | ||||
| import filepaths | ||||
| import onionrservices | ||||
| from onionrservices import pool | ||||
| 
 | ||||
| def _get_communicator(g): | ||||
|     while True: | ||||
|         try: | ||||
|             return g.too_many.get_by_string("OnionrCommunicatorDaemon") | ||||
|         except KeyError: | ||||
|             pass | ||||
| 
 | ||||
| class DirectConnectionManagement: | ||||
|     def __init__(self, client_api): | ||||
|         direct_conn_management_bp = Blueprint('direct_conn_management', __name__) | ||||
|         self.direct_conn_management_bp = direct_conn_management_bp | ||||
| 
 | ||||
|         cache = deadsimplekv.DeadSimpleKV(filepaths.cached_storage) | ||||
| 
 | ||||
|         @direct_conn_management_bp.route('/dc-client/isconnected/<pubkey>') | ||||
|         def is_connected(pubkey): | ||||
|             communicator = _get_communicator(g) | ||||
|             resp = "" | ||||
|             if pubkey in communicator.direct_connection_clients: | ||||
|                 resp = communicator.direct_connection_clients[pubkey] | ||||
|             return Response(resp) | ||||
|          | ||||
|         @direct_conn_management_bp.route('/dc-client/connect/<pubkey>') | ||||
|         def make_new_connection(pubkey): | ||||
|             communicator = _get_communicator(g) | ||||
|             resp = "pending" | ||||
|             if pubkey in communicator.shared_state.get(pool.ServicePool).bootstrap_pending: | ||||
|                 return Response(resp) | ||||
|                  | ||||
|             if pubkey in communicator.direct_connection_clients: | ||||
|                 resp = communicator.direct_connection_clients[pubkey] | ||||
|             else: | ||||
|                 """Spawn a thread that will create the client and eventually add it to the | ||||
|                 communicator.active_services  | ||||
|                 """ | ||||
|                 threading.Thread(target=onionrservices.OnionrServices().create_client,  | ||||
|                                  args=[pubkey, communicator], daemon=True).start() | ||||
| 
 | ||||
|             return Response(resp)</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-classes">Classes</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.directconnections.DirectConnectionManagement"><code class="flex name class"> | ||||
| <span>class <span class="ident">DirectConnectionManagement</span></span> | ||||
| <span>(</span><span>client_api)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">class DirectConnectionManagement: | ||||
|     def __init__(self, client_api): | ||||
|         direct_conn_management_bp = Blueprint('direct_conn_management', __name__) | ||||
|         self.direct_conn_management_bp = direct_conn_management_bp | ||||
| 
 | ||||
|         cache = deadsimplekv.DeadSimpleKV(filepaths.cached_storage) | ||||
| 
 | ||||
|         @direct_conn_management_bp.route('/dc-client/isconnected/<pubkey>') | ||||
|         def is_connected(pubkey): | ||||
|             communicator = _get_communicator(g) | ||||
|             resp = "" | ||||
|             if pubkey in communicator.direct_connection_clients: | ||||
|                 resp = communicator.direct_connection_clients[pubkey] | ||||
|             return Response(resp) | ||||
|          | ||||
|         @direct_conn_management_bp.route('/dc-client/connect/<pubkey>') | ||||
|         def make_new_connection(pubkey): | ||||
|             communicator = _get_communicator(g) | ||||
|             resp = "pending" | ||||
|             if pubkey in communicator.shared_state.get(pool.ServicePool).bootstrap_pending: | ||||
|                 return Response(resp) | ||||
|                  | ||||
|             if pubkey in communicator.direct_connection_clients: | ||||
|                 resp = communicator.direct_connection_clients[pubkey] | ||||
|             else: | ||||
|                 """Spawn a thread that will create the client and eventually add it to the | ||||
|                 communicator.active_services  | ||||
|                 """ | ||||
|                 threading.Thread(target=onionrservices.OnionrServices().create_client,  | ||||
|                                  args=[pubkey, communicator], daemon=True).start() | ||||
| 
 | ||||
|             return Response(resp)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="../index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-classes">Classes</a></h3> | ||||
| <ul> | ||||
| <li> | ||||
| <h4><code><a title="src.httpapi.directconnections.DirectConnectionManagement" href="#src.httpapi.directconnections.DirectConnectionManagement">DirectConnectionManagement</a></code></h4> | ||||
| </li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										141
									
								
								docs/html/src/httpapi/fdsafehandler.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								docs/html/src/httpapi/fdsafehandler.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,141 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.fdsafehandler API documentation</title> | ||||
| <meta name="description" content="" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.fdsafehandler</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">from gevent.pywsgi import WSGIServer, WSGIHandler | ||||
| from gevent import Timeout | ||||
| class FDSafeHandler(WSGIHandler): | ||||
|     '''Our WSGI handler. Doesn't do much non-default except timeouts''' | ||||
|     def handle(self): | ||||
|         self.timeout = Timeout(120, Exception) | ||||
|         self.timeout.start() | ||||
|         try: | ||||
|             WSGIHandler.handle(self) | ||||
|         except Timeout as ex: | ||||
|             if ex is self.timeout: | ||||
|                 pass | ||||
|             else:  | ||||
|                 raise</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-classes">Classes</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.fdsafehandler.FDSafeHandler"><code class="flex name class"> | ||||
| <span>class <span class="ident">FDSafeHandler</span></span> | ||||
| <span>(</span><span>sock, address, server, rfile=None)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Our WSGI handler. Doesn't do much non-default except timeouts</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">class FDSafeHandler(WSGIHandler): | ||||
|     '''Our WSGI handler. Doesn't do much non-default except timeouts''' | ||||
|     def handle(self): | ||||
|         self.timeout = Timeout(120, Exception) | ||||
|         self.timeout.start() | ||||
|         try: | ||||
|             WSGIHandler.handle(self) | ||||
|         except Timeout as ex: | ||||
|             if ex is self.timeout: | ||||
|                 pass | ||||
|             else:  | ||||
|                 raise</code></pre> | ||||
| </details> | ||||
| <h3>Ancestors</h3> | ||||
| <ul class="hlist"> | ||||
| <li>gevent.pywsgi.WSGIHandler</li> | ||||
| </ul> | ||||
| <h3>Methods</h3> | ||||
| <dl> | ||||
| <dt id="src.httpapi.fdsafehandler.FDSafeHandler.handle"><code class="name flex"> | ||||
| <span>def <span class="ident">handle</span></span>(<span>self)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>The main request handling method, called by the server.</p> | ||||
| <p>This method runs a request handling loop, calling | ||||
| :meth:<code>handle_one_request</code> until all requests on the | ||||
| connection have been handled (that is, it implements | ||||
| keep-alive).</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def handle(self): | ||||
|     self.timeout = Timeout(120, Exception) | ||||
|     self.timeout.start() | ||||
|     try: | ||||
|         WSGIHandler.handle(self) | ||||
|     except Timeout as ex: | ||||
|         if ex is self.timeout: | ||||
|             pass | ||||
|         else:  | ||||
|             raise</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-classes">Classes</a></h3> | ||||
| <ul> | ||||
| <li> | ||||
| <h4><code><a title="src.httpapi.fdsafehandler.FDSafeHandler" href="#src.httpapi.fdsafehandler.FDSafeHandler">FDSafeHandler</a></code></h4> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.fdsafehandler.FDSafeHandler.handle" href="#src.httpapi.fdsafehandler.FDSafeHandler.handle">handle</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										215
									
								
								docs/html/src/httpapi/friendsapi/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										215
									
								
								docs/html/src/httpapi/friendsapi/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,215 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.friendsapi API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.friendsapi</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>This file creates http endpoints for friend management</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">''' | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     This file creates http endpoints for friend management | ||||
| ''' | ||||
| ''' | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| import json | ||||
| from onionrusers import contactmanager | ||||
| from flask import Blueprint, Response, request, abort, redirect | ||||
| from coredb import keydb | ||||
| 
 | ||||
| friends = Blueprint('friends', __name__) | ||||
| 
 | ||||
| @friends.route('/friends/list') | ||||
| def list_friends(): | ||||
|     pubkey_list = {} | ||||
|     friend_list = contactmanager.ContactManager.list_friends() | ||||
|     for friend in friend_list: | ||||
|         pubkey_list[friend.publicKey] = {'name': friend.get_info('name')} | ||||
|     return json.dumps(pubkey_list) | ||||
| 
 | ||||
| @friends.route('/friends/add/<pubkey>', methods=['POST']) | ||||
| def add_friend(pubkey): | ||||
|     contactmanager.ContactManager(pubkey, saveUser=True).setTrust(1) | ||||
|     return redirect(request.referrer + '#' + request.form['token']) | ||||
| 
 | ||||
| @friends.route('/friends/remove/<pubkey>', methods=['POST']) | ||||
| def remove_friend(pubkey): | ||||
|     contactmanager.ContactManager(pubkey).setTrust(0) | ||||
|     contactmanager.ContactManager(pubkey).delete_contact() | ||||
|     keydb.removekeys.remove_user(pubkey) | ||||
|     return redirect(request.referrer + '#' + request.form['token']) | ||||
| 
 | ||||
| @friends.route('/friends/setinfo/<pubkey>/<key>', methods=['POST']) | ||||
| def set_info(pubkey, key): | ||||
|     data = request.form['data'] | ||||
|     contactmanager.ContactManager(pubkey).set_info(key, data) | ||||
|     return redirect(request.referrer + '#' + request.form['token']) | ||||
| 
 | ||||
| @friends.route('/friends/getinfo/<pubkey>/<key>') | ||||
| def get_info(pubkey, key): | ||||
|     retData = contactmanager.ContactManager(pubkey).get_info(key) | ||||
|     if retData is None: | ||||
|         abort(404) | ||||
|     else: | ||||
|         return retData</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.friendsapi.add_friend"><code class="name flex"> | ||||
| <span>def <span class="ident">add_friend</span></span>(<span>pubkey)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@friends.route('/friends/add/<pubkey>', methods=['POST']) | ||||
| def add_friend(pubkey): | ||||
|     contactmanager.ContactManager(pubkey, saveUser=True).setTrust(1) | ||||
|     return redirect(request.referrer + '#' + request.form['token'])</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.friendsapi.get_info"><code class="name flex"> | ||||
| <span>def <span class="ident">get_info</span></span>(<span>pubkey, key)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@friends.route('/friends/getinfo/<pubkey>/<key>') | ||||
| def get_info(pubkey, key): | ||||
|     retData = contactmanager.ContactManager(pubkey).get_info(key) | ||||
|     if retData is None: | ||||
|         abort(404) | ||||
|     else: | ||||
|         return retData</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.friendsapi.list_friends"><code class="name flex"> | ||||
| <span>def <span class="ident">list_friends</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@friends.route('/friends/list') | ||||
| def list_friends(): | ||||
|     pubkey_list = {} | ||||
|     friend_list = contactmanager.ContactManager.list_friends() | ||||
|     for friend in friend_list: | ||||
|         pubkey_list[friend.publicKey] = {'name': friend.get_info('name')} | ||||
|     return json.dumps(pubkey_list)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.friendsapi.remove_friend"><code class="name flex"> | ||||
| <span>def <span class="ident">remove_friend</span></span>(<span>pubkey)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@friends.route('/friends/remove/<pubkey>', methods=['POST']) | ||||
| def remove_friend(pubkey): | ||||
|     contactmanager.ContactManager(pubkey).setTrust(0) | ||||
|     contactmanager.ContactManager(pubkey).delete_contact() | ||||
|     keydb.removekeys.remove_user(pubkey) | ||||
|     return redirect(request.referrer + '#' + request.form['token'])</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.friendsapi.set_info"><code class="name flex"> | ||||
| <span>def <span class="ident">set_info</span></span>(<span>pubkey, key)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@friends.route('/friends/setinfo/<pubkey>/<key>', methods=['POST']) | ||||
| def set_info(pubkey, key): | ||||
|     data = request.form['data'] | ||||
|     contactmanager.ContactManager(pubkey).set_info(key, data) | ||||
|     return redirect(request.referrer + '#' + request.form['token'])</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="../index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.friendsapi.add_friend" href="#src.httpapi.friendsapi.add_friend">add_friend</a></code></li> | ||||
| <li><code><a title="src.httpapi.friendsapi.get_info" href="#src.httpapi.friendsapi.get_info">get_info</a></code></li> | ||||
| <li><code><a title="src.httpapi.friendsapi.list_friends" href="#src.httpapi.friendsapi.list_friends">list_friends</a></code></li> | ||||
| <li><code><a title="src.httpapi.friendsapi.remove_friend" href="#src.httpapi.friendsapi.remove_friend">remove_friend</a></code></li> | ||||
| <li><code><a title="src.httpapi.friendsapi.set_info" href="#src.httpapi.friendsapi.set_info">set_info</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										202
									
								
								docs/html/src/httpapi/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										202
									
								
								docs/html/src/httpapi/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,202 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>This file registers plugin's flask blueprints for the client http server</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">""" | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     This file registers plugin's flask blueprints for the client http server | ||||
| """ | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| import onionrplugins | ||||
| import config | ||||
| 
 | ||||
| def load_plugin_blueprints(flaskapp, blueprint: str = 'flask_blueprint'): | ||||
|     """Iterate enabled plugins and load any http endpoints they have""" | ||||
|     config.reload() | ||||
|     disabled = config.get('plugins.disabled') | ||||
|     for plugin in onionrplugins.get_enabled_plugins(): | ||||
|         if plugin in disabled: | ||||
|             continue | ||||
|         plugin = onionrplugins.get_plugin(plugin) | ||||
|         try: | ||||
|             flaskapp.register_blueprint(getattr(plugin, blueprint)) | ||||
|         except AttributeError: | ||||
|             pass</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-submodules">Sub-modules</h2> | ||||
| <dl> | ||||
| <dt><code class="name"><a title="src.httpapi.apiutils" href="apiutils/index.html">src.httpapi.apiutils</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.configapi" href="configapi/index.html">src.httpapi.configapi</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.daemoneventsapi" href="daemoneventsapi/index.html">src.httpapi.daemoneventsapi</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.directconnections" href="directconnections/index.html">src.httpapi.directconnections</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.fdsafehandler" href="fdsafehandler.html">src.httpapi.fdsafehandler</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.friendsapi" href="friendsapi/index.html">src.httpapi.friendsapi</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.insertblock" href="insertblock.html">src.httpapi.insertblock</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.miscclientapi" href="miscclientapi/index.html">src.httpapi.miscclientapi</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.miscpublicapi" href="miscpublicapi/index.html">src.httpapi.miscpublicapi</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.onionrsitesapi" href="onionrsitesapi/index.html">src.httpapi.onionrsitesapi</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.profilesapi" href="profilesapi/index.html">src.httpapi.profilesapi</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.security" href="security/index.html">src.httpapi.security</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.sse" href="sse/index.html">src.httpapi.sse</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.themeapi" href="themeapi/index.html">src.httpapi.themeapi</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.load_plugin_blueprints"><code class="name flex"> | ||||
| <span>def <span class="ident">load_plugin_blueprints</span></span>(<span>flaskapp, blueprint='flask_blueprint')</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Iterate enabled plugins and load any http endpoints they have</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def load_plugin_blueprints(flaskapp, blueprint: str = 'flask_blueprint'): | ||||
|     """Iterate enabled plugins and load any http endpoints they have""" | ||||
|     config.reload() | ||||
|     disabled = config.get('plugins.disabled') | ||||
|     for plugin in onionrplugins.get_enabled_plugins(): | ||||
|         if plugin in disabled: | ||||
|             continue | ||||
|         plugin = onionrplugins.get_plugin(plugin) | ||||
|         try: | ||||
|             flaskapp.register_blueprint(getattr(plugin, blueprint)) | ||||
|         except AttributeError: | ||||
|             pass</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src" href="../index.html">src</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-submodules">Sub-modules</a></h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.apiutils" href="apiutils/index.html">src.httpapi.apiutils</a></code></li> | ||||
| <li><code><a title="src.httpapi.configapi" href="configapi/index.html">src.httpapi.configapi</a></code></li> | ||||
| <li><code><a title="src.httpapi.daemoneventsapi" href="daemoneventsapi/index.html">src.httpapi.daemoneventsapi</a></code></li> | ||||
| <li><code><a title="src.httpapi.directconnections" href="directconnections/index.html">src.httpapi.directconnections</a></code></li> | ||||
| <li><code><a title="src.httpapi.fdsafehandler" href="fdsafehandler.html">src.httpapi.fdsafehandler</a></code></li> | ||||
| <li><code><a title="src.httpapi.friendsapi" href="friendsapi/index.html">src.httpapi.friendsapi</a></code></li> | ||||
| <li><code><a title="src.httpapi.insertblock" href="insertblock.html">src.httpapi.insertblock</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi" href="miscclientapi/index.html">src.httpapi.miscclientapi</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscpublicapi" href="miscpublicapi/index.html">src.httpapi.miscpublicapi</a></code></li> | ||||
| <li><code><a title="src.httpapi.onionrsitesapi" href="onionrsitesapi/index.html">src.httpapi.onionrsitesapi</a></code></li> | ||||
| <li><code><a title="src.httpapi.profilesapi" href="profilesapi/index.html">src.httpapi.profilesapi</a></code></li> | ||||
| <li><code><a title="src.httpapi.security" href="security/index.html">src.httpapi.security</a></code></li> | ||||
| <li><code><a title="src.httpapi.sse" href="sse/index.html">src.httpapi.sse</a></code></li> | ||||
| <li><code><a title="src.httpapi.themeapi" href="themeapi/index.html">src.httpapi.themeapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.load_plugin_blueprints" href="#src.httpapi.load_plugin_blueprints">load_plugin_blueprints</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										198
									
								
								docs/html/src/httpapi/insertblock.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										198
									
								
								docs/html/src/httpapi/insertblock.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,198 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.insertblock API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.insertblock</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>Create blocks with the client api server</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">''' | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     Create blocks with the client api server | ||||
| ''' | ||||
| ''' | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| import json, threading | ||||
| from flask import Blueprint, Response, request, g | ||||
| import onionrblocks | ||||
| from onionrcrypto import hashers | ||||
| from onionrutils import bytesconverter | ||||
| from onionrutils import mnemonickeys | ||||
| ib = Blueprint('insertblock', __name__) | ||||
| 
 | ||||
| @ib.route('/insertblock', methods=['POST']) | ||||
| def client_api_insert_block(): | ||||
|     encrypt = False | ||||
|     bData = request.get_json(force=True) | ||||
|     message = bData['message'] | ||||
|     message_hash = bytesconverter.bytes_to_str(hashers.sha3_hash(message)) | ||||
| 
 | ||||
|     # Detect if message (block body) is not specified | ||||
|     if type(message) is None: | ||||
|         return 'failure due to unspecified message', 400 | ||||
| 
 | ||||
|     # Detect if block with same message is already being inserted | ||||
|     if message_hash in g.too_many.get_by_string("OnionrCommunicatorDaemon").generating_blocks: | ||||
|         return 'failure due to duplicate insert', 400 | ||||
|     else: | ||||
|         g.too_many.get_by_string("OnionrCommunicatorDaemon").generating_blocks.append(message_hash) | ||||
| 
 | ||||
|     subject = 'temp' | ||||
|     encryptType = '' | ||||
|     sign = True | ||||
|     meta = {} | ||||
|     to = '' | ||||
|     try: | ||||
|         if bData['encrypt']: | ||||
|             to = bData['to'].strip() | ||||
|             if "-" in to: | ||||
|                 to = mnemonickeys.get_base32(to) | ||||
|             encrypt = True | ||||
|             encryptType = 'asym' | ||||
|     except KeyError: | ||||
|         pass | ||||
|     try: | ||||
|         if not bData['sign']: | ||||
|             sign = False | ||||
|     except KeyError: | ||||
|         pass | ||||
|     try: | ||||
|         bType = bData['type'] | ||||
|     except KeyError: | ||||
|         bType = 'bin' | ||||
|     try: | ||||
|         meta = json.loads(bData['meta']) | ||||
|     except KeyError: | ||||
|         pass | ||||
|     threading.Thread(target=onionrblocks.insert, args=(message,), kwargs={'header': bType, 'encryptType': encryptType, 'sign':sign, 'asymPeer': to, 'meta': meta}).start() | ||||
|     return Response('success')</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.insertblock.client_api_insert_block"><code class="name flex"> | ||||
| <span>def <span class="ident">client_api_insert_block</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@ib.route('/insertblock', methods=['POST']) | ||||
| def client_api_insert_block(): | ||||
|     encrypt = False | ||||
|     bData = request.get_json(force=True) | ||||
|     message = bData['message'] | ||||
|     message_hash = bytesconverter.bytes_to_str(hashers.sha3_hash(message)) | ||||
| 
 | ||||
|     # Detect if message (block body) is not specified | ||||
|     if type(message) is None: | ||||
|         return 'failure due to unspecified message', 400 | ||||
| 
 | ||||
|     # Detect if block with same message is already being inserted | ||||
|     if message_hash in g.too_many.get_by_string("OnionrCommunicatorDaemon").generating_blocks: | ||||
|         return 'failure due to duplicate insert', 400 | ||||
|     else: | ||||
|         g.too_many.get_by_string("OnionrCommunicatorDaemon").generating_blocks.append(message_hash) | ||||
| 
 | ||||
|     subject = 'temp' | ||||
|     encryptType = '' | ||||
|     sign = True | ||||
|     meta = {} | ||||
|     to = '' | ||||
|     try: | ||||
|         if bData['encrypt']: | ||||
|             to = bData['to'].strip() | ||||
|             if "-" in to: | ||||
|                 to = mnemonickeys.get_base32(to) | ||||
|             encrypt = True | ||||
|             encryptType = 'asym' | ||||
|     except KeyError: | ||||
|         pass | ||||
|     try: | ||||
|         if not bData['sign']: | ||||
|             sign = False | ||||
|     except KeyError: | ||||
|         pass | ||||
|     try: | ||||
|         bType = bData['type'] | ||||
|     except KeyError: | ||||
|         bType = 'bin' | ||||
|     try: | ||||
|         meta = json.loads(bData['meta']) | ||||
|     except KeyError: | ||||
|         pass | ||||
|     threading.Thread(target=onionrblocks.insert, args=(message,), kwargs={'header': bType, 'encryptType': encryptType, 'sign':sign, 'asymPeer': to, 'meta': meta}).start() | ||||
|     return Response('success')</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.insertblock.client_api_insert_block" href="#src.httpapi.insertblock.client_api_insert_block">client_api_insert_block</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										305
									
								
								docs/html/src/httpapi/miscclientapi/endpoints.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										305
									
								
								docs/html/src/httpapi/miscclientapi/endpoints.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,305 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.miscclientapi.endpoints API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.miscclientapi.endpoints</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication.</p> | ||||
| <p>Misc client API endpoints too small to need their own file and that need access to the client api inst</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">"""Onionr - Private P2P Communication. | ||||
| 
 | ||||
| Misc client API endpoints too small to need their own file and that need access to the client api inst | ||||
| """ | ||||
| import os | ||||
| import subprocess | ||||
| 
 | ||||
| from flask import Response, Blueprint, request, send_from_directory, abort | ||||
| from gevent import spawn | ||||
| from gevent import sleep | ||||
| import unpaddedbase32 | ||||
| 
 | ||||
| from httpapi import apiutils | ||||
| import onionrcrypto | ||||
| import config | ||||
| from netcontroller import NetController | ||||
| from onionrstatistics.serializeddata import SerializedData | ||||
| from onionrutils import mnemonickeys | ||||
| from onionrutils import bytesconverter | ||||
| from etc import onionrvalues | ||||
| from utils import reconstructhash | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| 
 | ||||
| pub_key = onionrcrypto.pub_key.replace('=', '') | ||||
| 
 | ||||
| SCRIPT_NAME = os.path.dirname(os.path.realpath(__file__)) + \ | ||||
|               f'/../../../{onionrvalues.SCRIPT_NAME}' | ||||
| 
 | ||||
| class PrivateEndpoints: | ||||
|     def __init__(self, client_api): | ||||
|         private_endpoints_bp = Blueprint('privateendpoints', __name__) | ||||
|         self.private_endpoints_bp = private_endpoints_bp | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/www/<path:path>', endpoint='www') | ||||
|         def wwwPublic(path): | ||||
|             if not config.get("www.private.run", True): | ||||
|                 abort(403) | ||||
|             return send_from_directory(config.get('www.private.path', 'static-data/www/private/'), path) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/hitcount') | ||||
|         def get_hit_count(): | ||||
|             return Response(str(client_api.publicAPI.hitCount)) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/ping') | ||||
|         def ping(): | ||||
|             # Used to check if client api is working | ||||
|             return Response("pong!") | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/lastconnect') | ||||
|         def lastConnect(): | ||||
|             return Response(str(client_api.publicAPI.lastRequest)) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/waitforshare/<name>', methods=['post']) | ||||
|         def wait_for_share(name): | ||||
|             """Prevent the **public** api from sharing blocks. | ||||
| 
 | ||||
|             Used for blocks we created usually | ||||
|             """ | ||||
|             if not name.isalnum(): | ||||
|                 raise ValueError('block hash needs to be alpha numeric') | ||||
|             name = reconstructhash.reconstruct_hash(name) | ||||
|             if name in client_api.publicAPI.hideBlocks: | ||||
|                 spawn(_delay_wait_for_share_block_removal) | ||||
|                 return Response("will be removed") | ||||
|             else: | ||||
|                 client_api.publicAPI.hideBlocks.append(name) | ||||
|                 return Response("added") | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/shutdown') | ||||
|         def shutdown(): | ||||
|             return apiutils.shutdown.shutdown(client_api) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/restartclean') | ||||
|         def restart_clean(): | ||||
|             subprocess.Popen([SCRIPT_NAME, 'restart']) | ||||
|             return Response("bye") | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/gethidden') | ||||
|         def get_hidden_blocks(): | ||||
|             return Response('\n'.join(client_api.publicAPI.hideBlocks)) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/getstats') | ||||
|         def get_stats(): | ||||
|             """Return serialized node statistics.""" | ||||
|             while True: | ||||
|                 try: | ||||
|                     return Response(client_api._too_many.get( | ||||
|                         SerializedData).get_stats()) | ||||
|                 except AttributeError: | ||||
|                     pass | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/getuptime') | ||||
|         def showUptime(): | ||||
|             return Response(str(client_api.getUptime())) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/getActivePubkey') | ||||
|         def getActivePubkey(): | ||||
|             return Response(pub_key) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/getHumanReadable') | ||||
|         def getHumanReadableDefault(): | ||||
|             return Response(mnemonickeys.get_human_readable_ID()) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/getHumanReadable/<name>') | ||||
|         def getHumanReadable(name): | ||||
|             name = unpaddedbase32.repad(bytesconverter.str_to_bytes(name)) | ||||
|             return Response(mnemonickeys.get_human_readable_ID(name)) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/getBase32FromHumanReadable/<words>') | ||||
|         def get_base32_from_human_readable(words): | ||||
|             return Response(bytesconverter.bytes_to_str(mnemonickeys.get_base32(words))) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/gettorsocks') | ||||
|         def get_tor_socks(): | ||||
|             return Response(str(client_api._too_many.get(NetController).socksPort)) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/setonboarding', methods=['POST']) | ||||
|         def set_onboarding(): | ||||
|             return Response(config.onboarding.set_config_from_onboarding(request.get_json()))</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-classes">Classes</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.miscclientapi.endpoints.PrivateEndpoints"><code class="flex name class"> | ||||
| <span>class <span class="ident">PrivateEndpoints</span></span> | ||||
| <span>(</span><span>client_api)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">class PrivateEndpoints: | ||||
|     def __init__(self, client_api): | ||||
|         private_endpoints_bp = Blueprint('privateendpoints', __name__) | ||||
|         self.private_endpoints_bp = private_endpoints_bp | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/www/<path:path>', endpoint='www') | ||||
|         def wwwPublic(path): | ||||
|             if not config.get("www.private.run", True): | ||||
|                 abort(403) | ||||
|             return send_from_directory(config.get('www.private.path', 'static-data/www/private/'), path) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/hitcount') | ||||
|         def get_hit_count(): | ||||
|             return Response(str(client_api.publicAPI.hitCount)) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/ping') | ||||
|         def ping(): | ||||
|             # Used to check if client api is working | ||||
|             return Response("pong!") | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/lastconnect') | ||||
|         def lastConnect(): | ||||
|             return Response(str(client_api.publicAPI.lastRequest)) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/waitforshare/<name>', methods=['post']) | ||||
|         def wait_for_share(name): | ||||
|             """Prevent the **public** api from sharing blocks. | ||||
| 
 | ||||
|             Used for blocks we created usually | ||||
|             """ | ||||
|             if not name.isalnum(): | ||||
|                 raise ValueError('block hash needs to be alpha numeric') | ||||
|             name = reconstructhash.reconstruct_hash(name) | ||||
|             if name in client_api.publicAPI.hideBlocks: | ||||
|                 spawn(_delay_wait_for_share_block_removal) | ||||
|                 return Response("will be removed") | ||||
|             else: | ||||
|                 client_api.publicAPI.hideBlocks.append(name) | ||||
|                 return Response("added") | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/shutdown') | ||||
|         def shutdown(): | ||||
|             return apiutils.shutdown.shutdown(client_api) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/restartclean') | ||||
|         def restart_clean(): | ||||
|             subprocess.Popen([SCRIPT_NAME, 'restart']) | ||||
|             return Response("bye") | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/gethidden') | ||||
|         def get_hidden_blocks(): | ||||
|             return Response('\n'.join(client_api.publicAPI.hideBlocks)) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/getstats') | ||||
|         def get_stats(): | ||||
|             """Return serialized node statistics.""" | ||||
|             while True: | ||||
|                 try: | ||||
|                     return Response(client_api._too_many.get( | ||||
|                         SerializedData).get_stats()) | ||||
|                 except AttributeError: | ||||
|                     pass | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/getuptime') | ||||
|         def showUptime(): | ||||
|             return Response(str(client_api.getUptime())) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/getActivePubkey') | ||||
|         def getActivePubkey(): | ||||
|             return Response(pub_key) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/getHumanReadable') | ||||
|         def getHumanReadableDefault(): | ||||
|             return Response(mnemonickeys.get_human_readable_ID()) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/getHumanReadable/<name>') | ||||
|         def getHumanReadable(name): | ||||
|             name = unpaddedbase32.repad(bytesconverter.str_to_bytes(name)) | ||||
|             return Response(mnemonickeys.get_human_readable_ID(name)) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/getBase32FromHumanReadable/<words>') | ||||
|         def get_base32_from_human_readable(words): | ||||
|             return Response(bytesconverter.bytes_to_str(mnemonickeys.get_base32(words))) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/gettorsocks') | ||||
|         def get_tor_socks(): | ||||
|             return Response(str(client_api._too_many.get(NetController).socksPort)) | ||||
| 
 | ||||
|         @private_endpoints_bp.route('/setonboarding', methods=['POST']) | ||||
|         def set_onboarding(): | ||||
|             return Response(config.onboarding.set_config_from_onboarding(request.get_json()))</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.miscclientapi" href="index.html">src.httpapi.miscclientapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-classes">Classes</a></h3> | ||||
| <ul> | ||||
| <li> | ||||
| <h4><code><a title="src.httpapi.miscclientapi.endpoints.PrivateEndpoints" href="#src.httpapi.miscclientapi.endpoints.PrivateEndpoints">PrivateEndpoints</a></code></h4> | ||||
| </li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										213
									
								
								docs/html/src/httpapi/miscclientapi/getblocks.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										213
									
								
								docs/html/src/httpapi/miscclientapi/getblocks.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,213 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.miscclientapi.getblocks API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.miscclientapi.getblocks</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>Create blocks with the client api server</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">''' | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     Create blocks with the client api server | ||||
| ''' | ||||
| ''' | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| from flask import Blueprint, Response, abort | ||||
| from onionrblocks import onionrblockapi | ||||
| from .. import apiutils | ||||
| from onionrutils import stringvalidators | ||||
| from coredb import blockmetadb | ||||
| 
 | ||||
| client_get_block = apiutils.GetBlockData() | ||||
| 
 | ||||
| client_get_blocks = Blueprint('miscclient', __name__) | ||||
| 
 | ||||
| @client_get_blocks.route('/getblocksbytype/<name>') | ||||
| def get_blocks_by_type_endpoint(name): | ||||
|     blocks = blockmetadb.get_blocks_by_type(name) | ||||
|     return Response(','.join(blocks)) | ||||
| 
 | ||||
| @client_get_blocks.route('/getblockbody/<name>') | ||||
| def getBlockBodyData(name): | ||||
|     resp = '' | ||||
|     if stringvalidators.validate_hash(name): | ||||
|         try: | ||||
|             resp = onionrblockapi.Block(name, decrypt=True).bcontent | ||||
|         except TypeError: | ||||
|             pass | ||||
|     else: | ||||
|         abort(404) | ||||
|     return Response(resp) | ||||
| 
 | ||||
| @client_get_blocks.route('/getblockdata/<name>') | ||||
| def getData(name): | ||||
|     resp = "" | ||||
|     if stringvalidators.validate_hash(name): | ||||
|         if name in blockmetadb.get_block_list(): | ||||
|             try: | ||||
|                 resp = client_get_block.get_block_data(name, decrypt=True) | ||||
|             except ValueError: | ||||
|                 pass | ||||
|         else: | ||||
|             abort(404) | ||||
|     else: | ||||
|         abort(404) | ||||
|     return Response(resp) | ||||
| 
 | ||||
| @client_get_blocks.route('/getblockheader/<name>') | ||||
| def getBlockHeader(name): | ||||
|     resp = client_get_block.get_block_data(name, decrypt=True, headerOnly=True) | ||||
|     return Response(resp)</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.miscclientapi.getblocks.getBlockBodyData"><code class="name flex"> | ||||
| <span>def <span class="ident">getBlockBodyData</span></span>(<span>name)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@client_get_blocks.route('/getblockbody/<name>') | ||||
| def getBlockBodyData(name): | ||||
|     resp = '' | ||||
|     if stringvalidators.validate_hash(name): | ||||
|         try: | ||||
|             resp = onionrblockapi.Block(name, decrypt=True).bcontent | ||||
|         except TypeError: | ||||
|             pass | ||||
|     else: | ||||
|         abort(404) | ||||
|     return Response(resp)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.getblocks.getBlockHeader"><code class="name flex"> | ||||
| <span>def <span class="ident">getBlockHeader</span></span>(<span>name)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@client_get_blocks.route('/getblockheader/<name>') | ||||
| def getBlockHeader(name): | ||||
|     resp = client_get_block.get_block_data(name, decrypt=True, headerOnly=True) | ||||
|     return Response(resp)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.getblocks.getData"><code class="name flex"> | ||||
| <span>def <span class="ident">getData</span></span>(<span>name)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@client_get_blocks.route('/getblockdata/<name>') | ||||
| def getData(name): | ||||
|     resp = "" | ||||
|     if stringvalidators.validate_hash(name): | ||||
|         if name in blockmetadb.get_block_list(): | ||||
|             try: | ||||
|                 resp = client_get_block.get_block_data(name, decrypt=True) | ||||
|             except ValueError: | ||||
|                 pass | ||||
|         else: | ||||
|             abort(404) | ||||
|     else: | ||||
|         abort(404) | ||||
|     return Response(resp)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.getblocks.get_blocks_by_type_endpoint"><code class="name flex"> | ||||
| <span>def <span class="ident">get_blocks_by_type_endpoint</span></span>(<span>name)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@client_get_blocks.route('/getblocksbytype/<name>') | ||||
| def get_blocks_by_type_endpoint(name): | ||||
|     blocks = blockmetadb.get_blocks_by_type(name) | ||||
|     return Response(','.join(blocks))</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.miscclientapi" href="index.html">src.httpapi.miscclientapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.miscclientapi.getblocks.getBlockBodyData" href="#src.httpapi.miscclientapi.getblocks.getBlockBodyData">getBlockBodyData</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.getblocks.getBlockHeader" href="#src.httpapi.miscclientapi.getblocks.getBlockHeader">getBlockHeader</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.getblocks.getData" href="#src.httpapi.miscclientapi.getblocks.getData">getData</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.getblocks.get_blocks_by_type_endpoint" href="#src.httpapi.miscclientapi.getblocks.get_blocks_by_type_endpoint">get_blocks_by_type_endpoint</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										86
									
								
								docs/html/src/httpapi/miscclientapi/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								docs/html/src/httpapi/miscclientapi/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,86 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.miscclientapi API documentation</title> | ||||
| <meta name="description" content="" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.miscclientapi</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">from . import getblocks, staticfiles, endpoints, motd</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-submodules">Sub-modules</h2> | ||||
| <dl> | ||||
| <dt><code class="name"><a title="src.httpapi.miscclientapi.endpoints" href="endpoints.html">src.httpapi.miscclientapi.endpoints</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.miscclientapi.getblocks" href="getblocks.html">src.httpapi.miscclientapi.getblocks</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.miscclientapi.motd" href="motd/index.html">src.httpapi.miscclientapi.motd</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.miscclientapi.staticfiles" href="staticfiles.html">src.httpapi.miscclientapi.staticfiles</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="../index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-submodules">Sub-modules</a></h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.miscclientapi.endpoints" href="endpoints.html">src.httpapi.miscclientapi.endpoints</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.getblocks" href="getblocks.html">src.httpapi.miscclientapi.getblocks</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.motd" href="motd/index.html">src.httpapi.miscclientapi.motd</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles" href="staticfiles.html">src.httpapi.miscclientapi.staticfiles</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										117
									
								
								docs/html/src/httpapi/miscclientapi/motd/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										117
									
								
								docs/html/src/httpapi/miscclientapi/motd/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,117 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.miscclientapi.motd API documentation</title> | ||||
| <meta name="description" content="" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.miscclientapi.motd</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">from flask import Blueprint | ||||
| from flask import Response | ||||
| import unpaddedbase32 | ||||
| 
 | ||||
| from coredb import blockmetadb | ||||
| import onionrblocks | ||||
| from etc import onionrvalues | ||||
| import config | ||||
| from onionrutils import bytesconverter | ||||
| 
 | ||||
| bp = Blueprint('motd', __name__) | ||||
| 
 | ||||
| signer = config.get("motd.motd_key", onionrvalues.MOTD_SIGN_KEY) | ||||
| 
 | ||||
| @bp.route('/getmotd') | ||||
| def get_motd()->Response: | ||||
|     motds = blockmetadb.get_blocks_by_type("motd") | ||||
|     newest_time = 0 | ||||
|     message = "No MOTD currently present." | ||||
|     for x in motds: | ||||
|         bl = onionrblocks.onionrblockapi.Block(x) | ||||
|         if not bl.verifySig() or bl.signer != bytesconverter.bytes_to_str(unpaddedbase32.repad(bytesconverter.str_to_bytes(signer))): continue | ||||
|         if not bl.isSigner(signer): continue | ||||
|         if bl.claimedTime > newest_time: | ||||
|             newest_time = bl.claimedTime | ||||
|             message = bl.bcontent | ||||
|     return Response(message, headers={"Content-Type": "text/plain"})</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.miscclientapi.motd.get_motd"><code class="name flex"> | ||||
| <span>def <span class="ident">get_motd</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@bp.route('/getmotd') | ||||
| def get_motd()->Response: | ||||
|     motds = blockmetadb.get_blocks_by_type("motd") | ||||
|     newest_time = 0 | ||||
|     message = "No MOTD currently present." | ||||
|     for x in motds: | ||||
|         bl = onionrblocks.onionrblockapi.Block(x) | ||||
|         if not bl.verifySig() or bl.signer != bytesconverter.bytes_to_str(unpaddedbase32.repad(bytesconverter.str_to_bytes(signer))): continue | ||||
|         if not bl.isSigner(signer): continue | ||||
|         if bl.claimedTime > newest_time: | ||||
|             newest_time = bl.claimedTime | ||||
|             message = bl.bcontent | ||||
|     return Response(message, headers={"Content-Type": "text/plain"})</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.miscclientapi" href="../index.html">src.httpapi.miscclientapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.miscclientapi.motd.get_motd" href="#src.httpapi.miscclientapi.motd.get_motd">get_motd</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										340
									
								
								docs/html/src/httpapi/miscclientapi/staticfiles.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										340
									
								
								docs/html/src/httpapi/miscclientapi/staticfiles.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,340 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.miscclientapi.staticfiles API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.miscclientapi.staticfiles</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>Register static file routes</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">''' | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     Register static file routes | ||||
| ''' | ||||
| ''' | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| import os | ||||
| import mimetypes | ||||
| from flask import Blueprint, send_from_directory | ||||
| 
 | ||||
| # Was having some mime type issues on windows, this appeared to fix it. | ||||
| # we have no-sniff set, so if the mime types are invalid sripts can't load. | ||||
| mimetypes.add_type('application/javascript', '.js') | ||||
| mimetypes.add_type('text/css', '.css') | ||||
| 
 | ||||
| static_files_bp = Blueprint('staticfiles', __name__) | ||||
| 
 | ||||
| root = os.path.dirname(os.path.realpath(__file__)) + '/../../../static-data/www/' # should be set to onionr install directory from onionr startup | ||||
| 
 | ||||
| @static_files_bp.route('/onboarding/', endpoint='onboardingIndex') | ||||
| def onboard(): | ||||
|     return send_from_directory(f'{root}onboarding/', "index.html") | ||||
| 
 | ||||
| @static_files_bp.route('/onboarding/<path:path>', endpoint='onboarding') | ||||
| def onboard_files(path): | ||||
|     return send_from_directory(f'{root}onboarding/', path) | ||||
| 
 | ||||
| @static_files_bp.route('/chat/', endpoint='chatIndex') | ||||
| def chat_index(): | ||||
|     return send_from_directory(root + 'chat/', "index.html") | ||||
| 
 | ||||
| @static_files_bp.route('/chat/<path:path>', endpoint='chat') | ||||
| def load_chat(path): | ||||
|     return send_from_directory(root + 'chat/', path) | ||||
| 
 | ||||
| @static_files_bp.route('/board/', endpoint='board') | ||||
| def loadBoard(): | ||||
|     return send_from_directory(root + 'board/', "index.html") | ||||
| 
 | ||||
| @static_files_bp.route('/mail/<path:path>', endpoint='mail') | ||||
| def loadMail(path): | ||||
|     return send_from_directory(root + 'mail/', path) | ||||
| 
 | ||||
| @static_files_bp.route('/mail/', endpoint='mailindex') | ||||
| def loadMailIndex(): | ||||
|     return send_from_directory(root + 'mail/', 'index.html') | ||||
| 
 | ||||
| @static_files_bp.route('/friends/<path:path>', endpoint='friends') | ||||
| def loadContacts(path): | ||||
|     return send_from_directory(root + 'friends/', path) | ||||
| 
 | ||||
| @static_files_bp.route('/friends/', endpoint='friendsindex') | ||||
| def loadContacts(): | ||||
|     return send_from_directory(root + 'friends/', 'index.html') | ||||
| 
 | ||||
| @static_files_bp.route('/profiles/<path:path>', endpoint='profiles') | ||||
| def loadContacts(path): | ||||
|     return send_from_directory(root + 'profiles/', path) | ||||
| 
 | ||||
| @static_files_bp.route('/profiles/', endpoint='profilesindex') | ||||
| def loadContacts(): | ||||
|     return send_from_directory(root + 'profiles/', 'index.html') | ||||
| 
 | ||||
| @static_files_bp.route('/board/<path:path>', endpoint='boardContent') | ||||
| def boardContent(path): | ||||
|     return send_from_directory(root + 'board/', path) | ||||
| 
 | ||||
| @static_files_bp.route('/shared/<path:path>', endpoint='sharedContent') | ||||
| def sharedContent(path): | ||||
|     return send_from_directory(root + 'shared/', path) | ||||
| 
 | ||||
| @static_files_bp.route('/', endpoint='onionrhome') | ||||
| def hello(): | ||||
|     # ui home | ||||
|     return send_from_directory(root + 'private/', 'index.html') | ||||
| 
 | ||||
| @static_files_bp.route('/private/<path:path>', endpoint='homedata') | ||||
| def homedata(path): | ||||
|     return send_from_directory(root + 'private/', path)</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.miscclientapi.staticfiles.boardContent"><code class="name flex"> | ||||
| <span>def <span class="ident">boardContent</span></span>(<span>path)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@static_files_bp.route('/board/<path:path>', endpoint='boardContent') | ||||
| def boardContent(path): | ||||
|     return send_from_directory(root + 'board/', path)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.staticfiles.chat_index"><code class="name flex"> | ||||
| <span>def <span class="ident">chat_index</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@static_files_bp.route('/chat/', endpoint='chatIndex') | ||||
| def chat_index(): | ||||
|     return send_from_directory(root + 'chat/', "index.html")</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.staticfiles.hello"><code class="name flex"> | ||||
| <span>def <span class="ident">hello</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@static_files_bp.route('/', endpoint='onionrhome') | ||||
| def hello(): | ||||
|     # ui home | ||||
|     return send_from_directory(root + 'private/', 'index.html')</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.staticfiles.homedata"><code class="name flex"> | ||||
| <span>def <span class="ident">homedata</span></span>(<span>path)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@static_files_bp.route('/private/<path:path>', endpoint='homedata') | ||||
| def homedata(path): | ||||
|     return send_from_directory(root + 'private/', path)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.staticfiles.loadBoard"><code class="name flex"> | ||||
| <span>def <span class="ident">loadBoard</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@static_files_bp.route('/board/', endpoint='board') | ||||
| def loadBoard(): | ||||
|     return send_from_directory(root + 'board/', "index.html")</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.staticfiles.loadContacts"><code class="name flex"> | ||||
| <span>def <span class="ident">loadContacts</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@static_files_bp.route('/profiles/', endpoint='profilesindex') | ||||
| def loadContacts(): | ||||
|     return send_from_directory(root + 'profiles/', 'index.html')</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.staticfiles.loadMail"><code class="name flex"> | ||||
| <span>def <span class="ident">loadMail</span></span>(<span>path)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@static_files_bp.route('/mail/<path:path>', endpoint='mail') | ||||
| def loadMail(path): | ||||
|     return send_from_directory(root + 'mail/', path)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.staticfiles.loadMailIndex"><code class="name flex"> | ||||
| <span>def <span class="ident">loadMailIndex</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@static_files_bp.route('/mail/', endpoint='mailindex') | ||||
| def loadMailIndex(): | ||||
|     return send_from_directory(root + 'mail/', 'index.html')</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.staticfiles.load_chat"><code class="name flex"> | ||||
| <span>def <span class="ident">load_chat</span></span>(<span>path)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@static_files_bp.route('/chat/<path:path>', endpoint='chat') | ||||
| def load_chat(path): | ||||
|     return send_from_directory(root + 'chat/', path)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.staticfiles.onboard"><code class="name flex"> | ||||
| <span>def <span class="ident">onboard</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@static_files_bp.route('/onboarding/', endpoint='onboardingIndex') | ||||
| def onboard(): | ||||
|     return send_from_directory(f'{root}onboarding/', "index.html")</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.staticfiles.onboard_files"><code class="name flex"> | ||||
| <span>def <span class="ident">onboard_files</span></span>(<span>path)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@static_files_bp.route('/onboarding/<path:path>', endpoint='onboarding') | ||||
| def onboard_files(path): | ||||
|     return send_from_directory(f'{root}onboarding/', path)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscclientapi.staticfiles.sharedContent"><code class="name flex"> | ||||
| <span>def <span class="ident">sharedContent</span></span>(<span>path)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@static_files_bp.route('/shared/<path:path>', endpoint='sharedContent') | ||||
| def sharedContent(path): | ||||
|     return send_from_directory(root + 'shared/', path)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.miscclientapi" href="index.html">src.httpapi.miscclientapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class="two-column"> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles.boardContent" href="#src.httpapi.miscclientapi.staticfiles.boardContent">boardContent</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles.chat_index" href="#src.httpapi.miscclientapi.staticfiles.chat_index">chat_index</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles.hello" href="#src.httpapi.miscclientapi.staticfiles.hello">hello</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles.homedata" href="#src.httpapi.miscclientapi.staticfiles.homedata">homedata</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles.loadBoard" href="#src.httpapi.miscclientapi.staticfiles.loadBoard">loadBoard</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles.loadContacts" href="#src.httpapi.miscclientapi.staticfiles.loadContacts">loadContacts</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles.loadMail" href="#src.httpapi.miscclientapi.staticfiles.loadMail">loadMail</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles.loadMailIndex" href="#src.httpapi.miscclientapi.staticfiles.loadMailIndex">loadMailIndex</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles.load_chat" href="#src.httpapi.miscclientapi.staticfiles.load_chat">load_chat</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles.onboard" href="#src.httpapi.miscclientapi.staticfiles.onboard">onboard</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles.onboard_files" href="#src.httpapi.miscclientapi.staticfiles.onboard_files">onboard_files</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscclientapi.staticfiles.sharedContent" href="#src.httpapi.miscclientapi.staticfiles.sharedContent">sharedContent</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										176
									
								
								docs/html/src/httpapi/miscpublicapi/announce.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										176
									
								
								docs/html/src/httpapi/miscpublicapi/announce.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,176 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.miscpublicapi.announce API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.miscpublicapi.announce</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication.</p> | ||||
| <p>Handle announcements to the public API server</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">"""Onionr - Private P2P Communication. | ||||
| 
 | ||||
| Handle announcements to the public API server | ||||
| """ | ||||
| from flask import Response, g | ||||
| import deadsimplekv | ||||
| 
 | ||||
| import logger | ||||
| from etc import onionrvalues | ||||
| from onionrutils import stringvalidators, bytesconverter | ||||
| import filepaths | ||||
| from communicator import OnionrCommunicatorDaemon | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| 
 | ||||
| 
 | ||||
| def handle_announce(request): | ||||
|     """accept announcement posts, validating POW | ||||
|     clientAPI should be an instance of the clientAPI server running, request is a instance of a flask request | ||||
|     """ | ||||
|     resp = 'failure' | ||||
|     newNode = '' | ||||
| 
 | ||||
|     try: | ||||
|         newNode = request.form['node'].encode() | ||||
|     except KeyError: | ||||
|         logger.warn('No node specified for upload') | ||||
|     else: | ||||
|         newNode = bytesconverter.bytes_to_str(newNode) | ||||
|         announce_queue = deadsimplekv.DeadSimpleKV(filepaths.announce_cache) | ||||
|         announce_queue_list = announce_queue.get('new_peers') | ||||
|         if announce_queue_list is None: | ||||
|             announce_queue_list = [] | ||||
|         else: | ||||
|             if len(announce_queue_list) >= onionrvalues.MAX_NEW_PEER_QUEUE: | ||||
|                 newNode = '' | ||||
| 
 | ||||
|         if stringvalidators.validate_transport(newNode) and \ | ||||
|                 newNode not in announce_queue_list: | ||||
|             g.shared_state.get( | ||||
|                 OnionrCommunicatorDaemon).newPeers.append(newNode) | ||||
|             announce_queue.put('new_peers', | ||||
|                                announce_queue_list.append(newNode)) | ||||
|             announce_queue.flush() | ||||
|             resp = 'Success' | ||||
| 
 | ||||
|     resp = Response(resp) | ||||
|     if resp == 'failure': | ||||
|         return resp, 406 | ||||
|     return resp</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.miscpublicapi.announce.handle_announce"><code class="name flex"> | ||||
| <span>def <span class="ident">handle_announce</span></span>(<span>request)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>accept announcement posts, validating POW | ||||
| clientAPI should be an instance of the clientAPI server running, request is a instance of a flask request</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def handle_announce(request): | ||||
|     """accept announcement posts, validating POW | ||||
|     clientAPI should be an instance of the clientAPI server running, request is a instance of a flask request | ||||
|     """ | ||||
|     resp = 'failure' | ||||
|     newNode = '' | ||||
| 
 | ||||
|     try: | ||||
|         newNode = request.form['node'].encode() | ||||
|     except KeyError: | ||||
|         logger.warn('No node specified for upload') | ||||
|     else: | ||||
|         newNode = bytesconverter.bytes_to_str(newNode) | ||||
|         announce_queue = deadsimplekv.DeadSimpleKV(filepaths.announce_cache) | ||||
|         announce_queue_list = announce_queue.get('new_peers') | ||||
|         if announce_queue_list is None: | ||||
|             announce_queue_list = [] | ||||
|         else: | ||||
|             if len(announce_queue_list) >= onionrvalues.MAX_NEW_PEER_QUEUE: | ||||
|                 newNode = '' | ||||
| 
 | ||||
|         if stringvalidators.validate_transport(newNode) and \ | ||||
|                 newNode not in announce_queue_list: | ||||
|             g.shared_state.get( | ||||
|                 OnionrCommunicatorDaemon).newPeers.append(newNode) | ||||
|             announce_queue.put('new_peers', | ||||
|                                announce_queue_list.append(newNode)) | ||||
|             announce_queue.flush() | ||||
|             resp = 'Success' | ||||
| 
 | ||||
|     resp = Response(resp) | ||||
|     if resp == 'failure': | ||||
|         return resp, 406 | ||||
|     return resp</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.miscpublicapi" href="index.html">src.httpapi.miscpublicapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.miscpublicapi.announce.handle_announce" href="#src.httpapi.miscpublicapi.announce.handle_announce">handle_announce</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										221
									
								
								docs/html/src/httpapi/miscpublicapi/endpoints.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										221
									
								
								docs/html/src/httpapi/miscpublicapi/endpoints.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,221 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.miscpublicapi.endpoints API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.miscpublicapi.endpoints</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>Misc public API endpoints too small to need their own file and that need access to the public api inst</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">''' | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     Misc public API endpoints too small to need their own file and that need access to the public api inst | ||||
| ''' | ||||
| ''' | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| from flask import Response, Blueprint, request, send_from_directory, abort, g | ||||
| from . import getblocks, upload, announce | ||||
| from coredb import keydb | ||||
| import config | ||||
| class PublicEndpoints: | ||||
|     def __init__(self, public_api): | ||||
| 
 | ||||
|         public_endpoints_bp = Blueprint('publicendpoints', __name__) | ||||
|         self.public_endpoints_bp = public_endpoints_bp | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/') | ||||
|         def banner(): | ||||
|             # Display a bit of information to people who visit a node address in their browser | ||||
|             try: | ||||
|                 with open('../static-data/index.html', 'r') as html: | ||||
|                     resp = Response(html.read(), mimetype='text/html') | ||||
|             except FileNotFoundError: | ||||
|                 resp = Response("") | ||||
|             return resp | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/getblocklist') | ||||
|         def get_block_list(): | ||||
|             '''Get a list of blocks, optionally filtered by epoch time stamp, excluding those hidden''' | ||||
|             return getblocks.get_public_block_list(public_api, request) | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/getdata/<name>') | ||||
|         def get_block_data(name): | ||||
|             # Share data for a block if we have it and it isn't hidden | ||||
|             return getblocks.get_block_data(public_api, name) | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/www/<path:path>') | ||||
|         def www_public(path): | ||||
|             # A way to share files directly over your .onion | ||||
|             if not config.get("www.public.run", True): | ||||
|                 abort(403) | ||||
|             return send_from_directory(config.get('www.public.path', 'static-data/www/public/'), path) | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/ping') | ||||
|         def ping(): | ||||
|             # Endpoint to test if nodes are up | ||||
|             return Response("pong!") | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/pex') | ||||
|         def peer_exchange(): | ||||
|             response = ','.join(keydb.listkeys.list_adders(recent=3600)) | ||||
|             if len(response) == 0: | ||||
|                 response = '' | ||||
|             return Response(response) | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/announce', methods=['post']) | ||||
|         def accept_announce(): | ||||
|             '''Accept announcements with pow token to prevent spam''' | ||||
|             g.shared_state = public_api._too_many | ||||
|             resp = announce.handle_announce(request) | ||||
|             return resp | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/upload', methods=['post']) | ||||
|         def upload_endpoint(): | ||||
|             '''Accept file uploads. In the future this will be done more often than on creation  | ||||
|             to speed up block sync | ||||
|             ''' | ||||
|             return upload.accept_upload(request)</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-classes">Classes</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.miscpublicapi.endpoints.PublicEndpoints"><code class="flex name class"> | ||||
| <span>class <span class="ident">PublicEndpoints</span></span> | ||||
| <span>(</span><span>public_api)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">class PublicEndpoints: | ||||
|     def __init__(self, public_api): | ||||
| 
 | ||||
|         public_endpoints_bp = Blueprint('publicendpoints', __name__) | ||||
|         self.public_endpoints_bp = public_endpoints_bp | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/') | ||||
|         def banner(): | ||||
|             # Display a bit of information to people who visit a node address in their browser | ||||
|             try: | ||||
|                 with open('../static-data/index.html', 'r') as html: | ||||
|                     resp = Response(html.read(), mimetype='text/html') | ||||
|             except FileNotFoundError: | ||||
|                 resp = Response("") | ||||
|             return resp | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/getblocklist') | ||||
|         def get_block_list(): | ||||
|             '''Get a list of blocks, optionally filtered by epoch time stamp, excluding those hidden''' | ||||
|             return getblocks.get_public_block_list(public_api, request) | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/getdata/<name>') | ||||
|         def get_block_data(name): | ||||
|             # Share data for a block if we have it and it isn't hidden | ||||
|             return getblocks.get_block_data(public_api, name) | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/www/<path:path>') | ||||
|         def www_public(path): | ||||
|             # A way to share files directly over your .onion | ||||
|             if not config.get("www.public.run", True): | ||||
|                 abort(403) | ||||
|             return send_from_directory(config.get('www.public.path', 'static-data/www/public/'), path) | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/ping') | ||||
|         def ping(): | ||||
|             # Endpoint to test if nodes are up | ||||
|             return Response("pong!") | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/pex') | ||||
|         def peer_exchange(): | ||||
|             response = ','.join(keydb.listkeys.list_adders(recent=3600)) | ||||
|             if len(response) == 0: | ||||
|                 response = '' | ||||
|             return Response(response) | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/announce', methods=['post']) | ||||
|         def accept_announce(): | ||||
|             '''Accept announcements with pow token to prevent spam''' | ||||
|             g.shared_state = public_api._too_many | ||||
|             resp = announce.handle_announce(request) | ||||
|             return resp | ||||
| 
 | ||||
|         @public_endpoints_bp.route('/upload', methods=['post']) | ||||
|         def upload_endpoint(): | ||||
|             '''Accept file uploads. In the future this will be done more often than on creation  | ||||
|             to speed up block sync | ||||
|             ''' | ||||
|             return upload.accept_upload(request)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.miscpublicapi" href="index.html">src.httpapi.miscpublicapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-classes">Classes</a></h3> | ||||
| <ul> | ||||
| <li> | ||||
| <h4><code><a title="src.httpapi.miscpublicapi.endpoints.PublicEndpoints" href="#src.httpapi.miscpublicapi.endpoints.PublicEndpoints">PublicEndpoints</a></code></h4> | ||||
| </li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										181
									
								
								docs/html/src/httpapi/miscpublicapi/getblocks.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										181
									
								
								docs/html/src/httpapi/miscpublicapi/getblocks.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,181 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.miscpublicapi.getblocks API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.miscpublicapi.getblocks</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>Public endpoints to get block data and lists</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">''' | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     Public endpoints to get block data and lists | ||||
| ''' | ||||
| ''' | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| from flask import Response, abort | ||||
| import config | ||||
| from onionrutils import bytesconverter, stringvalidators | ||||
| from coredb import blockmetadb | ||||
| from utils import reconstructhash | ||||
| from .. import apiutils | ||||
| def get_public_block_list(publicAPI, request): | ||||
|     # Provide a list of our blocks, with a date offset | ||||
|     dateAdjust = request.args.get('date') | ||||
|     bList = blockmetadb.get_block_list(dateRec=dateAdjust) | ||||
|     share_list = '' | ||||
|     if config.get('general.hide_created_blocks', True): | ||||
|         for b in publicAPI.hideBlocks: | ||||
|             if b in bList: | ||||
|                 # Don't share blocks we created if they haven't been *uploaded* yet, makes it harder to find who created a block | ||||
|                 bList.remove(b) | ||||
|     for b in bList: | ||||
|         share_list += '%s\n' % (reconstructhash.deconstruct_hash(b),) | ||||
|     return Response(share_list) | ||||
| 
 | ||||
| def get_block_data(publicAPI, data): | ||||
|     '''data is the block hash in hex''' | ||||
|     resp = '' | ||||
|     if stringvalidators.validate_hash(data): | ||||
|         if not config.get('general.hide_created_blocks', True) or data not in publicAPI.hideBlocks: | ||||
|             if data in blockmetadb.get_block_list(): | ||||
|                 block = apiutils.GetBlockData().get_block_data(data, raw=True) | ||||
|                 try: | ||||
|                     block = block.encode() # Encode in case data is binary | ||||
|                 except AttributeError: | ||||
|                     if len(block) == 0: | ||||
|                         abort(404) | ||||
|                 block = bytesconverter.str_to_bytes(block) | ||||
|                 resp = block | ||||
|     if len(resp) == 0: | ||||
|         abort(404) | ||||
|         resp = "" | ||||
|     # Has to be octet stream, otherwise binary data fails hash check | ||||
|     return Response(resp, mimetype='application/octet-stream')</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.miscpublicapi.getblocks.get_block_data"><code class="name flex"> | ||||
| <span>def <span class="ident">get_block_data</span></span>(<span>publicAPI, data)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>data is the block hash in hex</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def get_block_data(publicAPI, data): | ||||
|     '''data is the block hash in hex''' | ||||
|     resp = '' | ||||
|     if stringvalidators.validate_hash(data): | ||||
|         if not config.get('general.hide_created_blocks', True) or data not in publicAPI.hideBlocks: | ||||
|             if data in blockmetadb.get_block_list(): | ||||
|                 block = apiutils.GetBlockData().get_block_data(data, raw=True) | ||||
|                 try: | ||||
|                     block = block.encode() # Encode in case data is binary | ||||
|                 except AttributeError: | ||||
|                     if len(block) == 0: | ||||
|                         abort(404) | ||||
|                 block = bytesconverter.str_to_bytes(block) | ||||
|                 resp = block | ||||
|     if len(resp) == 0: | ||||
|         abort(404) | ||||
|         resp = "" | ||||
|     # Has to be octet stream, otherwise binary data fails hash check | ||||
|     return Response(resp, mimetype='application/octet-stream')</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.miscpublicapi.getblocks.get_public_block_list"><code class="name flex"> | ||||
| <span>def <span class="ident">get_public_block_list</span></span>(<span>publicAPI, request)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def get_public_block_list(publicAPI, request): | ||||
|     # Provide a list of our blocks, with a date offset | ||||
|     dateAdjust = request.args.get('date') | ||||
|     bList = blockmetadb.get_block_list(dateRec=dateAdjust) | ||||
|     share_list = '' | ||||
|     if config.get('general.hide_created_blocks', True): | ||||
|         for b in publicAPI.hideBlocks: | ||||
|             if b in bList: | ||||
|                 # Don't share blocks we created if they haven't been *uploaded* yet, makes it harder to find who created a block | ||||
|                 bList.remove(b) | ||||
|     for b in bList: | ||||
|         share_list += '%s\n' % (reconstructhash.deconstruct_hash(b),) | ||||
|     return Response(share_list)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.miscpublicapi" href="index.html">src.httpapi.miscpublicapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.miscpublicapi.getblocks.get_block_data" href="#src.httpapi.miscpublicapi.getblocks.get_block_data">get_block_data</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscpublicapi.getblocks.get_public_block_list" href="#src.httpapi.miscpublicapi.getblocks.get_public_block_list">get_public_block_list</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										91
									
								
								docs/html/src/httpapi/miscpublicapi/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										91
									
								
								docs/html/src/httpapi/miscpublicapi/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,91 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.miscpublicapi API documentation</title> | ||||
| <meta name="description" content="" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.miscpublicapi</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">from . import announce, upload, getblocks, endpoints | ||||
| 
 | ||||
| announce = announce.handle_announce # endpoint handler for accepting peer announcements | ||||
| upload = upload.accept_upload # endpoint handler for accepting public uploads | ||||
| public_block_list = getblocks.get_public_block_list # endpoint handler for getting block lists | ||||
| public_get_block_data = getblocks.get_block_data # endpoint handler for responding to peers requests for block data</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-submodules">Sub-modules</h2> | ||||
| <dl> | ||||
| <dt><code class="name"><a title="src.httpapi.miscpublicapi.announce" href="announce.html">src.httpapi.miscpublicapi.announce</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.miscpublicapi.endpoints" href="endpoints.html">src.httpapi.miscpublicapi.endpoints</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.miscpublicapi.getblocks" href="getblocks.html">src.httpapi.miscpublicapi.getblocks</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.miscpublicapi.upload" href="upload.html">src.httpapi.miscpublicapi.upload</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="../index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-submodules">Sub-modules</a></h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.miscpublicapi.announce" href="announce.html">src.httpapi.miscpublicapi.announce</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscpublicapi.endpoints" href="endpoints.html">src.httpapi.miscpublicapi.endpoints</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscpublicapi.getblocks" href="getblocks.html">src.httpapi.miscpublicapi.getblocks</a></code></li> | ||||
| <li><code><a title="src.httpapi.miscpublicapi.upload" href="upload.html">src.httpapi.miscpublicapi.upload</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										180
									
								
								docs/html/src/httpapi/miscpublicapi/upload.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										180
									
								
								docs/html/src/httpapi/miscpublicapi/upload.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,180 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.miscpublicapi.upload API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.miscpublicapi.upload</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>Accept block uploads to the public API server</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">''' | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     Accept block uploads to the public API server | ||||
| ''' | ||||
| from gevent import spawn | ||||
| from gevent import threading | ||||
| 
 | ||||
| import sys | ||||
| from flask import Response | ||||
| from flask import abort | ||||
| 
 | ||||
| from onionrutils import localcommand | ||||
| from onionrblocks import blockimporter | ||||
| import onionrexceptions | ||||
| import logger | ||||
| 
 | ||||
| ''' | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| 
 | ||||
| 
 | ||||
| def accept_upload(request): | ||||
|     """Accept uploaded blocks to our public Onionr protocol API server""" | ||||
|     resp = 'failure' | ||||
|     data = request.get_data() | ||||
|     b_hash = '' | ||||
|     if sys.getsizeof(data) < 100000000: | ||||
|         try: | ||||
|             b_hash = blockimporter.import_block_from_data(data) | ||||
|             if b_hash: | ||||
|                 spawn( | ||||
|                     localcommand.local_command, | ||||
|                     f'/daemon-event/upload_event', | ||||
|                     post=True, | ||||
|                     is_json=True, | ||||
|                     postData={'block': b_hash} | ||||
|                     ).get(timeout=10) | ||||
|                 resp = 'success' | ||||
|             else: | ||||
|                 resp = 'failure' | ||||
|                 logger.warn('Error encountered importing uploaded block') | ||||
|         except onionrexceptions.BlacklistedBlock: | ||||
|             logger.debug('uploaded block is blacklisted') | ||||
|             resp = 'failure' | ||||
|         except onionrexceptions.InvalidProof: | ||||
|             resp = 'proof' | ||||
|         except onionrexceptions.DataExists: | ||||
|             resp = 'exists' | ||||
|     if resp == 'failure': | ||||
|         abort(400) | ||||
|     elif resp == 'proof': | ||||
|         resp = Response(resp, 400) | ||||
|     else: | ||||
|         resp = Response(resp) | ||||
|     return resp</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.miscpublicapi.upload.accept_upload"><code class="name flex"> | ||||
| <span>def <span class="ident">accept_upload</span></span>(<span>request)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Accept uploaded blocks to our public Onionr protocol API server</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def accept_upload(request): | ||||
|     """Accept uploaded blocks to our public Onionr protocol API server""" | ||||
|     resp = 'failure' | ||||
|     data = request.get_data() | ||||
|     b_hash = '' | ||||
|     if sys.getsizeof(data) < 100000000: | ||||
|         try: | ||||
|             b_hash = blockimporter.import_block_from_data(data) | ||||
|             if b_hash: | ||||
|                 spawn( | ||||
|                     localcommand.local_command, | ||||
|                     f'/daemon-event/upload_event', | ||||
|                     post=True, | ||||
|                     is_json=True, | ||||
|                     postData={'block': b_hash} | ||||
|                     ).get(timeout=10) | ||||
|                 resp = 'success' | ||||
|             else: | ||||
|                 resp = 'failure' | ||||
|                 logger.warn('Error encountered importing uploaded block') | ||||
|         except onionrexceptions.BlacklistedBlock: | ||||
|             logger.debug('uploaded block is blacklisted') | ||||
|             resp = 'failure' | ||||
|         except onionrexceptions.InvalidProof: | ||||
|             resp = 'proof' | ||||
|         except onionrexceptions.DataExists: | ||||
|             resp = 'exists' | ||||
|     if resp == 'failure': | ||||
|         abort(400) | ||||
|     elif resp == 'proof': | ||||
|         resp = Response(resp, 400) | ||||
|     else: | ||||
|         resp = Response(resp) | ||||
|     return resp</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.miscpublicapi" href="index.html">src.httpapi.miscpublicapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.miscpublicapi.upload.accept_upload" href="#src.httpapi.miscpublicapi.upload.accept_upload">accept_upload</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										146
									
								
								docs/html/src/httpapi/onionrsitesapi/findsite.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										146
									
								
								docs/html/src/httpapi/onionrsitesapi/findsite.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,146 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.onionrsitesapi.findsite API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.onionrsitesapi.findsite</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>view and interact with onionr sites</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">""" | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     view and interact with onionr sites | ||||
| """ | ||||
| 
 | ||||
| from typing import Union | ||||
| 
 | ||||
| import onionrexceptions | ||||
| from onionrutils import mnemonickeys | ||||
| from onionrutils import stringvalidators | ||||
| from coredb import blockmetadb | ||||
| from onionrblocks.onionrblockapi import Block | ||||
| from onionrtypes import BlockHash | ||||
| 
 | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| 
 | ||||
| 
 | ||||
| def find_site(user_id: str) -> Union[BlockHash, None]: | ||||
|     """Returns block hash str for latest block for a site by a given user id""" | ||||
|     # If mnemonic delim in key, convert to base32 version | ||||
|     if mnemonickeys.DELIMITER in user_id: | ||||
|         user_id = mnemonickeys.get_base32(user_id) | ||||
| 
 | ||||
|     if not stringvalidators.validate_pub_key(user_id): | ||||
|         raise onionrexceptions.InvalidPubkey | ||||
| 
 | ||||
|     found_site = None | ||||
|     sites = blockmetadb.get_blocks_by_type('zsite') | ||||
| 
 | ||||
|     # Find site by searching all site blocks. eww O(N) ☹️, TODO: event based | ||||
|     for site in sites: | ||||
|         site = Block(site) | ||||
|         if site.isSigner(user_id) and site.verifySig(): | ||||
|             found_site = site.hash | ||||
|     return found_site</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.onionrsitesapi.findsite.find_site"><code class="name flex"> | ||||
| <span>def <span class="ident">find_site</span></span>(<span>user_id)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Returns block hash str for latest block for a site by a given user id</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def find_site(user_id: str) -> Union[BlockHash, None]: | ||||
|     """Returns block hash str for latest block for a site by a given user id""" | ||||
|     # If mnemonic delim in key, convert to base32 version | ||||
|     if mnemonickeys.DELIMITER in user_id: | ||||
|         user_id = mnemonickeys.get_base32(user_id) | ||||
| 
 | ||||
|     if not stringvalidators.validate_pub_key(user_id): | ||||
|         raise onionrexceptions.InvalidPubkey | ||||
| 
 | ||||
|     found_site = None | ||||
|     sites = blockmetadb.get_blocks_by_type('zsite') | ||||
| 
 | ||||
|     # Find site by searching all site blocks. eww O(N) ☹️, TODO: event based | ||||
|     for site in sites: | ||||
|         site = Block(site) | ||||
|         if site.isSigner(user_id) and site.verifySig(): | ||||
|             found_site = site.hash | ||||
|     return found_site</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.onionrsitesapi" href="index.html">src.httpapi.onionrsitesapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.onionrsitesapi.findsite.find_site" href="#src.httpapi.onionrsitesapi.findsite.find_site">find_site</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										261
									
								
								docs/html/src/httpapi/onionrsitesapi/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										261
									
								
								docs/html/src/httpapi/onionrsitesapi/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,261 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.onionrsitesapi API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.onionrsitesapi</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>view and interact with onionr sites</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">""" | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     view and interact with onionr sites | ||||
| """ | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| import base64 | ||||
| import binascii | ||||
| import mimetypes | ||||
| 
 | ||||
| import unpaddedbase32 | ||||
| 
 | ||||
| from flask import Blueprint, Response, request, abort | ||||
| 
 | ||||
| from onionrblocks import onionrblockapi | ||||
| import onionrexceptions | ||||
| from onionrutils import stringvalidators | ||||
| from utils import safezip | ||||
| from onionrutils import mnemonickeys | ||||
| from . import sitefiles | ||||
| 
 | ||||
| site_api = Blueprint('siteapi', __name__) | ||||
| 
 | ||||
| @site_api.route('/site/<name>/', endpoint='site') | ||||
| def site(name: str)->Response: | ||||
|     """Accept a site 'name', if pubkey then show multi-page site, if hash show single page site""" | ||||
|     resp: str = 'Not Found' | ||||
|     mime_type = 'text/html' | ||||
| 
 | ||||
|     # If necessary convert the name to base32 from mnemonic | ||||
|     if mnemonickeys.DELIMITER in name: | ||||
|         name = mnemonickeys.get_base32(name) | ||||
| 
 | ||||
|     # Now make sure the key is regardless a valid base32 format ed25519 key (readding padding if necessary) | ||||
|     if stringvalidators.validate_pub_key(name): | ||||
|         name = unpaddedbase32.repad(name) | ||||
|         resp = sitefiles.get_file(name, 'index.html') | ||||
| 
 | ||||
|     elif stringvalidators.validate_hash(name): | ||||
|         try: | ||||
|             resp = onionrblockapi.Block(name).bcontent | ||||
|         except onionrexceptions.NoDataAvailable: | ||||
|             abort(404) | ||||
|         except TypeError: | ||||
|             pass | ||||
|         try: | ||||
|             resp = base64.b64decode(resp) | ||||
|         except binascii.Error: | ||||
|             pass | ||||
|     if resp == 'Not Found' or not resp: | ||||
|         abort(404) | ||||
|     return Response(resp) | ||||
| 
 | ||||
| @site_api.route('/site/<name>/<path:file>', endpoint='siteFile') | ||||
| def site_file(name: str, file: str)->Response: | ||||
|     """Accept a site 'name', if pubkey then show multi-page site, if hash show single page site""" | ||||
|     resp: str = 'Not Found' | ||||
|     mime_type = mimetypes.MimeTypes().guess_type(file)[0] | ||||
| 
 | ||||
|     # If necessary convert the name to base32 from mnemonic | ||||
|     if mnemonickeys.DELIMITER in name: | ||||
|         name = mnemonickeys.get_base32(name) | ||||
| 
 | ||||
|     # Now make sure the key is regardless a valid base32 format ed25519 key (readding padding if necessary) | ||||
|     if stringvalidators.validate_pub_key(name): | ||||
|         name = unpaddedbase32.repad(name) | ||||
|         resp = sitefiles.get_file(name, file) | ||||
| 
 | ||||
|     elif stringvalidators.validate_hash(name): | ||||
|         try: | ||||
|             resp = onionrblockapi.Block(name).bcontent | ||||
|         except onionrexceptions.NoDataAvailable: | ||||
|             abort(404) | ||||
|         except TypeError: | ||||
|             pass | ||||
|         try: | ||||
|             resp = base64.b64decode(resp) | ||||
|         except binascii.Error: | ||||
|             pass | ||||
|     if resp == 'Not Found' or not resp: | ||||
|         abort(404) | ||||
|     return Response(resp, mimetype=mime_type)</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-submodules">Sub-modules</h2> | ||||
| <dl> | ||||
| <dt><code class="name"><a title="src.httpapi.onionrsitesapi.findsite" href="findsite.html">src.httpapi.onionrsitesapi.findsite</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.onionrsitesapi.sitefiles" href="sitefiles.html">src.httpapi.onionrsitesapi.sitefiles</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.onionrsitesapi.site"><code class="name flex"> | ||||
| <span>def <span class="ident">site</span></span>(<span>name)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Accept a site 'name', if pubkey then show multi-page site, if hash show single page site</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@site_api.route('/site/<name>/', endpoint='site') | ||||
| def site(name: str)->Response: | ||||
|     """Accept a site 'name', if pubkey then show multi-page site, if hash show single page site""" | ||||
|     resp: str = 'Not Found' | ||||
|     mime_type = 'text/html' | ||||
| 
 | ||||
|     # If necessary convert the name to base32 from mnemonic | ||||
|     if mnemonickeys.DELIMITER in name: | ||||
|         name = mnemonickeys.get_base32(name) | ||||
| 
 | ||||
|     # Now make sure the key is regardless a valid base32 format ed25519 key (readding padding if necessary) | ||||
|     if stringvalidators.validate_pub_key(name): | ||||
|         name = unpaddedbase32.repad(name) | ||||
|         resp = sitefiles.get_file(name, 'index.html') | ||||
| 
 | ||||
|     elif stringvalidators.validate_hash(name): | ||||
|         try: | ||||
|             resp = onionrblockapi.Block(name).bcontent | ||||
|         except onionrexceptions.NoDataAvailable: | ||||
|             abort(404) | ||||
|         except TypeError: | ||||
|             pass | ||||
|         try: | ||||
|             resp = base64.b64decode(resp) | ||||
|         except binascii.Error: | ||||
|             pass | ||||
|     if resp == 'Not Found' or not resp: | ||||
|         abort(404) | ||||
|     return Response(resp)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.onionrsitesapi.site_file"><code class="name flex"> | ||||
| <span>def <span class="ident">site_file</span></span>(<span>name, file)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Accept a site 'name', if pubkey then show multi-page site, if hash show single page site</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@site_api.route('/site/<name>/<path:file>', endpoint='siteFile') | ||||
| def site_file(name: str, file: str)->Response: | ||||
|     """Accept a site 'name', if pubkey then show multi-page site, if hash show single page site""" | ||||
|     resp: str = 'Not Found' | ||||
|     mime_type = mimetypes.MimeTypes().guess_type(file)[0] | ||||
| 
 | ||||
|     # If necessary convert the name to base32 from mnemonic | ||||
|     if mnemonickeys.DELIMITER in name: | ||||
|         name = mnemonickeys.get_base32(name) | ||||
| 
 | ||||
|     # Now make sure the key is regardless a valid base32 format ed25519 key (readding padding if necessary) | ||||
|     if stringvalidators.validate_pub_key(name): | ||||
|         name = unpaddedbase32.repad(name) | ||||
|         resp = sitefiles.get_file(name, file) | ||||
| 
 | ||||
|     elif stringvalidators.validate_hash(name): | ||||
|         try: | ||||
|             resp = onionrblockapi.Block(name).bcontent | ||||
|         except onionrexceptions.NoDataAvailable: | ||||
|             abort(404) | ||||
|         except TypeError: | ||||
|             pass | ||||
|         try: | ||||
|             resp = base64.b64decode(resp) | ||||
|         except binascii.Error: | ||||
|             pass | ||||
|     if resp == 'Not Found' or not resp: | ||||
|         abort(404) | ||||
|     return Response(resp, mimetype=mime_type)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="../index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-submodules">Sub-modules</a></h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.onionrsitesapi.findsite" href="findsite.html">src.httpapi.onionrsitesapi.findsite</a></code></li> | ||||
| <li><code><a title="src.httpapi.onionrsitesapi.sitefiles" href="sitefiles.html">src.httpapi.onionrsitesapi.sitefiles</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.onionrsitesapi.site" href="#src.httpapi.onionrsitesapi.site">site</a></code></li> | ||||
| <li><code><a title="src.httpapi.onionrsitesapi.site_file" href="#src.httpapi.onionrsitesapi.site_file">site_file</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										210
									
								
								docs/html/src/httpapi/onionrsitesapi/sitefiles.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										210
									
								
								docs/html/src/httpapi/onionrsitesapi/sitefiles.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,210 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.onionrsitesapi.sitefiles API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.onionrsitesapi.sitefiles</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>Read onionr site files</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">""" | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     Read onionr site files | ||||
| """ | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| from typing import Union, Tuple | ||||
| import tarfile | ||||
| import io | ||||
| import os | ||||
| 
 | ||||
| import unpaddedbase32 | ||||
| 
 | ||||
| from coredb import blockmetadb | ||||
| from onionrblocks import onionrblockapi | ||||
| from onionrblocks import insert | ||||
| 
 | ||||
| # Import types. Just for type hiting | ||||
| from onionrtypes import UserID, DeterministicKeyPassphrase, BlockHash | ||||
| 
 | ||||
| from onionrcrypto import generate_deterministic | ||||
| 
 | ||||
| def find_site_gzip(user_id: str)->tarfile.TarFile: | ||||
|     """Return verified site tar object""" | ||||
|     sites = blockmetadb.get_blocks_by_type('osite') | ||||
|     user_site = None | ||||
|     user_id = unpaddedbase32.repad(user_id) | ||||
|     for site in sites: | ||||
|         block = onionrblockapi.Block(site) | ||||
|         if block.isSigner(user_id): | ||||
|             user_site = block | ||||
|     if not user_site is None: | ||||
|         return tarfile.open(fileobj=io.BytesIO(user_site.bcontent), mode='r') | ||||
|     return None | ||||
| 
 | ||||
| def get_file(user_id, file)->Union[bytes, None]: | ||||
|     """Get a site file content""" | ||||
|     ret_data = "" | ||||
|     site = find_site_gzip(user_id) | ||||
|     if site is None: return None | ||||
|     for t_file in site.getmembers(): | ||||
|         if t_file.name.replace('./', '') == file: | ||||
|             return site.extractfile(t_file) | ||||
|     return None | ||||
| 
 | ||||
| def create_site(admin_pass: DeterministicKeyPassphrase, directory:str='.')->Tuple[UserID, BlockHash]: | ||||
|     public_key, private_key = generate_deterministic(admin_pass) | ||||
| 
 | ||||
|     raw_tar = io.BytesIO() | ||||
| 
 | ||||
|     tar = tarfile.open(mode='x:gz', fileobj=raw_tar) | ||||
|     tar.add(directory) | ||||
|     tar.close() | ||||
| 
 | ||||
|     raw_tar.seek(0) | ||||
| 
 | ||||
|     block_hash = insert(raw_tar.read(), header='osite', signing_key=private_key, sign=True) | ||||
| 
 | ||||
|     return (public_key, block_hash)</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.onionrsitesapi.sitefiles.create_site"><code class="name flex"> | ||||
| <span>def <span class="ident">create_site</span></span>(<span>admin_pass, directory='.')</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def create_site(admin_pass: DeterministicKeyPassphrase, directory:str='.')->Tuple[UserID, BlockHash]: | ||||
|     public_key, private_key = generate_deterministic(admin_pass) | ||||
| 
 | ||||
|     raw_tar = io.BytesIO() | ||||
| 
 | ||||
|     tar = tarfile.open(mode='x:gz', fileobj=raw_tar) | ||||
|     tar.add(directory) | ||||
|     tar.close() | ||||
| 
 | ||||
|     raw_tar.seek(0) | ||||
| 
 | ||||
|     block_hash = insert(raw_tar.read(), header='osite', signing_key=private_key, sign=True) | ||||
| 
 | ||||
|     return (public_key, block_hash)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.onionrsitesapi.sitefiles.find_site_gzip"><code class="name flex"> | ||||
| <span>def <span class="ident">find_site_gzip</span></span>(<span>user_id)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Return verified site tar object</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def find_site_gzip(user_id: str)->tarfile.TarFile: | ||||
|     """Return verified site tar object""" | ||||
|     sites = blockmetadb.get_blocks_by_type('osite') | ||||
|     user_site = None | ||||
|     user_id = unpaddedbase32.repad(user_id) | ||||
|     for site in sites: | ||||
|         block = onionrblockapi.Block(site) | ||||
|         if block.isSigner(user_id): | ||||
|             user_site = block | ||||
|     if not user_site is None: | ||||
|         return tarfile.open(fileobj=io.BytesIO(user_site.bcontent), mode='r') | ||||
|     return None</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.onionrsitesapi.sitefiles.get_file"><code class="name flex"> | ||||
| <span>def <span class="ident">get_file</span></span>(<span>user_id, file)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Get a site file content</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def get_file(user_id, file)->Union[bytes, None]: | ||||
|     """Get a site file content""" | ||||
|     ret_data = "" | ||||
|     site = find_site_gzip(user_id) | ||||
|     if site is None: return None | ||||
|     for t_file in site.getmembers(): | ||||
|         if t_file.name.replace('./', '') == file: | ||||
|             return site.extractfile(t_file) | ||||
|     return None</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.onionrsitesapi" href="index.html">src.httpapi.onionrsitesapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.onionrsitesapi.sitefiles.create_site" href="#src.httpapi.onionrsitesapi.sitefiles.create_site">create_site</a></code></li> | ||||
| <li><code><a title="src.httpapi.onionrsitesapi.sitefiles.find_site_gzip" href="#src.httpapi.onionrsitesapi.sitefiles.find_site_gzip">find_site_gzip</a></code></li> | ||||
| <li><code><a title="src.httpapi.onionrsitesapi.sitefiles.get_file" href="#src.httpapi.onionrsitesapi.sitefiles.get_file">get_file</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										121
									
								
								docs/html/src/httpapi/profilesapi/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								docs/html/src/httpapi/profilesapi/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,121 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.profilesapi API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.profilesapi</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>This file creates http endpoints for user profile pages</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">''' | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     This file creates http endpoints for user profile pages | ||||
| ''' | ||||
| ''' | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| from flask import Blueprint, Response, request, abort | ||||
| from . import profiles | ||||
| 
 | ||||
| profile_BP = Blueprint('profile_BP', __name__) | ||||
| 
 | ||||
| @profile_BP.route('/profile/get/<pubkey>', endpoint='profiles') | ||||
| def get_profile_page(pubkey): | ||||
|     return Response(pubkey)</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-submodules">Sub-modules</h2> | ||||
| <dl> | ||||
| <dt><code class="name"><a title="src.httpapi.profilesapi.profiles" href="profiles.html">src.httpapi.profilesapi.profiles</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.profilesapi.get_profile_page"><code class="name flex"> | ||||
| <span>def <span class="ident">get_profile_page</span></span>(<span>pubkey)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@profile_BP.route('/profile/get/<pubkey>', endpoint='profiles') | ||||
| def get_profile_page(pubkey): | ||||
|     return Response(pubkey)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="../index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-submodules">Sub-modules</a></h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.profilesapi.profiles" href="profiles.html">src.httpapi.profilesapi.profiles</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.profilesapi.get_profile_page" href="#src.httpapi.profilesapi.get_profile_page">get_profile_page</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										81
									
								
								docs/html/src/httpapi/profilesapi/profiles.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								docs/html/src/httpapi/profilesapi/profiles.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,81 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.profilesapi.profiles API documentation</title> | ||||
| <meta name="description" content="" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.profilesapi.profiles</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def get_latest_user_profile(pubkey): | ||||
|     return ''</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.profilesapi.profiles.get_latest_user_profile"><code class="name flex"> | ||||
| <span>def <span class="ident">get_latest_user_profile</span></span>(<span>pubkey)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def get_latest_user_profile(pubkey): | ||||
|     return ''</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.profilesapi" href="index.html">src.httpapi.profilesapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.profilesapi.profiles.get_latest_user_profile" href="#src.httpapi.profilesapi.profiles.get_latest_user_profile">get_latest_user_profile</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										193
									
								
								docs/html/src/httpapi/security/client.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										193
									
								
								docs/html/src/httpapi/security/client.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,193 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.security.client API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.security.client</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>Process incoming requests to the client api server to validate they are legitimate</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">''' | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     Process incoming requests to the client api server to validate they are legitimate | ||||
| ''' | ||||
| ''' | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| import hmac | ||||
| from flask import Blueprint, request, abort, g | ||||
| from onionrservices import httpheaders | ||||
| from . import pluginwhitelist | ||||
| 
 | ||||
| # Be extremely mindful of this. These are endpoints available without a password | ||||
| whitelist_endpoints = ['www', 'staticfiles.homedata', 'staticfiles.sharedContent', | ||||
| 'staticfiles.friends', 'staticfiles.friendsindex', 'siteapi.site', 'siteapi.siteFile', 'staticfiles.onionrhome', | ||||
| 'themes.getTheme', 'staticfiles.onboarding', 'staticfiles.onboardingIndex'] | ||||
| 
 | ||||
| class ClientAPISecurity: | ||||
|     def __init__(self, client_api): | ||||
|         client_api_security_bp = Blueprint('clientapisecurity', __name__) | ||||
|         self.client_api_security_bp = client_api_security_bp | ||||
|         self.client_api = client_api | ||||
|         pluginwhitelist.load_plugin_security_whitelist_endpoints(whitelist_endpoints) | ||||
| 
 | ||||
|         @client_api_security_bp.before_app_request | ||||
|         def validate_request(): | ||||
|             '''Validate request has set password and is the correct hostname''' | ||||
|             # For the purpose of preventing DNS rebinding attacks | ||||
|             if request.host != '%s:%s' % (client_api.host, client_api.bindPort): | ||||
|                 abort(403) | ||||
| 
 | ||||
|             # Add shared objects | ||||
|             try: | ||||
|                 g.too_many = self.client_api._too_many | ||||
|             except KeyError: | ||||
|                 g.too_many = None | ||||
| 
 | ||||
|             if request.endpoint in whitelist_endpoints: | ||||
|                 return | ||||
|             if request.path.startswith('/site/'): return | ||||
| 
 | ||||
|             try: | ||||
|                 if not hmac.compare_digest(request.headers['token'], client_api.clientToken): | ||||
|                     if not hmac.compare_digest(request.form['token'], client_api.clientToken): | ||||
|                         abort(403) | ||||
|             except KeyError: | ||||
|                 if not hmac.compare_digest(request.form['token'], client_api.clientToken): | ||||
|                     abort(403) | ||||
| 
 | ||||
|         @client_api_security_bp.after_app_request | ||||
|         def after_req(resp): | ||||
|             # Security headers | ||||
|             resp = httpheaders.set_default_onionr_http_headers(resp) | ||||
|             if request.endpoint in ('siteapi.site', 'siteapi.siteFile'): | ||||
|                 resp.headers['Content-Security-Policy'] = "default-src 'none'; style-src 'self' data: 'unsafe-inline'; img-src 'self' data:; media-src 'self' data:" | ||||
|             else: | ||||
|                 resp.headers['Content-Security-Policy'] = "default-src 'none'; script-src 'self'; object-src 'none'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; media-src 'none'; frame-src 'none'; font-src 'self'; connect-src 'self'" | ||||
|             return resp</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-classes">Classes</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.security.client.ClientAPISecurity"><code class="flex name class"> | ||||
| <span>class <span class="ident">ClientAPISecurity</span></span> | ||||
| <span>(</span><span>client_api)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">class ClientAPISecurity: | ||||
|     def __init__(self, client_api): | ||||
|         client_api_security_bp = Blueprint('clientapisecurity', __name__) | ||||
|         self.client_api_security_bp = client_api_security_bp | ||||
|         self.client_api = client_api | ||||
|         pluginwhitelist.load_plugin_security_whitelist_endpoints(whitelist_endpoints) | ||||
| 
 | ||||
|         @client_api_security_bp.before_app_request | ||||
|         def validate_request(): | ||||
|             '''Validate request has set password and is the correct hostname''' | ||||
|             # For the purpose of preventing DNS rebinding attacks | ||||
|             if request.host != '%s:%s' % (client_api.host, client_api.bindPort): | ||||
|                 abort(403) | ||||
| 
 | ||||
|             # Add shared objects | ||||
|             try: | ||||
|                 g.too_many = self.client_api._too_many | ||||
|             except KeyError: | ||||
|                 g.too_many = None | ||||
| 
 | ||||
|             if request.endpoint in whitelist_endpoints: | ||||
|                 return | ||||
|             if request.path.startswith('/site/'): return | ||||
| 
 | ||||
|             try: | ||||
|                 if not hmac.compare_digest(request.headers['token'], client_api.clientToken): | ||||
|                     if not hmac.compare_digest(request.form['token'], client_api.clientToken): | ||||
|                         abort(403) | ||||
|             except KeyError: | ||||
|                 if not hmac.compare_digest(request.form['token'], client_api.clientToken): | ||||
|                     abort(403) | ||||
| 
 | ||||
|         @client_api_security_bp.after_app_request | ||||
|         def after_req(resp): | ||||
|             # Security headers | ||||
|             resp = httpheaders.set_default_onionr_http_headers(resp) | ||||
|             if request.endpoint in ('siteapi.site', 'siteapi.siteFile'): | ||||
|                 resp.headers['Content-Security-Policy'] = "default-src 'none'; style-src 'self' data: 'unsafe-inline'; img-src 'self' data:; media-src 'self' data:" | ||||
|             else: | ||||
|                 resp.headers['Content-Security-Policy'] = "default-src 'none'; script-src 'self'; object-src 'none'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; media-src 'none'; frame-src 'none'; font-src 'self'; connect-src 'self'" | ||||
|             return resp</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.security" href="index.html">src.httpapi.security</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-classes">Classes</a></h3> | ||||
| <ul> | ||||
| <li> | ||||
| <h4><code><a title="src.httpapi.security.client.ClientAPISecurity" href="#src.httpapi.security.client.ClientAPISecurity">ClientAPISecurity</a></code></h4> | ||||
| </li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										81
									
								
								docs/html/src/httpapi/security/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								docs/html/src/httpapi/security/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,81 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.security API documentation</title> | ||||
| <meta name="description" content="" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.security</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">from . import client, public</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-submodules">Sub-modules</h2> | ||||
| <dl> | ||||
| <dt><code class="name"><a title="src.httpapi.security.client" href="client.html">src.httpapi.security.client</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.security.pluginwhitelist" href="pluginwhitelist.html">src.httpapi.security.pluginwhitelist</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.security.public" href="public.html">src.httpapi.security.public</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="../index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-submodules">Sub-modules</a></h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.security.client" href="client.html">src.httpapi.security.client</a></code></li> | ||||
| <li><code><a title="src.httpapi.security.pluginwhitelist" href="pluginwhitelist.html">src.httpapi.security.pluginwhitelist</a></code></li> | ||||
| <li><code><a title="src.httpapi.security.public" href="public.html">src.httpapi.security.public</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										124
									
								
								docs/html/src/httpapi/security/pluginwhitelist.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								docs/html/src/httpapi/security/pluginwhitelist.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,124 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.security.pluginwhitelist API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.security.pluginwhitelist</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>Load web UI client endpoints into the whitelist from plugins</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">""" | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     Load web UI client endpoints into the whitelist from plugins | ||||
| """ | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| import onionrplugins | ||||
| def load_plugin_security_whitelist_endpoints(whitelist: list): | ||||
|     """Accept a list reference of whitelist endpoints from security/client.py and | ||||
|     append plugin's specified endpoints to them by attribute""" | ||||
|     for plugin in onionrplugins.get_enabled_plugins(): | ||||
|         try: | ||||
|             plugin = onionrplugins.get_plugin(plugin) | ||||
|         except FileNotFoundError: | ||||
|             continue | ||||
|         try: | ||||
|             whitelist.extend(getattr(plugin, "security_whitelist")) | ||||
|         except AttributeError: | ||||
|             pass</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.security.pluginwhitelist.load_plugin_security_whitelist_endpoints"><code class="name flex"> | ||||
| <span>def <span class="ident">load_plugin_security_whitelist_endpoints</span></span>(<span>whitelist)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Accept a list reference of whitelist endpoints from security/client.py and | ||||
| append plugin's specified endpoints to them by attribute</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def load_plugin_security_whitelist_endpoints(whitelist: list): | ||||
|     """Accept a list reference of whitelist endpoints from security/client.py and | ||||
|     append plugin's specified endpoints to them by attribute""" | ||||
|     for plugin in onionrplugins.get_enabled_plugins(): | ||||
|         try: | ||||
|             plugin = onionrplugins.get_plugin(plugin) | ||||
|         except FileNotFoundError: | ||||
|             continue | ||||
|         try: | ||||
|             whitelist.extend(getattr(plugin, "security_whitelist")) | ||||
|         except AttributeError: | ||||
|             pass</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.security" href="index.html">src.httpapi.security</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.security.pluginwhitelist.load_plugin_security_whitelist_endpoints" href="#src.httpapi.security.pluginwhitelist.load_plugin_security_whitelist_endpoints">load_plugin_security_whitelist_endpoints</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										179
									
								
								docs/html/src/httpapi/security/public.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										179
									
								
								docs/html/src/httpapi/security/public.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,179 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.security.public API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.security.public</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>Process incoming requests to the public api server for certain attacks</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">''' | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     Process incoming requests to the public api server for certain attacks | ||||
| ''' | ||||
| ''' | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| ''' | ||||
| from flask import Blueprint, request, abort, g | ||||
| from onionrservices import httpheaders | ||||
| from onionrutils import epoch | ||||
| from utils import gettransports | ||||
| class PublicAPISecurity: | ||||
|     def __init__(self, public_api): | ||||
|         public_api_security_bp = Blueprint('publicapisecurity', __name__) | ||||
|         self.public_api_security_bp = public_api_security_bp | ||||
| 
 | ||||
|         @public_api_security_bp.before_app_request | ||||
|         def validate_request(): | ||||
|             '''Validate request has the correct hostname''' | ||||
|             # If high security level, deny requests to public (HS should be disabled anyway for Tor, but might not be for I2P) | ||||
|             transports = gettransports.get() | ||||
|             if public_api.config.get('general.security_level', default=1) > 0: | ||||
|                 abort(403) | ||||
|             if request.host not in transports: | ||||
|                 # Disallow connection if wrong HTTP hostname, in order to prevent DNS rebinding attacks | ||||
|                 abort(403) | ||||
|             public_api.hitCount += 1 # raise hit count for valid requests | ||||
|             try: | ||||
|                 if 'onionr' in request.headers['User-Agent'].lower(): | ||||
|                     g.is_onionr_client = True | ||||
|                 else: | ||||
|                     g.is_onionr_client = False | ||||
|             except KeyError: | ||||
|                 g.is_onionr_client = False | ||||
| 
 | ||||
|         @public_api_security_bp.after_app_request | ||||
|         def send_headers(resp): | ||||
|             '''Send api, access control headers''' | ||||
|             resp = httpheaders.set_default_onionr_http_headers(resp) | ||||
|             # Network API version | ||||
|             resp.headers['X-API'] = public_api.API_VERSION | ||||
|             # Delete some HTTP headers for Onionr user agents | ||||
|             NON_NETWORK_HEADERS = ('Content-Security-Policy', 'X-Frame-Options', | ||||
|             'X-Content-Type-Options', 'Feature-Policy', 'Clear-Site-Data', 'Referrer-Policy') | ||||
|             if g.is_onionr_client: | ||||
|                 for header in NON_NETWORK_HEADERS: del resp.headers[header] | ||||
|             public_api.lastRequest = epoch.get_rounded_epoch(roundS=5) | ||||
|             return resp</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-classes">Classes</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.security.public.PublicAPISecurity"><code class="flex name class"> | ||||
| <span>class <span class="ident">PublicAPISecurity</span></span> | ||||
| <span>(</span><span>public_api)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">class PublicAPISecurity: | ||||
|     def __init__(self, public_api): | ||||
|         public_api_security_bp = Blueprint('publicapisecurity', __name__) | ||||
|         self.public_api_security_bp = public_api_security_bp | ||||
| 
 | ||||
|         @public_api_security_bp.before_app_request | ||||
|         def validate_request(): | ||||
|             '''Validate request has the correct hostname''' | ||||
|             # If high security level, deny requests to public (HS should be disabled anyway for Tor, but might not be for I2P) | ||||
|             transports = gettransports.get() | ||||
|             if public_api.config.get('general.security_level', default=1) > 0: | ||||
|                 abort(403) | ||||
|             if request.host not in transports: | ||||
|                 # Disallow connection if wrong HTTP hostname, in order to prevent DNS rebinding attacks | ||||
|                 abort(403) | ||||
|             public_api.hitCount += 1 # raise hit count for valid requests | ||||
|             try: | ||||
|                 if 'onionr' in request.headers['User-Agent'].lower(): | ||||
|                     g.is_onionr_client = True | ||||
|                 else: | ||||
|                     g.is_onionr_client = False | ||||
|             except KeyError: | ||||
|                 g.is_onionr_client = False | ||||
| 
 | ||||
|         @public_api_security_bp.after_app_request | ||||
|         def send_headers(resp): | ||||
|             '''Send api, access control headers''' | ||||
|             resp = httpheaders.set_default_onionr_http_headers(resp) | ||||
|             # Network API version | ||||
|             resp.headers['X-API'] = public_api.API_VERSION | ||||
|             # Delete some HTTP headers for Onionr user agents | ||||
|             NON_NETWORK_HEADERS = ('Content-Security-Policy', 'X-Frame-Options', | ||||
|             'X-Content-Type-Options', 'Feature-Policy', 'Clear-Site-Data', 'Referrer-Policy') | ||||
|             if g.is_onionr_client: | ||||
|                 for header in NON_NETWORK_HEADERS: del resp.headers[header] | ||||
|             public_api.lastRequest = epoch.get_rounded_epoch(roundS=5) | ||||
|             return resp</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.security" href="index.html">src.httpapi.security</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-classes">Classes</a></h3> | ||||
| <ul> | ||||
| <li> | ||||
| <h4><code><a title="src.httpapi.security.public.PublicAPISecurity" href="#src.httpapi.security.public.PublicAPISecurity">PublicAPISecurity</a></code></h4> | ||||
| </li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										95
									
								
								docs/html/src/httpapi/sse/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								docs/html/src/httpapi/sse/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,95 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.sse API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.sse</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication.</p> | ||||
| <p>server sent event modules, incl a wrapper and endpoints for client + public api</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">"""Onionr - Private P2P Communication. | ||||
| 
 | ||||
| server sent event modules, incl a wrapper and endpoints for client + public api | ||||
| """ | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-submodules">Sub-modules</h2> | ||||
| <dl> | ||||
| <dt><code class="name"><a title="src.httpapi.sse.private" href="private/index.html">src.httpapi.sse.private</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| <dt><code class="name"><a title="src.httpapi.sse.wrapper" href="wrapper.html">src.httpapi.sse.wrapper</a></code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Onionr - Private P2P Communication …</p></section> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="../index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-submodules">Sub-modules</a></h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.sse.private" href="private/index.html">src.httpapi.sse.private</a></code></li> | ||||
| <li><code><a title="src.httpapi.sse.wrapper" href="wrapper.html">src.httpapi.sse.wrapper</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										153
									
								
								docs/html/src/httpapi/sse/private/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										153
									
								
								docs/html/src/httpapi/sse/private/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,153 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.sse.private API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.sse.private</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication.</p> | ||||
| <p>SSE API for node client access</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">"""Onionr - Private P2P Communication. | ||||
| 
 | ||||
| SSE API for node client access | ||||
| """ | ||||
| from flask import g, Blueprint | ||||
| from gevent import sleep | ||||
| import gevent | ||||
| 
 | ||||
| from onionrstatistics.transports.tor import TorStats | ||||
| from .. import wrapper | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| 
 | ||||
| private_sse_blueprint = Blueprint('privatesse', __name__) | ||||
| SSEWrapper = wrapper.SSEWrapper() | ||||
| 
 | ||||
| gevent.hub.Hub.NOT_ERROR = (gevent.GreenletExit, SystemExit, Exception) | ||||
| 
 | ||||
| @private_sse_blueprint.route('/hello') | ||||
| def stream_hello(): | ||||
|     def print_hello(): | ||||
|         while True: | ||||
|             yield "hello\n\n" | ||||
|             sleep(1) | ||||
|     return SSEWrapper.handle_sse_request(print_hello) | ||||
| 
 | ||||
| 
 | ||||
| @private_sse_blueprint.route('/torcircuits') | ||||
| def stream_tor_circuits(): | ||||
|     tor_stats = g.too_many.get(TorStats) | ||||
|     def circuit_stat_stream(): | ||||
|         while True: | ||||
|             yield "data: " + tor_stats.get_json() + "\n\n" | ||||
|             sleep(10) | ||||
|     return SSEWrapper.handle_sse_request(circuit_stat_stream)</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.sse.private.stream_hello"><code class="name flex"> | ||||
| <span>def <span class="ident">stream_hello</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@private_sse_blueprint.route('/hello') | ||||
| def stream_hello(): | ||||
|     def print_hello(): | ||||
|         while True: | ||||
|             yield "hello\n\n" | ||||
|             sleep(1) | ||||
|     return SSEWrapper.handle_sse_request(print_hello)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| <dt id="src.httpapi.sse.private.stream_tor_circuits"><code class="name flex"> | ||||
| <span>def <span class="ident">stream_tor_circuits</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@private_sse_blueprint.route('/torcircuits') | ||||
| def stream_tor_circuits(): | ||||
|     tor_stats = g.too_many.get(TorStats) | ||||
|     def circuit_stat_stream(): | ||||
|         while True: | ||||
|             yield "data: " + tor_stats.get_json() + "\n\n" | ||||
|             sleep(10) | ||||
|     return SSEWrapper.handle_sse_request(circuit_stat_stream)</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.sse" href="../index.html">src.httpapi.sse</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.sse.private.stream_hello" href="#src.httpapi.sse.private.stream_hello">stream_hello</a></code></li> | ||||
| <li><code><a title="src.httpapi.sse.private.stream_tor_circuits" href="#src.httpapi.sse.private.stream_tor_circuits">stream_tor_circuits</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										148
									
								
								docs/html/src/httpapi/sse/wrapper.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										148
									
								
								docs/html/src/httpapi/sse/wrapper.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,148 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.sse.wrapper API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.sse.wrapper</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication.</p> | ||||
| <p>wrapper for server sent event endpoints</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">"""Onionr - Private P2P Communication. | ||||
| 
 | ||||
| wrapper for server sent event endpoints | ||||
| """ | ||||
| from typing import Callable | ||||
| 
 | ||||
| from flask import Response | ||||
| 
 | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| 
 | ||||
| 
 | ||||
| class SSEWrapper: | ||||
|     def __init__(self): | ||||
|         self.active_count: int = 0 | ||||
| 
 | ||||
|     def handle_sse_request(self, handler: Callable): | ||||
|         self.active_count += 1 | ||||
|         resp = Response(handler()) | ||||
|         resp.content_type = "text/event-stream" | ||||
|         self.active_count -= 1 | ||||
|         return resp</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-classes">Classes</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.sse.wrapper.SSEWrapper"><code class="flex name class"> | ||||
| <span>class <span class="ident">SSEWrapper</span></span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">class SSEWrapper: | ||||
|     def __init__(self): | ||||
|         self.active_count: int = 0 | ||||
| 
 | ||||
|     def handle_sse_request(self, handler: Callable): | ||||
|         self.active_count += 1 | ||||
|         resp = Response(handler()) | ||||
|         resp.content_type = "text/event-stream" | ||||
|         self.active_count -= 1 | ||||
|         return resp</code></pre> | ||||
| </details> | ||||
| <h3>Methods</h3> | ||||
| <dl> | ||||
| <dt id="src.httpapi.sse.wrapper.SSEWrapper.handle_sse_request"><code class="name flex"> | ||||
| <span>def <span class="ident">handle_sse_request</span></span>(<span>self, handler)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">def handle_sse_request(self, handler: Callable): | ||||
|     self.active_count += 1 | ||||
|     resp = Response(handler()) | ||||
|     resp.content_type = "text/event-stream" | ||||
|     self.active_count -= 1 | ||||
|     return resp</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi.sse" href="index.html">src.httpapi.sse</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-classes">Classes</a></h3> | ||||
| <ul> | ||||
| <li> | ||||
| <h4><code><a title="src.httpapi.sse.wrapper.SSEWrapper" href="#src.httpapi.sse.wrapper.SSEWrapper">SSEWrapper</a></code></h4> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.sse.wrapper.SSEWrapper.handle_sse_request" href="#src.httpapi.sse.wrapper.SSEWrapper.handle_sse_request">handle_sse_request</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										135
									
								
								docs/html/src/httpapi/themeapi/index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										135
									
								
								docs/html/src/httpapi/themeapi/index.html
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,135 @@ | |||
| <!doctype html> | ||||
| <html lang="en"> | ||||
| <head> | ||||
| <meta charset="utf-8"> | ||||
| <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> | ||||
| <meta name="generator" content="pdoc 0.7.4" /> | ||||
| <title>src.httpapi.themeapi API documentation</title> | ||||
| <meta name="description" content="Onionr - Private P2P Communication …" /> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'> | ||||
| <link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'> | ||||
| <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet"> | ||||
| <style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> | ||||
| <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> | ||||
| <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> | ||||
| </head> | ||||
| <body> | ||||
| <main> | ||||
| <article id="content"> | ||||
| <header> | ||||
| <h1 class="title">Module <code>src.httpapi.themeapi</code></h1> | ||||
| </header> | ||||
| <section id="section-intro"> | ||||
| <p>Onionr - Private P2P Communication</p> | ||||
| <p>API to get current CSS theme for the client web UI</p> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">""" | ||||
|     Onionr - Private P2P Communication | ||||
| 
 | ||||
|     API to get current CSS theme for the client web UI | ||||
| """ | ||||
| """ | ||||
|     This program is free software: you can redistribute it and/or modify | ||||
|     it under the terms of the GNU General Public License as published by | ||||
|     the Free Software Foundation, either version 3 of the License, or | ||||
|     (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| from flask import Blueprint, Response | ||||
| 
 | ||||
| import config | ||||
| from utils import readstatic | ||||
| 
 | ||||
| theme_blueprint = Blueprint('themes', __name__) | ||||
| 
 | ||||
| LIGHT_THEME_FILES = ['bulma-light.min.css', 'styles-light.css'] | ||||
| DARK_THEME_FILES = ['bulma-dark.min.css', 'styles-dark.css'] | ||||
| 
 | ||||
| def _load_from_files(file_list: list)->str: | ||||
|     """Loads multiple static dir files and returns them in combined string format (non-binary)""" | ||||
|     combo_data = '' | ||||
|     for f in file_list: | ||||
|         combo_data += readstatic.read_static('www/shared/main/themes/' + f) | ||||
|     return combo_data | ||||
| 
 | ||||
| @theme_blueprint.route('/gettheme', endpoint='getTheme') | ||||
| def get_theme_file()->Response: | ||||
|     """Returns the css theme data""" | ||||
|     css: str | ||||
|     theme = config.get('ui.theme', 'dark').lower() | ||||
|     if theme == 'dark': | ||||
|         css = _load_from_files(DARK_THEME_FILES) | ||||
|     elif theme == 'light': | ||||
|         css = _load_from_files(LIGHT_THEME_FILES) | ||||
|     return Response(css, mimetype='text/css')</code></pre> | ||||
| </details> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| <section> | ||||
| <h2 class="section-title" id="header-functions">Functions</h2> | ||||
| <dl> | ||||
| <dt id="src.httpapi.themeapi.get_theme_file"><code class="name flex"> | ||||
| <span>def <span class="ident">get_theme_file</span></span>(<span>)</span> | ||||
| </code></dt> | ||||
| <dd> | ||||
| <section class="desc"><p>Returns the css theme data</p></section> | ||||
| <details class="source"> | ||||
| <summary> | ||||
| <span>Expand source code</span> | ||||
| </summary> | ||||
| <pre><code class="python">@theme_blueprint.route('/gettheme', endpoint='getTheme') | ||||
| def get_theme_file()->Response: | ||||
|     """Returns the css theme data""" | ||||
|     css: str | ||||
|     theme = config.get('ui.theme', 'dark').lower() | ||||
|     if theme == 'dark': | ||||
|         css = _load_from_files(DARK_THEME_FILES) | ||||
|     elif theme == 'light': | ||||
|         css = _load_from_files(LIGHT_THEME_FILES) | ||||
|     return Response(css, mimetype='text/css')</code></pre> | ||||
| </details> | ||||
| </dd> | ||||
| </dl> | ||||
| </section> | ||||
| <section> | ||||
| </section> | ||||
| </article> | ||||
| <nav id="sidebar"> | ||||
| <h1>Index</h1> | ||||
| <div class="toc"> | ||||
| <ul></ul> | ||||
| </div> | ||||
| <ul id="index"> | ||||
| <li><h3>Super-module</h3> | ||||
| <ul> | ||||
| <li><code><a title="src.httpapi" href="../index.html">src.httpapi</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| <li><h3><a href="#header-functions">Functions</a></h3> | ||||
| <ul class=""> | ||||
| <li><code><a title="src.httpapi.themeapi.get_theme_file" href="#src.httpapi.themeapi.get_theme_file">get_theme_file</a></code></li> | ||||
| </ul> | ||||
| </li> | ||||
| </ul> | ||||
| </nav> | ||||
| </main> | ||||
| <footer id="footer"> | ||||
| <p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.4</a>.</p> | ||||
| </footer> | ||||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||||
| <script>hljs.initHighlightingOnLoad()</script> | ||||
| </body> | ||||
| </html> | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue