Example #1
0
    def __manualToot(self, inFulluser, inDomain, inToot, inMastodon):
        #############################
        # 分かるよう加工
        wTag = '\n' + gVal.STR_MasterConfig['mTootTag'] + " @" + inFulluser
        wToot = inToot + wTag

        wMaxToot = 500 - len(wTag)
        if len(wToot) > 500:
            wRes = CLS_OSIF.sInp(str(wMaxToot) + " 文字以上は送信できません。[RT]")
            return False

        CLS_OSIF.sPrn("mastodonに送信中...")
        #############################
        # IP疎通チェック
        if CLS_OSIF.sPing(inDomain) != True:
            wRes = CLS_OSIF.sInp("mastodonと接続できないため送信できませんでした。[RT]")
            return False

        #############################
        #トゥート
        wRes = inMastodon.Toot(status=wToot,
                               visibility=self.STR_TootRange['ManualToot'])
        if wRes['Result'] != True:
            CLS_OSIF.sPrn("mastodon API Error: " + wRes['Reason'])
            wRes = CLS_OSIF.sInp("継続します。[RT]")
            return False

        wRes = CLS_OSIF.sInp("トゥートの送信を正常におこないました。[RT]")
        return True
Example #2
0
    def __multicastToot(self, inFulluser, inSendlist, inToot, inSTR_Mastodon):
        #############################
        # 分かるよう加工
        wTtl = "[Multicast] "
        wTag = '\n' + gVal.STR_MasterConfig['mTootTag'] + " @" + inFulluser
        wToot = wTtl + inToot + wTag

        wMaxToot = 500 - (len(wTtl) + len(wTag))
        if len(wToot) > 500:
            wRes = CLS_OSIF.sInp(str(wMaxToot) + " 文字以上は送信できません。[RT]")
            return False

        CLS_OSIF.sPrn("mastodonに配信中...")
        wKeylist = inSendlist.keys()
        wListLen = len(wKeylist)
        wSend = 0
        for iKey in wKeylist:
            #############################
            # mastodonオブジェクト取得
            wMastodon = inSTR_Mastodon.GetMastodon(iKey)
            if wMastodon['Result'] != True:
                wStr = "mastodon取得NG: user="******"    " + wMastodon['Reason']
                CLS_OSIF.sPrn(wStr)
                continue

            #############################
            # IP疎通チェック
            if CLS_OSIF.sPing(inSendlist[iKey]['domain']) != True:
                CLS_OSIF.sPrn("通信NG: " + inSendlist[iKey]['domain'])
                continue

            #############################
            #トゥート
            wRes = wMastodon['Responce'].Toot(
                status=wToot, visibility=self.STR_TootRange['Multicast'])
            if wRes['Result'] != True:
                CLS_OSIF.sPrn("mastodon API Error: " + wRes['Reason'] +
                              ": account= " + iKey)
                continue

            CLS_OSIF.sPrn("送信OK: " + inSendlist[iKey]['domain'])

            #############################
            #カウント
            wSend += 1
            if wListLen > wSend:
                ###送り切ってなければディレイする
                CLS_OSIF.sSleep(gVal.DEF_STR_TLNUM['getMcDelay'])

        wRes = CLS_OSIF.sPrn("配信完了。[RT]")
        return True
Example #3
0
	def CreateMastodon( self, inFulluser ):
		#############################
		# 応答形式の取得(mastodon形式)
		#   "Result" : False, "Reason" : None, "Responce" : None
		wRes = CLS_Mastodon_Use.sGet_API_Resp()
		
		#############################
		# 出力先領域のチェック
			#辞書型か?
		if isinstance( self.STR_Mastodon, dict )!=True :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: STR_Mastodon is not dict: type= " + type(self.STR_Mastodon)
			return wRes
		
			#重複してるか?
		if inFulluser in self.STR_Mastodon :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: Overlap user: "******"CLS_Regist: CreateMastodon: Domain check error: " + inFulluser
			return wRes
		
		#############################
		# ping疎通チェック
		if CLS_OSIF.sPing( wSTR_user['Domain'] )!=True :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: Ping check error: " + wSTR_user['Domain']
			return wRes	#失敗
		
		#############################
		# レジストファイルの存在チェック
		wGetPath = CLS_UserData.sGetUserPath( inFulluser )
##		if wGetPath['Result']!=True :
##			wRes['Reason'] = "CLS_Regist: CreateMastodon: User path ng: " + wGetPath['Reason']
##			return wRes
		
		wRegFile = wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_RegFile']
		if CLS_File.sExist( wRegFile )!=True :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: Regist File not is found: " + wRegFile
			return wRes		#ファイルがない
		
		wUserFile = wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_UserFile']
		if CLS_File.sExist( wUserFile )!=True :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: Userreg File not is found: " + wUserFile
			return wRes		#ファイルがない
		
		#############################
		# mastodon APIオブジェクトを生成する
		self.STR_Mastodon.update({ inFulluser : CLS_Mastodon_Use(
			api_base_url = "https://" + wSTR_user['Domain'],
			client_id    = wRegFile,
			access_token = wUserFile ) })
###			flg_orginit=True ) })
		
		wIniStatus = self.STR_Mastodon[inFulluser].GetIniStatus()
		if wIniStatus['Result']!=True :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: Create Mastodon object failuer: " + wIniStatus['Reason']
			return wRes		#mastodon error
		
		#############################
		# 通信テスト(トークンチェック)
		if self.STR_Mastodon[inFulluser].TokenCheck()!=True :
			wRes['Reason'] = "CLS_Regist: CreateMastodon: Mastodon Token is None (mastodon error): " + inFulluser
			return wRes		#ファイルがない
		
		wRes['Result'] = True
		return wRes
Example #4
0
	def Update( self, inFulluser=None ):
		#############################
		# ユーザ名がない場合、名前を入力する
		if inFulluser==None :
			wStr = gVal.STR_SystemInfo['Client_Name'] + " に再登録するユーザ名を入力します。" + '\n'
			wStr = wStr + "再登録するユーザ名をドメインを含めて入力してください。 例= " + gVal.DEF_EXAMPLE_ACCOUNT
			CLS_OSIF.sPrn( wStr )
			inFulluser = CLS_OSIF.sInp( "User?=> " )
		
		#############################
		# ユーザ名の妥当性チェック
		wSTR_user = CLS_UserData.sUserCheck( inFulluser )
		if wSTR_user['Result']!=True :
			CLS_OSIF.sPrn( wSTR_user['Reason'] )
			return False
		elif wSTR_user['Registed']==False :
			CLS_OSIF.sPrn( "そのユーザは登録されていません。: " + inFulluser )
			return False
		
		#############################
		# メールアドレス、パスワードの入力
		wStr = '\n' + inFulluser + " を登録します。"
		wStr = wStr + "mastodonに登録したメールアドレスとパスワードを入力してください。"
		CLS_OSIF.sPrn( wStr )
		
		###入力受け付け
		wMail = CLS_OSIF.sInp( "Mailaddr: " )
		wPass = CLS_OSIF.sGpp( "Password: "******"mastodon ID: " + inFulluser + '\n'
		wStr = wStr + "Mailaddress: " + wMail
		CLS_OSIF.sPrn( wStr )
		wRes = CLS_OSIF.sInp( "以上の内容で登録します(y/N): " )
		if wRes!="y" :
			CLS_OSIF.sPrn( "登録を中止しました" + '\n' )
			return False
		
		#############################
		# 入力チェック
		wRes = self.__registUser( inFulluser, wMail, wPass )
		if wRes['Result']!=True :
			CLS_OSIF.sPrn( wRes['Reason'] )
			return False
		
		CLS_OSIF.sPrn( '\n' + "通信テスト中..." )
		#############################
		# mastodonアクセス前 ping疎通チェック
		if CLS_OSIF.sPing( wSTR_user['Domain'] )!=True :
			CLS_OSIF.sPrn( "mastodonサーバ " + wSTR_user['Domain'] + " が応答しません。登録を中止します。" )
			return False
		
		CLS_OSIF.sPrn( "通信OK" + '\n' + "データ登録中......" )
		#############################
		# レジストファイルの作りなおし
		wGetPath = CLS_UserData.sGetUserPath( inFulluser )
		if wGetPath['Result']!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Update: User path ng: " + wGetPath['Reason'] )
			return False
		
		if CLS_File.sClrFile( wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_RegFile'] )!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Update: Reg File is not found: " + wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_RegFile'] )
			return False
		
		if CLS_File.sClrFile( wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_UserFile'] )!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Update: User File is not found: " + wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_UserFile'] )
			return False
		
		#############################
		# mastodonアカウントへの関連付け(本レジスト)
		wRes = CLS_Regist.sRegistMastodon( inFulluser, wMail, wPass )
		if wRes['Result']!=True :
			wStr = "mastodonへの関連付けに失敗しました" + '\n'
			wStr = wStr + "メールアドレス、パスワード、mastodonが運用中か確認してください。" + '\n'
			wStr = wStr + wRes['Reason']
			CLS_OSIF.sPrn( wStr )
			# データ削除
			CLS_File.sRmtree( wGetPath['Responce'] )
			return False
		
		CLS_OSIF.sPrn( "登録OK" + '\n' + "mastodon登録テスト中......" )
		#############################
		# 通信テスト
		wRes = self.CreateMastodon( inFulluser )
		if wRes['Result']!=True :
			wStr = "mastodonへの関連付けに失敗しました" + '\n'
			wStr = wStr + "メールアドレス、パスワード、mastodonが運用中か確認してください。" + '\n'
			wStr = wStr + wRes['Reason']
			CLS_OSIF.sPrn( wStr )
			# データ削除
			CLS_File.sRmtree( wGetPath['Responce'] )
			return False
		
		CLS_OSIF.sPrn( "mastodon登録OK" + '\n' )
		
		#############################
		# 完了
		CLS_OSIF.sPrn( inFulluser + " の再登録が完了しました" + '\n' )
		return True
Example #5
0
	def Regist( self, inFulluser=None ):
		#############################
		# ユーザ名がない場合、名前を入力する
		if inFulluser==None :
			wStr = gVal.STR_SystemInfo['Client_Name'] + " に新しいユーザ名を入力します。" + '\n'
			wStr = wStr + "登録するユーザ名をドメインを含めて入力してください。 例= " + gVal.DEF_EXAMPLE_ACCOUNT
			CLS_OSIF.sPrn( wStr )
			inFulluser = CLS_OSIF.sInp( "User?=> " )
		
		#############################
		# ユーザ名の妥当性チェック
		wSTR_user = CLS_UserData.sUserCheck( inFulluser )
		if wSTR_user['Result']!=True :
			CLS_OSIF.sPrn( wSTR_user['Reason'] )
			return False
		elif wSTR_user['Registed']==True :
			CLS_OSIF.sPrn( "既に登録されているユーザです。: " + inFulluser )
			return False
		
		#############################
		# メールアドレス、パスワードの入力
		wStr = '\n' + inFulluser + " を登録します。"
		wStr = wStr + "mastodonに登録したメールアドレスとパスワードを入力してください。"
		CLS_OSIF.sPrn( wStr )
		
		###入力受け付け
		wMail = CLS_OSIF.sInp( "Mailaddr: " )
		wPass = CLS_OSIF.sGpp( "Password: "******"mastodon ID: " + inFulluser + '\n'
		wStr = wStr + "Mailaddress: " + wMail
		CLS_OSIF.sPrn( wStr )
		wRes = CLS_OSIF.sInp( "以上の内容で登録します(y/N): " )
		if wRes!="y" :
			CLS_OSIF.sPrn( "登録を中止しました" + '\n' )
			return False
		
		#############################
		# 入力チェック
		wRes = self.__registUser( inFulluser, wMail, wPass )
		if wRes['Result']!=True :
			CLS_OSIF.sPrn( wRes['Reason'] )
			return False
		
		CLS_OSIF.sPrn( '\n' + "通信テスト中..." )
		#############################
		# mastodonアクセス前 ping疎通チェック
		if CLS_OSIF.sPing( wSTR_user['Domain'] )!=True :
			CLS_OSIF.sPrn( "mastodonサーバ " + wSTR_user['Domain'] + " が応答しません。登録を中止します。" )
			return False
		
		CLS_OSIF.sPrn( "通信OK" + '\n' + "データ登録中......" )
		#############################
		# テンプレートデータのコピー(データ作成)
		wGetPath = CLS_UserData.sGetUserPath( inFulluser )
##		if wGetPath['Result']!=True :
##			CLS_OSIF.sPrn( "CLS_Regist: Regist: User path ng: " + wGetPath['Reason'] )
##			return False
		
		if CLS_File.sCopytree(
			gVal.DEF_STR_FILE['defUserdata_path'],
			wGetPath['Responce'] )!=True :
			###ありえない
			CLS_OSIF.sPrn( "CLS_Regist: Regist: defaultデータコピー失敗" )
			return False
		
		if CLS_File.sFolderExist( gVal.DEF_USERDATA_PATH, inFulluser )!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Regist: ユーザデータの登録に失敗しました" )
			return False
		
		#############################
		# mastodonアカウントへの関連付け(本レジスト)
		wRes = self.sRegistMastodon( inFulluser, wMail, wPass )
		if wRes['Result']!=True :
			wStr = "mastodonへの関連付けに失敗しました" + '\n'
			wStr = wStr + "メールアドレス、パスワード、mastodonが運用中か確認してください。" + '\n'
			wStr = wStr + wRes['Reason']
			CLS_OSIF.sPrn( wStr )
			# データ削除
			CLS_File.sRmtree( wGetPath['Responce'] )
			return False
		
		CLS_OSIF.sPrn( "登録OK" + '\n' + "mastodon登録テスト中......" )
		#############################
		# 通信テスト
		wRes = self.CreateMastodon( inFulluser )
		if wRes['Result']!=True :
			wStr = "mastodonへの関連付けに失敗しました" + '\n'
			wStr = wStr + "メールアドレス、パスワード、mastodonが運用中か確認してください。" + '\n'
			wStr = wStr + wRes['Reason']
			CLS_OSIF.sPrn( wStr )
			# データ削除
			CLS_File.sRmtree( wGetPath['Responce'] )
			return False
		
		CLS_OSIF.sPrn( "mastodon登録OK" + '\n' )
		
		#############################
		# cron作成
		if inFulluser == gVal.STR_MasterConfig['MasterUser'] :
			wKind = gVal.DEF_CRON_MASTER
		else:
			wKind = gVal.DEF_CRON_SUB
		
		wCLS_botjib = CLS_Botjob()
		wPutRes = wCLS_botjib.Put( wKind, inFulluser )
		if wPutRes['Result']!=True :
##			CLS_OSIF.sPrn( "CLS_Regist: Regist: cron create failed: " + wPutRes['Reason'] )
##			return False
##		
##		CLS_OSIF.sPrn( '\n' + "cronを起動しました" )
			CLS_OSIF.sPrn( "cronの起動に失敗しました: " + wPutRes['Reason'] )
		else :
			CLS_OSIF.sPrn( '\n' + "cronを起動しました" )
		
		#############################
		# トラヒックの登録
		wRes = self.__regTrafficUser( inFulluser )
		if wRes['Result']!=True :
			CLS_OSIF.sPrn( "CLS_Regist: Regist: " + wRes['Reason'] )
			return False
		if wRes['Update']==True :
			CLS_OSIF.sPrn( "DBにトラヒック情報が追加されました" )
		
		#############################
		# 完了
		CLS_OSIF.sPrn( inFulluser + " の登録が完了しました" + '\n' )
		return True
Example #6
0
    def CnfAdminUser(self):
        #############################
        # ファイルの存在チェック
        if CLS_File.sExist(gVal.DEF_STR_FILE['MasterConfig']) != True:
            ###ありえない
            CLS_OSIF.sPrn(
                "CLS_Config: cCnfAdminUser: masterConfig file is not found : "
                + gVal.DEF_STR_FILE['MasterConfig'])
            return False  #ない

        #############################
        # 変更メニュー表示
        if gVal.STR_MasterConfig['AdminUser'] == "":
            wStr = "現在AdminUserは設定されていません。設定することで登録ユーザから通知を受け取ることができるようになります。"
            wSt2 = "AdminUserの設定をおこないますか?(y/N)=> "
        else:
            wStr = "現在AdminUserは次のアカウントが設定されています。: " + gVal.STR_MasterConfig[
                'AdminUser']
            wSt2 = "AdminUserの設定をおこないますか?(y:変更 /D:解除 /other: キャンセル)=> "

        CLS_OSIF.sPrn(wStr)
        wSelect = CLS_OSIF.sInp(wSt2)
        if wSelect == "D":
            ###削除
            gVal.STR_MasterConfig['AdminUser'] = ""
            self.sSetMasterConfig()
            CLS_OSIF.sPrn("AdminUserの設定を解除しました。" + '\n')
            CLS_OSIF.sPrn("設定内容をMaster環境情報にセーブしました: " +
                          gVal.DEF_STR_FILE['MasterConfig'] + '\n')
            return True
        elif wSelect != "y":
            ###設定しない
            CLS_OSIF.sPrn("キャンセルされました")
            return True

        #############################
        # 名前入力
        wStr = "AdminUser(通知先アカウント)をドメインを含めて入力してください。 例= " + gVal.DEF_EXAMPLE_ACCOUNT + '\n'
        wStr = wStr + "  ※ユーザ登録してないユーザも指定できます"
        CLS_OSIF.sPrn(wStr)
        wAdminUser = CLS_OSIF.sInp("AdminUser? => ")
        if wAdminUser=="" or \
           gVal.STR_MasterConfig['AdminUser'] ==wAdminUser :
            ###設定しない
            CLS_OSIF.sPrn("キャンセルされました")
            return True

        #############################
        # ユーザ名の妥当性チェック
        wSTR_user = CLS_UserData.sUserCheck(wAdminUser)
        if wSTR_user['Result'] != True:
            return False

        #############################
        # 通信テスト
        CLS_OSIF.sPrn("通信テスト中...")
        if CLS_OSIF.sPing(wSTR_user['Domain']) != True:
            CLS_OSIF.sPrn("mastodonとの通信テストに失敗したため、設定をキャンセルします。")
            return False

        CLS_OSIF.sPrn("通信OK")

        #############################
        # 変更
        gVal.STR_MasterConfig['AdminUser'] = wAdminUser
        self.sSetMasterConfig()
        CLS_OSIF.sPrn("設定内容をMaster環境情報にセーブしました: " +
                      gVal.DEF_STR_FILE['MasterConfig'] + '\n')
        return True