' + "\n" # description
793 | html += '
' + "\n" #regex
794 |
795 | # include repo/account/project/file link
796 | if 'github' == row[0]:
797 | begin = r[4].index('GrepBugs/remotesrc') + len('GrepBugs/remotesrc') # determine beginning position of repo path
798 | file_link = '
' + str(r[5]) + ''
799 | ltrim_by = row[1]
800 | ltrim_begin = begin
801 | else:
802 | file_link = str(r[5])
803 | ltrim_by = row[2]
804 | ltrim_begin = 0
805 |
806 | html += '
' + r[4][r[4].index(ltrim_by, ltrim_begin):] + ' ' + file_link + ': ' + cgi.escape(r[6]) + '
' + "\n" # finding
807 |
808 | try:
809 | html += '
' + r[4][r[4].index(ltrim_by, ltrim_begin):] + ' ' + file_link + ': ' + "\n " + cgi.escape(r[6]) + '
' + "\n" # finding
810 |
811 | except ValueError:
812 | html += 'Exception ValueError: Got a value error on a substring for ' + r[4] + '/' + r[5] + "\n"
813 | logging.error('Using grep binary ' + grepbin)
814 |
815 | count += 1
816 | language = r[0]
817 | regex = r[1]
818 |
819 | if 0 == count:
820 | html += '
No bugs found!
Contribute regular expressions to find bugs in this code at
GrepBugs.com';
821 | tabs += "No bugs found\n\nContribute regular expressions to find bugs in this code at https://GrepBugs.com\n";
822 | else:
823 | html += '
' + "\n"
824 | tabs += "\n"
825 |
826 | html += ''
827 | o.write(html)
828 | o.close()
829 | t.write(tabs)
830 | t.close()
831 |
832 | if 'mysql' == gbconfig.get('database', 'database'):
833 | mysqldb.close()
834 | else:
835 | db.close()
836 |
837 | """
838 | Handle and process command line arguments
839 | """
840 | parser = argparse.ArgumentParser(description='At minimum, the -d or -r options must be specified.')
841 | parser.add_argument('-d', help='specify a LOCAL directory to scan.')
842 | parser.add_argument('-f', help='force scan even if project has not been modified since last scan.', default=False, action="store_true")
843 | parser.add_argument('-u', help='Use existing rules, do not download updated set.', default=False, action="store_true")
844 |
845 | group = parser.add_argument_group('REMOTE Repository Scanning')
846 | group.add_argument('-r', help='specify a repo to scan (e.g. github, bitbucket, or sourceforge).')
847 | group.add_argument('-a', help='specify an account for the specified repo.')
848 | group.add_argument('-repo_user', help='specify a username to be used in authenticating to the specified repo (default: grepbugs).', default='grepbugs')
849 | group.add_argument('-repo_pass', help='specify a password to be used in authenticating to the specified repo (default: grepbugs).', default='grepbugs')
850 | parser.add_argument('-no_reports', help='Do not generate reports, only store results in the database.', default=False, action="store_true")
851 |
852 | args = parser.parse_args()
853 |
854 | if None == args.d and None == args.r:
855 | parser.print_help()
856 | sys.exit(1)
857 |
858 | if None != args.d:
859 | print 'scan directory: ' + args.d
860 | scan_id = local_scan(args.d)
861 | elif None != args.r:
862 | if None == args.a:
863 | print 'an account must be specified! use -a to specify an account.'
864 | sys.exit(1)
865 |
866 | print 'scan repo: ' + args.r + ' ' + args.a
867 | scan_id = repo_scan(args.r, args.a, args.f, args.no_reports)
868 |
--------------------------------------------------------------------------------