| 114 | |
| 115 | @PluginManager.acceptPlugins |
| 116 | class Actions(object): |
| 117 | def call(self, function_name, kwargs): |
| 118 | logging.info("Version: %s r%s, Python %s, Gevent: %s" % (config.version, config.rev, sys.version, gevent.__version__)) |
| 119 | |
| 120 | func = getattr(self, function_name, None) |
| 121 | back = func(**kwargs) |
| 122 | if back: |
| 123 | print(back) |
| 124 | |
| 125 | # Default action: Start serving UiServer and FileServer |
| 126 | def main(self): |
| 127 | global ui_server, file_server |
| 128 | from File import FileServer |
| 129 | from Ui import UiServer |
| 130 | logging.info("Creating FileServer....") |
| 131 | file_server = FileServer() |
| 132 | logging.info("Creating UiServer....") |
| 133 | ui_server = UiServer() |
| 134 | file_server.ui_server = ui_server |
| 135 | |
| 136 | logging.info("Removing old SSL certs...") |
| 137 | from Crypt import CryptConnection |
| 138 | CryptConnection.manager.removeCerts() |
| 139 | |
| 140 | logging.info("Starting servers....") |
| 141 | gevent.joinall([gevent.spawn(ui_server.start), gevent.spawn(file_server.start)]) |
| 142 | logging.info("All server stopped") |
| 143 | |
| 144 | # Site commands |
| 145 | |
| 146 | def siteCreate(self): |
| 147 | logging.info("Generating new privatekey...") |
| 148 | from Crypt import CryptBitcoin |
| 149 | privatekey = CryptBitcoin.newPrivatekey() |
| 150 | logging.info("----------------------------------------------------------------------") |
| 151 | logging.info("Site private key: %s" % privatekey) |
| 152 | logging.info(" !!! ^ Save it now, required to modify the site ^ !!!") |
| 153 | address = CryptBitcoin.privatekeyToAddress(privatekey) |
| 154 | logging.info("Site address: %s" % address) |
| 155 | logging.info("----------------------------------------------------------------------") |
| 156 | |
| 157 | while True and not config.batch: |
| 158 | if input("? Have you secured your private key? (yes, no) > ").lower() == "yes": |
| 159 | break |
| 160 | else: |
| 161 | logging.info("Please, secure it now, you going to need it to modify your site!") |
| 162 | |
| 163 | logging.info("Creating directory structure...") |
| 164 | from Site.Site import Site |
| 165 | from Site import SiteManager |
| 166 | SiteManager.site_manager.load() |
| 167 | |
| 168 | os.mkdir("%s/%s" % (config.data_dir, address)) |
| 169 | open("%s/%s/index.html" % (config.data_dir, address), "w").write("Hello %s!" % address) |
| 170 | |
| 171 | logging.info("Creating content.json...") |
| 172 | site = Site(address) |
| 173 | site.content_manager.sign(privatekey=privatekey, extend={"postmessage_nonce_security": True}) |