def main(argv): config = g.config = Config() config.load('/var/www/tachweb/settings.ini') GetLogger().app_configure() msg = sys.stdin.read() msg = email.message_from_string(msg) with db() as conn: cursor = conn.execute('SELECT * FROM newslist') for rcpt in cursor: to = "%s <%s>" % ( rcpt['name'], rcpt['email'], ) new = format_msg(msg, html_template=html_template, text_template=text_template, email_from='*****@*****.**', email_to=to, multipart=True, token=rcpt['token'], name=rcpt['name']) try: send_email('*****@*****.**', to, msg=new) except Exception as e: log.critical('Failed to send to %s (%s)' % ( rcpt, e, ))
def main(argv): # PLEASE STICK WITH THIS - ITS MORE SECURE unix_user = pwd.getpwuid(os.getuid())[0] if unix_user not in allowed: raise Exception( 'Not allowed user or ensure your authenticated via smtp' + '(%s)' % unix_user) config = g.config = Config() config.load('/var/www/tachweb/settings.ini') GetLogger().app_configure() msg = sys.stdin.read() msg = email.message_from_string(msg) with db() as conn: cursor = conn.execute('SELECT * FROM newslist') for rcpt in cursor: to = "%s <%s>" % ( rcpt['name'], rcpt['email'], ) new = format_msg(msg, html_template=html_template, text_template=text_template, email_from='*****@*****.**', email_to=to, multipart=True, token=rcpt['token'], name=rcpt['name']) try: send_email('*****@*****.**', to, msg=new) except Exception as e: log.critical('Failed to send to %s (%s)' % ( rcpt, e, ))
def main(argv): try: parser = argparse.ArgumentParser() action = parser.add_mutually_exclusive_group() parser.add_argument('path', help='Tachyonic Web Location') action.add_argument('-s', '--start', action='store_true', help='Fork Process') parser.add_argument('-f', '--fork', action='store_true', help='Fork Process') action.add_argument('-k', '--kill', action='store_true', help='Stop/Kill Process') action.add_argument('-r', '--restart', action='store_true', help='Restart Process') args = parser.parse_args() root_path = os.path.abspath(os.path.abspath(args.path)) pid_file = root_path + '/github.pid' config = g.config = Config() config.load(root_path + '/settings.ini') GetLogger().app_configure() site.addsitedir(os.path.abspath(root_path)) def proc(): daemon(root_path, config) fork = Daemon(pid_file, run=proc) if args.start: if args.fork is True: fork.start() else: fork.start(fork=False) else: if args.kill is True: fork.stop() if args.restart is True: fork.restart() except KeyboardInterrupt: print("Control-C closed / Killed")
def __init__(self, env, start_response): global _cached_wsgi_error_conf # Init Base super().__init__(env, start_response) # Set HTTP Request Method - Router uses this. self.method = env['REQUEST_METHOD'] # WSGI Error Handling. if _cached_wsgi_error_conf is False: root_logger = GetLogger() root_logger.log_wsgi(stream=env['wsgi.errors']) _cached_wsgi_error_conf = True # Set HTTP Request Application URL - Router uses this. # PEP 3333 specifies that PATH_INFO may be the # empty string, so normalize it in that case. route = env['PATH_INFO'] or '/' # PEP 3333 specifies that PATH_INFO variable are alwaysa # "bytes tunneled as latin-1" and must be encoded back self.route = route.encode('latin1').decode('utf-8', 'replace') # Set Environ self.env = env # Caching self._cached_app_uri = None self._cached_forwarded_app_uri = None self._cached_uri = None self._cached_relative_resource_uri = None self._cached_forwarded_uri = None self._cached_relative_uri = None self._cached_forwarded = None self._cached_query_string = None self._cached_content_type = None self._cached_content_length = None self._cached_stream = None self._cached_params = None self._cached_form = None self._cached_access_hops = None self._cached_cookies = None self._cached_is_mobile = None self._cached_is_bot = None self._cached_static = None self._cached_json = None
def execute(*args, check=True, virtualenv=False): from luxon import GetLogger log = GetLogger(__name__) loginfo = TemporaryFile() logerr = TemporaryFile() log_id = string_id(length=6) try: env = os.environ.copy() if virtualenv is False: if '__PYVENV_LAUNCHER__' in env: del env['__PYVENV_LAUNCHER__'] log.info("Execute '%s'" % " ".join(args[0]), log_id=log_id) subprocess.run(*args, stdout=loginfo, stderr=logerr, check=True, env=env) loginfo.seek(0) logerr.seek(0) log.info(if_bytes_to_unicode(loginfo.read()), log_id=log_id) log.error(if_bytes_to_unicode(logerr.read()), log_id=log_id) loginfo.seek(0) return if_bytes_to_unicode(loginfo.read()) except subprocess.CalledProcessError as e: logerr.seek(0) if check is True: cmd = " ".join(*args) raise ExecuteError(cmd, if_bytes_to_unicode(logerr.read())) from None loginfo.seek(0) logerr.seek(0) log.info(if_bytes_to_unicode(loginfo.read()), log_id=log_id) log.error(if_bytes_to_unicode(logerr.read()), log_id=log_id) logerr.seek(0) return if_bytes_to_unicode(logerr.read()) finally: loginfo.close() logerr.close()
# Sharing in the above context means that two threads may use a resource # without wrapping it using a mutex semaphore to implement resource locking. # Note that you cannot always make external resources thread safe by managing # access using a mutex: the resource may rely on global variables or other # external sources that are beyond your control. # # paramstyle paramstyle = "qmark" # paramstyle Meaning # qmark Question mark style, e.g. ...WHERE name=? # numeric Numeric, positional style, e.g. ...WHERE name=:1 # named Named style, e.g. ...WHERE name=:name # format ANSI C printf format codes, e.g. ...WHERE name=%s # pyformat Python extended format codes, e.g. ...WHERE name=%(name)s log = GetLogger(__name__) error_map = () cast_map = () class Connection(BaseExeptions): DB_API = None CHARSET = 'utf-8' DEST_FORMAT = None ERROR_MAP = error_map CAST_MAP = cast_map _crsr_cls_args = [] THREADSAFETY = threadsafety _instances = {}
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF # THE POSSIBILITY OF SUCH DAMAGE. from luxon import register from luxon import g from psychokinetic.client import Client from luxon import GetLogger log = GetLogger() @register.resource('POST', '/login') def login(req, resp): username = req.get_first('username') password = req.get_first('password') domain = req.get_first('domain') token = req.context.api.password(username, password, domain) token = token.json['token'] req.user_token = token resp.redirect(req.app) @register.resource('GET', '/logout') def logout(req, resp):